mirror of
https://github.com/servo/servo.git
synced 2025-08-13 17:35:36 +01:00
Fix servo build.
This commit is contained in:
parent
16ca8de6df
commit
54b444992d
13 changed files with 148 additions and 143 deletions
|
@ -24,6 +24,7 @@ use std::os::raw::{c_char, c_long};
|
|||
use std::sync::Arc;
|
||||
use style::computed_values::font_stretch::T as FontStretch;
|
||||
use style::computed_values::font_weight::T as FontWeight;
|
||||
use style::values::computed::font::FontStyle;
|
||||
use super::c_str_to_string;
|
||||
use text::glyph::GlyphId;
|
||||
use text::util::fixed_to_float;
|
||||
|
@ -149,8 +150,13 @@ impl FontHandleMethods for FontHandle {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_italic(&self) -> bool {
|
||||
unsafe { (*self.face).style_flags & FT_STYLE_FLAG_ITALIC as c_long != 0 }
|
||||
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
|
||||
} else {
|
||||
Normal
|
||||
}
|
||||
}
|
||||
|
||||
fn boldness(&self) -> FontWeight {
|
||||
|
@ -163,22 +169,25 @@ impl FontHandleMethods for FontHandle {
|
|||
}
|
||||
|
||||
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 {
|
||||
1 => FontStretch::UltraCondensed,
|
||||
2 => FontStretch::ExtraCondensed,
|
||||
3 => FontStretch::Condensed,
|
||||
4 => FontStretch::SemiCondensed,
|
||||
5 => FontStretch::Normal,
|
||||
6 => FontStretch::SemiExpanded,
|
||||
7 => FontStretch::Expanded,
|
||||
8 => FontStretch::ExtraExpanded,
|
||||
9 => FontStretch::UltraExpanded,
|
||||
_ => FontStretch::Normal
|
||||
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,
|
||||
_ => FontStretchKeyword::Normal
|
||||
}
|
||||
} else {
|
||||
FontStretch::Normal
|
||||
}
|
||||
FontStretchKeyword::Normal
|
||||
}.compute();
|
||||
NonNegative(percentage)
|
||||
}
|
||||
|
||||
fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
|
||||
|
|
|
@ -22,8 +22,7 @@ use servo_atoms::Atom;
|
|||
use std::{fmt, ptr};
|
||||
use std::ops::Range;
|
||||
use std::sync::Arc;
|
||||
use style::computed_values::font_stretch::T as FontStretch;
|
||||
use style::computed_values::font_weight::T as FontWeight;
|
||||
use style::values::computed::font::{FontStretch, FontStyle, FontWeight};
|
||||
use text::glyph::GlyphId;
|
||||
|
||||
const KERN_PAIR_LEN: usize = 6;
|
||||
|
@ -204,8 +203,13 @@ impl FontHandleMethods for FontHandle {
|
|||
Some(self.ctfont.face_name())
|
||||
}
|
||||
|
||||
fn is_italic(&self) -> bool {
|
||||
self.ctfont.symbolic_traits().is_italic()
|
||||
fn style(&self) -> FontStyle {
|
||||
use style::values::generics::font::FontStyle::*;
|
||||
if self.ctfont.symbolic_traits().is_italic() {
|
||||
Italic
|
||||
} else {
|
||||
Normal
|
||||
}
|
||||
}
|
||||
|
||||
fn boldness(&self) -> FontWeight {
|
||||
|
@ -221,19 +225,11 @@ impl FontHandleMethods for FontHandle {
|
|||
}
|
||||
|
||||
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 = (normalized + 1.0) / 2.0 * 9.0; // [0.0, 9.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,
|
||||
}
|
||||
NonNegative(Percentage(normalized as f32 + 1.0))
|
||||
}
|
||||
|
||||
fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
|
||||
|
|
|
@ -19,6 +19,10 @@ use servo_atoms::Atom;
|
|||
use std::sync::Arc;
|
||||
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::NonNegative;
|
||||
use style::values::generics::font::FontStyle as GenericFontStyle;
|
||||
use style::values::specified::font::FontStretchKeyword;
|
||||
use text::glyph::GlyphId;
|
||||
use truetype;
|
||||
|
||||
|
@ -98,7 +102,7 @@ struct FontInfo {
|
|||
face_name: String,
|
||||
weight: StyleFontWeight,
|
||||
stretch: StyleFontStretch,
|
||||
style: FontStyle,
|
||||
style: StyleFontStyle,
|
||||
}
|
||||
|
||||
impl FontInfo {
|
||||
|
@ -159,23 +163,23 @@ impl FontInfo {
|
|||
|
||||
let weight = StyleFontWeight(weight_val as f32);
|
||||
|
||||
let stretch = match min(9, max(1, width_val)) {
|
||||
1 => StyleFontStretch::UltraCondensed,
|
||||
2 => StyleFontStretch::ExtraCondensed,
|
||||
3 => StyleFontStretch::Condensed,
|
||||
4 => StyleFontStretch::SemiCondensed,
|
||||
5 => StyleFontStretch::Normal,
|
||||
6 => StyleFontStretch::SemiExpanded,
|
||||
7 => StyleFontStretch::Expanded,
|
||||
8 => StyleFontStretch::ExtraExpanded,
|
||||
9 => StyleFontStretch::UltraExpanded,
|
||||
let stretch = 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 style = if italic_bool {
|
||||
FontStyle::Italic
|
||||
GenericFontStyle::Italic
|
||||
} else {
|
||||
FontStyle::Normal
|
||||
GenericFontStyle::Normal
|
||||
};
|
||||
|
||||
Ok(FontInfo {
|
||||
|
@ -188,7 +192,11 @@ impl 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() {
|
||||
FontWeight::Thin => 100.,
|
||||
FontWeight::ExtraLight => 200.,
|
||||
|
@ -204,18 +212,18 @@ impl FontInfo {
|
|||
// slightly blacker black
|
||||
FontWeight::ExtraBlack => 1000.,
|
||||
});
|
||||
let stretch = match font.stretch() {
|
||||
FontStretch::Undefined => StyleFontStretch::Normal,
|
||||
FontStretch::UltraCondensed => StyleFontStretch::UltraCondensed,
|
||||
FontStretch::ExtraCondensed => StyleFontStretch::ExtraCondensed,
|
||||
FontStretch::Condensed => StyleFontStretch::Condensed,
|
||||
FontStretch::SemiCondensed => StyleFontStretch::SemiCondensed,
|
||||
FontStretch::Normal => StyleFontStretch::Normal,
|
||||
FontStretch::SemiExpanded => StyleFontStretch::SemiExpanded,
|
||||
FontStretch::Expanded => StyleFontStretch::Expanded,
|
||||
FontStretch::ExtraExpanded => StyleFontStretch::ExtraExpanded,
|
||||
FontStretch::UltraExpanded => StyleFontStretch::UltraExpanded,
|
||||
};
|
||||
let stretch = 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());
|
||||
|
||||
Ok(FontInfo {
|
||||
family_name: font.family_name(),
|
||||
|
@ -294,11 +302,8 @@ impl FontHandleMethods for FontHandle {
|
|||
Some(self.info.face_name.clone())
|
||||
}
|
||||
|
||||
fn is_italic(&self) -> bool {
|
||||
match self.info.style {
|
||||
FontStyle::Normal => false,
|
||||
FontStyle::Oblique | FontStyle::Italic => true,
|
||||
}
|
||||
fn style(&self) -> StyleFontStyle {
|
||||
self.info.style
|
||||
}
|
||||
|
||||
fn boldness(&self) -> StyleFontWeight {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue