mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:27:45 +00:00
LibGfx: Get weight from tables for TrueTypeFonts
First, try to find detailed weight metrics in the OS/2 table; barring that, fall back to the font header table.
This commit is contained in:
parent
fde48f1a7a
commit
39484fc02c
2 changed files with 18 additions and 22 deletions
|
@ -84,6 +84,11 @@ i16 Head::ymax() const
|
|||
return be_i16(m_slice.offset_pointer((u32)Offsets::YMax));
|
||||
}
|
||||
|
||||
u16 Head::style() const
|
||||
{
|
||||
return be_u16(m_slice.offset_pointer((u32)Offsets::Style));
|
||||
}
|
||||
|
||||
u16 Head::lowest_recommended_ppem() const
|
||||
{
|
||||
return be_u16(m_slice.offset_pointer((u32)Offsets::LowestRecPPEM));
|
||||
|
@ -462,29 +467,11 @@ String Font::variant() const
|
|||
|
||||
u16 Font::weight() const
|
||||
{
|
||||
// FIXME: This is pretty naive, read weight from the actual font table(s)
|
||||
auto variant_name = variant();
|
||||
|
||||
if (variant_name == "Thin")
|
||||
return 100;
|
||||
if (variant_name == "Extra Light")
|
||||
return 200;
|
||||
if (variant_name == "Light")
|
||||
return 300;
|
||||
if (variant_name == "Regular")
|
||||
return 400;
|
||||
if (variant_name == "Medium")
|
||||
return 500;
|
||||
if (variant_name == "Semi Bold")
|
||||
return 600;
|
||||
if (variant_name == "Bold")
|
||||
constexpr u16 bold_bit { 1 };
|
||||
if (m_os2.weight_class())
|
||||
return m_os2.weight_class();
|
||||
if (m_head.style() & bold_bit)
|
||||
return 700;
|
||||
if (variant_name == "Extra Bold")
|
||||
return 800;
|
||||
if (variant_name == "Black")
|
||||
return 900;
|
||||
if (variant_name == "Extra Black")
|
||||
return 950;
|
||||
|
||||
return 400;
|
||||
}
|
||||
|
@ -559,6 +546,11 @@ u8 ScaledFont::glyph_fixed_width() const
|
|||
return glyph_metrics(glyph_id_for_code_point(' ')).advance_width;
|
||||
}
|
||||
|
||||
u16 OS2::weight_class() const
|
||||
{
|
||||
return be_u16(m_slice.offset_pointer((u32)Offsets::WeightClass));
|
||||
}
|
||||
|
||||
i16 OS2::typographic_ascender() const
|
||||
{
|
||||
return be_i16(m_slice.offset_pointer((u32)Offsets::TypographicAscender));
|
||||
|
|
|
@ -23,6 +23,7 @@ public:
|
|||
i16 ymin() const;
|
||||
i16 xmax() const;
|
||||
i16 ymax() const;
|
||||
u16 style() const;
|
||||
u16 lowest_recommended_ppem() const;
|
||||
IndexToLocFormat index_to_loc_format() const;
|
||||
|
||||
|
@ -33,6 +34,7 @@ private:
|
|||
YMin = 38,
|
||||
XMax = 40,
|
||||
YMax = 42,
|
||||
Style = 44,
|
||||
LowestRecPPEM = 46,
|
||||
IndexToLocFormat = 50,
|
||||
};
|
||||
|
@ -129,11 +131,13 @@ private:
|
|||
class OS2 {
|
||||
public:
|
||||
enum class Offsets {
|
||||
WeightClass = 4,
|
||||
TypographicAscender = 68,
|
||||
TypographicDescender = 70,
|
||||
TypographicLineGap = 72,
|
||||
};
|
||||
|
||||
u16 weight_class() const;
|
||||
i16 typographic_ascender() const;
|
||||
i16 typographic_descender() const;
|
||||
i16 typographic_line_gap() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue