зеркало из https://github.com/mozilla/gecko-dev.git
Bug 282126 - Part 4: Use horizontal metrics for ch in vertical mixed/sideways writing modes and for ex always. r=emilio
Depends on D23425 Differential Revision: https://phabricator.services.mozilla.com/D23426 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
1e3269f7e9
Коммит
0b3540c9bb
|
@ -20,6 +20,16 @@ pub struct FontMetrics {
|
|||
pub zero_advance_measure: Option<Au>,
|
||||
}
|
||||
|
||||
/// Type of font metrics to retrieve.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum FontMetricsOrientation {
|
||||
/// Get metrics for horizontal or vertical according to the Context's
|
||||
/// writing mode.
|
||||
MatchContext,
|
||||
/// Force getting horizontal metrics.
|
||||
Horizontal,
|
||||
}
|
||||
|
||||
/// A trait used to represent something capable of providing us font metrics.
|
||||
pub trait FontMetricsProvider {
|
||||
/// Obtain the metrics for given font family.
|
||||
|
@ -27,7 +37,8 @@ pub trait FontMetricsProvider {
|
|||
&self,
|
||||
_context: &crate::values::computed::Context,
|
||||
_base_size: crate::values::specified::length::FontBaseSize,
|
||||
) -> FontMetricsQueryResult {
|
||||
_orientation: FontMetricsOrientation,
|
||||
) -> FontMetrics {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ use crate::context::{PostAnimationTasks, QuirksMode, SharedStyleContext, UpdateA
|
|||
use crate::data::ElementData;
|
||||
use crate::dom::{LayoutIterator, NodeInfo, OpaqueNode, TDocument, TElement, TNode, TShadowRoot};
|
||||
use crate::element_state::{DocumentState, ElementState};
|
||||
use crate::font_metrics::{FontMetrics, FontMetricsProvider};
|
||||
use crate::font_metrics::{FontMetrics, FontMetricsOrientation, FontMetricsProvider};
|
||||
use crate::gecko::data::GeckoStyleSheet;
|
||||
use crate::gecko::selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl};
|
||||
use crate::gecko::snapshot_helpers;
|
||||
|
@ -1035,6 +1035,7 @@ impl FontMetricsProvider for GeckoFontMetricsProvider {
|
|||
&self,
|
||||
context: &crate::values::computed::Context,
|
||||
base_size: FontBaseSize,
|
||||
orientation: FontMetricsOrientation,
|
||||
) -> FontMetrics {
|
||||
let pc = match context.device().pres_context() {
|
||||
Some(pc) => pc,
|
||||
|
@ -1056,10 +1057,14 @@ impl FontMetricsProvider for GeckoFontMetricsProvider {
|
|||
},
|
||||
};
|
||||
|
||||
let vertical_metrics = match orientation {
|
||||
FontMetricsOrientation::MatchContext => wm.is_vertical() && wm.is_upright(),
|
||||
FontMetricsOrientation::Horizontal => false,
|
||||
};
|
||||
let gecko_metrics = unsafe {
|
||||
bindings::Gecko_GetFontMetrics(
|
||||
pc,
|
||||
wm.is_vertical() && !wm.is_sideways(),
|
||||
vertical_metrics,
|
||||
font.gecko(),
|
||||
size.0,
|
||||
// we don't use the user font set in a media query
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
//! [length]: https://drafts.csswg.org/css-values/#lengths
|
||||
|
||||
use super::{AllowQuirks, Number, Percentage, ToComputedValue};
|
||||
use crate::font_metrics::FontMetrics;
|
||||
use crate::font_metrics::{FontMetrics, FontMetricsOrientation};
|
||||
use crate::parser::{Parse, ParserContext};
|
||||
use crate::properties::computed_value_flags::ComputedValueFlags;
|
||||
use crate::values::computed::{self, CSSPixelLength, Context};
|
||||
|
@ -133,8 +133,9 @@ impl FontRelativeLength {
|
|||
fn query_font_metrics(
|
||||
context: &Context,
|
||||
base_size: FontBaseSize,
|
||||
orientation: FontMetricsOrientation,
|
||||
) -> FontMetrics {
|
||||
context.font_metrics_provider.query(context, base_size)
|
||||
context.font_metrics_provider.query(context, base_size, orientation)
|
||||
}
|
||||
|
||||
let reference_font_size = base_size.resolve(context);
|
||||
|
@ -160,7 +161,12 @@ impl FontRelativeLength {
|
|||
context.rule_cache_conditions.borrow_mut().set_uncacheable();
|
||||
}
|
||||
context.builder.add_flags(ComputedValueFlags::DEPENDS_ON_FONT_METRICS);
|
||||
let metrics = query_font_metrics(context, base_size);
|
||||
// The x-height is an intrinsically horizontal metric.
|
||||
let metrics = query_font_metrics(
|
||||
context,
|
||||
base_size,
|
||||
FontMetricsOrientation::Horizontal
|
||||
);
|
||||
let reference_size = metrics.x_height.unwrap_or_else(|| {
|
||||
// https://drafts.csswg.org/css-values/#ex
|
||||
//
|
||||
|
@ -177,7 +183,18 @@ impl FontRelativeLength {
|
|||
context.rule_cache_conditions.borrow_mut().set_uncacheable();
|
||||
}
|
||||
context.builder.add_flags(ComputedValueFlags::DEPENDS_ON_FONT_METRICS);
|
||||
let metrics = query_font_metrics(context, base_size);
|
||||
// https://drafts.csswg.org/css-values/#ch:
|
||||
//
|
||||
// Equal to the used advance measure of the “0” (ZERO,
|
||||
// U+0030) glyph in the font used to render it. (The advance
|
||||
// measure of a glyph is its advance width or height,
|
||||
// whichever is in the inline axis of the element.)
|
||||
//
|
||||
let metrics = query_font_metrics(
|
||||
context,
|
||||
base_size,
|
||||
FontMetricsOrientation::MatchContext,
|
||||
);
|
||||
let reference_size = metrics.zero_advance_measure.unwrap_or_else(|| {
|
||||
// https://drafts.csswg.org/css-values/#ch
|
||||
//
|
||||
|
@ -189,7 +206,8 @@ impl FontRelativeLength {
|
|||
// writing-mode is vertical-rl or vertical-lr and
|
||||
// text-orientation is upright).
|
||||
//
|
||||
if context.style().writing_mode.is_vertical() {
|
||||
let wm = context.style().writing_mode;
|
||||
if wm.is_vertical() && wm.is_upright() {
|
||||
reference_font_size
|
||||
} else {
|
||||
reference_font_size.scale_by(0.5)
|
||||
|
|
Загрузка…
Ссылка в новой задаче