aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/values/computed/mod.rs
diff options
context:
space:
mode:
authorbors-servo <infra@servo.org>2023-05-11 21:04:45 +0200
committerGitHub <noreply@github.com>2023-05-11 21:04:45 +0200
commit9bec0d0f8e92e90b5d8c99ba691a9d9a6bb41bcc (patch)
treefbfaa73aa4702fdb2a32fe6838388189ab1d41db /components/style/values/computed/mod.rs
parentfeaa66b5972c3e31d77c2acce7d626c455320535 (diff)
parentab2ba273e342c6f1a0c1f29cca3f551fd8926e94 (diff)
downloadservo-9bec0d0f8e92e90b5d8c99ba691a9d9a6bb41bcc.tar.gz
servo-9bec0d0f8e92e90b5d8c99ba691a9d9a6bb41bcc.zip
Auto merge of #29728 - Loirooriol:sync-fontprovider-D157589, r=mrobinson
Simplify our setup for font metric queries from style This is a backport of https://phabricator.services.mozilla.com/D157589, by Emilio Cobos Álvarez, plus some additions so that Servo compiles, and some parts from https://phabricator.services.mozilla.com/D144455. Should have no change in behavior. <!-- Please describe your changes on the following line: --> --- <!-- 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 - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because there should be no change in behavior <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Diffstat (limited to 'components/style/values/computed/mod.rs')
-rw-r--r--components/style/values/computed/mod.rs53
1 files changed, 46 insertions, 7 deletions
diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs
index 1b242547307..9dbbf40b5f4 100644
--- a/components/style/values/computed/mod.rs
+++ b/components/style/values/computed/mod.rs
@@ -14,13 +14,15 @@ use super::generics::transform::IsParallelTo;
use super::generics::{self, GreaterThanOrEqualToOne, NonNegative, ZeroToOne};
use super::specified;
use super::{CSSFloat, CSSInteger};
+use crate::computed_value_flags::ComputedValueFlags;
use crate::context::QuirksMode;
-use crate::font_metrics::{get_metrics_provider_for_product, FontMetricsProvider};
+use crate::font_metrics::{FontMetrics, FontMetricsOrientation};
use crate::media_queries::Device;
#[cfg(feature = "gecko")]
use crate::properties;
use crate::properties::{ComputedValues, LonghandId, StyleBuilder};
use crate::rule_cache::RuleCacheConditions;
+use crate::values::specified::length::FontBaseSize;
use crate::{ArcSlice, Atom, One};
use euclid::{default, Point2D, Rect, Size2D};
use servo_arc::Arc;
@@ -155,10 +157,6 @@ pub struct Context<'a> {
#[cfg(feature = "servo")]
pub cached_system_font: Option<()>,
- /// A font metrics provider, used to access font metrics to implement
- /// font-relative units.
- pub font_metrics_provider: &'a dyn FontMetricsProvider,
-
/// Whether or not we are computing the media list in a media query
pub in_media_query: bool,
@@ -192,11 +190,9 @@ impl<'a> Context<'a> {
F: FnOnce(&Context) -> R,
{
let mut conditions = RuleCacheConditions::default();
- let provider = get_metrics_provider_for_product();
let context = Context {
builder: StyleBuilder::for_inheritance(device, None, None),
- font_metrics_provider: &provider,
cached_system_font: None,
in_media_query: true,
quirks_mode,
@@ -213,6 +209,49 @@ impl<'a> Context<'a> {
self.builder.device
}
+ /// Queries font metrics.
+ pub fn query_font_metrics(
+ &self,
+ base_size: FontBaseSize,
+ orientation: FontMetricsOrientation,
+ retrieve_math_scales: bool,
+ ) -> FontMetrics {
+ if self.for_non_inherited_property.is_some() {
+ self.rule_cache_conditions.borrow_mut().set_uncacheable();
+ }
+ self.builder.add_flags(match base_size {
+ FontBaseSize::CurrentStyle => ComputedValueFlags::DEPENDS_ON_SELF_FONT_METRICS,
+ FontBaseSize::InheritedStyle => ComputedValueFlags::DEPENDS_ON_INHERITED_FONT_METRICS,
+ });
+ let size = base_size.resolve(self);
+ let style = self.style();
+
+ let (wm, font) = match base_size {
+ FontBaseSize::CurrentStyle => (style.writing_mode, style.get_font()),
+ // This is only used for font-size computation.
+ FontBaseSize::InheritedStyle => {
+ (*style.inherited_writing_mode(), style.get_parent_font())
+ },
+ };
+
+ let vertical = match orientation {
+ FontMetricsOrientation::MatchContextPreferHorizontal => {
+ wm.is_vertical() && wm.is_upright()
+ },
+ FontMetricsOrientation::MatchContextPreferVertical => {
+ wm.is_vertical() && !wm.is_sideways()
+ },
+ FontMetricsOrientation::Horizontal => false,
+ };
+ self.device().query_font_metrics(
+ vertical,
+ font,
+ size,
+ self.in_media_query,
+ retrieve_math_scales,
+ )
+ }
+
/// The current viewport size, used to resolve viewport units.
pub fn viewport_size_for_viewport_unit_resolution(&self) -> default::Size2D<Au> {
self.builder