System/Libraries/(Css,Graphics2D,Html): Support underlined text

This commit adds the necessary functions to minimally implement support
for CSS text-decoration: underline.
This commit is contained in:
Alec Murphy 2025-04-16 14:53:16 -04:00
parent 622c35e038
commit 24500f52a3
4 changed files with 64 additions and 0 deletions

View file

@ -1162,6 +1162,24 @@ I64 X2Pos(CDC* src)
return -1;
}
I64 Y2Pos(CDC* src)
{
I64 x = src->width - 1;
I64 y = src->height - 1;
I64 color;
while (y > -1) {
x = src->width - 1;
while (x > -1) {
color = GrPeek(src, x, y);
if (color)
return y;
x--;
}
y--;
}
return -1;
}
I64 @get_truetype_text_width(U8* font_name, I64 size, U8* text)
{
stbtt_fontinfo* font = Fonts->@(font_name);
@ -1178,6 +1196,26 @@ I64 @get_truetype_text_width(U8* font_name, I64 size, U8* text)
return res;
}
I64 @get_truetype_baseline(U8* font_name, I64 size)
{
stbtt_fontinfo* font = Fonts->@(font_name);
if (!font) {
return 0;
}
I64 res = 0;
CDC* dc = DCNew(Display.Width() / 2, (size * 2));
Free(dc->body);
I32 i32char[16];
MemSet(&i32char, NULL, 16);
i32char[0] = 'o';
dc->body = @stbtt_RenderText(font, dc->width_internal, dc->height, ToI64(size * 1.2), &i32char);
dc->width -= 16;
dc->height -= size / 4;
res = Y2Pos(dc);
DCDel(dc);
return res;
}
U0 Text2D(Context2D* ctx, U8* font_name, I64 x, I64 y, I64 size, U32 color, U8* text)
{
stbtt_fontinfo* font = Fonts->@(font_name);