3 Text drawing is controlled by the <<TextStyle,GP_TextStyle>> structure. This
4 structure carries information about font, letter spacing and pixel
5 multiplication and spacing. (If no font is specified, the default mono-space
8 You may want to see the link:coordinate_system.html[coordinate system] first.
11 --------------------------------------------------------------------------------
14 #include <text/GP_Text.h>
16 /* Where the text should be drawn relatively to the specified point */
17 typedef enum GP_TextAlign {
18 GP_ALIGN_LEFT = 0x01, /* to the left from the point */
19 GP_ALIGN_CENTER = 0x02, /* centered on the point */
20 GP_ALIGN_RIGHT = 0x03, /* to the right from the point */
21 GP_VALIGN_ABOVE = 0x10, /* above the point */
22 GP_VALIGN_CENTER = 0x20, /* centered on the point */
23 GP_VALIGN_BASELINE = 0x30, /* baseline is on the point */
24 GP_VALIGN_BELOW = 0x40 /* below the point */
27 void GP_Text(GP_Context *context, const GP_TextStyle *style,
28 GP_Coord x, GP_Coord y, int align,
29 GP_Pixel fg, GP_Pixel bg, const char *str);
32 GP_Size GP_Print(GP_Context *context, const GP_TextStyle *style,
33 GP_Coord x, GP_Coord y, int align,
34 GP_Pixel fg, GP_Pixel bg, const char *fmt, ...);
36 GP_Size GP_VPrint(GP_Context *context, const GP_TextStyle *style,
37 GP_Coord x, GP_Coord y, int align,
38 GP_Pixel fg, GP_Pixel bg,
39 const char *fmt, va_list va);
40 --------------------------------------------------------------------------------
42 Draws text at the position x and y; the alignment of the text in relation
43 to the point is specified by alignment flags.
45 If the 'style' argument is 'NULL', a default style is used.
47 The text size can be computed by following functions:
50 --------------------------------------------------------------------------------
53 #include <text/GP_TextMetric.h>
55 unsigned int GP_TextWidth(const GP_TextStyle *style, const char *str);
56 --------------------------------------------------------------------------------
58 Returns the width (in pixels) that would be occupied by the string if rendered
59 using the specified style.
61 Computing a length of a given string is more complicated than it appears to
62 be. The first letter needs 'advance - bearing' pixels, the middle letters
63 needs 'advance' pixels and the last letter needs 'bearing + width' pixel. See
64 link:images/fonts/glyph_metrics.png[Glyph Metrics] for a description of the
65 terms used in this paragraph.
68 --------------------------------------------------------------------------------
71 #include <text/GP_TextMetric.h>
73 unsigned int GP_TextMaxWidth(const GP_TextStyle *style, unsigned int len);
74 --------------------------------------------------------------------------------
76 Returns maximum text width, in pixels, for string with 'len' letters.
78 This call simply computes width of a string rendered with 'len' largest glyphs
79 (letters) in the font. Because of this the resulting size is often much larger
83 --------------------------------------------------------------------------------
86 #include <text/GP_TextMetric.h>
88 GP_Size GP_TextMaxStrWidth(const GP_TextStyle *style, const char *str,
90 --------------------------------------------------------------------------------
92 Returns maximum text width, in pixels, for a string with 'len' letters that
93 are composed only of letters from 'str'.
95 This call simply computes width of a string rendered with largest letter from
96 'str' and with 'len' characters.
99 --------------------------------------------------------------------------------
102 #include <text/GP_TextMetric.h>
104 unsigned int GP_TextAscent(const GP_TextStyle *style);
105 --------------------------------------------------------------------------------
107 The Ascent is the height in pixels from the top to the baseline.
109 The baseline is imaginary line that letters are positioned upon and the ascent
110 is usually height of capital letter, but it may be larger for certain fonts.
113 --------------------------------------------------------------------------------
116 #include <text/GP_TextMetric.h>
118 unsigned int GP_TextDescent(const GP_TextStyle *style);
119 --------------------------------------------------------------------------------
121 The Descent is the height in pixels from baseline to the bottom.
123 The baseline is imaginary line that letters are positioned upon and the
124 descent is usually height of upper part of the letter y that goes under the
125 baseline, but it may be larger for certain fonts.
128 --------------------------------------------------------------------------------
131 #include <text/GP_TextMetric.h>
133 unsigned int GP_TextHeight(const GP_TextStyle *style);
134 --------------------------------------------------------------------------------
136 The Height is size of the font from top to the bottom, i.e. equals exactly to
137 the sum of ascent and descent.
139 This simply returns height that is needed to draw a line of a text using a
140 certain font style (without the spacing between the lines).
147 --------------------------------------------------------------------------------
150 #include <text/GP_TextStyle.h>
152 typedef struct GP_TextStyle {
153 const struct GP_FontFace *font;
155 /* Spacing between pixels (0 is the default, no spacing). */
156 int pixel_xspace, pixel_yspace;
158 /* Multiplier of pixel width/height (1 is default). */
159 int pixel_xmul, pixel_ymul;
161 /* Extra spacing (in pixels) between characters. */
165 --------------------------------------------------------------------------------
167 The TextStyle structure describes the parameters for text rendering.
169 The first parameter is font being used.
170 TODO: link to font format and description.
172 The 'xspace' and 'yspace' parameters controls spacing between the pixels and
173 the 'xmul' and 'ymul' describes pixel multiplication in respective directions.
175 The 'char_xspace' is used to add additional space between letters.
177 .Default Console Font xmul=ymul=1 xspace=yspace=0
178 image::images/fonts/default_console_font.png["Default Console Font"]
180 .Default Console Font xmul=ymul=2 xspace=yspace=-1
181 image::images/fonts/default_console_font_embolding.png["Default Console Font"]
183 .Default Console Font xmul=ymul=2 xspace=yspace=1
184 image::images/fonts/default_console_font_big.png["Default Console Font"]
190 There is a global constant pointer to each compiled-in font structure, see
191 'include/text/GP_Fonts.h'.
193 .Default Console Font
194 image::images/fonts/default_console_font.png["Default Console Font"]
196 .Default Proportional Font
197 image::images/fonts/default_proportional_font.png["Default Proportional Font"]
199 .Font Tiny Mono (GP_FontTinyMono)
200 image::images/fonts/font_tiny_mono.png["Font Tiny Mono"]
202 .Font Tiny (GP_FontTiny)
203 image::images/fonts/font_tiny.png["Font Tiny"]
209 --------------------------------------------------------------------------------
211 * Load font face from file.
213 GP_FontFace *GP_FontFaceLoad(const char *path, uint32_t width, uint32_t height);
216 * Free the font face.
218 void GP_FontFaceFree(GP_FontFace *self);
219 --------------------------------------------------------------------------------
221 Renders TrueType font using link:http://www.freetype.org[FreeType] (currently
222 printable ASCII only) into GFXprim font structures.
224 One of the 'width' or 'height' may be zero, which means that the second value
225 should be computed accordingly.
227 NOTE: If you pass both 'width' and 'height' non-zero the resulting font may
228 look strange as this action forced unnatural aspect ratio.
231 TIP: For Font and TextStyle handling see link:example_fonts.html[examples].