mirror of
https://github.com/servo/servo.git
synced 2025-08-12 00:45:33 +01:00
Prefer length and percentage for word spacing
This commit is contained in:
parent
7ed9134e5a
commit
a04028eede
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