mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
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.
This commit is contained in:
parent
6947902b57
commit
65016cdca4
@ -27,11 +27,7 @@ enum format_attr {
|
|||||||
AT_UNDERLINE = 4,
|
AT_UNDERLINE = 4,
|
||||||
AT_FIXED = 8,
|
AT_FIXED = 8,
|
||||||
AT_GRAPHICS = 16,
|
AT_GRAPHICS = 16,
|
||||||
AT_SUBSCRIPT = 32,
|
AT_PREFORMATTED = 32,
|
||||||
AT_SUPERSCRIPT = 64,
|
|
||||||
AT_PREFORMATTED = 128,
|
|
||||||
AT_UPDATE_SUB = 256,
|
|
||||||
AT_UPDATE_SUP = 512,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct text_attrib_style {
|
struct text_attrib_style {
|
||||||
|
@ -80,14 +80,21 @@ void
|
|||||||
html_subscript(struct html_context *html_context, unsigned char *a,
|
html_subscript(struct html_context *html_context, unsigned char *a,
|
||||||
unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5)
|
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
|
void
|
||||||
html_superscript(struct html_context *html_context, unsigned char *a,
|
html_superscript(struct html_context *html_context, unsigned char *a,
|
||||||
unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5)
|
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
|
void
|
||||||
|
@ -42,7 +42,9 @@ element_handler_T html_span;
|
|||||||
element_handler_T html_style;
|
element_handler_T html_style;
|
||||||
element_handler_T html_style_close;
|
element_handler_T html_style_close;
|
||||||
element_handler_T html_subscript;
|
element_handler_T html_subscript;
|
||||||
|
element_handler_T html_subscript_close;
|
||||||
element_handler_T html_superscript;
|
element_handler_T html_superscript;
|
||||||
|
element_handler_T html_superscript_close;
|
||||||
element_handler_T html_table;
|
element_handler_T html_table;
|
||||||
element_handler_T html_td;
|
element_handler_T html_td;
|
||||||
element_handler_T html_th;
|
element_handler_T html_th;
|
||||||
|
@ -480,7 +480,7 @@ static struct element_info elements[] = {
|
|||||||
{"STRIKE", html_underline, NULL, 0, ET_NESTABLE },
|
{"STRIKE", html_underline, NULL, 0, ET_NESTABLE },
|
||||||
{"STRONG", html_bold, NULL, 0, ET_NESTABLE },
|
{"STRONG", html_bold, NULL, 0, ET_NESTABLE },
|
||||||
{"STYLE", html_style, html_style_close, 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 },
|
{"SUP", html_superscript, NULL, 0, ET_NESTABLE },
|
||||||
{"TABLE", html_table, NULL, 2, ET_NESTABLE },
|
{"TABLE", html_table, NULL, 2, ET_NESTABLE },
|
||||||
{"TD", html_td, NULL, 0, ET_NESTABLE },
|
{"TD", html_td, NULL, 0, ET_NESTABLE },
|
||||||
|
@ -338,7 +338,7 @@ get_format_screen_char(struct html_context *html_context,
|
|||||||
copy_struct(&ta_cache, &format.style);
|
copy_struct(&ta_cache, &format.style);
|
||||||
|
|
||||||
schar_cache.attr = 0;
|
schar_cache.attr = 0;
|
||||||
if (format.style.attr & ~(AT_UPDATE_SUB|AT_UPDATE_SUP)) {
|
if (format.style.attr) {
|
||||||
if (format.style.attr & AT_UNDERLINE) {
|
if (format.style.attr & AT_UNDERLINE) {
|
||||||
schar_cache.attr |= SCREEN_ATTR_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,
|
set_screen_char_color(&schar_cache, format.style.bg, format.style.fg,
|
||||||
html_context->options->color_flags,
|
html_context->options->color_flags,
|
||||||
html_context->options->color_mode);
|
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)
|
if (!!(schar_cache.attr & SCREEN_ATTR_UNSEARCHABLE)
|
||||||
@ -1293,7 +1265,6 @@ void
|
|||||||
put_chars(struct html_context *html_context, unsigned char *chars, int charslen)
|
put_chars(struct html_context *html_context, unsigned char *chars, int charslen)
|
||||||
{
|
{
|
||||||
enum link_state link_state;
|
enum link_state link_state;
|
||||||
int update_after_subscript = renderer_context.subscript;
|
|
||||||
struct part *part;
|
struct part *part;
|
||||||
|
|
||||||
assert(html_context);
|
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);
|
set_hline(html_context, chars, charslen, link_state);
|
||||||
|
|
||||||
if (link_state != LINK_STATE_NONE) {
|
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 <sub> and
|
|
||||||
* <sup> 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);
|
process_link(html_context, link_state, chars, charslen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user