annotate dmtext_bm.c @ 70:a791146e3094

Make BM text work, a bit at least.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 01 Oct 2012 13:42:47 +0300
parents f18ad054a695
children 295d08376744
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"
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
8
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
9
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
10 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
11 {
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
12 const char *ptr = fmt;
66
f18ad054a695 Oops, some function arguments were reversed.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
13 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
14
60
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
15 while (*ptr)
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
16 {
70
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
17 SDL_Surface *glyph;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
18 int pos;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
19 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
20
70
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
21 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
22 {
70
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
23 xc += 15;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
24 continue;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
25 }
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
26 else
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
27 if (ch >= 'A' && ch <= 'Z')
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
28 pos = ch - 'A' + 256 + 1;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
29 else
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
30 if (ch >= 'a' && ch <= 'z')
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
31 pos = ch - 'a' + 1;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
32 else
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
33 if (ch >= '0' && ch <= '9')
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
34 pos = ch - '0' + 48;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
35 else
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
36 pos = ch;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
37
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
38 if (pos >= 0 && pos < font->nglyphs)
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
39 {
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
40 glyph = font->glyphs[pos];
63
3d9da937db69 More work on the text support.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
41 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
42 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
43 }
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
44 else
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
45 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
46 }
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 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
51 {
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
52 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
53 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
54 {
63
3d9da937db69 More work on the text support.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
55 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
56 dmFree(tmp);
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
57 }
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 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
62 {
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
63 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
64
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
65 va_start(ap, fmt);
63
3d9da937db69 More work on the text support.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
66 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
67 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
68 }
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
69
65
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
70
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
71 DMBitmapFont *dmNewBitmapFont(int nglyphs)
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
72 {
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
73 DMBitmapFont *font = dmMalloc0(sizeof(DMBitmapFont));
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
74 if (font == NULL)
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
75 return NULL;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
76
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
77 font->nglyphs = nglyphs;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
78 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
79
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
80 return font;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
81 }
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
82
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 int dmFreeBitmapFont(DMBitmapFont *font)
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
85 {
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
86 int i;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
87
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
88 if (font == NULL)
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
89 return DMERR_NULLPTR;
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 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
92 {
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
93 if (font->glyphs[i] != NULL)
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
94 {
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
95 SDL_FreeSurface(font->glyphs[i]);
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
96 font->glyphs[i] = NULL;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
97 }
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 dmFree(font);
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
101 return DMERR_OK;
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
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 int dmLoadBitmapFont(DMResource *res, DMBitmapFont **pfont)
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 return DMERR_OK;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
108 }
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
109
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 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
112 {
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
113 int glyph, xc, yc, xglyphs, yglyphs;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
114 DMBitmapFont *font;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
115
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
116 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
117 return DMERR_INVALID_ARGS;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
118
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
119 xglyphs = image->w / width;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
120 yglyphs = image->h / height;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
121
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
122 if ((font = dmNewBitmapFont(xglyphs * yglyphs)) == NULL)
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
123 return DMERR_MALLOC;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
124
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
125 font->width = width;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
126 font->height = height;
70
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
127
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
128 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
129 image->w, image->h,
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
130 width, height,
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
131 xglyphs, yglyphs, xglyphs * yglyphs);
65
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
132
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
133 glyph = 0;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
134 for (yc = 0; yc < yglyphs; yc++)
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
135 for (xc = 0; xc < xglyphs; xc++)
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
136 {
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
137 SDL_Surface *bmp = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
138 image->format->BitsPerPixel,
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
139 image->format->Rmask,
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
140 image->format->Gmask,
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
141 image->format->Bmask,
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
142 image->format->Amask);
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
143
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
144 if (bmp == NULL)
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
145 {
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
146 dmFreeBitmapFont(font);
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
147 return DMERR_MALLOC;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
148 }
70
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
149
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
150 SDL_Rect r;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
151 r.x = xc * width;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
152 r.y = yc * height;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
153 r.w = width;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
154 r.h = height;
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
155
a791146e3094 Make BM text work, a bit at least.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
156 SDL_BlitSurface(image, &r, bmp, NULL);
65
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 font->glyphs[glyph++] = bmp;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
159 }
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
160
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
161 *pfont = font;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
162 return DMERR_OK;
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
163 }