1 /* messages and text */
17 struct treenode
* chartree
= NULL
;
20 int ptrcomp(void* k1
, void* k2
){
24 void set_message(char* str
){
26 int N
= unicode_getc(str
, &u
);
28 vwchar
* C
= tree_search(chartree
, ptrcomp
, (void*)u
);
30 /* append this character to the message
31 if the current word is too long,
32 move the current word to the next line
33 if the current word is longer than a whole line
34 then just break here (would happen with japanese).
36 //printf("%04lx[%lc] ",u, C->u);
40 character not found, so use a rectangle or something
41 use four tiny numbers to indicate the character
44 //printf("%04lx[???] ", u);
46 N
+= unicode_getc(str
+N
, &u
);
53 void advance_message(){
61 void complete_message(){
67 vwchar
* C
= xmalloc(sizeof(vwchar
));
75 chartree
= xmalloc(sizeof(treenode
));
79 chartree
->key
= (void*)' ';
86 vwchar
* load_vwchar(reader
* rd
, int gfx
){
90 int ret
= loader_scanline(rd
, "%256s %d %d %d %d %d\n",str
,&x
,&y
,&w
,&k1
,&k2
);
95 vwchar
* C
= xmalloc(sizeof(vwchar
));
107 void print_tree(treenode
* node
){
108 printf("(%lx,",(utf32
)node
->key
);
126 void randomly_insert(vwchar
* C
[], int count
){
127 for(int i
=0; i
<count
-1; i
++){
128 int j
= randint(0,count
-i
-1);
129 tree_insert(chartree
, ptrcomp
, (void*)C
[j
]->u
, C
[j
]);
136 int load_font(char* filename
){
137 printf("load_font: loading %s\n",filename
);
138 char buf
[256] = "fonts/";
139 strmcat(buf
, filename
, 256);
140 reader
* rd
= loader_open(buf
);
142 fatal_error("load_font: cannot open %s\n",filename
);
146 loader_scanline(rd
, "%256s", str
);
147 int gfx
= load_gfx(str
);
149 /* we read 64 characters at a time and insert them
150 randomly into the binary search tree. this is supposed
151 to help produce a more balanced tree. */
155 C
[ptr
] = load_vwchar(rd
, gfx
);
159 randomly_insert(C
, 64);
163 C
[++ptr
] = load_vwchar(rd
, gfx
);
167 randomly_insert(C
, ptr
);
169 printf(" loaded %d characters\n",N
);
171 printf(" character tree is the following\n");
172 print_tree(chartree
);