mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Fix servo build.
This commit is contained in:
parent
16ca8de6df
commit
54b444992d
13 changed files with 148 additions and 143 deletions
|
@ -19,7 +19,7 @@ use std::rc::Rc;
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering};
|
use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering};
|
||||||
use style::computed_values::{font_stretch, font_variant_caps, font_weight};
|
use style::computed_values::{font_stretch, font_style, font_variant_caps, font_weight};
|
||||||
use style::properties::style_structs::Font as FontStyleStruct;
|
use style::properties::style_structs::Font as FontStyleStruct;
|
||||||
use style::values::computed::font::SingleFontFamily;
|
use style::values::computed::font::SingleFontFamily;
|
||||||
use text::Shaper;
|
use text::Shaper;
|
||||||
|
@ -47,18 +47,24 @@ static TEXT_SHAPING_PERFORMANCE_COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||||
// resources needed by the graphics layer to draw glyphs.
|
// resources needed by the graphics layer to draw glyphs.
|
||||||
|
|
||||||
pub trait FontHandleMethods: Sized {
|
pub trait FontHandleMethods: Sized {
|
||||||
fn new_from_template(fctx: &FontContextHandle, template: Arc<FontTemplateData>, pt_size: Option<Au>)
|
fn new_from_template(
|
||||||
-> Result<Self, ()>;
|
fctx: &FontContextHandle,
|
||||||
|
template: Arc<FontTemplateData>,
|
||||||
|
pt_size: Option<Au>,
|
||||||
|
) -> Result<Self, ()>;
|
||||||
|
|
||||||
fn template(&self) -> Arc<FontTemplateData>;
|
fn template(&self) -> Arc<FontTemplateData>;
|
||||||
fn family_name(&self) -> String;
|
fn family_name(&self) -> String;
|
||||||
fn face_name(&self) -> Option<String>;
|
fn face_name(&self) -> Option<String>;
|
||||||
fn is_italic(&self) -> bool;
|
|
||||||
|
fn style(&self) -> font_style::T;
|
||||||
fn boldness(&self) -> font_weight::T;
|
fn boldness(&self) -> font_weight::T;
|
||||||
fn stretchiness(&self) -> font_stretch::T;
|
fn stretchiness(&self) -> font_stretch::T;
|
||||||
|
|
||||||
fn glyph_index(&self, codepoint: char) -> Option<GlyphId>;
|
fn glyph_index(&self, codepoint: char) -> Option<GlyphId>;
|
||||||
fn glyph_h_advance(&self, GlyphId) -> Option<FractionalPixel>;
|
fn glyph_h_advance(&self, GlyphId) -> Option<FractionalPixel>;
|
||||||
fn glyph_h_kerning(&self, glyph0: GlyphId, glyph1: GlyphId) -> FractionalPixel;
|
fn glyph_h_kerning(&self, glyph0: GlyphId, glyph1: GlyphId) -> FractionalPixel;
|
||||||
|
|
||||||
/// Can this font do basic horizontal LTR shaping without Harfbuzz?
|
/// Can this font do basic horizontal LTR shaping without Harfbuzz?
|
||||||
fn can_do_fast_shaping(&self) -> bool;
|
fn can_do_fast_shaping(&self) -> bool;
|
||||||
fn metrics(&self) -> FontMetrics;
|
fn metrics(&self) -> FontMetrics;
|
||||||
|
|
|
@ -18,14 +18,11 @@ use platform::font_list::system_default_family;
|
||||||
use platform::font_template::FontTemplateData;
|
use platform::font_template::FontTemplateData;
|
||||||
use servo_atoms::Atom;
|
use servo_atoms::Atom;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
|
use std::{fmt, f32, mem, thread};
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt;
|
|
||||||
use std::mem;
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::thread;
|
|
||||||
use std::u32;
|
|
||||||
use style::font_face::{EffectiveSources, Source};
|
use style::font_face::{EffectiveSources, Source};
|
||||||
use style::values::computed::font::{SingleFontFamily, FamilyName};
|
use style::values::computed::font::{SingleFontFamily, FamilyName};
|
||||||
use webrender_api;
|
use webrender_api;
|
||||||
|
@ -63,7 +60,7 @@ impl FontTemplates {
|
||||||
|
|
||||||
// We didn't find an exact match. Do more expensive fuzzy matching.
|
// We didn't find an exact match. Do more expensive fuzzy matching.
|
||||||
// TODO(#190): Do a better job.
|
// TODO(#190): Do a better job.
|
||||||
let (mut best_template_data, mut best_distance) = (None, u32::MAX);
|
let (mut best_template_data, mut best_distance) = (None, f32::MAX);
|
||||||
for template in &mut self.templates {
|
for template in &mut self.templates {
|
||||||
if let Some((template_data, distance)) =
|
if let Some((template_data, distance)) =
|
||||||
template.data_for_approximate_descriptor(fctx, desc) {
|
template.data_for_approximate_descriptor(fctx, desc) {
|
||||||
|
|
|
@ -10,7 +10,6 @@ use servo_atoms::Atom;
|
||||||
use std::fmt::{Debug, Error, Formatter};
|
use std::fmt::{Debug, Error, Formatter};
|
||||||
use std::io::Error as IoError;
|
use std::io::Error as IoError;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::u32;
|
|
||||||
use style::computed_values::font_stretch::T as FontStretch;
|
use style::computed_values::font_stretch::T as FontStretch;
|
||||||
use style::computed_values::font_style::T as FontStyle;
|
use style::computed_values::font_style::T as FontStyle;
|
||||||
use style::properties::style_structs::Font as FontStyleStruct;
|
use style::properties::style_structs::Font as FontStyleStruct;
|
||||||
|
@ -20,24 +19,35 @@ use style::values::computed::font::FontWeight;
|
||||||
/// to be expanded or refactored when we support more of the font styling parameters.
|
/// to be expanded or refactored when we support more of the font styling parameters.
|
||||||
///
|
///
|
||||||
/// NB: If you change this, you will need to update `style::properties::compute_font_hash()`.
|
/// NB: If you change this, you will need to update `style::properties::compute_font_hash()`.
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
pub struct FontTemplateDescriptor {
|
pub struct FontTemplateDescriptor {
|
||||||
pub weight: FontWeight,
|
pub weight: FontWeight,
|
||||||
pub stretch: FontStretch,
|
pub stretch: FontStretch,
|
||||||
pub italic: bool,
|
pub style: FontStyle,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
impl FontTemplateDescriptor {
|
impl FontTemplateDescriptor {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
weight: FontWeight,
|
weight: FontWeight,
|
||||||
stretch: FontStretch,
|
stretch: FontStretch,
|
||||||
italic: bool,
|
style: FontStyle,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
weight,
|
weight,
|
||||||
stretch,
|
stretch,
|
||||||
italic,
|
style,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,30 +59,15 @@ impl FontTemplateDescriptor {
|
||||||
///
|
///
|
||||||
/// The policy is to care most about differences in italicness, then weight, then stretch
|
/// The policy is to care most about differences in italicness, then weight, then stretch
|
||||||
#[inline]
|
#[inline]
|
||||||
fn distance_from(&self, other: &FontTemplateDescriptor) -> u32 {
|
fn distance_from(&self, other: &FontTemplateDescriptor) -> f32 {
|
||||||
let italic_part = if self.italic == other.italic { 0 } else { 1000 };
|
// 0 <= style_part <= 180, since font-style obliqueness should be
|
||||||
|
// between -90 and +90deg.
|
||||||
|
let style_part = (style_to_number(&self.style) - style_to_number(&other.style)).abs();
|
||||||
// 0 <= weightPart <= 800
|
// 0 <= weightPart <= 800
|
||||||
let weight_part = ((self.weight.0 as i16) - (other.weight.0 as i16)).abs() as u32;
|
let weight_part = (self.weight.0 - other.weight.0).abs();
|
||||||
// 0 <= stretchPart <= 8
|
// 0 <= stretchPart <= 8
|
||||||
let stretch_part = (self.stretch_number() - other.stretch_number()).abs() as u32;
|
let stretch_part = ((self.stretch.0).0 - (other.stretch.0).0).abs();
|
||||||
italic_part + weight_part + stretch_part
|
style_part + weight_part + stretch_part
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a number between 1 and 9 for the stretch property.
|
|
||||||
/// 1 is ultra_condensed, 5 is normal, and 9 is ultra_expanded
|
|
||||||
#[inline]
|
|
||||||
fn stretch_number(&self) -> i32 {
|
|
||||||
match self.stretch {
|
|
||||||
FontStretch::UltraCondensed => 1,
|
|
||||||
FontStretch::ExtraCondensed => 2,
|
|
||||||
FontStretch::Condensed => 3,
|
|
||||||
FontStretch::SemiCondensed => 4,
|
|
||||||
FontStretch::Normal => 5,
|
|
||||||
FontStretch::SemiExpanded => 6,
|
|
||||||
FontStretch::Expanded => 7,
|
|
||||||
FontStretch::ExtraExpanded => 8,
|
|
||||||
FontStretch::UltraExpanded => 9,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,17 +76,11 @@ impl<'a> From<&'a FontStyleStruct> for FontTemplateDescriptor {
|
||||||
FontTemplateDescriptor {
|
FontTemplateDescriptor {
|
||||||
weight: style.font_weight,
|
weight: style.font_weight,
|
||||||
stretch: style.font_stretch,
|
stretch: style.font_stretch,
|
||||||
italic: style.font_style == FontStyle::Italic || style.font_style == FontStyle::Oblique,
|
style: style.font_style,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for FontTemplateDescriptor {
|
|
||||||
fn eq(&self, other: &FontTemplateDescriptor) -> bool {
|
|
||||||
self.weight == other.weight && self.stretch == other.stretch && self.italic == other.italic
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This describes all the information needed to create
|
/// This describes all the information needed to create
|
||||||
/// font instance handles. It contains a unique
|
/// font instance handles. It contains a unique
|
||||||
/// FontTemplateData structure that is platform specific.
|
/// FontTemplateData structure that is platform specific.
|
||||||
|
@ -176,10 +165,11 @@ impl FontTemplate {
|
||||||
|
|
||||||
/// Returns the font data along with the distance between this font's descriptor and the given
|
/// Returns the font data along with the distance between this font's descriptor and the given
|
||||||
/// descriptor, if the font can be loaded.
|
/// descriptor, if the font can be loaded.
|
||||||
pub fn data_for_approximate_descriptor(&mut self,
|
pub fn data_for_approximate_descriptor(
|
||||||
font_context: &FontContextHandle,
|
&mut self,
|
||||||
requested_descriptor: &FontTemplateDescriptor)
|
font_context: &FontContextHandle,
|
||||||
-> Option<(Arc<FontTemplateData>, u32)> {
|
requested_descriptor: &FontTemplateDescriptor,
|
||||||
|
) -> Option<(Arc<FontTemplateData>, f32)> {
|
||||||
self.descriptor(&font_context).and_then(|descriptor| {
|
self.descriptor(&font_context).and_then(|descriptor| {
|
||||||
self.data().ok().map(|data| {
|
self.data().ok().map(|data| {
|
||||||
(data, descriptor.distance_from(requested_descriptor))
|
(data, descriptor.distance_from(requested_descriptor))
|
||||||
|
@ -198,9 +188,11 @@ impl FontTemplate {
|
||||||
None);
|
None);
|
||||||
self.is_valid = handle.is_ok();
|
self.is_valid = handle.is_ok();
|
||||||
let handle = handle?;
|
let handle = handle?;
|
||||||
self.descriptor = Some(FontTemplateDescriptor::new(handle.boldness(),
|
self.descriptor = Some(FontTemplateDescriptor::new(
|
||||||
handle.stretchiness(),
|
handle.boldness(),
|
||||||
handle.is_italic()));
|
handle.stretchiness(),
|
||||||
|
handle.style(),
|
||||||
|
));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ use std::os::raw::{c_char, c_long};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use style::computed_values::font_stretch::T as FontStretch;
|
use style::computed_values::font_stretch::T as FontStretch;
|
||||||
use style::computed_values::font_weight::T as FontWeight;
|
use style::computed_values::font_weight::T as FontWeight;
|
||||||
|
use style::values::computed::font::FontStyle;
|
||||||
use super::c_str_to_string;
|
use super::c_str_to_string;
|
||||||
use text::glyph::GlyphId;
|
use text::glyph::GlyphId;
|
||||||
use text::util::fixed_to_float;
|
use text::util::fixed_to_float;
|
||||||
|
@ -149,8 +150,13 @@ impl FontHandleMethods for FontHandle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_italic(&self) -> bool {
|
fn style(&self) -> FontStyle {
|
||||||
unsafe { (*self.face).style_flags & FT_STYLE_FLAG_ITALIC as c_long != 0 }
|
use style::values::generics::font::FontStyle::*;
|
||||||
|
if unsafe { (*self.face).style_flags & FT_STYLE_FLAG_ITALIC as c_long != 0 } {
|
||||||
|
Italic
|
||||||
|
} else {
|
||||||
|
Normal
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn boldness(&self) -> FontWeight {
|
fn boldness(&self) -> FontWeight {
|
||||||
|
@ -163,22 +169,25 @@ impl FontHandleMethods for FontHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stretchiness(&self) -> FontStretch {
|
fn stretchiness(&self) -> FontStretch {
|
||||||
if let Some(os2) = self.os2_table() {
|
use style::values::generics::NonNegative;
|
||||||
|
use style::values::specified::font::FontStretchKeyword;
|
||||||
|
let percentage = if let Some(os2) = self.os2_table() {
|
||||||
match os2.us_width_class {
|
match os2.us_width_class {
|
||||||
1 => FontStretch::UltraCondensed,
|
1 => FontStretchKeyword::UltraCondensed,
|
||||||
2 => FontStretch::ExtraCondensed,
|
2 => FontStretchKeyword::ExtraCondensed,
|
||||||
3 => FontStretch::Condensed,
|
3 => FontStretchKeyword::Condensed,
|
||||||
4 => FontStretch::SemiCondensed,
|
4 => FontStretchKeyword::SemiCondensed,
|
||||||
5 => FontStretch::Normal,
|
5 => FontStretchKeyword::Normal,
|
||||||
6 => FontStretch::SemiExpanded,
|
6 => FontStretchKeyword::SemiExpanded,
|
||||||
7 => FontStretch::Expanded,
|
7 => FontStretchKeyword::Expanded,
|
||||||
8 => FontStretch::ExtraExpanded,
|
8 => FontStretchKeyword::ExtraExpanded,
|
||||||
9 => FontStretch::UltraExpanded,
|
9 => FontStretchKeyword::UltraExpanded,
|
||||||
_ => FontStretch::Normal
|
_ => FontStretchKeyword::Normal
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
FontStretch::Normal
|
FontStretchKeyword::Normal
|
||||||
}
|
}.compute();
|
||||||
|
NonNegative(percentage)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
|
fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
|
||||||
|
|
|
@ -22,8 +22,7 @@ use servo_atoms::Atom;
|
||||||
use std::{fmt, ptr};
|
use std::{fmt, ptr};
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use style::computed_values::font_stretch::T as FontStretch;
|
use style::values::computed::font::{FontStretch, FontStyle, FontWeight};
|
||||||
use style::computed_values::font_weight::T as FontWeight;
|
|
||||||
use text::glyph::GlyphId;
|
use text::glyph::GlyphId;
|
||||||
|
|
||||||
const KERN_PAIR_LEN: usize = 6;
|
const KERN_PAIR_LEN: usize = 6;
|
||||||
|
@ -204,8 +203,13 @@ impl FontHandleMethods for FontHandle {
|
||||||
Some(self.ctfont.face_name())
|
Some(self.ctfont.face_name())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_italic(&self) -> bool {
|
fn style(&self) -> FontStyle {
|
||||||
self.ctfont.symbolic_traits().is_italic()
|
use style::values::generics::font::FontStyle::*;
|
||||||
|
if self.ctfont.symbolic_traits().is_italic() {
|
||||||
|
Italic
|
||||||
|
} else {
|
||||||
|
Normal
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn boldness(&self) -> FontWeight {
|
fn boldness(&self) -> FontWeight {
|
||||||
|
@ -221,19 +225,11 @@ impl FontHandleMethods for FontHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stretchiness(&self) -> FontStretch {
|
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]
|
let normalized = self.ctfont.all_traits().normalized_width(); // [-1.0, 1.0]
|
||||||
let normalized = (normalized + 1.0) / 2.0 * 9.0; // [0.0, 9.0]
|
NonNegative(Percentage(normalized as f32 + 1.0))
|
||||||
match normalized {
|
|
||||||
v if v < 1.0 => FontStretch::UltraCondensed,
|
|
||||||
v if v < 2.0 => FontStretch::ExtraCondensed,
|
|
||||||
v if v < 3.0 => FontStretch::Condensed,
|
|
||||||
v if v < 4.0 => FontStretch::SemiCondensed,
|
|
||||||
v if v < 5.0 => FontStretch::Normal,
|
|
||||||
v if v < 6.0 => FontStretch::SemiExpanded,
|
|
||||||
v if v < 7.0 => FontStretch::Expanded,
|
|
||||||
v if v < 8.0 => FontStretch::ExtraExpanded,
|
|
||||||
_ => FontStretch::UltraExpanded,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
|
fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
|
||||||
|
|
|
@ -19,6 +19,10 @@ use servo_atoms::Atom;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use style::computed_values::font_stretch::T as StyleFontStretch;
|
use style::computed_values::font_stretch::T as StyleFontStretch;
|
||||||
use style::computed_values::font_weight::T as StyleFontWeight;
|
use style::computed_values::font_weight::T as StyleFontWeight;
|
||||||
|
use style::values::computed::font::FontStyle as StyleFontStyle;
|
||||||
|
use style::values::generics::NonNegative;
|
||||||
|
use style::values::generics::font::FontStyle as GenericFontStyle;
|
||||||
|
use style::values::specified::font::FontStretchKeyword;
|
||||||
use text::glyph::GlyphId;
|
use text::glyph::GlyphId;
|
||||||
use truetype;
|
use truetype;
|
||||||
|
|
||||||
|
@ -98,7 +102,7 @@ struct FontInfo {
|
||||||
face_name: String,
|
face_name: String,
|
||||||
weight: StyleFontWeight,
|
weight: StyleFontWeight,
|
||||||
stretch: StyleFontStretch,
|
stretch: StyleFontStretch,
|
||||||
style: FontStyle,
|
style: StyleFontStyle,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FontInfo {
|
impl FontInfo {
|
||||||
|
@ -159,23 +163,23 @@ impl FontInfo {
|
||||||
|
|
||||||
let weight = StyleFontWeight(weight_val as f32);
|
let weight = StyleFontWeight(weight_val as f32);
|
||||||
|
|
||||||
let stretch = match min(9, max(1, width_val)) {
|
let stretch = NonNegative(match min(9, max(1, width_val)) {
|
||||||
1 => StyleFontStretch::UltraCondensed,
|
1 => FontStretchKeyword::UltraCondensed,
|
||||||
2 => StyleFontStretch::ExtraCondensed,
|
2 => FontStretchKeyword::ExtraCondensed,
|
||||||
3 => StyleFontStretch::Condensed,
|
3 => FontStretchKeyword::Condensed,
|
||||||
4 => StyleFontStretch::SemiCondensed,
|
4 => FontStretchKeyword::SemiCondensed,
|
||||||
5 => StyleFontStretch::Normal,
|
5 => FontStretchKeyword::Normal,
|
||||||
6 => StyleFontStretch::SemiExpanded,
|
6 => FontStretchKeyword::SemiExpanded,
|
||||||
7 => StyleFontStretch::Expanded,
|
7 => FontStretchKeyword::Expanded,
|
||||||
8 => StyleFontStretch::ExtraExpanded,
|
8 => FontStretchKeyword::ExtraExpanded,
|
||||||
9 => StyleFontStretch::UltraExpanded,
|
9 => FontStretchKeyword::UltraExpanded,
|
||||||
_ => return Err(()),
|
_ => return Err(()),
|
||||||
};
|
}.compute());
|
||||||
|
|
||||||
let style = if italic_bool {
|
let style = if italic_bool {
|
||||||
FontStyle::Italic
|
GenericFontStyle::Italic
|
||||||
} else {
|
} else {
|
||||||
FontStyle::Normal
|
GenericFontStyle::Normal
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(FontInfo {
|
Ok(FontInfo {
|
||||||
|
@ -188,7 +192,11 @@ impl FontInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_from_font(font: &Font) -> Result<FontInfo, ()> {
|
fn new_from_font(font: &Font) -> Result<FontInfo, ()> {
|
||||||
let style = font.style();
|
let style = match font.style() {
|
||||||
|
FontStyle::Normal => GenericFontStyle::Normal,
|
||||||
|
FontStyle::Oblique => GenericFontStyle::Oblique(StyleFontStyle::default_angle()),
|
||||||
|
FontStyle::Italic => GenericFontStyle::Italic,
|
||||||
|
};
|
||||||
let weight = StyleFontWeight(match font.weight() {
|
let weight = StyleFontWeight(match font.weight() {
|
||||||
FontWeight::Thin => 100.,
|
FontWeight::Thin => 100.,
|
||||||
FontWeight::ExtraLight => 200.,
|
FontWeight::ExtraLight => 200.,
|
||||||
|
@ -204,18 +212,18 @@ impl FontInfo {
|
||||||
// slightly blacker black
|
// slightly blacker black
|
||||||
FontWeight::ExtraBlack => 1000.,
|
FontWeight::ExtraBlack => 1000.,
|
||||||
});
|
});
|
||||||
let stretch = match font.stretch() {
|
let stretch = NonNegative(match font.stretch() {
|
||||||
FontStretch::Undefined => StyleFontStretch::Normal,
|
FontStretch::Undefined => FontStretchKeyword::Normal,
|
||||||
FontStretch::UltraCondensed => StyleFontStretch::UltraCondensed,
|
FontStretch::UltraCondensed => FontStretchKeyword::UltraCondensed,
|
||||||
FontStretch::ExtraCondensed => StyleFontStretch::ExtraCondensed,
|
FontStretch::ExtraCondensed => FontStretchKeyword::ExtraCondensed,
|
||||||
FontStretch::Condensed => StyleFontStretch::Condensed,
|
FontStretch::Condensed => FontStretchKeyword::Condensed,
|
||||||
FontStretch::SemiCondensed => StyleFontStretch::SemiCondensed,
|
FontStretch::SemiCondensed => FontStretchKeyword::SemiCondensed,
|
||||||
FontStretch::Normal => StyleFontStretch::Normal,
|
FontStretch::Normal => FontStretchKeyword::Normal,
|
||||||
FontStretch::SemiExpanded => StyleFontStretch::SemiExpanded,
|
FontStretch::SemiExpanded => FontStretchKeyword::SemiExpanded,
|
||||||
FontStretch::Expanded => StyleFontStretch::Expanded,
|
FontStretch::Expanded => FontStretchKeyword::Expanded,
|
||||||
FontStretch::ExtraExpanded => StyleFontStretch::ExtraExpanded,
|
FontStretch::ExtraExpanded => FontStretchKeyword::ExtraExpanded,
|
||||||
FontStretch::UltraExpanded => StyleFontStretch::UltraExpanded,
|
FontStretch::UltraExpanded => FontStretchKeyword::UltraExpanded,
|
||||||
};
|
}.compute());
|
||||||
|
|
||||||
Ok(FontInfo {
|
Ok(FontInfo {
|
||||||
family_name: font.family_name(),
|
family_name: font.family_name(),
|
||||||
|
@ -294,11 +302,8 @@ impl FontHandleMethods for FontHandle {
|
||||||
Some(self.info.face_name.clone())
|
Some(self.info.face_name.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_italic(&self) -> bool {
|
fn style(&self) -> StyleFontStyle {
|
||||||
match self.info.style {
|
self.info.style
|
||||||
FontStyle::Normal => false,
|
|
||||||
FontStyle::Oblique | FontStyle::Italic => true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn boldness(&self) -> StyleFontWeight {
|
fn boldness(&self) -> StyleFontWeight {
|
||||||
|
|
|
@ -22,12 +22,13 @@ use std::fs::File;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use style::properties::longhands::font_stretch::computed_value::T as FontStretch;
|
|
||||||
use style::properties::longhands::font_style::computed_value::T as FontStyle;
|
|
||||||
use style::properties::longhands::font_variant_caps::computed_value::T as FontVariantCaps;
|
use style::properties::longhands::font_variant_caps::computed_value::T as FontVariantCaps;
|
||||||
use style::properties::style_structs::Font as FontStyleStruct;
|
use style::properties::style_structs::Font as FontStyleStruct;
|
||||||
|
use style::values::computed::Percentage;
|
||||||
use style::values::computed::font::{FamilyName, FamilyNameSyntax, FontFamily, FontFamilyList, FontSize};
|
use style::values::computed::font::{FamilyName, FamilyNameSyntax, FontFamily, FontFamilyList, FontSize};
|
||||||
use style::values::computed::font::{FontWeight, SingleFontFamily};
|
use style::values::computed::font::{FontWeight, SingleFontFamily};
|
||||||
|
use style::values::generics::NonNegative;
|
||||||
|
use style::values::generics::font::FontStyle;
|
||||||
|
|
||||||
struct TestFontSource {
|
struct TestFontSource {
|
||||||
handle: FontContextHandle,
|
handle: FontContextHandle,
|
||||||
|
@ -108,7 +109,7 @@ fn style() -> FontStyleStruct {
|
||||||
font_variant_caps: FontVariantCaps::Normal,
|
font_variant_caps: FontVariantCaps::Normal,
|
||||||
font_weight: FontWeight::normal(),
|
font_weight: FontWeight::normal(),
|
||||||
font_size: FontSize::medium(),
|
font_size: FontSize::medium(),
|
||||||
font_stretch: FontStretch::Normal,
|
font_stretch: NonNegative(Percentage(1.)),
|
||||||
hash: 0,
|
hash: 0,
|
||||||
};
|
};
|
||||||
style.compute_font_hash();
|
style.compute_font_hash();
|
||||||
|
|
|
@ -16,8 +16,10 @@ fn test_font_template_descriptor() {
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use style::computed_values::font_stretch::T as FontStretch;
|
use style::values::computed::Percentage;
|
||||||
use style::values::computed::font::FontWeight;
|
use style::values::computed::font::FontWeight;
|
||||||
|
use style::values::generics::NonNegative;
|
||||||
|
use style::values::generics::font::FontStyle;
|
||||||
|
|
||||||
fn descriptor(filename: &str) -> FontTemplateDescriptor {
|
fn descriptor(filename: &str) -> FontTemplateDescriptor {
|
||||||
let mut path: PathBuf = [
|
let mut path: PathBuf = [
|
||||||
|
@ -43,25 +45,25 @@ fn test_font_template_descriptor() {
|
||||||
|
|
||||||
assert_eq!(descriptor("DejaVuSans"), FontTemplateDescriptor {
|
assert_eq!(descriptor("DejaVuSans"), FontTemplateDescriptor {
|
||||||
weight: FontWeight::normal(),
|
weight: FontWeight::normal(),
|
||||||
stretch: FontStretch::Normal,
|
stretch: NonNegative(Percentage(1.)),
|
||||||
italic: false,
|
style: FontStyle::Normal,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(descriptor("DejaVuSans-Bold"), FontTemplateDescriptor {
|
assert_eq!(descriptor("DejaVuSans-Bold"), FontTemplateDescriptor {
|
||||||
weight: FontWeight::bold(),
|
weight: FontWeight::bold(),
|
||||||
stretch: FontStretch::Normal,
|
stretch: NonNegative(Percentage(1.)),
|
||||||
italic: false,
|
style: FontStyle::Normal,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(descriptor("DejaVuSans-Oblique"), FontTemplateDescriptor {
|
assert_eq!(descriptor("DejaVuSans-Oblique"), FontTemplateDescriptor {
|
||||||
weight: FontWeight::normal(),
|
weight: FontWeight::normal(),
|
||||||
stretch: FontStretch::Normal,
|
stretch: NonNegative(Percentage(1.)),
|
||||||
italic: true,
|
style: FontStyle::Italic,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(descriptor("DejaVuSansCondensed-BoldOblique"), FontTemplateDescriptor {
|
assert_eq!(descriptor("DejaVuSansCondensed-BoldOblique"), FontTemplateDescriptor {
|
||||||
weight: FontWeight::bold(),
|
weight: FontWeight::bold(),
|
||||||
stretch: FontStretch::SemiCondensed,
|
stretch: NonNegative(Percentage(0.875)),
|
||||||
italic: true,
|
style: FontStyle::Italic,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,13 +104,13 @@ impl Flow for MulticolFlow {
|
||||||
self.block_flow.fragment.border_box.size.inline - padding_and_borders;
|
self.block_flow.fragment.border_box.size.inline - padding_and_borders;
|
||||||
let column_width;
|
let column_width;
|
||||||
{
|
{
|
||||||
let column_style = self.block_flow.fragment.style.get_column();
|
let style = &self.block_flow.fragment.style;
|
||||||
|
let column_gap = match style.get_position().column_gap {
|
||||||
let column_gap = match column_style.column_gap {
|
|
||||||
Either::First(len) => len.0.to_pixel_length(content_inline_size).into(),
|
Either::First(len) => len.0.to_pixel_length(content_inline_size).into(),
|
||||||
Either::Second(_normal) => self.block_flow.fragment.style.get_font().font_size.size(),
|
Either::Second(_normal) => self.block_flow.fragment.style.get_font().font_size.size(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let column_style = style.get_column();
|
||||||
let mut column_count;
|
let mut column_count;
|
||||||
if let Either::First(column_width) = column_style.column_width {
|
if let Either::First(column_width) = column_style.column_width {
|
||||||
let column_width = Au::from(column_width);
|
let column_width = Au::from(column_width);
|
||||||
|
|
|
@ -352,7 +352,7 @@ ${helpers.predefined_type("grid-template-areas",
|
||||||
${helpers.predefined_type("column-gap",
|
${helpers.predefined_type("column-gap",
|
||||||
"length::NonNegativeLengthOrPercentageOrNormal",
|
"length::NonNegativeLengthOrPercentageOrNormal",
|
||||||
"Either::Second(Normal)",
|
"Either::Second(Normal)",
|
||||||
alias="grid-column-gap",
|
alias="grid-column-gap" if product == "gecko" else "",
|
||||||
extra_prefixes="moz",
|
extra_prefixes="moz",
|
||||||
servo_pref="layout.columns.enabled",
|
servo_pref="layout.columns.enabled",
|
||||||
spec="https://drafts.csswg.org/css-align-3/#propdef-column-gap",
|
spec="https://drafts.csswg.org/css-align-3/#propdef-column-gap",
|
||||||
|
@ -364,7 +364,7 @@ ${helpers.predefined_type("row-gap",
|
||||||
"length::NonNegativeLengthOrPercentageOrNormal",
|
"length::NonNegativeLengthOrPercentageOrNormal",
|
||||||
"Either::Second(Normal)",
|
"Either::Second(Normal)",
|
||||||
alias="grid-row-gap",
|
alias="grid-row-gap",
|
||||||
servo_pref="layout.columns.enabled",
|
products="gecko",
|
||||||
spec="https://drafts.csswg.org/css-align-3/#propdef-row-gap",
|
spec="https://drafts.csswg.org/css-align-3/#propdef-row-gap",
|
||||||
animation_value_type="NonNegativeLengthOrPercentageOrNormal",
|
animation_value_type="NonNegativeLengthOrPercentageOrNormal",
|
||||||
servo_restyle_damage = "reflow")}
|
servo_restyle_damage = "reflow")}
|
||||||
|
|
|
@ -2242,9 +2242,13 @@ pub mod style_structs {
|
||||||
pub fn compute_font_hash(&mut self) {
|
pub fn compute_font_hash(&mut self) {
|
||||||
// Corresponds to the fields in
|
// Corresponds to the fields in
|
||||||
// `gfx::font_template::FontTemplateDescriptor`.
|
// `gfx::font_template::FontTemplateDescriptor`.
|
||||||
|
//
|
||||||
|
// FIXME(emilio): Where's font-style?
|
||||||
let mut hasher: FnvHasher = Default::default();
|
let mut hasher: FnvHasher = Default::default();
|
||||||
self.font_weight.hash(&mut hasher);
|
// We hash the floating point number with four decimal
|
||||||
self.font_stretch.hash(&mut hasher);
|
// places.
|
||||||
|
hasher.write_u64((self.font_weight.0 * 10000.).trunc() as u64);
|
||||||
|
hasher.write_u64(((self.font_stretch.0).0 * 10000.).trunc() as u64);
|
||||||
self.font_family.hash(&mut hasher);
|
self.font_family.hash(&mut hasher);
|
||||||
self.hash = hasher.finish()
|
self.hash = hasher.finish()
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ use gecko_bindings::sugar::refptr::RefPtr;
|
||||||
#[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};
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
@ -122,16 +123,6 @@ impl FontWeight {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hash for FontWeight {
|
|
||||||
fn hash<H>(&self, state: &mut H)
|
|
||||||
where
|
|
||||||
H: Hasher,
|
|
||||||
{
|
|
||||||
// We hash the floating point number with four decimal places.
|
|
||||||
state.write_u32((self.0 * 10000.).trunc() as u32)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FontSize {
|
impl FontSize {
|
||||||
/// The actual computed font size.
|
/// The actual computed font size.
|
||||||
pub fn size(self) -> Au {
|
pub fn size(self) -> Au {
|
||||||
|
@ -841,6 +832,7 @@ impl ToComputedValue for specified::MozScriptLevel {
|
||||||
/// A wrapper over an `Angle`, that handles clamping to the appropriate range
|
/// A wrapper over an `Angle`, that handles clamping to the appropriate range
|
||||||
/// for `font-style` animation.
|
/// for `font-style` animation.
|
||||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||||
pub struct FontStyleAngle(pub Angle);
|
pub struct FontStyleAngle(pub Angle);
|
||||||
|
|
||||||
impl ToAnimatedValue for FontStyleAngle {
|
impl ToAnimatedValue for FontStyleAngle {
|
||||||
|
@ -878,7 +870,7 @@ impl FontStyle {
|
||||||
///
|
///
|
||||||
/// https://drafts.csswg.org/css-fonts-4/#valdef-font-style-oblique-angle
|
/// https://drafts.csswg.org/css-fonts-4/#valdef-font-style-oblique-angle
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default_angle() -> FontStyleAngle {
|
pub fn default_angle() -> FontStyleAngle {
|
||||||
FontStyleAngle(Angle::Deg(specified::DEFAULT_FONT_STYLE_OBLIQUE_ANGLE_DEGREES))
|
FontStyleAngle(Angle::Deg(specified::DEFAULT_FONT_STYLE_OBLIQUE_ANGLE_DEGREES))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -238,6 +238,7 @@ impl ToCss for KeywordSize {
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf,
|
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf,
|
||||||
PartialEq, ToAnimatedValue, ToAnimatedZero)]
|
PartialEq, ToAnimatedValue, ToAnimatedZero)]
|
||||||
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||||
pub enum FontStyle<Angle> {
|
pub enum FontStyle<Angle> {
|
||||||
#[animation(error)]
|
#[animation(error)]
|
||||||
Normal,
|
Normal,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue