| 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/Lib/grtext.h $ |
| 21 | * $Revision: 25 $ |
| 22 | * $Date: 11/16/99 3:18p $ |
| 23 | * $Author: Samir $ |
| 24 | * |
| 25 | * |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/Lib/grtext.h $ |
| 28 | * |
| 29 | * 25 11/16/99 3:18p Samir |
| 30 | * added new data to font file and kept compatibility with D3 fonts: |
| 31 | * tracking value. |
| 32 | * |
| 33 | * 24 4/17/99 6:16p Samir |
| 34 | * added kerning and 4444 alphaed font support. |
| 35 | * |
| 36 | * 23 4/02/99 3:49p Kevin |
| 37 | * Added profanity filter code |
| 38 | * |
| 39 | * 22 4/01/99 5:23p Samir |
| 40 | * Added function to get character info. |
| 41 | * |
| 42 | * 21 3/02/99 6:26p Samir |
| 43 | * added font template width and height functions. |
| 44 | * |
| 45 | * 20 2/21/99 6:39p Samir |
| 46 | * added function to get ascii value of font character. |
| 47 | * |
| 48 | * 19 1/20/99 3:43a Jeff |
| 49 | * added function to get clipping parameters |
| 50 | * |
| 51 | * 18 11/03/98 7:04p Samir |
| 52 | * made Grtext_spacing global so word wrapper could access it. |
| 53 | * |
| 54 | * 17 10/22/98 2:41p Samir |
| 55 | * made grtext_Puts public. |
| 56 | * |
| 57 | * 16 10/21/98 11:50p Samir |
| 58 | * added prototype for advanced grtext get char info function. |
| 59 | * |
| 60 | * 15 10/16/98 1:54p Kevin |
| 61 | * Changes for Demo Beta 4 |
| 62 | * |
| 63 | * 14 9/24/98 2:56p Samir |
| 64 | * added ability to format strings inside string. |
| 65 | * |
| 66 | * 13 9/08/98 10:27a Samir |
| 67 | * added function to get text height. |
| 68 | * |
| 69 | * 12 6/23/98 5:04p Samir |
| 70 | * added grtext_GetColor |
| 71 | * |
| 72 | * 11 4/27/98 3:46p Samir |
| 73 | * scaling fonts. |
| 74 | * |
| 75 | * 10 4/18/98 2:08a Samir |
| 76 | * extended text buffer. |
| 77 | * |
| 78 | * 9 2/13/98 6:37p Samir |
| 79 | * Fixed tabs. |
| 80 | * |
| 81 | * 8 2/03/98 12:13p Samir |
| 82 | * Font shadowing support added. |
| 83 | * |
| 84 | * 7 1/30/98 2:15p Samir |
| 85 | * Allow for text saturation. |
| 86 | * |
| 87 | * 6 1/23/98 6:53p Samir |
| 88 | * Added grtext_PutChar. |
| 89 | * |
| 90 | * 5 1/12/98 5:24p Samir |
| 91 | * Fixed font reading and created font spew test function. |
| 92 | * |
| 93 | * 4 1/08/98 12:16p Samir |
| 94 | * GetLineWidth now takes a const char * |
| 95 | * |
| 96 | * 3 12/30/97 5:23p Samir |
| 97 | * More stuff. |
| 98 | * |
| 99 | * 2 12/29/97 5:50p Samir |
| 100 | * Added ability to set text window. |
| 101 | * |
| 102 | * 1 12/29/97 3:24p Samir |
| 103 | * Initial revision |
| 104 | * |
| 105 | * $NoKeywords: $ |
| 106 | */ |
| 107 | |
| 108 | #ifndef GRTEXT_H |
| 109 | #define GRTEXT_Hcxx . . $ `grtext/grtext.h:109:9`! |
| 110 | |
| 111 | #include <cstdint> |
| 112 | |
| 113 | #include "ddvid.h"cxx . . $ `<file>/lib/ddvid.h`/ |
| 114 | |
| 115 | #define GRTEXT_BUFLENcxx . . $ `grtext/grtext.h:115:9`! 16384 |
| 116 | #define GRTEXT_FORMAT_CHARcxx . . $ `grtext/grtext.h:116:9`! 0x2 |
| 117 | #define GRTEXT_FORMAT_SCALARcxx . . $ `grtext/grtext.h:117:9`! 4 // value mulitplied to formatting value in string. |
| 118 | |
| 119 | #define GRTEXTFLAG_SATURATEcxx . . $ `grtext/grtext.h:119:9`! 1 |
| 120 | #define GRTEXTFLAG_SHADOWcxx . . $ `grtext/grtext.h:120:9`! 2 |
| 121 | |
| 122 | struct tFontTemplatecxx . . $ tFontTemplate#; |
| 123 | |
| 124 | extern int Grtext_spacingcxx . . $ Grtext_spacing.; |
| 125 | |
| 126 | // sets text clipping parameters |
| 127 | void grtext_SetParameterscxx . . $ grtext_SetParameters(1559a299834bcdd5).(int left, int top, int right, int bottom, int tabspace = 4); |
| 128 | |
| 129 | // gets text clipping parameters |
| 130 | void grtext_GetParameterscxx . . $ grtext_GetParameters(adf20dddcf83aa52).(int *left, int *top, int *right, int *bottom, int *tabspace); |
| 131 | |
| 132 | // clears text buffer. doesn't render. |
| 133 | void grtext_Resetcxx . . $ grtext_Reset(49f6e7a06ebc5aa8).(); |
| 134 | |
| 135 | // sets the color for text |
| 136 | void grtext_SetColorcxx . . $ grtext_SetColor(cb2f890c2fdad230).(ddgr_colorcxx . . $ ddgr_color# col); |
| 137 | |
| 138 | // returns color set by grtext_SetColor (does not count intra-string color changes) |
| 139 | ddgr_colorcxx . . $ ddgr_color# grtext_GetColorcxx . . $ grtext_GetColor(db52760e79bf9054).(); |
| 140 | |
| 141 | // sets fancy color for text |
| 142 | void grtext_SetFancyColorcxx . . $ grtext_SetFancyColor(eda338842932bf2b).(ddgr_colorcxx . . $ ddgr_color# col1, ddgr_colorcxx . . $ ddgr_color# col2, ddgr_colorcxx . . $ ddgr_color# col3, ddgr_colorcxx . . $ ddgr_color# col4); |
| 143 | |
| 144 | // sets the alpha value for text |
| 145 | void grtext_SetAlphacxx . . $ grtext_SetAlpha(ac50b47256ae7414).(uint8_tcxx . . $ uint8_t# alpha); |
| 146 | |
| 147 | // gets font alpha |
| 148 | uint8_tcxx . . $ uint8_t# grtext_GetAlphacxx . . $ grtext_GetAlpha(7c4be072098b358f).(); |
| 149 | |
| 150 | // toggles text saturation |
| 151 | void grtext_SetFlagscxx . . $ grtext_SetFlags(d4f767463ce0a6b3).(int flags); |
| 152 | |
| 153 | // sets the font for text |
| 154 | void grtext_SetFontcxx . . $ grtext_SetFont(d4f767463ce0a6b3).(int font_handle); |
| 155 | |
| 156 | // sets font scale (1.0 = normal, 0.5 = 1/2, 2.0 = twice as large. |
| 157 | void grtext_SetFontScalecxx . . $ grtext_SetFontScale(9364e6e7bff7660).(float scale); |
| 158 | |
| 159 | // gets the current font |
| 160 | int grtext_GetFontcxx . . $ grtext_GetFont(b126dc7c1de90089).(); |
| 161 | |
| 162 | // returns the height of a string in current font. |
| 163 | int grtext_GetTextHeightcxx . . $ grtext_GetTextHeight(5c4306d8553b3696).(const char *str); |
| 164 | #define grtext_GetHeightcxx . . $ `grtext/grtext.h:164:9`!(_s) grtext_GetTextHeight(_s) |
| 165 | |
| 166 | // returns height of text using a font template |
| 167 | int grtext_GetTextHeightTemplatecxx . . $ grtext_GetTextHeightTemplate(93ac3d427ebf4f7a).(tFontTemplatecxx . . $ tFontTemplate# *ft, const char *str); |
| 168 | #define grtext_GetHeightTemplatecxx . . $ `grtext/grtext.h:168:9`!(_t, _s) grtext_GetTextHeightTemplate(_t, _s) |
| 169 | |
| 170 | // returns width of text in current font. |
| 171 | int grtext_GetTextLineWidthcxx . . $ grtext_GetTextLineWidth(5c4306d8553b3696).(const char *str); |
| 172 | #define grtext_GetLineWidthcxx . . $ `grtext/grtext.h:172:9`!(_s) grtext_GetTextLineWidth(_s) |
| 173 | |
| 174 | // returns width of text using a font template |
| 175 | int grtext_GetTextLineWidthTemplatecxx . . $ grtext_GetTextLineWidthTemplate(1590a249ecc23cdb).(const tFontTemplatecxx . . $ tFontTemplate# *ft, const char *str); |
| 176 | #define grtext_GetLineWidthTemplatecxx . . $ `grtext/grtext.h:176:9`!(_t, _s) grtext_GetTextLineWidthTemplate(_t, _s) |
| 177 | |
| 178 | // puts a formatted string in the text buffer |
| 179 | void grtext_Printfcxx . . $ grtext_Printf(9514e36549094170).(int x, int y, const char *fmt, ...); |
| 180 | |
| 181 | // puts a string on the buffer |
| 182 | void grtext_Putscxx . . $ grtext_Puts(3139f19a0dbb8edf).(int x, int y, const char *str); |
| 183 | |
| 184 | // puts a character down |
| 185 | void grtext_PutCharcxx . . $ grtext_PutChar(b1146eedae1e1d0b).(int x, int y, int ch); |
| 186 | |
| 187 | // puts a centered string in the text buffer. |
| 188 | void grtext_CenteredPrintfcxx . . $ grtext_CenteredPrintf(9514e36549094170).(int xoff, int y, const char *fmt, ...); |
| 189 | |
| 190 | // renders all text in buffer and clears buffer. USUALLY CALL THIS TO RENDER TEXT |
| 191 | void grtext_Flushcxx . . $ grtext_Flush(49f6e7a06ebc5aa8).(); |
| 192 | |
| 193 | // renders all text but DOESN'T flush buffer |
| 194 | void grtext_Rendercxx . . $ grtext_Render(49f6e7a06ebc5aa8).(); |
| 195 | |
| 196 | // gets character information for the current string |
| 197 | // ch is a SINGLE CHARACTER |
| 198 | // col is the color of the current string as reported through formatting, or GR_NULL if no info |
| 199 | // x is the old x before call and the new potential adjusted x after the call. |
| 200 | // newline if it's a newline. |
| 201 | // line start x; |
| 202 | struct tGetCharInfocxx . . $ tGetCharInfo# { |
| 203 | int sxcxx . . $ tGetCharInfo#sx.; // this will not be modified. the initial x on the same line as the string |
| 204 | |
| 205 | ddgr_colorcxx . . $ ddgr_color# colcxx . . $ tGetCharInfo#col.; // these values will be modified |
| 206 | int xcxx . . $ tGetCharInfo#x., wcxx . . $ tGetCharInfo#w.; // x of char, and width of char. |
| 207 | bool newlinecxx . . $ tGetCharInfo#newline.; // reached a newline? |
| 208 | bool font_charcxx . . $ tGetCharInfo#font_char.; // character exists in font? |
| 209 | char chcxx . . $ tGetCharInfo#ch.; |
| 210 | }; |
| 211 | |
| 212 | const char *grtext_GetCharcxx . . $ grtext_GetChar(41314a824f77152).(const char *str, tGetCharInfocxx . . $ tGetCharInfo# *ci); |
| 213 | |
| 214 | ////////////////////////////////////////////////////////////////////////////// |
| 215 | // font functions! |
| 216 | |
| 217 | // we can load a font template into this structure. call grfont_FreeTemplate(tFontTemplate) to free memory here. |
| 218 | struct tFontTemplatecxx . . $ tFontTemplate# { |
| 219 | uint16_tcxx . . $ uint16_t# min_asciicxx . . $ tFontTemplate#min_ascii., max_asciicxx . . $ tFontTemplate#max_ascii.; |
| 220 | uint8_tcxx . . $ uint8_t# *ch_widthscxx . . $ tFontTemplate#ch_widths.; |
| 221 | uint8_tcxx . . $ uint8_t# *kern_datacxx . . $ tFontTemplate#kern_data.; |
| 222 | uint8_tcxx . . $ uint8_t# ch_heightcxx . . $ tFontTemplate#ch_height.; |
| 223 | uint8_tcxx . . $ uint8_t# ch_maxwidthcxx . . $ tFontTemplate#ch_maxwidth.; // max width of character in font. |
| 224 | bool proportionalcxx . . $ tFontTemplate#proportional.; // is this font proportional? if so use array of widths, else use maxwidth |
| 225 | bool uppercasecxx . . $ tFontTemplate#uppercase.; // uppercase font? |
| 226 | bool monochromaticcxx . . $ tFontTemplate#monochromatic.; // font is monochromatic? |
| 227 | bool newstylecxx . . $ tFontTemplate#newstyle.; // new style 4444 font. |
| 228 | bool ffi2cxx . . $ tFontTemplate#ffi2.; // new font info added. |
| 229 | |
| 230 | // ffi2 style (font file info 2) |
| 231 | int8_tcxx . . $ int8_t# ch_trackingcxx . . $ tFontTemplate#ch_tracking.; // global tracking for font. |
| 232 | }; |
| 233 | |
| 234 | // clears out font buffer. |
| 235 | void grfont_Resetcxx . . $ grfont_Reset(49f6e7a06ebc5aa8).(); |
| 236 | |
| 237 | // returns a handle to a loaded font. |
| 238 | int grfont_Loadcxx . . $ grfont_Load(5c4306d8553b3696).(const char *fname); |
| 239 | |
| 240 | // frees a loaded font |
| 241 | void grfont_Freecxx . . $ grfont_Free(d4f767463ce0a6b3).(int handle); |
| 242 | |
| 243 | // loads a font template |
| 244 | bool grfont_LoadTemplatecxx . . $ grfont_LoadTemplate(5e0be355757499ea).(const char *fname, tFontTemplatecxx . . $ tFontTemplate# *ft); |
| 245 | |
| 246 | // frees a font template |
| 247 | void grfont_FreeTemplatecxx . . $ grfont_FreeTemplate(218f1c398dde951b).(tFontTemplatecxx . . $ tFontTemplate# *ft); |
| 248 | |
| 249 | // returns a character's width |
| 250 | int grfont_GetCharWidthcxx . . $ grfont_GetCharWidth(9b79fb6aee4c0440).(int font, int ch); |
| 251 | |
| 252 | // returns a font's height |
| 253 | int grfont_GetHeightcxx . . $ grfont_GetHeight(7864480464b09eea).(int font); |
| 254 | |
| 255 | // returns a character's width |
| 256 | int grfont_GetKernedSpacingcxx . . $ grfont_GetKernedSpacing(2326284602b0bb2d).(int font, int ch1, int ch2); |
| 257 | |
| 258 | // returns a character's width |
| 259 | int grfont_GetKernedSpacingTempcxx . . $ grfont_GetKernedSpacingTemp(1511bff7f72f8bee).(const tFontTemplatecxx . . $ tFontTemplate# *ft, int ch1, int ch2); |
| 260 | |
| 261 | // converts a key code to ascii version, and checks if in font. converts lowercase to upper if font |
| 262 | // doesn't have a lowercase set. useful alternative to ddio_KeyToAscii. |
| 263 | int grfont_KeyToAsciicxx . . $ grfont_KeyToAscii(9b79fb6aee4c0440).(int font, int key); |
| 264 | |
| 265 | // returns the raw bitmap data for a character in a font, its width and height |
| 266 | // returned data should be in 565 hicolor format if (*mono) is false. if (*mono) is true, |
| 267 | // then a bitmask will be returned, and you should treat a bit as a pixel. |
| 268 | uint16_tcxx . . $ uint16_t# *grfont_GetRawCharacterDatacxx . . $ grfont_GetRawCharacterData(d8905bd92668b855).(int font, int ch, int *w, int *h, bool *mono); |
| 269 | |
| 270 | ///////////////////////////////////////////////////////////////////// |
| 271 | // EDITING FUNCTIONS ONLY |
| 272 | |
| 273 | // sets a template to a font, be careful. |
| 274 | bool grfont_SetTemplatecxx . . $ grfont_SetTemplate(773c94601bc0322b).(const char *pathname, const tFontTemplatecxx . . $ tFontTemplate# *ft); |
| 275 | |
| 276 | // sets a font's template without saving... |
| 277 | bool grfont_SetKerningcxx . . $ grfont_SetKerning(f90e3f9e410d4f54).(int font, uint8_tcxx . . $ uint8_t# *kern_data); |
| 278 | |
| 279 | // sets a font's tracking |
| 280 | bool grfont_SetTrackingcxx . . $ grfont_SetTracking(cf9ef193275fa6d8).(int font, int tracking); |
| 281 | int grfont_GetTrackingcxx . . $ grfont_GetTracking(7864480464b09eea).(int font); |
| 282 | |
| 283 | ///////////////////////////////////////////////////////////////////// |
| 284 | |
| 285 | // Init functions -- call before anything is rendered! |
| 286 | void grtext_Initcxx . . $ grtext_Init(49f6e7a06ebc5aa8).(); |
| 287 | |
| 288 | #ifndef RELEASE |
| 289 | void grfont_Spewcxx . . $ grfont_Spew(b1146eedae1e1d0b).(int font, int x, int y); |
| 290 | #endif |
| 291 | |
| 292 | struct tFontFileInfo2cxx . . $ tFontFileInfo2# // to maintain compatibility with older fonts (64 bytes long) |
| 293 | { |
| 294 | int16_tcxx . . $ int16_t# trackingcxx . . $ tFontFileInfo2#tracking.; |
| 295 | char reservedcxx . . $ tFontFileInfo2#reserved.[62]; |
| 296 | }; |
| 297 | |
| 298 | // font data structure internal to library but available for font editors |
| 299 | struct tFontFileInfocxx . . $ tFontFileInfo# { |
| 300 | int16_tcxx . . $ int16_t# widthcxx . . $ tFontFileInfo#width., heightcxx . . $ tFontFileInfo#height.; // width of widest character and height of longest char |
| 301 | int16_tcxx . . $ int16_t# flagscxx . . $ tFontFileInfo#flags.; // flags used by the character renderer |
| 302 | int16_tcxx . . $ int16_t# baselinecxx . . $ tFontFileInfo#baseline.; // pixels given to lowercase below script line start at baseline |
| 303 | uint8_tcxx . . $ uint8_t# min_asciicxx . . $ tFontFileInfo#min_ascii.; // minimum ascii value used by font |
| 304 | uint8_tcxx . . $ uint8_t# max_asciicxx . . $ tFontFileInfo#max_ascii.; // max ascii value used by the font |
| 305 | int16_tcxx . . $ int16_t# byte_widthcxx . . $ tFontFileInfo#byte_width.; // width of a character in the font in bytes |
| 306 | uint8_tcxx . . $ uint8_t# *raw_datacxx . . $ tFontFileInfo#raw_data.; // pixel, map data. |
| 307 | uint8_tcxx . . $ uint8_t# **char_datacxx . . $ tFontFileInfo#char_data.; // pointers to each character |
| 308 | uint8_tcxx . . $ uint8_t# *char_widthscxx . . $ tFontFileInfo#char_widths.; // individual pixel widths of each character |
| 309 | uint8_tcxx . . $ uint8_t# *kern_datacxx . . $ tFontFileInfo#kern_data.; // kerning information for specific letter combos |
| 310 | |
| 311 | // FFI2 (newstyle) data |
| 312 | tFontFileInfo2cxx . . $ tFontFileInfo2# ffi2cxx . . $ tFontFileInfo#ffi2.; |
| 313 | |
| 314 | // misc. |
| 315 | float brightnesscxx . . $ tFontFileInfo#brightness.; // this IS NOT in the file, but a part of the baseline element. (upper 8bits) |
| 316 | }; |
| 317 | |
| 318 | #define FT_COLORcxx . . $ `grtext/grtext.h:318:9`! 1 |
| 319 | #define FT_PROPORTIONALcxx . . $ `grtext/grtext.h:319:9`! 2 |
| 320 | #define FT_KERNEDcxx . . $ `grtext/grtext.h:320:9`! 4 |
| 321 | #define FT_GRADIENTcxx . . $ `grtext/grtext.h:321:9`! 8 |
| 322 | #define FT_FMT4444cxx . . $ `grtext/grtext.h:322:9`! 16 |
| 323 | #define FT_FFI2cxx . . $ `grtext/grtext.h:323:9`! 32 // all fonts made after D3 should have this flag set. |
| 324 | |
| 325 | #endif |