annotate dmtext_bm.c @ 76:7d201aed1fd9

Cleanups, cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 02 Oct 2012 05:51:25 +0300
parents e6535609c161
children b10884934aca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
7d201aed1fd9 Cleanups, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
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
7d201aed1fd9 Cleanups, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
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
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
72 DMBitmapFont *dmNewBitmapFont(int nglyphs)
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
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
78 font->nglyphs = nglyphs;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
79 font->glyphs = dmCalloc(nglyphs, sizeof(SDL_Surface *));
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
80
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
81 return font;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
82 }
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
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
85 int dmFreeBitmapFont(DMBitmapFont *font)
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
86 {
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
87 int i;
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 if (font == NULL)
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
90 return DMERR_NULLPTR;
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 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
93 {
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
94 if (font->glyphs[i] != NULL)
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 SDL_FreeSurface(font->glyphs[i]);
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
97 font->glyphs[i] = NULL;
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 }
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 dmFree(font);
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
102 return DMERR_OK;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
103 }
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
104
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 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
107 {
76
7d201aed1fd9 Cleanups, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
108 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
109 DMBitmapFont *font;
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 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
112 return DMERR_INVALID_ARGS;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
113
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
114 xglyphs = image->w / width;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
115 yglyphs = image->h / height;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
116
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
117 if ((font = dmNewBitmapFont(xglyphs * yglyphs)) == NULL)
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
118 return DMERR_MALLOC;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
119
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
120 font->width = width;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
121 font->height = height;
70
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
122
76
7d201aed1fd9 Cleanups, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
123 /*
70
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
124 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
125 image->w, image->h,
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
126 width, height,
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
127 xglyphs, yglyphs, xglyphs * yglyphs);
76
7d201aed1fd9 Cleanups, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
128 */
65
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
129
76
7d201aed1fd9 Cleanups, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
130 nglyph = 0;
65
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
131 for (yc = 0; yc < yglyphs; yc++)
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
132 for (xc = 0; xc < xglyphs; xc++)
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
133 {
76
7d201aed1fd9 Cleanups, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
134 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
135 image->format->BitsPerPixel,
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
136 image->format->Rmask,
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
137 image->format->Gmask,
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
138 image->format->Bmask,
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
139 image->format->Amask);
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
140
76
7d201aed1fd9 Cleanups, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
141 if (glyph == NULL)
65
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
142 {
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
143 dmFreeBitmapFont(font);
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
144 return DMERR_MALLOC;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
145 }
70
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
146
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
147 SDL_Rect r;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
148 r.x = xc * width;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
149 r.y = yc * height;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
150 r.w = width;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
151 r.h = height;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
152
76
7d201aed1fd9 Cleanups, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
153 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
154
76
7d201aed1fd9 Cleanups, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
155 font->glyphs[nglyph++] = glyph;
65
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
156 }
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
157
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
158 *pfont = font;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
159 return DMERR_OK;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
160 }
73
295d08376744 Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
161
75
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
162
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
163 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
164 {
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
165 DMBitmapFont *font;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
166 char magic[8];
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
167 Uint16 version;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
168 Uint32 width, height, nglyphs;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
169
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
170 // Check magic and version
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
171 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
172 dmf_read_le16(res, &version);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
173
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
174 if (memcmp(magic, DMFONT_MAGIC, 6) != 0)
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
175 return DMERR_INVALID;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
176
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
177 if (version != DMFONT_VERSION)
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
178 return DMERR_VERSION;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
179
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
180 // Check other data
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
181 dmf_read_le32(res, &width);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
182 dmf_read_le32(res, &height);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
183 dmf_read_le32(res, &nglyphs);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
184
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
185 if (width > 128 || height > 128 || nglyphs > 1024)
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
186 return DMERR_INVALID_DATA;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
187
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
188 // Allocate font
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
189 if ((*pfont = font = dmNewBitmapFont(nglyphs)) == NULL)
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
190 return DMERR_MALLOC;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
191
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
192 font->width = width;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
193 font->height = height;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
194 font->nglyphs = nglyphs;
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 // Read glyph data, if any
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
197 if (nglyphs > 0)
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
198 {
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
199 Uint32 i, BitsPerPixel, Rmask, Gmask, Bmask, Amask, pitch;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
200
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
201 BitsPerPixel = dmfgetc(res);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
202 dmf_read_le32(res, &Rmask);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
203 dmf_read_le32(res, &Gmask);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
204 dmf_read_le32(res, &Bmask);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
205 dmf_read_le32(res, &Amask);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
206
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
207 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
208 {
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
209 int y;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
210 Uint8 *pixels;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
211 SDL_Surface *glyph;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
212 dmf_read_le32(res, &width);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
213 dmf_read_le32(res, &height);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
214 dmf_read_le32(res, &pitch);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
215
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
216 font->glyphs[i] = glyph = SDL_CreateRGBSurface(
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
217 SDL_SWSURFACE, width, height,
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
218 BitsPerPixel, Rmask, Gmask,
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
219 Bmask,
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
220 Amask);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
221
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
222 if (glyph == NULL)
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
223 return DMERR_MALLOC;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
224
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
225 pixels = glyph->pixels;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
226 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
227 {
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
228 if (dmfread(pixels, glyph->format->BytesPerPixel, glyph->w, res) != glyph->w)
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
229 return DMERR_FREAD;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
230 pixels += glyph->pitch;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
231 }
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
232 }
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
233 }
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
234
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
235 return DMERR_OK;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
236 }
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
237
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
238
73
295d08376744 Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
239 int dmSaveBitmapFont(DMResource *res, DMBitmapFont *font)
295d08376744 Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
240 {
75
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
241 if (font == NULL)
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
242 return DMERR_NULLPTR;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
243
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
244 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
245 return DMERR_FWRITE;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
246
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
247 dmf_write_le16(res, DMFONT_VERSION);
73
295d08376744 Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
248 dmf_write_le32(res, font->width);
295d08376744 Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
249 dmf_write_le32(res, font->height);
295d08376744 Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
250 dmf_write_le32(res, font->nglyphs);
75
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
251
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
252 if (font->nglyphs > 0)
73
295d08376744 Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
253 {
75
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
254 int i;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
255 SDL_Surface *glyph = font->glyphs[0];
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
256
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
257 dmfputc(glyph->format->BitsPerPixel, res);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
258 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
259 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
260 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
261 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
262
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
263 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
264 {
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
265 int y;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
266 glyph = font->glyphs[i];
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
267 Uint8 *pixels = glyph->pixels;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
268
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
269 dmf_write_le32(res, glyph->w);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
270 dmf_write_le32(res, glyph->h);
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
271
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
272 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
273 {
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
274 if (dmfwrite(pixels, glyph->format->BytesPerPixel, glyph->w, res) != glyph->w)
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
275 return DMERR_FWRITE;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
276 pixels += glyph->pitch;
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
277 }
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
278 }
73
295d08376744 Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
279 }
75
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
280
73
295d08376744 Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
281 return DMERR_OK;
295d08376744 Add function for saving a bitmap font.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
282 }