mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:57:45 +00:00
LibGfx: Determine slope attributes for TrueTypeFonts from tables
First checks the OS/2 table for an oblique selection flag before falling back on italic flags.
This commit is contained in:
parent
a79e730839
commit
87a149c9a4
5 changed files with 29 additions and 1 deletions
|
@ -37,7 +37,7 @@ public:
|
||||||
u16 weight() const override { return m_weight; }
|
u16 weight() const override { return m_weight; }
|
||||||
void set_weight(u16 weight) { m_weight = weight; }
|
void set_weight(u16 weight) { m_weight = weight; }
|
||||||
|
|
||||||
u8 slope() const { return m_slope; }
|
virtual u8 slope() const override { return m_slope; }
|
||||||
void set_slope(u8 slope) { m_slope = slope; }
|
void set_slope(u8 slope) { m_slope = slope; }
|
||||||
|
|
||||||
Glyph glyph(u32 code_point) const override;
|
Glyph glyph(u32 code_point) const override;
|
||||||
|
|
|
@ -101,6 +101,7 @@ public:
|
||||||
FontMetrics metrics(u32 code_point) const;
|
FontMetrics metrics(u32 code_point) const;
|
||||||
|
|
||||||
virtual u8 presentation_size() const = 0;
|
virtual u8 presentation_size() const = 0;
|
||||||
|
virtual u8 slope() const = 0;
|
||||||
|
|
||||||
virtual u16 weight() const = 0;
|
virtual u16 weight() const = 0;
|
||||||
virtual Glyph glyph(u32 code_point) const = 0;
|
virtual Glyph glyph(u32 code_point) const = 0;
|
||||||
|
|
|
@ -474,6 +474,24 @@ u16 Font::weight() const
|
||||||
return 400;
|
return 400;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u8 Font::slope() const
|
||||||
|
{
|
||||||
|
// https://docs.microsoft.com/en-us/typography/opentype/spec/os2
|
||||||
|
constexpr u16 italic_selection_bit { 1 };
|
||||||
|
constexpr u16 oblique_selection_bit { 512 };
|
||||||
|
// https://docs.microsoft.com/en-us/typography/opentype/spec/head
|
||||||
|
constexpr u16 italic_style_bit { 2 };
|
||||||
|
|
||||||
|
if (m_os2.selection() & oblique_selection_bit)
|
||||||
|
return 2;
|
||||||
|
if (m_os2.selection() & italic_selection_bit)
|
||||||
|
return 1;
|
||||||
|
if (m_head.style() & italic_style_bit)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool Font::is_fixed_width() const
|
bool Font::is_fixed_width() const
|
||||||
{
|
{
|
||||||
// FIXME: Read this information from the font file itself.
|
// FIXME: Read this information from the font file itself.
|
||||||
|
@ -549,6 +567,11 @@ u16 OS2::weight_class() const
|
||||||
return be_u16(m_slice.offset_pointer((u32)Offsets::WeightClass));
|
return be_u16(m_slice.offset_pointer((u32)Offsets::WeightClass));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u16 OS2::selection() const
|
||||||
|
{
|
||||||
|
return be_u16(m_slice.offset_pointer((u32)Offsets::Selection));
|
||||||
|
}
|
||||||
|
|
||||||
i16 OS2::typographic_ascender() const
|
i16 OS2::typographic_ascender() const
|
||||||
{
|
{
|
||||||
return be_i16(m_slice.offset_pointer((u32)Offsets::TypographicAscender));
|
return be_i16(m_slice.offset_pointer((u32)Offsets::TypographicAscender));
|
||||||
|
|
|
@ -57,6 +57,7 @@ public:
|
||||||
String family() const;
|
String family() const;
|
||||||
String variant() const;
|
String variant() const;
|
||||||
u16 weight() const;
|
u16 weight() const;
|
||||||
|
u8 slope() const;
|
||||||
bool is_fixed_width() const;
|
bool is_fixed_width() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -122,6 +123,7 @@ public:
|
||||||
// Gfx::Font implementation
|
// Gfx::Font implementation
|
||||||
virtual NonnullRefPtr<Font> clone() const override { return *this; } // FIXME: clone() should not need to be implemented
|
virtual NonnullRefPtr<Font> clone() const override { return *this; } // FIXME: clone() should not need to be implemented
|
||||||
virtual u8 presentation_size() const override { return m_point_height; }
|
virtual u8 presentation_size() const override { return m_point_height; }
|
||||||
|
virtual u8 slope() const override { return m_font->slope(); }
|
||||||
virtual u16 weight() const override { return m_font->weight(); }
|
virtual u16 weight() const override { return m_font->weight(); }
|
||||||
virtual Gfx::Glyph glyph(u32 code_point) const override;
|
virtual Gfx::Glyph glyph(u32 code_point) const override;
|
||||||
virtual bool contains_glyph(u32 code_point) const override { return m_font->glyph_id_for_code_point(code_point) > 0; }
|
virtual bool contains_glyph(u32 code_point) const override { return m_font->glyph_id_for_code_point(code_point) > 0; }
|
||||||
|
|
|
@ -133,12 +133,14 @@ class OS2 {
|
||||||
public:
|
public:
|
||||||
enum class Offsets {
|
enum class Offsets {
|
||||||
WeightClass = 4,
|
WeightClass = 4,
|
||||||
|
Selection = 62,
|
||||||
TypographicAscender = 68,
|
TypographicAscender = 68,
|
||||||
TypographicDescender = 70,
|
TypographicDescender = 70,
|
||||||
TypographicLineGap = 72,
|
TypographicLineGap = 72,
|
||||||
};
|
};
|
||||||
|
|
||||||
u16 weight_class() const;
|
u16 weight_class() const;
|
||||||
|
u16 selection() const;
|
||||||
i16 typographic_ascender() const;
|
i16 typographic_ascender() const;
|
||||||
i16 typographic_descender() const;
|
i16 typographic_descender() const;
|
||||||
i16 typographic_line_gap() const;
|
i16 typographic_line_gap() const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue