mirror of
https://github.com/servo/servo.git
synced 2025-09-29 16:19:14 +01:00
fonts: Add more types to fonts_traits
(#38898)
This is necessary so that `constellation_traits` can get these types via a dependency on `fonts_traits`. This will allow sending IPC channels to shared workers so that they can have access to a shared `FontContext` from `script`. Testing: This just moves code between crates, so is covered by existing tests. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
0b5bcfbf17
commit
3a97d4eed2
22 changed files with 495 additions and 446 deletions
|
@ -15,6 +15,7 @@ use app_units::Au;
|
|||
use bitflags::bitflags;
|
||||
use euclid::default::{Point2D, Rect, Size2D};
|
||||
use euclid::num::Zero;
|
||||
use fonts_traits::FontDescriptor;
|
||||
use log::debug;
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use parking_lot::RwLock;
|
||||
|
@ -190,44 +191,6 @@ impl FontMetrics {
|
|||
}
|
||||
}
|
||||
|
||||
/// `FontDescriptor` describes the parameters of a `Font`. It represents rendering a given font
|
||||
/// template at a particular size, with a particular font-variant-caps applied, etc. This contrasts
|
||||
/// with `FontTemplateDescriptor` in that the latter represents only the parameters inherent in the
|
||||
/// font data (weight, stretch, etc.).
|
||||
#[derive(Clone, Debug, Deserialize, Hash, MallocSizeOf, PartialEq, Serialize)]
|
||||
pub struct FontDescriptor {
|
||||
pub weight: FontWeight,
|
||||
pub stretch: FontStretch,
|
||||
pub style: FontStyle,
|
||||
pub variant: font_variant_caps::T,
|
||||
pub pt_size: Au,
|
||||
pub variation_settings: Vec<FontVariation>,
|
||||
}
|
||||
|
||||
impl Eq for FontDescriptor {}
|
||||
|
||||
impl<'a> From<&'a FontStyleStruct> for FontDescriptor {
|
||||
fn from(style: &'a FontStyleStruct) -> Self {
|
||||
let variation_settings = style
|
||||
.clone_font_variation_settings()
|
||||
.0
|
||||
.into_iter()
|
||||
.map(|setting| FontVariation {
|
||||
tag: setting.tag.0,
|
||||
value: setting.value,
|
||||
})
|
||||
.collect();
|
||||
FontDescriptor {
|
||||
weight: style.font_weight,
|
||||
stretch: style.font_stretch,
|
||||
style: style.font_style,
|
||||
variant: style.font_variant_caps,
|
||||
pt_size: Au::from_f32_px(style.font_size.computed_size().px()),
|
||||
variation_settings,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct CachedShapeData {
|
||||
glyph_advances: HashMap<GlyphId, FractionalPixel>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue