Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upPrefer length and percentage for word spacing #12783
Conversation
highfive
commented
Aug 9, 2016
|
Heads up! This PR modifies the following files:
|
highfive
commented
Aug 9, 2016
|
It requires tests (I guess?) r? @Manishearth and @SimonSapin |
| @@ -225,7 +226,8 @@ impl Font { | |||
|
|
|||
| let mut advance = Au::from_f64_px(self.glyph_h_advance(glyph_id)); | |||
| if character == ' ' { | |||
| advance += options.word_spacing; | |||
| let (length, percent) = options.word_spacing; | |||
| advance = (advance + length) + Au((advance.0 as f32 * percent.into_inner()) as i32); | |||
This comment has been minimized.
This comment has been minimized.
Manishearth
Aug 9, 2016
•
Member
Link to https://www.w3.org/TR/css-text-3/#word-spacing
This looks correct, but I'd like to wait for Simon's review
| @@ -403,7 +403,8 @@ 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 | |||
| let (length, percent) = options.word_spacing; | |||
| advance = (advance + length) + Au((advance.0 as f32 * percent.into_inner()) as i32); | |||
This comment has been minimized.
This comment has been minimized.
| @@ -285,23 +285,23 @@ | |||
| #[cfg_attr(feature = "servo", derive(HeapSizeOf))] | |||
| pub enum SpecifiedValue { | |||
| Normal, | |||
| Specified(specified::Length), // FIXME(SimonSapin) support percentages | |||
| LengthOrPercentage(specified::LengthOrPercentage), | |||
This comment has been minimized.
This comment has been minimized.
|
LGTM modulo nits. r=me post @SimonSapin's sign-off |
2c54092
to
ee82ff6
|
Post IRC discussion we know that your method of calculation is correct. r=me needs lockfile updates: diff --git a/ports/geckolib/Cargo.lock b/ports/geckolib/Cargo.lock
index 405fadd..b60e592 100644
--- a/ports/geckolib/Cargo.lock
+++ b/ports/geckolib/Cargo.lock
@@ -215,6 +215,33 @@ dependencies = [
]
[[package]]
+name = "num"
+version = "0.1.32"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "num-integer"
+version = "0.1.32"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "num-iter"
+version = "0.1.32"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "num-traits"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -228,6 +255,15 @@ dependencies = [
]
[[package]]
+name = "ordered-float"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unreachable 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "quickersort"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -325,6 +361,7 @@ dependencies = [
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "ordered-float 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -388,6 +425,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unreachable"
+version = "0.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "void 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "unreachable"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@@ -427,6 +472,11 @@ dependencies = [
[[package]]
name = "void"
+version = "0.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" |
ee82ff6
to
3b131ee
|
lock file updated :) Thanks! |
|
|
Prefer length and percentage for word spacing <!-- Please describe your changes on the following line: --> The goal is to make use of `LengthOrPercentage` for word spacing in `ShapingOptions`, but since it makes use of `f32` which doesn't implement `Hash`, we're going for `NotNan<f32>` from [ordered-float](https://github.com/reem/rust-ordered-float/), which supports hashing. Instead of implementing `Hash` for `LengthOrPercentage` and thereby the inner types like `CSSFloat`, `CalcLengthOrPercentage`, etc., we convert it to `(Au, NotNan<f32>)`. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors <!-- Either: --> - [ ] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12783) <!-- Reviewable:end -->
|
|
|
forgot to update |
3b131ee
to
a04028e
|
@bors-servo r=Manishearth |
|
|
Prefer length and percentage for word spacing <!-- Please describe your changes on the following line: --> The goal is to make use of `LengthOrPercentage` for word spacing in `ShapingOptions`, but since it makes use of `f32` which doesn't implement `Hash`, we're going for `NotNan<f32>` from [ordered-float](https://github.com/reem/rust-ordered-float/), which supports hashing. Instead of implementing `Hash` for `LengthOrPercentage` and thereby the inner types like `CSSFloat`, `CalcLengthOrPercentage`, etc., we convert it to `(Au, NotNan<f32>)`. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors <!-- Either: --> - [ ] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12783) <!-- Reviewable:end -->
|
|
highfive
commented
Aug 9, 2016
|
|
@bors-servo retry #11631 |
Prefer length and percentage for word spacing <!-- Please describe your changes on the following line: --> The goal is to make use of `LengthOrPercentage` for word spacing in `ShapingOptions`, but since it makes use of `f32` which doesn't implement `Hash`, we're going for `NotNan<f32>` from [ordered-float](https://github.com/reem/rust-ordered-float/), which supports hashing. Instead of implementing `Hash` for `LengthOrPercentage` and thereby the inner types like `CSSFloat`, `CalcLengthOrPercentage`, etc., we convert it to `(Au, NotNan<f32>)`. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors <!-- Either: --> - [ ] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12783) <!-- Reviewable:end -->
|
|
wafflespeanut commentedAug 9, 2016
•
edited
The goal is to make use of
LengthOrPercentagefor word spacing inShapingOptions, but since it makes use off32which doesn't implementHash, we're going forNotNan<f32>from ordered-float, which supports hashing. Instead of implementingHashforLengthOrPercentageand thereby the inner types likeCSSFloat,CalcLengthOrPercentage, etc., we convert it to(Au, NotNan<f32>)../mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is