mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Further changes required by Servo
This commit is contained in:
parent
dcafbde256
commit
105050d46d
9 changed files with 72 additions and 88 deletions
|
@ -1412,15 +1412,15 @@ fn load_system_font_from_style(font_style: Option<&FontStyleStruct>) -> Option<F
|
|||
.collect::<Vec<_>>();
|
||||
let properties = properties
|
||||
.style(match style.font_style {
|
||||
font::FontStyle::Normal => Style::Normal,
|
||||
font::FontStyle::Italic => Style::Italic,
|
||||
font::FontStyle::Oblique(..) => {
|
||||
font::FontStyle::NORMAL => Style::Normal,
|
||||
font::FontStyle::ITALIC => Style::Italic,
|
||||
_ => {
|
||||
// TODO: support oblique angle.
|
||||
Style::Oblique
|
||||
},
|
||||
})
|
||||
.weight(Weight(style.font_weight.0))
|
||||
.stretch(Stretch(style.font_stretch.value()));
|
||||
.weight(Weight(style.font_weight.value()))
|
||||
.stretch(Stretch(style.font_stretch.to_percentage().0));
|
||||
let font_handle = match SystemSource::new().select_best_match(&family_names, &properties) {
|
||||
Ok(handle) => handle,
|
||||
Err(e) => {
|
||||
|
|
|
@ -34,12 +34,10 @@ pub struct FontTemplateDescriptor {
|
|||
impl Eq for FontTemplateDescriptor {}
|
||||
|
||||
fn style_to_number(s: &FontStyle) -> f32 {
|
||||
use style::values::generics::font::FontStyle as GenericFontStyle;
|
||||
|
||||
match *s {
|
||||
GenericFontStyle::Normal => 0.,
|
||||
GenericFontStyle::Italic => FontStyle::default_angle().0.degrees(),
|
||||
GenericFontStyle::Oblique(ref angle) => angle.0.degrees(),
|
||||
FontStyle::NORMAL => 0.,
|
||||
FontStyle::ITALIC => FontStyle::DEFAULT_OBLIQUE_DEGREES as f32,
|
||||
_ => s.oblique_degrees(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,9 +64,9 @@ impl FontTemplateDescriptor {
|
|||
// between -90 and +90deg.
|
||||
let style_part = (style_to_number(&self.style) - style_to_number(&other.style)).abs();
|
||||
// 0 <= weightPart <= 800
|
||||
let weight_part = (self.weight.0 - other.weight.0).abs();
|
||||
let weight_part = (self.weight.value() - other.weight.value()).abs();
|
||||
// 0 <= stretchPart <= 8
|
||||
let stretch_part = (self.stretch.value() - other.stretch.value()).abs();
|
||||
let stretch_part = (self.stretch.to_percentage().0 - other.stretch.to_percentage().0).abs();
|
||||
style_part + weight_part + stretch_part
|
||||
}
|
||||
}
|
||||
|
|
|
@ -186,11 +186,10 @@ impl FontHandleMethods for FontHandle {
|
|||
}
|
||||
|
||||
fn style(&self) -> FontStyle {
|
||||
use style::values::generics::font::FontStyle::*;
|
||||
if unsafe { (*self.face).style_flags & FT_STYLE_FLAG_ITALIC as c_long != 0 } {
|
||||
Italic
|
||||
FontStyle::ITALIC
|
||||
} else {
|
||||
Normal
|
||||
FontStyle::NORMAL
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,13 +199,12 @@ impl FontHandleMethods for FontHandle {
|
|||
Some(os2) => os2,
|
||||
};
|
||||
let weight = os2.us_weight_class as f32;
|
||||
FontWeight(weight.max(1.).min(1000.))
|
||||
FontWeight::from_float(weight)
|
||||
}
|
||||
|
||||
fn stretchiness(&self) -> FontStretch {
|
||||
use style::values::generics::NonNegative;
|
||||
use style::values::specified::font::FontStretchKeyword;
|
||||
let percentage = if let Some(os2) = self.os2_table() {
|
||||
if let Some(os2) = self.os2_table() {
|
||||
match os2.us_width_class {
|
||||
1 => FontStretchKeyword::UltraCondensed,
|
||||
2 => FontStretchKeyword::ExtraCondensed,
|
||||
|
@ -222,8 +220,7 @@ impl FontHandleMethods for FontHandle {
|
|||
} else {
|
||||
FontStretchKeyword::Normal
|
||||
}
|
||||
.compute();
|
||||
FontStretch(NonNegative(percentage))
|
||||
.compute()
|
||||
}
|
||||
|
||||
fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
|
||||
|
|
|
@ -207,11 +207,10 @@ impl FontHandleMethods for FontHandle {
|
|||
}
|
||||
|
||||
fn style(&self) -> FontStyle {
|
||||
use style::values::generics::font::FontStyle::*;
|
||||
if self.ctfont.symbolic_traits().is_italic() {
|
||||
Italic
|
||||
FontStyle::ITALIC
|
||||
} else {
|
||||
Normal
|
||||
FontStyle::NORMAL
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -225,15 +224,12 @@ impl FontHandleMethods for FontHandle {
|
|||
} else {
|
||||
4.0 + normalized * 5.0 // [4.0, 9.0]
|
||||
}; // [1.0, 9.0], centered on 4.0
|
||||
FontWeight(normalized as f32 * 100.)
|
||||
FontWeight::from_float(normalized as f32 * 100.)
|
||||
}
|
||||
|
||||
fn stretchiness(&self) -> FontStretch {
|
||||
use style::values::computed::Percentage;
|
||||
use style::values::generics::NonNegative;
|
||||
|
||||
let normalized = self.ctfont.all_traits().normalized_width(); // [-1.0, 1.0]
|
||||
FontStretch(NonNegative(Percentage(normalized as f32 + 1.0)))
|
||||
FontStretch::from_percentage(normalized as f32 + 1.0)
|
||||
}
|
||||
|
||||
fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
|
||||
|
|
|
@ -17,8 +17,6 @@ use servo_atoms::Atom;
|
|||
use style::computed_values::font_stretch::T as StyleFontStretch;
|
||||
use style::computed_values::font_weight::T as StyleFontWeight;
|
||||
use style::values::computed::font::FontStyle as StyleFontStyle;
|
||||
use style::values::generics::font::FontStyle as GenericFontStyle;
|
||||
use style::values::generics::NonNegative;
|
||||
use style::values::specified::font::FontStretchKeyword;
|
||||
|
||||
use crate::font::{
|
||||
|
@ -140,28 +138,26 @@ impl FontInfo {
|
|||
},
|
||||
};
|
||||
|
||||
let weight = StyleFontWeight(weight_val as f32);
|
||||
let weight = StyleFontWeight::from_float(weight_val as f32);
|
||||
|
||||
let stretch = StyleFontStretch(NonNegative(
|
||||
match min(9, max(1, width_val)) {
|
||||
1 => FontStretchKeyword::UltraCondensed,
|
||||
2 => FontStretchKeyword::ExtraCondensed,
|
||||
3 => FontStretchKeyword::Condensed,
|
||||
4 => FontStretchKeyword::SemiCondensed,
|
||||
5 => FontStretchKeyword::Normal,
|
||||
6 => FontStretchKeyword::SemiExpanded,
|
||||
7 => FontStretchKeyword::Expanded,
|
||||
8 => FontStretchKeyword::ExtraExpanded,
|
||||
9 => FontStretchKeyword::UltraExpanded,
|
||||
_ => return Err(()),
|
||||
}
|
||||
.compute(),
|
||||
));
|
||||
let stretch = match min(9, max(1, width_val)) {
|
||||
1 => FontStretchKeyword::UltraCondensed,
|
||||
2 => FontStretchKeyword::ExtraCondensed,
|
||||
3 => FontStretchKeyword::Condensed,
|
||||
4 => FontStretchKeyword::SemiCondensed,
|
||||
5 => FontStretchKeyword::Normal,
|
||||
6 => FontStretchKeyword::SemiExpanded,
|
||||
7 => FontStretchKeyword::Expanded,
|
||||
8 => FontStretchKeyword::ExtraExpanded,
|
||||
9 => FontStretchKeyword::UltraExpanded,
|
||||
_ => return Err(()),
|
||||
}
|
||||
.compute();
|
||||
|
||||
let style = if italic_bool {
|
||||
GenericFontStyle::Italic
|
||||
StyleFontStyle::ITALIC
|
||||
} else {
|
||||
GenericFontStyle::Normal
|
||||
StyleFontStyle::NORMAL
|
||||
};
|
||||
|
||||
Ok(FontInfo {
|
||||
|
@ -175,26 +171,24 @@ impl FontInfo {
|
|||
|
||||
fn new_from_font(font: &Font) -> Result<FontInfo, ()> {
|
||||
let style = match font.style() {
|
||||
FontStyle::Normal => GenericFontStyle::Normal,
|
||||
FontStyle::Oblique => GenericFontStyle::Oblique(StyleFontStyle::default_angle()),
|
||||
FontStyle::Italic => GenericFontStyle::Italic,
|
||||
FontStyle::Normal => StyleFontStyle::NORMAL,
|
||||
FontStyle::Oblique => StyleFontStyle::OBLIQUE,
|
||||
FontStyle::Italic => StyleFontStyle::ITALIC,
|
||||
};
|
||||
let weight = StyleFontWeight(font.weight().to_u32() as f32);
|
||||
let stretch = StyleFontStretch(NonNegative(
|
||||
match font.stretch() {
|
||||
FontStretch::Undefined => FontStretchKeyword::Normal,
|
||||
FontStretch::UltraCondensed => FontStretchKeyword::UltraCondensed,
|
||||
FontStretch::ExtraCondensed => FontStretchKeyword::ExtraCondensed,
|
||||
FontStretch::Condensed => FontStretchKeyword::Condensed,
|
||||
FontStretch::SemiCondensed => FontStretchKeyword::SemiCondensed,
|
||||
FontStretch::Normal => FontStretchKeyword::Normal,
|
||||
FontStretch::SemiExpanded => FontStretchKeyword::SemiExpanded,
|
||||
FontStretch::Expanded => FontStretchKeyword::Expanded,
|
||||
FontStretch::ExtraExpanded => FontStretchKeyword::ExtraExpanded,
|
||||
FontStretch::UltraExpanded => FontStretchKeyword::UltraExpanded,
|
||||
}
|
||||
.compute(),
|
||||
));
|
||||
let weight = StyleFontWeight::from_float(font.weight().to_u32() as f32);
|
||||
let stretch = match font.stretch() {
|
||||
FontStretch::Undefined => FontStretchKeyword::Normal,
|
||||
FontStretch::UltraCondensed => FontStretchKeyword::UltraCondensed,
|
||||
FontStretch::ExtraCondensed => FontStretchKeyword::ExtraCondensed,
|
||||
FontStretch::Condensed => FontStretchKeyword::Condensed,
|
||||
FontStretch::SemiCondensed => FontStretchKeyword::SemiCondensed,
|
||||
FontStretch::Normal => FontStretchKeyword::Normal,
|
||||
FontStretch::SemiExpanded => FontStretchKeyword::SemiExpanded,
|
||||
FontStretch::Expanded => FontStretchKeyword::Expanded,
|
||||
FontStretch::ExtraExpanded => FontStretchKeyword::ExtraExpanded,
|
||||
FontStretch::UltraExpanded => FontStretchKeyword::UltraExpanded,
|
||||
}
|
||||
.compute();
|
||||
|
||||
Ok(FontInfo {
|
||||
family_name: font.family_name(),
|
||||
|
|
|
@ -21,10 +21,9 @@ use servo_atoms::Atom;
|
|||
use style::properties::longhands::font_variant_caps::computed_value::T as FontVariantCaps;
|
||||
use style::properties::style_structs::Font as FontStyleStruct;
|
||||
use style::values::computed::font::{
|
||||
FamilyName, FontFamily, FontFamilyList, FontFamilyNameSyntax, FontSize, FontStretch,
|
||||
FamilyName, FontFamily, FontFamilyList, FontFamilyNameSyntax, FontSize, FontStretch, FontStyle,
|
||||
FontWeight, SingleFontFamily,
|
||||
};
|
||||
use style::values::generics::font::FontStyle;
|
||||
use webrender_api::{FontInstanceKey, FontKey, IdNamespace};
|
||||
|
||||
struct TestFontSource {
|
||||
|
@ -95,7 +94,7 @@ impl FontSource for TestFontSource {
|
|||
fn style() -> FontStyleStruct {
|
||||
let mut style = FontStyleStruct {
|
||||
font_family: FontFamily::serif(),
|
||||
font_style: FontStyle::Normal,
|
||||
font_style: FontStyle::NORMAL,
|
||||
font_variant_caps: FontVariantCaps::Normal,
|
||||
font_weight: FontWeight::normal(),
|
||||
font_size: FontSize::medium(),
|
||||
|
@ -134,7 +133,7 @@ fn test_font_group_is_cached_by_style() {
|
|||
let style1 = style();
|
||||
|
||||
let mut style2 = style();
|
||||
style2.set_font_style(FontStyle::Italic);
|
||||
style2.set_font_style(FontStyle::ITALIC);
|
||||
|
||||
assert_eq!(
|
||||
context.font_group(Arc::new(style1.clone())).as_ptr(),
|
||||
|
@ -231,7 +230,7 @@ fn test_font_template_is_cached() {
|
|||
template_descriptor: FontTemplateDescriptor {
|
||||
weight: FontWeight::normal(),
|
||||
stretch: FontStretch::hundred(),
|
||||
style: FontStyle::Normal,
|
||||
style: FontStyle::normal(),
|
||||
},
|
||||
variant: FontVariantCaps::Normal,
|
||||
pt_size: Au(10),
|
||||
|
|
|
@ -13,10 +13,7 @@ fn test_font_template_descriptor() {
|
|||
use gfx::font_context::FontContextHandle;
|
||||
use gfx::font_template::{FontTemplate, FontTemplateDescriptor};
|
||||
use servo_atoms::Atom;
|
||||
use style::values::computed::font::{FontStretch, FontWeight};
|
||||
use style::values::computed::Percentage;
|
||||
use style::values::generics::font::FontStyle;
|
||||
use style::values::generics::NonNegative;
|
||||
use style::values::computed::font::{FontStretch, FontStyle, FontWeight};
|
||||
|
||||
fn descriptor(filename: &str) -> FontTemplateDescriptor {
|
||||
let mut path: PathBuf = [
|
||||
|
@ -46,36 +43,36 @@ fn test_font_template_descriptor() {
|
|||
assert_eq!(
|
||||
descriptor("DejaVuSans"),
|
||||
FontTemplateDescriptor {
|
||||
weight: FontWeight::normal(),
|
||||
weight: FontWeight::NORMAL,
|
||||
stretch: FontStretch::hundred(),
|
||||
style: FontStyle::Normal,
|
||||
style: FontStyle::NORMAL,
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
descriptor("DejaVuSans-Bold"),
|
||||
FontTemplateDescriptor {
|
||||
weight: FontWeight::bold(),
|
||||
weight: FontWeight::BOLD,
|
||||
stretch: FontStretch::hundred(),
|
||||
style: FontStyle::Normal,
|
||||
style: FontStyle::NORMAL,
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
descriptor("DejaVuSans-Oblique"),
|
||||
FontTemplateDescriptor {
|
||||
weight: FontWeight::normal(),
|
||||
weight: FontWeight::NORMAL,
|
||||
stretch: FontStretch::hundred(),
|
||||
style: FontStyle::Italic,
|
||||
style: FontStyle::ITALIC,
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
descriptor("DejaVuSansCondensed-BoldOblique"),
|
||||
FontTemplateDescriptor {
|
||||
weight: FontWeight::bold(),
|
||||
stretch: FontStretch(NonNegative(Percentage(0.875))),
|
||||
style: FontStyle::Italic,
|
||||
weight: FontWeight::BOLD,
|
||||
stretch: FontStretch::from_percentage(0.875),
|
||||
style: FontStyle::ITALIC,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1779,7 +1779,7 @@ fn serialize_font<W>(style: &Font, dest: &mut W) -> fmt::Result
|
|||
where
|
||||
W: fmt::Write,
|
||||
{
|
||||
if style.font_style == FontStyle::Italic {
|
||||
if style.font_style == FontStyle::ITALIC {
|
||||
write!(dest, "{} ", style.font_style.to_css_string())?;
|
||||
}
|
||||
if style.font_weight.is_bold() {
|
||||
|
|
|
@ -48,8 +48,9 @@ pub use crate::values::specified::Integer as SpecifiedInteger;
|
|||
/// cbindgen:derive-gte
|
||||
#[repr(C)]
|
||||
#[derive(
|
||||
Clone, ComputeSquaredDistance, Copy, Debug, Hash, MallocSizeOf, PartialEq, PartialOrd, ToResolvedValue,
|
||||
Clone, ComputeSquaredDistance, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, PartialOrd, ToResolvedValue,
|
||||
)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
pub struct FixedPoint<T, const FRACTION_BITS: u16> {
|
||||
value: T,
|
||||
}
|
||||
|
@ -901,8 +902,9 @@ pub type FontStyleFixedPoint = FixedPoint<i16, FONT_STYLE_FRACTION_BITS>;
|
|||
/// cbindgen:derive-gt
|
||||
/// cbindgen:derive-gte
|
||||
#[derive(
|
||||
Clone, ComputeSquaredDistance, Copy, Debug, Hash, MallocSizeOf, PartialEq, PartialOrd, ToResolvedValue,
|
||||
Clone, ComputeSquaredDistance, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, PartialOrd, ToResolvedValue,
|
||||
)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[repr(C)]
|
||||
pub struct FontStyle(FontStyleFixedPoint);
|
||||
|
||||
|
@ -1012,6 +1014,7 @@ pub type FontStretchFixedPoint = FixedPoint<u16, FONT_STRETCH_FRACTION_BITS>;
|
|||
#[derive(
|
||||
Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf, PartialEq, PartialOrd, ToResolvedValue,
|
||||
)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Hash, Serialize))]
|
||||
#[repr(C)]
|
||||
pub struct FontStretch(pub FontStretchFixedPoint);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue