sdf: add oblique, bold oblique fonts

This commit is contained in:
K. Lange 2018-11-14 17:16:11 +09:00
parent 9ae59ecdb9
commit d1ff49e70b
6 changed files with 29 additions and 10 deletions

View File

@ -2068,7 +2068,8 @@ int main(int argc, char * argv[]) {
TRACE("Loading fonts...");
{
sprite_t _font_data[6];
#define FONT_COUNT 8
sprite_t _font_data[FONT_COUNT];
load_sprite(&_font_data[0], "/usr/share/sdf_thin.bmp");
load_sprite(&_font_data[1], "/usr/share/sdf_bold.bmp");
@ -2076,11 +2077,13 @@ int main(int argc, char * argv[]) {
load_sprite(&_font_data[3], "/usr/share/sdf_mono_bold.bmp");
load_sprite(&_font_data[4], "/usr/share/sdf_mono_oblique.bmp");
load_sprite(&_font_data[5], "/usr/share/sdf_mono_bold_oblique.bmp");
load_sprite(&_font_data[6], "/usr/share/sdf_oblique.bmp");
load_sprite(&_font_data[7], "/usr/share/sdf_bold_oblique.bmp");
TRACE(" Data loaded...");
size_t font_data_size = sizeof(unsigned int) * (1 + 6 * 3);
for (int i = 0; i < 6; ++i) {
size_t font_data_size = sizeof(unsigned int) * (1 + FONT_COUNT * 3);
for (int i = 0; i < FONT_COUNT; ++i) {
font_data_size += 4 * _font_data[i].width * _font_data[i].height;
}
@ -2093,15 +2096,15 @@ int main(int argc, char * argv[]) {
assert((s >= font_data_size) && "Font server failure.");
uint32_t * data = (uint32_t *)font;
data[0] = 6;
data[0] = FONT_COUNT;
data[1] = _font_data[0].width;
data[2] = _font_data[0].height;
data[3] = (6 * 3 + 1) * sizeof(unsigned int);
data[3] = (FONT_COUNT * 3 + 1) * sizeof(unsigned int);
memcpy(&font[data[3]], _font_data[0].bitmap, _font_data[0].width * _font_data[0].height * 4);
free(_font_data[0].bitmap);
for (int i = 1; i < 6; ++i) {
for (int i = 1; i < FONT_COUNT; ++i) {
TRACE(" Loaded %d font(s)... %d %d %d", i, data[(i - 1) * 3 + 2], data[(i - 1) * 3 + 1], data[(i - 1) * 3 + 3]);
data[i * 3 + 1] = _font_data[i].width;
data[i * 3 + 2] = _font_data[i].height;

View File

@ -40,10 +40,14 @@ void redraw() {
decors();
draw_sdf_string(ctx, 30, 30, "ABCDEFGHIJKLMNOPQRSTUVWXYZABC", size, rgb(0,0,0), SDF_FONT_THIN);
draw_sdf_string(ctx, 30, 60, "abcdefghijklmnopqrstuvwxyzabc", size, rgb(0,0,0), SDF_FONT_THIN);
draw_sdf_string(ctx, 30, 90, "ABCDEFGHIJKLMNOPQRSTUVWXYZABC", size, rgb(0,0,0), SDF_FONT_BOLD);
draw_sdf_string(ctx, 30,120, "abcdefghijklmnopqrstuvwxyzabc", size, rgb(0,0,0), SDF_FONT_BOLD);
draw_sdf_string(ctx, 30,30*1, "ABCDEFGHIJKLMNOPQRSTUVWXYZABC", size, rgb(0,0,0), SDF_FONT_THIN);
draw_sdf_string(ctx, 30,30*2, "abcdefghijklmnopqrstuvwxyzabc", size, rgb(0,0,0), SDF_FONT_THIN);
draw_sdf_string(ctx, 30,30*3, "ABCDEFGHIJKLMNOPQRSTUVWXYZABC", size, rgb(0,0,0), SDF_FONT_BOLD);
draw_sdf_string(ctx, 30,30*4, "abcdefghijklmnopqrstuvwxyzabc", size, rgb(0,0,0), SDF_FONT_BOLD);
draw_sdf_string(ctx, 30,30*5, "ABCDEFGHIJKLMNOPQRSTUVWXYZABC", size, rgb(0,0,0), SDF_FONT_OBLIQUE);
draw_sdf_string(ctx, 30,30*6, "abcdefghijklmnopqrstuvwxyzabc", size, rgb(0,0,0), SDF_FONT_OBLIQUE);
draw_sdf_string(ctx, 30,30*7, "ABCDEFGHIJKLMNOPQRSTUVWXYZABC", size, rgb(0,0,0), SDF_FONT_BOLD_OBLIQUE);
draw_sdf_string(ctx, 30,30*8, "abcdefghijklmnopqrstuvwxyzabc", size, rgb(0,0,0), SDF_FONT_BOLD_OBLIQUE);
}
void resize_finish(int w, int h) {

View File

@ -12,6 +12,8 @@ enum sdf_font {
SDF_FONT_MONO_BOLD,
SDF_FONT_MONO_OBLIQUE,
SDF_FONT_MONO_BOLD_OBLIQUE,
SDF_FONT_OBLIQUE,
SDF_FONT_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.

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 636 KiB

View File

@ -20,6 +20,8 @@
static sprite_t _font_data_thin;
static sprite_t _font_data_bold;
static sprite_t _font_data_oblique;
static sprite_t _font_data_bold_oblique;
static sprite_t _font_data_mono;
static sprite_t _font_data_mono_bold;
static sprite_t _font_data_mono_oblique;
@ -76,6 +78,8 @@ static void _init_sdf(void) {
load_font(&_font_data_thin, SDF_FONT_THIN);
load_font(&_font_data_bold, SDF_FONT_BOLD);
load_font(&_font_data_oblique, SDF_FONT_OBLIQUE);
load_font(&_font_data_bold_oblique, SDF_FONT_BOLD_OBLIQUE);
load_font(&_font_data_mono, SDF_FONT_MONO);
load_font(&_font_data_mono_bold, SDF_FONT_MONO_BOLD);
load_font(&_font_data_mono_oblique, SDF_FONT_MONO_OBLIQUE);
@ -121,6 +125,10 @@ static sprite_t * _select_font(int font) {
return &_font_data_mono_oblique;
case SDF_FONT_MONO_BOLD_OBLIQUE:
return &_font_data_mono_bold_oblique;
case SDF_FONT_OBLIQUE:
return &_font_data_oblique;
case SDF_FONT_BOLD_OBLIQUE:
return &_font_data_bold_oblique;
case SDF_FONT_THIN:
default:
return &_font_data_thin;
@ -130,12 +138,14 @@ static sprite_t * _select_font(int font) {
static int _select_width(char ch, int font) {
switch (font) {
case SDF_FONT_BOLD:
case SDF_FONT_BOLD_OBLIQUE:
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_OBLIQUE:
case SDF_FONT_THIN:
default:
return _char_data[(int)ch].width_thin;