mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
style: Remove the dependency on font-kit from style.
No good reason to have this IMO, and helps remove some #[cfg] blocks.
This commit is contained in:
parent
7a696cbffe
commit
e5484250db
6 changed files with 35 additions and 61 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -519,6 +519,7 @@ dependencies = [
|
||||||
"servo_config",
|
"servo_config",
|
||||||
"sparkle",
|
"sparkle",
|
||||||
"style",
|
"style",
|
||||||
|
"style_traits",
|
||||||
"surfman",
|
"surfman",
|
||||||
"surfman-chains",
|
"surfman-chains",
|
||||||
"surfman-chains-api",
|
"surfman-chains-api",
|
||||||
|
@ -5466,7 +5467,6 @@ dependencies = [
|
||||||
"encoding_rs",
|
"encoding_rs",
|
||||||
"euclid",
|
"euclid",
|
||||||
"fallible",
|
"fallible",
|
||||||
"font-kit",
|
|
||||||
"fxhash",
|
"fxhash",
|
||||||
"hashglobe",
|
"hashglobe",
|
||||||
"html5ever",
|
"html5ever",
|
||||||
|
|
|
@ -37,6 +37,7 @@ servo_arc = { path = "../servo_arc" }
|
||||||
servo_config = { path = "../config" }
|
servo_config = { path = "../config" }
|
||||||
sparkle = "0.1.25"
|
sparkle = "0.1.25"
|
||||||
style = { path = "../style" }
|
style = { path = "../style" }
|
||||||
|
style_traits = { path = "../style_traits" }
|
||||||
# NOTE: the sm-angle feature only enables ANGLE on Windows, not other platforms!
|
# NOTE: the sm-angle feature only enables ANGLE on Windows, not other platforms!
|
||||||
surfman = { version = "0.2", features = ["sm-angle", "sm-angle-default"] }
|
surfman = { version = "0.2", features = ["sm-angle", "sm-angle-default"] }
|
||||||
surfman-chains = "0.3"
|
surfman-chains = "0.3"
|
||||||
|
|
|
@ -11,7 +11,7 @@ use euclid::{point2, vec2};
|
||||||
use font_kit::family_name::FamilyName;
|
use font_kit::family_name::FamilyName;
|
||||||
use font_kit::font::Font;
|
use font_kit::font::Font;
|
||||||
use font_kit::metrics::Metrics;
|
use font_kit::metrics::Metrics;
|
||||||
use font_kit::properties::Properties;
|
use font_kit::properties::{Properties, Weight, Stretch, Style};
|
||||||
use font_kit::source::SystemSource;
|
use font_kit::source::SystemSource;
|
||||||
use gfx::font::FontHandleMethods;
|
use gfx::font::FontHandleMethods;
|
||||||
use gfx::font_cache_thread::FontCacheThread;
|
use gfx::font_cache_thread::FontCacheThread;
|
||||||
|
@ -25,6 +25,8 @@ use std::marker::PhantomData;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use style::properties::style_structs::Font as FontStyleStruct;
|
use style::properties::style_structs::Font as FontStyleStruct;
|
||||||
|
use style::values::computed::font;
|
||||||
|
use style_traits::values::ToCss;
|
||||||
use webrender_api::units::RectExt as RectExt_;
|
use webrender_api::units::RectExt as RectExt_;
|
||||||
|
|
||||||
/// The canvas data stores a state machine for the current status of
|
/// The canvas data stores a state machine for the current status of
|
||||||
|
@ -1372,6 +1374,24 @@ impl RectExt for Rect<u32> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_font_kit_family(font_family: &font::SingleFontFamily) -> FamilyName {
|
||||||
|
match font_family {
|
||||||
|
font::SingleFontFamily::FamilyName(family_name) => {
|
||||||
|
FamilyName::Title(family_name.to_css_string())
|
||||||
|
},
|
||||||
|
font::SingleFontFamily::Generic(generic) => match generic {
|
||||||
|
font::GenericFontFamily::Serif => FamilyName::Serif,
|
||||||
|
font::GenericFontFamily::SansSerif => FamilyName::SansSerif,
|
||||||
|
font::GenericFontFamily::Monospace => FamilyName::Monospace,
|
||||||
|
font::GenericFontFamily::Fantasy => FamilyName::Fantasy,
|
||||||
|
font::GenericFontFamily::Cursive => FamilyName::Cursive,
|
||||||
|
font::GenericFontFamily::None => {
|
||||||
|
unreachable!("Shouldn't appear in computed values")
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn load_system_font_from_style(font_style: Option<&FontStyleStruct>) -> Font {
|
fn load_system_font_from_style(font_style: Option<&FontStyleStruct>) -> Font {
|
||||||
let mut properties = Properties::new();
|
let mut properties = Properties::new();
|
||||||
let style = match font_style {
|
let style = match font_style {
|
||||||
|
@ -1382,12 +1402,19 @@ fn load_system_font_from_style(font_style: Option<&FontStyleStruct>) -> Font {
|
||||||
.font_family
|
.font_family
|
||||||
.families
|
.families
|
||||||
.iter()
|
.iter()
|
||||||
.map(|family_name| family_name.into())
|
.map(to_font_kit_family)
|
||||||
.collect::<Vec<FamilyName>>();
|
.collect::<Vec<_>>();
|
||||||
let properties = properties
|
let properties = properties
|
||||||
.style(style.font_style.into())
|
.style(match style.font_style {
|
||||||
.weight(style.font_weight.into())
|
font::FontStyle::Normal => Style::Normal,
|
||||||
.stretch(style.font_stretch.into());
|
font::FontStyle::Italic => Style::Italic,
|
||||||
|
font::FontStyle::Oblique(..) => {
|
||||||
|
// TODO: support oblique angle.
|
||||||
|
Style::Oblique
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.weight(Weight(style.font_weight.0))
|
||||||
|
.stretch(Stretch(style.font_stretch.value()));
|
||||||
let font_handle = match SystemSource::new().select_best_match(&family_names, &properties) {
|
let font_handle = match SystemSource::new().select_best_match(&family_names, &properties) {
|
||||||
Ok(handle) => handle,
|
Ok(handle) => handle,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
|
@ -40,7 +40,6 @@ derive_more = "0.99"
|
||||||
encoding_rs = { version = "0.8", optional = true }
|
encoding_rs = { version = "0.8", optional = true }
|
||||||
euclid = "0.20"
|
euclid = "0.20"
|
||||||
fallible = { path = "../fallible" }
|
fallible = { path = "../fallible" }
|
||||||
font-kit = "0.7"
|
|
||||||
fxhash = "0.2"
|
fxhash = "0.2"
|
||||||
hashglobe = { path = "../hashglobe" }
|
hashglobe = { path = "../hashglobe" }
|
||||||
html5ever = { version = "0.25", optional = true }
|
html5ever = { version = "0.25", optional = true }
|
||||||
|
|
|
@ -40,8 +40,6 @@ extern crate debug_unreachable;
|
||||||
extern crate derive_more;
|
extern crate derive_more;
|
||||||
extern crate euclid;
|
extern crate euclid;
|
||||||
extern crate fallible;
|
extern crate fallible;
|
||||||
#[cfg(feature = "servo")]
|
|
||||||
extern crate font_kit;
|
|
||||||
extern crate fxhash;
|
extern crate fxhash;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -22,12 +22,6 @@ use crate::values::specified::length::{FontBaseSize, NoCalcLength};
|
||||||
use crate::values::CSSFloat;
|
use crate::values::CSSFloat;
|
||||||
use crate::Atom;
|
use crate::Atom;
|
||||||
use cssparser::{serialize_identifier, CssStringWriter, Parser};
|
use cssparser::{serialize_identifier, CssStringWriter, Parser};
|
||||||
#[cfg(feature = "servo")]
|
|
||||||
use font_kit::family_name::FamilyName as FontKitFamilyName;
|
|
||||||
#[cfg(feature = "servo")]
|
|
||||||
use font_kit::properties::{
|
|
||||||
Stretch as FontKitFontStretch, Style as FontKitFontStyle, Weight as FontKitFontWeight,
|
|
||||||
};
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
|
@ -75,13 +69,6 @@ impl ToAnimatedValue for FontWeight {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "servo")]
|
|
||||||
impl From<FontWeight> for FontKitFontWeight {
|
|
||||||
fn from(font_weight: FontWeight) -> Self {
|
|
||||||
FontKitFontWeight(font_weight.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Animate,
|
Animate,
|
||||||
Clone,
|
Clone,
|
||||||
|
@ -457,26 +444,6 @@ impl SingleFontFamily {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "servo")]
|
|
||||||
impl From<&SingleFontFamily> for FontKitFamilyName {
|
|
||||||
fn from(font_family: &SingleFontFamily) -> Self {
|
|
||||||
match font_family {
|
|
||||||
SingleFontFamily::FamilyName(family_name) => {
|
|
||||||
FontKitFamilyName::Title(family_name.to_css_string())
|
|
||||||
},
|
|
||||||
SingleFontFamily::Generic(GenericFontFamily::Serif) => FontKitFamilyName::Serif,
|
|
||||||
SingleFontFamily::Generic(GenericFontFamily::SansSerif) => FontKitFamilyName::SansSerif,
|
|
||||||
SingleFontFamily::Generic(GenericFontFamily::Monospace) => FontKitFamilyName::Monospace,
|
|
||||||
SingleFontFamily::Generic(GenericFontFamily::Fantasy) => FontKitFamilyName::Fantasy,
|
|
||||||
SingleFontFamily::Generic(GenericFontFamily::Cursive) => FontKitFamilyName::Cursive,
|
|
||||||
SingleFontFamily::Generic(family_name) => {
|
|
||||||
warn!("unsupported font family name: {:?}", family_name);
|
|
||||||
FontKitFamilyName::SansSerif
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone,
|
Clone,
|
||||||
|
@ -975,17 +942,6 @@ impl ToCss for FontStyle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "servo")]
|
|
||||||
impl From<FontStyle> for FontKitFontStyle {
|
|
||||||
fn from(font_style: FontStyle) -> Self {
|
|
||||||
match font_style {
|
|
||||||
FontStyle::Normal => FontKitFontStyle::Normal,
|
|
||||||
FontStyle::Italic => FontKitFontStyle::Italic,
|
|
||||||
FontStyle::Oblique(_) => FontKitFontStyle::Oblique,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A value for the font-stretch property per:
|
/// A value for the font-stretch property per:
|
||||||
///
|
///
|
||||||
/// https://drafts.csswg.org/css-fonts-4/#propdef-font-stretch
|
/// https://drafts.csswg.org/css-fonts-4/#propdef-font-stretch
|
||||||
|
@ -1008,13 +964,6 @@ impl FontStretch {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "servo")]
|
|
||||||
impl From<FontStretch> for FontKitFontStretch {
|
|
||||||
fn from(stretch: FontStretch) -> Self {
|
|
||||||
FontKitFontStretch(stretch.value())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToAnimatedValue for FontStretch {
|
impl ToAnimatedValue for FontStretch {
|
||||||
type AnimatedValue = Percentage;
|
type AnimatedValue = Percentage;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue