Mercurial > hg > dmlib
view src/dmtext.h @ 2208:90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
lib64util for handling external palette file options and add support for
specifying one of the "internal" palettes or external (.act) palette file to
gfxconv and 64vw.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 14 Jun 2019 05:01:12 +0300 |
parents | 1edf494226c6 |
children | 43e39d9ec42f |
line wrap: on
line source
/* * DMLib * -- Bitmap font support * Programmed and designed by Matti 'ccr' Hamalainen * (C) Copyright 2012 Tecnic Software productions (TNSP) */ #ifndef DMFONT_H #define DMFONT_H #include "dmlib.h" #include "dmres.h" #ifdef DM_GFX_TTF_TEXT #include <SDL_ttf.h> #endif #ifdef __cplusplus extern "C" { #endif /* Bitmapped fonts and text */ #ifdef DM_GFX_BM_TEXT // DMFONT format constants #define DMFONT_MAGIC "DMFONT" #define DMFONT_VERSION 0x0200 #define DMFONT_MIN_WIDTH 3 #define DMFONT_MIN_HEIGHT 3 #define DMFONT_MAX_WIDTH 128 #define DMFONT_MAX_HEIGHT 128 #define DMFONT_MAX_GLYPHS 1024 #define DMFONT_NPALETTE 256 // Legacy TSFONT loading support #define TSFONT_MAGIC "TSFONT" #define TSFONT_VERSION 0x0205 typedef struct { int width, height, // Dimensions of this glyph index; // Index to surface, value of "maxglyph" means unused } DMBitmapGlyph; typedef struct { int width, height; // Dimensions int nglyphs, // How many glyphs worth of data is allocated for the surface maxglyph; // Number of character indices, e.g. typically 256 size_t gsize; // Size of one glyph in bytes, e.g. glyphs->pitch * font->height DMBitmapGlyph *glyphMap; SDL_Surface *glyphs; // Surface containing glyphs } DMBitmapFont; DMBitmapFont *dmNewBitmapFont(const int nglyphs, const int maxglyph, const int width, const int height, const int bpp); int dmFreeBitmapFont(DMBitmapFont *font); int dmLoadBitmapFont(DMResource *res, DMBitmapFont **pfont); int dmSetBitmapFontPalette(DMBitmapFont *font, const SDL_Color *pal, const int start, const int size); void dmDrawBMTextConst(SDL_Surface *screen, const DMBitmapFont *font, const BOOL condensed, const int mode, int xc, int yc, const char *str); void dmDrawBMTextVA(SDL_Surface *screen, const DMBitmapFont *font, const BOOL condensed, const int mode, const int xc, const int yc, const char *fmt, va_list ap); void dmDrawBMText(SDL_Surface *screen, const DMBitmapFont *font, const BOOL condensed, const int mode, const int xc, const int yc, const char *fmt, ...); static inline void dmInitializeGetBMGlyphSurface(SDL_Surface *surf, DMBitmapFont *font) { memcpy(surf, font->glyphs, sizeof(SDL_Surface)); } static inline void dmGetBMGlyph(SDL_Surface *surf, DMBitmapFont *font, int ch) { DMBitmapGlyph *glyph; if (ch < 0 || ch >= font->nglyphs || ch == '\n' || ch == '\r') ch = 32; memcpy(surf, font->glyphs, sizeof(SDL_Surface)); glyph = &font->glyphMap[ch]; surf->w = glyph->width; surf->h = glyph->height; surf->pixels = font->glyphs->pixels + font->gsize * glyph->index; } #endif /* TTF text drawing */ #ifdef DM_GFX_TTF_TEXT void dmDrawTTFTextConst(SDL_Surface *screen, TTF_Font *font, SDL_Color col, const int xc, const int yc, const char *fmt); void dmDrawTTFTextVA(SDL_Surface *screen, TTF_Font *font, SDL_Color col, const int xc, const int yc, const char *fmt, va_list ap); void dmDrawTTFText(SDL_Surface *screen, TTF_Font *font, SDL_Color col, const int xc, const int yc, const char *fmt, ...); #endif #ifdef __cplusplus } #endif #endif // DMFONT_H