1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

document: Unify text style -> screen attribute handling

Currently, all DOM, HTML and plain renderers had their own routine for
conversion from text style to screen attribute. This moves text_style and
text_style_format from html/parser.h to renderer.h and introduces new generic
routine get_screen_chracter_template() that is used by all the specific
rendering engines.
This commit is contained in:
Petr Baudis 2007-08-28 20:39:15 +02:00 committed by Petr Baudis
parent 38ee8a137c
commit b66d2bec67
8 changed files with 72 additions and 68 deletions

View File

@ -216,7 +216,6 @@ dom_rss_push_document(struct dom_stack *stack, struct dom_node *root, void *xxx)
struct screen_char *template = &data->styles[type];
color_T background = document->options.default_bg;
color_T foreground = document->options.default_fg;
enum screen_char_attr attr = 0;
static int i_want_struct_module_for_dom;
static unsigned char *names[RSS_STYLES] = { "title", "aux" };
@ -238,7 +237,7 @@ dom_rss_push_document(struct dom_stack *stack, struct dom_node *root, void *xxx)
selector = find_css_selector(&css->selectors,
CST_ELEMENT, CSR_ROOT,
names[type], strlen(names[type]));
init_template_by_style(template, &document->options, background, foreground, attr,
init_template_by_style(template, &document->options, 0, foreground, background,
selector ? &selector->properties : NULL);
}

View File

@ -344,7 +344,6 @@ render_dom_document_start(struct dom_stack *stack, struct dom_node *node, void *
struct screen_char *template = &data->styles[type];
color_T background = document->options.default_bg;
color_T foreground = document->options.default_fg;
enum screen_char_attr attr = 0;
static int i_want_struct_module_for_dom;
struct dom_string *name = get_dom_node_type_name(type);
@ -373,7 +372,7 @@ render_dom_document_start(struct dom_stack *stack, struct dom_node *node, void *
selector = find_css_selector(&css->selectors,
CST_ELEMENT, CSR_ROOT,
name->string, name->length);
init_template_by_style(template, &document->options, background, foreground, attr,
init_template_by_style(template, &document->options, 0, foreground, background,
selector ? &selector->properties : NULL);
}

View File

@ -28,18 +28,14 @@
static inline void
init_template(struct screen_char *template, struct document_options *options,
color_T background, color_T foreground, enum screen_char_attr attr)
enum screen_char_attr attr, color_T foreground, color_T background)
{
struct color_pair colors = INIT_COLOR_PAIR(background, foreground);
struct text_style style = { attr, foreground, background };
template->attr = attr;
template->data = ' ';
set_term_color(template, &colors,
options->color_flags, options->color_mode);
get_screen_char_template(template, options, style);
}
inline void
void
init_template_by_style(struct screen_char *template, struct document_options *options,
color_T background, color_T foreground, enum screen_char_attr attr,
LIST_OF(struct css_property) *properties)
@ -47,6 +43,7 @@ init_template_by_style(struct screen_char *template, struct document_options *op
struct css_property *property;
if (properties) {
/* TODO: Use the CSS appliers. */
foreach (property, *properties) {
switch (property->type) {
case CSS_PT_BACKGROUND_COLOR:
@ -58,19 +55,13 @@ init_template_by_style(struct screen_char *template, struct document_options *op
foreground = property->value.color;
break;
case CSS_PT_FONT_WEIGHT:
if (property->value.font_attribute.add & AT_BOLD)
attr |= SCREEN_ATTR_BOLD;
attr |= property->value.font_attribute.add;
break;
case CSS_PT_FONT_STYLE:
if (property->value.font_attribute.add & AT_UNDERLINE)
attr |= SCREEN_ATTR_UNDERLINE;
if (property->value.font_attribute.add & AT_ITALIC)
attr |= SCREEN_ATTR_ITALIC;
attr |= property->value.font_attribute.add;
break;
case CSS_PT_TEXT_DECORATION:
if (property->value.font_attribute.add & AT_UNDERLINE)
attr |= SCREEN_ATTR_UNDERLINE;
attr |= property->value.font_attribute.add;
break;
case CSS_PT_DISPLAY:
case CSS_PT_NONE:
@ -82,7 +73,7 @@ init_template_by_style(struct screen_char *template, struct document_options *op
}
}
init_template(template, options, background, foreground, attr);
init_template(template, options, attr, foreground, background);
}
@ -305,7 +296,7 @@ add_dom_link(struct dom_renderer *renderer, unsigned char *string, int length,
link->number = document->nlinks;
init_template(&template, &document->options,
link->color.background, link->color.foreground, 0);
0, link->color.foreground, link->color.background);
render_dom_text(renderer, &template, string, length);

View File

@ -2,6 +2,7 @@
#ifndef EL__DOCUMENT_HTML_PARSER_H
#define EL__DOCUMENT_HTML_PARSER_H
#include "document/renderer.h"
#include "intl/charsets.h" /* unicode_val_T */
#include "util/align.h"
#include "util/color.h"
@ -21,21 +22,6 @@ struct uri;
* files - there's lack of any well defined interface and it's all randomly
* mixed up :/. */
enum text_style_format {
AT_BOLD = 1,
AT_ITALIC = 2,
AT_UNDERLINE = 4,
AT_FIXED = 8,
AT_GRAPHICS = 16,
AT_PREFORMATTED = 32,
};
struct text_style {
enum text_style_format attr;
color_T fg;
color_T bg;
};
struct text_attrib {
struct text_style style;

View File

@ -345,34 +345,14 @@ get_format_screen_char(struct html_context *html_context,
if (memcmp(&ta_cache, &format.style, sizeof(ta_cache))) {
copy_struct(&ta_cache, &format.style);
schar_cache.attr = 0;
if (format.style.attr) {
if (format.style.attr & AT_UNDERLINE) {
schar_cache.attr |= SCREEN_ATTR_UNDERLINE;
}
if (format.style.attr & AT_BOLD) {
schar_cache.attr |= SCREEN_ATTR_BOLD;
}
if (format.style.attr & AT_ITALIC) {
schar_cache.attr |= SCREEN_ATTR_ITALIC;
}
if (format.style.attr & AT_GRAPHICS) {
schar_cache.attr |= SCREEN_ATTR_FRAME;
}
}
struct text_style final_style = format.style;
if (link_state != LINK_STATE_NONE
&& html_context->options->underline_links) {
schar_cache.attr |= SCREEN_ATTR_UNDERLINE;
final_style.attr |= AT_UNDERLINE;
}
set_screen_char_color(&schar_cache, format.style.bg, format.style.fg,
html_context->options->color_flags,
html_context->options->color_mode);
get_screen_char_template(&schar_cache, html_context->options, final_style);
}
if (!!(schar_cache.attr & SCREEN_ATTR_UNSEARCHABLE)

View File

@ -478,14 +478,9 @@ next:
static void
init_template(struct screen_char *template, struct document_options *options)
{
color_T background = options->default_bg;
color_T foreground = options->default_fg;
struct color_pair colors = INIT_COLOR_PAIR(background, foreground);
struct text_style style = { 0, options->default_fg, options->default_bg };
template->attr = 0;
template->data = ' ';
set_term_color(template, &colors,
options->color_flags, options->color_mode);
get_screen_char_template(template, options, style);
}
static struct node *

View File

@ -31,6 +31,7 @@
#include "protocol/uri.h"
#include "session/location.h"
#include "session/session.h"
#include "terminal/draw.h"
#include "terminal/terminal.h"
#include "terminal/window.h"
#include "util/error.h"
@ -624,3 +625,36 @@ get_convert_table(unsigned char *head, int to_cp,
return get_translation_table(cp_index, to_cp);
}
void
get_screen_char_template(struct screen_char *template,
struct document_options *options,
struct text_style style)
{
template->attr = 0;
template->data = ' ';
if (style.attr) {
if (style.attr & AT_UNDERLINE) {
template->attr |= SCREEN_ATTR_UNDERLINE;
}
if (style.attr & AT_BOLD) {
template->attr |= SCREEN_ATTR_BOLD;
}
if (style.attr & AT_ITALIC) {
template->attr |= SCREEN_ATTR_ITALIC;
}
if (style.attr & AT_GRAPHICS) {
template->attr |= SCREEN_ATTR_FRAME;
}
}
{
struct color_pair colors = INIT_COLOR_PAIR(style.bg, style.fg);
set_term_color(template, &colors, options->color_flags, options->color_mode);
}
}

View File

@ -8,6 +8,26 @@ struct document_options;
struct document_view;
struct session;
struct view_state;
struct screen_char;
enum text_style_format {
AT_BOLD = 1,
AT_ITALIC = 2,
AT_UNDERLINE = 4,
AT_FIXED = 8,
AT_GRAPHICS = 16,
AT_PREFORMATTED = 32,
};
struct text_style {
enum text_style_format attr;
color_T fg;
color_T bg;
};
void get_screen_char_template(struct screen_char *template, struct document_options *options, struct text_style style);
void render_document(struct view_state *, struct document_view *, struct document_options *);
void render_document_frames(struct session *ses, int no_cache);