mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Implement boldness and stretchiness for Freetype
The current implementation for boldness assumes that if Freetype claims a font is not bold then it must have normal weight. However fonts with lighter-than-normal weight are not claimed to be bold. Therefore we get rid of this check.
This commit is contained in:
parent
8f24005e17
commit
84de6a84d6
1 changed files with 33 additions and 18 deletions
|
@ -10,7 +10,7 @@ use freetype::freetype::{FT_F26Dot6, FT_Face, FT_FaceRec};
|
||||||
use freetype::freetype::{FT_Get_Char_Index, FT_Get_Postscript_Name};
|
use freetype::freetype::{FT_Get_Char_Index, FT_Get_Postscript_Name};
|
||||||
use freetype::freetype::{FT_Get_Kerning, FT_Get_Sfnt_Table, FT_Load_Sfnt_Table};
|
use freetype::freetype::{FT_Get_Kerning, FT_Get_Sfnt_Table, FT_Load_Sfnt_Table};
|
||||||
use freetype::freetype::{FT_GlyphSlot, FT_Library, FT_Long, FT_ULong};
|
use freetype::freetype::{FT_GlyphSlot, FT_Library, FT_Long, FT_ULong};
|
||||||
use freetype::freetype::{FT_Int32, FT_Kerning_Mode, FT_STYLE_FLAG_BOLD, FT_STYLE_FLAG_ITALIC};
|
use freetype::freetype::{FT_Int32, FT_Kerning_Mode, FT_STYLE_FLAG_ITALIC};
|
||||||
use freetype::freetype::{FT_Load_Glyph, FT_Set_Char_Size};
|
use freetype::freetype::{FT_Load_Glyph, FT_Set_Char_Size};
|
||||||
use freetype::freetype::{FT_SizeRec, FT_Size_Metrics, FT_UInt, FT_Vector};
|
use freetype::freetype::{FT_SizeRec, FT_Size_Metrics, FT_UInt, FT_Vector};
|
||||||
use freetype::freetype::FT_Sfnt_Tag;
|
use freetype::freetype::FT_Sfnt_Tag;
|
||||||
|
@ -137,9 +137,6 @@ impl FontHandleMethods for FontHandle {
|
||||||
}
|
}
|
||||||
fn boldness(&self) -> FontWeight {
|
fn boldness(&self) -> FontWeight {
|
||||||
let default_weight = FontWeight::normal();
|
let default_weight = FontWeight::normal();
|
||||||
if unsafe { (*self.face).style_flags & FT_STYLE_FLAG_BOLD as c_long == 0 } {
|
|
||||||
default_weight
|
|
||||||
} else {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let os2 = FT_Get_Sfnt_Table(self.face, FT_Sfnt_Tag::FT_SFNT_OS2) as *mut TT_OS2;
|
let os2 = FT_Get_Sfnt_Table(self.face, FT_Sfnt_Tag::FT_SFNT_OS2) as *mut TT_OS2;
|
||||||
let valid = !os2.is_null() && (*os2).version != 0xffff;
|
let valid = !os2.is_null() && (*os2).version != 0xffff;
|
||||||
|
@ -157,10 +154,28 @@ impl FontHandleMethods for FontHandle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
fn stretchiness(&self) -> FontStretch {
|
fn stretchiness(&self) -> FontStretch {
|
||||||
// TODO(pcwalton): Implement this.
|
let default_stretch = FontStretch::Normal;
|
||||||
FontStretch::Normal
|
unsafe {
|
||||||
|
let os2 = FT_Get_Sfnt_Table(self.face, FT_Sfnt_Tag::FT_SFNT_OS2) as *mut TT_OS2;
|
||||||
|
let valid = !os2.is_null() && (*os2).version != 0xffff;
|
||||||
|
if valid {
|
||||||
|
match (*os2).usWidthClass {
|
||||||
|
1 => FontStretch::UltraCondensed,
|
||||||
|
2 => FontStretch::ExtraCondensed,
|
||||||
|
3 => FontStretch::Condensed,
|
||||||
|
4 => FontStretch::SemiCondensed,
|
||||||
|
5 => FontStretch::Normal, // called medium in TrueType spec
|
||||||
|
6 => FontStretch::SemiExpanded,
|
||||||
|
7 => FontStretch::Expanded,
|
||||||
|
8 => FontStretch::ExtraExpanded,
|
||||||
|
9 => FontStretch::UltraExpanded,
|
||||||
|
_ => default_stretch,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
default_stretch
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
|
fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue