layout: Implement word-spacing per CSS 2.1 § 16.4.

This assumes that there are no ligatures that span across multiple
words. Since we have a per-word shape cache, this is a safe assumption
as of now. I have left comments to ensure that, if and when this is
revisted, we make sure to handle it properly.
This commit is contained in:
Patrick Walton 2014-12-12 17:49:37 -08:00
parent ea39b878ac
commit 106fdb1d32
7 changed files with 94 additions and 7 deletions

View file

@ -107,16 +107,19 @@ impl TextRunScanner {
let compression;
let text_transform;
let letter_spacing;
let word_spacing;
{
let in_fragment = self.clump.front().unwrap();
let font_style = in_fragment.style().get_font_arc();
let inherited_text_style = in_fragment.style().get_inheritedtext();
fontgroup = font_context.get_layout_font_group_for_style(font_style);
compression = match in_fragment.white_space() {
white_space::normal | white_space::nowrap => CompressWhitespaceNewline,
white_space::pre => CompressNone,
};
text_transform = in_fragment.style().get_inheritedtext().text_transform;
letter_spacing = in_fragment.style().get_inheritedtext().letter_spacing;
text_transform = inherited_text_style.text_transform;
letter_spacing = inherited_text_style.letter_spacing;
word_spacing = inherited_text_style.word_spacing.unwrap_or(Au(0));
}
// First, transform/compress text of all the nodes.
@ -160,6 +163,7 @@ impl TextRunScanner {
// `fi n a l l y`.
let options = ShapingOptions {
letter_spacing: letter_spacing,
word_spacing: word_spacing,
flags: match letter_spacing {
Some(Au(0)) | None => ShapingFlags::empty(),
Some(_) => IGNORE_LIGATURES_SHAPING_FLAG,