Mercurial > hg > dmlib
annotate dmtext_bm.c @ 101:8bba97252d85
Oops, 10L.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 02 Oct 2012 20:33:32 +0300 |
parents | f16d102dbbac |
children | 751af3f0e3f2 |
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" |
73
295d08376744
Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
8 #include "dmresw.h" |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
9 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
10 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
11 void dmDrawBMTextConst(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt) |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
12 { |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
13 const char *ptr = fmt; |
66
f18ad054a695
Oops, some function arguments were reversed.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
14 DMScaledBlitFunc blit = dmGetScaledBlitFunc(font->glyphs[0]->format, screen->format, mode); |
70
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
15 |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
16 while (*ptr) |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
17 { |
70
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
18 SDL_Surface *glyph; |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
19 int pos; |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
20 int ch = *ptr++; |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
21 |
76 | 22 if (ch == '_') |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
23 { |
76 | 24 xc += 4; |
70
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
25 continue; |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
26 } |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
27 else |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
28 if (ch >= 'A' && ch <= 'Z') |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
29 pos = ch - 'A' + 256 + 1; |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
30 else |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
31 if (ch >= 'a' && ch <= 'z') |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
32 pos = ch - 'a' + 1; |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
33 else |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
34 if (ch >= '0' && ch <= '9') |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
35 pos = ch - '0' + 48; |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
36 else |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
37 pos = ch; |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
38 |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
39 if (pos >= 0 && pos < font->nglyphs) |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
40 { |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
41 glyph = font->glyphs[pos]; |
63
3d9da937db69
More work on the text support.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
42 blit(glyph, xc, yc, glyph->w, glyph->h, screen); |
3d9da937db69
More work on the text support.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
43 xc += glyph->w; |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
44 } |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
45 else |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
46 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
|
47 } |
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 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
50 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
51 void dmDrawBMTextVA(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, 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
|
52 { |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
53 char *tmp = dm_strdup_vprintf(fmt, ap); |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
54 if (tmp != NULL) |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
55 { |
63
3d9da937db69
More work on the text support.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
56 dmDrawBMTextConst(screen, font, mode, xc, yc, tmp); |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
57 dmFree(tmp); |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
58 } |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
59 } |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
60 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
61 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
62 void dmDrawBMText(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, ...) |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
63 { |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
64 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
|
65 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
66 va_start(ap, fmt); |
63
3d9da937db69
More work on the text support.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
67 dmDrawBMTextVA(screen, font, 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
|
68 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
|
69 } |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
70 |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
71 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
72 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
|
73 { |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
74 DMBitmapFont *font = dmMalloc0(sizeof(DMBitmapFont)); |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
75 if (font == NULL) |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
76 return NULL; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
77 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
78 font->width = width; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
79 font->height = height; |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
80 font->nglyphs = nglyphs; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
81 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
|
82 if (font->glyphs == NULL) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
83 { |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
84 dmFree(font); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
85 return NULL; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
86 } |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
87 |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
88 return font; |
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 |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
92 int dmFreeBitmapFont(DMBitmapFont *font) |
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 int i; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
95 |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
96 if (font == NULL) |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
97 return DMERR_NULLPTR; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
98 |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
99 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
|
100 { |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
101 if (font->glyphs[i] != NULL) |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
102 { |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
103 SDL_FreeSurface(font->glyphs[i]); |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
104 font->glyphs[i] = NULL; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
105 } |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
106 } |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
107 |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
108 dmFree(font); |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
109 return DMERR_OK; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
110 } |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
111 |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
112 |
100
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
113 /* 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
|
114 * 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
|
115 * 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
|
116 */ |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
117 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
|
118 { |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
119 int i; |
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 if (font == NULL) |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
122 return DMERR_NULLPTR; |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
123 |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
124 if (start < 0 || end < start) |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
125 return DMERR_INVALID_ARGS; |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
126 |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
127 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
|
128 { |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
129 SDL_Surface *glyph = font->glyphs[i]; |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
130 if (glyph != NULL) |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
131 { |
101 | 132 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
|
133 } |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
134 } |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
135 |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
136 return DMERR_OK; |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
137 } |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
138 |
f16d102dbbac
Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
139 |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
140 int dmCreateBitmapFontFromImage(SDL_Surface *image, int width, int height, DMBitmapFont **pfont) |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
141 { |
76 | 142 int nglyph, xc, yc, xglyphs, yglyphs; |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
143 DMBitmapFont *font; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
144 |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
145 if (image->w < width || width < 4 || image->h < height || height < 4) |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
146 return DMERR_INVALID_ARGS; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
147 |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
148 xglyphs = image->w / width; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
149 yglyphs = image->h / height; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
150 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
151 if ((font = dmNewBitmapFont(xglyphs * yglyphs, width, height)) == NULL) |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
152 return DMERR_MALLOC; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
153 |
76 | 154 /* |
70
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
155 fprintf(stderr, "%d x %d split as %d x %d blocks => %d x %d = %d glyphs\n", |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
156 image->w, image->h, |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
157 width, height, |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
158 xglyphs, yglyphs, xglyphs * yglyphs); |
76 | 159 */ |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
160 |
76 | 161 nglyph = 0; |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
162 for (yc = 0; yc < yglyphs; yc++) |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
163 for (xc = 0; xc < xglyphs; xc++) |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
164 { |
76 | 165 SDL_Surface *glyph = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
166 image->format->BitsPerPixel, |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
167 image->format->Rmask, |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
168 image->format->Gmask, |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
169 image->format->Bmask, |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
170 image->format->Amask); |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
171 |
76 | 172 if (glyph == NULL) |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
173 { |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
174 dmFreeBitmapFont(font); |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
175 return DMERR_MALLOC; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
176 } |
70
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
177 |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
178 SDL_Rect r; |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
179 r.x = xc * width; |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
180 r.y = yc * height; |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
181 r.w = width; |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
182 r.h = height; |
a791146e3094
Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
183 |
76 | 184 SDL_BlitSurface(image, &r, glyph, NULL); |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
185 |
76 | 186 font->glyphs[nglyph++] = glyph; |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
187 } |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
188 |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
189 *pfont = font; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
190 return DMERR_OK; |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
191 } |
73
295d08376744
Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
192 |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
193 |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
194 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
|
195 { |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
196 DMBitmapFont *font; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
197 char magic[8]; |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
198 Uint16 version, nglyphs, maxglyph; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
199 int width, height; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
200 BOOL tsfont = FALSE; |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
201 |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
202 // Check magic and version |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
203 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
|
204 dmf_read_le16(res, &version); |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
205 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
206 // 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
|
207 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
|
208 { |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
209 // 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
|
210 int encoding = dmfgetc(res); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
211 tsfont = TRUE; |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
212 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
213 if (version > TSFONT_VERSION) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
214 return DMERR_VERSION; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
215 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
216 // 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
|
217 // 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
|
218 if (encoding != 0) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
219 return DMERR_NOT_SUPPORTED; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
220 } |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
221 else |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
222 { |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
223 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
|
224 return DMERR_INVALID; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
225 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
226 if (version > DMFONT_VERSION) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
227 return DMERR_VERSION; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
228 } |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
229 |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
230 // 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
|
231 if (tsfont) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
232 { |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
233 // 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
|
234 nglyphs = dmfgetc(res); |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
235 |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
236 // Maximum glyph number |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
237 maxglyph = 255; |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
238 } |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
239 else |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
240 { |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
241 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
|
242 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
|
243 } |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
244 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
245 width = dmfgetc(res); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
246 height = dmfgetc(res); |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
247 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
248 if (tsfont) |
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 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
|
251 dmfgetc(res); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
252 } |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
253 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
254 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
|
255 height < DMFONT_MIN_HEIGHT || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
256 width > DMFONT_MAX_WIDTH || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
257 height > DMFONT_MAX_HEIGHT || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
258 nglyphs > DMFONT_MAX_GLYPHS || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
259 maxglyph > DMFONT_MAX_GLYPHS || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
260 maxglyph < 1) |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
261 return DMERR_INVALID_DATA; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
262 |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
263 // Allocate font |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
264 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
|
265 return DMERR_MALLOC; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
266 |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
267 // Read glyph data, if any |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
268 if (nglyphs > 0) |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
269 { |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
270 int n, i; |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
271 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
|
272 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
|
273 |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
274 // 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
|
275 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
|
276 { |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
277 pal[n].r = n * 16; |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
278 pal[n].g = n * 16; |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
279 pal[n].b = n * 16; |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
280 pal[n].unused = n > 0 ? n * 16 : 0; |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
281 } |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
282 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
283 if (tsfont) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
284 { |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
285 BitsPerPixel = 8; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
286 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
|
287 } |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
288 else |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
289 { |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
290 BitsPerPixel = dmfgetc(res); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
291 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
|
292 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
|
293 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
|
294 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
|
295 } |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
296 |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
297 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
|
298 { |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
299 int y; |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
300 Uint16 index; |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
301 Uint8 *pixels; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
302 SDL_Surface *glyph; |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
303 |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
304 // 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
|
305 if (tsfont) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
306 index = dmfgetc(res); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
307 else |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
308 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
|
309 |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
310 // Read dimensions |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
311 width = dmfgetc(res); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
312 height = dmfgetc(res); |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
313 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
314 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
|
315 height < DMFONT_MIN_HEIGHT || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
316 width > DMFONT_MAX_WIDTH || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
317 height > DMFONT_MAX_HEIGHT || |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
318 index > maxglyph) |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
319 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
|
320 |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
321 // Allocate bitmap |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
322 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
|
323 SDL_SWSURFACE, width, height, |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
324 BitsPerPixel, Rmask, Gmask, |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
325 Bmask, |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
326 Amask); |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
327 |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
328 if (glyph == NULL) |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
329 return DMERR_MALLOC; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
330 |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
331 if (BitsPerPixel == 8) |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
332 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
|
333 |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
334 // Read pixel data |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
335 pixels = glyph->pixels; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
336 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
|
337 { |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
338 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
|
339 return DMERR_FREAD; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
340 pixels += glyph->pitch; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
341 } |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
342 } |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
343 } |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
344 |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
345 return DMERR_OK; |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
346 } |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
347 |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
348 |
73
295d08376744
Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
349 int dmSaveBitmapFont(DMResource *res, DMBitmapFont *font) |
295d08376744
Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
350 { |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
351 int maxglyph, nglyphs, n; |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
352 if (font == NULL) |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
353 return DMERR_NULLPTR; |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
354 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
355 if (font->nglyphs > DMFONT_MAX_GLYPHS || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
356 font->width > DMFONT_MAX_WIDTH || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
357 font->height > DMFONT_MAX_HEIGHT || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
358 font->width < DMFONT_MIN_WIDTH || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
359 font->height < DMFONT_MIN_HEIGHT) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
360 return DMERR_INVALID_DATA; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
361 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
362 // Count number of actually existing glyphs |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
363 for (maxglyph = nglyphs = n = 0; n < font->nglyphs; n++) |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
364 { |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
365 if (font->glyphs[n] != NULL) |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
366 { |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
367 nglyphs++; |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
368 maxglyph = n; |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
369 } |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
370 } |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
371 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
372 // Write the DMFONT header |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
373 if (!dmf_write_str(res, (Uint8 *) DMFONT_MAGIC, 6)) |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
374 return DMERR_FWRITE; |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
375 |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
376 dmf_write_le16(res, DMFONT_VERSION); |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
377 dmf_write_le16(res, nglyphs); |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
378 dmf_write_le16(res, maxglyph); |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
379 dmfputc(font->width, res); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
380 dmfputc(font->height, res); |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
381 |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
382 if (nglyphs > 0) |
73
295d08376744
Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
383 { |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
384 int i; |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
385 SDL_Surface *glyph = font->glyphs[maxglyph]; |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
386 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
387 // If there are actual glyphs stored, save thi |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
388 dmfputc(glyph->format->BitsPerPixel, res); |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
389 dmf_write_le32(res, glyph->format->Rmask); |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
390 dmf_write_le32(res, glyph->format->Gmask); |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
391 dmf_write_le32(res, glyph->format->Bmask); |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
392 dmf_write_le32(res, glyph->format->Amask); |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
393 |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
394 for (i = 0; i < font->nglyphs; i++) |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
395 { |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
396 glyph = font->glyphs[i]; |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
397 if (glyph != NULL) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
398 { |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
399 int y; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
400 Uint8 *pixels = glyph->pixels; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
401 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
402 if (glyph->w < DMFONT_MIN_WIDTH || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
403 glyph->h < DMFONT_MIN_HEIGHT || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
404 glyph->w > DMFONT_MAX_WIDTH || |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
405 glyph->h > DMFONT_MAX_HEIGHT) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
406 return DMERR_INVALID_DATA; |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
407 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
408 // Each glyph has its table index and w/h stored |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
409 dmf_write_le16(res, i); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
410 dmf_write_le16(res, glyph->w); |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
411 dmf_write_le16(res, glyph->h); |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
412 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
413 // Write the pixel data |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
414 for (y = 0; y < glyph->h; y++) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
415 { |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
416 if (dmfwrite(pixels, glyph->format->BytesPerPixel, glyph->w, res) != (size_t) glyph->w) |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
417 return DMERR_FWRITE; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
418 pixels += glyph->pitch; |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
419 } |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
420 } |
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
421 } |
73
295d08376744
Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
422 } |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
423 |
73
295d08376744
Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
424 return DMERR_OK; |
295d08376744
Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
425 } |