GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_text_metric.h
Go to the documentation of this file.
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-2024 Cyril Hrubis <metan@ucw.cz>
7 */
8
15#ifndef TEXT_GP_TEXT_METRIC_H
16#define TEXT_GP_TEXT_METRIC_H
17
18#include <core/gp_types.h>
19#include <text/gp_text_style.h>
20
21enum gp_text_len_type {
22 /*
23 * Return bounding box, i.e. for the last letter return the greater of
24 * advance and letter width. This makes sure that the resulting size
25 * will fit the text.
26 */
27 GP_TEXT_LEN_BBOX,
28 /*
29 * Returns advance, i.e. where next letter would start after a string
30 * would have been printed. This may return slightly less than the
31 * GP_TEXT_LEN_BBOX.
32 */
33 GP_TEXT_LEN_ADVANCE,
34};
35
44gp_size gp_glyph_advance_x(const gp_text_style *style, uint32_t ch);
45
58gp_ssize gp_glyph_bearing_x(const gp_text_style *style, uint32_t ch);
59
70gp_size gp_text_width_len(const gp_text_style *style, enum gp_text_len_type type,
71 const char *str, size_t len);
72
82static inline gp_size gp_text_wbbox_len(const gp_text_style *style, const char *str, size_t len)
83{
84 return gp_text_width_len(style, GP_TEXT_LEN_BBOX, str, len);
85}
86
96gp_size gp_text_width(const gp_text_style *style, enum gp_text_len_type type, const char *str);
97
106static inline gp_size gp_text_wbbox(const gp_text_style *style, const char *str)
107{
108 return gp_text_width(style, GP_TEXT_LEN_BBOX, str);
109}
110
119gp_size gp_text_max_width(const gp_text_style *style, unsigned int len);
120
129gp_size gp_text_avg_width(const gp_text_style *style, unsigned int len);
130
144gp_size gp_text_max_width_chars(const gp_text_style *style, const char *chars,
145 unsigned int len);
146
155
167
179
189size_t gp_text_fit_width(const gp_text_style *style, const char *str,
190 gp_size width);
191
204gp_size gp_text_cur_pos(const gp_text_style *style, const char *str, gp_coord x_off);
205
206#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
gp_size gp_glyph_advance_x(const gp_text_style *style, uint32_t ch)
Returns a letter advance in horizontal direction.
gp_size gp_text_avg_width(const gp_text_style *style, unsigned int len)
Counts average width for len characters.
size_t gp_text_fit_width(const gp_text_style *style, const char *str, gp_size width)
Counts how many characters will fit into a width pixels.
gp_size gp_text_width_len(const gp_text_style *style, enum gp_text_len_type type, const char *str, size_t len)
Calculates the width of the string drawn in the given style.
gp_size gp_text_max_width(const gp_text_style *style, unsigned int len)
Counts maximal width for len characters.
static gp_size gp_text_wbbox_len(const gp_text_style *style, const char *str, size_t len)
Calculates bounding box width of the string drawn in the given style.
gp_size gp_text_width(const gp_text_style *style, enum gp_text_len_type type, const char *str)
Calculates the width of the string drawn in the given style.
gp_size gp_text_max_width_chars(const gp_text_style *style, const char *chars, unsigned int len)
Returns maximal width for text written with len characters from str.
gp_ssize gp_glyph_bearing_x(const gp_text_style *style, uint32_t ch)
Returns horizontal bearing.
gp_size gp_text_ascent(const gp_text_style *style)
Returns an ascent.
static gp_size gp_text_wbbox(const gp_text_style *style, const char *str)
Calculates bounding box width of the string drawn in the given style.
gp_size gp_text_cur_pos(const gp_text_style *style, const char *str, gp_coord x_off)
Returns position between string characters given an x pixel coordinate from the start of the rendered...
gp_size gp_text_descent(const gp_text_style *style)
Returns a descent.
gp_size gp_text_height(const gp_text_style *style)
Returns maximal text height.
A text style.
A text style.