Debian Codegraph @

grtext/grfont.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/grtext/grfont.cpp $
21 * $Revision: 25 $
22 * $Date: 11/16/99 4:56p $
23 * $Author: Samir $
24 *
25 *
26 *
27 * $Log: /DescentIII/Main/grtext/grfont.cpp $
28 *
29 * 25 11/16/99 4:56p Samir
30 * upped max texture count per font.
31 *
32 * 24 11/16/99 3:18p Samir
33 * added new data to font file and kept compatibility with D3 fonts:
34 * tracking value.
35 *
36 * 23 8/10/99 5:11p Jeff
37 * close open files
38 *
39 * 22 6/08/99 5:45p Samir
40 * correctly take care of values about 128 when character passed to
41 * grfont_GetCharWidth
42 *
43 * 21 4/24/99 8:41p Samir
44 * fixed clipped text scaling probs.
45 *
46 * 20 4/17/99 6:16p Samir
47 * added kerning and 4444 alphaed font support.
48 *
49 * 19 4/14/99 1:15a Jeff
50 * fixed case mismatched #includes
51 *
52 * 18 4/01/99 5:23p Samir
53 * Added function to get character info.
54 *
55 * 17 3/02/99 6:26p Samir
56 * added font template width and height functions.
57 *
58 * 16 2/21/99 6:39p Samir
59 * added function to get ascii value of font character.
60 *
61 * 15 10/16/98 1:54p Kevin
62 * Changes for Demo Beta 4
63 *
64 * 14 5/22/98 12:44p Samir
65 * fixed grayscale conversion bug.
66 *
67 * 13 5/15/98 5:36p Samir
68 * reset references count of font when freeing.
69 *
70 * 12 5/08/98 5:23p Samir
71 * added font brightness and grayscale caps.
72 *
73 * 11 5/01/98 3:09p Samir
74 * properly translate monochrome fonts to 555 output.
75 *
76 * 10 4/27/98 3:46p Samir
77 * scaling fonts.
78 *
79 * 9 4/24/98 8:00a Samir
80 * hopefully fixed font pixel format translation to 555 problem.
81 *
82 * 8 4/23/98 6:38p Jason
83 * made bitmaps use 1555 format
84 *
85 * 7 4/15/98 12:10p Samir
86 * commented out unnecessary mprints.
87 *
88 * 6 3/31/98 3:49p Jason
89 * added memory lib
90 *
91 * 5 1/12/98 7:03p Samir
92 * Centering works fully.
93 *
94 * 4 1/12/98 5:24p Samir
95 * Fixed font reading and created font spew test function.
96 *
97 * 3 1/02/98 12:53p Samir
98 * Convert lowercase to uppercase if there are no lowercase chars in the
99 * font.
100 *
101 * 2 12/29/97 5:48p Samir
102 * Fixed problem with non clipping text rendering (a hack.)
103 *
104 * 1 12/29/97 3:24p Samir
105 * Initial revision
106 *
107 * $NoKeywords: $
108 */
109
110 #include <cstdio>
111 #include <cstdlib>
112 #include <cstring>
113 #include <cctype>
114
115 #include "bitmap.h"cxx . . $ `<file>/lib/bitmap.h`/
116 #include "cfile.h"cxx . . $ `<file>/cfile/cfile.h`/
117 #include "ddio.h"cxx . . $ `<file>/ddio/ddio.h`/
118 #include "grtextlib.h"cxx . . $ `<file>/grtext/grtextlib.h`/
119 #include "mem.h"cxx . . $ `<file>/mem/mem.h`/
120 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
121 #include "renderer.h"cxx . . $ `<file>/lib/renderer.h`/
122
123 const int MAX_FONTScxx . . $ MAX_FONTS. = 16, MAX_FONT_BITMAPScxx . . $ MAX_FONT_BITMAPS. = 32;
124
125 #define FT_UPPERCASEcxx . . $ `grtext/grfont.cpp:125:9`! 128
126
127 #define GRFONT_SURFACE_WIDTHcxx . . $ `grtext/grfont.cpp:127:9`! 128
128 #define GRFONT_SURFACE_HEIGHTcxx . . $ `grtext/grfont.cpp:128:9`! 128
129
130 #define BITS_TO_BYTEScxx . . $ `grtext/grfont.cpp:130:9`!(_c) (((_c) + 7) >> 3)
131 #define BITS_TO_SHORTScxx . . $ `grtext/grfont.cpp:131:9`!(_c) (((_c) + 15) >> 4)
132
133 //////////////////////////////////////////////////////////////////////////////
134 // Variables
135
136 struct tFontInfocxx . . $ tFontInfo# {
137 char filenamecxx . . $ tFontInfo#filename.[32]; // filename of font
138 int referencescxx . . $ tFontInfo#references.; // number of references of that font
139 int bmpscxx . . $ tFontInfo#bmps.[MAX_FONT_BITMAPScxx . . $ MAX_FONT_BITMAPS.]; // font bitmap handles
140 uint8_tcxx . . $ uint8_t# *ch_ucxx . . $ tFontInfo#ch_u., *ch_vcxx . . $ tFontInfo#ch_v., *ch_wcxx . . $ tFontInfo#ch_w., *ch_hcxx . . $ tFontInfo#ch_h.;
141 int *ch_bmpcxx . . $ tFontInfo#ch_bmp.;
142 float *ch_ufcxx . . $ tFontInfo#ch_uf., *ch_vfcxx . . $ tFontInfo#ch_vf., *ch_wfcxx . . $ tFontInfo#ch_wf., *ch_hfcxx . . $ tFontInfo#ch_hf.;
143 tFontFileInfocxx . . $ tFontFileInfo# fontcxx . . $ tFontInfo#font.;
144 };
145
146 // Font information stored here.
147 static tFontInfocxx . . $ tFontInfo# Fontscxx . . $ Fonts.[MAX_FONTScxx . . $ MAX_FONTS.];
148 static bool Font_initcxx . . $ Font_init. = false;
149
150 #define GRFONT_SURFACE_WIDTHcxx . . $ `grtext/grfont.cpp:150:9`! 128
151 #define GRFONT_SURFACE_HEIGHTcxx . . $ `grtext/grfont.cpp:151:9`! 128
152
153 // ----------------------------------------------------------------------------
154 // Macros for file io.
155 // ----------------------------------------------------------------------------
156
157 typedef CFILEcxx . . $ CFILE# *FONTFILEcxx . . $ FONTFILE#;
158
159 static inline int READ_FONT_INTcxx . . $ READ_FONT_INT(413716a422df0036).(FONTFILEcxx . . $ FONTFILE# ffile);
160 static inline int16_t READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(FONTFILEcxx . . $ FONTFILE# ffile);
161 static inline uint8_tcxx . . $ uint8_t# READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(FONTFILEcxx . . $ FONTFILE# ffile);
162 static inline int READ_FONT_DATAcxx . . $ READ_FONT_DATA(fc60f957852e351e).(FONTFILEcxx . . $ FONTFILE# ffile, void *buf, int size, int nelem);
163 static inline FONTFILEcxx . . $ FONTFILE# OPEN_FONTcxx . . $ OPEN_FONT(2cd0beae2d28be2a).(char *filename);
164 static inline void CLOSE_FONTcxx . . $ CLOSE_FONT(3639e799710acb68).(FONTFILEcxx . . $ FONTFILE# ffile);
165
166 inline int READ_FONT_INTcxx . . $ READ_FONT_INT(413716a422df0036).(FONTFILEcxx . . $ FONTFILE# ffile) { return cf_ReadIntcxx . . $ cf_ReadInt(d60d6f5e30f0c96a).(ffile); }
167
168 inline int16_t READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(FONTFILEcxx . . $ FONTFILE# ffile) { return cf_ReadShortcxx . . $ cf_ReadShort(30b00389b433b379).(ffile); }
169
170 inline uint8_tcxx . . $ uint8_t# READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(FONTFILEcxx . . $ FONTFILE# ffile) { return (uint8_tcxx . . $ uint8_t#)cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(ffile); }
171
172 inline int READ_FONT_DATAcxx . . $ READ_FONT_DATA(fc60f957852e351e).(FONTFILEcxx . . $ FONTFILE# ffile, void *buf, int size, int nelem) {
173 int i;
174
175 i = cf_ReadBytescxx . . $ cf_ReadBytes(de6325ef3380a744).((uint8_tcxx . . $ uint8_t# *)buf, size * nelem, ffile);
176
177 ASSERTcxx . . $ `misc/pserror.h:246:9`!(i == (size * nelem));
178
179 return i;
180 }
181
182 inline FONTFILEcxx . . $ FONTFILE# OPEN_FONTcxx . . $ OPEN_FONT(6cfe12765e653818).(const char *filename) {
183 FONTFILEcxx . . $ FONTFILE# fp;
184 int file_id;
185
186 fp = (FONTFILEcxx . . $ FONTFILE#)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(filenamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "rb");
187 if (!fp)
188 return nullptr;
189
190 file_id = READ_FONT_INTcxx . . $ READ_FONT_INT(413716a422df0036).(fp);
191 if (file_id != 0xfeedbaba)
192 return (FONTFILEcxx . . $ FONTFILE#)(-1);
193
194 return fp;
195 }
196
197 inline void CLOSE_FONTcxx . . $ CLOSE_FONT(3639e799710acb68).(FONTFILEcxx . . $ FONTFILE# ffile) { cfclosecxx . . $ cfclose(3639e799710acb68).(ffile); }
198
199 typedef FILE *FONTFILE2cxx . . $ FONTFILE2#;
200
201 static inline int WRITE_FONT_INTcxx . . $ WRITE_FONT_INT(c2adc39b7d70763e).(FONTFILE2cxx . . $ FONTFILE2# ffile, int i);
202 static inline int WRITE_FONT_SHORTcxx . . $ WRITE_FONT_SHORT(86be10c099ec69cc).(FONTFILE2cxx . . $ FONTFILE2# ffile, int16_t s);
203 static inline int WRITE_FONT_BYTEcxx . . $ WRITE_FONT_BYTE(fafe40e4b9ebf6eb).(FONTFILE2cxx . . $ FONTFILE2# ffile, uint8_tcxx . . $ uint8_t# c);
204 static inline int WRITE_FONT_DATAcxx . . $ WRITE_FONT_DATA(5122c2bbcc2ce4c8).(FONTFILE2cxx . . $ FONTFILE2# ffile, void *buf, int size, int nelem);
205 static inline FONTFILE2cxx . . $ FONTFILE2# OPEN_FONT2cxx . . $ OPEN_FONT2(102d3a3004848b86).(char *filename);
206 static inline void CLOSE_FONT2cxx . . $ CLOSE_FONT2(8d4262d45fc644ab).(FONTFILE2cxx . . $ FONTFILE2# ffile);
207
208 inline int WRITE_FONT_INTcxx . . $ WRITE_FONT_INT(c2adc39b7d70763e).(FONTFILE2cxx . . $ FONTFILE2# ffile, int i) { return fwrite(&i, sizeof(i), 1, (FILE *)ffile); }
209
210 inline int WRITE_FONT_SHORTcxx . . $ WRITE_FONT_SHORT(86be10c099ec69cc).(FONTFILE2cxx . . $ FONTFILE2# ffile, int16_t s) { return fwrite(&s, sizeof(s), 1, (FILE *)ffile); }
211
212 inline int WRITE_FONT_BYTEcxx . . $ WRITE_FONT_BYTE(fafe40e4b9ebf6eb).(FONTFILE2cxx . . $ FONTFILE2# ffile, uint8_tcxx . . $ uint8_t# c) { return fwrite(&c, sizeof(c), 1, (FILE *)ffile); }
213
214 inline int WRITE_FONT_DATAcxx . . $ WRITE_FONT_DATA(5122c2bbcc2ce4c8).(FONTFILE2cxx . . $ FONTFILE2# ffile, void *buf, int size, int nelem) {
215 int i;
216 i = (int)fwrite(buf, size, nelem, (FILE *)ffile);
217
218 ASSERTcxx . . $ `misc/pserror.h:246:9`!(i == nelem);
219
220 return i;
221 }
222
223 inline FONTFILE2cxx . . $ FONTFILE2# OPEN_FONT2cxx . . $ OPEN_FONT2(270b3c3705632523).(const char *filename) {
224 FONTFILE2cxx . . $ FONTFILE2# fp;
225
226 fp = (FONTFILE2cxx . . $ FONTFILE2#)fopen(filename, "wb");
227 if (!fp)
228 return nullptr;
229
230 return fp;
231 }
232
233 inline void CLOSE_FONT2cxx . . $ CLOSE_FONT2(8d4262d45fc644ab).(FONTFILE2cxx . . $ FONTFILE2# ffile) { fclose((FILE *)ffile); }
234
235 //////////////////////////////////////////////////////////////////////////////
236 // Functions
237
238 static void grfont_Closecxx . . $ grfont_Close(49f6e7a06ebc5aa8).();
239 static void grfont_TranslateToBitmapscxx . . $ grfont_TranslateToBitmaps(d4f767463ce0a6b3).(int handle);
240 static void grfont_XlateMonoCharcxx . . $ grfont_XlateMonoChar(c097311e36299223).(int bmp_handle, int x, int y, int index, tFontFileInfocxx . . $ tFontFileInfo# *ft, int width);
241 static void grfont_XlateColorCharcxx . . $ grfont_XlateColorChar(c097311e36299223).(int bmp_handle, int x, int y, int index, tFontFileInfocxx . . $ tFontFileInfo# *ft, int width);
242 static void grfont_XlateColorGrayCharcxx . . $ grfont_XlateColorGrayChar(c097311e36299223).(int bmp_handle, int x, int y, int index, tFontFileInfocxx . . $ tFontFileInfo# *ft, int width);
243 static void grfont_ClearBitmapcxx . . $ grfont_ClearBitmap(d4f767463ce0a6b3).(int bmp_handle);
244
245 // clears out font buffer.
246 void grfont_Resetcxx . . $ grfont_Reset(49f6e7a06ebc5aa8).() {
247 int i;
248
249 if (Font_initcxx . . $ Font_init.) {
250 // free all allocated fonts.
251 grfont_Closecxx . . $ grfont_Close(49f6e7a06ebc5aa8).();
252 } else {
253 atexitcxx . . $ atexit(cc8c495369588262).(grfont_Closecxx . . $ grfont_Close(49f6e7a06ebc5aa8).);
254 }
255
256 for (i = 0; i < MAX_FONTScxx . . $ MAX_FONTS.; i++)
257 Fontscxx . . $ Fonts.[i].referencescxx . . $ tFontInfo#references. = 0;
258
259 Font_initcxx . . $ Font_init. = true;
260 }
261
262 void grfont_Closecxx . . $ grfont_Close(49f6e7a06ebc5aa8).() {
263 int i;
264
265 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Font_init);
266
267 for (i = 0; i < MAX_FONTScxx . . $ MAX_FONTS.; i++)
268 if (Fontscxx . . $ Fonts.[i].referencescxx . . $ tFontInfo#references.)
269 grfont_Freecxx . . $ grfont_Free(d4f767463ce0a6b3).(i);
270
271 Font_initcxx . . $ Font_init. = false;
272 }
273
274 // returns a handle to a loaded font.
275 int grfont_Loadcxx . . $ grfont_Load(5c4306d8553b3696).(const char *fname) {
276 FONTFILEcxx . . $ FONTFILE# ff;
277 tFontFileInfocxx . . $ tFontFileInfo# fnt;
278 char fontname[32];
279 int num_char, i, handle = -1;
280
281 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Font_init);
282
283 // check if font is in list. if so, just return the handle.
284
285 // find free slot in font list.
286 for (i = 0; i < MAX_FONTScxx . . $ MAX_FONTS.; i++) {
287 if (Fontscxx . . $ Fonts.[i].referencescxx . . $ tFontInfo#references. == 0)
288 break;
289 }
290 ASSERTcxx . . $ `misc/pserror.h:246:9`!(i < MAX_FONTS);
291
292 handle = i;
293
294 // open file.
295 ff = OPEN_FONTcxx . . $ OPEN_FONT(6cfe12765e653818).(fname);
296 if (!ff) {
297 return false;
298 } else if (ff == (FONTFILEcxx . . $ FONTFILE#)0xffffffff) {
299 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Illegal font file: %s.\n", fname);
300 return false;
301 }
302
303 // read header information
304 fnt.widthcxx . . $ tFontFileInfo#width. = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff);
305 fnt.heightcxx . . $ tFontFileInfo#height. = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff);
306 fnt.flagscxx . . $ tFontFileInfo#flags. = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff);
307 fnt.baselinecxx . . $ tFontFileInfo#baseline. = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff);
308 fnt.min_asciicxx . . $ tFontFileInfo#min_ascii. = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ff);
309 fnt.max_asciicxx . . $ tFontFileInfo#max_ascii. = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ff);
310 READ_FONT_DATAcxx . . $ READ_FONT_DATA(fc60f957852e351e).(ff, fontname, 32, 1);
311
312 // read new info
313 if (fnt.flagscxx . . $ tFontFileInfo#flags. & FT_FFI2cxx . . $ `grtext/grtext.h:323:9`!) {
314 fnt.ffi2cxx . . $ tFontFileInfo#ffi2..trackingcxx . . $ tFontFileInfo2#tracking. = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff);
315 READ_FONT_DATAcxx . . $ READ_FONT_DATA(fc60f957852e351e).(ff, fnt.ffi2cxx . . $ tFontFileInfo#ffi2..reservedcxx . . $ tFontFileInfo2#reserved., sizeof(fnt.ffi2cxx . . $ tFontFileInfo#ffi2..reservedcxx . . $ tFontFileInfo2#reserved.), 1);
316 } else {
317 fnt.ffi2cxx . . $ tFontFileInfo#ffi2..trackingcxx . . $ tFontFileInfo2#tracking. = 0;
318 }
319
320 fnt.brightnesscxx . . $ tFontFileInfo#brightness. = ((fnt.baselinecxx . . $ tFontFileInfo#baseline. >> 8) / 10.0f);
321 /*
322 mprintf(0, "%s font.\n", fname);
323 mprintf(0, " <ht %d>::<min %d>::<max %d>::<base %d>", fnt.height, fnt.min_ascii, fnt.max_ascii, fnt.baseline);
324 */
325 num_char = fnt.max_asciicxx . . $ tFontFileInfo#max_ascii. - fnt.min_asciicxx . . $ tFontFileInfo#min_ascii. + 1;
326
327 if (fnt.max_asciicxx . . $ tFontFileInfo#max_ascii. < 'a') {
328 fnt.flagscxx . . $ tFontFileInfo#flags. |= FT_UPPERCASEcxx . . $ `grtext/grfont.cpp:125:9`!;
329 }
330
331 // Read in all widths
332 if (fnt.flagscxx . . $ tFontFileInfo#flags. & FT_PROPORTIONALcxx . . $ `grtext/grtext.h:319:9`!) {
333 fnt.char_widthscxx . . $ tFontFileInfo#char_widths. = (uint8_tcxx . . $ uint8_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(sizeof(uint8_t) * num_char);
334 for (i = 0; i < num_char; i++)
335 fnt.char_widthscxx . . $ tFontFileInfo#char_widths.[i] = (uint8_tcxx . . $ uint8_t#)READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff);
336 } else {
337 fnt.char_widthscxx . . $ tFontFileInfo#char_widths. = nullptr;
338 }
339
340 // Read in kerning data
341 if (fnt.flagscxx . . $ tFontFileInfo#flags. & FT_KERNEDcxx . . $ `grtext/grtext.h:320:9`!) {
342 int n_pairs = (int)READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff);
343 fnt.kern_datacxx . . $ tFontFileInfo#kern_data. = (uint8_tcxx . . $ uint8_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(sizeof(uint8_t) * 3 * (n_pairs + 1));
344 for (i = 0; i < n_pairs; i++) {
345 fnt.kern_datacxx . . $ tFontFileInfo#kern_data.[i * 3] = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ff);
346 fnt.kern_datacxx . . $ tFontFileInfo#kern_data.[i * 3 + 1] = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ff);
347 fnt.kern_datacxx . . $ tFontFileInfo#kern_data.[i * 3 + 2] = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ff);
348 }
349 fnt.kern_datacxx . . $ tFontFileInfo#kern_data.[i * 3] = 255;
350 fnt.kern_datacxx . . $ tFontFileInfo#kern_data.[i * 3 + 1] = 255;
351 fnt.kern_datacxx . . $ tFontFileInfo#kern_data.[i * 3 + 2] = 0;
352 } else {
353 fnt.kern_datacxx . . $ tFontFileInfo#kern_data. = nullptr;
354 }
355
356 // Read in pixel data.
357 // for color fonts, read in byte count and then the data,
358 // generate character data pointer table
359 // for mono fonts, read in byte count, then the data, convert to bits and store
360 // generate character data pointer table
361 int bytesize = READ_FONT_INTcxx . . $ READ_FONT_INT(413716a422df0036).(ff);
362
363 fnt.raw_datacxx . . $ tFontFileInfo#raw_data. = (uint8_tcxx . . $ uint8_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(bytesize);
364 fnt.char_datacxx . . $ tFontFileInfo#char_data. = (uint8_tcxx . . $ uint8_t# **)mem_malloccxx . . $ `mem/mem.h:79:9`!(num_char * sizeof(uint8_t *));
365
366 READ_FONT_DATAcxx . . $ READ_FONT_DATA(fc60f957852e351e).(ff, fnt.raw_datacxx . . $ tFontFileInfo#raw_data., bytesize, 1);
367
368 if (fnt.flagscxx . . $ tFontFileInfo#flags. & FT_COLORcxx . . $ `grtext/grtext.h:318:9`!) {
369 int off = 0;
370 // mprintf(0, "::color");
371 for (i = 0; i < num_char; i++) {
372 fnt.char_datacxx . . $ tFontFileInfo#char_data.[i] = fnt.raw_datacxx . . $ tFontFileInfo#raw_data. + off;
373 if (fnt.flagscxx . . $ tFontFileInfo#flags. & FT_PROPORTIONALcxx . . $ `grtext/grtext.h:319:9`!)
374 off += (fnt.char_widthscxx . . $ tFontFileInfo#char_widths.[i] * fnt.heightcxx . . $ tFontFileInfo#height. * BITS_TO_BYTEScxx . . $ `grtext/grfont.cpp:130:9`!(BPP_16cxx . . $ `lib/grdefs.h:61:9`!));
375 else
376 off += (fnt.widthcxx . . $ tFontFileInfo#width. * fnt.heightcxx . . $ tFontFileInfo#height. * BITS_TO_BYTEScxx . . $ `grtext/grfont.cpp:130:9`!(BPP_16cxx . . $ `lib/grdefs.h:61:9`!));
377 }
378 } else { // Monochrome
379 uint8_tcxx . . $ uint8_t# *ptr = fnt.raw_datacxx . . $ tFontFileInfo#raw_data.;
380 // mprintf(0, "::mono");
381 for (i = 0; i < num_char; i++) {
382 fnt.char_datacxx . . $ tFontFileInfo#char_data.[i] = ptr;
383 if (fnt.flagscxx . . $ tFontFileInfo#flags. & FT_PROPORTIONALcxx . . $ `grtext/grtext.h:319:9`!)
384 ptr += BITS_TO_BYTEScxx . . $ `grtext/grfont.cpp:130:9`!(fnt.char_widths[i]) * fnt.heightcxx . . $ tFontFileInfo#height.;
385 else
386 ptr += BITS_TO_BYTEScxx . . $ `grtext/grfont.cpp:130:9`!(fnt.width) * fnt.heightcxx . . $ tFontFileInfo#height.;
387 }
388 }
389
390 // Then read in
391 CLOSE_FONTcxx . . $ CLOSE_FONT(3639e799710acb68).(ff);
392
393 // mprintf(0, "\n");
394
395 strcpy(Fontscxx . . $ Fonts.[handle].filenamecxx . . $ tFontInfo#filename., fname);
396 Fontscxx . . $ Fonts.[handle].referencescxx . . $ tFontInfo#references. = 1;
397 Fontscxx . . $ Fonts.[handle].fontcxx . . $ tFontInfo#font. =cxx . . $ tFontFileInfo#`operator=`(31d8b2ced4827b77). fnt;
398
399 // draw font to bitmaps, load into surfaces too.
400 grfont_TranslateToBitmapscxx . . $ grfont_TranslateToBitmaps(d4f767463ce0a6b3).(handle);
401
402 return handle;
403 }
404
405 // frees a loaded font
406 void grfont_Freecxx . . $ grfont_Free(d4f767463ce0a6b3).(int handle) {
407 tFontInfocxx . . $ tFontInfo# *ft;
408 int i;
409
410 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Font_init);
411 ASSERTcxx . . $ `misc/pserror.h:246:9`!(handle > -1 && handle < MAX_FONTS);
412
413 // delete font surface info.
414 ft = &Fontscxx . . $ Fonts.[handle];
415 if (ft->ch_bmpcxx . . $ tFontInfo#ch_bmp.)
416 delete[] ft->ch_bmpcxx . . $ tFontInfo#ch_bmp.;
417 if (ft->ch_wfcxx . . $ tFontInfo#ch_wf.)
418 delete[] ft->ch_wfcxx . . $ tFontInfo#ch_wf.;
419 if (ft->ch_hfcxx . . $ tFontInfo#ch_hf.)
420 delete[] ft->ch_hfcxx . . $ tFontInfo#ch_hf.;
421 if (ft->ch_ufcxx . . $ tFontInfo#ch_uf.)
422 delete[] ft->ch_ufcxx . . $ tFontInfo#ch_uf.;
423 if (ft->ch_vfcxx . . $ tFontInfo#ch_vf.)
424 delete[] ft->ch_vfcxx . . $ tFontInfo#ch_vf.;
425 if (ft->ch_wcxx . . $ tFontInfo#ch_w.)
426 delete[] ft->ch_wcxx . . $ tFontInfo#ch_w.;
427 if (ft->ch_hcxx . . $ tFontInfo#ch_h.)
428 delete[] ft->ch_hcxx . . $ tFontInfo#ch_h.;
429 if (ft->ch_ucxx . . $ tFontInfo#ch_u.)
430 delete[] ft->ch_ucxx . . $ tFontInfo#ch_u.;
431 if (ft->ch_vcxx . . $ tFontInfo#ch_v.)
432 delete[] ft->ch_vcxx . . $ tFontInfo#ch_v.;
433
434 for (i = 0; i < MAX_FONT_BITMAPScxx . . $ MAX_FONT_BITMAPS.; i++) {
435 if (ft->bmpscxx . . $ tFontInfo#bmps.[i] != -1)
436 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(ft->bmpscxx . . $ tFontInfo#bmps.[i]);
437 }
438
439 // delete font file info.
440 if ((ft->fontcxx . . $ tFontInfo#font..flagscxx . . $ tFontFileInfo#flags. & FT_KERNEDcxx . . $ `grtext/grtext.h:320:9`!) && ft->fontcxx . . $ tFontInfo#font..kern_datacxx . . $ tFontFileInfo#kern_data.) {
441 mem_freecxx . . $ `mem/mem.h:80:9`!(ft->font.kern_data);
442 }
443
444 if (ft->fontcxx . . $ tFontInfo#font..flagscxx . . $ tFontFileInfo#flags. & FT_PROPORTIONALcxx . . $ `grtext/grtext.h:319:9`!) {
445 mem_freecxx . . $ `mem/mem.h:80:9`!(ft->font.char_widths);
446 }
447
448 ft->referencescxx . . $ tFontInfo#references. = 0;
449
450 mem_freecxx . . $ `mem/mem.h:80:9`!(ft->font.raw_data);
451 mem_freecxx . . $ `mem/mem.h:80:9`!(ft->font.char_data);
452 }
453
454 // loads a font template
455 bool grfont_LoadTemplatecxx . . $ grfont_LoadTemplate(5e0be355757499ea).(const char *fname, tFontTemplatecxx . . $ tFontTemplate# *ft) {
456 FONTFILEcxx . . $ FONTFILE# ff;
457 char fontname[32];
458 int16_t ft_width, ft_height, ft_flags, ft_minasc, ft_maxasc, num_char, i;
459 tFontFileInfo2cxx . . $ tFontFileInfo2# ffi2;
460
461 // open file.
462 ff = OPEN_FONTcxx . . $ OPEN_FONT(6cfe12765e653818).(fname);
463 if (!ff) {
464 Errorcxx . . $ Error(326aeb464d16410c).("Unable to open font %s.\n", fname);
465 } else if (ff == (FONTFILEcxx . . $ FONTFILE#)0xffffffff) {
466 Errorcxx . . $ Error(326aeb464d16410c).("Illegal font file: %s.\n", fname);
467 }
468
469 // read header information
470 ft_width = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff);
471 ft_height = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff);
472 ft_flags = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff);
473 READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff); // skip baseline value (HACKED FOR BRIGHTNESS)
474 ft_minasc = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ff);
475 ft_maxasc = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ff);
476 READ_FONT_DATAcxx . . $ READ_FONT_DATA(fc60f957852e351e).(ff, fontname, 32, 1); // read namae
477
478 // read ffi2 font info
479 if (ft_flags & FT_FFI2cxx . . $ `grtext/grtext.h:323:9`!) {
480 ffi2.trackingcxx . . $ tFontFileInfo2#tracking. = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff);
481 READ_FONT_DATAcxx . . $ READ_FONT_DATA(fc60f957852e351e).(ff, &ffi2.reservedcxx . . $ tFontFileInfo2#reserved., sizeof(ffi2.reservedcxx . . $ tFontFileInfo2#reserved.), 1);
482 }
483
484 num_char = ft_maxasc - ft_minasc + 1;
485
486 // Read in all widths
487 if (ft_flags & FT_PROPORTIONALcxx . . $ `grtext/grtext.h:319:9`!) {
488 ft->ch_widthscxx . . $ tFontTemplate#ch_widths. = (uint8_tcxx . . $ uint8_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(num_char);
489 for (i = 0; i < num_char; i++)
490 ft->ch_widthscxx . . $ tFontTemplate#ch_widths.[i] = (uint8_tcxx . . $ uint8_t#)READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff);
491 } else {
492 ft->ch_widthscxx . . $ tFontTemplate#ch_widths. = nullptr;
493 }
494
495 if (ft_flags & FT_KERNEDcxx . . $ `grtext/grtext.h:320:9`!) {
496 int n_pairs = (int)READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff);
497 ft->kern_datacxx . . $ tFontTemplate#kern_data. = (uint8_tcxx . . $ uint8_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(sizeof(uint8_t) * 3 * (n_pairs + 1));
498 for (i = 0; i < n_pairs; i++) {
499 ft->kern_datacxx . . $ tFontTemplate#kern_data.[i * 3] = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ff);
500 ft->kern_datacxx . . $ tFontTemplate#kern_data.[i * 3 + 1] = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ff);
501 ft->kern_datacxx . . $ tFontTemplate#kern_data.[i * 3 + 2] = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ff);
502 }
503 ft->kern_datacxx . . $ tFontTemplate#kern_data.[i * 3] = 255;
504 ft->kern_datacxx . . $ tFontTemplate#kern_data.[i * 3 + 1] = 255;
505 ft->kern_datacxx . . $ tFontTemplate#kern_data.[i * 3 + 2] = 0;
506 } else {
507 ft->kern_datacxx . . $ tFontTemplate#kern_data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
508 }
509
510 ft->ch_heightcxx . . $ tFontTemplate#ch_height. = (uint8_tcxx . . $ uint8_t#)ft_height;
511 ft->ch_maxwidthcxx . . $ tFontTemplate#ch_maxwidth. = (uint8_tcxx . . $ uint8_t#)ft_width;
512 ft->max_asciicxx . . $ tFontTemplate#max_ascii. = ft_maxasc;
513 ft->min_asciicxx . . $ tFontTemplate#min_ascii. = ft_minasc;
514 ft->proportionalcxx . . $ tFontTemplate#proportional. = (ft_flags & FT_PROPORTIONALcxx . . $ `grtext/grtext.h:319:9`!) ? true : false;
515 ft->uppercasecxx . . $ tFontTemplate#uppercase. = (ft_maxasc < 'a');
516 ft->monochromaticcxx . . $ tFontTemplate#monochromatic. = (ft_flags & FT_COLORcxx . . $ `grtext/grtext.h:318:9`!) ? false : true;
517 ft->newstylecxx . . $ tFontTemplate#newstyle. = (ft_flags & FT_FMT4444cxx . . $ `grtext/grtext.h:322:9`!) ? true : false;
518 ft->ffi2cxx . . $ tFontTemplate#ffi2. = (ft_flags & FT_FFI2cxx . . $ `grtext/grtext.h:323:9`!) ? true : false;
519
520 ft->ch_trackingcxx . . $ tFontTemplate#ch_tracking. = (int8_t)((ft_flags & FT_FFI2cxx . . $ `grtext/grtext.h:323:9`!) ? ffi2.trackingcxx . . $ tFontFileInfo2#tracking. : 0);
521
522 CLOSE_FONTcxx . . $ CLOSE_FONT(3639e799710acb68).(ff);
523
524 return true;
525 }
526
527 // frees a font template
528 void grfont_FreeTemplatecxx . . $ grfont_FreeTemplate(218f1c398dde951b).(tFontTemplatecxx . . $ tFontTemplate# *ft) {
529 if (ft->kern_datacxx . . $ tFontTemplate#kern_data.) {
530 mem_freecxx . . $ `mem/mem.h:80:9`!(ft->kern_data);
531 ft->kern_datacxx . . $ tFontTemplate#kern_data. = nullptr;
532 }
533 if (ft->ch_widthscxx . . $ tFontTemplate#ch_widths.) {
534 mem_freecxx . . $ `mem/mem.h:80:9`!(ft->ch_widths);
535 ft->ch_widthscxx . . $ tFontTemplate#ch_widths. = nullptr;
536 }
537 }
538
539 // MTS: unused?
540 // sets a template to a font, be careful.
541 bool grfont_SetTemplatecxx . . $ grfont_SetTemplate(773c94601bc0322b).(const char *pathname, const tFontTemplatecxx . . $ tFontTemplate# *ft) {
542 // okay, load the font manually, set the template members, then save it out.
543 tFontFileInfocxx . . $ tFontFileInfo# fnt;
544 char tempstr[32];
545 FONTFILEcxx . . $ FONTFILE# ffin;
546 FONTFILE2cxx . . $ FONTFILE2# ffout;
547 int num_char, i;
548
549 tFontFileInfo2cxx . . $ tFontFileInfo2# ffi2;
550
551 ffin = OPEN_FONTcxx . . $ OPEN_FONT(6cfe12765e653818).(pathname);
552 if (!ffin) {
553 return false;
554 } else if (ffin == (FONTFILEcxx . . $ FONTFILE#)0xffffffff) {
555 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Illegal font file %s\n", pathname);
556 return false;
557 }
558
559 // read header information
560 fnt.widthcxx . . $ tFontFileInfo#width. = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ffin);
561 fnt.heightcxx . . $ tFontFileInfo#height. = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ffin);
562 fnt.flagscxx . . $ tFontFileInfo#flags. = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ffin);
563 fnt.baselinecxx . . $ tFontFileInfo#baseline. = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ffin);
564 fnt.min_asciicxx . . $ tFontFileInfo#min_ascii. = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ffin);
565 fnt.max_asciicxx . . $ tFontFileInfo#max_ascii. = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ffin);
566 READ_FONT_DATAcxx . . $ READ_FONT_DATA(fc60f957852e351e).(ffin, tempstr, 32, 1);
567
568 // read ffi2 font info
569 if (fnt.flagscxx . . $ tFontFileInfo#flags. & FT_FFI2cxx . . $ `grtext/grtext.h:323:9`!) {
570 ffi2.trackingcxx . . $ tFontFileInfo2#tracking. = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ffin);
571 READ_FONT_DATAcxx . . $ READ_FONT_DATA(fc60f957852e351e).(ffin, &ffi2.reservedcxx . . $ tFontFileInfo2#reserved., sizeof(ffi2.reservedcxx . . $ tFontFileInfo2#reserved.), 1);
572 }
573
574 fnt.brightnesscxx . . $ tFontFileInfo#brightness. = ((fnt.baselinecxx . . $ tFontFileInfo#baseline. >> 8) / 10.0f);
575
576 num_char = fnt.max_asciicxx . . $ tFontFileInfo#max_ascii. - fnt.min_asciicxx . . $ tFontFileInfo#min_ascii. + 1;
577
578 // Read in all widths
579 if (fnt.flagscxx . . $ tFontFileInfo#flags. & FT_PROPORTIONALcxx . . $ `grtext/grtext.h:319:9`!) {
580 fnt.char_widthscxx . . $ tFontFileInfo#char_widths. = (uint8_tcxx . . $ uint8_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(sizeof(uint8_t) * num_char);
581 for (i = 0; i < num_char; i++)
582 fnt.char_widthscxx . . $ tFontFileInfo#char_widths.[i] = (uint8_tcxx . . $ uint8_t#)READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ffin);
583 } else {
584 fnt.char_widthscxx . . $ tFontFileInfo#char_widths. = nullptr;
585 }
586
587 // Read in kerning data
588 if (fnt.flagscxx . . $ tFontFileInfo#flags. & FT_KERNEDcxx . . $ `grtext/grtext.h:320:9`!) {
589 int n_pairs = (int)READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ffin);
590 fnt.kern_datacxx . . $ tFontFileInfo#kern_data. = (uint8_tcxx . . $ uint8_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(sizeof(uint8_t) * 3 * (n_pairs + 1));
591 for (i = 0; i < n_pairs; i++) {
592 fnt.kern_datacxx . . $ tFontFileInfo#kern_data.[i * 3] = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ffin);
593 fnt.kern_datacxx . . $ tFontFileInfo#kern_data.[i * 3 + 1] = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ffin);
594 fnt.kern_datacxx . . $ tFontFileInfo#kern_data.[i * 3 + 2] = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ffin);
595 }
596 fnt.kern_datacxx . . $ tFontFileInfo#kern_data.[i * 3] = 255;
597 fnt.kern_datacxx . . $ tFontFileInfo#kern_data.[i * 3 + 1] = 255;
598 fnt.kern_datacxx . . $ tFontFileInfo#kern_data.[i * 3 + 2] = 0;
599 } else {
600 fnt.kern_datacxx . . $ tFontFileInfo#kern_data. = nullptr;
601 }
602
603 // Read in pixel data.
604 int bytesize = READ_FONT_INTcxx . . $ READ_FONT_INT(413716a422df0036).(ffin);
605
606 fnt.raw_datacxx . . $ tFontFileInfo#raw_data. = (uint8_tcxx . . $ uint8_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(bytesize);
607
608 READ_FONT_DATAcxx . . $ READ_FONT_DATA(fc60f957852e351e).(ffin, fnt.raw_datacxx . . $ tFontFileInfo#raw_data., bytesize, 1);
609
610 CLOSE_FONTcxx . . $ CLOSE_FONT(3639e799710acb68).(ffin);
611
612 // set template values
613 fnt.widthcxx . . $ tFontFileInfo#width. = ft->ch_maxwidthcxx . . $ tFontTemplate#ch_maxwidth.;
614 fnt.heightcxx . . $ tFontFileInfo#height. = ft->ch_heightcxx . . $ tFontTemplate#ch_height.;
615 fnt.flagscxx . . $ tFontFileInfo#flags. = (ft->proportionalcxx . . $ tFontTemplate#proportional. ? FT_PROPORTIONALcxx . . $ `grtext/grtext.h:319:9`! : 0) + ((!ft->monochromaticcxx . . $ tFontTemplate#monochromatic.) ? FT_COLORcxx . . $ `grtext/grtext.h:318:9`! : 0) +
616 (ft->kern_datacxx . . $ tFontTemplate#kern_data. ? FT_KERNEDcxx . . $ `grtext/grtext.h:320:9`! : 0) + (ft->newstylecxx . . $ tFontTemplate#newstyle. ? FT_FMT4444cxx . . $ `grtext/grtext.h:322:9`! : 0);
617 fnt.min_asciicxx . . $ tFontFileInfo#min_ascii. = (uint8_tcxx . . $ uint8_t#)ft->min_asciicxx . . $ tFontTemplate#min_ascii.;
618 fnt.max_asciicxx . . $ tFontFileInfo#max_ascii. = (uint8_tcxx . . $ uint8_t#)ft->max_asciicxx . . $ tFontTemplate#max_ascii.;
619
620 if (ft->ffi2cxx . . $ tFontTemplate#ffi2.)
621 fnt.flagscxx . . $ tFontFileInfo#flags. |= FT_FFI2cxx . . $ `grtext/grtext.h:323:9`!;
622
623 if (fnt.kern_datacxx . . $ tFontFileInfo#kern_data.) {
624 mem_freecxx . . $ `mem/mem.h:80:9`!(fnt.kern_data);
625 }
626 if (fnt.char_widthscxx . . $ tFontFileInfo#char_widths.) {
627 mem_freecxx . . $ `mem/mem.h:80:9`!(fnt.char_widths);
628 }
629 fnt.kern_datacxx . . $ tFontFileInfo#kern_data. = ft->kern_datacxx . . $ tFontTemplate#kern_data.;
630 fnt.char_widthscxx . . $ tFontFileInfo#char_widths. = ft->ch_widthscxx . . $ tFontTemplate#ch_widths.;
631
632 // write out font.
633 ffout = OPEN_FONT2cxx . . $ OPEN_FONT2(270b3c3705632523).(pathname);
634 if (!ffout) {
635 return false;
636 }
637
638 // Write file id.
639 WRITE_FONT_INTcxx . . $ WRITE_FONT_INT(c2adc39b7d70763e).(ffout, 0xfeedbaba);
640 WRITE_FONT_SHORTcxx . . $ WRITE_FONT_SHORT(86be10c099ec69cc).(ffout, fnt.widthcxx . . $ tFontFileInfo#width.);
641 WRITE_FONT_SHORTcxx . . $ WRITE_FONT_SHORT(86be10c099ec69cc).(ffout, fnt.heightcxx . . $ tFontFileInfo#height.);
642 WRITE_FONT_SHORTcxx . . $ WRITE_FONT_SHORT(86be10c099ec69cc).(ffout, fnt.flagscxx . . $ tFontFileInfo#flags.);
643 WRITE_FONT_SHORTcxx . . $ WRITE_FONT_SHORT(86be10c099ec69cc).(ffout, fnt.baselinecxx . . $ tFontFileInfo#baseline.);
644 WRITE_FONT_BYTEcxx . . $ WRITE_FONT_BYTE(fafe40e4b9ebf6eb).(ffout, fnt.min_asciicxx . . $ tFontFileInfo#min_ascii.);
645 WRITE_FONT_BYTEcxx . . $ WRITE_FONT_BYTE(fafe40e4b9ebf6eb).(ffout, fnt.max_asciicxx . . $ tFontFileInfo#max_ascii.);
646 WRITE_FONT_DATAcxx . . $ WRITE_FONT_DATA(5122c2bbcc2ce4c8).(ffout, tempstr, 32, 1);
647
648 if (fnt.flagscxx . . $ tFontFileInfo#flags. & FT_FFI2cxx . . $ `grtext/grtext.h:323:9`!) {
649 WRITE_FONT_SHORTcxx . . $ WRITE_FONT_SHORT(86be10c099ec69cc).(ffout, (int16_t)ft->ch_trackingcxx . . $ tFontTemplate#ch_tracking.);
650 WRITE_FONT_DATAcxx . . $ WRITE_FONT_DATA(5122c2bbcc2ce4c8).(ffout, ffi2.reservedcxx . . $ tFontFileInfo2#reserved., sizeof(ffi2.reservedcxx . . $ tFontFileInfo2#reserved.), 1);
651 }
652
653 num_char = ft->max_asciicxx . . $ tFontTemplate#max_ascii. - ft->min_asciicxx . . $ tFontTemplate#min_ascii. + 1;
654
655 // Write widths now if necessary.(FT_PROPORTIONAL)
656 if (fnt.flagscxx . . $ tFontFileInfo#flags. & FT_PROPORTIONALcxx . . $ `grtext/grtext.h:319:9`!) {
657 for (i = 0; i < num_char; i++)
658 WRITE_FONT_SHORTcxx . . $ WRITE_FONT_SHORT(86be10c099ec69cc).(ffout, (int16_t)fnt.char_widthscxx . . $ tFontFileInfo#char_widths.[i]);
659 }
660
661 if (fnt.flagscxx . . $ tFontFileInfo#flags. & FT_KERNEDcxx . . $ `grtext/grtext.h:320:9`!) {
662 // iterate new kerning info bytes
663 uint8_tcxx . . $ uint8_t# *ch = fnt.kern_datacxx . . $ tFontFileInfo#kern_data.;
664 int n_bytes = 0, n_pairs;
665 while (ch[n_bytes] != 255) {
666 n_bytes += 3;
667 }
668
669 ASSERTcxx . . $ `misc/pserror.h:246:9`!((n_bytes % 3) == 0);
670 n_pairs = n_bytes / 3;
671 WRITE_FONT_SHORTcxx . . $ WRITE_FONT_SHORT(86be10c099ec69cc).(ffout, (int16_t)n_pairs);
672
673 for (i = 0; i < n_pairs; i++) {
674 WRITE_FONT_BYTEcxx . . $ WRITE_FONT_BYTE(fafe40e4b9ebf6eb).(ffout, ch[i * 3]);
675 WRITE_FONT_BYTEcxx . . $ WRITE_FONT_BYTE(fafe40e4b9ebf6eb).(ffout, ch[i * 3 + 1]);
676 WRITE_FONT_BYTEcxx . . $ WRITE_FONT_BYTE(fafe40e4b9ebf6eb).(ffout, ch[i * 3 + 2]);
677 }
678 }
679
680 WRITE_FONT_INTcxx . . $ WRITE_FONT_INT(c2adc39b7d70763e).(ffout, bytesize);
681 WRITE_FONT_DATAcxx . . $ WRITE_FONT_DATA(5122c2bbcc2ce4c8).(ffout, fnt.raw_datacxx . . $ tFontFileInfo#raw_data., bytesize, 1);
682
683 CLOSE_FONT2cxx . . $ CLOSE_FONT2(8d4262d45fc644ab).(ffout);
684
685 // free raw data loaded, don't free kern and widths, already freed, template versions remain
686 mem_freecxx . . $ `mem/mem.h:80:9`!(fnt.raw_data);
687
688 return true;
689 }
690
691 // MTS: Unused?
692 // sets a font's template without saving...
693 bool grfont_SetKerningcxx . . $ grfont_SetKerning(f90e3f9e410d4f54).(int font, uint8_tcxx . . $ uint8_t# *kern_data) {
694 tFontInfocxx . . $ tFontInfo# *oldft = &Fontscxx . . $ Fonts.[font];
695 int n_pairs = 0;
696
697 // reset kerning...
698 if (oldft->fontcxx . . $ tFontInfo#font..kern_datacxx . . $ tFontFileInfo#kern_data.) {
699 mem_freecxx . . $ `mem/mem.h:80:9`!(oldft->font.kern_data);
700 oldft->fontcxx . . $ tFontInfo#font..kern_datacxx . . $ tFontFileInfo#kern_data. = nullptr;
701 }
702
703 if (kern_data) {
704 while (kern_data[n_pairs * 3] != 255)
705 n_pairs++;
706
707 oldft->fontcxx . . $ tFontInfo#font..kern_datacxx . . $ tFontFileInfo#kern_data. = (uint8_tcxx . . $ uint8_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!((n_pairs + 1) * 3 * sizeof(uint8_t));
708 n_pairs = 0;
709 while (kern_data[n_pairs * 3] != 255) {
710 oldft->fontcxx . . $ tFontInfo#font..kern_datacxx . . $ tFontFileInfo#kern_data.[n_pairs * 3] = kern_data[n_pairs * 3];
711 oldft->fontcxx . . $ tFontInfo#font..kern_datacxx . . $ tFontFileInfo#kern_data.[n_pairs * 3 + 1] = kern_data[n_pairs * 3 + 1];
712 oldft->fontcxx . . $ tFontInfo#font..kern_datacxx . . $ tFontFileInfo#kern_data.[n_pairs * 3 + 2] = kern_data[n_pairs * 3 + 2];
713 n_pairs++;
714 }
715 oldft->fontcxx . . $ tFontInfo#font..kern_datacxx . . $ tFontFileInfo#kern_data.[n_pairs * 3] = 255;
716 oldft->fontcxx . . $ tFontInfo#font..kern_datacxx . . $ tFontFileInfo#kern_data.[n_pairs * 3 + 1] = 255;
717 oldft->fontcxx . . $ tFontInfo#font..kern_datacxx . . $ tFontFileInfo#kern_data.[n_pairs * 3 + 2] = 0;
718 }
719
720 // we're not going to reset other stuff for now... just kerning!
721 return true;
722 }
723
724 // MTS: Unused?
725 // sets a font's tracking
726 bool grfont_SetTrackingcxx . . $ grfont_SetTracking(cf9ef193275fa6d8).(int font, int tracking) {
727 ASSERTcxx . . $ `misc/pserror.h:246:9`!(font >= 0 && font < MAX_FONTS);
728
729 tFontInfocxx . . $ tFontInfo# *oldft = &Fontscxx . . $ Fonts.[font];
730
731 oldft->fontcxx . . $ tFontInfo#font..ffi2cxx . . $ tFontFileInfo#ffi2..trackingcxx . . $ tFontFileInfo2#tracking. = (int16_t)tracking;
732
733 return false;
734 }
735
736 int grfont_GetTrackingcxx . . $ grfont_GetTracking(7864480464b09eea).(int font) {
737 ASSERTcxx . . $ `misc/pserror.h:246:9`!(font >= 0 && font < MAX_FONTS);
738 // if (Fonts[font].font.flags & FT_FFI2) {
739 return (int)Fontscxx . . $ Fonts.[font].fontcxx . . $ tFontInfo#font..ffi2cxx . . $ tFontFileInfo#ffi2..trackingcxx . . $ tFontFileInfo2#tracking.;
740 // }
741
742 // return 0;
743 }
744
745 // render a character
746 int grfont_BltCharcxx . . $ grfont_BltChar(3fbed1af05ab96ff).(int font, tCharBltcxx . . $ tCharBlt# *cbi) {
747 ASSERTcxx . . $ `misc/pserror.h:246:9`!(font > -1 && font < MAX_FONTS);
748
749 tFontInfocxx . . $ tFontInfo# *ft = &Fontscxx . . $ Fonts.[font];
750
751 // save current x and get this font
752 if (cbi->chcxx . . $ tCharBlt#ch. > ft->fontcxx . . $ tFontInfo#font..max_asciicxx . . $ tFontFileInfo#max_ascii. && (ft->fontcxx . . $ tFontInfo#font..flagscxx . . $ tFontFileInfo#flags. & FT_UPPERCASEcxx . . $ `grtext/grfont.cpp:125:9`!)) {
753 cbi->chcxx . . $ tCharBlt#ch. = toupper(cbi->chcxx . . $ tCharBlt#ch.);
754 }
755
756 if ((cbi->chcxx . . $ tCharBlt#ch. < ft->fontcxx . . $ tFontInfo#font..min_asciicxx . . $ tFontFileInfo#min_ascii.) || (cbi->chcxx . . $ tCharBlt#ch. > ft->fontcxx . . $ tFontInfo#font..max_asciicxx . . $ tFontFileInfo#max_ascii.))
757 return (cbi->xcxx . . $ tCharBlt#x. + 1);
758
759 cbi->chcxx . . $ tCharBlt#ch. = cbi->chcxx . . $ tCharBlt#ch. - ft->fontcxx . . $ tFontInfo#font..min_asciicxx . . $ tFontFileInfo#min_ascii.;
760
761 if (!cbi->clippedcxx . . $ tCharBlt#clipped.) {
762
763 if (ft->fontcxx . . $ tFontInfo#font..flagscxx . . $ tFontFileInfo#flags. & FT_PROPORTIONALcxx . . $ `grtext/grtext.h:319:9`!)
764 cbi->swcxx . . $ tCharBlt#sw. = (int)(ft->fontcxx . . $ tFontInfo#font..char_widthscxx . . $ tFontFileInfo#char_widths.[cbi->chcxx . . $ tCharBlt#ch.]);
765 else
766 cbi->swcxx . . $ tCharBlt#sw. = (int)(ft->fontcxx . . $ tFontInfo#font..widthcxx . . $ tFontFileInfo#width.);
767 cbi->shcxx . . $ tCharBlt#sh. = (int)(ft->fontcxx . . $ tFontInfo#font..heightcxx . . $ tFontFileInfo#height.);
768 cbi->sxcxx . . $ tCharBlt#sx. = 0;
769 cbi->sycxx . . $ tCharBlt#sy. = 0;
770
771 rend_DrawFontCharactercxx . . $ rend_DrawFontCharacter(d3f982e0313c7b8c).(ft->bmpscxx . . $ tFontInfo#bmps.[ft->ch_bmpcxx . . $ tFontInfo#ch_bmp.[cbi->chcxx . . $ tCharBlt#ch.]], cbi->xcxx . . $ tCharBlt#x., cbi->ycxx . . $ tCharBlt#y., (int)(cbi->xcxx . . $ tCharBlt#x. + cbi->swcxx . . $ tCharBlt#sw. * cbi->dswcxx . . $ tCharBlt#dsw.),
772 (int)(cbi->ycxx . . $ tCharBlt#y. + cbi->shcxx . . $ tCharBlt#sh. * cbi->dshcxx . . $ tCharBlt#dsh.), ft->ch_ufcxx . . $ tFontInfo#ch_uf.[cbi->chcxx . . $ tCharBlt#ch.], ft->ch_vfcxx . . $ tFontInfo#ch_vf.[cbi->chcxx . . $ tCharBlt#ch.],
773 ft->ch_wfcxx . . $ tFontInfo#ch_wf.[cbi->chcxx . . $ tCharBlt#ch.], ft->ch_hfcxx . . $ tFontInfo#ch_hf.[cbi->chcxx . . $ tCharBlt#ch.]);
774 return (cbi->xcxx . . $ tCharBlt#x. + (int)(cbi->swcxx . . $ tCharBlt#sw. * cbi->dswcxx . . $ tCharBlt#dsw.));
775 //@@ rend_DrawFontCharacter (ft->bmps[ft->ch_bmp[cbi->ch]], cbi->x,cbi->y,
776 //@@ cbi->x+ft->ch_w[cbi->ch], cbi->y+ft->ch_h[cbi->ch],
777 //@@ ft->ch_uf[cbi->ch],
778 // ft->ch_vf[cbi->ch],
779 //@@ ft->ch_wf[cbi->ch],
780 // ft->ch_hf[cbi->ch]);
781 //@@ return (cbi->x + ft->ch_w[cbi->ch] - 1);
782 } else {
783 rend_DrawFontCharactercxx . . $ rend_DrawFontCharacter(d3f982e0313c7b8c).(
784 ft->bmpscxx . . $ tFontInfo#bmps.[ft->ch_bmpcxx . . $ tFontInfo#ch_bmp.[cbi->chcxx . . $ tCharBlt#ch.]], cbi->xcxx . . $ tCharBlt#x., cbi->ycxx . . $ tCharBlt#y.,
785 (int)(cbi->xcxx . . $ tCharBlt#x. + cbi->swcxx . . $ tCharBlt#sw.), // don't scale since these values are already scaled
786 (int)(cbi->ycxx . . $ tCharBlt#y. + cbi->shcxx . . $ tCharBlt#sh.), ft->ch_ufcxx . . $ tFontInfo#ch_uf.[cbi->chcxx . . $ tCharBlt#ch.] + (((float)cbi->sxcxx . . $ tCharBlt#sx.) / ((float)GRFONT_SURFACE_WIDTHcxx . . $ `grtext/grfont.cpp:150:9`!)),
787 ft->ch_vfcxx . . $ tFontInfo#ch_vf.[cbi->chcxx . . $ tCharBlt#ch.] + (((float)cbi->sycxx . . $ tCharBlt#sy.) / ((float)GRFONT_SURFACE_HEIGHTcxx . . $ `grtext/grfont.cpp:151:9`!)),
788 ((float)cbi->swcxx . . $ tCharBlt#sw.) / ((float)GRFONT_SURFACE_WIDTHcxx . . $ `grtext/grfont.cpp:150:9`!), ((float)cbi->shcxx . . $ tCharBlt#sh.) / ((float)GRFONT_SURFACE_HEIGHTcxx . . $ `grtext/grfont.cpp:151:9`!));
789 return (cbi->xcxx . . $ tCharBlt#x. + (int)(cbi->swcxx . . $ tCharBlt#sw.)); // scaled value already
790 }
791 }
792
793 // returns a character's width
794 int grfont_GetCharWidthcxx . . $ grfont_GetCharWidth(9b79fb6aee4c0440).(int font, int ch) {
795 tFontFileInfocxx . . $ tFontFileInfo# *ft;
796
797 ASSERTcxx . . $ `misc/pserror.h:246:9`!(font > -1 && font < MAX_FONTS);
798
799 ft = &Fontscxx . . $ Fonts.[font].fontcxx . . $ tFontInfo#font.;
800 ch = (int)((uint8_tcxx . . $ uint8_t#)ch);
801
802 if (ch > ft->max_asciicxx . . $ tFontFileInfo#max_ascii. && (ft->flagscxx . . $ tFontFileInfo#flags. & FT_UPPERCASEcxx . . $ `grtext/grfont.cpp:125:9`!)) {
803 ch = toupper(ch);
804 }
805
806 if (ch < ft->min_asciicxx . . $ tFontFileInfo#min_ascii. || ch > ft->max_asciicxx . . $ tFontFileInfo#max_ascii.)
807 return 0;
808 else if (ft->flagscxx . . $ tFontFileInfo#flags. & FT_PROPORTIONALcxx . . $ `grtext/grtext.h:319:9`!)
809 return ft->char_widthscxx . . $ tFontFileInfo#char_widths.[ch - ft->min_asciicxx . . $ tFontFileInfo#min_ascii.];
810 else
811 return ft->widthcxx . . $ tFontFileInfo#width.;
812 }
813
814 // returns a font's height
815 int grfont_GetHeightcxx . . $ grfont_GetHeight(7864480464b09eea).(int font) {
816 ASSERTcxx . . $ `misc/pserror.h:246:9`!(font > -1 && font < MAX_FONTS);
817 return Fontscxx . . $ Fonts.[font].fontcxx . . $ tFontInfo#font..heightcxx . . $ tFontFileInfo#height.;
818 }
819
820 // translates raw font data to bitmaps.
821 void grfont_TranslateToBitmapscxx . . $ grfont_TranslateToBitmaps(d4f767463ce0a6b3).(int handle) {
822 tFontFileInfocxx . . $ tFontFileInfo# *fntfile;
823 tFontInfocxx . . $ tFontInfo# *fnt;
824 int i;
825
826 fnt = &Fontscxx . . $ Fonts.[handle];
827 fntfile = &Fontscxx . . $ Fonts.[handle].fontcxx . . $ tFontInfo#font.;
828
829 // start creating font surfaces, map these surfaces onto bitmaps created via bitmap library
830 // this is needed for the renderer library.
831 // create a 128x128 bitmap.
832 // draw each character into bitmap until we need to create another
833 // surface.
834 uint8_tcxx . . $ uint8_t# u = 0, v = 0, w;
835 int ch, num_ch;
836 uint8_tcxx . . $ uint8_t# surf_index = 0;
837
838 num_ch = fntfile->max_asciicxx . . $ tFontFileInfo#max_ascii. - fntfile->min_asciicxx . . $ tFontFileInfo#min_ascii. + 1;
839
840 // initialize memory
841 fnt->ch_wcxx . . $ tFontInfo#ch_w. = new uint8_tcxx . . $ uint8_t#[num_ch];
842 fnt->ch_hcxx . . $ tFontInfo#ch_h. = new uint8_tcxx . . $ uint8_t#[num_ch];
843 fnt->ch_ucxx . . $ tFontInfo#ch_u. = new uint8_tcxx . . $ uint8_t#[num_ch];
844 fnt->ch_vcxx . . $ tFontInfo#ch_v. = new uint8_tcxx . . $ uint8_t#[num_ch];
845 fnt->ch_bmpcxx . . $ tFontInfo#ch_bmp. = new int[num_ch];
846 fnt->ch_ufcxx . . $ tFontInfo#ch_uf. = new float[num_ch];
847 fnt->ch_vfcxx . . $ tFontInfo#ch_vf. = new float[num_ch];
848 fnt->ch_wfcxx . . $ tFontInfo#ch_wf. = new float[num_ch];
849 fnt->ch_hfcxx . . $ tFontInfo#ch_hf. = new float[num_ch];
850
851 for (i = 0; i < MAX_FONT_BITMAPScxx . . $ MAX_FONT_BITMAPS.; i++)
852 fnt->bmpscxx . . $ tFontInfo#bmps.[i] = -1;
853
854 fnt->bmpscxx . . $ tFontInfo#bmps.[surf_index] = bm_AllocBitmapcxx . . $ bm_AllocBitmap(2326284602b0bb2d).(GRFONT_SURFACE_WIDTHcxx . . $ `grtext/grfont.cpp:150:9`!, GRFONT_SURFACE_HEIGHTcxx . . $ `grtext/grfont.cpp:151:9`!, 0);
855 if (fnt->bmpscxx . . $ tFontInfo#bmps.[surf_index] == -1 || fnt->bmpscxx . . $ tFontInfo#bmps.[surf_index] == BAD_BITMAP_HANDLEcxx . . $ `lib/bitmap.h:42:9`!)
856 Errorcxx . . $ Error(326aeb464d16410c).("TranslateToBitmaps <Bitmap allocation error>");
857 if (fntfile->flagscxx . . $ tFontFileInfo#flags. & FT_FMT4444cxx . . $ `grtext/grtext.h:322:9`!) {
858 GameBitmapscxx . . $ GameBitmaps.[fnt->bmpscxx . . $ tFontInfo#bmps.[surf_index]].formatcxx . . $ bms_bitmap#format. = BITMAP_FORMAT_4444cxx . . $ `lib/bitmap.h:57:9`!;
859 }
860
861 grfont_ClearBitmapcxx . . $ grfont_ClearBitmap(d4f767463ce0a6b3).(fnt->bmpscxx . . $ tFontInfo#bmps.[surf_index]);
862 surf_index++;
863
864 for (ch = 0; ch < num_ch; ch++) {
865 if (fntfile->flagscxx . . $ tFontFileInfo#flags. & FT_PROPORTIONALcxx . . $ `grtext/grtext.h:319:9`!)
866 w = (int)fntfile->char_widthscxx . . $ tFontFileInfo#char_widths.[ch];
867 else
868 w = (int)fntfile->widthcxx . . $ tFontFileInfo#width.;
869
870 if ((u + w) > GRFONT_SURFACE_WIDTHcxx . . $ `grtext/grfont.cpp:150:9`!) {
871 u = 0;
872 v += fntfile->heightcxx . . $ tFontFileInfo#height.;
873 if ((v + fntfile->heightcxx . . $ tFontFileInfo#height.) > GRFONT_SURFACE_HEIGHTcxx . . $ `grtext/grfont.cpp:151:9`!) {
874 if (surf_index == MAX_FONT_BITMAPScxx . . $ MAX_FONT_BITMAPS.)
875 Int3cxx . . $ `misc/pserror.h:247:9`!();
876 fnt->bmpscxx . . $ tFontInfo#bmps.[surf_index] = bm_AllocBitmapcxx . . $ bm_AllocBitmap(2326284602b0bb2d).(GRFONT_SURFACE_WIDTHcxx . . $ `grtext/grfont.cpp:150:9`!, GRFONT_SURFACE_HEIGHTcxx . . $ `grtext/grfont.cpp:151:9`!, 0);
877 if (fnt->bmpscxx . . $ tFontInfo#bmps.[surf_index] == -1 || fnt->bmpscxx . . $ tFontInfo#bmps.[surf_index] == BAD_BITMAP_HANDLEcxx . . $ `lib/bitmap.h:42:9`!)
878 Errorcxx . . $ Error(326aeb464d16410c).("TranslateToBitmaps <Bitmap allocation error>");
879 if (fntfile->flagscxx . . $ tFontFileInfo#flags. & FT_FMT4444cxx . . $ `grtext/grtext.h:322:9`!) {
880 GameBitmapscxx . . $ GameBitmaps.[fnt->bmpscxx . . $ tFontInfo#bmps.[surf_index]].formatcxx . . $ bms_bitmap#format. = BITMAP_FORMAT_4444cxx . . $ `lib/bitmap.h:57:9`!;
881 }
882 grfont_ClearBitmapcxx . . $ grfont_ClearBitmap(d4f767463ce0a6b3).(fnt->bmpscxx . . $ tFontInfo#bmps.[surf_index]);
883 surf_index++;
884 v = 0;
885 }
886 }
887
888 // blt each character
889 if (fntfile->flagscxx . . $ tFontFileInfo#flags. & FT_COLORcxx . . $ `grtext/grtext.h:318:9`!) {
890 if (fntfile->flagscxx . . $ tFontFileInfo#flags. & FT_GRADIENTcxx . . $ `grtext/grtext.h:321:9`!)
891 grfont_XlateColorGrayCharcxx . . $ grfont_XlateColorGrayChar(c097311e36299223).(fnt->bmpscxx . . $ tFontInfo#bmps.[surf_index - 1], u, v, ch, fntfile, w);
892 // else
893 grfont_XlateColorCharcxx . . $ grfont_XlateColorChar(c097311e36299223).(fnt->bmpscxx . . $ tFontInfo#bmps.[surf_index - 1], u, v, ch, fntfile, w);
894 } else { // font monochrome, convert bits to pixels
895 grfont_XlateMonoCharcxx . . $ grfont_XlateMonoChar(c097311e36299223).(fnt->bmpscxx . . $ tFontInfo#bmps.[surf_index - 1], u, v, ch, fntfile, w);
896 }
897
898 fnt->ch_hcxx . . $ tFontInfo#ch_h.[ch] = (uint8_tcxx . . $ uint8_t#)fntfile->heightcxx . . $ tFontFileInfo#height.;
899 fnt->ch_wcxx . . $ tFontInfo#ch_w.[ch] = w;
900 fnt->ch_ucxx . . $ tFontInfo#ch_u.[ch] = u;
901 fnt->ch_vcxx . . $ tFontInfo#ch_v.[ch] = v;
902 fnt->ch_bmpcxx . . $ tFontInfo#ch_bmp.[ch] = surf_index - 1;
903 fnt->ch_hfcxx . . $ tFontInfo#ch_hf.[ch] = ((float)fntfile->heightcxx . . $ tFontFileInfo#height.) / ((float)GRFONT_SURFACE_HEIGHTcxx . . $ `grtext/grfont.cpp:151:9`!);
904 fnt->ch_wfcxx . . $ tFontInfo#ch_wf.[ch] = ((float)w) / ((float)GRFONT_SURFACE_WIDTHcxx . . $ `grtext/grfont.cpp:150:9`!);
905 fnt->ch_ufcxx . . $ tFontInfo#ch_uf.[ch] = ((float)u) / ((float)GRFONT_SURFACE_WIDTHcxx . . $ `grtext/grfont.cpp:150:9`!);
906 fnt->ch_vfcxx . . $ tFontInfo#ch_vf.[ch] = ((float)v) / ((float)GRFONT_SURFACE_HEIGHTcxx . . $ `grtext/grfont.cpp:151:9`!);
907
908 // check to adjust uv's if we are outside surface.
909 u += w;
910 }
911 }
912
913 // Font translation routines
914 void grfont_XlateMonoCharcxx . . $ grfont_XlateMonoChar(c097311e36299223).(int bmp_handle, int x, int y, int index, tFontFileInfocxx . . $ tFontFileInfo# *ft, int width) {
915 int row, col; // byte width of char
916 uint8_tcxx . . $ uint8_t# bit_mask = 0, byte = 0;
917 uint8_tcxx . . $ uint8_t# *fp;
918
919 fp = ft->char_datacxx . . $ tFontFileInfo#char_data.[index];
920
921 /* draw one-bit one color. */
922 uint16_tcxx . . $ uint16_t# *dest_ptr;
923 uint16_tcxx . . $ uint16_t# col_w = GR_COLOR_TO_16cxx . . $ GR_COLOR_TO_16(6557041c941ab807).(GR_RGBcxx . . $ GR_RGB(530956271a9518a5).(255, 255, 255));
924 int rowsize_w;
925
926 dest_ptr = bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(bmp_handle, 0);
927 rowsize_w = bm_rowsizecxx . . $ bm_rowsize(9b79fb6aee4c0440).(bmp_handle, 0) >> 1;
928 dest_ptr += (y * rowsize_w) + x;
929
930 for (row = 0; row < ft->heightcxx . . $ tFontFileInfo#height.; row++) {
931 bit_mask = 0;
932 for (col = 0; col < width; col++) {
933 if (bit_mask == 0) {
934 byte = *fp++;
935 bit_mask = 0x80;
936 }
937
938 if (byte & bit_mask)
939 dest_ptr[col] = (col_w | OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!);
940
941 bit_mask >>= 1;
942 }
943 dest_ptr += rowsize_w;
944 }
945 }
946
947 void grfont_XlateColorCharcxx . . $ grfont_XlateColorChar(c097311e36299223).(int bmp_handle, int x, int y, int index, tFontFileInfocxx . . $ tFontFileInfo# *ft, int width) {
948 /* 16-bit copy from source bitmap to destination surface just created and
949 locked
950 This function performs scaling if the source width and height don't match
951 that of the destinations - JL
952 */
953 uint16_tcxx . . $ uint16_t# *dptr, *sptr;
954 int row, col;
955 int rowsize_w;
956
957 dptr = bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(bmp_handle, 0);
958 sptr = (uint16_tcxx . . $ uint16_t# *)ft->char_datacxx . . $ tFontFileInfo#char_data.[index];
959 rowsize_w = bm_rowsizecxx . . $ bm_rowsize(9b79fb6aee4c0440).(bmp_handle, 0) / 2;
960
961 // height = std::min(h, ddsfObj.h);
962 // width = std::min(w, ddsfObj.w);
963 dptr = dptr + (y * rowsize_w);
964
965 if (ft->flagscxx . . $ tFontFileInfo#flags. & FT_FMT4444cxx . . $ `grtext/grtext.h:322:9`!) {
966 for (row = 0; row < ft->heightcxx . . $ tFontFileInfo#height.; row++) {
967 for (col = 0; col < width; col++) {
968 dptr[x + col] = *(sptr++);
969 }
970 dptr += rowsize_w;
971 }
972 } else {
973 // old style
974 for (row = 0; row < ft->heightcxx . . $ tFontFileInfo#height.; row++) {
975 for (col = 0; col < width; col++) {
976 uint16_tcxx . . $ uint16_t# col565 = *(sptr++);
977 if (col565 == 0x07e0)
978 dptr[x + col] = NEW_TRANSPARENT_COLORcxx . . $ `lib/grdefs.h:71:9`!;
979 else
980 dptr[x + col] = (((col565 & 0xf800) >> 1) | ((col565 & 0x07c0) >> 1) | (col565 & 0x001f)) | OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!;
981 }
982 dptr += rowsize_w;
983 }
984 }
985 }
986
987 void grfont_XlateColorGrayCharcxx . . $ grfont_XlateColorGrayChar(c097311e36299223).(int bmp_handle, int x, int y, int index, tFontFileInfocxx . . $ tFontFileInfo# *ft, int width) {
988 /* 16-bit copy from source bitmap to destination surface just created and
989 locked
990 This function performs scaling if the source width and height don't match
991 that of the destinations - JL
992 */
993 uint16_tcxx . . $ uint16_t# *dptr, *sptr;
994 int row, col;
995 int rowsize_w;
996
997 dptr = bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(bmp_handle, 0);
998 sptr = (uint16_tcxx . . $ uint16_t# *)ft->char_datacxx . . $ tFontFileInfo#char_data.[index];
999 rowsize_w = bm_rowsizecxx . . $ bm_rowsize(9b79fb6aee4c0440).(bmp_handle, 0) / 2;
1000
1001 // height = std::min(h, ddsfObj.h);
1002 // width = std::min(w, ddsfObj.w);
1003 dptr = dptr + (y * rowsize_w);
1004
1005 float recip32 = 1.0f / 32.0f;
1006
1007 for (row = 0; row < ft->heightcxx . . $ tFontFileInfo#height.; row++) {
1008 for (col = 0; col < width; col++) {
1009 uint16_tcxx . . $ uint16_t# col565 = *(sptr++);
1010 if (col565 == 0x07e0)
1011 dptr[x + col] = NEW_TRANSPARENT_COLORcxx . . $ `lib/grdefs.h:71:9`!;
1012 else {
1013 uint8_tcxx . . $ uint8_t# r = (uint8_tcxx . . $ uint8_t#)((col565 & 0xf800) >> 11);
1014 uint8_tcxx . . $ uint8_t# g = (uint8_tcxx . . $ uint8_t#)((col565 & 0x07c0) >> 6);
1015 uint8_tcxx . . $ uint8_t# b = (uint8_tcxx . . $ uint8_t#)(col565 & 0x001f);
1016 float brightness = ((r * 0.30f) + (g * 0.59f) + (b * 0.11f)) * recip32;
1017 uint8_tcxx . . $ uint8_t# elem = (uint8_tcxx . . $ uint8_t#)(255 * brightness * ft->brightnesscxx . . $ tFontFileInfo#brightness.);
1018 if ((brightness * ft->brightnesscxx . . $ tFontFileInfo#brightness.) > 1.0f)
1019 elem = 255;
1020 dptr[x + col] = GR_RGB16cxx . . $ GR_RGB16(6461fafb79bad5b9).(elem, elem, elem) | OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!;
1021 }
1022 }
1023 dptr += rowsize_w;
1024 }
1025 }
1026
1027 void grfont_ClearBitmapcxx . . $ grfont_ClearBitmap(d4f767463ce0a6b3).(int bmp_handle) {
1028 int dx, dy;
1029 int rowsize_w = bm_rowsizecxx . . $ bm_rowsize(9b79fb6aee4c0440).(bmp_handle, 0) / 2;
1030 uint16_tcxx . . $ uint16_t# *bmpdata = bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(bmp_handle, 0);
1031
1032 for (dy = 0; dy < bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(bmp_handle, 0); dy++) {
1033 for (dx = 0; dx < rowsize_w; dx++)
1034 bmpdata[dx] = NEW_TRANSPARENT_COLORcxx . . $ `lib/grdefs.h:71:9`!;
1035
1036 bmpdata += rowsize_w;
1037 }
1038 }
1039
1040 #ifndef RELEASE
1041 void grfont_Spewcxx . . $ grfont_Spew(b1146eedae1e1d0b).(int font, int x, int y) {
1042 int i;
1043 tFontInfocxx . . $ tFontInfo# *fnt;
1044
1045 fnt = &Fontscxx . . $ Fonts.[font];
1046
1047 for (i = 0; i < MAX_FONT_BITMAPScxx . . $ MAX_FONT_BITMAPS.; i++)
1048 if (fnt->bmpscxx . . $ tFontInfo#bmps.[i] > -1)
1049 rend_DrawScaledBitmapcxx . . $ rend_DrawScaledBitmap(bffd21ce5f93b71b).(i * GRFONT_SURFACE_WIDTHcxx . . $ `grtext/grfont.cpp:150:9`!, 0, (i + 1) * GRFONT_SURFACE_WIDTHcxx . . $ `grtext/grfont.cpp:150:9`!, GRFONT_SURFACE_HEIGHTcxx . . $ `grtext/grfont.cpp:151:9`!,
1050 fnt->bmpscxx . . $ tFontInfo#bmps.[i], 0, 0, 1.0, 1.0);
1051 }
1052 #endif
1053
1054 // returns character equivalent in font (converts lowercase to uppercase if no lowercase version avail)
1055 // similar to ddio_KeyToAscii
1056 int grfont_KeyToAsciicxx . . $ grfont_KeyToAscii(9b79fb6aee4c0440).(int font, int key) {
1057 key = ddio_KeyToAsciicxx . . $ ddio_KeyToAscii(7864480464b09eea).(key);
1058
1059 if (font >= 0 && font < MAX_FONTScxx . . $ MAX_FONTS.) {
1060 tFontInfocxx . . $ tFontInfo# *ft = &Fontscxx . . $ Fonts.[font];
1061
1062 // save current x and get this font
1063 if (key > ft->fontcxx . . $ tFontInfo#font..max_asciicxx . . $ tFontFileInfo#max_ascii. && (ft->fontcxx . . $ tFontInfo#font..flagscxx . . $ tFontFileInfo#flags. & FT_UPPERCASEcxx . . $ `grtext/grfont.cpp:125:9`!)) {
1064 return toupper(key);
1065 }
1066 }
1067
1068 return key;
1069 }
1070
1071 // MTS: Unused?
1072 // returns the raw bitmap data for a character in a font, its width and height
1073 // returned data should be in 565 hicolor format if (*mono) is false. if (*mono) is true,
1074 // then a bitmask will be returned, and you should treat a bit as a pixel.
1075 uint16_tcxx . . $ uint16_t# *grfont_GetRawCharacterDatacxx . . $ grfont_GetRawCharacterData(d8905bd92668b855).(int font, int ch, int *w, int *h, bool *mono) {
1076 tFontFileInfocxx . . $ tFontFileInfo# *fntfile;
1077 tFontInfocxx . . $ tFontInfo# *fnt;
1078
1079 ASSERTcxx . . $ `misc/pserror.h:246:9`!(font > -1 && font < MAX_FONTS);
1080
1081 fnt = &Fontscxx . . $ Fonts.[font];
1082 fntfile = &fnt->fontcxx . . $ tFontInfo#font.;
1083
1084 if (ch > fnt->fontcxx . . $ tFontInfo#font..max_asciicxx . . $ tFontFileInfo#max_ascii. && (fntfile->flagscxx . . $ tFontFileInfo#flags. & FT_UPPERCASEcxx . . $ `grtext/grfont.cpp:125:9`!)) {
1085 ch = toupper(ch);
1086 }
1087
1088 if ((ch < fnt->fontcxx . . $ tFontInfo#font..min_asciicxx . . $ tFontFileInfo#min_ascii.) || (ch > fnt->fontcxx . . $ tFontInfo#font..max_asciicxx . . $ tFontFileInfo#max_ascii.))
1089 return nullptr;
1090
1091 ch = ch - fnt->fontcxx . . $ tFontInfo#font..min_asciicxx . . $ tFontFileInfo#min_ascii.;
1092 *mono = !(fnt->fontcxx . . $ tFontInfo#font..flagscxx . . $ tFontFileInfo#flags. & FT_COLORcxx . . $ `grtext/grtext.h:318:9`!);
1093
1094 if (fnt->fontcxx . . $ tFontInfo#font..flagscxx . . $ tFontFileInfo#flags. & FT_PROPORTIONALcxx . . $ `grtext/grtext.h:319:9`!) {
1095 *w = (int)(fnt->fontcxx . . $ tFontInfo#font..char_widthscxx . . $ tFontFileInfo#char_widths.[ch]);
1096 } else {
1097 *w = (int)(fnt->fontcxx . . $ tFontInfo#font..widthcxx . . $ tFontFileInfo#width.);
1098 }
1099
1100 *h = fnt->fontcxx . . $ tFontInfo#font..heightcxx . . $ tFontFileInfo#height.;
1101
1102 return (uint16_tcxx . . $ uint16_t# *)fnt->fontcxx . . $ tFontInfo#font..char_datacxx . . $ tFontFileInfo#char_data.[ch];
1103 }
1104
1105 // returns a character's width
1106 int grfont_GetKernedSpacingcxx . . $ grfont_GetKernedSpacing(2326284602b0bb2d).(int font, int ch1, int ch2) {
1107 tFontFileInfocxx . . $ tFontFileInfo# *ft;
1108
1109 ASSERTcxx . . $ `misc/pserror.h:246:9`!(font > -1 && font < MAX_FONTS);
1110
1111 ft = &Fontscxx . . $ Fonts.[font].fontcxx . . $ tFontInfo#font.;
1112
1113 if (ft->kern_datacxx . . $ tFontFileInfo#kern_data.) {
1114 uint8_tcxx . . $ uint8_t# *kern = ft->kern_datacxx . . $ tFontFileInfo#kern_data.;
1115 while (kern[0] != 255) {
1116 if (ch1 == kern[0] && ch2 == kern[1]) {
1117 return (int)((int8_t)kern[2]);
1118 }
1119 kern += 3;
1120 }
1121 }
1122 return 0;
1123 }
1124
1125 // returns a character's width
1126 int grfont_GetKernedSpacingTempcxx . . $ grfont_GetKernedSpacingTemp(1511bff7f72f8bee).(const tFontTemplatecxx . . $ tFontTemplate# *ft, int ch1, int ch2) {
1127 if (ft->kern_datacxx . . $ tFontTemplate#kern_data.) {
1128 uint8_tcxx . . $ uint8_t# *kern = ft->kern_datacxx . . $ tFontTemplate#kern_data.;
1129 while (kern[0] != 255) {
1130 if (ch1 == kern[0] && ch2 == kern[1]) {
1131 return (int)((int8_t)kern[2]);
1132 }
1133 kern += 3;
1134 }
1135 }
1136 return 0;
1137 }