mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:07:44 +00:00
LibTTF: Convert code to east-const style
This commit is contained in:
parent
84efed502a
commit
8070bbd442
7 changed files with 50 additions and 50 deletions
|
@ -9,9 +9,9 @@
|
||||||
|
|
||||||
namespace TTF {
|
namespace TTF {
|
||||||
|
|
||||||
extern u16 be_u16(const u8* ptr);
|
extern u16 be_u16(u8 const*);
|
||||||
extern u32 be_u32(const u8* ptr);
|
extern u32 be_u32(u8 const*);
|
||||||
extern i16 be_i16(const u8* ptr);
|
extern i16 be_i16(u8 const*);
|
||||||
|
|
||||||
Cmap::Subtable::Platform Cmap::Subtable::platform_id() const
|
Cmap::Subtable::Platform Cmap::Subtable::platform_id() const
|
||||||
{
|
{
|
||||||
|
@ -143,7 +143,7 @@ u32 Cmap::glyph_id_for_code_point(u32 code_point) const
|
||||||
return subtable.glyph_id_for_code_point(code_point);
|
return subtable.glyph_id_for_code_point(code_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Cmap> Cmap::from_slice(const ReadonlyBytes& slice)
|
Optional<Cmap> Cmap::from_slice(ReadonlyBytes const& slice)
|
||||||
{
|
{
|
||||||
if (slice.size() < (size_t)Sizes::TableHeader) {
|
if (slice.size() < (size_t)Sizes::TableHeader) {
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
UnicodeFullRepertoire = 10,
|
UnicodeFullRepertoire = 10,
|
||||||
};
|
};
|
||||||
|
|
||||||
Subtable(const ReadonlyBytes& slice, u16 platform_id, u16 encoding_id)
|
Subtable(ReadonlyBytes const& slice, u16 platform_id, u16 encoding_id)
|
||||||
: m_slice(slice)
|
: m_slice(slice)
|
||||||
, m_raw_platform_id(platform_id)
|
, m_raw_platform_id(platform_id)
|
||||||
, m_encoding_id(encoding_id)
|
, m_encoding_id(encoding_id)
|
||||||
|
@ -81,7 +81,7 @@ public:
|
||||||
u16 m_encoding_id { 0 };
|
u16 m_encoding_id { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
static Optional<Cmap> from_slice(const ReadonlyBytes&);
|
static Optional<Cmap> from_slice(ReadonlyBytes const&);
|
||||||
u32 num_subtables() const;
|
u32 num_subtables() const;
|
||||||
Optional<Subtable> subtable(u32 index) const;
|
Optional<Subtable> subtable(u32 index) const;
|
||||||
void set_active_index(u32 index) { m_active_index = index; }
|
void set_active_index(u32 index) { m_active_index = index; }
|
||||||
|
@ -99,7 +99,7 @@ private:
|
||||||
EncodingRecord = 8,
|
EncodingRecord = 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
Cmap(const ReadonlyBytes& slice)
|
Cmap(ReadonlyBytes const& slice)
|
||||||
: m_slice(slice)
|
: m_slice(slice)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,38 +20,38 @@
|
||||||
|
|
||||||
namespace TTF {
|
namespace TTF {
|
||||||
|
|
||||||
u16 be_u16(const u8* ptr);
|
u16 be_u16(u8 const*);
|
||||||
u32 be_u32(const u8* ptr);
|
u32 be_u32(u8 const*);
|
||||||
i16 be_i16(const u8* ptr);
|
i16 be_i16(u8 const*);
|
||||||
float be_fword(const u8* ptr);
|
float be_fword(u8 const*);
|
||||||
u32 tag_from_str(const char* str);
|
u32 tag_from_str(char const*);
|
||||||
|
|
||||||
u16 be_u16(const u8* ptr)
|
u16 be_u16(u8 const* ptr)
|
||||||
{
|
{
|
||||||
return (((u16)ptr[0]) << 8) | ((u16)ptr[1]);
|
return (((u16)ptr[0]) << 8) | ((u16)ptr[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 be_u32(const u8* ptr)
|
u32 be_u32(u8 const* ptr)
|
||||||
{
|
{
|
||||||
return (((u32)ptr[0]) << 24) | (((u32)ptr[1]) << 16) | (((u32)ptr[2]) << 8) | ((u32)ptr[3]);
|
return (((u32)ptr[0]) << 24) | (((u32)ptr[1]) << 16) | (((u32)ptr[2]) << 8) | ((u32)ptr[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
i16 be_i16(const u8* ptr)
|
i16 be_i16(u8 const* ptr)
|
||||||
{
|
{
|
||||||
return (((i16)ptr[0]) << 8) | ((i16)ptr[1]);
|
return (((i16)ptr[0]) << 8) | ((i16)ptr[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
float be_fword(const u8* ptr)
|
float be_fword(u8 const* ptr)
|
||||||
{
|
{
|
||||||
return (float)be_i16(ptr) / (float)(1 << 14);
|
return (float)be_i16(ptr) / (float)(1 << 14);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 tag_from_str(const char* str)
|
u32 tag_from_str(char const* str)
|
||||||
{
|
{
|
||||||
return be_u32((const u8*)str);
|
return be_u32((u8 const*)str);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Head> Head::from_slice(const ReadonlyBytes& slice)
|
Optional<Head> Head::from_slice(ReadonlyBytes const& slice)
|
||||||
{
|
{
|
||||||
if (slice.size() < (size_t)Sizes::Table) {
|
if (slice.size() < (size_t)Sizes::Table) {
|
||||||
return {};
|
return {};
|
||||||
|
@ -102,7 +102,7 @@ IndexToLocFormat Head::index_to_loc_format() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Hhea> Hhea::from_slice(const ReadonlyBytes& slice)
|
Optional<Hhea> Hhea::from_slice(ReadonlyBytes const& slice)
|
||||||
{
|
{
|
||||||
if (slice.size() < (size_t)Sizes::Table) {
|
if (slice.size() < (size_t)Sizes::Table) {
|
||||||
return {};
|
return {};
|
||||||
|
@ -135,7 +135,7 @@ u16 Hhea::number_of_h_metrics() const
|
||||||
return be_u16(m_slice.offset_pointer((u32)Offsets::NumberOfHMetrics));
|
return be_u16(m_slice.offset_pointer((u32)Offsets::NumberOfHMetrics));
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Maxp> Maxp::from_slice(const ReadonlyBytes& slice)
|
Optional<Maxp> Maxp::from_slice(ReadonlyBytes const& slice)
|
||||||
{
|
{
|
||||||
if (slice.size() < (size_t)Sizes::TableV0p5) {
|
if (slice.size() < (size_t)Sizes::TableV0p5) {
|
||||||
return {};
|
return {};
|
||||||
|
@ -148,7 +148,7 @@ u16 Maxp::num_glyphs() const
|
||||||
return be_u16(m_slice.offset_pointer((u32)Offsets::NumGlyphs));
|
return be_u16(m_slice.offset_pointer((u32)Offsets::NumGlyphs));
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Hmtx> Hmtx::from_slice(const ReadonlyBytes& slice, u32 num_glyphs, u32 number_of_h_metrics)
|
Optional<Hmtx> Hmtx::from_slice(ReadonlyBytes const& slice, u32 num_glyphs, u32 number_of_h_metrics)
|
||||||
{
|
{
|
||||||
if (slice.size() < number_of_h_metrics * (u32)Sizes::LongHorMetric + (num_glyphs - number_of_h_metrics) * (u32)Sizes::LeftSideBearing) {
|
if (slice.size() < number_of_h_metrics * (u32)Sizes::LongHorMetric + (num_glyphs - number_of_h_metrics) * (u32)Sizes::LeftSideBearing) {
|
||||||
return {};
|
return {};
|
||||||
|
@ -156,7 +156,7 @@ Optional<Hmtx> Hmtx::from_slice(const ReadonlyBytes& slice, u32 num_glyphs, u32
|
||||||
return Hmtx(slice, num_glyphs, number_of_h_metrics);
|
return Hmtx(slice, num_glyphs, number_of_h_metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Name> Name::from_slice(const ReadonlyBytes& slice)
|
Optional<Name> Name::from_slice(ReadonlyBytes const& slice)
|
||||||
{
|
{
|
||||||
return Name(slice);
|
return Name(slice);
|
||||||
}
|
}
|
||||||
|
@ -192,10 +192,10 @@ String Name::string_for_id(NameId id) const
|
||||||
|
|
||||||
if (platform == (u16)Platform::Windows) {
|
if (platform == (u16)Platform::Windows) {
|
||||||
static auto& decoder = *TextCodec::decoder_for("utf-16be");
|
static auto& decoder = *TextCodec::decoder_for("utf-16be");
|
||||||
return decoder.to_utf8(StringView { (const char*)m_slice.offset_pointer(string_offset + offset), length });
|
return decoder.to_utf8(StringView { (char const*)m_slice.offset_pointer(string_offset + offset), length });
|
||||||
}
|
}
|
||||||
|
|
||||||
return String((const char*)m_slice.offset_pointer(string_offset + offset), length);
|
return String((char const*)m_slice.offset_pointer(string_offset + offset), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
GlyphHorizontalMetrics Hmtx::get_glyph_horizontal_metrics(u32 glyph_id) const
|
GlyphHorizontalMetrics Hmtx::get_glyph_horizontal_metrics(u32 glyph_id) const
|
||||||
|
|
|
@ -132,9 +132,9 @@ public:
|
||||||
virtual u8 glyph_fixed_width() const override;
|
virtual u8 glyph_fixed_width() const override;
|
||||||
virtual u8 baseline() const override { return m_point_height; } // FIXME: Read from font
|
virtual u8 baseline() const override { return m_point_height; } // FIXME: Read from font
|
||||||
virtual u8 mean_line() const override { return m_point_height; } // FIXME: Read from font
|
virtual u8 mean_line() const override { return m_point_height; } // FIXME: Read from font
|
||||||
virtual int width(const StringView&) const override;
|
virtual int width(StringView const&) const override;
|
||||||
virtual int width(const Utf8View&) const override;
|
virtual int width(Utf8View const&) const override;
|
||||||
virtual int width(const Utf32View&) const override;
|
virtual int width(Utf32View const&) const override;
|
||||||
virtual String name() const override { return String::formatted("{} {}", family(), variant()); }
|
virtual String name() const override { return String::formatted("{} {}", family(), variant()); }
|
||||||
virtual bool is_fixed_width() const override { return m_font->is_fixed_width(); }
|
virtual bool is_fixed_width() const override { return m_font->is_fixed_width(); }
|
||||||
virtual u8 glyph_spacing() const override { return m_x_scale; } // FIXME: Read from font
|
virtual u8 glyph_spacing() const override { return m_x_scale; } // FIXME: Read from font
|
||||||
|
|
|
@ -10,10 +10,10 @@
|
||||||
|
|
||||||
namespace TTF {
|
namespace TTF {
|
||||||
|
|
||||||
extern u16 be_u16(const u8* ptr);
|
extern u16 be_u16(u8 const* ptr);
|
||||||
extern u32 be_u32(const u8* ptr);
|
extern u32 be_u32(u8 const* ptr);
|
||||||
extern i16 be_i16(const u8* ptr);
|
extern i16 be_i16(u8 const* ptr);
|
||||||
extern float be_fword(const u8* ptr);
|
extern float be_fword(u8 const* ptr);
|
||||||
|
|
||||||
enum class SimpleGlyfFlags {
|
enum class SimpleGlyfFlags {
|
||||||
// From spec.
|
// From spec.
|
||||||
|
@ -56,7 +56,7 @@ public:
|
||||||
Gfx::FloatPoint point;
|
Gfx::FloatPoint point;
|
||||||
};
|
};
|
||||||
|
|
||||||
PointIterator(const ReadonlyBytes& slice, u16 num_points, u32 flags_offset, u32 x_offset, u32 y_offset, Gfx::AffineTransform affine)
|
PointIterator(ReadonlyBytes const& slice, u16 num_points, u32 flags_offset, u32 x_offset, u32 y_offset, Gfx::AffineTransform affine)
|
||||||
: m_slice(slice)
|
: m_slice(slice)
|
||||||
, m_points_remaining(num_points)
|
, m_points_remaining(num_points)
|
||||||
, m_flags_offset(flags_offset)
|
, m_flags_offset(flags_offset)
|
||||||
|
@ -319,7 +319,7 @@ void Rasterizer::draw_line(Gfx::FloatPoint p0, Gfx::FloatPoint p1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Loca> Loca::from_slice(const ReadonlyBytes& slice, u32 num_glyphs, IndexToLocFormat index_to_loc_format)
|
Optional<Loca> Loca::from_slice(ReadonlyBytes const& slice, u32 num_glyphs, IndexToLocFormat index_to_loc_format)
|
||||||
{
|
{
|
||||||
switch (index_to_loc_format) {
|
switch (index_to_loc_format) {
|
||||||
case IndexToLocFormat::Offset16:
|
case IndexToLocFormat::Offset16:
|
||||||
|
@ -349,7 +349,7 @@ u32 Loca::get_glyph_offset(u32 glyph_id) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_ttglyph_offsets(const ReadonlyBytes& slice, u32 num_points, u32 flags_offset, u32* x_offset, u32* y_offset)
|
static void get_ttglyph_offsets(ReadonlyBytes const& slice, u32 num_points, u32 flags_offset, u32* x_offset, u32* y_offset)
|
||||||
{
|
{
|
||||||
u32 flags_size = 0;
|
u32 flags_size = 0;
|
||||||
u32 x_size = 0;
|
u32 x_size = 0;
|
||||||
|
|
|
@ -30,11 +30,11 @@ private:
|
||||||
|
|
||||||
class Loca {
|
class Loca {
|
||||||
public:
|
public:
|
||||||
static Optional<Loca> from_slice(const ReadonlyBytes&, u32 num_glyphs, IndexToLocFormat);
|
static Optional<Loca> from_slice(ReadonlyBytes const&, u32 num_glyphs, IndexToLocFormat);
|
||||||
u32 get_glyph_offset(u32 glyph_id) const;
|
u32 get_glyph_offset(u32 glyph_id) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Loca(const ReadonlyBytes& slice, u32 num_glyphs, IndexToLocFormat index_to_loc_format)
|
Loca(ReadonlyBytes const& slice, u32 num_glyphs, IndexToLocFormat index_to_loc_format)
|
||||||
: m_slice(slice)
|
: m_slice(slice)
|
||||||
, m_num_glyphs(num_glyphs)
|
, m_num_glyphs(num_glyphs)
|
||||||
, m_index_to_loc_format(index_to_loc_format)
|
, m_index_to_loc_format(index_to_loc_format)
|
||||||
|
@ -50,7 +50,7 @@ class Glyf {
|
||||||
public:
|
public:
|
||||||
class Glyph {
|
class Glyph {
|
||||||
public:
|
public:
|
||||||
Glyph(const ReadonlyBytes& slice, i16 xmin, i16 ymin, i16 xmax, i16 ymax, i16 num_contours = -1)
|
Glyph(ReadonlyBytes const& slice, i16 xmin, i16 ymin, i16 xmax, i16 ymax, i16 num_contours = -1)
|
||||||
: m_xmin(xmin)
|
: m_xmin(xmin)
|
||||||
, m_ymin(ymin)
|
, m_ymin(ymin)
|
||||||
, m_xmax(xmax)
|
, m_xmax(xmax)
|
||||||
|
@ -89,7 +89,7 @@ public:
|
||||||
Gfx::AffineTransform affine;
|
Gfx::AffineTransform affine;
|
||||||
};
|
};
|
||||||
|
|
||||||
ComponentIterator(const ReadonlyBytes& slice)
|
ComponentIterator(ReadonlyBytes const& slice)
|
||||||
: m_slice(slice)
|
: m_slice(slice)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ public:
|
||||||
ReadonlyBytes m_slice;
|
ReadonlyBytes m_slice;
|
||||||
};
|
};
|
||||||
|
|
||||||
Glyf(const ReadonlyBytes& slice)
|
Glyf(ReadonlyBytes const& slice)
|
||||||
: m_slice(slice)
|
: m_slice(slice)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ enum class IndexToLocFormat {
|
||||||
|
|
||||||
class Head {
|
class Head {
|
||||||
public:
|
public:
|
||||||
static Optional<Head> from_slice(const ReadonlyBytes&);
|
static Optional<Head> from_slice(ReadonlyBytes const&);
|
||||||
u16 units_per_em() const;
|
u16 units_per_em() const;
|
||||||
i16 xmin() const;
|
i16 xmin() const;
|
||||||
i16 ymin() const;
|
i16 ymin() const;
|
||||||
|
@ -40,7 +40,7 @@ private:
|
||||||
Table = 54,
|
Table = 54,
|
||||||
};
|
};
|
||||||
|
|
||||||
Head(const ReadonlyBytes& slice)
|
Head(ReadonlyBytes const& slice)
|
||||||
: m_slice(slice)
|
: m_slice(slice)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ private:
|
||||||
|
|
||||||
class Hhea {
|
class Hhea {
|
||||||
public:
|
public:
|
||||||
static Optional<Hhea> from_slice(const ReadonlyBytes&);
|
static Optional<Hhea> from_slice(ReadonlyBytes const&);
|
||||||
i16 ascender() const;
|
i16 ascender() const;
|
||||||
i16 descender() const;
|
i16 descender() const;
|
||||||
i16 line_gap() const;
|
i16 line_gap() const;
|
||||||
|
@ -69,7 +69,7 @@ private:
|
||||||
Table = 36,
|
Table = 36,
|
||||||
};
|
};
|
||||||
|
|
||||||
Hhea(const ReadonlyBytes& slice)
|
Hhea(ReadonlyBytes const& slice)
|
||||||
: m_slice(slice)
|
: m_slice(slice)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ private:
|
||||||
|
|
||||||
class Maxp {
|
class Maxp {
|
||||||
public:
|
public:
|
||||||
static Optional<Maxp> from_slice(const ReadonlyBytes&);
|
static Optional<Maxp> from_slice(ReadonlyBytes const&);
|
||||||
u16 num_glyphs() const;
|
u16 num_glyphs() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -90,7 +90,7 @@ private:
|
||||||
TableV0p5 = 6,
|
TableV0p5 = 6,
|
||||||
};
|
};
|
||||||
|
|
||||||
Maxp(const ReadonlyBytes& slice)
|
Maxp(ReadonlyBytes const& slice)
|
||||||
: m_slice(slice)
|
: m_slice(slice)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ struct GlyphHorizontalMetrics {
|
||||||
|
|
||||||
class Hmtx {
|
class Hmtx {
|
||||||
public:
|
public:
|
||||||
static Optional<Hmtx> from_slice(const ReadonlyBytes&, u32 num_glyphs, u32 number_of_h_metrics);
|
static Optional<Hmtx> from_slice(ReadonlyBytes const&, u32 num_glyphs, u32 number_of_h_metrics);
|
||||||
GlyphHorizontalMetrics get_glyph_horizontal_metrics(u32 glyph_id) const;
|
GlyphHorizontalMetrics get_glyph_horizontal_metrics(u32 glyph_id) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -114,7 +114,7 @@ private:
|
||||||
LeftSideBearing = 2
|
LeftSideBearing = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
Hmtx(const ReadonlyBytes& slice, u32 num_glyphs, u32 number_of_h_metrics)
|
Hmtx(ReadonlyBytes const& slice, u32 num_glyphs, u32 number_of_h_metrics)
|
||||||
: m_slice(slice)
|
: m_slice(slice)
|
||||||
, m_num_glyphs(num_glyphs)
|
, m_num_glyphs(num_glyphs)
|
||||||
, m_number_of_h_metrics(number_of_h_metrics)
|
, m_number_of_h_metrics(number_of_h_metrics)
|
||||||
|
@ -139,7 +139,7 @@ public:
|
||||||
enum class WindowsLanguage {
|
enum class WindowsLanguage {
|
||||||
EnglishUnitedStates = 0x0409,
|
EnglishUnitedStates = 0x0409,
|
||||||
};
|
};
|
||||||
static Optional<Name> from_slice(const ReadonlyBytes&);
|
static Optional<Name> from_slice(ReadonlyBytes const&);
|
||||||
|
|
||||||
String family_name() const { return string_for_id(NameId::FamilyName); }
|
String family_name() const { return string_for_id(NameId::FamilyName); }
|
||||||
String subfamily_name() const { return string_for_id(NameId::SubfamilyName); }
|
String subfamily_name() const { return string_for_id(NameId::SubfamilyName); }
|
||||||
|
@ -163,7 +163,7 @@ private:
|
||||||
TypographicSubfamilyName = 17,
|
TypographicSubfamilyName = 17,
|
||||||
};
|
};
|
||||||
|
|
||||||
Name(const ReadonlyBytes& slice)
|
Name(ReadonlyBytes const& slice)
|
||||||
: m_slice(slice)
|
: m_slice(slice)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue