mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -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 e1339412068f97be1aa5f91871ba7ebeedbdb5f document: struct format_attr -> struct text_style_format commit 070d335796c3e71c5feff8813e681ef4534ee016 document: Unify text style -> screen attribute handling commit b66d2bec674f59016ca0708c20249421914b1d2b document: Move text_style-related stuff to dedicated format.* commit db9431465fd77658cfe804947ab336158c1974bd
This commit is contained in:
parent
286a6a09d8
commit
09cf904814
@ -6,6 +6,6 @@ SUBDIRS-$(CONFIG_DOM) += dom
|
|||||||
|
|
||||||
SUBDIRS = html plain
|
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
|
include $(top_srcdir)/Makefile.lib
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "document/css/property.h"
|
#include "document/css/property.h"
|
||||||
#include "document/css/scanner.h"
|
#include "document/css/scanner.h"
|
||||||
#include "document/css/stylesheet.h"
|
#include "document/css/stylesheet.h"
|
||||||
|
#include "document/format.h"
|
||||||
#include "document/html/parser/parse.h"
|
#include "document/html/parser/parse.h"
|
||||||
#include "document/options.h"
|
#include "document/options.h"
|
||||||
#include "util/align.h"
|
#include "util/align.h"
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
#ifndef EL__DOCUMENT_CSS_PROPERTY_H
|
#ifndef EL__DOCUMENT_CSS_PROPERTY_H
|
||||||
#define 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/color.h"
|
||||||
#include "util/lists.h"
|
#include "util/lists.h"
|
||||||
|
|
||||||
@ -48,7 +49,7 @@ struct css_property {
|
|||||||
CSS_DISP_BLOCK,
|
CSS_DISP_BLOCK,
|
||||||
} display;
|
} display;
|
||||||
struct {
|
struct {
|
||||||
enum format_attr add, rem;
|
enum text_style_format add, rem;
|
||||||
} font_attribute;
|
} font_attribute;
|
||||||
enum format_align text_align;
|
enum format_align text_align;
|
||||||
/* TODO:
|
/* TODO:
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#ifndef EL__DOCUMENT_CSS_STYLESHEET_H
|
#ifndef EL__DOCUMENT_CSS_STYLESHEET_H
|
||||||
#define EL__DOCUMENT_CSS_STYLESHEET_H
|
#define EL__DOCUMENT_CSS_STYLESHEET_H
|
||||||
|
|
||||||
|
#include "protocol/uri.h"
|
||||||
#include "util/lists.h"
|
#include "util/lists.h"
|
||||||
|
|
||||||
/* #define DEBUG_CSS */
|
/* #define DEBUG_CSS */
|
||||||
|
@ -1038,7 +1038,7 @@ render_dom_document(struct cache_entry *cached, struct document *document,
|
|||||||
|
|
||||||
init_dom_renderer(&renderer, document, buffer, convert_table);
|
init_dom_renderer(&renderer, document, buffer, convert_table);
|
||||||
|
|
||||||
document->bgcolor = document->options.default_bg;
|
document->bgcolor = document->options.default_style.bg;
|
||||||
#ifdef CONFIG_UTF8
|
#ifdef CONFIG_UTF8
|
||||||
document->options.utf8 = is_cp_utf8(document->options.cp);
|
document->options.utf8 = is_cp_utf8(document->options.cp);
|
||||||
#endif /* CONFIG_UTF8 */
|
#endif /* CONFIG_UTF8 */
|
||||||
|
46
src/document/format.c
Normal file
46
src/document/format.c
Normal 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
28
src/document/format.h
Normal 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
|
||||||
|
|
@ -896,8 +896,7 @@ init_html_parser(struct uri *uri, struct document_options *options,
|
|||||||
format.form = NULL;
|
format.form = NULL;
|
||||||
format.title = NULL;
|
format.title = NULL;
|
||||||
|
|
||||||
format.style.fg = options->default_fg;
|
format.style = options->default_style;
|
||||||
format.style.bg = options->default_bg;
|
|
||||||
format.clink = options->default_link;
|
format.clink = options->default_link;
|
||||||
format.vlink = options->default_vlink;
|
format.vlink = options->default_vlink;
|
||||||
#ifdef CONFIG_BOOKMARKS
|
#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.dd_margin = options->margin;
|
||||||
par_format.flags = P_NONE;
|
par_format.flags = P_NONE;
|
||||||
|
|
||||||
par_format.bgcolor = options->default_bg;
|
par_format.bgcolor = options->default_style.bg;
|
||||||
|
|
||||||
html_top->invisible = 0;
|
html_top->invisible = 0;
|
||||||
html_top->name = NULL;
|
html_top->name = NULL;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#ifndef EL__DOCUMENT_HTML_PARSER_H
|
#ifndef EL__DOCUMENT_HTML_PARSER_H
|
||||||
#define EL__DOCUMENT_HTML_PARSER_H
|
#define EL__DOCUMENT_HTML_PARSER_H
|
||||||
|
|
||||||
|
#include "document/format.h"
|
||||||
#include "intl/charsets.h" /* unicode_val_T */
|
#include "intl/charsets.h" /* unicode_val_T */
|
||||||
#include "util/align.h"
|
#include "util/align.h"
|
||||||
#include "util/color.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
|
* files - there's lack of any well defined interface and it's all randomly
|
||||||
* mixed up :/. */
|
* 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 {
|
||||||
struct text_attrib_style style;
|
struct text_style style;
|
||||||
|
|
||||||
int fontsize;
|
int fontsize;
|
||||||
unsigned char *link;
|
unsigned char *link;
|
||||||
|
@ -197,7 +197,7 @@ html_apply_canvas_bgcolor(struct html_context *html_context)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (html_context->has_link_lines
|
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")) {
|
&& !search_html_stack(html_context, "BODY")) {
|
||||||
html_context->special_f(html_context, SP_COLOR_LINK_LINES);
|
html_context->special_f(html_context, SP_COLOR_LINK_LINES);
|
||||||
}
|
}
|
||||||
|
@ -340,39 +340,19 @@ static inline struct screen_char *
|
|||||||
get_format_screen_char(struct html_context *html_context,
|
get_format_screen_char(struct html_context *html_context,
|
||||||
enum link_state link_state)
|
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;
|
static struct screen_char schar_cache;
|
||||||
|
|
||||||
if (memcmp(&ta_cache, &format.style, sizeof(ta_cache))) {
|
if (memcmp(&ta_cache, &format.style, sizeof(ta_cache))) {
|
||||||
copy_struct(&ta_cache, &format.style);
|
copy_struct(&ta_cache, &format.style);
|
||||||
|
struct text_style final_style = 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (link_state != LINK_STATE_NONE
|
if (link_state != LINK_STATE_NONE
|
||||||
&& html_context->options->underline_links) {
|
&& 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,
|
get_screen_char_template(&schar_cache, html_context->options, final_style);
|
||||||
html_context->options->color_flags,
|
|
||||||
html_context->options->color_mode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!!(schar_cache.attr & SCREEN_ATTR_UNSEARCHABLE)
|
if (!!(schar_cache.attr & SCREEN_ATTR_UNSEARCHABLE)
|
||||||
|
@ -37,8 +37,8 @@ init_document_options(struct document_options *doo)
|
|||||||
doo->default_form_input_size = get_opt_int("document.browse.forms.input_size");
|
doo->default_form_input_size = get_opt_int("document.browse.forms.input_size");
|
||||||
|
|
||||||
/* Color options. */
|
/* Color options. */
|
||||||
doo->default_fg = get_opt_color("document.colors.text");
|
doo->default_style.fg = get_opt_color("document.colors.text");
|
||||||
doo->default_bg = get_opt_color("document.colors.background");
|
doo->default_style.bg = get_opt_color("document.colors.background");
|
||||||
doo->default_link = get_opt_color("document.colors.link");
|
doo->default_link = get_opt_color("document.colors.link");
|
||||||
doo->default_vlink = get_opt_color("document.colors.vlink");
|
doo->default_vlink = get_opt_color("document.colors.vlink");
|
||||||
#ifdef CONFIG_BOOKMARKS
|
#ifdef CONFIG_BOOKMARKS
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef EL__DOCUMENT_OPTIONS_H
|
#ifndef EL__DOCUMENT_OPTIONS_H
|
||||||
#define EL__DOCUMENT_OPTIONS_H
|
#define EL__DOCUMENT_OPTIONS_H
|
||||||
|
|
||||||
|
#include "document/format.h"
|
||||||
#include "terminal/color.h"
|
#include "terminal/color.h"
|
||||||
#include "util/color.h"
|
#include "util/color.h"
|
||||||
#include "util/box.h"
|
#include "util/box.h"
|
||||||
@ -34,8 +35,7 @@ struct document_options {
|
|||||||
|
|
||||||
/** @name The default (fallback) colors.
|
/** @name The default (fallback) colors.
|
||||||
* @{ */
|
* @{ */
|
||||||
color_T default_fg;
|
struct text_style default_style;
|
||||||
color_T default_bg;
|
|
||||||
color_T default_link;
|
color_T default_link;
|
||||||
color_T default_vlink;
|
color_T default_vlink;
|
||||||
#ifdef CONFIG_BOOKMARKS
|
#ifdef CONFIG_BOOKMARKS
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "config/options.h"
|
#include "config/options.h"
|
||||||
#include "document/docdata.h"
|
#include "document/docdata.h"
|
||||||
#include "document/document.h"
|
#include "document/document.h"
|
||||||
|
#include "document/format.h"
|
||||||
#include "document/options.h"
|
#include "document/options.h"
|
||||||
#include "document/plain/renderer.h"
|
#include "document/plain/renderer.h"
|
||||||
#include "document/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->npoints = length;
|
||||||
link->type = LINK_HYPERTEXT;
|
link->type = LINK_HYPERTEXT;
|
||||||
link->where = uri;
|
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->color.foreground = document->options.default_link;
|
||||||
link->number = document->nlinks;
|
link->number = document->nlinks;
|
||||||
|
|
||||||
@ -213,7 +214,7 @@ print_document_link(struct plain_renderer *renderer, int lineno,
|
|||||||
|
|
||||||
line[link_end] = saved_char;
|
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,
|
set_term_color(&template, &new_link->color,
|
||||||
doc_opts->color_flags, doc_opts->color_mode);
|
doc_opts->color_flags, doc_opts->color_mode);
|
||||||
@ -478,14 +479,7 @@ next:
|
|||||||
static void
|
static void
|
||||||
init_template(struct screen_char *template, struct document_options *options)
|
init_template(struct screen_char *template, struct document_options *options)
|
||||||
{
|
{
|
||||||
color_T background = options->default_bg;
|
get_screen_char_template(template, options, options->default_style);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct node *
|
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
|
renderer.max_width = document->options.wrap ? document->options.box.width
|
||||||
: INT_MAX;
|
: INT_MAX;
|
||||||
|
|
||||||
document->bgcolor = document->options.default_bg;
|
document->bgcolor = document->options.default_style.bg;
|
||||||
document->width = 0;
|
document->width = 0;
|
||||||
#ifdef CONFIG_UTF8
|
#ifdef CONFIG_UTF8
|
||||||
document->options.utf8 = is_cp_utf8(document->options.cp);
|
document->options.utf8 = is_cp_utf8(document->options.cp);
|
||||||
|
@ -8,6 +8,7 @@ struct document_options;
|
|||||||
struct document_view;
|
struct document_view;
|
||||||
struct session;
|
struct session;
|
||||||
struct view_state;
|
struct view_state;
|
||||||
|
struct screen_char;
|
||||||
|
|
||||||
void render_document(struct view_state *, struct document_view *, struct document_options *);
|
void render_document(struct view_state *, struct document_view *, struct document_options *);
|
||||||
void render_document_frames(struct session *ses, int no_cache);
|
void render_document_frames(struct session *ses, int no_cache);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user