annotate tools/fontconv.c @ 1976:5f9e8dd62c70

Use font general width/height for glyphs when generating from TrueType font, at least until I can figure out a working method to use metrics.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 01 Jul 2018 02:35:42 +0300
parents 868e39741d26
children a8a942c25df3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * fontconv - Convert bitmap fonts
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
874
9d874c1c4a58 Cleanups in fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
4 * (C) Copyright 2012-2015 Tecnic Software productions (TNSP)
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include <stdio.h>
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "dmlib.h"
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include "dmargs.h"
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include "dmfile.h"
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #include "dmimage.h"
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #include "dmtext.h"
1881
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
14 #include "dmres.h"
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
579
f87446a81887 Remove C source output mode, it is useless.
Matti Hamalainen <ccr@tnsp.org>
parents: 362
diff changeset
16 char *optInFilename = NULL, *optOutFilename = NULL;
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
579
f87446a81887 Remove C source output mode, it is useless.
Matti Hamalainen <ccr@tnsp.org>
parents: 362
diff changeset
18 int optSplitWidth = 8,
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
19 optSplitHeight = 8,
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
20 optBPP = 32;
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
633
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
22 SDL_Color optColor = { 255, 255, 255, 100 };
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
23
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
25 static const DMOptArg optList[] =
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 {
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 { 0, '?', "help", "Show this help", OPT_NONE },
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
1357
370c40e0847f Remove useless -o option from fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 1272
diff changeset
29 { 2, 's', "size", "Set glyph dimensions (-s W:H) for image->font conversion", OPT_ARGREQ },
1272
acae5f8ebc67 Fix build process.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
30 #ifdef DM_GFX_TTF_TEXT
1357
370c40e0847f Remove useless -o option from fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 1272
diff changeset
31 { 3, 'c', "color", "TTF font rendering color (def: 0xFFFFFF)", OPT_ARGREQ },
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
32 { 4, 'b', "bpp", "Render font in 8 or 32 bits per pixel (default 32)", OPT_ARGREQ },
1272
acae5f8ebc67 Fix build process.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
33 #endif
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 };
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 const int optListN = sizeof(optList) / sizeof(optList[0]);
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 {
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 switch (optN)
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 {
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 case 0:
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 dmPrintBanner(stdout, dmProgName,
645
6dd155bbfc5c Change semantics of fontconv utility.
Matti Hamalainen <ccr@tnsp.org>
parents: 644
diff changeset
45 "[options] <sourcefile.(ttf|fnt|dmf|png)> <outputfile.dmf>");
646
cc4e6ab6120b Add some help text to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
46
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
47 dmArgsPrintHelp(stdout, optList, optListN, 0);
646
cc4e6ab6120b Add some help text to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
48 printf(
647
afdcd000313c Add linefeed.
Matti Hamalainen <ccr@tnsp.org>
parents: 646
diff changeset
49 "\n"
646
cc4e6ab6120b Add some help text to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
50 "This utility can be used to convert TSFONT files to bitmap DMFONT (DMF)\n"
cc4e6ab6120b Add some help text to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
51 "files, render TrueType TTF to DMFONT at desired glyph resolution, or\n"
cc4e6ab6120b Add some help text to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
52 "cut a PNG (or JPEG) image to glyphs of desired size.\n");
cc4e6ab6120b Add some help text to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
53
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 exit(0);
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 break;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 case 1:
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 dmVerbosity++;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 break;
213
5b1554eb9928 Add option for specifying the output variable name for C source output mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 212
diff changeset
60
648
7303c43bf347 Fix fontconv option handling again.
Matti Hamalainen <ccr@tnsp.org>
parents: 647
diff changeset
61 case 2:
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 {
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 int w, h;
885
ee46d039c45d Change fontconv -s option syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 874
diff changeset
64 if (sscanf(optArg, "%d:%d", &w, &h) != 2)
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
66 dmErrorMsg("Invalid argument for -s option, '%s'.\n",
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 optArg);
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 return FALSE;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 }
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 if (w < DMFONT_MIN_WIDTH || w > DMFONT_MAX_WIDTH ||
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 h < DMFONT_MIN_HEIGHT || h > DMFONT_MAX_HEIGHT)
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
73 dmErrorMsg("Invalid dimensions, must be %d < W %d, %d < H < %d.\n",
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 DMFONT_MIN_WIDTH , DMFONT_MAX_WIDTH,
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 DMFONT_MIN_HEIGHT , DMFONT_MAX_HEIGHT);
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 return FALSE;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 }
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 optSplitWidth = w;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 optSplitHeight = h;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 }
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 break;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
1357
370c40e0847f Remove useless -o option from fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 1272
diff changeset
83 case 3:
633
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
84 {
867
56e12109b936 Portability warning fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
85 unsigned int colR, colG, colB, colA = 100;
633
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
86 if (optArg[0] == '#' || optArg[0] == '$') optArg++;
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
87 else
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
88 if (optArg[0] == '0' && optArg[1] == 'x') optArg += 2;
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
89
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
90 if (sscanf(optArg, "%02x%02x%02x", &colR, &colG, &colB) != 3 &&
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
91 sscanf(optArg, "%02x%02x%02x%02x", &colR, &colG, &colB, &colA) != 4)
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
92 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
93 dmErrorMsg("Invalid RGB hex representation '%s'.\n",
633
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
94 optArg);
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
95 return FALSE;
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
96 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1203
diff changeset
97
633
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
98 optColor.r = colR;
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
99 optColor.g = colG;
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
100 optColor.b = colB;
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1357
diff changeset
101 optColor.a = colA;
633
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
102 }
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
103 break;
151747a24f57 Add color setting option to fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 579
diff changeset
104
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
105 case 4:
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
106 if (sscanf(optArg, "%d", &optBPP) != 1)
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
107 {
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
108 dmErrorMsg("Invalid argument for -b option, '%s'.\n",
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
109 optArg);
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
110 return FALSE;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
111 }
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
112 if (optBPP != 8 && optBPP != 32)
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
113 {
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
114 dmErrorMsg("Invalid bit depth %d, must be 8 or 32.\n",
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
115 optBPP);
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
116 return FALSE;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
117 }
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
118 break;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
119
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
121 dmErrorMsg("Unknown argument '%s'.\n", currArg);
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 return FALSE;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1203
diff changeset
124
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 return TRUE;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 }
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 BOOL argHandleFile(char *currArg)
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 {
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
131 if (optInFilename == NULL)
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 optInFilename = currArg;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 else
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
134 if (optOutFilename == NULL)
645
6dd155bbfc5c Change semantics of fontconv utility.
Matti Hamalainen <ccr@tnsp.org>
parents: 644
diff changeset
135 optOutFilename = currArg;
6dd155bbfc5c Change semantics of fontconv utility.
Matti Hamalainen <ccr@tnsp.org>
parents: 644
diff changeset
136 else
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
138 dmErrorMsg("Too many filename arguments, '%s'\n", currArg);
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 return FALSE;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1203
diff changeset
141
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 return TRUE;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 }
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 int dmCreateBitmapFontFromImage(SDL_Surface *image, int width, int height, DMBitmapFont **pfont)
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 {
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
148 int nglyph, xglyphs, yglyphs;
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 DMBitmapFont *font;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
151 if (image->w < width || width < 2 ||
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
152 image->h < height || height < 2)
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 return DMERR_INVALID_ARGS;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1203
diff changeset
154
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 xglyphs = image->w / width;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 yglyphs = image->h / height;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1203
diff changeset
157
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
158 if ((font = dmNewBitmapFont(
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
159 xglyphs * yglyphs,
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
160 xglyphs * yglyphs,
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
161 width, height, image->format->BitsPerPixel)) == NULL)
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 return DMERR_MALLOC;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
164 dmMsg(1, "%d x %d split as %d x %d blocks => %d x %d = %d glyphs, bpp=%d.\n",
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 image->w, image->h,
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 width, height,
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
167 xglyphs, yglyphs,
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
168 xglyphs * yglyphs, image->format->BitsPerPixel);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1203
diff changeset
169
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 nglyph = 0;
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
171 for (int yc = 0; yc < yglyphs; yc++)
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
172 for (int xc = 0; xc < xglyphs; xc++)
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 {
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
174 DMBitmapGlyph *glyph = &font->glyphMap[nglyph++];
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
175 SDL_Rect src, dst;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1203
diff changeset
176
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
177 src.x = xc * width;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
178 src.y = yc * height;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
179 dst.w = src.w = width;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
180 dst.h = src.h = height;
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
182 dst.x = 0;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
183 dst.y = nglyph * height;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
184 glyph->index = nglyph;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1203
diff changeset
185
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
186 SDL_BlitSurface(image, &src, font->glyphs, &dst);
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1203
diff changeset
188
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 *pfont = font;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 return DMERR_OK;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 }
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
194 int dmSaveBitmapFont(DMResource *fp, DMBitmapFont *font)
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
195 {
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
196 if (font == NULL)
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
197 return DMERR_NULLPTR;
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
198
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
199 if (font->nglyphs > font->maxglyph ||
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
200 font->maxglyph > DMFONT_MAX_GLYPHS ||
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
201 font->width > DMFONT_MAX_WIDTH ||
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
202 font->height > DMFONT_MAX_HEIGHT ||
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
203 font->width < DMFONT_MIN_WIDTH ||
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
204 font->height < DMFONT_MIN_HEIGHT)
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
205 return DMERR_INVALID_DATA;
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
206
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
207 // Write the DMFONT header
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
208 if (!dmf_write_str(fp, (Uint8 *) DMFONT_MAGIC, 6) ||
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
209 !dmf_write_le16(fp, DMFONT_VERSION) ||
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
210 !dmf_write_le16(fp, font->nglyphs) ||
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
211 !dmf_write_le16(fp, font->maxglyph) ||
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
212 !dmf_write_byte(fp, font->width) ||
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
213 !dmf_write_byte(fp, font->height) ||
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
214 !dmf_write_byte(fp, font->glyphs->format->BitsPerPixel))
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
215 return DMERR_FWRITE;
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
216
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
217 // Write the glyph data
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
218 for (int index = 0; index < font->maxglyph; index++)
874
9d874c1c4a58 Cleanups in fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
219 {
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
220 DMBitmapGlyph *glyph = &font->glyphMap[index];
1967
8a98d1517460 Fix glyph index saving .. sigh.
Matti Hamalainen <ccr@tnsp.org>
parents: 1965
diff changeset
221 if (glyph->index >= 0)
874
9d874c1c4a58 Cleanups in fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
222 {
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
223 Uint8 *pixels = font->glyphs->pixels + font->gsize * glyph->index;
874
9d874c1c4a58 Cleanups in fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
224
9d874c1c4a58 Cleanups in fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
225 // Each glyph has its table index and w/h stored
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
226 if (!dmf_write_le16(fp, index) ||
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
227 !dmf_write_byte(fp, glyph->width) ||
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
228 !dmf_write_byte(fp, glyph->height))
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
229 return DMERR_FWRITE;
874
9d874c1c4a58 Cleanups in fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
230
9d874c1c4a58 Cleanups in fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
231 // Write the pixel data
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
232 for (int y = 0; y < glyph->height; y++)
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
233 {
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
234 if (dmfwrite(pixels, font->glyphs->format->BytesPerPixel,
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
235 glyph->width, fp) != (size_t) glyph->width)
874
9d874c1c4a58 Cleanups in fontconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
236 return DMERR_FWRITE;
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
237
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
238 pixels += font->glyphs->pitch;
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
239 }
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
240 }
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
241 }
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
242
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
243 return DMERR_OK;
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
244 }
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
245
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
246
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 int main(int argc, char *argv[])
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 {
209
17d4cc4c3ed1 Add ability to dump a DMFONT as a binary data in a C header file.
Matti Hamalainen <ccr@tnsp.org>
parents: 178
diff changeset
249 DMResource *inFile = NULL, *outFile = NULL;
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 DMBitmapFont *font = NULL;
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
251 SDL_Surface *fontbmap = NULL;
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 int res;
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
253 #ifdef DM_GFX_TTF_TEXT
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
254 BOOL initTTF = FALSE;
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
255 TTF_Font *ttf = NULL;
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
256 #endif
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
258 dmInitProg("fontconv", "Bitmap font converter", "0.4", NULL, NULL);
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 dmVerbosity = 1;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 // Parse arguments
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 if (!dmArgsProcess(argc, argv, optList, optListN,
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
263 argHandleOpt, argHandleFile, OPTH_BAILOUT))
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 exit(1);
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 // Check arguments
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
267 if (optInFilename == NULL || optOutFilename == NULL)
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
269 dmErrorMsg("Input or output file not specified!\n");
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 return 1;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 }
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
272
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
273 #ifdef DM_GFX_TTF_TEXT
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
274 if (TTF_Init() < 0)
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
275 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
276 dmErrorMsg("Could not initialize FreeType/TTF: %s\n", SDL_GetError());
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
277 goto out;
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
278 }
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
279 initTTF = TRUE;
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
280 #endif
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1203
diff changeset
281
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 // Open the source file
1606
93d1050eac99 Rename dmf_create_*() functions to dmf_open_*().
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
283 if ((res = dmf_open_stdio(optInFilename, "rb", &inFile)) != DMERR_OK)
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
285 dmErrorMsg("Error opening input file '%s', %d: %s\n",
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 655
diff changeset
286 optInFilename, res, dmErrorStr(res));
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 return 1;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 }
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
290
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
291 if ((res = dmLoadBitmapFont(inFile, &font)) == DMERR_OK)
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
292 {
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
293 dmMsg(1, "Input is a TSFONT/DMFONT font file, %d x %d, %d glyphs (%d max).\n",
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
294 font->width, font->height, font->nglyphs, font->maxglyph);
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
295 }
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
296 else
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
297 if (res != DMERR_INVALID)
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
298 {
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
299 dmErrorMsg("Input is a TSFONT/DMFONT font file, but there is an error: %s\n",
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
300 dmErrorStr(res));
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
301 goto out;
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
302 }
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
303 #ifdef DM_GFX_TTF_TEXT
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
304 else
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
305 if ((ttf = TTF_OpenFont(optInFilename, optSplitWidth - 1)) != NULL)
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 {
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
307 int gmin = 34, gmax = 127;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
308
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
309 dmMsg(1, "Input is a TTF TrueType font, rendering at %d x %d, %d bpp.\n",
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
310 optSplitWidth, optSplitHeight, optBPP);
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
311
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
312 dmMsg(1, "Rendering glyph range %d to %d inclusive.\n",
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
313 gmin, gmax);
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
314
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
315 TTF_SetFontStyle(ttf, TTF_STYLE_NORMAL);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1203
diff changeset
316
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
317 // Create the bitmap font
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
318 if ((font = dmNewBitmapFont(gmax - gmin + 1, 256,
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
319 optSplitWidth - 6, optSplitHeight + 2, optBPP)) == NULL)
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
320 {
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
321 dmErrorMsg("Could not allocate bitmap font!\n");
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
322 goto out;
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
323 }
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
325 // Render glyphs from the normal ASCII range only
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
326 for (int index = 0, nglyph = gmin; nglyph <= gmax; nglyph++)
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
327 {
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
328 SDL_Surface *tmp;
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
329 char str[2];
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
330 str[0] = nglyph;
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
331 str[1] = 0;
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
332
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
333 // Render the glyph from TTF to surface
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
334 if (optBPP == 8)
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
335 tmp = TTF_RenderText_Solid(ttf, str, optColor);
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
336 else
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
337 tmp = TTF_RenderText_Blended(ttf, str, optColor);
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
338
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
339 if (tmp != NULL)
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
340 {
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
341 DMBitmapGlyph *glyph = &font->glyphMap[nglyph];
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
342 int minx, miny, advance;
1960
b99e04c356ec Some dead code was accidentally left in. Delete it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1957
diff changeset
343 SDL_Rect dst;
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
344
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
345 if (TTF_GlyphMetrics(ttf, nglyph, &minx, NULL, &miny, NULL, &advance) == -1)
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
346 {
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
347 dmErrorMsg("Could not get TTF glyph metrics for character '%c' (%d).\n",
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
348 nglyph, nglyph);
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
349 goto out;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
350 }
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
351
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
352 dst.x = 0;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
353 dst.y = index * font->height;
1976
5f9e8dd62c70 Use font general width/height for glyphs when generating from TrueType font,
Matti Hamalainen <ccr@tnsp.org>
parents: 1968
diff changeset
354 dst.w = font->width;
5f9e8dd62c70 Use font general width/height for glyphs when generating from TrueType font,
Matti Hamalainen <ccr@tnsp.org>
parents: 1968
diff changeset
355 dst.h = font->height;
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
356
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
357 // Set glyph data
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
358 glyph->width = font->width;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
359 glyph->height = font->height;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
360 glyph->index = index;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
361
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
362 SDL_BlitSurface(tmp, NULL, font->glyphs, &dst);
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
363 SDL_FreeSurface(tmp);
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
364 index++;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
365 }
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
366 }
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
367 }
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
368 #endif
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
369 else
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
370 {
1203
2b48b7fe95bc Use dmfreset() instead of dmfseek() to seek to stream start.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
371 dmfreset(inFile);
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 if ((fontbmap = dmLoadImage(inFile)) == NULL)
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
375 dmErrorMsg("Could not load image file '%s'.\n", optInFilename);
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
376 goto out;
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 }
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
379 dmMsg(1, "Input is a bitmap image (%d x %d, %d bpp), splitting to %d x %d.\n",
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
380 fontbmap->w, fontbmap->h, fontbmap->format->BitsPerPixel,
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
381 optSplitWidth, optSplitHeight);
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
382
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 if ((res = dmCreateBitmapFontFromImage(fontbmap, optSplitWidth, optSplitHeight, &font)) != DMERR_OK)
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
385 dmErrorMsg("Could not create a font from image, %d: %s\n",
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 res, dmErrorStr(res));
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
387 goto out;
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 }
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 }
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 if (font == NULL)
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
393 dmErrorMsg("No font loaded.\n");
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
394 goto out;
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1203
diff changeset
396
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
397 // Count number of actually existing glyphs despite that we should have
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
398 // that information in font->nglyphs. Also sanity check the glyphs.
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
399 font->nglyphs = 0;
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
400 for (int n = 0; n < font->maxglyph; n++)
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
401 {
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
402 DMBitmapGlyph *glyph = &font->glyphMap[n];
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
403
1968
868e39741d26 Only check glyphs that will be saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 1967
diff changeset
404 if (glyph->index >= 0)
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
405 {
1968
868e39741d26 Only check glyphs that will be saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 1967
diff changeset
406 font->nglyphs++;
868e39741d26 Only check glyphs that will be saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 1967
diff changeset
407 if (glyph->width < DMFONT_MIN_WIDTH ||
868e39741d26 Only check glyphs that will be saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 1967
diff changeset
408 glyph->height < DMFONT_MIN_HEIGHT ||
868e39741d26 Only check glyphs that will be saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 1967
diff changeset
409 glyph->width > DMFONT_MAX_WIDTH ||
868e39741d26 Only check glyphs that will be saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 1967
diff changeset
410 glyph->height > DMFONT_MAX_HEIGHT ||
868e39741d26 Only check glyphs that will be saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 1967
diff changeset
411 glyph->width > font->width ||
868e39741d26 Only check glyphs that will be saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 1967
diff changeset
412 glyph->height > font->height)
868e39741d26 Only check glyphs that will be saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 1967
diff changeset
413 {
868e39741d26 Only check glyphs that will be saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 1967
diff changeset
414 dmErrorMsg("Invalid glyph #%d: %d x %d (font %d x %d)\n",
868e39741d26 Only check glyphs that will be saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 1967
diff changeset
415 n,
868e39741d26 Only check glyphs that will be saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 1967
diff changeset
416 glyph->width, glyph->height,
868e39741d26 Only check glyphs that will be saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 1967
diff changeset
417 font->width, font->height);
868e39741d26 Only check glyphs that will be saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 1967
diff changeset
418 goto out;
868e39741d26 Only check glyphs that will be saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 1967
diff changeset
419 }
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
420 }
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
421 }
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
422
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
423 dmMsg(1, "Outputting a DMFONT format bitmap font, %d x %d with %d glyphs (%d max), %d bpp.\n",
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
424 font->width, font->height,
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
425 font->nglyphs, font->maxglyph,
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
426 font->glyphs->format->BitsPerPixel);
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427
1606
93d1050eac99 Rename dmf_create_*() functions to dmf_open_*().
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
428 if ((res = dmf_open_stdio(optOutFilename, "wb", &outFile)) != DMERR_OK)
209
17d4cc4c3ed1 Add ability to dump a DMFONT as a binary data in a C header file.
Matti Hamalainen <ccr@tnsp.org>
parents: 178
diff changeset
429 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
430 dmErrorMsg("Error creating file '%s', %d: %s\n",
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 655
diff changeset
431 optInFilename, res, dmErrorStr(res));
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
432 goto out;
209
17d4cc4c3ed1 Add ability to dump a DMFONT as a binary data in a C header file.
Matti Hamalainen <ccr@tnsp.org>
parents: 178
diff changeset
433 }
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434
209
17d4cc4c3ed1 Add ability to dump a DMFONT as a binary data in a C header file.
Matti Hamalainen <ccr@tnsp.org>
parents: 178
diff changeset
435 res = dmSaveBitmapFont(outFile, font);
17d4cc4c3ed1 Add ability to dump a DMFONT as a binary data in a C header file.
Matti Hamalainen <ccr@tnsp.org>
parents: 178
diff changeset
436 dmf_close(outFile);
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 if (res != DMERR_OK)
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 885
diff changeset
440 dmErrorMsg("Error saving font, %d: %s\n",
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 res, dmErrorStr(res));
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 }
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443
1957
ef08af6887b7 Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
444 out:
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
445
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
446 #ifdef DM_GFX_TTF_TEXT
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
447 if (initTTF)
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
448 TTF_Quit();
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
449 #endif
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1203
diff changeset
450
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 dmf_close(inFile);
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 dmFreeBitmapFont(font);
178
63ff0fb944cd Implement TTF to bitmap font conversion (crude).
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
453 SDL_FreeSurface(fontbmap);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1203
diff changeset
454
160
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455 return 0;
67d2cba58a87 Add fontconv tool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 }