Mercurial > hg > dmlib
annotate src/dmtext_bm.c @ 875:8aa0d640af74
Cleanup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 04 Feb 2015 17:55:38 +0200 |
parents | 1e5cf1144f36 |
children | 21aeff49d974 |
rev | line source |
---|---|
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1 /* |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
2 * DMLib |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
3 * -- Bitmap and TTF text & font support |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
4 * Programmed and designed by Matti 'ccr' Hamalainen |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
5 * (C) Copyright 2012 Tecnic Software productions (TNSP) |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
6 */ |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
7 #include "dmtext.h" |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
8 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
9 |
634
656332eec724
Add condensed boolean flag to bitmap text rendering functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
200
diff
changeset
|
10 void dmDrawBMTextConst(SDL_Surface *screen, DMBitmapFont *font, BOOL condensed, int mode, int xc, int yc, const char *fmt) |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
11 { |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
12 const char *ptr = fmt; |
129
975725e3126d
Cleanup some prototyping code.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
13 DMUnscaledBlitFunc blit = NULL; |
70
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
14 |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
15 while (*ptr) |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
16 { |
129
975725e3126d
Cleanup some prototyping code.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
17 int ch = *ptr++; |
70
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
18 SDL_Surface *glyph; |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
19 |
129
975725e3126d
Cleanup some prototyping code.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
20 if (ch >= 0 && ch < font->nglyphs && (glyph = font->glyphs[ch]) != NULL) |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
21 { |
129
975725e3126d
Cleanup some prototyping code.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
22 if (blit == NULL) |
975725e3126d
Cleanup some prototyping code.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
23 blit = dmGetUnscaledBlitFunc(glyph->format, screen->format, mode); |
875 | 24 else |
25 { | |
26 blit(glyph, xc, yc, screen); | |
27 xc += condensed ? glyph->w : font->width; | |
28 } | |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
29 } |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
30 else |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
31 xc += font->width; |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
32 } |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
33 } |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
34 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
35 |
634
656332eec724
Add condensed boolean flag to bitmap text rendering functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
200
diff
changeset
|
36 void dmDrawBMTextVA(SDL_Surface *screen, DMBitmapFont *font, BOOL condensed, int mode, int xc, int yc, const char *fmt, va_list ap) |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
37 { |
200
b842cc92c787
No need for dynamic allocation here, I think.
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
38 char tmp[512]; |
b842cc92c787
No need for dynamic allocation here, I think.
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
39 vsnprintf(tmp, sizeof(tmp), fmt, ap); |
634
656332eec724
Add condensed boolean flag to bitmap text rendering functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
200
diff
changeset
|
40 dmDrawBMTextConst(screen, font, condensed, mode, xc, yc, tmp); |
200
b842cc92c787
No need for dynamic allocation here, I think.
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
41 dmFree(tmp); |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
42 } |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
43 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
44 |
634
656332eec724
Add condensed boolean flag to bitmap text rendering functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
200
diff
changeset
|
45 void dmDrawBMText(SDL_Surface *screen, DMBitmapFont *font, BOOL condensed, int mode, int xc, int yc, const char *fmt, ...) |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
46 { |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
47 va_list ap; |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
48 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
49 va_start(ap, fmt); |
634
656332eec724
Add condensed boolean flag to bitmap text rendering functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
200
diff
changeset
|
50 dmDrawBMTextVA(screen, font, condensed, mode, xc, yc, fmt, ap); |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
51 va_end(ap); |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
52 } |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
53 |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
54 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
55 DMBitmapFont *dmNewBitmapFont(int nglyphs, int width, int height) |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
56 { |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
57 DMBitmapFont *font = dmMalloc0(sizeof(DMBitmapFont)); |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
58 if (font == NULL) |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
59 return NULL; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
60 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
61 font->width = width; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
62 font->height = height; |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
63 font->nglyphs = nglyphs; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
64 font->glyphs = dmCalloc(nglyphs, sizeof(SDL_Surface *)); |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
65 if (font->glyphs == NULL) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
66 { |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
67 dmFree(font); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
68 return NULL; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
69 } |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
70 |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
71 return font; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
72 } |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
73 |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
74 |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
75 int dmFreeBitmapFont(DMBitmapFont *font) |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
76 { |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
77 int i; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
78 |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
79 if (font == NULL) |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
80 return DMERR_NULLPTR; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
81 |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
82 for (i = 0; i < font->nglyphs; i++) |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
83 { |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
84 if (font->glyphs[i] != NULL) |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
85 { |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
86 SDL_FreeSurface(font->glyphs[i]); |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
87 font->glyphs[i] = NULL; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
88 } |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
89 } |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
90 |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
91 dmFree(font); |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
92 return DMERR_OK; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
93 } |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
94 |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
95 |
100
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
96 /* Set the palette for each glyph. While the function allows you to |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
97 * specify 'start' and 'end' indices and palette array freely, you should |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
98 * typically use DMFONT_NPALETTE size palette starting at index 0. |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
99 */ |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
100 int dmSetBitmapFontPalette(DMBitmapFont *font, SDL_Color *pal, int start, int size) |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
101 { |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
102 int i; |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
103 |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
104 if (font == NULL) |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
105 return DMERR_NULLPTR; |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
106 |
102 | 107 if (start < 0 || size < 1) |
100
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
108 return DMERR_INVALID_ARGS; |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
109 |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
110 for (i = 0; i < font->nglyphs; i++) |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
111 { |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
112 SDL_Surface *glyph = font->glyphs[i]; |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
113 if (glyph != NULL) |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
114 { |
101 | 115 SDL_SetColors(glyph, pal, start, size); |
100
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
116 } |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
117 } |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
118 |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
119 return DMERR_OK; |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
120 } |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
121 |
162
040e3bbce5ba
Add some extra debugging stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
122 //#define FN_DEBUG |
100
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
123 |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
124 int dmLoadBitmapFont(DMResource *res, DMBitmapFont **pfont) |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
125 { |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
126 DMBitmapFont *font; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
127 char magic[8]; |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
128 Uint16 version, nglyphs, maxglyph; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
129 int width, height; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
130 BOOL tsfont = FALSE; |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
131 |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
132 // Check magic and version |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
133 dmf_read_str(res, (Uint8 *) &magic, 6); |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
134 dmf_read_le16(res, &version); |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
135 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
136 // Check if it is a legacy TSFONT file |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
137 if (memcmp(magic, TSFONT_MAGIC, 6) == 0) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
138 { |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
139 // Yep, we handle these a bit differently |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
140 int encoding = dmfgetc(res); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
141 tsfont = TRUE; |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
142 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
143 if (version > TSFONT_VERSION) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
144 return DMERR_VERSION; |
132
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
145 |
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
146 #ifdef FN_DEBUG |
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
147 fprintf(stderr, "TSFONT v%d.%d (0x%04x), encoding=%d\n", version >> 8, version & 0xff, version, encoding); |
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
148 #endif |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
149 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
150 // There were only two encodings, 0 = none and 1 = RLE |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
151 // of which RLE was never actually used ... derp. |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
152 if (encoding != 0) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
153 return DMERR_NOT_SUPPORTED; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
154 } |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
155 else |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
156 { |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
157 if (memcmp(magic, DMFONT_MAGIC, 6) != 0) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
158 return DMERR_INVALID; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
159 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
160 if (version > DMFONT_VERSION) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
161 return DMERR_VERSION; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
162 } |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
163 |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
164 // Read other header data |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
165 if (tsfont) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
166 { |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
167 // TSFONT only has number of glyphs stored in the file |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
168 nglyphs = dmfgetc(res); |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
169 |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
170 // Maximum glyph number |
104
7160c1d71ade
Few nasty bugs fixed in TSFONT loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
171 maxglyph = 256; |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
172 } |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
173 else |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
174 { |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
175 dmf_read_le16(res, &nglyphs); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
176 dmf_read_le16(res, &maxglyph); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
177 } |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
178 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
179 width = dmfgetc(res); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
180 height = dmfgetc(res); |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
181 |
132
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
182 #ifdef FN_DEBUG |
162
040e3bbce5ba
Add some extra debugging stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
183 fprintf(stderr, "nglyphs=%d (0x%02x), maxglyph=%d (0x%02x) width=%d, height=%d\n", |
040e3bbce5ba
Add some extra debugging stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
184 nglyphs, nglyphs, maxglyph, maxglyph, width, height); |
132
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
185 #endif |
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
186 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
187 if (tsfont) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
188 { |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
189 // TSFONT color assignments (boolean) .. we discard this. |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
190 dmfgetc(res); |
132
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
191 |
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
192 // Very old TSFONTs have some extra data that is not used |
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
193 // .. can't actually even remember what it was for. |
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
194 if (version == 0x0200) |
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
195 { |
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
196 int i; |
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
197 for (i = 0; i < 32; i++) |
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
198 dmfgetc(res); |
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
199 } |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
200 } |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
201 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
202 if (width < DMFONT_MIN_WIDTH || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
203 height < DMFONT_MIN_HEIGHT || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
204 width > DMFONT_MAX_WIDTH || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
205 height > DMFONT_MAX_HEIGHT || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
206 nglyphs > DMFONT_MAX_GLYPHS || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
207 maxglyph > DMFONT_MAX_GLYPHS || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
208 maxglyph < 1) |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
209 return DMERR_INVALID_DATA; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
210 |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
211 // Allocate font |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
212 if ((*pfont = font = dmNewBitmapFont(maxglyph, width, height)) == NULL) |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
213 return DMERR_MALLOC; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
214 |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
215 // Read glyph data, if any |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
216 if (nglyphs > 0) |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
217 { |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
218 int n, i; |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
219 Uint32 BitsPerPixel, Rmask, Gmask, Bmask, Amask; |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
220 SDL_Color pal[DMFONT_NPALETTE]; |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
221 |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
222 // Setup palette for 8bpp fonts |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
223 for (n = 0; n < DMFONT_NPALETTE; n++) |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
224 { |
104
7160c1d71ade
Few nasty bugs fixed in TSFONT loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
225 pal[n].r = pal[n].g = pal[n].b = 0; |
7160c1d71ade
Few nasty bugs fixed in TSFONT loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
226 pal[n].unused = n > 0 ? 255 : 0; |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
227 } |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
228 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
229 if (tsfont) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
230 { |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
231 BitsPerPixel = 8; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
232 Rmask = Gmask = Bmask = Amask = 0; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
233 } |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
234 else |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
235 { |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
236 BitsPerPixel = dmfgetc(res); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
237 dmf_read_le32(res, &Rmask); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
238 dmf_read_le32(res, &Gmask); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
239 dmf_read_le32(res, &Bmask); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
240 dmf_read_le32(res, &Amask); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
241 } |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
242 |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
243 for (i = 0; i < nglyphs; i++) |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
244 { |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
245 int y; |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
246 Uint16 index; |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
247 Uint8 *pixels; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
248 SDL_Surface *glyph; |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
249 |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
250 // TSFONT format has only byte sized index |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
251 if (tsfont) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
252 index = dmfgetc(res); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
253 else |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
254 dmf_read_le16(res, &index); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
255 |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
256 // Read dimensions |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
257 width = dmfgetc(res); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
258 height = dmfgetc(res); |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
259 |
132
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
260 #ifdef FN_DEBUG |
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
261 fprintf(stderr, "#%d @ %d - w=%d, h=%d\n", i, index, width, height); |
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
262 #endif |
b5569c84f00a
Add support for loading ancient version of TSFONTs.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
263 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
264 if (width < DMFONT_MIN_WIDTH || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
265 height < DMFONT_MIN_HEIGHT || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
266 width > DMFONT_MAX_WIDTH || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
267 height > DMFONT_MAX_HEIGHT || |
104
7160c1d71ade
Few nasty bugs fixed in TSFONT loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
268 index >= maxglyph) |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
269 return DMERR_INVALID_DATA; |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
270 |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
271 // Allocate bitmap |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
272 font->glyphs[index] = glyph = SDL_CreateRGBSurface( |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
273 SDL_SWSURFACE, width, height, |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
274 BitsPerPixel, Rmask, Gmask, |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
275 Bmask, |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
276 Amask); |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
277 |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
278 if (glyph == NULL) |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
279 return DMERR_MALLOC; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
280 |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
281 if (BitsPerPixel == 8) |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
282 SDL_SetColors(glyph, pal, 0, DMFONT_NPALETTE); |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
283 |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
284 // Read pixel data |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
285 pixels = glyph->pixels; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
286 for (y = 0; y < glyph->h; y++) |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
287 { |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
288 if (dmfread(pixels, glyph->format->BytesPerPixel, glyph->w, res) != (size_t) glyph->w) |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
289 return DMERR_FREAD; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
290 pixels += glyph->pitch; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
291 } |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
292 } |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
293 } |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
294 |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
295 return DMERR_OK; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
296 } |