Mercurial > hg > dmlib
annotate src/dmtext.h @ 2383:43e39d9ec42f
Add __attribute__(__format__ ..) specifiers for functions that use printf() style format specifiers.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 09 Jan 2020 14:55:41 +0200 |
parents | 1edf494226c6 |
children | 5ffc48a0bebe |
rev | line source |
---|---|
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * DMLib |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * -- Bitmap font support |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
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:
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:
diff
changeset
|
6 */ |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 #ifndef DMFONT_H |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 #define DMFONT_H |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #include "dmlib.h" |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 #include "dmres.h" |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 #ifdef DM_GFX_TTF_TEXT |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 #include <SDL_ttf.h> |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 #endif |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 #ifdef __cplusplus |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 extern "C" { |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 #endif |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 /* Bitmapped fonts and text |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 */ |
63
3d9da937db69
More work on the text support.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
23 #ifdef DM_GFX_BM_TEXT |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
24 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
25 // DMFONT format constants |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
26 #define DMFONT_MAGIC "DMFONT" |
1957
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
27 #define DMFONT_VERSION 0x0200 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
28 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
29 #define DMFONT_MIN_WIDTH 3 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
30 #define DMFONT_MIN_HEIGHT 3 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
31 #define DMFONT_MAX_WIDTH 128 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
32 #define DMFONT_MAX_HEIGHT 128 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
33 #define DMFONT_MAX_GLYPHS 1024 |
91
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
34 #define DMFONT_NPALETTE 256 |
e1e308167991
Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
35 |
89
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
36 // Legacy TSFONT loading support |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
37 #define TSFONT_MAGIC "TSFONT" |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
38 #define TSFONT_VERSION 0x0205 |
b10884934aca
Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
39 |
75
e6535609c161
Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
40 |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 typedef struct |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 { |
1957
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
43 int width, height, // Dimensions of this glyph |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
44 index; // Index to surface, value of "maxglyph" means unused |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
45 } DMBitmapGlyph; |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
46 |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
47 |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
48 typedef struct |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
49 { |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
50 int width, height; // Dimensions |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
51 int nglyphs, // How many glyphs worth of data is allocated for the surface |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
52 maxglyph; // Number of character indices, e.g. typically 256 |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
53 size_t gsize; // Size of one glyph in bytes, e.g. glyphs->pitch * font->height |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
54 |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
55 DMBitmapGlyph *glyphMap; |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
56 SDL_Surface *glyphs; // Surface containing glyphs |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 } DMBitmapFont; |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 |
1957
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
60 DMBitmapFont *dmNewBitmapFont(const int nglyphs, const int maxglyph, const int width, const int height, const int bpp); |
65
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
61 int dmFreeBitmapFont(DMBitmapFont *font); |
03375aa0ef2b
Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
62 int dmLoadBitmapFont(DMResource *res, DMBitmapFont **pfont); |
1950 | 63 int dmSetBitmapFontPalette(DMBitmapFont *font, const SDL_Color *pal, const int start, const int size); |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 |
883
1edb93456bcc
Remove unused function declaration.
Matti Hamalainen <ccr@tnsp.org>
parents:
812
diff
changeset
|
65 |
1957
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
66 void dmDrawBMTextConst(SDL_Surface *screen, const DMBitmapFont *font, |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
67 const BOOL condensed, const int mode, int xc, int yc, const char *str); |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
68 void dmDrawBMTextVA(SDL_Surface *screen, const DMBitmapFont *font, |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
69 const BOOL condensed, const int mode, const int xc, const int yc, const char *fmt, va_list ap); |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
70 void dmDrawBMText(SDL_Surface *screen, const DMBitmapFont *font, |
2383
43e39d9ec42f
Add __attribute__(__format__ ..) specifiers for functions that use printf() style format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents:
2104
diff
changeset
|
71 const BOOL condensed, const int mode, const int xc, const int yc, const char *fmt, ...) |
43e39d9ec42f
Add __attribute__(__format__ ..) specifiers for functions that use printf() style format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents:
2104
diff
changeset
|
72 __attribute__ ((__format__ (__printf__, 7, 8))); |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
73 |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
74 |
1957
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
75 static inline void dmInitializeGetBMGlyphSurface(SDL_Surface *surf, DMBitmapFont *font) |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
76 { |
1957
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
77 memcpy(surf, font->glyphs, sizeof(SDL_Surface)); |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
78 } |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
79 |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
80 static inline void dmGetBMGlyph(SDL_Surface *surf, DMBitmapFont *font, int ch) |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
81 { |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
82 DMBitmapGlyph *glyph; |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
83 if (ch < 0 || ch >= font->nglyphs || ch == '\n' || ch == '\r') |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
84 ch = 32; |
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
85 |
2104
1edf494226c6
Copy surface attributes in dmGetBMGlyph().
Matti Hamalainen <ccr@tnsp.org>
parents:
1957
diff
changeset
|
86 memcpy(surf, font->glyphs, sizeof(SDL_Surface)); |
1edf494226c6
Copy surface attributes in dmGetBMGlyph().
Matti Hamalainen <ccr@tnsp.org>
parents:
1957
diff
changeset
|
87 |
1957
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
88 glyph = &font->glyphMap[ch]; |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
89 surf->w = glyph->width; |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
90 surf->h = glyph->height; |
ef08af6887b7
Revamp the bitmap font system to use single SDL_Surface for the font
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
91 surf->pixels = font->glyphs->pixels + font->gsize * glyph->index; |
105
d5d27f262227
Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
92 } |
63
3d9da937db69
More work on the text support.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
93 #endif |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 /* TTF text drawing |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 */ |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 #ifdef DM_GFX_TTF_TEXT |
1950 | 99 void dmDrawTTFTextConst(SDL_Surface *screen, TTF_Font *font, SDL_Color col, const int xc, const int yc, const char *fmt); |
100 void dmDrawTTFTextVA(SDL_Surface *screen, TTF_Font *font, SDL_Color col, const int xc, const int yc, const char *fmt, va_list ap); | |
101 void dmDrawTTFText(SDL_Surface *screen, TTF_Font *font, SDL_Color col, const int xc, const int yc, const char *fmt, ...); | |
60
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 #endif |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 #ifdef __cplusplus |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 } |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 #endif |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 |
f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 #endif // DMFONT_H |