loaders: PNG: Handle gamma on 16bpp conversion
[gfxprim.git] / include / text / GP_Font.h
blobe14e6cb12bc6a8ecb57f0fd30f6e74588c4e04fb
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
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. *
8 * *
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. *
13 * *
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 *
18 * *
19 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
23 #ifndef TEXT_GP_FONT_H
24 #define TEXT_GP_FONT_H
26 #include <stdint.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
37 * supported.
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
41 * aligned.
43 typedef struct GP_GlyphBitmap {
45 * Bitmap width in pixels.
47 uint8_t width;
50 * Bitmap heigth in pixels.
52 uint8_t height;
55 * X offset to be applied before we start drawing.
57 int8_t bearing_x;
60 * Y offset from baseline to the top of the bitmap.
62 int8_t bearing_y;
65 * Offset to be applied after drawing, defines
66 * basepoint for next glyph.
68 uint8_t advance_x;
71 * Character bitmap, byte aligned bitmap.
73 uint8_t bitmap[];
74 } GP_GlyphBitmap;
76 typedef enum GP_CharSet {
77 GP_CHARSET_7BIT,
78 } GP_CharSet;
81 * Glyph bitmap data format.
83 * The bitmap is byte aligned and for 1BPP the number of bytes per row is
84 * rounted to bytes.
87 typedef enum GP_FontBitmapFormat {
88 GP_FONT_BITMAP_1BPP,
89 GP_FONT_BITMAP_8BPP,
90 } GP_FontBitmapFormat;
93 * Font face
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.
109 uint8_t charset;
112 * Maximal height of font glyph from baseline to the top.
114 uint16_t ascend;
117 * Maximal length of font glyph from baseline to the bottom.
119 uint16_t descend;
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.
141 void *glyphs;
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
151 * glyph table.
153 uint32_t glyph_offsets[];
154 } GP_FontFace;
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)
166 return font->ascend;
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 */