mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
fonts: Add support for generic font families and font size configuration (#32673)
This adds support for generic font families in Servo and allows for configuration of them as well as their default font sizes. One interesting fix here is that now monospace default to 13px, like it does in other browsers. In addition to that, this exposes a new interface in Stylo which allows setting a default style. This is quite useful for fonts, but also for other kinds of default style settings -- like text zoom. Fixes #8371. Fixes #14773. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This commit is contained in:
parent
956b7f62e0
commit
77e9e3deba
32 changed files with 397 additions and 300 deletions
|
@ -59,6 +59,7 @@ use script_traits::{
|
|||
use servo_arc::Arc as ServoArc;
|
||||
use servo_atoms::Atom;
|
||||
use servo_config::opts::{self, DebugOptions};
|
||||
use servo_config::pref;
|
||||
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||
use style::animation::DocumentAnimationSet;
|
||||
use style::context::{
|
||||
|
@ -71,7 +72,7 @@ use style::global_style_data::{GLOBAL_STYLE_DATA, STYLE_THREAD_POOL};
|
|||
use style::invalidation::element::restyle_hints::RestyleHint;
|
||||
use style::media_queries::{Device, MediaList, MediaType};
|
||||
use style::properties::style_structs::Font;
|
||||
use style::properties::PropertyId;
|
||||
use style::properties::{ComputedValues, PropertyId};
|
||||
use style::selector_parser::{PseudoElement, SnapshotMap};
|
||||
use style::servo::media_queries::FontMetricsProvider;
|
||||
use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard, StylesheetGuards};
|
||||
|
@ -82,7 +83,9 @@ use style::stylesheets::{
|
|||
use style::stylist::Stylist;
|
||||
use style::traversal::DomTraversal;
|
||||
use style::traversal_flags::TraversalFlags;
|
||||
use style::values::computed::CSSPixelLength;
|
||||
use style::values::computed::font::GenericFontFamily;
|
||||
use style::values::computed::{CSSPixelLength, FontSize, Length, NonNegativeLength};
|
||||
use style::values::specified::font::KeywordInfo;
|
||||
use style::{driver, Zero};
|
||||
use style_traits::{CSSPixel, DevicePixel, SpeculativePainter};
|
||||
use url::Url;
|
||||
|
@ -494,6 +497,14 @@ impl LayoutThread {
|
|||
// Let webrender know about this pipeline by sending an empty display list.
|
||||
webrender_api_sender.send_initial_transaction(id.into());
|
||||
|
||||
let mut font = Font::initial_values();
|
||||
let default_font_size = pref!(fonts.default_size);
|
||||
font.font_size = FontSize {
|
||||
computed_size: NonNegativeLength::new(default_font_size as f32),
|
||||
used_size: NonNegativeLength::new(default_font_size as f32),
|
||||
keyword_info: KeywordInfo::medium(),
|
||||
};
|
||||
|
||||
// The device pixel ratio is incorrect (it does not have the hidpi value),
|
||||
// but it will be set correctly when the initial reflow takes place.
|
||||
let font_context = Arc::new(FontContext::new(font_cache_thread, resource_threads));
|
||||
|
@ -503,6 +514,7 @@ impl LayoutThread {
|
|||
window_size.initial_viewport,
|
||||
window_size.device_pixel_ratio,
|
||||
Box::new(LayoutFontMetricsProvider(font_context.clone())),
|
||||
ComputedValues::initial_values_with_font_override(font),
|
||||
);
|
||||
|
||||
LayoutThread {
|
||||
|
@ -1043,6 +1055,7 @@ impl LayoutThread {
|
|||
window_size_data.initial_viewport,
|
||||
window_size_data.device_pixel_ratio,
|
||||
Box::new(LayoutFontMetricsProvider(self.font_context.clone())),
|
||||
self.stylist.device().default_computed_values().to_arc(),
|
||||
);
|
||||
|
||||
// Preserve any previously computed root font size.
|
||||
|
@ -1262,6 +1275,14 @@ impl FontMetricsProvider for LayoutFontMetricsProvider {
|
|||
script_script_percent_scale_down: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn base_size_for_generic(&self, generic: GenericFontFamily) -> Length {
|
||||
Length::new(match generic {
|
||||
GenericFontFamily::Monospace => pref!(fonts.default_monospace_size),
|
||||
_ => pref!(fonts.default_size),
|
||||
} as f32)
|
||||
.max(Length::new(0.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for LayoutFontMetricsProvider {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue