| 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/2dlib/font.cpp $ |
| 21 | * $Revision: 15 $ |
| 22 | * $Date: 4/17/99 6:15p $ |
| 23 | * $Author: Samir $ |
| 24 | * |
| 25 | * will load and manage a font's capabilities. |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/2dlib/font.cpp $ |
| 28 | * |
| 29 | * 15 4/17/99 6:15p Samir |
| 30 | * replaced gr.h with grdefs.h and fixed resulting compile bugs. |
| 31 | * |
| 32 | * 14 10/13/98 10:31a Sean |
| 33 | * Fixed a mem_free (free()) conflict |
| 34 | * |
| 35 | * 13 4/23/98 6:38p Jason |
| 36 | * made bitmaps use 1555 format |
| 37 | * |
| 38 | * 12 3/31/98 3:48p Jason |
| 39 | * added memory lib |
| 40 | * |
| 41 | * 11 12/19/97 12:31p Samir |
| 42 | * load font registration |
| 43 | * |
| 44 | * 10 12/12/97 6:40p Samir |
| 45 | * Some viewport font functions. |
| 46 | * |
| 47 | * 9 11/16/97 6:53p Samir |
| 48 | * Reinstated instance count for fonts. |
| 49 | * |
| 50 | * 8 11/16/97 4:41p Matt |
| 51 | * Commented-out an assert. |
| 52 | * |
| 53 | * 7 11/14/97 12:06p Samir |
| 54 | * When you use a font for the first time, load it. Never free font until |
| 55 | * game closes. |
| 56 | * |
| 57 | * 6 10/15/97 5:20p Jason |
| 58 | * did a HUGE overhaul of the bitmap system |
| 59 | * |
| 60 | * 5 9/26/97 2:53p Samir |
| 61 | * Delete old m_CharSurf if creating a new one. |
| 62 | * |
| 63 | * 4 9/19/97 5:37p Samir |
| 64 | * Software font coloring works. |
| 65 | * |
| 66 | * 3 8/07/97 3:15p Samir |
| 67 | * May have fixed horizontal left clipping problem. |
| 68 | * |
| 69 | * 22 6/25/97 10:10a Samir |
| 70 | * Removed unused code causing warning. |
| 71 | * |
| 72 | * 21 6/24/97 7:42p Matt |
| 73 | * Included bitmap.h instead of font.h |
| 74 | * |
| 75 | * 20 6/16/97 4:45p Samir |
| 76 | * Fixed transparency probs |
| 77 | * |
| 78 | * 19 6/16/97 3:01p Samir |
| 79 | * Changed font system to work better with renderer. Fonts are rendered |
| 80 | * on bitmaps of 128x128 at load time. |
| 81 | * |
| 82 | * 18 6/12/97 6:27p Samir |
| 83 | * DDGR v2.0 (GR v1.1) Changes to ddgr system reflected in 2d system |
| 84 | * |
| 85 | * 17 5/14/97 8:07p Samir |
| 86 | * some pathname problem which screwed up Mac. |
| 87 | * |
| 88 | * 16 3/07/97 4:01p Samir |
| 89 | * Took out malloc.h for ANSI compliance. |
| 90 | * |
| 91 | * 15 3/03/97 6:20p Matt |
| 92 | * Changed cfile functions to use D3 naming convention |
| 93 | * |
| 94 | * 14 2/28/97 3:17 PM Jeremy |
| 95 | * changed a call of strcmpi to stricmp |
| 96 | * |
| 97 | * 13 2/28/97 2:57p Samir |
| 98 | * Took out __cdecl from atexit |
| 99 | * |
| 100 | * 12 2/10/97 12:14p Samir |
| 101 | * Allow multiple font loading per viewport. |
| 102 | * |
| 103 | * 11 2/06/97 6:33p Samir |
| 104 | * Added clipping character functions for font. |
| 105 | * |
| 106 | * 10 2/06/97 12:43p Samir |
| 107 | * Mono fonts work. |
| 108 | * |
| 109 | * 9 2/05/97 12:19p Samir |
| 110 | * Stopped redundant increases in font reference count for same font |
| 111 | * object. |
| 112 | * |
| 113 | * 8 2/05/97 10:35a Samir |
| 114 | * Fixed text drawing at wrong location problem |
| 115 | * |
| 116 | * $NoKeywords: $ |
| 117 | */ |
| 118 | |
| 119 | #include <cstring> |
| 120 | #include <cstdlib> |
| 121 | |
| 122 | #include "bitmap.h"cxx . . $ `<file>/lib/bitmap.h`/ |
| 123 | #include "cfile.h"cxx . . $ `<file>/cfile/cfile.h`/ |
| 124 | #include "gr.h"cxx . . $ `<file>/2dlib/gr.h`/ |
| 125 | #include "mem.h"cxx . . $ `<file>/mem/mem.h`/ |
| 126 | #include "mono.h"cxx . . $ `<file>/ddebug/mono.h`/ |
| 127 | #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/ |
| 128 | #include "renderer.h"cxx . . $ `<file>/lib/renderer.h`/ |
| 129 | |
| 130 | #define FT_COLORcxx . . $ `2dlib/font.cpp:130:9`! 1 |
| 131 | #define FT_PROPORTIONALcxx . . $ `2dlib/font.cpp:131:9`! 2 |
| 132 | #define FT_KERNEDcxx . . $ `2dlib/font.cpp:132:9`! 4 |
| 133 | #define FT_GRADIENTcxx . . $ `2dlib/font.cpp:133:9`! 8 |
| 134 | |
| 135 | #define GRFONT_SURFACE_WIDTHcxx . . $ `2dlib/font.cpp:135:9`! 128 |
| 136 | #define GRFONT_SURFACE_HEIGHTcxx . . $ `2dlib/font.cpp:136:9`! 128 |
| 137 | |
| 138 | // ---------------------------------------------------------------------------- |
| 139 | // Macros for file io. |
| 140 | // ---------------------------------------------------------------------------- |
| 141 | |
| 142 | typedef CFILEcxx . . $ CFILE# *FONTFILEcxx . . $ FONTFILE#; |
| 143 | |
| 144 | static inline int READ_FONT_INTcxx . . $ READ_FONT_INT(413716a422df0036).(FONTFILEcxx . . $ FONTFILE# ffile); |
| 145 | static inline int16_t READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(FONTFILEcxx . . $ FONTFILE# ffile); |
| 146 | static inline uint8_tcxx . . $ uint8_t# READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(FONTFILEcxx . . $ FONTFILE# ffile); |
| 147 | static inline int READ_FONT_DATAcxx . . $ READ_FONT_DATA(fc60f957852e351e).(FONTFILEcxx . . $ FONTFILE# ffile, void *buf, int size, int nelem); |
| 148 | static inline FONTFILEcxx . . $ FONTFILE# OPEN_FONTcxx . . $ OPEN_FONT(8c472d7249121f63).(char *filename, bool &success); |
| 149 | static inline void CLOSE_FONTcxx . . $ CLOSE_FONT(3639e799710acb68).(FONTFILEcxx . . $ FONTFILE# ffile); |
| 150 | |
| 151 | #define BITS_TO_BYTEScxx . . $ `2dlib/font.cpp:151:9`!(_c) (((_c) + 7) >> 3) |
| 152 | #define BITS_TO_SHORTScxx . . $ `2dlib/font.cpp:152:9`!(_c) (((_c) + 15) >> 4) |
| 153 | |
| 154 | inline int READ_FONT_INTcxx . . $ READ_FONT_INT(413716a422df0036).(FONTFILEcxx . . $ FONTFILE# ffile) { return cf_ReadIntcxx . . $ cf_ReadInt(d60d6f5e30f0c96a).(ffile); } |
| 155 | |
| 156 | inline int16_t READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(FONTFILEcxx . . $ FONTFILE# ffile) { return cf_ReadShortcxx . . $ cf_ReadShort(30b00389b433b379).(ffile); } |
| 157 | |
| 158 | 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); } |
| 159 | |
| 160 | inline int READ_FONT_DATAcxx . . $ READ_FONT_DATA(fc60f957852e351e).(FONTFILEcxx . . $ FONTFILE# ffile, void *buf, int size, int nelem) { |
| 161 | int i; |
| 162 | |
| 163 | i = cf_ReadBytescxx . . $ cf_ReadBytes(de6325ef3380a744).((uint8_tcxx . . $ uint8_t# *)buf, size * nelem, ffile); |
| 164 | |
| 165 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(i == (size * nelem)); |
| 166 | |
| 167 | return i; |
| 168 | } |
| 169 | |
| 170 | inline FONTFILEcxx . . $ FONTFILE# OPEN_FONTcxx . . $ OPEN_FONT(8c472d7249121f63).(char *filename, bool &success) { |
| 171 | FONTFILEcxx . . $ FONTFILE# fp; |
| 172 | int file_id; |
| 173 | |
| 174 | success = false; |
| 175 | fp = (FONTFILEcxx . . $ FONTFILE#)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(filenamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "rb"); |
| 176 | if (!fp) |
| 177 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 178 | |
| 179 | file_id = READ_FONT_INTcxx . . $ READ_FONT_INT(413716a422df0036).(fp); |
| 180 | if (file_id != 0xfeedbaba) |
| 181 | return (FONTFILEcxx . . $ FONTFILE#)(-1); |
| 182 | |
| 183 | success = true; |
| 184 | return fp; |
| 185 | } |
| 186 | |
| 187 | inline void CLOSE_FONTcxx . . $ CLOSE_FONT(3639e799710acb68).(FONTFILEcxx . . $ FONTFILE# ffile) { cfclosecxx . . $ cfclose(3639e799710acb68).(ffile); } |
| 188 | |
| 189 | // ---------------------------------------------------------------------------- |
| 190 | // static variables and functions |
| 191 | // ---------------------------------------------------------------------------- |
| 192 | |
| 193 | gr_font_recordcxx . . $ gr_font_record# grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[MAX_FONTScxx . . $ MAX_FONTS.]; |
| 194 | grMemorySurfacecxx . . $ grMemorySurface# *grFontcxx . . $ grFont#::m_CharSurfcxx . . $ grFont#m_CharSurf. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 195 | |
| 196 | void grFontcxx . . $ grFont#::init_systemcxx . . $ grFont#init_system(49f6e7a06ebc5aa8).() { |
| 197 | for (int i = 0; i < MAX_FONTScxx . . $ MAX_FONTS.; i++) { |
| 198 | grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[i].referencescxx . . $ gr_font_record#references. = 0; |
| 199 | grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[i].filenamecxx . . $ gr_font_record#filename.[0] = 0; |
| 200 | } |
| 201 | |
| 202 | if (grFontcxx . . $ grFont#::m_CharSurfcxx . . $ grFont#m_CharSurf.) { |
| 203 | delete grFontcxx . . $ grFont#::m_CharSurfcxx . . $ grFont#m_CharSurf.; |
| 204 | grFontcxx . . $ grFont#::m_CharSurfcxx . . $ grFont#m_CharSurf. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 205 | } |
| 206 | |
| 207 | if (!grFontcxx . . $ grFont#::m_CharSurfcxx . . $ grFont#m_CharSurf.) { |
| 208 | grFontcxx . . $ grFont#::m_CharSurfcxx . . $ grFont#m_CharSurf. = new grMemorySurfacecxx . . $ grMemorySurface#grMemorySurface(49f6e7a06ebc5aa8).; |
| 209 | grFontcxx . . $ grFont#::m_CharSurfcxx . . $ grFont#m_CharSurf.->initcxx . . $ grMemorySurface#init(fe591fed253a3675).(0, 0, BPP_16cxx . . $ `lib/grdefs.h:61:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 0, 0, "char_surf"); |
| 210 | } |
| 211 | |
| 212 | atexitcxx . . $ atexit(cc8c495369588262).(grFontcxx . . $ grFont#::close_systemcxx . . $ grFont#close_system(49f6e7a06ebc5aa8).); |
| 213 | } |
| 214 | |
| 215 | void grFontcxx . . $ grFont#::close_systemcxx . . $ grFont#close_system(49f6e7a06ebc5aa8).() { |
| 216 | if (grFontcxx . . $ grFont#::m_CharSurfcxx . . $ grFont#m_CharSurf.) { |
| 217 | delete grFontcxx . . $ grFont#::m_CharSurfcxx . . $ grFont#m_CharSurf.; |
| 218 | grFontcxx . . $ grFont#::m_CharSurfcxx . . $ grFont#m_CharSurf. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 219 | } |
| 220 | |
| 221 | // we should free any fonts currently allocated here. |
| 222 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Freeing cached fonts..."); |
| 223 | for (int i = 0; i < MAX_FONTScxx . . $ MAX_FONTS.; i++) { |
| 224 | gr_font_recordcxx . . $ gr_font_record# *ft; |
| 225 | if (grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[i].referencescxx . . $ gr_font_record#references.) { |
| 226 | ft = &grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[i]; |
| 227 | grFontcxx . . $ grFont#::free_fontcxx . . $ grFont#free_font(fe8ae557a2cea0).(ft); |
| 228 | grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[i].referencescxx . . $ gr_font_record#references. = 0; |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | int grFontcxx . . $ grFont#::register_fontcxx . . $ grFont#register_font(e99f026884c896d5).(char *fontname, char *filename) { |
| 234 | /* look for a slot with no fontname and place fontname in it */ |
| 235 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(fontname != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 236 | |
| 237 | int i; |
| 238 | |
| 239 | for (i = 0; i < MAX_FONTScxx . . $ MAX_FONTS.; i++) { |
| 240 | if (grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[i].filenamecxx . . $ gr_font_record#filename.[0] == 0) { |
| 241 | strcpy(grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[i].filenamecxx . . $ gr_font_record#filename., filename); |
| 242 | strcpy(grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[i].namecxx . . $ gr_font_record#name., fontname); |
| 243 | grFontcxx . . $ grFont#::loadcxx . . $ grFont#load(a07d8cccb7673f5a).(m_FontListcxx . . $ grFont#m_FontList.[i].filenamecxx . . $ gr_font_record#filename., i); |
| 244 | grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[i].referencescxx . . $ gr_font_record#references. = 1; |
| 245 | break; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | if (i == MAX_FONTScxx . . $ MAX_FONTS.) |
| 250 | i = -1; |
| 251 | |
| 252 | return i; |
| 253 | } |
| 254 | |
| 255 | // ---------------------------------------------------------------------------- |
| 256 | // constructor and destructor of font object |
| 257 | // ---------------------------------------------------------------------------- |
| 258 | |
| 259 | grFontcxx . . $ grFont#::grFontcxx . . $ grFont#grFont(49f6e7a06ebc5aa8).() { m_FontHandlecxx . . $ grFont#m_FontHandle. = -1; } |
| 260 | |
| 261 | grFontcxx . . $ grFont#::~cxx . . $ grFont#`~grFont`(ced63f7c635d850d).grFontcxx . . $ grFont#() { |
| 262 | if (m_FontHandlecxx . . $ grFont#m_FontHandle. > -1) |
| 263 | grFontcxx . . $ grFont#::freecxx . . $ grFont#free(49f6e7a06ebc5aa8).(); |
| 264 | } |
| 265 | |
| 266 | // ---------------------------------------------------------------------------- |
| 267 | // high level font initialization and cleanup routines |
| 268 | // ---------------------------------------------------------------------------- |
| 269 | |
| 270 | void grFontcxx . . $ grFont#::initcxx . . $ grFont#init(85c52e162fed56f9).(const char *fontname) { |
| 271 | int i, slot = -1; |
| 272 | |
| 273 | // Look for this font in the list, check if it has any references, and load it if |
| 274 | // there are none. |
| 275 | if (fontname == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 276 | slot = 0; |
| 277 | } else { |
| 278 | for (i = 0; i < MAX_FONTScxx . . $ MAX_FONTS.; i++) { |
| 279 | if (stricmpcxx . . $ `linux/linux_fix.h:43:9`!(grFont::m_FontList[i].name, fontname) == 0) { |
| 280 | slot = i; |
| 281 | |
| 282 | if (grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[i].referencescxx . . $ gr_font_record#references. == 0) { |
| 283 | break; |
| 284 | } else { |
| 285 | m_FontHandlecxx . . $ grFont#m_FontHandle. = slot; |
| 286 | return; |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(slot != -1); |
| 292 | |
| 293 | // clear up surface and bitmap lists |
| 294 | grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[slot].ch_wcxx . . $ gr_font_record#ch_w. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 295 | grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[slot].ch_hcxx . . $ gr_font_record#ch_h. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 296 | grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[slot].ch_ucxx . . $ gr_font_record#ch_u. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 297 | grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[slot].ch_vcxx . . $ gr_font_record#ch_v. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 298 | |
| 299 | for (i = 0; i < MAX_FONT_BITMAPScxx . . $ MAX_FONT_BITMAPS.; i++) { |
| 300 | grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[slot].bmpscxx . . $ gr_font_record#bmps.[i] = -1; |
| 301 | grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[slot].surfscxx . . $ gr_font_record#surfs.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 302 | } |
| 303 | |
| 304 | // We must load this font from the 'hogfile' |
| 305 | grFontcxx . . $ grFont#::loadcxx . . $ grFont#load(a07d8cccb7673f5a).(m_FontListcxx . . $ grFont#m_FontList.[slot].filenamecxx . . $ gr_font_record#filename., slot); |
| 306 | |
| 307 | grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[slot].referencescxx . . $ gr_font_record#references.++; |
| 308 | } |
| 309 | |
| 310 | m_FontHandlecxx . . $ grFont#m_FontHandle. = slot; |
| 311 | } |
| 312 | |
| 313 | void grFontcxx . . $ grFont#::freecxx . . $ grFont#free(49f6e7a06ebc5aa8).() { |
| 314 | if (m_FontHandlecxx . . $ grFont#m_FontHandle. == -1) |
| 315 | return; |
| 316 | |
| 317 | return; |
| 318 | |
| 319 | //!! Removed the following assert because there are bugs in the reference count system. Matt, 11-15-97. |
| 320 | //!! ASSERT(grFont::m_FontList[m_FontHandle].references > 0); |
| 321 | //@@ |
| 322 | // free font if there was only one reference left. |
| 323 | //@@ if (grFont::m_FontList[m_FontHandle].references == 1) { |
| 324 | //@@ gr_font_record *ft; |
| 325 | //@@ |
| 326 | //@@ // free up all memory allocated to this font. |
| 327 | //@@ ft = &grFont::m_FontList[m_FontHandle]; |
| 328 | //@@ |
| 329 | //@@ grFont::free_font(ft); |
| 330 | //@@ } |
| 331 | //@@ |
| 332 | //@@ grFont::m_FontList[m_FontHandle].references--; |
| 333 | m_FontHandlecxx . . $ grFont#m_FontHandle. = -1; |
| 334 | } |
| 335 | |
| 336 | void grFontcxx . . $ grFont#::free_fontcxx . . $ grFont#free_font(fe8ae557a2cea0).(gr_font_recordcxx . . $ gr_font_record# *ft) { |
| 337 | int i; |
| 338 | |
| 339 | // delete font surface info. |
| 340 | if (ft->ch_wfcxx . . $ gr_font_record#ch_wf.) |
| 341 | delete[] ft->ch_wfcxx . . $ gr_font_record#ch_wf.; |
| 342 | if (ft->ch_hfcxx . . $ gr_font_record#ch_hf.) |
| 343 | delete[] ft->ch_hfcxx . . $ gr_font_record#ch_hf.; |
| 344 | if (ft->ch_ufcxx . . $ gr_font_record#ch_uf.) |
| 345 | delete[] ft->ch_ufcxx . . $ gr_font_record#ch_uf.; |
| 346 | if (ft->ch_vfcxx . . $ gr_font_record#ch_vf.) |
| 347 | delete[] ft->ch_vfcxx . . $ gr_font_record#ch_vf.; |
| 348 | if (ft->ch_wcxx . . $ gr_font_record#ch_w.) |
| 349 | delete[] ft->ch_wcxx . . $ gr_font_record#ch_w.; |
| 350 | if (ft->ch_hcxx . . $ gr_font_record#ch_h.) |
| 351 | delete[] ft->ch_hcxx . . $ gr_font_record#ch_h.; |
| 352 | if (ft->ch_ucxx . . $ gr_font_record#ch_u.) |
| 353 | delete[] ft->ch_ucxx . . $ gr_font_record#ch_u.; |
| 354 | if (ft->ch_vcxx . . $ gr_font_record#ch_v.) |
| 355 | delete[] ft->ch_vcxx . . $ gr_font_record#ch_v.; |
| 356 | if (ft->ch_surfcxx . . $ gr_font_record#ch_surf.) |
| 357 | delete[] ft->ch_surfcxx . . $ gr_font_record#ch_surf.; |
| 358 | |
| 359 | for (i = 0; i < MAX_FONT_BITMAPScxx . . $ MAX_FONT_BITMAPS.; i++) { |
| 360 | if (ft->bmpscxx . . $ gr_font_record#bmps.[i] != -1) |
| 361 | bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(ft->bmpscxx . . $ gr_font_record#bmps.[i]); |
| 362 | if (ft->surfscxx . . $ gr_font_record#surfs.[i]) |
| 363 | delete ft->surfscxx . . $ gr_font_record#surfs.[i]; |
| 364 | } |
| 365 | |
| 366 | // delete font file info. |
| 367 | if (ft->fontcxx . . $ gr_font_record#font..flagscxx . . $ gr_font_file_record#flags. & FT_PROPORTIONALcxx . . $ `2dlib/font.cpp:131:9`!) { |
| 368 | delete[] ft->fontcxx . . $ gr_font_record#font..char_widthscxx . . $ gr_font_file_record#char_widths.; |
| 369 | } |
| 370 | |
| 371 | ::mem_freecxx . . $ `mem/mem.h:80:9`!(ft->font.raw_data); |
| 372 | ::mem_freecxx . . $ `mem/mem.h:80:9`!(ft->font.char_data); |
| 373 | } |
| 374 | |
| 375 | void grFontcxx . . $ grFont#::loadcxx . . $ grFont#load(a07d8cccb7673f5a).(char *filename, int slot) { |
| 376 | FONTFILEcxx . . $ FONTFILE# ff; |
| 377 | gr_font_file_recordcxx . . $ gr_font_file_record# fnt, *ft; |
| 378 | char fontname[32]; |
| 379 | int num_char; |
| 380 | int i; |
| 381 | |
| 382 | ft = &fnt; |
| 383 | |
| 384 | bool success; |
| 385 | ff = OPEN_FONTcxx . . $ OPEN_FONT(8c472d7249121f63).(filename, success); |
| 386 | if (!ff) { |
| 387 | Errorcxx . . $ Error(326aeb464d16410c).("Unable to open font in file %s.\n", filename); |
| 388 | } else if (!success) { |
| 389 | Errorcxx . . $ Error(326aeb464d16410c).("Illegal font file: %s.\n", filename); |
| 390 | } |
| 391 | |
| 392 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "%s font.\n", grFont::m_FontList[slot].name); |
| 393 | |
| 394 | ft->widthcxx . . $ gr_font_file_record#width. = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff); |
| 395 | ft->heightcxx . . $ gr_font_file_record#height. = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff); |
| 396 | ft->flagscxx . . $ gr_font_file_record#flags. = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff); |
| 397 | ft->baselinecxx . . $ gr_font_file_record#baseline. = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff); |
| 398 | ft->min_asciicxx . . $ gr_font_file_record#min_ascii. = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ff); |
| 399 | ft->max_asciicxx . . $ gr_font_file_record#max_ascii. = READ_FONT_BYTEcxx . . $ READ_FONT_BYTE(848bd77af7750b0d).(ff); |
| 400 | READ_FONT_DATAcxx . . $ READ_FONT_DATA(fc60f957852e351e).(ff, fontname, 32, 1); |
| 401 | |
| 402 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, " <ht %d>::<min %d>::<max %d>::<base %d>", ft->height, ft->min_ascii, ft->max_ascii, ft->baseline); |
| 403 | |
| 404 | num_char = ft->max_asciicxx . . $ gr_font_file_record#max_ascii. - ft->min_asciicxx . . $ gr_font_file_record#min_ascii. + 1; |
| 405 | |
| 406 | // Read in all widths |
| 407 | if (ft->flagscxx . . $ gr_font_file_record#flags. & FT_PROPORTIONALcxx . . $ `2dlib/font.cpp:131:9`!) { |
| 408 | ft->char_widthscxx . . $ gr_font_file_record#char_widths. = new int16_t[num_char]; |
| 409 | for (i = 0; i < num_char; i++) |
| 410 | ft->char_widthscxx . . $ gr_font_file_record#char_widths.[i] = READ_FONT_SHORTcxx . . $ READ_FONT_SHORT(644dbbe4555be8a0).(ff); |
| 411 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "::proportional"); |
| 412 | } else { |
| 413 | ft->char_widthscxx . . $ gr_font_file_record#char_widths. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 414 | } |
| 415 | |
| 416 | // Read in pixel data. |
| 417 | // for color fonts, read in byte count and then the data, |
| 418 | // generate character data pointer table |
| 419 | // for mono fonts, read in byte count, then the data, convert to bits and store |
| 420 | // generate character data pointer table |
| 421 | int bytesize = READ_FONT_INTcxx . . $ READ_FONT_INT(413716a422df0036).(ff); |
| 422 | |
| 423 | ft->raw_datacxx . . $ gr_font_file_record#raw_data. = (uint8_tcxx . . $ uint8_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(bytesize); |
| 424 | ft->char_datacxx . . $ gr_font_file_record#char_data. = (uint8_tcxx . . $ uint8_t# **)mem_malloccxx . . $ `mem/mem.h:79:9`!(num_char * sizeof(uint8_t *)); |
| 425 | |
| 426 | READ_FONT_DATAcxx . . $ READ_FONT_DATA(fc60f957852e351e).(ff, ft->raw_datacxx . . $ gr_font_file_record#raw_data., bytesize, 1); |
| 427 | |
| 428 | if (ft->flagscxx . . $ gr_font_file_record#flags. & FT_COLORcxx . . $ `2dlib/font.cpp:130:9`!) { |
| 429 | int off = 0; |
| 430 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "::color"); |
| 431 | for (i = 0; i < num_char; i++) { |
| 432 | ft->char_datacxx . . $ gr_font_file_record#char_data.[i] = ft->raw_datacxx . . $ gr_font_file_record#raw_data. + off; |
| 433 | if (ft->flagscxx . . $ gr_font_file_record#flags. & FT_PROPORTIONALcxx . . $ `2dlib/font.cpp:131:9`!) |
| 434 | off += (ft->char_widthscxx . . $ gr_font_file_record#char_widths.[i] * ft->heightcxx . . $ gr_font_file_record#height. * BITS_TO_BYTEScxx . . $ `2dlib/font.cpp:151:9`!(BPP_16cxx . . $ `lib/grdefs.h:61:9`!)); |
| 435 | else |
| 436 | off += (ft->widthcxx . . $ gr_font_file_record#width. * ft->heightcxx . . $ gr_font_file_record#height. * BITS_TO_BYTEScxx . . $ `2dlib/font.cpp:151:9`!(BPP_16cxx . . $ `lib/grdefs.h:61:9`!)); |
| 437 | } |
| 438 | } else { // Monochrome |
| 439 | uint8_tcxx . . $ uint8_t# *ptr = ft->raw_datacxx . . $ gr_font_file_record#raw_data.; |
| 440 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "::mono"); |
| 441 | for (i = 0; i < num_char; i++) { |
| 442 | ft->char_datacxx . . $ gr_font_file_record#char_data.[i] = ptr; |
| 443 | if (ft->flagscxx . . $ gr_font_file_record#flags. & FT_PROPORTIONALcxx . . $ `2dlib/font.cpp:131:9`!) |
| 444 | ptr += BITS_TO_BYTEScxx . . $ `2dlib/font.cpp:151:9`!(ft->char_widths[i]) * ft->heightcxx . . $ gr_font_file_record#height.; |
| 445 | else |
| 446 | ptr += BITS_TO_BYTEScxx . . $ `2dlib/font.cpp:151:9`!(ft->width) * ft->heightcxx . . $ gr_font_file_record#height.; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | // Read in kerning data |
| 451 | ft->kern_datacxx . . $ gr_font_file_record#kern_data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 452 | |
| 453 | // Then read in |
| 454 | CLOSE_FONTcxx . . $ CLOSE_FONT(3639e799710acb68).(ff); |
| 455 | |
| 456 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "\n"); |
| 457 | |
| 458 | grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[slot].fontcxx . . $ gr_font_record#font. =cxx . . $ gr_font_file_record#`operator=`(32a77b1eb9ad2033). fnt; |
| 459 | |
| 460 | // draw font to bitmaps, load into surfaces too. |
| 461 | grFontcxx . . $ grFont#::translate_to_surfacescxx . . $ grFont#translate_to_surfaces(d4f767463ce0a6b3).(slot); |
| 462 | } |
| 463 | |
| 464 | // translates a font to surfaces |
| 465 | void grFontcxx . . $ grFont#::translate_to_surfacescxx . . $ grFont#translate_to_surfaces(d4f767463ce0a6b3).(int slot) { |
| 466 | gr_font_file_recordcxx . . $ gr_font_file_record# *fntfile; |
| 467 | gr_font_recordcxx . . $ gr_font_record# *fnt; |
| 468 | |
| 469 | fnt = &grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[slot]; |
| 470 | fntfile = &grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[slot].fontcxx . . $ gr_font_record#font.; |
| 471 | |
| 472 | // start creating font surfaces, map these surfaces onto bitmaps created via bitmap library |
| 473 | // this is needed for the renderer library. |
| 474 | // create a 128x128 surface first. |
| 475 | // draw each character into surface until we need to create another |
| 476 | // surface. |
| 477 | uint8_tcxx . . $ uint8_t# u = 0, v = 0, w; |
| 478 | int ch, num_ch; |
| 479 | uint8_tcxx . . $ uint8_t# surf_index = 0; |
| 480 | |
| 481 | num_ch = fntfile->max_asciicxx . . $ gr_font_file_record#max_ascii. - fntfile->min_asciicxx . . $ gr_font_file_record#min_ascii. + 1; |
| 482 | |
| 483 | // initialize memory |
| 484 | fnt->ch_wcxx . . $ gr_font_record#ch_w. = new uint8_tcxx . . $ uint8_t#[num_ch]; |
| 485 | fnt->ch_hcxx . . $ gr_font_record#ch_h. = new uint8_tcxx . . $ uint8_t#[num_ch]; |
| 486 | fnt->ch_ucxx . . $ gr_font_record#ch_u. = new uint8_tcxx . . $ uint8_t#[num_ch]; |
| 487 | fnt->ch_vcxx . . $ gr_font_record#ch_v. = new uint8_tcxx . . $ uint8_t#[num_ch]; |
| 488 | fnt->ch_surfcxx . . $ gr_font_record#ch_surf. = new uint8_tcxx . . $ uint8_t#[num_ch]; |
| 489 | fnt->ch_ufcxx . . $ gr_font_record#ch_uf. = new float[num_ch]; |
| 490 | fnt->ch_vfcxx . . $ gr_font_record#ch_vf. = new float[num_ch]; |
| 491 | fnt->ch_wfcxx . . $ gr_font_record#ch_wf. = new float[num_ch]; |
| 492 | fnt->ch_hfcxx . . $ gr_font_record#ch_hf. = new float[num_ch]; |
| 493 | |
| 494 | fnt->bmpscxx . . $ gr_font_record#bmps.[surf_index] = bm_AllocBitmapcxx . . $ bm_AllocBitmap(2326284602b0bb2d).(GRFONT_SURFACE_WIDTHcxx . . $ `2dlib/font.cpp:135:9`!, GRFONT_SURFACE_HEIGHTcxx . . $ `2dlib/font.cpp:136:9`!, 0); |
| 495 | if (fnt->bmpscxx . . $ gr_font_record#bmps.[surf_index] == -1) |
| 496 | Errorcxx . . $ Error(326aeb464d16410c).("grFont::translate_to_surfaces <Bitmap allocation error>"); |
| 497 | fnt->surfscxx . . $ gr_font_record#surfs.[surf_index] = new grMemorySurfacecxx . . $ grMemorySurface#grMemorySurface(49f6e7a06ebc5aa8).; |
| 498 | fnt->surfscxx . . $ gr_font_record#surfs.[surf_index]->initcxx . . $ grMemorySurface#init(fe591fed253a3675).(GRFONT_SURFACE_WIDTHcxx . . $ `2dlib/font.cpp:135:9`!, GRFONT_SURFACE_HEIGHTcxx . . $ `2dlib/font.cpp:136:9`!, BPP_16cxx . . $ `lib/grdefs.h:61:9`!, |
| 499 | (char *)bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(fnt->bmpscxx . . $ gr_font_record#bmps.[surf_index], 0), GRFONT_SURFACE_WIDTHcxx . . $ `2dlib/font.cpp:135:9`! * BITS_TO_BYTEScxx . . $ `2dlib/font.cpp:151:9`!(BPP_16cxx . . $ `lib/grdefs.h:61:9`!), |
| 500 | SURFFLAG_COLORKEYcxx . . $ SURFFLAG_COLORKEY.); |
| 501 | fnt->surfscxx . . $ gr_font_record#surfs.[surf_index]->clearcxx . . $ grSurface#clear(cb2f890c2fdad230).(TRANSPARENT_COLOR32cxx . . $ `lib/grdefs.h:70:9`!); |
| 502 | surf_index++; |
| 503 | |
| 504 | for (ch = 0; ch < num_ch; ch++) { |
| 505 | if (fntfile->flagscxx . . $ gr_font_file_record#flags. & FT_PROPORTIONALcxx . . $ `2dlib/font.cpp:131:9`!) |
| 506 | w = (int)fntfile->char_widthscxx . . $ gr_font_file_record#char_widths.[ch]; |
| 507 | else |
| 508 | w = (int)fntfile->widthcxx . . $ gr_font_file_record#width.; |
| 509 | |
| 510 | // blt each character |
| 511 | if (fntfile->flagscxx . . $ gr_font_file_record#flags. & FT_COLORcxx . . $ `2dlib/font.cpp:130:9`!) { |
| 512 | m_CharSurfcxx . . $ grFont#m_CharSurf.->initcxx . . $ grMemorySurface#init(fe591fed253a3675).(w, fntfile->heightcxx . . $ gr_font_file_record#height., BPP_16cxx . . $ `lib/grdefs.h:61:9`!, (char *)fntfile->char_datacxx . . $ gr_font_file_record#char_data.[ch], w * BITS_TO_BYTEScxx . . $ `2dlib/font.cpp:151:9`!(BPP_16cxx . . $ `lib/grdefs.h:61:9`!), |
| 513 | SURFFLAG_COLORKEYcxx . . $ SURFFLAG_COLORKEY.); |
| 514 | |
| 515 | fnt->surfscxx . . $ gr_font_record#surfs.[surf_index - 1]->bltcxx . . $ grSurface#blt(3c4a031b05aa6aa3).(u, v, m_CharSurfcxx . . $ grFont#m_CharSurf.); |
| 516 | } else { // font monochrome, convert bits to pixels |
| 517 | grFontcxx . . $ grFont#::translate_mono_charcxx . . $ grFont#translate_mono_char(f04fccacaaac6574).(fnt->surfscxx . . $ gr_font_record#surfs.[surf_index - 1], u, v, ch, fntfile, w); |
| 518 | } |
| 519 | |
| 520 | fnt->ch_hcxx . . $ gr_font_record#ch_h.[ch] = fntfile->heightcxx . . $ gr_font_file_record#height.; |
| 521 | fnt->ch_wcxx . . $ gr_font_record#ch_w.[ch] = w; |
| 522 | fnt->ch_ucxx . . $ gr_font_record#ch_u.[ch] = u; |
| 523 | fnt->ch_vcxx . . $ gr_font_record#ch_v.[ch] = v; |
| 524 | fnt->ch_surfcxx . . $ gr_font_record#ch_surf.[ch] = surf_index - 1; |
| 525 | fnt->ch_hfcxx . . $ gr_font_record#ch_hf.[ch] = ((float)fntfile->heightcxx . . $ gr_font_file_record#height.) / ((float)GRFONT_SURFACE_HEIGHTcxx . . $ `2dlib/font.cpp:136:9`!); |
| 526 | fnt->ch_wfcxx . . $ gr_font_record#ch_wf.[ch] = ((float)w) / ((float)GRFONT_SURFACE_WIDTHcxx . . $ `2dlib/font.cpp:135:9`!); |
| 527 | fnt->ch_ufcxx . . $ gr_font_record#ch_uf.[ch] = ((float)u) / ((float)GRFONT_SURFACE_WIDTHcxx . . $ `2dlib/font.cpp:135:9`!); |
| 528 | fnt->ch_vfcxx . . $ gr_font_record#ch_vf.[ch] = ((float)v) / ((float)GRFONT_SURFACE_HEIGHTcxx . . $ `2dlib/font.cpp:136:9`!); |
| 529 | |
| 530 | // check to adjust uv's if we are outside surface. |
| 531 | u += w; |
| 532 | if ((u + w) > GRFONT_SURFACE_WIDTHcxx . . $ `2dlib/font.cpp:135:9`!) { |
| 533 | u = 0; |
| 534 | v += fntfile->heightcxx . . $ gr_font_file_record#height.; |
| 535 | if ((v + fntfile->heightcxx . . $ gr_font_file_record#height.) > GRFONT_SURFACE_HEIGHTcxx . . $ `2dlib/font.cpp:136:9`!) { |
| 536 | if (surf_index == MAX_FONT_BITMAPScxx . . $ MAX_FONT_BITMAPS.) |
| 537 | Int3cxx . . $ `misc/pserror.h:247:9`!(); |
| 538 | fnt->bmpscxx . . $ gr_font_record#bmps.[surf_index] = bm_AllocBitmapcxx . . $ bm_AllocBitmap(2326284602b0bb2d).(GRFONT_SURFACE_WIDTHcxx . . $ `2dlib/font.cpp:135:9`!, GRFONT_SURFACE_HEIGHTcxx . . $ `2dlib/font.cpp:136:9`!, 0); |
| 539 | if (fnt->bmpscxx . . $ gr_font_record#bmps.[surf_index] == -1) |
| 540 | Errorcxx . . $ Error(326aeb464d16410c).("grFont::translate_to_surfaces <Bitmap allocation error>"); |
| 541 | fnt->surfscxx . . $ gr_font_record#surfs.[surf_index] = new grMemorySurfacecxx . . $ grMemorySurface#grMemorySurface(49f6e7a06ebc5aa8).; |
| 542 | fnt->surfscxx . . $ gr_font_record#surfs.[surf_index]->initcxx . . $ grMemorySurface#init(fe591fed253a3675).(GRFONT_SURFACE_WIDTHcxx . . $ `2dlib/font.cpp:135:9`!, GRFONT_SURFACE_HEIGHTcxx . . $ `2dlib/font.cpp:136:9`!, BPP_16cxx . . $ `lib/grdefs.h:61:9`!, |
| 543 | (char *)bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(fnt->bmpscxx . . $ gr_font_record#bmps.[surf_index], 0), |
| 544 | GRFONT_SURFACE_WIDTHcxx . . $ `2dlib/font.cpp:135:9`! * BITS_TO_BYTEScxx . . $ `2dlib/font.cpp:151:9`!(BPP_16cxx . . $ `lib/grdefs.h:61:9`!), SURFFLAG_COLORKEYcxx . . $ SURFFLAG_COLORKEY.); |
| 545 | fnt->surfscxx . . $ gr_font_record#surfs.[surf_index]->clearcxx . . $ grSurface#clear(cb2f890c2fdad230).(TRANSPARENT_COLOR32cxx . . $ `lib/grdefs.h:70:9`!); |
| 546 | surf_index++; |
| 547 | v = 0; |
| 548 | } |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | // translate mono font data to the surface |
| 554 | void grFontcxx . . $ grFont#::translate_mono_charcxx . . $ grFont#translate_mono_char(f04fccacaaac6574).(grSurfacecxx . . $ grSurface# *sf, int x, int y, int index, gr_font_file_recordcxx . . $ gr_font_file_record# *ft, int width) { |
| 555 | int row, col; // byte width of char |
| 556 | int rowsize; |
| 557 | uint8_tcxx . . $ uint8_t# bit_mask = 0, byte = 0; |
| 558 | uint8_tcxx . . $ uint8_t# *fp; |
| 559 | |
| 560 | fp = ft->char_datacxx . . $ gr_font_file_record#char_data.[index]; |
| 561 | |
| 562 | switch (sf->bppcxx . . $ grSurface#bpp(455f465bc33b4cdf).()) { |
| 563 | case BPP_16cxx . . $ `lib/grdefs.h:61:9`!: { |
| 564 | /* draw one-bit one color. */ |
| 565 | uint16_tcxx . . $ uint16_t# *dest_ptr; |
| 566 | uint16_tcxx . . $ uint16_t# col_w = GR_COLOR_TO_16cxx . . $ GR_COLOR_TO_16(6557041c941ab807).(GR_RGBcxx . . $ GR_RGB(530956271a9518a5).(255, 255, 255)); |
| 567 | int rowsize_w; |
| 568 | |
| 569 | dest_ptr = (uint16_tcxx . . $ uint16_t# *)sf->lockcxx . . $ grSurface#lock(3f31f7b3b80edb32).(&rowsize); |
| 570 | rowsize_w = sf->rowsizecxx . . $ grSurface#rowsize(455f465bc33b4cdf).() / 2; |
| 571 | dest_ptr += (y * rowsize_w) + x; |
| 572 | |
| 573 | for (row = 0; row < ft->heightcxx . . $ gr_font_file_record#height.; row++) { |
| 574 | bit_mask = 0; |
| 575 | for (col = 0; col < width; col++) { |
| 576 | if (bit_mask == 0) { |
| 577 | byte = *fp++; |
| 578 | bit_mask = 0x80; |
| 579 | } |
| 580 | |
| 581 | if (byte & bit_mask) |
| 582 | dest_ptr[col] = col_w; |
| 583 | bit_mask >>= 1; |
| 584 | } |
| 585 | dest_ptr += rowsize_w; |
| 586 | } |
| 587 | |
| 588 | sf->unlockcxx . . $ grSurface#unlock(49f6e7a06ebc5aa8).(); |
| 589 | break; |
| 590 | } |
| 591 | |
| 592 | case BPP_32cxx . . $ `lib/grdefs.h:63:9`!: |
| 593 | default: |
| 594 | Int3cxx . . $ `misc/pserror.h:247:9`!(); // NOT SUPPORTED YET |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | // ---------------------------------------------------------------------------- |
| 599 | // draw_char function |
| 600 | // give a viewport x,y and char |
| 601 | // ---------------------------------------------------------------------------- |
| 602 | |
| 603 | int grFontcxx . . $ grFont#::draw_charcxx . . $ grFont#draw_char(222b2b3cf8cd66cf).(grSurfacecxx . . $ grSurface# *sf, int x, int y, int ch, tCharPropertiescxx . . $ tCharProperties# *chprop) { |
| 604 | gr_font_recordcxx . . $ gr_font_record# *ft; |
| 605 | int next_x = 0, width, index; |
| 606 | |
| 607 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_FontHandle > -1); |
| 608 | if ((ch < min_asciicxx . . $ grFont#min_ascii(455f465bc33b4cdf).()) || (ch > max_asciicxx . . $ grFont#max_ascii(455f465bc33b4cdf).())) |
| 609 | return (next_x + 1); |
| 610 | |
| 611 | // save current x and get this font |
| 612 | ft = &grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[m_FontHandlecxx . . $ grFont#m_FontHandle.]; |
| 613 | next_x = x; |
| 614 | index = ch - ft->fontcxx . . $ gr_font_record#font..min_asciicxx . . $ gr_font_file_record#min_ascii.; |
| 615 | |
| 616 | // draw either a color bitmap or mono font. |
| 617 | if (ft->fontcxx . . $ gr_font_record#font..flagscxx . . $ gr_font_file_record#flags. & FT_PROPORTIONALcxx . . $ `2dlib/font.cpp:131:9`!) { |
| 618 | width = (int)ft->fontcxx . . $ gr_font_record#font..char_widthscxx . . $ gr_font_file_record#char_widths.[index]; |
| 619 | } else { |
| 620 | width = (int)ft->fontcxx . . $ gr_font_record#font..widthcxx . . $ gr_font_file_record#width.; |
| 621 | } |
| 622 | |
| 623 | // perform blt. |
| 624 | if (sf->get_flagscxx . . $ grSurface#get_flags(ddd8539a2fcdd4ce).() & SURFFLAG_RENDERERcxx . . $ SURFFLAG_RENDERER.) { |
| 625 | rend_SetCharacterParameterscxx . . $ rend_SetCharacterParameters(eda338842932bf2b).(chprop->colcxx . . $ tCharProperties#col.[0], chprop->colcxx . . $ tCharProperties#col.[1], chprop->colcxx . . $ tCharProperties#col.[2], chprop->colcxx . . $ tCharProperties#col.[3]); |
| 626 | rend_DrawFontCharactercxx . . $ rend_DrawFontCharacter(d3f982e0313c7b8c).(ft->bmpscxx . . $ gr_font_record#bmps.[ft->ch_surfcxx . . $ gr_font_record#ch_surf.[index]], x, y, x + ft->ch_wcxx . . $ gr_font_record#ch_w.[index] - 1, y + ft->ch_hcxx . . $ gr_font_record#ch_h.[index] - 1, |
| 627 | ft->ch_ufcxx . . $ gr_font_record#ch_uf.[index], ft->ch_vfcxx . . $ gr_font_record#ch_vf.[index], ft->ch_wfcxx . . $ gr_font_record#ch_wf.[index], ft->ch_hfcxx . . $ gr_font_record#ch_hf.[index]); |
| 628 | } else if (ft->fontcxx . . $ gr_font_record#font..flagscxx . . $ gr_font_file_record#flags. & FT_COLORcxx . . $ `2dlib/font.cpp:130:9`!) { |
| 629 | sf->bltcxx . . $ grSurface#blt(ff120d6cc88a52cd).(x, y, ft->surfscxx . . $ gr_font_record#surfs.[ft->ch_surfcxx . . $ gr_font_record#ch_surf.[index]], ft->ch_ucxx . . $ gr_font_record#ch_u.[index], ft->ch_vcxx . . $ gr_font_record#ch_v.[index], ft->ch_wcxx . . $ gr_font_record#ch_w.[index], ft->ch_hcxx . . $ gr_font_record#ch_h.[index]); |
| 630 | } else { |
| 631 | charblt16cxx . . $ grFont#charblt16(12c723590b6d1aa0).(sf, chprop->colcxx . . $ tCharProperties#col.[0], x, y, ft->surfscxx . . $ gr_font_record#surfs.[ft->ch_surfcxx . . $ gr_font_record#ch_surf.[index]], ft->ch_ucxx . . $ gr_font_record#ch_u.[index], ft->ch_vcxx . . $ gr_font_record#ch_v.[index], |
| 632 | ft->ch_wcxx . . $ gr_font_record#ch_w.[index], ft->ch_hcxx . . $ gr_font_record#ch_h.[index]); |
| 633 | } |
| 634 | |
| 635 | // adjust next x value with kerning and return it. |
| 636 | next_x += width; |
| 637 | |
| 638 | return next_x; |
| 639 | } |
| 640 | |
| 641 | int grFontcxx . . $ grFont#::draw_charcxx . . $ grFont#draw_char(9867803b38a2387f).(grSurfacecxx . . $ grSurface# *sf, int x, int y, int ch, int sx, int sy, int sw, int sh, tCharPropertiescxx . . $ tCharProperties# *chprop) { |
| 642 | gr_font_recordcxx . . $ gr_font_record# *ft; |
| 643 | int next_x = 0, width, index; |
| 644 | |
| 645 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_FontHandle > -1); |
| 646 | if ((ch < min_asciicxx . . $ grFont#min_ascii(455f465bc33b4cdf).()) || (ch > max_asciicxx . . $ grFont#max_ascii(455f465bc33b4cdf).())) |
| 647 | return (next_x + 1); |
| 648 | |
| 649 | // save current x and get this font |
| 650 | ft = &grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[m_FontHandlecxx . . $ grFont#m_FontHandle.]; |
| 651 | next_x = x; |
| 652 | index = ch - ft->fontcxx . . $ gr_font_record#font..min_asciicxx . . $ gr_font_file_record#min_ascii.; |
| 653 | |
| 654 | // draw either a color bitmap or mono font. |
| 655 | if (ft->fontcxx . . $ gr_font_record#font..flagscxx . . $ gr_font_file_record#flags. & FT_PROPORTIONALcxx . . $ `2dlib/font.cpp:131:9`!) { |
| 656 | width = (int)ft->fontcxx . . $ gr_font_record#font..char_widthscxx . . $ gr_font_file_record#char_widths.[index]; |
| 657 | } else { |
| 658 | width = (int)ft->fontcxx . . $ gr_font_record#font..widthcxx . . $ gr_font_file_record#width.; |
| 659 | } |
| 660 | |
| 661 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(sx + sw <= width); |
| 662 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(sy + sh <= ft->font.height); |
| 663 | |
| 664 | // peform blt instead. |
| 665 | // perform blt. |
| 666 | if (sf->get_flagscxx . . $ grSurface#get_flags(ddd8539a2fcdd4ce).() & SURFFLAG_RENDERERcxx . . $ SURFFLAG_RENDERER.) { |
| 667 | rend_SetCharacterParameterscxx . . $ rend_SetCharacterParameters(eda338842932bf2b).(chprop->colcxx . . $ tCharProperties#col.[0], chprop->colcxx . . $ tCharProperties#col.[1], chprop->colcxx . . $ tCharProperties#col.[2], chprop->colcxx . . $ tCharProperties#col.[3]); |
| 668 | |
| 669 | rend_DrawFontCharactercxx . . $ rend_DrawFontCharacter(d3f982e0313c7b8c).(ft->bmpscxx . . $ gr_font_record#bmps.[ft->ch_surfcxx . . $ gr_font_record#ch_surf.[index]], x, y, x + sw - 1, y + sh - 1, |
| 670 | ft->ch_ufcxx . . $ gr_font_record#ch_uf.[index] + (((float)sx) / ((float)GRFONT_SURFACE_WIDTHcxx . . $ `2dlib/font.cpp:135:9`!)), |
| 671 | ft->ch_vfcxx . . $ gr_font_record#ch_vf.[index] + (((float)sy) / ((float)GRFONT_SURFACE_HEIGHTcxx . . $ `2dlib/font.cpp:136:9`!)), |
| 672 | ((float)sw) / ((float)GRFONT_SURFACE_WIDTHcxx . . $ `2dlib/font.cpp:135:9`!), ((float)sh) / ((float)GRFONT_SURFACE_HEIGHTcxx . . $ `2dlib/font.cpp:136:9`!)); |
| 673 | } else if (ft->fontcxx . . $ gr_font_record#font..flagscxx . . $ gr_font_file_record#flags. & FT_COLORcxx . . $ `2dlib/font.cpp:130:9`!) { |
| 674 | sf->bltcxx . . $ grSurface#blt(ff120d6cc88a52cd).(x, y, ft->surfscxx . . $ gr_font_record#surfs.[ft->ch_surfcxx . . $ gr_font_record#ch_surf.[index]], ft->ch_ucxx . . $ gr_font_record#ch_u.[index] + sx, ft->ch_vcxx . . $ gr_font_record#ch_v.[index] + sy, sw, sh); |
| 675 | } else { |
| 676 | charblt16cxx . . $ grFont#charblt16(12c723590b6d1aa0).(sf, chprop->colcxx . . $ tCharProperties#col.[0], x, y, ft->surfscxx . . $ gr_font_record#surfs.[ft->ch_surfcxx . . $ gr_font_record#ch_surf.[index]], ft->ch_ucxx . . $ gr_font_record#ch_u.[index] + sx, ft->ch_vcxx . . $ gr_font_record#ch_v.[index] + sy, sw, |
| 677 | sh); |
| 678 | } |
| 679 | |
| 680 | // adjust next x value with kerning and return it. |
| 681 | next_x += sw; |
| 682 | |
| 683 | return next_x; |
| 684 | } |
| 685 | |
| 686 | // ---------------------------------------------------------------------------- |
| 687 | // accessor functions |
| 688 | // ---------------------------------------------------------------------------- |
| 689 | |
| 690 | int grFontcxx . . $ grFont#::get_char_infocxx . . $ grFont#get_char_info(ac48f4a6ffa9e770).(int ch, int *width) { |
| 691 | gr_font_file_recordcxx . . $ gr_font_file_record# *ft; |
| 692 | |
| 693 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_FontHandle > -1); |
| 694 | |
| 695 | ft = &grFontcxx . . $ grFont#::m_FontListcxx . . $ grFont#m_FontList.[m_FontHandlecxx . . $ grFont#m_FontHandle.].fontcxx . . $ gr_font_record#font.; |
| 696 | |
| 697 | if (ch < ft->min_asciicxx . . $ gr_font_file_record#min_ascii. || ch > ft->max_asciicxx . . $ gr_font_file_record#max_ascii.) |
| 698 | *width = 0; |
| 699 | else if (ft->flagscxx . . $ gr_font_file_record#flags. & FT_PROPORTIONALcxx . . $ `2dlib/font.cpp:131:9`!) |
| 700 | *width = ft->char_widthscxx . . $ gr_font_file_record#char_widths.[ch - ft->min_asciicxx . . $ gr_font_file_record#min_ascii.]; |
| 701 | else |
| 702 | *width = ft->widthcxx . . $ gr_font_file_record#width.; |
| 703 | |
| 704 | return 0; |
| 705 | } |
| 706 | |
| 707 | uint8_tcxx . . $ uint8_t# *grFontcxx . . $ grFont#::get_kern_infocxx . . $ grFont#get_kern_info(59fcd22a18ea873d).(uint8_tcxx . . $ uint8_t# c1, uint8_tcxx . . $ uint8_t# c2) { |
| 708 | // gr_font_file_record *ft; |
| 709 | // uint8_t *p; |
| 710 | |
| 711 | // p = ft->kern_data; |
| 712 | // ft = &grFont::m_FontList[m_FontHandle].font; |
| 713 | // c2 = c2 - ft->min_ascii; |
| 714 | // c1 = c1 - ft->min_ascii; |
| 715 | |
| 716 | // while (*p!=255) |
| 717 | // { |
| 718 | // if (p[0]==c1 && p[1]==c2) return p; |
| 719 | // else p+=3; |
| 720 | // } |
| 721 | |
| 722 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 723 | } |
| 724 | |
| 725 | void grFontcxx . . $ grFont#::charblt16cxx . . $ grFont#charblt16(12c723590b6d1aa0).(grSurfacecxx . . $ grSurface# *dsf, ddgr_colorcxx . . $ ddgr_color# col, int dx, int dy, grSurfacecxx . . $ grSurface# *ssf, int sx, int sy, int sw, int sh) { |
| 726 | uint16_tcxx . . $ uint16_t# *dbits; |
| 727 | uint16_tcxx . . $ uint16_t# *sbits; |
| 728 | int srowsize_w, drowsize_w, row, coln; |
| 729 | uint16_tcxx . . $ uint16_t# scol = GR_COLOR_TO_16cxx . . $ GR_COLOR_TO_16(6557041c941ab807).(col); |
| 730 | |
| 731 | dbits = (uint16_tcxx . . $ uint16_t# *)dsf->lockcxx . . $ grSurface#lock(3f31f7b3b80edb32).(&drowsize_w); |
| 732 | if (dbits) { |
| 733 | sbits = (uint16_tcxx . . $ uint16_t# *)ssf->lockcxx . . $ grSurface#lock(3f31f7b3b80edb32).(&srowsize_w); |
| 734 | if (sbits) { |
| 735 | srowsize_w >>= 1; // rowsize in shorts |
| 736 | drowsize_w >>= 1; |
| 737 | dbits = dbits + (dy * drowsize_w) + dx; |
| 738 | sbits = sbits + (sy * srowsize_w) + sx; |
| 739 | |
| 740 | for (row = 0; row < sh; row++) { |
| 741 | for (coln = 0; coln < sw; coln++) { |
| 742 | if (sbits[coln] & OPAQUE_FLAG16cxx . . $ `lib/grdefs.h:69:9`!) |
| 743 | dbits[coln] = scol; |
| 744 | } |
| 745 | sbits += srowsize_w; |
| 746 | dbits += drowsize_w; |
| 747 | } |
| 748 | |
| 749 | ssf->unlockcxx . . $ grSurface#unlock(49f6e7a06ebc5aa8).(); |
| 750 | } |
| 751 | dsf->unlockcxx . . $ grSurface#unlock(49f6e7a06ebc5aa8).(); |
| 752 | } |
| 753 | } |