1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 22:57:44 +00:00

LibGfx: Generalize glyph placement in Painter

This commit is contained in:
Stephan Unverwerth 2021-01-03 17:31:18 +01:00 committed by Andreas Kling
parent 972c7cf9f4
commit 79dfe9846d
3 changed files with 14 additions and 6 deletions

View file

@ -223,7 +223,12 @@ bool BitmapFont::write_to_file(const StringView& path)
Glyph BitmapFont::glyph(u32 code_point) const
{
return Glyph(GlyphBitmap(&m_rows[code_point * m_glyph_height], { glyph_width(code_point), m_glyph_height }));
auto width = glyph_width(code_point);
return Glyph(
GlyphBitmap(&m_rows[code_point * m_glyph_height], { width, m_glyph_height }),
0,
width,
m_glyph_height);
}
int BitmapFont::glyph_or_emoji_width(u32 code_point) const

View file

@ -70,8 +70,11 @@ private:
class Glyph {
public:
Glyph(const GlyphBitmap& glyph_bitmap)
Glyph(const GlyphBitmap& glyph_bitmap, int left_bearing, int advance, int ascent)
: m_glyph_bitmap(glyph_bitmap)
, m_left_bearing(left_bearing)
, m_advance(advance)
, m_ascent(ascent)
{
}

View file

@ -901,11 +901,11 @@ FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 code_point, Color co
FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 code_point, const Font& font, Color color)
{
auto glyph = font.glyph(code_point);
if (glyph.is_glyph_bitmap()) {
draw_bitmap(point, glyph.glyph_bitmap(), color);
} else {
auto top_left = point + IntPoint(glyph.left_bearing(), font.x_height() - glyph.ascent());
auto top_left = point + IntPoint(glyph.left_bearing(), font.glyph_height() - glyph.ascent());
if (glyph.is_glyph_bitmap()) {
draw_bitmap(top_left, glyph.glyph_bitmap(), color);
} else {
blit_filtered(top_left, *glyph.bitmap(), glyph.bitmap()->rect(), [color](Color pixel) -> Color {
return pixel.multiply(color);
});