summaryrefslogtreecommitdiff
path: root/fonts.c
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-10-23 10:04:04 +0200
committerErich Eckner <git@eckner.net>2018-10-23 10:04:04 +0200
commit80e3c3ce5744272d3eef9f9b32f7da5ae96088cd (patch)
tree43a0cad03bd1dea9eef4416df604767cfa5e7aa9 /fonts.c
parentd646809abf052fd949ca839395735a91d7084198 (diff)
downloadanzeige-80e3c3ce5744272d3eef9f9b32f7da5ae96088cd.tar.xz
fonts: put rendering into a function
Diffstat (limited to 'fonts.c')
-rw-r--r--fonts.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/fonts.c b/fonts.c
new file mode 100644
index 0000000..f72f38c
--- /dev/null
+++ b/fonts.c
@@ -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++;
+ }
+}