forked from Bananymous/banan-os
LibFont: Font::get_glyph() now returns nullptr if glyph does not exist
This allows getting glyphs with a single hash lookup
This commit is contained in:
parent
b2a4797d16
commit
f12ffa92a0
|
@ -274,14 +274,4 @@ namespace LibFont
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Font::has_glyph(uint32_t codepoint) const
|
|
||||||
{
|
|
||||||
return m_glyph_offsets.contains(codepoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint8_t* Font::glyph(uint32_t codepoint) const
|
|
||||||
{
|
|
||||||
return m_glyph_data.data() + m_glyph_offsets[codepoint];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,14 @@ namespace LibFont
|
||||||
uint32_t height() const { return m_height; }
|
uint32_t height() const { return m_height; }
|
||||||
uint32_t pitch() const { return m_pitch; }
|
uint32_t pitch() const { return m_pitch; }
|
||||||
|
|
||||||
bool has_glyph(uint32_t) const;
|
bool has_glyph(uint32_t codepoint) const { return glyph(codepoint) != nullptr; }
|
||||||
const uint8_t* glyph(uint32_t) const;
|
const uint8_t* glyph(uint32_t codepoint) const
|
||||||
|
{
|
||||||
|
auto it = m_glyph_offsets.find(codepoint);
|
||||||
|
if (it == m_glyph_offsets.end())
|
||||||
|
return nullptr;
|
||||||
|
return m_glyph_data.data() + it->value;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static BAN::ErrorOr<Font> parse_psf1(BAN::ConstByteSpan);
|
static BAN::ErrorOr<Font> parse_psf1(BAN::ConstByteSpan);
|
||||||
|
|
Loading…
Reference in New Issue