summaryrefslogtreecommitdiff
path: root/fonts.c
blob: 2ef80527b40e4e4d2ce6174b0e04faeab8bcb908 (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
28
#include <string.h>

#include "fonts.h"

int render(char *input, int input_len, 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[input_i]; 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++;
  }
  return output_i*(SYMBOL_WIDTH+1);
}