Debian Codegraph @

grtext/grtext.h

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/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_H
110
111 #include <cstdint>
112
113 #include "ddvid.h"
114
115 #define GRTEXT_BUFLEN 16384
116 #define GRTEXT_FORMAT_CHAR 0x2
117 #define GRTEXT_FORMAT_SCALAR 4 // value mulitplied to formatting value in string.
118
119 #define GRTEXTFLAG_SATURATE 1
120 #define GRTEXTFLAG_SHADOW 2
121
122 struct tFontTemplate;
123
124 extern int Grtext_spacing;
125
126 // sets text clipping parameters
127 void grtext_SetParameters(int left, int top, int right, int bottom, int tabspace = 4);
128
129 // gets text clipping parameters
130 void grtext_GetParameters(int *left, int *top, int *right, int *bottom, int *tabspace);
131
132 // clears text buffer. doesn't render.
133 void grtext_Reset();
134
135 // sets the color for text
136 void grtext_SetColor(ddgr_color col);
137
138 // returns color set by grtext_SetColor (does not count intra-string color changes)
139 ddgr_color grtext_GetColor();
140
141 // sets fancy color for text
142 void grtext_SetFancyColor(ddgr_color col1, ddgr_color col2, ddgr_color col3, ddgr_color col4);
143
144 // sets the alpha value for text
145 void grtext_SetAlpha(uint8_t alpha);
146
147 // gets font alpha
148 uint8_t grtext_GetAlpha();
149
150 // toggles text saturation
151 void grtext_SetFlags(int flags);
152
153 // sets the font for text
154 void grtext_SetFont(int font_handle);
155
156 // sets font scale (1.0 = normal, 0.5 = 1/2, 2.0 = twice as large.
157 void grtext_SetFontScale(float scale);
158
159 // gets the current font
160 int grtext_GetFont();
161
162 // returns the height of a string in current font.
163 int grtext_GetTextHeight(const char *str);
164 #define grtext_GetHeight(_s) grtext_GetTextHeight(_s)
165
166 // returns height of text using a font template
167 int grtext_GetTextHeightTemplate(tFontTemplate *ft, const char *str);
168 #define grtext_GetHeightTemplate(_t, _s) grtext_GetTextHeightTemplate(_t, _s)
169
170 // returns width of text in current font.
171 int grtext_GetTextLineWidth(const char *str);
172 #define grtext_GetLineWidth(_s) grtext_GetTextLineWidth(_s)
173
174 // returns width of text using a font template
175 int grtext_GetTextLineWidthTemplate(const tFontTemplate *ft, const char *str);
176 #define grtext_GetLineWidthTemplate(_t, _s) grtext_GetTextLineWidthTemplate(_t, _s)
177
178 // puts a formatted string in the text buffer
179 void grtext_Printf(int x, int y, const char *fmt, ...);
180
181 // puts a string on the buffer
182 void grtext_Puts(int x, int y, const char *str);
183
184 // puts a character down
185 void grtext_PutChar(int x, int y, int ch);
186
187 // puts a centered string in the text buffer.
188 void grtext_CenteredPrintf(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_Flush();
192
193 // renders all text but DOESN'T flush buffer
194 void grtext_Render();
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 tGetCharInfo {
203 int sx; // this will not be modified. the initial x on the same line as the string
204
205 ddgr_color col; // these values will be modified
206 int x, w; // x of char, and width of char.
207 bool newline; // reached a newline?
208 bool font_char; // character exists in font?
209 char ch;
210 };
211
212 const char *grtext_GetChar(const char *str, 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 tFontTemplate {
219 uint16_t min_ascii, max_ascii;
220 uint8_t *ch_widths;
221 uint8_t *kern_data;
222 uint8_t ch_height;
223 uint8_t ch_maxwidth; // max width of character in font.
224 bool proportional; // is this font proportional? if so use array of widths, else use maxwidth
225 bool uppercase; // uppercase font?
226 bool monochromatic; // font is monochromatic?
227 bool newstyle; // new style 4444 font.
228 bool ffi2; // new font info added.
229
230 // ffi2 style (font file info 2)
231 int8_t ch_tracking; // global tracking for font.
232 };
233
234 // clears out font buffer.
235 void grfont_Reset();
236
237 // returns a handle to a loaded font.
238 int grfont_Load(const char *fname);
239
240 // frees a loaded font
241 void grfont_Free(int handle);
242
243 // loads a font template
244 bool grfont_LoadTemplate(const char *fname, tFontTemplate *ft);
245
246 // frees a font template
247 void grfont_FreeTemplate(tFontTemplate *ft);
248
249 // returns a character's width
250 int grfont_GetCharWidth(int font, int ch);
251
252 // returns a font's height
253 int grfont_GetHeight(int font);
254
255 // returns a character's width
256 int grfont_GetKernedSpacing(int font, int ch1, int ch2);
257
258 // returns a character's width
259 int grfont_GetKernedSpacingTemp(const 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_KeyToAscii(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_t *grfont_GetRawCharacterData(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_SetTemplate(const char *pathname, const tFontTemplate *ft);
275
276 // sets a font's template without saving...
277 bool grfont_SetKerning(int font, uint8_t *kern_data);
278
279 // sets a font's tracking
280 bool grfont_SetTracking(int font, int tracking);
281 int grfont_GetTracking(int font);
282
283 /////////////////////////////////////////////////////////////////////
284
285 // Init functions -- call before anything is rendered!
286 void grtext_Init();
287
288 #ifndef RELEASE
289 void grfont_Spew(int font, int x, int y);
290 #endif
291
292 struct tFontFileInfo2 // to maintain compatibility with older fonts (64 bytes long)
293 {
294 int16_t tracking;
295 char reserved[62];
296 };
297
298 // font data structure internal to library but available for font editors
299 struct tFontFileInfo {
300 int16_t width, height; // width of widest character and height of longest char
301 int16_t flags; // flags used by the character renderer
302 int16_t baseline; // pixels given to lowercase below script line start at baseline
303 uint8_t min_ascii; // minimum ascii value used by font
304 uint8_t max_ascii; // max ascii value used by the font
305 int16_t byte_width; // width of a character in the font in bytes
306 uint8_t *raw_data; // pixel, map data.
307 uint8_t **char_data; // pointers to each character
308 uint8_t *char_widths; // individual pixel widths of each character
309 uint8_t *kern_data; // kerning information for specific letter combos
310
311 // FFI2 (newstyle) data
312 tFontFileInfo2 ffi2;
313
314 // misc.
315 float brightness; // this IS NOT in the file, but a part of the baseline element. (upper 8bits)
316 };
317
318 #define FT_COLOR 1
319 #define FT_PROPORTIONAL 2
320 #define FT_KERNED 4
321 #define FT_GRADIENT 8
322 #define FT_FMT4444 16
323 #define FT_FFI2 32 // all fonts made after D3 should have this flag set.
324
325 #endif