Add more monospace font options and support 8-bit grayscale bitmaps

This commit is contained in:
K. Lange 2018-05-08 15:41:12 +09:00
parent db4337f17b
commit 4818a8cc43
10 changed files with 29 additions and 3 deletions

View File

@ -429,10 +429,18 @@ term_write_char(
term_set_point(x+j,y+i,premultiply(_bg));
}
}
int _font = SDF_FONT_MONO;
if (flags & ANSI_BOLD && flags & ANSI_ITALIC) {
_font = SDF_FONT_MONO_BOLD_OBLIQUE;
} else if (flags & ANSI_BOLD) {
_font = SDF_FONT_MONO_BOLD;
} else if (flags & ANSI_ITALIC) {
_font = SDF_FONT_MONO_OBLIQUE;
}
if (_no_frame) {
draw_sdf_string_gamma(ctx, x, y, tmp, font_size, _fg, SDF_FONT_MONO, font_gamma);
draw_sdf_string_gamma(ctx, x, y, tmp, font_size, _fg, _font, font_gamma);
} else {
draw_sdf_string_gamma(ctx, x+decor_left_width, y+decor_top_height, tmp, font_size, _fg, SDF_FONT_MONO, font_gamma);
draw_sdf_string_gamma(ctx, x+decor_left_width, y+decor_top_height, tmp, font_size, _fg, _font, font_gamma);
}
} else {
#ifdef number_font

View File

@ -4,6 +4,9 @@ enum sdf_font {
SDF_FONT_THIN,
SDF_FONT_BOLD,
SDF_FONT_MONO,
SDF_FONT_MONO_BOLD,
SDF_FONT_MONO_OBLIQUE,
SDF_FONT_MONO_BOLD_OBLIQUE,
};
extern int draw_sdf_string(gfx_context_t * ctx, int32_t x, int32_t y, const char * str, int size, uint32_t color, int font);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

After

Width:  |  Height:  |  Size: 636 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

After

Width:  |  Height:  |  Size: 636 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 636 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 636 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 636 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

After

Width:  |  Height:  |  Size: 636 KiB

View File

@ -413,7 +413,7 @@ void load_sprite(sprite_t * sprite, char * filename) {
color = premultiply(color);
}
} else {
color = rgb(0,0,0); /* Unsupported */
color = rgb(bufferb[i + x],bufferb[i + x],bufferb[i + x]); /* Unsupported */
}
/* Set our point */
sprite->bitmap[(height - y - 1) * width + x] = color;

View File

@ -17,6 +17,9 @@
static sprite_t _font_data_thin;
static sprite_t _font_data_bold;
static sprite_t _font_data_mono;
static sprite_t _font_data_mono_bold;
static sprite_t _font_data_mono_oblique;
static sprite_t _font_data_mono_bold_oblique;
static hashmap_t * _font_cache;
@ -44,6 +47,9 @@ static void _init_sdf(void) {
load_sprite(&_font_data_thin, "/usr/share/sdf_thin.bmp");
load_sprite(&_font_data_bold, "/usr/share/sdf_bold.bmp");
load_sprite(&_font_data_mono, "/usr/share/sdf_mono.bmp");
load_sprite(&_font_data_mono_bold, "/usr/share/sdf_mono_bold.bmp");
load_sprite(&_font_data_mono_oblique, "/usr/share/sdf_mono_oblique.bmp");
load_sprite(&_font_data_mono_bold_oblique, "/usr/share/sdf_mono_bold_oblique.bmp");
FILE * fi = fopen("/etc/sdf.conf", "r");
char tmp[1024];
char * s = tmp;
@ -78,6 +84,12 @@ static sprite_t * _select_font(int font) {
return &_font_data_bold;
case SDF_FONT_MONO:
return &_font_data_mono;
case SDF_FONT_MONO_BOLD:
return &_font_data_mono_bold;
case SDF_FONT_MONO_OBLIQUE:
return &_font_data_mono_oblique;
case SDF_FONT_MONO_BOLD_OBLIQUE:
return &_font_data_mono_bold_oblique;
case SDF_FONT_THIN:
default:
return &_font_data_thin;
@ -89,6 +101,9 @@ static int _select_width(char ch, int font) {
case SDF_FONT_BOLD:
return _char_data[(int)ch].width_bold;
case SDF_FONT_MONO:
case SDF_FONT_MONO_BOLD:
case SDF_FONT_MONO_OBLIQUE:
case SDF_FONT_MONO_BOLD_OBLIQUE:
return _char_data[(int)ch].width_mono;
case SDF_FONT_THIN:
default: