Mercurial > hg > dmlib
comparison tools/fontconv.c @ 1235:5b8245e5f785
Remove trailing whitespace.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 06 Mar 2015 13:40:47 +0200 |
parents | 2b48b7fe95bc |
children | acae5f8ebc67 |
comparison
equal
deleted
inserted
replaced
1234:beae399c6473 | 1235:5b8245e5f785 |
---|---|
93 { | 93 { |
94 dmErrorMsg("Invalid RGB hex representation '%s'.\n", | 94 dmErrorMsg("Invalid RGB hex representation '%s'.\n", |
95 optArg); | 95 optArg); |
96 return FALSE; | 96 return FALSE; |
97 } | 97 } |
98 | 98 |
99 optColor.r = colR; | 99 optColor.r = colR; |
100 optColor.g = colG; | 100 optColor.g = colG; |
101 optColor.b = colB; | 101 optColor.b = colB; |
102 optColor.unused = colA; | 102 optColor.unused = colA; |
103 } | 103 } |
105 | 105 |
106 default: | 106 default: |
107 dmErrorMsg("Unknown argument '%s'.\n", currArg); | 107 dmErrorMsg("Unknown argument '%s'.\n", currArg); |
108 return FALSE; | 108 return FALSE; |
109 } | 109 } |
110 | 110 |
111 return TRUE; | 111 return TRUE; |
112 } | 112 } |
113 | 113 |
114 | 114 |
115 BOOL argHandleFile(char *currArg) | 115 BOOL argHandleFile(char *currArg) |
122 else | 122 else |
123 { | 123 { |
124 dmErrorMsg("Too many filename arguments, '%s'\n", currArg); | 124 dmErrorMsg("Too many filename arguments, '%s'\n", currArg); |
125 return FALSE; | 125 return FALSE; |
126 } | 126 } |
127 | 127 |
128 return TRUE; | 128 return TRUE; |
129 } | 129 } |
130 | 130 |
131 | 131 |
132 int dmCreateBitmapFontFromImage(SDL_Surface *image, int width, int height, DMBitmapFont **pfont) | 132 int dmCreateBitmapFontFromImage(SDL_Surface *image, int width, int height, DMBitmapFont **pfont) |
134 int nglyph, xc, yc, xglyphs, yglyphs; | 134 int nglyph, xc, yc, xglyphs, yglyphs; |
135 DMBitmapFont *font; | 135 DMBitmapFont *font; |
136 | 136 |
137 if (image->w < width || width < 2 || image->h < height || height < 2) | 137 if (image->w < width || width < 2 || image->h < height || height < 2) |
138 return DMERR_INVALID_ARGS; | 138 return DMERR_INVALID_ARGS; |
139 | 139 |
140 xglyphs = image->w / width; | 140 xglyphs = image->w / width; |
141 yglyphs = image->h / height; | 141 yglyphs = image->h / height; |
142 | 142 |
143 if ((font = dmNewBitmapFont(xglyphs * yglyphs, width, height)) == NULL) | 143 if ((font = dmNewBitmapFont(xglyphs * yglyphs, width, height)) == NULL) |
144 return DMERR_MALLOC; | 144 return DMERR_MALLOC; |
145 | 145 |
146 dmMsg(1, "%d x %d split as %d x %d blocks => %d x %d = %d glyphs.\n", | 146 dmMsg(1, "%d x %d split as %d x %d blocks => %d x %d = %d glyphs.\n", |
147 image->w, image->h, | 147 image->w, image->h, |
148 width, height, | 148 width, height, |
149 xglyphs, yglyphs, xglyphs * yglyphs); | 149 xglyphs, yglyphs, xglyphs * yglyphs); |
150 | 150 |
151 nglyph = 0; | 151 nglyph = 0; |
152 for (yc = 0; yc < yglyphs; yc++) | 152 for (yc = 0; yc < yglyphs; yc++) |
153 for (xc = 0; xc < xglyphs; xc++) | 153 for (xc = 0; xc < xglyphs; xc++) |
154 { | 154 { |
155 SDL_Surface *glyph = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, | 155 SDL_Surface *glyph = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, |
156 image->format->BitsPerPixel, | 156 image->format->BitsPerPixel, |
157 image->format->Rmask, | 157 image->format->Rmask, |
158 image->format->Gmask, | 158 image->format->Gmask, |
159 image->format->Bmask, | 159 image->format->Bmask, |
160 image->format->Amask); | 160 image->format->Amask); |
161 | 161 |
162 if (glyph == NULL) | 162 if (glyph == NULL) |
163 { | 163 { |
164 dmFreeBitmapFont(font); | 164 dmFreeBitmapFont(font); |
165 return DMERR_MALLOC; | 165 return DMERR_MALLOC; |
166 } | 166 } |
168 SDL_Rect r; | 168 SDL_Rect r; |
169 r.x = xc * width; | 169 r.x = xc * width; |
170 r.y = yc * height; | 170 r.y = yc * height; |
171 r.w = width; | 171 r.w = width; |
172 r.h = height; | 172 r.h = height; |
173 | 173 |
174 SDL_BlitSurface(image, &r, glyph, NULL); | 174 SDL_BlitSurface(image, &r, glyph, NULL); |
175 | 175 |
176 font->glyphs[nglyph++] = glyph; | 176 font->glyphs[nglyph++] = glyph; |
177 } | 177 } |
178 | 178 |
179 *pfont = font; | 179 *pfont = font; |
180 return DMERR_OK; | 180 return DMERR_OK; |
181 } | 181 } |
182 | 182 |
183 | 183 |
297 dmErrorMsg("Could not initialize FreeType/TTF: %s\n", SDL_GetError()); | 297 dmErrorMsg("Could not initialize FreeType/TTF: %s\n", SDL_GetError()); |
298 goto error_exit; | 298 goto error_exit; |
299 } | 299 } |
300 initTTF = TRUE; | 300 initTTF = TRUE; |
301 #endif | 301 #endif |
302 | 302 |
303 // Open the source file | 303 // Open the source file |
304 if ((res = dmf_create_stdio(optInFilename, "rb", &inFile)) != DMERR_OK) | 304 if ((res = dmf_create_stdio(optInFilename, "rb", &inFile)) != DMERR_OK) |
305 { | 305 { |
306 dmErrorMsg("Error opening input file '%s', %d: %s\n", | 306 dmErrorMsg("Error opening input file '%s', %d: %s\n", |
307 optInFilename, res, dmErrorStr(res)); | 307 optInFilename, res, dmErrorStr(res)); |
320 int i; | 320 int i; |
321 dmMsg(1, "Input is a TTF TrueType font, rendering at %d x %d.\n", | 321 dmMsg(1, "Input is a TTF TrueType font, rendering at %d x %d.\n", |
322 optSplitWidth, optSplitHeight); | 322 optSplitWidth, optSplitHeight); |
323 | 323 |
324 TTF_SetFontStyle(ttf, TTF_STYLE_NORMAL); | 324 TTF_SetFontStyle(ttf, TTF_STYLE_NORMAL); |
325 | 325 |
326 if ((font = dmNewBitmapFont(256, optSplitWidth - 1, optSplitHeight+4)) == NULL) | 326 if ((font = dmNewBitmapFont(256, optSplitWidth - 1, optSplitHeight+4)) == NULL) |
327 { | 327 { |
328 goto error_exit; | 328 goto error_exit; |
329 } | 329 } |
330 | 330 |
362 if (font == NULL) | 362 if (font == NULL) |
363 { | 363 { |
364 dmErrorMsg("No font loaded.\n"); | 364 dmErrorMsg("No font loaded.\n"); |
365 goto error_exit; | 365 goto error_exit; |
366 } | 366 } |
367 | 367 |
368 dmMsg(1, "Outputting a DMFONT format bitmap font.\n"); | 368 dmMsg(1, "Outputting a DMFONT format bitmap font.\n"); |
369 | 369 |
370 if ((res = dmf_create_stdio(optOutFilename, "wb", &outFile)) != DMERR_OK) | 370 if ((res = dmf_create_stdio(optOutFilename, "wb", &outFile)) != DMERR_OK) |
371 { | 371 { |
372 dmErrorMsg("Error creating file '%s', %d: %s\n", | 372 dmErrorMsg("Error creating file '%s', %d: %s\n", |
387 | 387 |
388 #ifdef DM_GFX_TTF_TEXT | 388 #ifdef DM_GFX_TTF_TEXT |
389 if (initTTF) | 389 if (initTTF) |
390 TTF_Quit(); | 390 TTF_Quit(); |
391 #endif | 391 #endif |
392 | 392 |
393 dmf_close(inFile); | 393 dmf_close(inFile); |
394 dmFreeBitmapFont(font); | 394 dmFreeBitmapFont(font); |
395 SDL_FreeSurface(fontbmap); | 395 SDL_FreeSurface(fontbmap); |
396 | 396 |
397 return 0; | 397 return 0; |
398 } | 398 } |