diff options
author | Martin Robinson <mrobinson@igalia.com> | 2024-05-30 07:33:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-30 05:33:07 +0000 |
commit | 60b4b6c9f086a6f4bc1cc439daf3b64cf73d1ca8 (patch) | |
tree | 037389c9fbfc7527dbdbc26a25d5dd98ffa56ea4 /components/gfx/text/util.rs | |
parent | c0dedf06d68f5fd6fb8c8b4b970fb47ef91d5431 (diff) | |
download | servo-60b4b6c9f086a6f4bc1cc439daf3b64cf73d1ca8.tar.gz servo-60b4b6c9f086a6f4bc1cc439daf3b64cf73d1ca8.zip |
layout: Add support for `white-space-collapse: break-spaces` (#32388)
This change adds support for `white-space-collapse: break-spaces` and
adds initial parsing support for `overflow-wrap` and `word-break`. The
later two properties are not fully supported, only in their interaction
with `break-spaces`. This is a preliminary change preparing to implement
them.
In addition, `break_and_shape` is now forked and added to Layout 2020.
This function is going to change a lot soon and forking is preparation
for this. More code that is only used by Layout 2013 is moved from `gfx`
to that crate.
Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
Diffstat (limited to 'components/gfx/text/util.rs')
-rw-r--r-- | components/gfx/text/util.rs | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/components/gfx/text/util.rs b/components/gfx/text/util.rs index 016e18f2b56..0efa16cec7b 100644 --- a/components/gfx/text/util.rs +++ b/components/gfx/text/util.rs @@ -4,106 +4,6 @@ use ucd::{Codepoint, UnicodeBlock}; -#[derive(Clone, Copy, Debug, Eq, PartialEq)] -pub enum CompressionMode { - CompressNone, - CompressWhitespace, - CompressWhitespaceNewline, - DiscardNewline, -} - -// ported from Gecko's nsTextFrameUtils::TransformText. -// -// High level TODOs: -// -// * Issue #113: consider incoming text state (arabic, etc) -// and propagate outgoing text state (dual of above) -// -// * Issue #114: record skipped and kept chars for mapping original to new text -// -// * Untracked: various edge cases for bidi, CJK, etc. -pub fn transform_text( - text: &str, - mode: CompressionMode, - incoming_whitespace: bool, - output_text: &mut String, -) -> bool { - let out_whitespace = match mode { - CompressionMode::CompressNone | CompressionMode::DiscardNewline => { - for ch in text.chars() { - if is_discardable_char(ch, mode) { - // TODO: record skipped char - } else { - // TODO: record kept char - if ch == '\t' { - // TODO: set "has tab" flag - } - output_text.push(ch); - } - } - false - }, - - CompressionMode::CompressWhitespace | CompressionMode::CompressWhitespaceNewline => { - let mut in_whitespace: bool = incoming_whitespace; - for ch in text.chars() { - // TODO: discard newlines between CJK chars - let mut next_in_whitespace: bool = is_in_whitespace(ch, mode); - - if !next_in_whitespace { - if is_always_discardable_char(ch) { - // revert whitespace setting, since this char was discarded - next_in_whitespace = in_whitespace; - // TODO: record skipped char - } else { - // TODO: record kept char - output_text.push(ch); - } - } else { - /* next_in_whitespace; possibly add a space char */ - if in_whitespace { - // TODO: record skipped char - } else { - // TODO: record kept char - output_text.push(' '); - } - } - // save whitespace context for next char - in_whitespace = next_in_whitespace; - } /* /for str::each_char */ - in_whitespace - }, - }; - - return out_whitespace; - - fn is_in_whitespace(ch: char, mode: CompressionMode) -> bool { - match (ch, mode) { - (' ', _) => true, - ('\t', _) => true, - ('\n', CompressionMode::CompressWhitespaceNewline) => true, - (_, _) => false, - } - } - - fn is_discardable_char(ch: char, mode: CompressionMode) -> bool { - if is_always_discardable_char(ch) { - return true; - } - match mode { - CompressionMode::DiscardNewline | CompressionMode::CompressWhitespaceNewline => { - ch == '\n' - }, - _ => false, - } - } - - fn is_always_discardable_char(ch: char) -> bool { - // TODO: check for soft hyphens. - is_bidi_control(ch) - } -} - pub fn float_to_fixed(before: usize, f: f64) -> i32 { ((1i32 << before) as f64 * f) as i32 } |