AmendHub

Download:

jcs

/

detritus

/

amendments

/

61

html_output: Honor <center> and <p align="center">

Support for this was added to TextView

jcs made amendment 61 about 1 year ago
--- html.c Thu Dec 12 12:08:30 2024 +++ html.c Fri Dec 13 21:41:20 2024 @@ -220,6 +220,8 @@ html_is_block_tag(struct html_page *html, html_tag_typ case HTML_TAG_SECTION: case HTML_TAG_UL: return true; + case HTML_TAG_CENTER: + return true; default: return false; } @@ -288,7 +290,7 @@ html_render_current_node(struct html_page *html, bool if (html->last_output != '\r' && html->last_output != '\0' && html_is_block_tag(html, el->type)) { HTML_DEBUG(("[block-separate:%s\\r]", html_tag_names[el->type])); - html_output_new_line(html->cookie, html); + html_output(html->cookie, html, "\r", 1); } /* if the element has a top margin, add more space */ @@ -299,7 +301,7 @@ html_render_current_node(struct html_page *html, bool html_tag_names[el->type])); } else { HTML_DEBUG(("[margin-top:%s\\r]", html_tag_names[el->type])); - html_output_new_line(html->cookie, html); + html_output(html->cookie, html, "\r", 1); } html->last_margin_bottom = 0; } @@ -426,7 +428,7 @@ html_render_current_node(struct html_page *html, bool /* brrrr */ if (el->type == HTML_TAG_BR) { HTML_DEBUG(("[br\\r]")); - html_output_new_line(html->cookie, html); + html_output(html->cookie, html, "\r", 1); have_height = true; } @@ -451,14 +453,14 @@ html_render_current_node(struct html_page *html, bool !(el->type == HTML_TAG_OL || el->type == HTML_TAG_UL) && !(el->type == HTML_TAG_LI && html->last_output == '\r')) { HTML_DEBUG(("[end-block:/%s\\r]", html_tag_names[el->type])); - html_output_new_line(html->cookie, html); + html_output(html->cookie, html, "\r", 1); } if (el->margin_bottom) { /* unless the last element had a bottom margin */ if (!html->last_margin_bottom) { HTML_DEBUG(("[margin-bottom\\r]")); - html_output_new_line(html->cookie, html); + html_output(html->cookie, html, "\r", 1); html->last_margin_bottom = el->margin_bottom; } } --- html.h Wed Dec 11 11:24:31 2024 +++ html.h Fri Dec 13 21:20:36 2024 @@ -37,7 +37,6 @@ extern short strncasecmp(const char *s1, const char *s #endif void html_output(void *cookie, struct html_page *html, char *str, size_t len); -void html_output_new_line(void *cookie, struct html_page *html); void html_debug(const char *fmt, ...); void html_have_title(void *cookie, struct html_page *html, char *str, size_t len); --- http.c Thu Dec 12 21:38:17 2024 +++ http.c Fri Dec 13 21:56:07 2024 @@ -244,135 +244,139 @@ void html_output(void *cookie, struct html_page *html, char *str, size_t len) { struct page *page = *((page_handle)cookie); - struct TVStyle style = { 0 }; - short n; + short n, j; + char *val; - style.font = geneva; - style.size = 10; - style.style = 0; + page->cur_style.font = geneva; + page->cur_style.size = 10; + page->cur_style.style = 0; + page->cur_style.align = TV_ALIGN_LEFT; for (n = 0; n < html->open_count; n++) { switch (html->open[n]->type) { case HTML_TAG_A: - style.style |= underline; + page->cur_style.style |= underline; break; case HTML_TAG_ADDRESS: - style.style |= italic; + page->cur_style.style |= italic; break; case HTML_TAG_B: - style.style |= bold | condense; + page->cur_style.style |= bold | condense; break; + case HTML_TAG_CENTER: + page->cur_style.align = TV_ALIGN_CENTER; + break; case HTML_TAG_CITE: - style.style |= italic; + page->cur_style.style |= italic; break; case HTML_TAG_CODE: - style.font = monaco; - style.size = 9; + page->cur_style.font = courier; + page->cur_style.size = 9; break; case HTML_TAG_DFN: - style.style |= italic; + page->cur_style.style |= italic; break; case HTML_TAG_EM: - style.style |= italic; + page->cur_style.style |= italic; break; case HTML_TAG_H1: /* 2em */ - style.size = 16; - style.style |= bold | condense; + page->cur_style.size = 20; + page->cur_style.style |= bold; break; case HTML_TAG_H2: /* 1.5em */ - style.size = 14; - style.style |= bold | condense; + page->cur_style.size = 14; + page->cur_style.style |= bold; break; case HTML_TAG_H3: /* 1.17em */ - style.size = 12; - style.style |= bold | condense; + page->cur_style.size = 12; + page->cur_style.style |= bold; break; case HTML_TAG_H4: /* 1em */ - style.size = 10; - style.style |= bold | condense; + page->cur_style.size = 10; + page->cur_style.style |= bold; break; case HTML_TAG_H5: /* 0.83em */ - style.size = 8; - style.style |= bold | condense; + page->cur_style.size = 9; + page->cur_style.style |= bold; break; case HTML_TAG_H6: /* 0.67em */ - style.size = 8; - style.style |= bold | condense; + page->cur_style.size = 9; + page->cur_style.style |= bold | condense; break; case HTML_TAG_I: - style.style |= italic; + page->cur_style.style |= italic; break; case HTML_TAG_INS: - style.style |= underline; + page->cur_style.style |= underline; break; case HTML_TAG_KBD: - style.font = monaco; - style.size = 9; + page->cur_style.font = courier; + page->cur_style.size = 9; break; case HTML_TAG_PRE: - style.font = monaco; - style.size = 9; + page->cur_style.font = courier; + page->cur_style.size = 9; break; case HTML_TAG_S: /* TODO: line-through */ break; case HTML_TAG_SAMP: - style.font = monaco; - style.size = 9; + page->cur_style.font = courier; + page->cur_style.size = 9; break; case HTML_TAG_SMALL: - style.size -= 2; + page->cur_style.size -= 2; break; case HTML_TAG_STRIKE: /* TODO: line-through */ break; case HTML_TAG_STRONG: - style.style |= bold | condense; + page->cur_style.style |= bold | condense; break; case HTML_TAG_SUP: - style.size -= 2; + page->cur_style.size -= 2; break; case HTML_TAG_TH: - style.style |= bold | condense; + page->cur_style.style |= bold | condense; break; case HTML_TAG_U: - style.style |= underline; + page->cur_style.style |= underline; break; case HTML_TAG_VAR: - style.style |= italic; + page->cur_style.style |= italic; break; } + + /* honor the "align" attribute on certain block elements */ + switch (html->open[n]->type) { + case HTML_TAG_DIV: + case HTML_TAG_P: + if (html_get_attribute_value(html, html->open[n], "align", + &val)) { + if (strcasecmp(val, "left") == 0) + page->cur_style.align = TV_ALIGN_LEFT; + else if (strcasecmp(val, "center") == 0) + page->cur_style.align = TV_ALIGN_CENTER; + else if (strcasecmp(val, "right") == 0) + page->cur_style.align = TV_ALIGN_RIGHT; + } + break; + } } - if (style.size < 8) - style.size = 8; + if (page->cur_style.size < 9) + page->cur_style.size = 9; - if (!TVAppend(page->browser->output_tv, &style, str, len)) + if (!TVAppend(page->browser->output_tv, &page->cur_style, str, len)) panic("out of memory in TVAppend"); html->last_output = str[len - 1]; -} - -void -html_output_new_line(void *cookie, struct html_page *html) -{ - struct page *page = *((page_handle)cookie); - struct TVStyle style = { 0 }; - - style.font = geneva; - style.size = 10; - style.style = 0; - - if (!TVAppend(page->browser->output_tv, &style, "\r", 1)) - panic("out of memory in TVAppend"); - - html->last_output = '\r'; } void --- main.c Thu Nov 21 11:47:00 2024 +++ main.c Fri Dec 13 22:54:07 2024 @@ -238,7 +238,7 @@ handle_menu(long menu_id) default: n = item - BOOKMARKS_MENU_SEP_ID - 1; if (settings.bookmark_uris[n][0] != '\0') - browser_go_uri(browser, settings.bookmark_uris[n]); + browser_go_uri_str(browser, settings.bookmark_uris[n]); break; } break;