Skip to content

Commit

Permalink
Bug 1681691 - Add ascent-, descent- and line-gap-override descriptors…
Browse files Browse the repository at this point in the history
… to the style system. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D109287
  • Loading branch information
jfkthame committed Mar 23, 2021
1 parent 829e786 commit 9c70dc7
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 1 deletion.
24 changes: 24 additions & 0 deletions layout/style/FontFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,30 @@ Maybe<StyleFontLanguageOverride> FontFace::GetFontLanguageOverride() const {
return Some(langOverride);
}

Maybe<StylePercentage> FontFace::GetAscentOverride() const {
StylePercentage ascent{0};
if (!Servo_FontFaceRule_GetAscentOverride(GetData(), &ascent)) {
return Nothing();
}
return Some(ascent);
}

Maybe<StylePercentage> FontFace::GetDescentOverride() const {
StylePercentage descent{0};
if (!Servo_FontFaceRule_GetDescentOverride(GetData(), &descent)) {
return Nothing();
}
return Some(descent);
}

Maybe<StylePercentage> FontFace::GetLineGapOverride() const {
StylePercentage lineGap{0};
if (!Servo_FontFaceRule_GetLineGapOverride(GetData(), &lineGap)) {
return Nothing();
}
return Some(lineGap);
}

bool FontFace::HasLocalSrc() const {
AutoTArray<StyleFontFaceSourceListComponent, 8> components;
GetSources(components);
Expand Down
3 changes: 3 additions & 0 deletions layout/style/FontFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class FontFace final : public nsISupports, public nsWrapperCache {
void GetFontVariationSettings(nsTArray<gfxFontVariation>&) const;
void GetSources(nsTArray<StyleFontFaceSourceListComponent>&) const;
Maybe<StyleFontLanguageOverride> GetFontLanguageOverride() const;
Maybe<StylePercentage> GetAscentOverride() const;
Maybe<StylePercentage> GetDescentOverride() const;
Maybe<StylePercentage> GetLineGapOverride() const;

gfxUserFontEntry* CreateUserFontEntry();
gfxUserFontEntry* GetUserFontEntry() const { return mUserFontEntry; }
Expand Down
3 changes: 3 additions & 0 deletions layout/style/nsCSSFontDescList.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ CSS_FONT_DESC(font-feature-settings, FontFeatureSettings)
CSS_FONT_DESC(font-variation-settings, FontVariationSettings)
CSS_FONT_DESC(font-language-override, FontLanguageOverride)
CSS_FONT_DESC(font-display, Display)
CSS_FONT_DESC(ascent-override, AscentOverride)
CSS_FONT_DESC(descent-override, DescentOverride)
CSS_FONT_DESC(line-gap-override, LineGapOverride)
7 changes: 7 additions & 0 deletions modules/libpref/init/StaticPrefList.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6396,6 +6396,13 @@
value: true
mirror: always

# Is support for the @font-face metrics override descriptors enabled?
- name: layout.css.font-metrics-overrides.enabled
type: RelaxedAtomicBool
value: @IS_NIGHTLY_BUILD@
mirror: always
rust: true

# Is support for variation fonts enabled?
- name: layout.css.font-variations.enabled
type: RelaxedAtomicBool
Expand Down
20 changes: 19 additions & 1 deletion servo/components/style/font_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::values::specified::font::SpecifiedFontFeatureSettings;
use crate::values::specified::font::SpecifiedFontStyle;
#[cfg(feature = "gecko")]
use crate::values::specified::font::SpecifiedFontVariationSettings;
use crate::values::specified::font::{AbsoluteFontWeight, FontStretch};
use crate::values::specified::font::{AbsoluteFontWeight, FontStretch, MetricsOverride};
use crate::values::specified::url::SpecifiedUrl;
use crate::values::specified::Angle;
#[cfg(feature = "gecko")]
Expand Down Expand Up @@ -419,6 +419,15 @@ macro_rules! is_descriptor_enabled {
("font-variation-settings") => {
static_prefs::pref!("layout.css.font-variations.enabled")
};
("ascent-override") => {
static_prefs::pref!("layout.css.font-metrics-overrides.enabled")
};
("descent-override") => {
static_prefs::pref!("layout.css.font-metrics-overrides.enabled")
};
("line-gap-override") => {
static_prefs::pref!("layout.css.font-metrics-overrides.enabled")
};
($name:tt) => {
true
};
Expand Down Expand Up @@ -577,6 +586,15 @@ font_face_descriptors! {

/// The language override of this font face.
"font-language-override" language_override / mFontLanguageOverride: font_language_override::SpecifiedValue,

/// The ascent override for this font face.
"ascent-override" ascent_override / mAscentOverride: MetricsOverride,

/// The descent override for this font face.
"descent-override" descent_override / mDescentOverride: MetricsOverride,

/// The line-gap override for this font face.
"line-gap-override" line_gap_override / mLineGapOverride: MetricsOverride,
]
}

Expand Down
31 changes: 31 additions & 0 deletions servo/components/style/values/specified/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,37 @@ impl Parse for VariationValue<Number> {
}
}

/// A metrics override value for a @font-face descriptor
///
/// https://drafts.csswg.org/css-fonts/#font-metrics-override-desc
#[derive(Clone, Copy, Debug, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
pub enum MetricsOverride {
/// A non-negative `<percentage>` of the computed font size
Override(NonNegativePercentage),
/// Normal metrics from the font.
Normal,
}

impl MetricsOverride {
#[inline]
/// Get default value with `normal`
pub fn normal() -> MetricsOverride {
MetricsOverride::Normal
}

/// The ToComputedValue implementation, used for @font-face descriptors.
///
/// Valid override percentages must be non-negative; we return -1.0 to indicate
/// the absence of an override (i.e. 'normal').
#[inline]
pub fn compute(&self) -> ComputedPercentage {
match *self {
MetricsOverride::Normal => ComputedPercentage(-1.0),
MetricsOverride::Override(percent) => ComputedPercentage(percent.0.get()),
}
}
}

#[derive(
Clone,
Copy,
Expand Down
33 changes: 33 additions & 0 deletions servo/ports/geckolib/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2865,6 +2865,9 @@ macro_rules! apply_font_desc_list {
eCSSFontDesc_FontVariationSettings => variation_settings,
eCSSFontDesc_FontLanguageOverride => language_override,
eCSSFontDesc_Display => display,
eCSSFontDesc_AscentOverride => ascent_override,
eCSSFontDesc_DescentOverride => descent_override,
eCSSFontDesc_LineGapOverride => line_gap_override,
]
invalid: [
eCSSFontDesc_UNKNOWN,
Expand Down Expand Up @@ -2980,6 +2983,36 @@ pub unsafe extern "C" fn Servo_FontFaceRule_GetFontLanguageOverride(
simple_font_descriptor_getter_impl!(rule, out, language_override, compute_non_system)
}

// Returns a Percentage of -1.0 if the override descriptor is present but 'normal'
// rather than an actual percentage value.
#[no_mangle]
pub extern "C" fn Servo_FontFaceRule_GetAscentOverride(
rule: &RawServoFontFaceRule,
out: &mut computed::Percentage,
) -> bool {
simple_font_descriptor_getter_impl!(rule, out, ascent_override, compute)
}

// Returns a Percentage of -1.0 if the override descriptor is present but 'normal'
// rather than an actual percentage value.
#[no_mangle]
pub extern "C" fn Servo_FontFaceRule_GetDescentOverride(
rule: &RawServoFontFaceRule,
out: &mut computed::Percentage,
) -> bool {
simple_font_descriptor_getter_impl!(rule, out, descent_override, compute)
}

// Returns a Percentage of -1.0 if the override descriptor is present but 'normal'
// rather than an actual percentage value.
#[no_mangle]
pub extern "C" fn Servo_FontFaceRule_GetLineGapOverride(
rule: &RawServoFontFaceRule,
out: &mut computed::Percentage,
) -> bool {
simple_font_descriptor_getter_impl!(rule, out, line_gap_override, compute)
}

#[no_mangle]
pub unsafe extern "C" fn Servo_FontFaceRule_GetFamilyName(
rule: &RawServoFontFaceRule,
Expand Down

0 comments on commit 9c70dc7

Please sign in to comment.