From 65016cdca4364f18b8916a1c41c3453074466a27 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Sat, 27 May 2006 05:23:38 +0000 Subject: [PATCH] Fix superscript and subscript support Introduce html_subscript_close callback. Draw opening and closing brackets and carets for subscript and superscript text directly in the element handlers rather than performing weirdness in the renderer. This both improves readability and fixes bug 284, misplaced brackets with subscripts. --- src/document/html/parser.h | 6 +--- src/document/html/parser/general.c | 11 +++++-- src/document/html/parser/general.h | 2 ++ src/document/html/parser/parse.c | 2 +- src/document/html/renderer.c | 50 +----------------------------- 5 files changed, 14 insertions(+), 57 deletions(-) diff --git a/src/document/html/parser.h b/src/document/html/parser.h index fa178aa4f..b73ac877f 100644 --- a/src/document/html/parser.h +++ b/src/document/html/parser.h @@ -27,11 +27,7 @@ enum format_attr { AT_UNDERLINE = 4, AT_FIXED = 8, AT_GRAPHICS = 16, - AT_SUBSCRIPT = 32, - AT_SUPERSCRIPT = 64, - AT_PREFORMATTED = 128, - AT_UPDATE_SUB = 256, - AT_UPDATE_SUP = 512, + AT_PREFORMATTED = 32, }; struct text_attrib_style { diff --git a/src/document/html/parser/general.c b/src/document/html/parser/general.c index 1d0849f24..53ac592ce 100644 --- a/src/document/html/parser/general.c +++ b/src/document/html/parser/general.c @@ -80,14 +80,21 @@ void html_subscript(struct html_context *html_context, unsigned char *a, unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5) { - format.style.attr |= AT_SUBSCRIPT | AT_UPDATE_SUB; + html_context->put_chars_f(html_context, "[", 1); +} + +void +html_subscript_close(struct html_context *html_context, unsigned char *a, + unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5) +{ + html_context->put_chars_f(html_context, "]", 1); } void html_superscript(struct html_context *html_context, unsigned char *a, unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5) { - format.style.attr |= AT_SUPERSCRIPT | AT_UPDATE_SUP; + html_context->put_chars_f(html_context, "^", 1); } void diff --git a/src/document/html/parser/general.h b/src/document/html/parser/general.h index ba2b0c409..0abc41843 100644 --- a/src/document/html/parser/general.h +++ b/src/document/html/parser/general.h @@ -42,7 +42,9 @@ element_handler_T html_span; element_handler_T html_style; element_handler_T html_style_close; element_handler_T html_subscript; +element_handler_T html_subscript_close; element_handler_T html_superscript; +element_handler_T html_superscript_close; element_handler_T html_table; element_handler_T html_td; element_handler_T html_th; diff --git a/src/document/html/parser/parse.c b/src/document/html/parser/parse.c index dac91abeb..238d3e3ed 100644 --- a/src/document/html/parser/parse.c +++ b/src/document/html/parser/parse.c @@ -480,7 +480,7 @@ static struct element_info elements[] = { {"STRIKE", html_underline, NULL, 0, ET_NESTABLE }, {"STRONG", html_bold, NULL, 0, ET_NESTABLE }, {"STYLE", html_style, html_style_close, 0, ET_NESTABLE }, - {"SUB", html_subscript, NULL, 0, ET_NESTABLE }, + {"SUB", html_subscript, html_subscript_close, 0, ET_NESTABLE }, {"SUP", html_superscript, NULL, 0, ET_NESTABLE }, {"TABLE", html_table, NULL, 2, ET_NESTABLE }, {"TD", html_td, NULL, 0, ET_NESTABLE }, diff --git a/src/document/html/renderer.c b/src/document/html/renderer.c index d1d27d76f..f21e3e697 100644 --- a/src/document/html/renderer.c +++ b/src/document/html/renderer.c @@ -338,7 +338,7 @@ get_format_screen_char(struct html_context *html_context, copy_struct(&ta_cache, &format.style); schar_cache.attr = 0; - if (format.style.attr & ~(AT_UPDATE_SUB|AT_UPDATE_SUP)) { + if (format.style.attr) { if (format.style.attr & AT_UNDERLINE) { schar_cache.attr |= SCREEN_ATTR_UNDERLINE; } @@ -364,34 +364,6 @@ get_format_screen_char(struct html_context *html_context, set_screen_char_color(&schar_cache, format.style.bg, format.style.fg, html_context->options->color_flags, html_context->options->color_mode); - - if (html_context->options->display_subs) { - if (format.style.attr & AT_SUBSCRIPT) { - if (format.style.attr & AT_UPDATE_SUB) { - renderer_context.subscript++; - format.style.attr &= ~AT_UPDATE_SUB; - put_chars(html_context, "[", 1); - } - } else { - while (renderer_context.subscript) { - renderer_context.subscript--; - put_chars(html_context, "]", 1); - } - } - } - - if (html_context->options->display_sups) { - if (format.style.attr & AT_SUPERSCRIPT) { - if (format.style.attr & AT_UPDATE_SUP) { - renderer_context.supscript++; - format.style.attr &= ~AT_UPDATE_SUP; - put_chars(html_context, "^", 1); - } - } else { - while (renderer_context.supscript) - renderer_context.supscript--; - } - } } if (!!(schar_cache.attr & SCREEN_ATTR_UNSEARCHABLE) @@ -1293,7 +1265,6 @@ void put_chars(struct html_context *html_context, unsigned char *chars, int charslen) { enum link_state link_state; - int update_after_subscript = renderer_context.subscript; struct part *part; assert(html_context); @@ -1357,25 +1328,6 @@ put_chars(struct html_context *html_context, unsigned char *chars, int charslen) set_hline(html_context, chars, charslen, link_state); if (link_state != LINK_STATE_NONE) { - -#define is_drawing_subs_or_sups() \ - ((format.style.attr & AT_SUBSCRIPT \ - && html_context->options->display_subs) \ - || (format.style.attr & AT_SUPERSCRIPT \ - && html_context->options->display_sups)) - - /* We need to update the current @link_state because and - * tags will output to the canvas using an inner - * put_chars() call which results in their process_link() call - * will ``update'' the @link_state. */ - if (link_state == LINK_STATE_NEW - && (is_drawing_subs_or_sups() - || update_after_subscript != renderer_context.subscript)) { - link_state = get_link_state(html_context); - } - -#undef is_drawing_subs_or_sups - process_link(html_context, link_state, chars, charslen); }