System/Libraries/Html/Renderer: Handle italic/oblique text
This commit is contained in:
parent
97187728e8
commit
0a579a4f09
1 changed files with 33 additions and 22 deletions
|
@ -307,6 +307,7 @@ Bool @apply_css_rules_to_node(@html_dom_node* node, HtmlRenderer* renderer)
|
||||||
node->fontSize = node->parentNode->fontSize;
|
node->fontSize = node->parentNode->fontSize;
|
||||||
node->fontWeight = node->parentNode->fontWeight;
|
node->fontWeight = node->parentNode->fontWeight;
|
||||||
node->textAlign = node->parentNode->textAlign;
|
node->textAlign = node->parentNode->textAlign;
|
||||||
|
node->italic = node->parentNode->italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < renderer->css_rules->length; i++) {
|
for (i = 0; i < renderer->css_rules->length; i++) {
|
||||||
|
@ -464,6 +465,12 @@ Bool @apply_css_rules_to_node(@html_dom_node* node, HtmlRenderer* renderer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!StrICmp(key->name, "font-style")) {
|
||||||
|
if (!StrICmp(values->@(0), "italic")) {
|
||||||
|
node->italic = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
css_continue_to_next_property:
|
css_continue_to_next_property:
|
||||||
key = key->next;
|
key = key->next;
|
||||||
}
|
}
|
||||||
|
@ -720,31 +727,31 @@ Bool @code_point_is_whitespace(I32 code_point)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
U8* @resolved_font_weight_for_node(@html_dom_node* node)
|
U8* @resolved_font_name_for_node(@html_dom_node* node)
|
||||||
{
|
{
|
||||||
U8 buf[128];
|
|
||||||
if (!node || !node->fontFamily || !StrLen(node->fontFamily))
|
if (!node || !node->fontFamily || !StrLen(node->fontFamily))
|
||||||
return;
|
return NULL;
|
||||||
switch (node->fontWeight) {
|
|
||||||
case 700:
|
U8* font_name_with_weight_applied = node->fontFamily;
|
||||||
case 800:
|
U8 buf[128];
|
||||||
case 900:
|
|
||||||
if (!StrICmp(node->fontFamily + StrLen(node->fontFamily) - 4, "bold")) {
|
// Handle font weight
|
||||||
return node->fontFamily;
|
if (node->fontWeight >= 700 && StrICmp(node->fontFamily + StrLen(node->fontFamily) - 4, "bold")) {
|
||||||
} else {
|
|
||||||
StrPrint(buf, "%s Bold", node->fontFamily);
|
StrPrint(buf, "%s Bold", node->fontFamily);
|
||||||
|
if (Fonts->@(buf)) {
|
||||||
|
font_name_with_weight_applied = StrNew(buf, erythros_mem_task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle italic
|
||||||
|
if (node->italic) {
|
||||||
|
StrPrint(buf, "%s Italic", font_name_with_weight_applied);
|
||||||
if (Fonts->@(buf)) {
|
if (Fonts->@(buf)) {
|
||||||
return StrNew(buf, erythros_mem_task);
|
return StrNew(buf, erythros_mem_task);
|
||||||
} else {
|
|
||||||
// Can't find Bold variant, return Normal
|
|
||||||
return node->fontFamily;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
default:
|
return font_name_with_weight_applied;
|
||||||
return node->fontFamily;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
U0 @render_node_text(@html_dom_node* node, HtmlRenderer* renderer)
|
U0 @render_node_text(@html_dom_node* node, HtmlRenderer* renderer)
|
||||||
|
@ -794,7 +801,7 @@ U0 @render_node_text(@html_dom_node* node, HtmlRenderer* renderer)
|
||||||
Context2DWidget* fragment_widget;
|
Context2DWidget* fragment_widget;
|
||||||
|
|
||||||
U32 fragment_bounding_box_color = Color(0x00, 0xff, 0x00);
|
U32 fragment_bounding_box_color = Color(0x00, 0xff, 0x00);
|
||||||
U8* font_name = @resolved_font_weight_for_node(node->parentNode);
|
U8* font_name = @resolved_font_name_for_node(node->parentNode);
|
||||||
|
|
||||||
for (i = 0; i < fragment_count; i++) {
|
for (i = 0; i < fragment_count; i++) {
|
||||||
if (fragments[i] && *fragments[i]) {
|
if (fragments[i] && *fragments[i]) {
|
||||||
|
@ -911,6 +918,10 @@ U0 @render_node_list(@html_dom_node* node, HtmlRenderer* renderer)
|
||||||
node->fontWeight = 700;
|
node->fontWeight = 700;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!StrICmp(node->tagName, "i") || !StrICmp(node->tagName, "em")) {
|
||||||
|
node->italic = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!StrICmp(node->tagName, "body")) {
|
if (!StrICmp(node->tagName, "body")) {
|
||||||
renderer->background_ctx->width = Display.Width();
|
renderer->background_ctx->width = Display.Width();
|
||||||
renderer->background_ctx->height = Display.Height();
|
renderer->background_ctx->height = Display.Height();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue