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

@ -308,6 +308,7 @@ Bool @apply_css_rules_to_node(@html_dom_node* node, HtmlRenderer* renderer)
node->fontSize = node->parentNode->fontSize;
node->fontWeight = node->parentNode->fontWeight;
node->textAlign = node->parentNode->textAlign;
node->textDecoration = node->parentNode->textDecoration;
node->italic = node->parentNode->italic;
}
@ -425,6 +426,15 @@ Bool @apply_css_rules_to_node(@html_dom_node* node, HtmlRenderer* renderer)
if (!StrICmp(key->name, "text-align") && !StrICmp(values->@(0), "right"))
node->textAlign = CSS_TEXT_ALIGN_RIGHT;
if (!StrICmp(key->name, "text-decoration")) {
if (!StrICmp(values->@(0), "none")) {
node->textDecoration = 0;
}
if (!StrICmp(values->@(0), "underline")) {
node->textDecoration = CSS_TEXT_UNDERLINE;
}
}
if (!StrICmp(key->name, "line-height") && !StrICmp(values->@(0) + StrLen(values->@(0)) - 2, "px")) {
StrCpy(node_tmpnum_buf, values->@(0));
node_tmpnum_buf[StrLen(node_tmpnum_buf) - 2] = NULL;
@ -849,6 +859,7 @@ U0 @render_node_text(@html_dom_node* node, HtmlRenderer* renderer)
U32 fragment_bounding_box_color = Color(0x00, 0xff, 0x00);
U8* font_name = @resolved_font_name_for_node(node->parentNode);
I64 underline_y_pos = -1;
for (i = 0; i < fragment_count; i++) {
if (fragments[i] && *fragments[i]) {
@ -860,6 +871,18 @@ U0 @render_node_text(@html_dom_node* node, HtmlRenderer* renderer)
fragment_widget->data = node;
fragment_widget->ctx = NewContext2D(text_width, ToI64(node->parentNode->fontSize * 1.2))->fill(node->parentNode->backgroundColor)->text(font_name, 0, 0, node->parentNode->fontSize, node->parentNode->color, fragments[i]);
switch (node->parentNode->textDecoration) {
case CSS_TEXT_UNDERLINE:
if (underline_y_pos < 0)
underline_y_pos = @get_truetype_baseline(font_name, node->parentNode->fontSize) + 2;
if (!(underline_y_pos < 0)) {
fragment_widget->ctx->line(0, underline_y_pos, fragment_widget->ctx->width, underline_y_pos, node->parentNode->color);
}
break;
default:
break;
}
if (renderer->debug && fragment_widget->ctx) {
fragment_widget->ctx->line(0, 0, fragment_widget->ctx->width - 1, 0, fragment_bounding_box_color);
fragment_widget->ctx->line(0, fragment_widget->ctx->height - 1, fragment_widget->ctx->width - 1, fragment_widget->ctx->height - 1, fragment_bounding_box_color);