mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:07:45 +00:00
LibGfx: Generalize glyph placement in Painter
This commit is contained in:
parent
972c7cf9f4
commit
79dfe9846d
3 changed files with 14 additions and 6 deletions
|
@ -223,7 +223,12 @@ bool BitmapFont::write_to_file(const StringView& path)
|
||||||
|
|
||||||
Glyph BitmapFont::glyph(u32 code_point) const
|
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
|
int BitmapFont::glyph_or_emoji_width(u32 code_point) const
|
||||||
|
|
|
@ -70,8 +70,11 @@ private:
|
||||||
|
|
||||||
class Glyph {
|
class Glyph {
|
||||||
public:
|
public:
|
||||||
Glyph(const GlyphBitmap& glyph_bitmap)
|
Glyph(const GlyphBitmap& glyph_bitmap, int left_bearing, int advance, int ascent)
|
||||||
: m_glyph_bitmap(glyph_bitmap)
|
: m_glyph_bitmap(glyph_bitmap)
|
||||||
|
, m_left_bearing(left_bearing)
|
||||||
|
, m_advance(advance)
|
||||||
|
, m_ascent(ascent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
FLATTEN void Painter::draw_glyph(const IntPoint& point, u32 code_point, const Font& font, Color color)
|
||||||
{
|
{
|
||||||
auto glyph = font.glyph(code_point);
|
auto glyph = font.glyph(code_point);
|
||||||
if (glyph.is_glyph_bitmap()) {
|
auto top_left = point + IntPoint(glyph.left_bearing(), font.glyph_height() - glyph.ascent());
|
||||||
draw_bitmap(point, glyph.glyph_bitmap(), color);
|
|
||||||
} else {
|
|
||||||
auto top_left = point + IntPoint(glyph.left_bearing(), font.x_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 {
|
blit_filtered(top_left, *glyph.bitmap(), glyph.bitmap()->rect(), [color](Color pixel) -> Color {
|
||||||
return pixel.multiply(color);
|
return pixel.multiply(color);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue