1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:17:35 +00:00

LibGfx: Always scale emojis to fit font height

This commit is contained in:
Maciej 2022-01-21 18:48:47 +01:00 committed by Linus Groh
parent 7a92842017
commit 8542d1da5a
2 changed files with 8 additions and 12 deletions

View file

@ -314,7 +314,7 @@ int BitmapFont::glyph_or_emoji_width_for_variable_width_font(u32 code_point) con
auto* emoji = Emoji::emoji_for_code_point(code_point); auto* emoji = Emoji::emoji_for_code_point(code_point);
if (emoji == nullptr) if (emoji == nullptr)
return glyph_width(0xFFFD); return glyph_width(0xFFFD);
return emoji->size().width(); return glyph_height() * emoji->width() / emoji->height();
} }
int BitmapFont::width(StringView view) const { return unicode_view_width(Utf8View(view)); } int BitmapFont::width(StringView view) const { return unicode_view_width(Utf8View(view)); }

View file

@ -1226,17 +1226,13 @@ FLATTEN void Painter::draw_glyph(IntPoint const& point, u32 code_point, Font con
void Painter::draw_emoji(IntPoint const& point, Gfx::Bitmap const& emoji, Font const& font) void Painter::draw_emoji(IntPoint const& point, Gfx::Bitmap const& emoji, Font const& font)
{ {
if (!font.is_fixed_width()) IntRect dst_rect {
blit(point, emoji, emoji.rect()); point.x(),
else { point.y(),
IntRect dst_rect { font.glyph_height() * emoji.width() / emoji.height(),
point.x(), font.glyph_height()
point.y(), };
font.glyph_width('x'), draw_scaled_bitmap(dst_rect, emoji, emoji.rect());
font.glyph_height()
};
draw_scaled_bitmap(dst_rect, emoji, emoji.rect());
}
} }
void Painter::draw_glyph_or_emoji(IntPoint const& point, u32 code_point, Font const& font, Color color) void Painter::draw_glyph_or_emoji(IntPoint const& point, u32 code_point, Font const& font, Color color)