Everywhere: Changes to @html_dom_node and TrueType API

CSS properties fontFamily and fontSize are part of @html_dom_node now,
and the TrueType API only accepts I32 code point streams, so we have
to preprocess UTF-8 streams before rendering text.
This commit is contained in:
Alec Murphy 2025-04-12 18:09:26 -04:00
parent bef1c78c5d
commit df0adc0a15
4 changed files with 130 additions and 22 deletions

View file

@ -1171,7 +1171,7 @@ I64 @get_truetype_text_width(U8* font_name, I64 size, U8* text)
I64 res = 0;
CDC* dc = DCNew(Display.Width(), (size * 2));
Free(dc->body);
dc->body = @stbtt_RenderText(font, dc->width_internal, dc->height, ToI64(size * 1.5), text);
dc->body = @stbtt_RenderText(font, dc->width_internal, dc->height, ToI64(size * 1.2), text);
res = X2Pos(dc) - X1Pos(dc);
DCDel(dc);
return res;
@ -1186,7 +1186,7 @@ U0 Text2D(Context2D* ctx, U8* font_name, I64 x, I64 y, I64 size, U32 color, U8*
Context2D* text_ctx = NewContext2D(ctx->width, ctx->height);
CDC* dc = DCNew(ctx->width, ctx->height);
Free(dc->body);
dc->body = @stbtt_RenderText(font, dc->width_internal, dc->height, ToI64(size * 1.5), text);
dc->body = @stbtt_RenderText(font, dc->width_internal, dc->height, ToI64(size * 1.2), text);
I64 text_x, text_y, text_c;
for (text_y = 0; text_y < dc->height; text_y++) {
for (text_x = 0; text_x < dc->width; text_x++) {