mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:17:44 +00:00
LibGfx: Don't render OpenType glyphs that have no outline
The spec tells us that for glyph offsets in the "loca" table, if an offset appears twice in a row, the index of the first one refers to a glyph without an outline (such as the space character). We didn't check for this, which would cause us to render a glyph outline where there should have been nothing.
This commit is contained in:
parent
a28aba7663
commit
5ccb240945
2 changed files with 11 additions and 3 deletions
|
@ -699,8 +699,15 @@ RefPtr<Gfx::Bitmap> Font::rasterize_glyph(u32 glyph_id, float x_scale, float y_s
|
||||||
if (glyph_id >= glyph_count()) {
|
if (glyph_id >= glyph_count()) {
|
||||||
glyph_id = 0;
|
glyph_id = 0;
|
||||||
}
|
}
|
||||||
auto glyph_offset = m_loca->get_glyph_offset(glyph_id);
|
|
||||||
auto glyph = m_glyf->glyph(glyph_offset);
|
auto glyph_offset0 = m_loca->get_glyph_offset(glyph_id);
|
||||||
|
auto glyph_offset1 = m_loca->get_glyph_offset(glyph_id + 1);
|
||||||
|
|
||||||
|
// If a glyph has no outline, then loca[n] = loca [n+1].
|
||||||
|
if (glyph_offset0 == glyph_offset1)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto glyph = m_glyf->glyph(glyph_offset0);
|
||||||
|
|
||||||
i16 ascender = 0;
|
i16 ascender = 0;
|
||||||
i16 descender = 0;
|
i16 descender = 0;
|
||||||
|
|
|
@ -208,7 +208,8 @@ Optional<Loca> Loca::from_slice(ReadonlyBytes slice, u32 num_glyphs, IndexToLocF
|
||||||
|
|
||||||
u32 Loca::get_glyph_offset(u32 glyph_id) const
|
u32 Loca::get_glyph_offset(u32 glyph_id) const
|
||||||
{
|
{
|
||||||
VERIFY(glyph_id < m_num_glyphs);
|
// NOTE: The value of n is numGlyphs + 1.
|
||||||
|
VERIFY(glyph_id <= m_num_glyphs);
|
||||||
switch (m_index_to_loc_format) {
|
switch (m_index_to_loc_format) {
|
||||||
case IndexToLocFormat::Offset16:
|
case IndexToLocFormat::Offset16:
|
||||||
return ((u32)be_u16(m_slice.offset_pointer(glyph_id * 2))) * 2;
|
return ((u32)be_u16(m_slice.offset_pointer(glyph_id * 2))) * 2;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue