mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:27:43 +00:00
LibGfx: Add Painter::draw_text_run(), a simplified text painting API
This API does: - Take a Utf8View - Take the starting point on the baseline as its input coordinate This API does not: - Align the text - Wrap the text - Elide too-long text into "..."
This commit is contained in:
parent
e398164f10
commit
7850628ff1
2 changed files with 22 additions and 0 deletions
|
@ -2314,4 +2314,23 @@ void Gfx::Painter::draw_ui_text(Gfx::IntRect const& rect, StringView text, Gfx::
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Painter::draw_text_run(FloatPoint const& baseline_start, Utf8View const& string, Font const& font, Color color)
|
||||
{
|
||||
auto pixel_metrics = font.pixel_metrics();
|
||||
float x = baseline_start.x();
|
||||
int y = baseline_start.y() - pixel_metrics.ascent;
|
||||
float space_width = font.glyph_or_emoji_width(' ');
|
||||
|
||||
for (auto code_point : string) {
|
||||
if (code_point == ' ') {
|
||||
x += space_width;
|
||||
continue;
|
||||
}
|
||||
float advance = font.glyph_or_emoji_width(code_point) + font.glyph_spacing();
|
||||
draw_glyph_or_emoji({ (int)roundf(x), y }, code_point, font, color);
|
||||
x += advance;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue