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-2010 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
22 * Copyright (C) 2009-2010 Cyril Hrubis <metan@ucw.cz> *
24 *****************************************************************************/
31 /* The smallest charset, covering only the 7-bit ASCII (0x20 .. 0x7f). */
32 typedef enum GP_Charset
{
36 /* Maximum length of the font name, author, etc. (Note: these values are
37 * used by the on-disc font format.)
39 #define GP_FONT_FAMILY_MAX 63
40 #define GP_FONT_NAME_MAX 63
41 #define GP_FONT_AUTHOR_MAX 63
42 #define GP_FONT_LICENSE_MAX 15
44 /* The current version of the on-disc font format. */
45 #define GP_FONT_FORMAT_VMAJOR 1
46 #define GP_FONT_FORMAT_VMINOR 0
48 /* Magic string starting the on-disc font file. */
49 #define GP_FONT_MAGIC "# gfxprim font file"
52 * Contains font metadata.
54 typedef struct GP_Font
{
56 /* Name of the font family. */
57 char family
[GP_FONT_NAME_MAX
+ 1];
60 char name
[GP_FONT_NAME_MAX
+ 1];
62 /* Name of the font author. */
63 char author
[GP_FONT_AUTHOR_MAX
+ 1];
65 /* Font license (default is "GPL2"). */
66 char license
[GP_FONT_LICENSE_MAX
+ 1];
68 /* Font version (incremented by font author when modifying the font data,
69 * do not confuse with format version).
73 /* The charset specifies which characters are defined by the font. */
77 /* Height of every character in pixels. */
80 /* Height of the baseline (number of pixels from the bottom). */
84 * Number of bytes for each pixel line in the character data
85 * (typically 1/8 of char_width, rounded upwards).
87 uint8_t bytes_per_line
;
89 /* Maximum width of the character bounding box (including empty areas
90 * that are not drawn but cause other characters to shift).
92 uint8_t max_bounding_width
;
95 * Array of GP_CharData structures, packed together sequentially
98 * Characters are stored in encoding order. The first encoded character
99 * is 0x20 (space). A font must, at a minimum, encode all characters
100 * of the 7-bit ASCII set (0x20 .. 0x7F, inclusive).
105 #define GP_CHECK_FONT(font) do { \
106 GP_CHECK(font->data, "invalid font: NULL font data"); \
107 GP_CHECK(font->height > 0, "invalid font: height == 0"); \
108 GP_CHECK(font->baseline <= font->height, "invalid font: baseline exceeds height"); \
109 GP_CHECK(font->bytes_per_line > 0, "invalid font: bytes_per_line == 0"); \
112 /* Data describing a single character. */
113 typedef struct GP_CharData
{
115 /* Width of the character in pixels. This is the area that is drawn
116 * onto, but the real area occupied by the character can be different
117 * and is defined by pre_offset and post_offset.
121 /* X offset to be applied to the current position *before*
122 * drawing the character.
126 /* X offset to be applied to the current position *after*
127 * the character is drawn.
131 /* Character bitmap (size depends on width and height). */
136 /* The default font, which is hardcoded and always available. */
137 extern struct GP_Font GP_default_console_font
;
138 extern struct GP_Font GP_default_proportional_font
;
140 /* Returns the number of bytes occupied by the GP_CharData structure
141 * for this font. (Currently, all characters occupy the same space
142 * regardless of proportionality.)
144 unsigned int GP_GetCharDataSize(const GP_Font
*font
);
146 /* Returns a pointer to the character data (which start by the header)
147 * of the specified character in the font data area.
149 const GP_CharData
*GP_GetCharData(const GP_Font
*font
, int c
);
151 /* Returns the overall size (in bytes) occupied by all characters
152 * of the font (the font metadata do not count into this value;
153 * add sizeof(GP_Font) to get the complete size of the font in memory.)
155 unsigned int GP_GetFontDataSize(const GP_Font
*font
);
157 #include "GP_RetCode.h"
159 GP_RetCode
GP_FontLoad(GP_Font
**font
, const char *filename
);
160 GP_RetCode
GP_FontSave(const GP_Font
*font
, const char *filename
);
162 #endif /* GP_FONT_H */