1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

Backport Pasky's changes concerning text_style-related stuff.

It partially includes changes made in following commits:

document/html: struct text_attrib_style -> struct text_style
commit    e133941206

document: struct format_attr -> struct text_style_format
commit    070d335796

document: Unify text style -> screen attribute handling
commit    b66d2bec67

document: Move text_style-related stuff to dedicated format.*
commit    db9431465f
This commit is contained in:
Laurent MONIN 2007-09-14 14:59:37 +02:00
parent 286a6a09d8
commit 09cf904814
15 changed files with 100 additions and 63 deletions

View File

@ -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

View File

@ -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"

View File

@ -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:

View File

@ -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 */

View File

@ -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 */

46
src/document/format.c Normal file
View File

@ -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);
}
}

28
src/document/format.h Normal file
View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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);