diff options
author | Erich Eckner <git@eckner.net> | 2018-10-29 11:44:24 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-10-31 21:48:36 +0100 |
commit | 36949167f398639f05c3c97cd7b652ce66d35f34 (patch) | |
tree | 4745d3c5938739bf2f6c48d0f08f16dad983231b /fonts.c | |
parent | a40eccd30b8294735834149379cfd1538ebe8651 (diff) | |
download | anzeige-36949167f398639f05c3c97cd7b652ce66d35f34.tar.xz |
fixed width font => variable width font
Diffstat (limited to 'fonts.c')
-rw-r--r-- | fonts.c | 38 |
1 files changed, 30 insertions, 8 deletions
@@ -3,6 +3,23 @@ #include "fonts.h" +void init_symbols_boundaries() +{ + // space needs special treatment + symbols_boundaries[0][0] = 0; + symbols_boundaries[0][1] = MAX_SYMBOL_WIDTH - 1; + for (int i = 1; i < SYMBOL_COUNT; i++) { + symbols_boundaries[i][0] = -1; + symbols_boundaries[i][1] = -1; + for (int j = 0; j < MAX_SYMBOL_WIDTH; j++) { + if ((symbols_boundaries[i][0] == -1) && (symbols[i * MAX_SYMBOL_WIDTH + j] != 0x00)) + symbols_boundaries[i][0] = j; + if ((symbols_boundaries[i][1] == -1) && (symbols[i * MAX_SYMBOL_WIDTH + MAX_SYMBOL_WIDTH - 1 - j] != 0x00)) + symbols_boundaries[i][1] = MAX_SYMBOL_WIDTH - 1 - j; + } + } +} + int skip_gaps(char16_t *operand) { for (int i=sizeof(skip_ranges)/sizeof(skip_ranges[0])-1; i>=0; i--) { @@ -12,7 +29,7 @@ int skip_gaps(char16_t *operand) return 1; *operand -= skip_ranges[i][1] - skip_ranges[i][0] + 1; } - if ((*operand < 0) || (*operand >= (sizeof(symbols) / SYMBOL_WIDTH))) + if ((*operand < 0) || (*operand >= SYMBOL_COUNT)) return 1; return 0; } @@ -21,7 +38,7 @@ int render(char *input, int input_len, char *output, int max_output_len, int ski { memset(output, 0, max_output_len); int output_i = 0; - for (int input_i=0; (input_i < input_len) && (output_i*(SYMBOL_WIDTH+1) < max_output_len) && input[input_i]; input_i++) { + for (int input_i=0; (input_i < input_len) && (output_i < max_output_len) && input[input_i]; input_i++) { char16_t c = (unsigned char)input[input_i]; if ((c == 0xc2) || (c == 0xc3)) { input_i++; @@ -30,15 +47,20 @@ int render(char *input, int input_len, char *output, int max_output_len, int ski c = (c << 8) | (unsigned char)input[input_i]; } if (skip_gaps(&c)) { - output_i += !!skip_unprintables; - continue; + if (skip_unprintables) + continue; + c = 0x00; // space + } + for (int i = symbols_boundaries[c][0]; i <= symbols_boundaries[c][1]; i++) { + if (output_i >= max_output_len) + break; + output[output_i] = symbols[c * MAX_SYMBOL_WIDTH + i]; + output_i++; } - for (int i=0; (i<SYMBOL_WIDTH) && (output_i*(SYMBOL_WIDTH+1) + i < max_output_len); i++) - output[output_i*(SYMBOL_WIDTH+1) + i] = symbols[c*SYMBOL_WIDTH + i]; output_i++; } - if (output_i*(SYMBOL_WIDTH+1) >= max_output_len) + if (output_i >= max_output_len) return max_output_len; else - return output_i*(SYMBOL_WIDTH+1); + return output_i; } |