1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:47:35 +00:00

LibGfx: draw_glyph_or_emoji fix check for available glyph

This would cause question marks to be rendered when a ttf with fewer
glyphs than the value of the code_point was used.
This commit is contained in:
Stephan Unverwerth 2021-01-03 19:24:59 +01:00 committed by Andreas Kling
parent 6948f9ca55
commit 3b67b55c84
4 changed files with 5 additions and 3 deletions

View file

@ -58,6 +58,7 @@ public:
void set_weight(u16 weight) { m_weight = weight; } void set_weight(u16 weight) { m_weight = weight; }
Glyph glyph(u32 code_point) const; Glyph glyph(u32 code_point) const;
bool contains_glyph(u32 code_point) const { return code_point < (u32)glyph_count(); }
u8 glyph_width(size_t ch) const { return m_fixed_width ? m_glyph_width : m_glyph_widths[ch]; } u8 glyph_width(size_t ch) const { return m_fixed_width ? m_glyph_width : m_glyph_widths[ch]; }
int glyph_or_emoji_width(u32 code_point) const; int glyph_or_emoji_width(u32 code_point) const;

View file

@ -110,6 +110,7 @@ public:
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;
virtual bool contains_glyph(u32 code_point) const = 0;
virtual u8 glyph_width(size_t ch) const = 0; virtual u8 glyph_width(size_t ch) const = 0;
virtual int glyph_or_emoji_width(u32 code_point) const = 0; virtual int glyph_or_emoji_width(u32 code_point) const = 0;

View file

@ -929,9 +929,8 @@ void Painter::draw_emoji(const IntPoint& point, const Gfx::Bitmap& emoji, const
void Painter::draw_glyph_or_emoji(const IntPoint& point, u32 code_point, const Font& font, Color color) void Painter::draw_glyph_or_emoji(const IntPoint& point, u32 code_point, const Font& font, Color color)
{ {
if (code_point < (u32)font.glyph_count()) { if (font.contains_glyph(code_point)) {
// This looks like a regular character. draw_glyph(point, code_point, font, color);
draw_glyph(point, (size_t)code_point, font, color);
return; return;
} }

View file

@ -140,6 +140,7 @@ public:
virtual u8 presentation_size() const override { return m_point_height; } virtual u8 presentation_size() const override { return m_point_height; }
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_codepoint(code_point) > 0; }
virtual u8 glyph_width(size_t ch) const override; virtual u8 glyph_width(size_t ch) const override;
virtual int glyph_or_emoji_width(u32 code_point) const override; virtual int glyph_or_emoji_width(u32 code_point) const override;
virtual u8 glyph_height() const override { return m_point_height; } /* TODO */ virtual u8 glyph_height() const override { return m_point_height; } /* TODO */