summaryrefslogtreecommitdiff
path: root/fonts.c
blob: f72f38c923c1bc80c90647408258980afee493e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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++;
  }
}