GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_text.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos
4 * <jiri.bluebear.dluhos@gmail.com>
5 *
6 * Copyright (C) 2009-2024 Cyril Hrubis <metan@ucw.cz>
7 */
8
14#ifndef TEXT_GP_TEXT_H
15#define TEXT_GP_TEXT_H
16
17#include <stdarg.h>
18
19#include <core/gp_types.h>
20#include <core/gp_compiler.h>
21#include <text/gp_text_style.h>
22#include <text/gp_text_metric.h>
23#include <text/gp_fonts.h>
24
64
88 gp_pixel fg_color, gp_pixel bg_color,
89 const char *str, size_t max_chars);
90
111 gp_coord x, gp_coord y, gp_text_flags flags,
112 gp_pixel fg_color, gp_pixel bg_color, const char *str);
113
138 gp_coord x, gp_coord y, int flags,
139 gp_pixel fg_color, gp_pixel bg_color,
140 uint32_t glyph);
141
162static inline gp_size gp_text_xxy(gp_pixmap *pixmap, const gp_text_style *style,
163 gp_coord x1, gp_coord x2, gp_coord y, gp_text_flags flags,
164 gp_pixel fg_color, gp_pixel bg_color, const char *str)
165{
166 gp_coord x, len;
167
168 if (x1 < x2) {
169 x = x1;
170 len = x2 - x1;
171 } else {
172 x = x2;
173 len = x1 - x2;
174 }
175
176 int halign = flags & GP_ALIGN_HORIZ;
177
178 flags &= ~GP_ALIGN_HORIZ;
179
180 switch (halign) {
181 case GP_ALIGN_LEFT:
182 flags |= GP_ALIGN_RIGHT;
183 break;
184 case GP_ALIGN_CENTER:
185 x += len/2;
186 flags |= GP_ALIGN_CENTER;
187 break;
188 case GP_ALIGN_RIGHT:
189 x += len;
190 flags |= GP_ALIGN_LEFT;
191 break;
192 }
193
194 return gp_text(pixmap, style, x, y, flags, fg_color, bg_color, str);
195}
196
197/*
198 * Same as the gp_text() but the number of characters can be limited.
199 */
200gp_size gp_text_ext(gp_pixmap *pixmap, const gp_text_style *style,
201 gp_coord x, gp_coord y, gp_text_flags flags,
202 gp_pixel fg_color, gp_pixel bg_color,
203 const char *str, size_t max_chars);
204
226 gp_coord x, gp_coord y, gp_text_flags flags,
227 gp_pixel fg_color, gp_pixel bg_color, const char *fmt, ...)
228 GP_FMT_PRINTF(8, 9);
229
250 gp_coord x, gp_coord y, gp_text_flags flags,
251 gp_pixel fg_color, gp_pixel bg_color,
252 const char *fmt, va_list va)
253 GP_FMT_PRINTF(8, 0);
254
276GP_FMT_PRINTF(9, 10)
277static inline gp_size gp_print_xxy(gp_pixmap *pixmap, const gp_text_style *style,
278 gp_coord x1, gp_coord x2, gp_coord y, gp_text_flags flags,
279 gp_pixel fg_color, gp_pixel bg_color, const char *fmt, ...)
280{
281 gp_coord x, len;
282 gp_size ret;
283 va_list va;
284
285 if (x1 < x2) {
286 x = x1;
287 len = x2 - x1;
288 } else {
289 x = x2;
290 len = x1 - x2;
291 }
292
293 int halign = flags & GP_ALIGN_HORIZ;
294
295 flags &= ~GP_ALIGN_HORIZ;
296
297 switch (halign) {
298 case GP_ALIGN_LEFT:
299 flags |= GP_ALIGN_RIGHT;
300 break;
301 case GP_ALIGN_CENTER:
302 x += len/2;
303 flags |= GP_ALIGN_CENTER;
304 break;
305 case GP_ALIGN_RIGHT:
306 x += len;
307 flags |= GP_ALIGN_LEFT;
308 break;
309 }
310
311 va_start(va, fmt);
312 ret = gp_vprint(pixmap, style, x, y, flags, fg_color, bg_color, fmt, va);
313 va_end(va);
314
315 return ret;
316}
317
327void gp_text_clear(gp_pixmap *pixmap, const gp_text_style *style,
328 gp_coord x, gp_coord y, gp_text_flags flags,
329 gp_pixel bg_color, gp_size size);
330
331/*
332 * Dtto, but with string.
333 */
334void gp_text_clear_str(gp_pixmap *pixmap, const gp_text_style *style,
335 gp_coord x, gp_coord y, gp_text_flags flags,
336 gp_pixel bg_color, const char *str);
337
338#endif /* TEXT_GP_TEXT_H */
A common types.
uint32_t gp_pixel
Pixel integer value.
Definition gp_types.h:33
int gp_coord
Integer type for coordinates i.e. x, y, ...
Definition gp_types.h:19
unsigned int gp_size
Integer type for sizes i.e. w, h, ...
Definition gp_types.h:24
A compiler dependent macros.
#define GP_FMT_PRINTF(fmt, list)
Expands to format printf attribute when supported by the compiler.
Definition gp_compiler.h:31
A font lookup functions.
gp_size gp_vprint(gp_pixmap *pixmap, const gp_text_style *style, gp_coord x, gp_coord y, gp_text_flags flags, gp_pixel fg_color, gp_pixel bg_color, const char *fmt, va_list va)
Draws a string.
gp_size gp_text(gp_pixmap *pixmap, const gp_text_style *style, gp_coord x, gp_coord y, gp_text_flags flags, gp_pixel fg_color, gp_pixel bg_color, const char *str)
Draws a string.
gp_size gp_text_raw(gp_pixmap *pixmap, const gp_text_style *style, gp_coord x, gp_coord y, gp_text_flags flags, gp_pixel fg_color, gp_pixel bg_color, const char *str, size_t max_chars)
Draws a string.
static gp_size gp_print_xxy(gp_pixmap *pixmap, const gp_text_style *style, gp_coord x1, gp_coord x2, gp_coord y, gp_text_flags flags, gp_pixel fg_color, gp_pixel bg_color, const char *fmt,...)
Draws a string.
Definition gp_text.h:277
gp_size gp_glyph_draw(gp_pixmap *pixmap, const gp_text_style *style, gp_coord x, gp_coord y, int flags, gp_pixel fg_color, gp_pixel bg_color, uint32_t glyph)
Renders a single glyph.
void gp_text_clear(gp_pixmap *pixmap, const gp_text_style *style, gp_coord x, gp_coord y, gp_text_flags flags, gp_pixel bg_color, gp_size size)
Clears a rectangle that would be used to draw text of size pixels.
gp_text_flags
Text flags, mostly alignment.
Definition gp_text.h:30
@ GP_ALIGN_LEFT
Draws the text to the left of the point.
Definition gp_text.h:32
@ GP_ALIGN_RIGHT
Draws the text to the right of the point.
Definition gp_text.h:36
@ GP_TEXT_BEARING
Apply bearing before start of the string.
Definition gp_text.h:40
@ GP_VALIGN_BOTTOM
Alias for GP_VALIGN_BELOW.
Definition gp_text.h:52
@ GP_VALIGN_TOP
Alias for GP_VALIGN_ABOVE.
Definition gp_text.h:44
@ GP_VALIGN_BELOW
Draws the text below the point.
Definition gp_text.h:50
@ GP_TEXT_NOBG
Use pixmap background.
Definition gp_text.h:62
@ GP_VALIGN_VERT
Vertical alignment mask.
Definition gp_text.h:54
@ GP_ALIGN_CENTER
Centers the text at the point horizontally.
Definition gp_text.h:34
@ GP_VALIGN_ABOVE
Draws the text above the point.
Definition gp_text.h:42
@ GP_ALIGN_HORIZ
Horizontal alignment mask.
Definition gp_text.h:38
@ GP_VALIGN_BASELINE
Places the text baseline at the point.
Definition gp_text.h:48
@ GP_VALIGN_CENTER
Centers the text vertically at the point.
Definition gp_text.h:46
static gp_size gp_text_xxy(gp_pixmap *pixmap, const gp_text_style *style, gp_coord x1, gp_coord x2, gp_coord y, gp_text_flags flags, gp_pixel fg_color, gp_pixel bg_color, const char *str)
Draws a string.
Definition gp_text.h:162
gp_size gp_print(gp_pixmap *pixmap, const gp_text_style *style, gp_coord x, gp_coord y, gp_text_flags flags, gp_pixel fg_color, gp_pixel bg_color, const char *fmt,...)
Draws a string.
A text metric.
A text style.
A pixmap buffer.
Definition gp_pixmap.h:33
A text style.