openTRI 0.1
triFont.h
1/*
2 * triFont.h: Header for bitmap font library
3 * This file is part of the "tri Engine".
4 *
5 * Copyright (C) 2007 tri
6 * Copyright (C) 2007 David Perry 'InsertWittyName' <tias_dp@hotmail.com>
7 * Copyright (C) 2008, 2010 Alexander Berl 'Raphael' <raphael@fx-world.org>
8 *
9 * $Id:$
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26#ifndef __TRIFONT_H__
27#define __TRIFONT_H__
28
33#ifdef TRI_SUPPORT_FT
34#include <ft2build.h>
35#include FT_FREETYPE_H
36#endif
37
38#include "triTypes.h"
39
40
41enum triFontLocation
42{
43 TRI_FONT_RAM = 0,
44 TRI_FONT_VRAM,
45};
46
52typedef struct Glyph
53{
54 triU16 x;
55 triU16 y;
56 triUChar width;
57 triUChar height;
58 triChar left;
59 triChar top;
60 triChar advance;
61 triUChar unused;
63
67typedef struct
68{
69 triUInt texSize;
70 triUInt texHeight;
71 triUChar *texture;
72 enum triFontLocation location;
73 triUChar map[256];
74 Glyph glyph[256];
75 triSInt fontHeight;
76 triSInt fixedWidth;
77 triSInt fixedHeight;
78 triSInt letterSpacing;
79 triSInt wordSpacing;
80 triFloat justify;
81} triFont;
82
83enum triFontSizeType
84{
85 TRI_FONT_SIZE_PIXELS = 0,
86 TRI_FONT_SIZE_POINTS
87};
88
89enum triFontAlignMode
90{
91 TRI_FONT_ALIGN_LEFT = 0x0,
92 TRI_FONT_ALIGN_CENTER = 0x1,
93 TRI_FONT_ALIGN_RIGHT = 0x2,
94 TRI_FONT_ALIGN_JUSTIFY = 0x3,
95 TRI_FONT_HALIGN = 0xF,
96 TRI_FONT_ALIGN_TOP = 0x00,
97 TRI_FONT_ALIGN_MIDDLE = 0x10,
98 TRI_FONT_ALIGN_BOTTOM = 0x20,
99 TRI_FONT_VALIGN = 0xF0
100};
101
107triBool triFontInit(void);
108
112triVoid triFontShutdown(void);
113
114#ifdef TRI_SUPPORT_FT
125triFont* triFontLoad(const triChar *filename, triUInt fontSize, enum triFontSizeType fontSizeType, triUInt textureSize, enum triFontLocation location);
126#endif
127
133triVoid triFontUnload(triFont *font);
134
142triFont* triFontLoadTRF(const triChar *filename);
143
150triVoid triFontSaveTRF(triFont *font, triChar *filename);
151
158triVoid triFontSetMono( triFont* font, triS32 width );
159
167triVoid triFontSetSpacing( triFont* font, triS32 letter, triS32 word );
168
175triVoid triFontSetLineheight( triFont* font, triS32 height );
176
183
194triSInt triFontPrint(triFloat x, triFloat y, triUInt color, const triChar *text);
195
206triSInt triFontPrintf(triFloat x, triFloat y, triUInt color, const triChar *text, ...);
207
208
222triSInt triFontPrintAlign(triFloat x, triFloat y, triSInt width, triSInt height, triUInt color, enum triFontAlignMode align, const triChar *text);
223
237triSInt triFontPrintAlignf(triFloat x, triFloat y, triSInt width, triSInt height, triUInt color, enum triFontAlignMode align, const triChar *text, ...);
238
246triSInt triFontMeasureTextHeight(const triChar *text);
247
255triSInt triFontMeasureText(const triChar *text);
256
264triSInt triFontMeasureLine(const triChar *text);
265
268#endif // __TRIFONT_H__
triVoid triFontSetMono(triFont *font, triS32 width)
Set a font mono spaced or not (default).
triVoid triFontUnload(triFont *font)
Free the specified font.
triSInt triFontPrintf(triFloat x, triFloat y, triUInt color, const triChar *text,...)
Draw text along the baseline starting at x, y (with formatting).
triVoid triFontSetSpacing(triFont *font, triS32 letter, triS32 word)
Set a spacing values.
triSInt triFontMeasureLine(const triChar *text)
Measure a length of the current line of text if it were to be drawn.
triSInt triFontPrintAlign(triFloat x, triFloat y, triSInt width, triSInt height, triUInt color, enum triFontAlignMode align, const triChar *text)
Draw text along the baseline aligned within the box starting at x, y.
triSInt triFontMeasureTextHeight(const triChar *text)
Measure height of a text if it were to be drawn.
struct Glyph Glyph
A Glyph struct.
triVoid triFontActivate(triFont *font)
Activate the specified font.
triVoid triFontSaveTRF(triFont *font, triChar *filename)
Save the specified font to a triFont file.
triVoid triFontShutdown(void)
Shutdown the Font library.
triSInt triFontPrint(triFloat x, triFloat y, triUInt color, const triChar *text)
Draw text along the baseline starting at x, y.
triVoid triFontSetLineheight(triFont *font, triS32 height)
Set line height.
triSInt triFontMeasureText(const triChar *text)
Measure a length of text if it were to be drawn.
triSInt triFontPrintAlignf(triFloat x, triFloat y, triSInt width, triSInt height, triUInt color, enum triFontAlignMode align, const triChar *text,...)
Draw text along the baseline aligned within the box starting at x, y (with formatting).
triFont * triFontLoadTRF(const triChar *filename)
Load a TRF (triFont) font.
triBool triFontInit(void)
Initialise the Font library.
A Glyph struct.
Definition triFont.h:53
A Font struct.
Definition triFont.h:68
triFloat justify
Justify adjustment for the current line.
Definition triFont.h:80
triSInt wordSpacing
Spacing adjustment for all whitespaces.
Definition triFont.h:79
triSInt fixedWidth
Width for mono spaced output.
Definition triFont.h:76
triUInt texSize
Texture size (power2)
Definition triFont.h:69
triSInt letterSpacing
Spacing adjustment for all characters.
Definition triFont.h:78
triUInt texHeight
Texture height (power2)
Definition triFont.h:70
triSInt fixedHeight
Height for fixed line height.
Definition triFont.h:77
enum triFontLocation location
Either in RAM or VRAM.
Definition triFont.h:72
triUChar * texture
The bitmap data.
Definition triFont.h:71