mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:07:45 +00:00
LibGfx: Reduce bit casting in OpenType CBLC table after construction
The subtables are still read at use-time for now. I'm sure we could build some kind of wrapper structures for them though.
This commit is contained in:
parent
3c7d654182
commit
a28f035d76
2 changed files with 12 additions and 10 deletions
|
@ -451,12 +451,14 @@ ErrorOr<CBLC> CBLC::from_slice(ReadonlyBytes slice)
|
||||||
if (slice.size() < total_size)
|
if (slice.size() < total_size)
|
||||||
return Error::from_string_literal("CBLC table too small");
|
return Error::from_string_literal("CBLC table too small");
|
||||||
|
|
||||||
return CBLC { slice };
|
ReadonlySpan<BitmapSize> bitmap_sizes { bit_cast<BitmapSize const*>(slice.data() + sizeof(CblcHeader)), num_sizes };
|
||||||
|
|
||||||
|
return CBLC { slice, header, bitmap_sizes };
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<CBLC::BitmapSize const&> CBLC::bitmap_size_for_glyph_id(u32 glyph_id) const
|
Optional<CBLC::BitmapSize const&> CBLC::bitmap_size_for_glyph_id(u32 glyph_id) const
|
||||||
{
|
{
|
||||||
for (auto const& bitmap_size : this->bitmap_sizes()) {
|
for (auto const& bitmap_size : m_bitmap_sizes) {
|
||||||
if (glyph_id >= bitmap_size.start_glyph_index && glyph_id <= bitmap_size.end_glyph_index) {
|
if (glyph_id >= bitmap_size.start_glyph_index && glyph_id <= bitmap_size.end_glyph_index) {
|
||||||
return bitmap_size;
|
return bitmap_size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -549,26 +549,26 @@ public:
|
||||||
BigEndian<u16> major_version;
|
BigEndian<u16> major_version;
|
||||||
BigEndian<u16> minor_version;
|
BigEndian<u16> minor_version;
|
||||||
BigEndian<u32> num_sizes;
|
BigEndian<u32> num_sizes;
|
||||||
BitmapSize bitmap_sizes[];
|
// Stored in a separate span:
|
||||||
|
// BitmapSize bitmap_sizes[];
|
||||||
};
|
};
|
||||||
static_assert(AssertSize<CblcHeader, 8>());
|
static_assert(AssertSize<CblcHeader, 8>());
|
||||||
|
|
||||||
CblcHeader const& header() const { return *bit_cast<CblcHeader const*>(m_slice.data()); }
|
|
||||||
ReadonlySpan<BitmapSize> bitmap_sizes() const { return { header().bitmap_sizes, header().num_sizes }; }
|
|
||||||
Optional<BitmapSize const&> bitmap_size_for_glyph_id(u32 glyph_id) const;
|
|
||||||
|
|
||||||
static ErrorOr<CBLC> from_slice(ReadonlyBytes);
|
static ErrorOr<CBLC> from_slice(ReadonlyBytes);
|
||||||
ReadonlyBytes bytes() const { return m_slice; }
|
Optional<BitmapSize const&> bitmap_size_for_glyph_id(u32 glyph_id) const;
|
||||||
|
|
||||||
Optional<EBLC::IndexSubHeader const&> index_subtable_for_glyph_id(u32 glyph_id, u16& first_glyph_index, u16& last_glyph_index) const;
|
Optional<EBLC::IndexSubHeader const&> index_subtable_for_glyph_id(u32 glyph_id, u16& first_glyph_index, u16& last_glyph_index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit CBLC(ReadonlyBytes slice)
|
explicit CBLC(ReadonlyBytes slice, CblcHeader const& header, ReadonlySpan<BitmapSize> bitmap_sizes)
|
||||||
: m_slice(slice)
|
: m_slice(slice)
|
||||||
|
, m_header(header)
|
||||||
|
, m_bitmap_sizes(bitmap_sizes)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadonlyBytes m_slice;
|
ReadonlyBytes m_slice;
|
||||||
|
CblcHeader const& m_header;
|
||||||
|
ReadonlySpan<BitmapSize> m_bitmap_sizes;
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://learn.microsoft.com/en-us/typography/opentype/spec/ebdt
|
// https://learn.microsoft.com/en-us/typography/opentype/spec/ebdt
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue