mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Attempt to improve sub/sup rendering. Now 2<sup>2<sup>2</sup></sup> is
rendered as 2^2^2 and mixed sub/sup should be rendered in a better way. A bit hacky though.
This commit is contained in:
parent
80af673860
commit
7392b8c503
@ -33,6 +33,8 @@ enum format_attr {
|
|||||||
AT_SUBSCRIPT = 32,
|
AT_SUBSCRIPT = 32,
|
||||||
AT_SUPERSCRIPT = 64,
|
AT_SUPERSCRIPT = 64,
|
||||||
AT_PREFORMATTED = 128,
|
AT_PREFORMATTED = 128,
|
||||||
|
AT_UPDATE_SUB = 256,
|
||||||
|
AT_UPDATE_SUP = 512,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct text_attrib_style {
|
struct text_attrib_style {
|
||||||
|
@ -73,13 +73,13 @@ html_fixed(struct html_context *html_context, unsigned char *a)
|
|||||||
void
|
void
|
||||||
html_subscript(struct html_context *html_context, unsigned char *a)
|
html_subscript(struct html_context *html_context, unsigned char *a)
|
||||||
{
|
{
|
||||||
format.style.attr |= AT_SUBSCRIPT;
|
format.style.attr |= AT_SUBSCRIPT | AT_UPDATE_SUB;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
html_superscript(struct html_context *html_context, unsigned char *a)
|
html_superscript(struct html_context *html_context, unsigned char *a)
|
||||||
{
|
{
|
||||||
format.style.attr |= AT_SUPERSCRIPT;
|
format.style.attr |= AT_SUPERSCRIPT | AT_UPDATE_SUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -114,13 +114,13 @@ struct renderer_context {
|
|||||||
struct cache_entry *cached;
|
struct cache_entry *cached;
|
||||||
|
|
||||||
int g_ctrl_num;
|
int g_ctrl_num;
|
||||||
|
int subscript; /* Count stacked subscripts */
|
||||||
|
int supscript; /* Count stacked supscripts */
|
||||||
|
|
||||||
unsigned int empty_format:1;
|
unsigned int empty_format:1;
|
||||||
unsigned int nobreak:1;
|
unsigned int nobreak:1;
|
||||||
unsigned int nosearchable:1;
|
unsigned int nosearchable:1;
|
||||||
unsigned int nowrap:1; /* Activated/deactivated by SP_NOWRAP. */
|
unsigned int nowrap:1; /* Activated/deactivated by SP_NOWRAP. */
|
||||||
unsigned int did_subscript:1;
|
|
||||||
unsigned int did_superscript:1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct renderer_context renderer_context;
|
static struct renderer_context renderer_context;
|
||||||
@ -330,15 +330,10 @@ get_format_screen_char(struct html_context *html_context,
|
|||||||
static struct screen_char schar_cache;
|
static struct screen_char schar_cache;
|
||||||
|
|
||||||
if (memcmp(&ta_cache, &format.style, sizeof(ta_cache))) {
|
if (memcmp(&ta_cache, &format.style, sizeof(ta_cache))) {
|
||||||
struct color_pair colors = INIT_COLOR_PAIR(format.style.bg, format.style.fg);
|
copy_struct(&ta_cache, &format.style);
|
||||||
static enum color_mode color_mode;
|
|
||||||
static enum color_flags color_flags;
|
|
||||||
|
|
||||||
color_mode = html_context->options->color_mode;
|
|
||||||
color_flags = html_context->options->color_flags;
|
|
||||||
|
|
||||||
schar_cache.attr = 0;
|
schar_cache.attr = 0;
|
||||||
if (format.style.attr) {
|
if (format.style.attr & ~(AT_UPDATE_SUB|AT_UPDATE_SUP)) {
|
||||||
if (format.style.attr & AT_UNDERLINE) {
|
if (format.style.attr & AT_UNDERLINE) {
|
||||||
schar_cache.attr |= SCREEN_ATTR_UNDERLINE;
|
schar_cache.attr |= SCREEN_ATTR_UNDERLINE;
|
||||||
}
|
}
|
||||||
@ -361,33 +356,40 @@ get_format_screen_char(struct html_context *html_context,
|
|||||||
schar_cache.attr |= SCREEN_ATTR_UNDERLINE;
|
schar_cache.attr |= SCREEN_ATTR_UNDERLINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_struct(&ta_cache, &format.style);
|
{
|
||||||
set_term_color(&schar_cache, &colors, color_flags, color_mode);
|
struct color_pair colors = INIT_COLOR_PAIR(format.style.bg,
|
||||||
|
format.style.fg);
|
||||||
|
|
||||||
|
set_term_color(&schar_cache, &colors,
|
||||||
|
html_context->options->color_flags,
|
||||||
|
html_context->options->color_mode);
|
||||||
|
}
|
||||||
|
|
||||||
if (html_context->options->display_subs) {
|
if (html_context->options->display_subs) {
|
||||||
if (format.style.attr & AT_SUBSCRIPT) {
|
if (format.style.attr & AT_SUBSCRIPT) {
|
||||||
if (!renderer_context.did_subscript) {
|
if (format.style.attr & AT_UPDATE_SUB) {
|
||||||
renderer_context.did_subscript = 1;
|
renderer_context.subscript++;
|
||||||
|
format.style.attr &= ~AT_UPDATE_SUB;
|
||||||
put_chars(html_context, "[", 1);
|
put_chars(html_context, "[", 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (renderer_context.did_subscript) {
|
while (renderer_context.subscript) {
|
||||||
|
renderer_context.subscript--;
|
||||||
put_chars(html_context, "]", 1);
|
put_chars(html_context, "]", 1);
|
||||||
renderer_context.did_subscript = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (html_context->options->display_sups) {
|
if (html_context->options->display_sups) {
|
||||||
if (format.style.attr & AT_SUPERSCRIPT) {
|
if (format.style.attr & AT_SUPERSCRIPT) {
|
||||||
if (!renderer_context.did_superscript) {
|
if (format.style.attr & AT_UPDATE_SUP) {
|
||||||
renderer_context.did_superscript = 1;
|
renderer_context.supscript++;
|
||||||
|
format.style.attr &= ~AT_UPDATE_SUP;
|
||||||
put_chars(html_context, "^", 1);
|
put_chars(html_context, "^", 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (renderer_context.did_superscript) {
|
while (renderer_context.supscript)
|
||||||
renderer_context.did_superscript = 0;
|
renderer_context.supscript--;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1270,7 +1272,7 @@ 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.did_subscript;
|
int update_after_subscript = renderer_context.subscript;
|
||||||
struct part *part;
|
struct part *part;
|
||||||
|
|
||||||
assert(html_context);
|
assert(html_context);
|
||||||
@ -1340,7 +1342,7 @@ put_chars(struct html_context *html_context, unsigned char *chars, int charslen)
|
|||||||
* will ``update'' the @link_state. */
|
* will ``update'' the @link_state. */
|
||||||
if (link_state == LINK_STATE_NEW
|
if (link_state == LINK_STATE_NEW
|
||||||
&& (is_drawing_subs_or_sups()
|
&& (is_drawing_subs_or_sups()
|
||||||
|| update_after_subscript != renderer_context.did_subscript)) {
|
|| update_after_subscript != renderer_context.subscript)) {
|
||||||
link_state = get_link_state(html_context);
|
link_state = get_link_state(html_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user