annotate nuklear_ui/font_android.c @ 1965:3a46ff899fa6

More correct implementation of byte printing in builtin debugger. Fix GDB debugger to use helper in backend.c for reading bytes
author Michael Pavone <pavone@retrodev.com>
date Sun, 03 May 2020 23:28:42 -0700
parents 78abbabfd58d
children 13abdc98379e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1839
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <stdio.h>
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include <stdlib.h>
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include <stdint.h>
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include <limits.h>
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 #include "../util.h"
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #include "../paths.h"
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 #include "sfnt.h"
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 typedef enum {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 STATE_DEFAULT,
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 STATE_DECL,
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 STATE_COMMENT,
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 STATE_TAG,
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 STATE_PRE_ATTRIB,
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 STATE_ATTRIB,
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 STATE_PRE_VALUE,
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 STATE_VALUE
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 } parse_state;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 #define DEFAULT_WEIGHT 400
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 char *default_font_path(void)
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
24 //Would probably be better to call into Java for this, but this should do for now
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25 FILE *f = fopen("/system/etc/fonts.xml", "rb");
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 if (!f) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27 return NULL;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 long size = file_size(f);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30 char *font_xml = malloc(size+1);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
31 if (size != fread(font_xml, 1, size, f)) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 free(font_xml);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 fclose(f);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
34 return NULL;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
35 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 fclose(f);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37 font_xml[size] = 0;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
38
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
39 char *last_tag = NULL, *last_attrib = NULL, *last_value = NULL;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
40 uint8_t last_style_was_normal = 0;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 char *capture_best = NULL;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42 char *best = NULL;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 int best_weight_diff = INT_MAX;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44 int last_weight = INT_MAX;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 parse_state state = STATE_DEFAULT;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 for(char *cur = font_xml; *cur; ++cur) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47 switch (state)
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48 {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49 case STATE_DEFAULT:
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 if (*cur == '<' && cur[1]) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
51 cur++;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
52 switch(*cur)
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54 case '?':
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55 state = STATE_DECL;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
56 break;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
57 case '!':
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
58 if (cur[1] == '-' && cur[2] == '-') {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
59 state = STATE_COMMENT;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 cur++;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61 } else {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 debug_message("Invalid comment\n");
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 cur = font_xml + size - 1;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 break;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 default:
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 if (capture_best) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 cur[-1] = 0;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 best = strip_ws(capture_best);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 capture_best = NULL;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 best_weight_diff = abs(last_weight - DEFAULT_WEIGHT);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72 debug_message("Found candidate %s with weight %d\n", best, last_weight);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74 state = STATE_TAG;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
75 last_tag = cur;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76 last_attrib = NULL;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
77 last_value = NULL;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 last_weight = INT_MAX;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 break;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
80 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 break;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 case STATE_DECL:
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 if (*cur == '?' && cur[1] == '>') {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
85 cur++;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 state = STATE_DEFAULT;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
88 break;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 case STATE_COMMENT:
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
90 if (*cur == '-' && cur[1] == '-' && cur[2] == '>') {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
91 cur += 2;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
92 state = STATE_DEFAULT;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
94 break;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
95 case STATE_TAG:
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
96 if (*cur == ' ' || *cur == '\t' || *cur == '\n' || *cur == '\r') {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
97 *cur = 0;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
98 state = STATE_PRE_ATTRIB;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
99 } else if (*cur == '>') {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
100 *cur = 0;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
101 state = STATE_DEFAULT;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
102 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
103 break;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104 case STATE_PRE_ATTRIB:
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105 if (!(*cur == ' ' || *cur == '\t' || *cur == '\n' || *cur == '\r')) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
106 if (*cur == '>') {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
107 state = STATE_DEFAULT;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
108 if (last_style_was_normal && abs(last_weight - DEFAULT_WEIGHT) < best_weight_diff) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
109 capture_best = cur + 1;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
110 } else if (best && !strcmp("/family", last_tag)) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
111 debug_message("found family close tag, stopping search\n");
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
112 cur = font_xml + size - 1;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
113 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
114 } else {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
115 last_attrib = cur;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
116 state = STATE_ATTRIB;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
117 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
118 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
119 break;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
120 case STATE_ATTRIB:
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
121 if (*cur == '=') {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
122 *cur = 0;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
123 state = STATE_PRE_VALUE;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
124 } else if (*cur == ' ' || *cur == '\t' || *cur == '\n' || *cur == '\r') {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
125 *cur = 0;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
126 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
127 break;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
128 case STATE_PRE_VALUE:
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
129 if (*cur == '"') {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
130 state = STATE_VALUE;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
131 last_value = cur + 1;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
132 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
133 break;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
134 case STATE_VALUE:
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
135 if (*cur == '"') {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
136 *cur = 0;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
137 state = STATE_PRE_ATTRIB;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
138 if (!strcmp("weight", last_attrib)) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
139 last_weight = atoi(last_value);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
140 } else if (!strcmp("style", last_attrib)) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
141 last_style_was_normal = !strcmp("normal", last_value);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
142 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
143 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
144 break;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
145 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
146 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
147 if (best) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
148 best = path_append("/system/fonts", best);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
149 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
150 free(font_xml);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
151 return best;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
152 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
153
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
154 static uint8_t *try_load_font(char *path, uint32_t *size_out)
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
155 {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
156 debug_message("Trying to load font %s\n", path);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
157 FILE *f = fopen(path, "rb");
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
158 free(path);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
159 if (!f) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
160 return NULL;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
161 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
162 long size = file_size(f);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
163 uint8_t *buffer = malloc(size);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
164 if (size != fread(buffer, 1, size, f)) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 fclose(f);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
166 return NULL;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
168 fclose(f);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
169 sfnt_container *sfnt = load_sfnt(buffer, size);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
170 if (!sfnt) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
171 free(buffer);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
172 return NULL;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
173 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
174 return sfnt_flatten(sfnt->tables, size_out);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
175 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
176
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
177 uint8_t *default_font(uint32_t *size_out)
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
178 {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
179 char *path = default_font_path();
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
180 if (!path) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
181 goto error;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
182 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
183 uint8_t *ret = try_load_font(path, size_out);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
184 if (ret) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
185 return ret;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
186 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
187 error:
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
188 //try some likely suspects if we failed to parse fonts.xml or failed to find the indicated font
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
189 ret = try_load_font("/system/fonts/Roboto-Regular.ttf", size_out);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
190 if (!ret) {
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
191 ret = try_load_font("/system/fonts/DroidSans.ttf", size_out);
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
192 }
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
193 return ret;
78abbabfd58d Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
194 }