filters/gp_filter_resize_alloc: Check w and h
[gfxprim.git] / include / text / GP_Text.h
blob8d7ba57983eeabf9e7b6c8d6223ea905ce773aa4
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-2011 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
21 * *
22 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
23 * *
24 *****************************************************************************/
26 #ifndef TEXT_GP_TEXT_H
27 #define TEXT_GP_TEXT_H
29 #include <stdarg.h>
31 #include <core/GP_Types.h>
32 #include <text/GP_TextStyle.h>
33 #include <text/GP_TextMetric.h>
34 #include <text/GP_Fonts.h>
36 /* How the rendered text should be aligned.
37 * For gp_text(), the alignment is relative to the specified point:
39 * - GP_ALIGN_LEFT draws the text to the left of the point,
40 * - GP_ALIGN_CENTER centers it at the point horizontally,
41 * - GP_ALIGN_RIGHT draws the text to the right of the point
42 * - GP_VALIGN_ABOVE (or TOP) draws the text above the point
43 * - GP_VALIGN_CENTER centers the text vertically at the point
44 * - GP_VALIGN_BASELINE places the text baseline at the point
45 * - GP_VALIGN_BELOW (or BOTTOM) draws the text below the point
46 * - GP_TEXT_NOBG mix the alpha pixels with data read from the pixmap
47 * rather than mixing them with bg_color
48 * (which is slightly slower)
50 typedef enum gp_text_attr {
51 GP_ALIGN_LEFT = 0x01,
52 GP_ALIGN_CENTER = 0x02,
53 GP_ALIGN_RIGHT = 0x03,
54 GP_VALIGN_ABOVE = 0x10,
55 GP_VALIGN_TOP = GP_VALIGN_ABOVE,
56 GP_VALIGN_CENTER = 0x20,
57 GP_VALIGN_BASELINE = 0x30,
58 GP_VALIGN_BELOW = 0x40,
59 GP_VALIGN_BOTTOM = GP_VALIGN_BELOW,
60 GP_TEXT_NOBG = 0x80,
61 } gp_text_attr;
64 * Raw version, doesn't use Text aligment.
66 * If flags are set to GP_TEXT_NOBG the the bg_color is ignored and
67 * the pixmap pixels are used for alpha mixing.
69 void gp_text_raw(gp_pixmap *pixmap, const gp_text_style *style,
70 gp_coord x, gp_coord y, uint8_t flags,
71 gp_pixel fg_color, gp_pixel bg_color,
72 const char *str);
75 * Draws a string.
77 * The string is rendered to pixmap (horizontally) with defined text style.
78 * The x and y coordinates determines point defined by aligment flags.
80 * The background color is ignored for 1bpp font formats.
82 void gp_text(gp_pixmap *pixmap, const gp_text_style *style,
83 gp_coord x, gp_coord y, int align,
84 gp_pixel fg_color, gp_pixel bg_color, const char *str);
87 * Same as above, but printf like and returns text width in pixels.
89 gp_size gp_print(gp_pixmap *pixmap, const gp_text_style *style,
90 gp_coord x, gp_coord y, int align,
91 gp_pixel fg_color, gp_pixel bg_color, const char *fmt, ...)
92 __attribute__ ((format (printf, 8, 9)));
94 gp_size gp_vprint(gp_pixmap *pixmap, const gp_text_style *style,
95 gp_coord x, gp_coord y, int align,
96 gp_pixel fg_color, gp_pixel bg_color,
97 const char *fmt, va_list va);
99 * Clears rectangle that would be used to draw text of size pixels.
101 void gp_text_clear(gp_pixmap *pixmap, const gp_text_style *style,
102 gp_coord x, gp_coord y, int align,
103 gp_pixel bg_color, gp_size size);
106 * Dtto, but with string.
108 void gp_text_clear_str(gp_pixmap *pixmap, const gp_text_style *style,
109 gp_coord x, gp_coord y, int align,
110 gp_pixel bg_color, const char *str);
112 #endif /* TEXT_GP_TEXT_H */