1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
23 #ifndef TEXT_GP_FONT_H
24 #define TEXT_GP_FONT_H
28 #define GP_FONT_NAME_MAX 64
31 * Data describing single Glyph.
33 * Note that glyph do not necessarily correspond to one character (for example
34 * ligature is a glyph but corresponds to at least two characters).
36 * The glyphs are rendered to horizontal baseline, vertical rendering is not
39 * The structure could contain glyphs of different BPP and information about
40 * the bitmap format is stored in the font structure. The bitmap lines are byte
43 typedef struct GP_GlyphBitmap
{
45 * Bitmap width in pixels.
50 * Bitmap heigth in pixels.
55 * X offset to be applied before we start drawing.
60 * Y offset from baseline to the top of the bitmap.
65 * Offset to be applied after drawing, defines
66 * basepoint for next glyph.
71 * Character bitmap, byte aligned bitmap.
76 typedef enum GP_CharSet
{
81 * Glyph bitmap data format.
83 * The bitmap is byte aligned and for 1BPP the number of bytes per row is
87 typedef enum GP_FontBitmapFormat
{
90 } GP_FontBitmapFormat
;
95 typedef struct GP_FontFace
{
97 * Font family name - eg. Sans, Serif ...
99 char family_name
[GP_FONT_NAME_MAX
];
102 * Font style name - Medium, Bold, Italic ...
104 char style_name
[GP_FONT_NAME_MAX
];
107 * Enum for supported charsets.
112 * Maximal height of font glyph from baseline to the top.
117 * Maximal length of font glyph from baseline to the bottom.
122 * Maximal width of font glyph.
124 * (basically max from glyph->width + glyph->bearing_x)
126 uint16_t max_glyph_width
;
129 * Maximal glyph advance.
131 uint16_t max_glyph_advance
;
134 * Bitmap format for all glyphs
136 GP_FontBitmapFormat glyph_bitmap_format
;
139 * Pointer to glyph bitmap buffer.
144 * Offsets to the glyph data.
146 * If glyph_offset[0] == 0, the table glyph_offsets holds offsets for
147 * all characters in glyphs, the last offset i.e. offsets[len] holds
148 * the size of glyphs array.
150 * If glyph_offset[0] != 0 the glyph_offset[0] defines step in the
153 uint32_t glyph_offsets
[];
157 * Returns font height eg. ascend + descend
159 static inline unsigned int GP_FontHeight(const GP_FontFace
*font
)
161 return font
->ascend
+ font
->descend
;
164 static inline unsigned int GP_FontAscend(const GP_FontFace
*font
)
169 static inline unsigned int GP_FontDescend(const GP_FontFace
*font
)
171 return font
->descend
;
174 static inline unsigned int GP_FontMaxWidth(const GP_FontFace
*font
)
176 return font
->max_glyph_width
;
179 static inline unsigned int GP_FontMaxAdvanceX(const GP_FontFace
*font
)
181 return font
->max_glyph_advance
;
184 static inline const char *GP_FontFamily(const GP_FontFace
*font
)
186 return font
->family_name
;
189 static inline const char *GP_FontStyle(const GP_FontFace
*font
)
191 return font
->style_name
;
195 * Returns glyph count for charset.
197 uint32_t GP_GetGlyphCount(GP_CharSet charset
);
200 * Returns glyph mapping
202 GP_GlyphBitmap
*GP_GetGlyphBitmap(const GP_FontFace
*font
, int c
);
205 * Loads font face from file.
207 GP_FontFace
*GP_FontFaceLoad(const char *path
, uint32_t width
, uint32_t height
);
210 * Free the font face memory.
212 void GP_FontFaceFree(GP_FontFace
*self
);
214 #endif /* TEXT_GP_FONT_H */