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-2011 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
22 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
24 *****************************************************************************/
26 #ifndef TEXT_GP_TEXT_H
27 #define TEXT_GP_TEXT_H
31 #include "core/GP_Pixmap.h"
33 #include "text/GP_TextStyle.h"
34 #include "text/GP_TextMetric.h"
35 #include "text/GP_DefaultFont.h"
36 #include "text/GP_Fonts.h"
38 /* How the rendered text should be aligned.
39 * For GP_Text(), the alignment is relative to the specified point:
41 * - GP_ALIGN_LEFT draws the text to the left of the point,
42 * - GP_ALIGN_CENTER centers it at the point horizontally,
43 * - GP_ALIGN_RIGHT draws the text to the right of the point
44 * - GP_VALIGN_ABOVE (or TOP) draws the text above the point
45 * - GP_VALIGN_CENTER centers the text vertically at the point
46 * - GP_VALIGN_BASELINE places the text baseline at the point
47 * - GP_VALIGN_BELOW (or BOTTOM) draws the text below the point
48 * - GP_TEXT_NOBG mix the alpha pixels with data read from the pixmap
49 * rather than mixing them with bg_color
50 * (which is slightly slower)
52 typedef enum GP_TextAttr
{
54 GP_ALIGN_CENTER
= 0x02,
55 GP_ALIGN_RIGHT
= 0x03,
56 GP_VALIGN_ABOVE
= 0x10,
57 GP_VALIGN_TOP
= GP_VALIGN_ABOVE
,
58 GP_VALIGN_CENTER
= 0x20,
59 GP_VALIGN_BASELINE
= 0x30,
60 GP_VALIGN_BELOW
= 0x40,
61 GP_VALIGN_BOTTOM
= GP_VALIGN_BELOW
,
66 * Raw version, doesn't use Text aligment.
68 * If flags are set to GP_TEXT_NOBG the the bg_color is ignored and
69 * the pixmap pixels are used for alpha mixing.
71 void GP_Text_Raw(GP_Pixmap
*pixmap
, const GP_TextStyle
*style
,
72 GP_Coord x
, GP_Coord y
, uint8_t flags
,
73 GP_Pixel fg_color
, GP_Pixel bg_color
,
79 * The string is rendered to pixmap (horizontally) with defined text style.
80 * The x and y coordinates determines point defined by aligment flags.
82 * The background color is ignored for 1bpp font formats.
84 void GP_Text(GP_Pixmap
*pixmap
, const GP_TextStyle
*style
,
85 GP_Coord x
, GP_Coord y
, int align
,
86 GP_Pixel fg_color
, GP_Pixel bg_color
, const char *str
);
89 * Same as above, but printf like and returns text width in pixels.
91 GP_Size
GP_Print(GP_Pixmap
*pixmap
, const GP_TextStyle
*style
,
92 GP_Coord x
, GP_Coord y
, int align
,
93 GP_Pixel fg_color
, GP_Pixel bg_color
, const char *fmt
, ...)
94 __attribute__ ((format (printf
, 8, 9)));
96 GP_Size
GP_VPrint(GP_Pixmap
*pixmap
, const GP_TextStyle
*style
,
97 GP_Coord x
, GP_Coord y
, int align
,
98 GP_Pixel fg_color
, GP_Pixel bg_color
,
99 const char *fmt
, va_list va
);
101 * Clears rectangle that would be used to draw text of size pixels.
103 void GP_TextClear(GP_Pixmap
*pixmap
, const GP_TextStyle
*style
,
104 GP_Coord x
, GP_Coord y
, int align
,
105 GP_Pixel bg_color
, GP_Size size
);
108 * Dtto, but with string.
110 void GP_TextClearStr(GP_Pixmap
*pixmap
, const GP_TextStyle
*style
,
111 GP_Coord x
, GP_Coord y
, int align
,
112 GP_Pixel bg_color
, const char *str
);
114 #endif /* TEXT_GP_TEXT_H */