mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,9 @@ public:
|
||||||
void draw_glyph_or_emoji(IntPoint const&, Utf8CodePointIterator&, Font const&, Color);
|
void draw_glyph_or_emoji(IntPoint const&, Utf8CodePointIterator&, Font const&, Color);
|
||||||
void draw_circle_arc_intersecting(IntRect const&, IntPoint const&, int radius, Color, int thickness);
|
void draw_circle_arc_intersecting(IntRect const&, IntPoint const&, int radius, Color, int thickness);
|
||||||
|
|
||||||
|
// Streamlined text drawing routine that does no wrapping/elision/alignment.
|
||||||
|
void draw_text_run(FloatPoint const& baseline_start, Utf8View const&, Font const&, Color);
|
||||||
|
|
||||||
enum class CornerOrientation {
|
enum class CornerOrientation {
|
||||||
TopLeft,
|
TopLeft,
|
||||||
TopRight,
|
TopRight,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue