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.
This commit is contained in:
Eli Friedman 2015-10-12 19:02:14 -07:00
parent 5e4f132b3b
commit 3a451ff845
17 changed files with 427 additions and 104 deletions

View file

@ -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