diff --git a/src/document/Makefile b/src/document/Makefile index 8014c251..8ea77ed2 100644 --- a/src/document/Makefile +++ b/src/document/Makefile @@ -6,6 +6,6 @@ SUBDIRS-$(CONFIG_DOM) += dom SUBDIRS = html plain -OBJS = docdata.o document.o forms.o options.o refresh.o renderer.o +OBJS = docdata.o document.o format.o forms.o options.o refresh.o renderer.o include $(top_srcdir)/Makefile.lib diff --git a/src/document/css/apply.c b/src/document/css/apply.c index 1e198ae8..7755046c 100644 --- a/src/document/css/apply.c +++ b/src/document/css/apply.c @@ -21,6 +21,7 @@ #include "document/css/property.h" #include "document/css/scanner.h" #include "document/css/stylesheet.h" +#include "document/format.h" #include "document/html/parser/parse.h" #include "document/options.h" #include "util/align.h" diff --git a/src/document/css/property.h b/src/document/css/property.h index c362801b..1d69cdbd 100644 --- a/src/document/css/property.h +++ b/src/document/css/property.h @@ -2,7 +2,8 @@ #ifndef EL__DOCUMENT_CSS_PROPERTY_H #define EL__DOCUMENT_CSS_PROPERTY_H -#include "document/html/parser.h" +#include "document/format.h" +#include "util/align.h" #include "util/color.h" #include "util/lists.h" @@ -48,7 +49,7 @@ struct css_property { CSS_DISP_BLOCK, } display; struct { - enum format_attr add, rem; + enum text_style_format add, rem; } font_attribute; enum format_align text_align; /* TODO: diff --git a/src/document/css/stylesheet.h b/src/document/css/stylesheet.h index 7928a921..670af934 100644 --- a/src/document/css/stylesheet.h +++ b/src/document/css/stylesheet.h @@ -2,6 +2,7 @@ #ifndef EL__DOCUMENT_CSS_STYLESHEET_H #define EL__DOCUMENT_CSS_STYLESHEET_H +#include "protocol/uri.h" #include "util/lists.h" /* #define DEBUG_CSS */ diff --git a/src/document/dom/renderer.c b/src/document/dom/renderer.c index 6391ff82..f1392702 100644 --- a/src/document/dom/renderer.c +++ b/src/document/dom/renderer.c @@ -1038,7 +1038,7 @@ render_dom_document(struct cache_entry *cached, struct document *document, init_dom_renderer(&renderer, document, buffer, convert_table); - document->bgcolor = document->options.default_bg; + document->bgcolor = document->options.default_style.bg; #ifdef CONFIG_UTF8 document->options.utf8 = is_cp_utf8(document->options.cp); #endif /* CONFIG_UTF8 */ diff --git a/src/document/format.c b/src/document/format.c new file mode 100644 index 00000000..bcae2ac0 --- /dev/null +++ b/src/document/format.c @@ -0,0 +1,46 @@ +/** Format attributes utilities + * @file */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "elinks.h" + +#include "document/format.h" +#include "document/options.h" +#include "terminal/draw.h" +#include "util/color.h" + + +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); + } +} diff --git a/src/document/format.h b/src/document/format.h new file mode 100644 index 00000000..c38d96d8 --- /dev/null +++ b/src/document/format.h @@ -0,0 +1,28 @@ +#ifndef EL__DOCUMENT_FORMAT_H +#define EL__DOCUMENT_FORMAT_H + +#include "util/color.h" + +struct document_options; +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); + +#endif + diff --git a/src/document/html/parser.c b/src/document/html/parser.c index 220cec0c..31387676 100644 --- a/src/document/html/parser.c +++ b/src/document/html/parser.c @@ -896,8 +896,7 @@ init_html_parser(struct uri *uri, struct document_options *options, format.form = NULL; format.title = NULL; - format.style.fg = options->default_fg; - format.style.bg = options->default_bg; + format.style = options->default_style; format.clink = options->default_link; format.vlink = options->default_vlink; #ifdef CONFIG_BOOKMARKS @@ -914,7 +913,7 @@ init_html_parser(struct uri *uri, struct document_options *options, par_format.dd_margin = options->margin; par_format.flags = P_NONE; - par_format.bgcolor = options->default_bg; + par_format.bgcolor = options->default_style.bg; html_top->invisible = 0; html_top->name = NULL; diff --git a/src/document/html/parser.h b/src/document/html/parser.h index c10cb8a8..816ca0aa 100644 --- a/src/document/html/parser.h +++ b/src/document/html/parser.h @@ -2,6 +2,7 @@ #ifndef EL__DOCUMENT_HTML_PARSER_H #define EL__DOCUMENT_HTML_PARSER_H +#include "document/format.h" #include "intl/charsets.h" /* unicode_val_T */ #include "util/align.h" #include "util/color.h" @@ -21,23 +22,8 @@ struct uri; * files - there's lack of any well defined interface and it's all randomly * mixed up :/. */ -enum format_attr { - AT_BOLD = 1, - AT_ITALIC = 2, - AT_UNDERLINE = 4, - AT_FIXED = 8, - AT_GRAPHICS = 16, - AT_PREFORMATTED = 32, -}; - -struct text_attrib_style { - enum format_attr attr; - color_T fg; - color_T bg; -}; - struct text_attrib { - struct text_attrib_style style; + struct text_style style; int fontsize; unsigned char *link; diff --git a/src/document/html/parser/general.c b/src/document/html/parser/general.c index 0dbff5e9..bd653a5c 100644 --- a/src/document/html/parser/general.c +++ b/src/document/html/parser/general.c @@ -197,7 +197,7 @@ html_apply_canvas_bgcolor(struct html_context *html_context) } if (html_context->has_link_lines - && par_format.bgcolor != html_context->options->default_bg + && par_format.bgcolor != html_context->options->default_style.bg && !search_html_stack(html_context, "BODY")) { html_context->special_f(html_context, SP_COLOR_LINK_LINES); } diff --git a/src/document/html/renderer.c b/src/document/html/renderer.c index 2e4f801d..c62586f6 100644 --- a/src/document/html/renderer.c +++ b/src/document/html/renderer.c @@ -340,39 +340,19 @@ static inline struct screen_char * get_format_screen_char(struct html_context *html_context, enum link_state link_state) { - static struct text_attrib_style ta_cache = { -1, 0x0, 0x0 }; + static struct text_style ta_cache = { -1, 0x0, 0x0 }; static struct screen_char schar_cache; 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) diff --git a/src/document/options.c b/src/document/options.c index 8d77ce89..b8a697b5 100644 --- a/src/document/options.c +++ b/src/document/options.c @@ -37,8 +37,8 @@ init_document_options(struct document_options *doo) doo->default_form_input_size = get_opt_int("document.browse.forms.input_size"); /* Color options. */ - doo->default_fg = get_opt_color("document.colors.text"); - doo->default_bg = get_opt_color("document.colors.background"); + doo->default_style.fg = get_opt_color("document.colors.text"); + doo->default_style.bg = get_opt_color("document.colors.background"); doo->default_link = get_opt_color("document.colors.link"); doo->default_vlink = get_opt_color("document.colors.vlink"); #ifdef CONFIG_BOOKMARKS diff --git a/src/document/options.h b/src/document/options.h index dd5f6bb7..19ad801e 100644 --- a/src/document/options.h +++ b/src/document/options.h @@ -1,6 +1,7 @@ #ifndef EL__DOCUMENT_OPTIONS_H #define EL__DOCUMENT_OPTIONS_H +#include "document/format.h" #include "terminal/color.h" #include "util/color.h" #include "util/box.h" @@ -34,8 +35,7 @@ struct document_options { /** @name The default (fallback) colors. * @{ */ - color_T default_fg; - color_T default_bg; + struct text_style default_style; color_T default_link; color_T default_vlink; #ifdef CONFIG_BOOKMARKS diff --git a/src/document/plain/renderer.c b/src/document/plain/renderer.c index 3d4cde91..99cfbf05 100644 --- a/src/document/plain/renderer.c +++ b/src/document/plain/renderer.c @@ -14,6 +14,7 @@ #include "config/options.h" #include "document/docdata.h" #include "document/document.h" +#include "document/format.h" #include "document/options.h" #include "document/plain/renderer.h" #include "document/renderer.h" @@ -92,7 +93,7 @@ add_document_link(struct document *document, unsigned char *uri, int length, link->npoints = length; link->type = LINK_HYPERTEXT; link->where = uri; - link->color.background = document->options.default_bg; + link->color.background = document->options.default_style.bg; link->color.foreground = document->options.default_link; link->number = document->nlinks; @@ -213,7 +214,7 @@ print_document_link(struct plain_renderer *renderer, int lineno, line[link_end] = saved_char; - new_link->color.background = doc_opts->default_bg; + new_link->color.background = doc_opts->default_style.bg; set_term_color(&template, &new_link->color, doc_opts->color_flags, doc_opts->color_mode); @@ -478,14 +479,7 @@ 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); - - template->attr = 0; - template->data = ' '; - set_term_color(template, &colors, - options->color_flags, options->color_mode); + get_screen_char_template(template, options, options->default_style); } static struct node * @@ -643,7 +637,7 @@ render_plain_document(struct cache_entry *cached, struct document *document, renderer.max_width = document->options.wrap ? document->options.box.width : INT_MAX; - document->bgcolor = document->options.default_bg; + document->bgcolor = document->options.default_style.bg; document->width = 0; #ifdef CONFIG_UTF8 document->options.utf8 = is_cp_utf8(document->options.cp); diff --git a/src/document/renderer.h b/src/document/renderer.h index 8cc828d7..350d7964 100644 --- a/src/document/renderer.h +++ b/src/document/renderer.h @@ -8,6 +8,7 @@ struct document_options; struct document_view; struct session; struct view_state; +struct screen_char; void render_document(struct view_state *, struct document_view *, struct document_options *); void render_document_frames(struct session *ses, int no_cache);