Implement strikethrough formatting
This commit is contained in:
parent
0d92c7708d
commit
d562a2eef3
50
dip.c
50
dip.c
|
@ -1996,11 +1996,14 @@ bypass_freetype:
|
||||||
* at least 1 apart
|
* at least 1 apart
|
||||||
* Otherwise g_print_text will print nonsense (but won't segfault)
|
* Otherwise g_print_text will print nonsense (but won't segfault)
|
||||||
*/
|
*/
|
||||||
static void get_underline_pos(int height, int *top, int *bottom)
|
static void get_line_pos(int height, int *top, int *bottom, unsigned style)
|
||||||
{
|
{
|
||||||
int thickness, baseline;
|
int thickness, baseline;
|
||||||
thickness=(height+15)/16;
|
thickness=(height+15)/16;
|
||||||
baseline=height/7;
|
if (style == FF_STRIKE)
|
||||||
|
baseline=height/2 - height/12;
|
||||||
|
else
|
||||||
|
baseline=height/7;
|
||||||
if (baseline<=0) baseline=1;
|
if (baseline<=0) baseline=1;
|
||||||
if (thickness>baseline) thickness=baseline;
|
if (thickness>baseline) thickness=baseline;
|
||||||
*top=height-baseline;
|
*top=height-baseline;
|
||||||
|
@ -2010,38 +2013,39 @@ static void get_underline_pos(int height, int *top, int *bottom)
|
||||||
/* *width will be advanced by the width of the text */
|
/* *width will be advanced by the width of the text */
|
||||||
void g_print_text(struct graphics_device *device, int x, int y, struct style *style, unsigned char *text, int *width)
|
void g_print_text(struct graphics_device *device, int x, int y, struct style *style, unsigned char *text, int *width)
|
||||||
{
|
{
|
||||||
int top_underline, bottom_underline, original_width, my_width;
|
int top_line, bottom_line, original_width, my_width;
|
||||||
unsigned char original_flags;
|
unsigned char original_flags, line_style;
|
||||||
struct rect saved_clip;
|
struct rect saved_clip;
|
||||||
|
|
||||||
if (y + style->height <= device->clip.y1 || y >= device->clip.y2)
|
if (y + style->height <= device->clip.y1 || y >= device->clip.y2)
|
||||||
goto o;
|
goto o;
|
||||||
if (style->flags & FF_UNDERLINE) {
|
if (style->flags & FF_UNDERLINE || style->flags & FF_STRIKE) {
|
||||||
/* Underline */
|
/* Underline or strike */
|
||||||
if (!width) {
|
if (!width) {
|
||||||
width = &my_width;
|
width = &my_width;
|
||||||
*width = 0;
|
*width = 0;
|
||||||
}
|
}
|
||||||
original_flags = style->flags;
|
original_flags = style->flags;
|
||||||
original_width = *width;
|
original_width = *width;
|
||||||
style->flags &= ~FF_UNDERLINE;
|
line_style = style->flags & FF_UNDERLINE ? FF_UNDERLINE : FF_STRIKE;
|
||||||
get_underline_pos(style->height, &top_underline, &bottom_underline);
|
style->flags &= ~line_style;
|
||||||
restrict_clip_area(device, &saved_clip, 0, 0, device->size.x2, y + top_underline);
|
get_line_pos(style->height, &top_line, &bottom_line, line_style);
|
||||||
|
restrict_clip_area(device, &saved_clip, 0, 0, device->size.x2, y + top_line);
|
||||||
g_print_text(device, x, y, style, text, width);
|
g_print_text(device, x, y, style, text, width);
|
||||||
set_clip_area(device, &saved_clip);
|
set_clip_area(device, &saved_clip);
|
||||||
if (bottom_underline - top_underline == 1) {
|
if (bottom_line - top_line == 1) {
|
||||||
/* Line */
|
/* Line */
|
||||||
drv->draw_hline(device, x, y + top_underline, safe_add(x, *width) - original_width, style->underline_color);
|
drv->draw_hline(device, x, y + top_line, safe_add(x, *width) - original_width, style->line_color);
|
||||||
} else {
|
} else {
|
||||||
/* Area */
|
/* Area */
|
||||||
drv->fill_area(device, x, y + top_underline, safe_add(x, *width) - original_width, y + bottom_underline, style->underline_color);
|
drv->fill_area(device, x, y + top_line, safe_add(x, *width) - original_width, y + bottom_line, style->line_color);
|
||||||
}
|
}
|
||||||
if (bottom_underline < style->height) {
|
if (bottom_line < style->height) {
|
||||||
/* Do the bottom half only if the underline is above
|
/* Do the bottom half only if the line is above
|
||||||
* the bottom of the letters.
|
* the bottom of the letters.
|
||||||
*/
|
*/
|
||||||
*width = original_width;
|
*width = original_width;
|
||||||
restrict_clip_area(device, &saved_clip, 0, y + bottom_underline, device->size.x2, device->size.y2);
|
restrict_clip_area(device, &saved_clip, 0, y + bottom_line, device->size.x2, device->size.y2);
|
||||||
g_print_text(device, x, y, style, text, width);
|
g_print_text(device, x, y, style, text, width);
|
||||||
set_clip_area(device, &saved_clip);
|
set_clip_area(device, &saved_clip);
|
||||||
}
|
}
|
||||||
|
@ -2275,9 +2279,11 @@ struct style *g_invert_style(struct style *old)
|
||||||
#ifdef HAVE_FREETYPE
|
#ifdef HAVE_FREETYPE
|
||||||
st->ft_face = old->ft_face;
|
st->ft_face = old->ft_face;
|
||||||
#endif
|
#endif
|
||||||
if (st->flags & FF_UNDERLINE) {
|
if (st->flags & FF_UNDERLINE || st->flags & FF_STRIKE) {
|
||||||
/* We have to get a foreground color for underlining */
|
/* We have to get a foreground color for underlining and
|
||||||
st->underline_color = dip_get_color_sRGB((st->r1 << 16) | (st->g1 << 8) | (st->b1));
|
* striking
|
||||||
|
*/
|
||||||
|
st->line_color = dip_get_color_sRGB((st->r1 << 16) | (st->g1 << 8) | (st->b1));
|
||||||
}
|
}
|
||||||
st->mono_space = old->mono_space;
|
st->mono_space = old->mono_space;
|
||||||
st->mono_height = old->mono_height;
|
st->mono_height = old->mono_height;
|
||||||
|
@ -2323,9 +2329,11 @@ struct style *g_get_style_font(int fg, int bg, int size, int fflags, unsigned ch
|
||||||
else
|
else
|
||||||
st->ft_face = freetype_get_font(font);
|
st->ft_face = freetype_get_font(font);
|
||||||
#endif
|
#endif
|
||||||
if (fflags & FF_UNDERLINE) {
|
if (fflags & FF_UNDERLINE || fflags & FF_STRIKE) {
|
||||||
/* We have to get a foreground color for underlining */
|
/* We have to get a foreground color for underlining and
|
||||||
st->underline_color = dip_get_color_sRGB(fg);
|
* striking
|
||||||
|
*/
|
||||||
|
st->line_color = dip_get_color_sRGB(fg);
|
||||||
}
|
}
|
||||||
if (fflags & FF_MONOSPACED)
|
if (fflags & FF_MONOSPACED)
|
||||||
load_metric(st, ' ', &st->mono_space, &st->mono_height);
|
load_metric(st, ' ', &st->mono_space, &st->mono_height);
|
||||||
|
|
12
html.c
12
html.c
|
@ -967,6 +967,12 @@ static void html_underline(unsigned char *a)
|
||||||
format_.attr |= AT_UNDERLINE;
|
format_.attr |= AT_UNDERLINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void html_strike(unsigned char *a)
|
||||||
|
{
|
||||||
|
get_js_events(a);
|
||||||
|
format_.attr |= AT_STRIKE;
|
||||||
|
}
|
||||||
|
|
||||||
static void html_fixed(unsigned char *a)
|
static void html_fixed(unsigned char *a)
|
||||||
{
|
{
|
||||||
get_js_events(a);
|
get_js_events(a);
|
||||||
|
@ -2777,8 +2783,10 @@ static struct element_info elements[] = {
|
||||||
{"EM", html_italic, 0, 0},
|
{"EM", html_italic, 0, 0},
|
||||||
{"ABBR", html_italic, 0, 0},
|
{"ABBR", html_italic, 0, 0},
|
||||||
{"U", html_underline, 0, 0},
|
{"U", html_underline, 0, 0},
|
||||||
{"S", html_underline, 0, 0},
|
{"INS", html_underline, 0, 0},
|
||||||
{"STRIKE", html_underline, 0, 0},
|
{"S", html_strike, 0, 0},
|
||||||
|
{"DEL", html_strike, 0, 0},
|
||||||
|
{"STRIKE", html_strike, 0, 0},
|
||||||
{"FIXED", html_fixed, 0, 0},
|
{"FIXED", html_fixed, 0, 0},
|
||||||
{"CODE", html_fixed, 0, 0},
|
{"CODE", html_fixed, 0, 0},
|
||||||
{"TT", html_fixed, 0, 0},
|
{"TT", html_fixed, 0, 0},
|
||||||
|
|
|
@ -113,6 +113,7 @@ static struct style *get_style_by_ta(struct text_attrib *ta)
|
||||||
|
|
||||||
fflags = 0;
|
fflags = 0;
|
||||||
if (ta->attr & AT_UNDERLINE) fflags |= FF_UNDERLINE;
|
if (ta->attr & AT_UNDERLINE) fflags |= FF_UNDERLINE;
|
||||||
|
if (ta->attr & AT_STRIKE) fflags |= FF_STRIKE;
|
||||||
if (ta->attr & AT_BOLD) fflags |= FF_BOLD;
|
if (ta->attr & AT_BOLD) fflags |= FF_BOLD;
|
||||||
if (ta->attr & AT_ITALIC) fflags |= FF_ITALIC;
|
if (ta->attr & AT_ITALIC) fflags |= FF_ITALIC;
|
||||||
if (ta->attr & AT_FIXED) fflags |= FF_MONOSPACED;
|
if (ta->attr & AT_FIXED) fflags |= FF_MONOSPACED;
|
||||||
|
|
1
html_r.c
1
html_r.c
|
@ -868,6 +868,7 @@ static void put_chars(void *p_, unsigned char *c, int l)
|
||||||
fg = fg_color(fg, bg);
|
fg = fg_color(fg, bg);
|
||||||
if (format_.attr & AT_ITALIC) fg = fg ^ 0x01;
|
if (format_.attr & AT_ITALIC) fg = fg ^ 0x01;
|
||||||
if (format_.attr & AT_UNDERLINE) fg = (fg ^ 0x04) | 0x08;
|
if (format_.attr & AT_UNDERLINE) fg = (fg ^ 0x04) | 0x08;
|
||||||
|
if (format_.attr & AT_STRIKE) fg = (fg ^ 0x06);
|
||||||
if (format_.attr & AT_BOLD) fg = fg | 0x08;
|
if (format_.attr & AT_BOLD) fg = fg | 0x08;
|
||||||
fg = fg_color(fg, bg);
|
fg = fg_color(fg, bg);
|
||||||
if (format_.attr & AT_GRAPHICS) bg = bg | 0x10;
|
if (format_.attr & AT_GRAPHICS) bg = bg | 0x10;
|
||||||
|
|
8
links.h
8
links.h
|
@ -2174,9 +2174,11 @@ struct style {
|
||||||
/* ?0 are background, ?1 foreground.
|
/* ?0 are background, ?1 foreground.
|
||||||
* These are unrounded 8-bit sRGB space
|
* These are unrounded 8-bit sRGB space
|
||||||
*/
|
*/
|
||||||
unsigned char flags; /* non-zero means underline */
|
unsigned char flags; /* FF_ flags */
|
||||||
int height;
|
int height;
|
||||||
long underline_color; /* Valid only if flags are nonzero */
|
long line_color; /* Valid only if flags includes FF_UNDERLINE or
|
||||||
|
* FF_STRIKE
|
||||||
|
*/
|
||||||
int mono_space; /* -1 if the font is not monospaced
|
int mono_space; /* -1 if the font is not monospaced
|
||||||
* width of the space otherwise
|
* width of the space otherwise
|
||||||
*/
|
*/
|
||||||
|
@ -2266,6 +2268,7 @@ int hack_rgb(int rgb);
|
||||||
#define FF_MONOSPACED 2
|
#define FF_MONOSPACED 2
|
||||||
#define FF_ITALIC 4
|
#define FF_ITALIC 4
|
||||||
#define FF_UNDERLINE 8
|
#define FF_UNDERLINE 8
|
||||||
|
#define FF_STRIKE 16
|
||||||
|
|
||||||
#ifndef USE_ITALIC
|
#ifndef USE_ITALIC
|
||||||
#define FF_SHAPES 4
|
#define FF_SHAPES 4
|
||||||
|
@ -4539,6 +4542,7 @@ void init_grview(void);
|
||||||
#define AT_FIXED 8
|
#define AT_FIXED 8
|
||||||
#define AT_GRAPHICS 16
|
#define AT_GRAPHICS 16
|
||||||
#define AT_INVERT 32
|
#define AT_INVERT 32
|
||||||
|
#define AT_STRIKE 64
|
||||||
|
|
||||||
#define AL_LEFT 0
|
#define AL_LEFT 0
|
||||||
#define AL_CENTER 1
|
#define AL_CENTER 1
|
||||||
|
|
Loading…
Reference in New Issue