diff options
author | Erich Eckner <git@eckner.net> | 2018-10-23 10:04:04 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-10-23 10:04:04 +0200 |
commit | 80e3c3ce5744272d3eef9f9b32f7da5ae96088cd (patch) | |
tree | 43a0cad03bd1dea9eef4416df604767cfa5e7aa9 /fonts.c | |
parent | d646809abf052fd949ca839395735a91d7084198 (diff) | |
download | anzeige-80e3c3ce5744272d3eef9f9b32f7da5ae96088cd.tar.xz |
fonts: put rendering into a function
Diffstat (limited to 'fonts.c')
-rw-r--r-- | fonts.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -0,0 +1,27 @@ +#include <string.h> + +#include "fonts.h" + +void render(unsigned char *input, int input_len, unsigned char *output, int max_output_len, int skip_unprintables) +{ + 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_i++) { + unsigned char c = input[input_i]; + if (c >= 0x7f) { + if (c <= 0xaf) { + output_i += !!skip_unprintables; + continue; + } + c -= 0xaf - 0x7f + 1; + } + c -= 0x20; + if ((c < 0) || (c >= (sizeof(symbols) / SYMBOL_WIDTH))) { + output_i += !!skip_unprintables; + continue; + } + 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++; + } +} |