GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_text_metric.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos
4 * <jiri.bluebear.dluhos@gmail.com>
5 *
6 * Copyright (C) 2009-2021 Cyril Hrubis <metan@ucw.cz>
7 */
8
9#ifndef TEXT_GP_TEXT_METRIC_H
10#define TEXT_GP_TEXT_METRIC_H
11
12#include <core/gp_types.h>
13#include <text/gp_text_style.h>
14
15enum gp_text_len_type {
16 /*
17 * Return bounding box, i.e. for the last letter return the greater of
18 * advance and letter width. This makes sure that the resulting size
19 * will fit the text.
20 */
21 GP_TEXT_LEN_BBOX,
22 /*
23 * Returns advance, i.e. where next letter would start after a string
24 * would have been printed. This may return slightly less than the
25 * GP_TEXT_LEN_BBOX.
26 */
27 GP_TEXT_LEN_ADVANCE,
28};
29
38gp_size gp_glyph_advance_x(const gp_text_style *style, uint32_t ch);
39
51gp_ssize gp_glyph_bearing_x(const gp_text_style *style, uint32_t ch);
52
63gp_size gp_text_width_len(const gp_text_style *style, enum gp_text_len_type type,
64 const char *str, size_t len);
65
75static inline gp_size gp_text_wbbox_len(const gp_text_style *style, const char *str, size_t len)
76{
77 return gp_text_width_len(style, GP_TEXT_LEN_BBOX, str, len);
78}
79
89gp_size gp_text_width(const gp_text_style *style, enum gp_text_len_type type, const char *str);
90
99static inline gp_size gp_text_wbbox(const gp_text_style *style, const char *str)
100{
101 return gp_text_width(style, GP_TEXT_LEN_BBOX, str);
102}
103
104/*
105 * Maximal text width for string with len characters.
106 */
107gp_size gp_text_max_width(const gp_text_style *style, unsigned int len);
108
109/*
110 * Returns average width for len characters.
111 */
112gp_size gp_text_avg_width(const gp_text_style *style, unsigned int len);
113
114/*
115 * Returns maximal width for text written with len characters from str.
116 */
117gp_size gp_text_max_width_chars(const gp_text_style *style, const char *chars,
118 unsigned int len);
119
120/*
121 * Returns maximal text height, in pixels.
122 */
123gp_size gp_text_height(const gp_text_style *style);
124
125/*
126 * Returns the ascent (height from the baseline to the top of characters),
127 * for the given text style. (Result is in pixels.)
128 */
129gp_size gp_text_ascent(const gp_text_style *style);
130
131/*
132 * Returns the descent (height from the baseline to the bottom of characters),
133 * for the given text style. (Result is in pixels.)
134 */
135gp_size gp_text_descent(const gp_text_style *style);
136
144size_t gp_text_fit_width(const gp_text_style *style, const char *str,
145 gp_size width);
146
159gp_size gp_text_cur_pos(const gp_text_style *style, const char *str, gp_coord x_off);
160
161#endif /* TEXT_GP_TEXT_METRIC_H */
A common types.
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