diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2015-10-12 19:02:14 -0700 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2015-10-20 10:44:51 -0700 |
commit | 3a451ff84517f63faaf2d3439ee56748f162eb9f (patch) | |
tree | 52a8702c5b00cf4ecb9f7f68ed6b378c4d33b9e3 /components/layout/text.rs | |
parent | 5e4f132b3b63ad0e18cccf186e8d90a5054406b0 (diff) | |
download | servo-3a451ff84517f63faaf2d3439ee56748f162eb9f.tar.gz servo-3a451ff84517f63faaf2d3439ee56748f162eb9f.zip |
Add support for `pre-wrap` and `pre-line` values for `white-space`.
This is mostly straightforward. I had to modify a couple of places
which were accidentally discarding whitespace.
Fixes #1513.
Diffstat (limited to 'components/layout/text.rs')
-rw-r--r-- | components/layout/text.rs | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/components/layout/text.rs b/components/layout/text.rs index 6efc5302a61..e007eb3d25b 100644 --- a/components/layout/text.rs +++ b/components/layout/text.rs @@ -40,13 +40,10 @@ fn text(fragments: &LinkedList<Fragment>) -> String { for fragment in fragments { match fragment.specific { SpecificFragmentInfo::UnscannedText(ref info) => { - match fragment.white_space() { - white_space::T::normal | white_space::T::nowrap => { - text.push_str(&info.text.replace("\n", " ")); - } - white_space::T::pre => { - text.push_str(&info.text); - } + if fragment.white_space_preserve_newlines() { + text.push_str(&info.text); + } else { + text.push_str(&info.text.replace("\n", " ")); } } _ => {} @@ -161,10 +158,11 @@ impl TextRunScanner { let inherited_text_style = in_fragment.style().get_inheritedtext(); fontgroup = font_context.layout_font_group_for_style(font_style); compression = match in_fragment.white_space() { - white_space::T::normal | white_space::T::nowrap => { - CompressionMode::CompressWhitespaceNewline - } - white_space::T::pre => CompressionMode::CompressNone, + white_space::T::normal | + white_space::T::nowrap => CompressionMode::CompressWhitespaceNewline, + white_space::T::pre | + white_space::T::pre_wrap => CompressionMode::CompressNone, + white_space::T::pre_line => CompressionMode::CompressWhitespace, }; text_transform = inherited_text_style.text_transform; letter_spacing = inherited_text_style.letter_spacing.0; @@ -413,6 +411,10 @@ fn split_first_fragment_at_newline_if_necessary(fragments: &mut LinkedList<Fragm let string_before; let insertion_point_before; { + if !first_fragment.white_space_preserve_newlines() { + return; + } + let unscanned_text_fragment_info = match first_fragment.specific { SpecificFragmentInfo::UnscannedText(ref mut unscanned_text_fragment_info) => { unscanned_text_fragment_info @@ -420,10 +422,6 @@ fn split_first_fragment_at_newline_if_necessary(fragments: &mut LinkedList<Fragm _ => return, }; - if first_fragment.style.get_inheritedtext().white_space != white_space::T::pre { - return - } - let position = match unscanned_text_fragment_info.text.find('\n') { Some(position) if position < unscanned_text_fragment_info.text.len() - 1 => { position |