comparison tools/fontconv.c @ 2586:9807ae37ad69

Require stdbool.h, we require C11 now.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 08 Dec 2022 15:59:22 +0200
parents 92b93a12c014
children ad18774054e3
comparison
equal deleted inserted replaced
2585:ef6c826c5b7a 2586:9807ae37ad69
50 "files, render TrueType TTF to DMFONT at desired glyph resolution, or\n" 50 "files, render TrueType TTF to DMFONT at desired glyph resolution, or\n"
51 "cut a PNG (or JPEG) image to glyphs of desired size.\n"); 51 "cut a PNG (or JPEG) image to glyphs of desired size.\n");
52 } 52 }
53 53
54 54
55 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) 55 bool argHandleOpt(const int optN, char *optArg, char *currArg)
56 { 56 {
57 switch (optN) 57 switch (optN)
58 { 58 {
59 case 0: 59 case 0:
60 argShowHelp(); 60 argShowHelp();
83 { 83 {
84 dmErrorMsg("Invalid font width or height value ('%s')\n", 84 dmErrorMsg("Invalid font width or height value ('%s')\n",
85 optArg); 85 optArg);
86 86
87 dmFree(tmpStr); 87 dmFree(tmpStr);
88 return FALSE; 88 return false;
89 } 89 }
90 90
91 dmFree(tmpStr); 91 dmFree(tmpStr);
92 } 92 }
93 else 93 else
95 if (!dmGetIntVal(optArg, &fontW, NULL)) 95 if (!dmGetIntVal(optArg, &fontW, NULL))
96 { 96 {
97 dmErrorMsg("Invalid font size value ('%s')\n", 97 dmErrorMsg("Invalid font size value ('%s')\n",
98 optArg); 98 optArg);
99 99
100 return FALSE; 100 return false;
101 } 101 }
102 fontH = fontW; 102 fontH = fontW;
103 } 103 }
104 104
105 if (fontW < DMFONT_MIN_WIDTH || fontW > DMFONT_MAX_WIDTH || 105 if (fontW < DMFONT_MIN_WIDTH || fontW > DMFONT_MAX_WIDTH ||
106 fontH < DMFONT_MIN_HEIGHT || fontH > DMFONT_MAX_HEIGHT) 106 fontH < DMFONT_MIN_HEIGHT || fontH > DMFONT_MAX_HEIGHT)
107 { 107 {
108 dmErrorMsg("Invalid font dimensions, must be %d < W %d, %d < H < %d.\n", 108 dmErrorMsg("Invalid font dimensions, must be %d < W %d, %d < H < %d.\n",
109 DMFONT_MIN_WIDTH , DMFONT_MAX_WIDTH, 109 DMFONT_MIN_WIDTH , DMFONT_MAX_WIDTH,
110 DMFONT_MIN_HEIGHT , DMFONT_MAX_HEIGHT); 110 DMFONT_MIN_HEIGHT , DMFONT_MAX_HEIGHT);
111 return FALSE; 111 return false;
112 } 112 }
113 optSplitWidth = fontW; 113 optSplitWidth = fontW;
114 optSplitHeight = fontH; 114 optSplitHeight = fontH;
115 } 115 }
116 break; 116 break;
125 if (sscanf(optArg, "%02x%02x%02x", &colR, &colG, &colB) != 3 && 125 if (sscanf(optArg, "%02x%02x%02x", &colR, &colG, &colB) != 3 &&
126 sscanf(optArg, "%02x%02x%02x%02x", &colR, &colG, &colB, &colA) != 4) 126 sscanf(optArg, "%02x%02x%02x%02x", &colR, &colG, &colB, &colA) != 4)
127 { 127 {
128 dmErrorMsg("Invalid RGB hex representation '%s'.\n", 128 dmErrorMsg("Invalid RGB hex representation '%s'.\n",
129 optArg); 129 optArg);
130 return FALSE; 130 return false;
131 } 131 }
132 132
133 optColor.r = colR; 133 optColor.r = colR;
134 optColor.g = colG; 134 optColor.g = colG;
135 optColor.b = colB; 135 optColor.b = colB;
140 case 14: 140 case 14:
141 if (sscanf(optArg, "%d", &optBPP) != 1) 141 if (sscanf(optArg, "%d", &optBPP) != 1)
142 { 142 {
143 dmErrorMsg("Invalid argument for -b option, '%s'.\n", 143 dmErrorMsg("Invalid argument for -b option, '%s'.\n",
144 optArg); 144 optArg);
145 return FALSE; 145 return false;
146 } 146 }
147 if (optBPP != 8 && optBPP != 32) 147 if (optBPP != 8 && optBPP != 32)
148 { 148 {
149 dmErrorMsg("Invalid bit depth %d, must be 8 or 32.\n", 149 dmErrorMsg("Invalid bit depth %d, must be 8 or 32.\n",
150 optBPP); 150 optBPP);
151 return FALSE; 151 return false;
152 } 152 }
153 break; 153 break;
154 154
155 default: 155 default:
156 dmErrorMsg("Unimplemented option argument '%s'.\n", currArg); 156 dmErrorMsg("Unimplemented option argument '%s'.\n", currArg);
157 return FALSE; 157 return false;
158 } 158 }
159 159
160 return TRUE; 160 return true;
161 } 161 }
162 162
163 163
164 BOOL argHandleFile(char *currArg) 164 bool argHandleFile(char *currArg)
165 { 165 {
166 if (optInFilename == NULL) 166 if (optInFilename == NULL)
167 optInFilename = currArg; 167 optInFilename = currArg;
168 else 168 else
169 if (optOutFilename == NULL) 169 if (optOutFilename == NULL)
170 optOutFilename = currArg; 170 optOutFilename = currArg;
171 else 171 else
172 { 172 {
173 dmErrorMsg("Too many filename arguments, '%s'\n", currArg); 173 dmErrorMsg("Too many filename arguments, '%s'\n", currArg);
174 return FALSE; 174 return false;
175 } 175 }
176 176
177 return TRUE; 177 return true;
178 } 178 }
179 179
180 180
181 int dmCreateBitmapFontFromImage(SDL_Surface *image, int width, int height, DMBitmapFont **pfont) 181 int dmCreateBitmapFontFromImage(SDL_Surface *image, int width, int height, DMBitmapFont **pfont)
182 { 182 {
284 DMResource *inFile = NULL, *outFile = NULL; 284 DMResource *inFile = NULL, *outFile = NULL;
285 DMBitmapFont *font = NULL; 285 DMBitmapFont *font = NULL;
286 SDL_Surface *fontbmap = NULL; 286 SDL_Surface *fontbmap = NULL;
287 int res = DMERR_OK; 287 int res = DMERR_OK;
288 #ifdef DM_GFX_TTF_TEXT 288 #ifdef DM_GFX_TTF_TEXT
289 BOOL initTTF = FALSE; 289 bool initTTF = false;
290 TTF_Font *ttf = NULL; 290 TTF_Font *ttf = NULL;
291 #endif 291 #endif
292 292
293 dmInitProg("fontconv", "Bitmap font converter", "0.4", NULL, NULL); 293 dmInitProg("fontconv", "Bitmap font converter", "0.4", NULL, NULL);
294 294
310 if (TTF_Init() < 0) 310 if (TTF_Init() < 0)
311 { 311 {
312 dmErrorMsg("Could not initialize FreeType/TTF: %s\n", SDL_GetError()); 312 dmErrorMsg("Could not initialize FreeType/TTF: %s\n", SDL_GetError());
313 goto out; 313 goto out;
314 } 314 }
315 initTTF = TRUE; 315 initTTF = true;
316 #endif 316 #endif
317 317
318 // Open the source file 318 // Open the source file
319 if ((res = dmf_open_stdio(optInFilename, "rb", &inFile)) != DMERR_OK) 319 if ((res = dmf_open_stdio(optInFilename, "rb", &inFile)) != DMERR_OK)
320 { 320 {