mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Auto merge of #12783 - Wafflespeanut:word_spacing, 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 -->
This commit is contained in:
commit
3b676bc85d
15 changed files with 135 additions and 10 deletions
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue