GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_fonts.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz>
4 */
5
6#ifndef TEXT_GP_FONTS_H
7#define TEXT_GP_FONTS_H
8
9#include <text/gp_font.h>
10
11extern const gp_font_family *gp_font_family_default;
12
13/*
14 * Looks up a font family by a family name in the compiled in fonts.
15 *
16 * @family_name A family name, such as 'gfxprim', 'tiny', etc.
17 *
18 * @return A pointer to a font family or NULL if not found.
19 */
20const gp_font_family *gp_font_family_lookup(const char *family_name);
21
22/*
23 * Looks up a font face in a family given a style flags.
24 *
25 * If family pointer is a null default 'gfxprim' family is used instead.
26 *
27 * @family A pointer to a font family. If NULL is passed default is used.
28 * @style A bitmask of enum gp_font_style.
29 * If GP_FONT_FALLBACK is passed the function never returns NULL.
30 *
31 * @return A pointer to a font or NULL if not found.
32 */
33const gp_font_face *gp_font_family_face_lookup(const gp_font_family *family, uint8_t style);
34
35/*
36 * Looks up a font face in a family given a family name and style flags.
37 *
38 * @family_name A family name such as 'gfxprim', 'tiny', etc.
39 * @style A bitmask of enum gp_font_style.
40 * If GP_FONT_FALLBACK is passed the function never returns NULL.
41 *
42 * @return A pointer to a font family or NULL if not found.
43 */
44const gp_font_face *gp_font_face_lookup(const char *family_name, uint8_t style);
45
46typedef struct gp_fonts_iter {
47 int16_t family_idx;
48 int16_t font_idx;
49} gp_fonts_iter;
50
51enum gp_fonts_iter_dir {
52 GP_FONTS_ITER_NOP = 0,
53 GP_FONTS_ITER_PREV = -1,
54 GP_FONTS_ITER_NEXT = 1,
55 GP_FONTS_ITER_FIRST = -2,
56 GP_FONTS_ITER_LAST = 2,
57};
58
59/*
60 * Iterates over all compiled in fonts.
61 *
62 * @iter An iterator.
63 * @wrap If non zero makes the iteration circular,
64 * i.e. NULL is not returned at the end.
65 * @dir Direction to move to.
66 *
67 * @return A font face.
68 */
69const gp_font_face *gp_fonts_iter_font(gp_fonts_iter *iter, int wrap,
70 enum gp_fonts_iter_dir dir);
71
72/*
73 * Iterates over all compiled in families.
74 *
75 * @iter An iterator.
76 * @wrap If non zero makes the iteration circular,
77 * i.e. NULL is not returned at the end.
78 * @dir Direction to move to.
79 *
80 * @return Current font family.
81 */
82const gp_font_family *gp_fonts_iter_family(gp_fonts_iter *iter, int wrap,
83 enum gp_fonts_iter_dir dir);
84
85#define GP_FONT_FAMILY_FOREACH(iter, family) \
86 for (family = gp_fonts_iter_family(iter, 0, GP_FONTS_ITER_FIRST); \
87 family; \
88 family = gp_fonts_iter_family(iter, 0, GP_FONTS_ITER_NEXT))
89
90#endif /* TEXT_GP_FONTS_H */