Skip to content

Commit

Permalink
Prefer length and percentage for word spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
wafflespeanut committed Aug 9, 2016
1 parent 7ed9134 commit a04028e
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 10 deletions.
1 change: 1 addition & 0 deletions components/gfx/Cargo.toml
Expand Up @@ -28,6 +28,7 @@ log = "0.3.5"
mime = "0.2"
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
ordered-float = "0.2.2"
plugins = {path = "../plugins"}
profile_traits = {path = "../profile_traits"}
rand = "0.3"
Expand Down
7 changes: 5 additions & 2 deletions components/gfx/font.rs
Expand Up @@ -5,6 +5,7 @@
use app_units::Au;
use euclid::{Point2D, Rect, Size2D};
use font_template::FontTemplateDescriptor;
use ordered_float::NotNaN;
use platform::font::{FontHandle, FontTable};
use platform::font_context::FontContextHandle;
use platform::font_template::FontTemplateData;
Expand Down Expand Up @@ -157,7 +158,7 @@ pub struct ShapingOptions {
/// NB: You will probably want to set the `IGNORE_LIGATURES_SHAPING_FLAG` if this is non-null.
pub letter_spacing: Option<Au>,
/// Spacing to add between each word. Corresponds to the CSS 2.1 `word-spacing` property.
pub word_spacing: Au,
pub word_spacing: (Au, NotNaN<f32>),
/// The Unicode script property of the characters in this run.
pub script: Script,
/// Various flags.
Expand Down Expand Up @@ -225,7 +226,9 @@ impl Font {

let mut advance = Au::from_f64_px(self.glyph_h_advance(glyph_id));
if character == ' ' {
advance += options.word_spacing;
// https://drafts.csswg.org/css-text-3/#word-spacing-property
let (length, percent) = options.word_spacing;
advance = (advance + length) + Au((advance.0 as f32 * percent.into_inner()) as i32);
}
if let Some(letter_spacing) = options.letter_spacing {
advance += letter_spacing;
Expand Down
1 change: 1 addition & 0 deletions components/gfx/lib.rs
Expand Up @@ -60,6 +60,7 @@ extern crate log;
extern crate mime;
extern crate msg;
extern crate net_traits;
extern crate ordered_float;
#[macro_use]
extern crate profile_traits;
extern crate rand;
Expand Down
4 changes: 3 additions & 1 deletion components/gfx/text/shaping/harfbuzz.rs
Expand Up @@ -403,7 +403,9 @@ impl Shaper {
// applied. The effect of the property on other word-separator characters is undefined."
// We elect to only space the two required code points.
if character == ' ' || character == '\u{a0}' {
advance = advance + options.word_spacing
// https://drafts.csswg.org/css-text-3/#word-spacing-property
let (length, percent) = options.word_spacing;
advance = (advance + length) + Au((advance.0 as f32 * percent.into_inner()) as i32);
}

advance
Expand Down
1 change: 1 addition & 0 deletions components/layout/Cargo.toml
Expand Up @@ -26,6 +26,7 @@ libc = "0.2"
log = "0.3.5"
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
ordered-float = "0.2.2"
plugins = {path = "../plugins"}
profile_traits = {path = "../profile_traits"}
range = {path = "../range"}
Expand Down
1 change: 1 addition & 0 deletions components/layout/lib.rs
Expand Up @@ -35,6 +35,7 @@ extern crate libc;
extern crate log;
extern crate msg;
extern crate net_traits;
extern crate ordered_float;
#[macro_use]
#[no_link]
extern crate plugins as servo_plugins;
Expand Down
5 changes: 4 additions & 1 deletion components/layout/text.rs
Expand Up @@ -17,6 +17,7 @@ use gfx::text::text_run::TextRun;
use gfx::text::util::{self, CompressionMode};
use inline::{FIRST_FRAGMENT_OF_ELEMENT, InlineFragments, LAST_FRAGMENT_OF_ELEMENT};
use linked_list::split_off_head;
use ordered_float::NotNaN;
use range::Range;
use std::borrow::ToOwned;
use std::collections::LinkedList;
Expand Down Expand Up @@ -164,7 +165,9 @@ impl TextRunScanner {
};
text_transform = inherited_text_style.text_transform;
letter_spacing = inherited_text_style.letter_spacing.0;
word_spacing = inherited_text_style.word_spacing.0.unwrap_or(Au(0));
word_spacing = inherited_text_style.word_spacing.0
.map(|lop| lop.to_hash_key())
.unwrap_or((Au(0), NotNaN::new(0.0).unwrap()));
text_rendering = inherited_text_style.text_rendering;
}

Expand Down
25 changes: 25 additions & 0 deletions components/servo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/style/Cargo.toml
Expand Up @@ -34,6 +34,7 @@ lazy_static = "0.2"
log = "0.3.5"
matches = "0.1"
num-traits = "0.1.32"
ordered-float = "0.2.2"
rand = "0.3"
rustc-serialize = "0.3"
selectors = "0.7"
Expand Down
1 change: 1 addition & 0 deletions components/style/lib.rs
Expand Up @@ -57,6 +57,7 @@ extern crate log;
#[macro_use]
extern crate matches;
extern crate num_traits;
extern crate ordered_float;
extern crate rand;
extern crate rustc_serialize;
extern crate selectors;
Expand Down
11 changes: 6 additions & 5 deletions components/style/properties/longhand/inherited_text.mako.rs
Expand Up @@ -285,7 +285,7 @@
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum SpecifiedValue {
Normal,
Specified(specified::Length), // FIXME(SimonSapin) support percentages
Specified(specified::LengthOrPercentage),
}

impl ToCss for SpecifiedValue {
Expand All @@ -298,10 +298,10 @@
}

pub mod computed_value {
use app_units::Au;
use values::computed::LengthOrPercentage;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Option<Au>);
pub struct T(pub Option<LengthOrPercentage>);
}

impl ToCss for computed_value::T {
Expand All @@ -326,7 +326,7 @@
match *self {
SpecifiedValue::Normal => computed_value::T(None),
SpecifiedValue::Specified(l) =>
computed_value::T(Some(l.to_computed_value(context)))
computed_value::T(Some(l.to_computed_value(context))),
}
}
}
Expand All @@ -335,7 +335,8 @@
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
Ok(SpecifiedValue::Normal)
} else {
specified::Length::parse_non_negative(input).map(SpecifiedValue::Specified)
specified::LengthOrPercentage::parse_non_negative(input)
.map(SpecifiedValue::Specified)
}
}
</%helpers:longhand>
Expand Down
10 changes: 10 additions & 0 deletions components/style/values/computed/mod.rs
Expand Up @@ -4,6 +4,7 @@

use app_units::Au;
use euclid::size::Size2D;
use ordered_float::NotNaN;
use properties::ComputedValues;
use std::fmt;
use super::LocalToCss;
Expand Down Expand Up @@ -241,6 +242,15 @@ impl LengthOrPercentage {
Length(_) | Percentage(_) | Calc(_) => false
}
}

pub fn to_hash_key(&self) -> (Au, NotNaN<f32>) {
use self::LengthOrPercentage::*;
match *self {
Length(l) => (l, NotNaN::new(0.0).unwrap()),
Percentage(p) => (Au(0), NotNaN::new(p).unwrap()),
Calc(c) => (c.length(), NotNaN::new(c.percentage()).unwrap()),
}
}
}

impl fmt::Debug for LengthOrPercentage {
Expand Down
25 changes: 25 additions & 0 deletions ports/cef/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions ports/geckolib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion python/tidy/servo_tidy/tidy.py
Expand Up @@ -261,7 +261,7 @@ def find_reverse_dependencies(dependency, version, content):
raise StopIteration

# package names to be neglected (as named by cargo)
exceptions = ["lazy_static"]
exceptions = ["lazy_static", "unreachable", "void"]

import toml
content = toml.loads(contents)
Expand Down

0 comments on commit a04028e

Please sign in to comment.