mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
gfx: Implement font-stretch
per CSS3-FONTS § 3.3 in the Core Text
font backend.
This commit is contained in:
parent
aba5c16091
commit
abddfa742f
8 changed files with 101 additions and 44 deletions
|
@ -15,7 +15,7 @@ use servo_util::geometry::{Au, px_to_pt};
|
|||
use servo_util::geometry;
|
||||
use platform::macos::font_context::FontContextHandle;
|
||||
use text::glyph::GlyphId;
|
||||
use style::computed_values::font_weight;
|
||||
use style::computed_values::{font_stretch, font_weight};
|
||||
use platform::font_template::FontTemplateData;
|
||||
|
||||
use core_foundation::base::CFIndex;
|
||||
|
@ -111,6 +111,21 @@ impl FontHandleMethods for FontHandle {
|
|||
return font_weight::T::Weight900;
|
||||
}
|
||||
|
||||
fn stretchiness(&self) -> font_stretch::T {
|
||||
let normalized = self.ctfont.all_traits().normalized_width(); // [-1.0, 1.0]
|
||||
match (normalized + 1.0) / 2.0 * 9.0 { // [0.0, 9.0]
|
||||
v if v < 1.0 => font_stretch::T::ultra_condensed,
|
||||
v if v < 2.0 => font_stretch::T::extra_condensed,
|
||||
v if v < 3.0 => font_stretch::T::condensed,
|
||||
v if v < 4.0 => font_stretch::T::semi_condensed,
|
||||
v if v < 5.0 => font_stretch::T::normal,
|
||||
v if v < 6.0 => font_stretch::T::semi_expanded,
|
||||
v if v < 7.0 => font_stretch::T::expanded,
|
||||
v if v < 8.0 => font_stretch::T::extra_expanded,
|
||||
_ => font_stretch::T::ultra_expanded,
|
||||
}
|
||||
}
|
||||
|
||||
fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
|
||||
let characters: [UniChar; 1] = [codepoint as UniChar];
|
||||
let mut glyphs: [CGGlyph; 1] = [0 as CGGlyph];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue