GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Functions
gp_text_metric.h File Reference

A text metric. More...

#include <core/gp_types.h>
#include <text/gp_text_style.h>

Go to the source code of this file.

Functions

gp_size gp_glyph_advance_x (const gp_text_style *style, uint32_t ch)
 Returns a letter advance in horizontal direction.
 
gp_ssize gp_glyph_bearing_x (const gp_text_style *style, uint32_t ch)
 Returns horizontal bearing.
 
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.
 
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.
 
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_max_width (const gp_text_style *style, unsigned int len)
 Counts maximal width for len characters.
 
gp_size gp_text_avg_width (const gp_text_style *style, unsigned int len)
 Counts average width for len characters.
 
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_size gp_text_height (const gp_text_style *style)
 Returns maximal text height.
 
gp_size gp_text_ascent (const gp_text_style *style)
 Returns an ascent.
 
gp_size gp_text_descent (const gp_text_style *style)
 Returns a descent.
 
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_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 string. The return value is between [0, strlen(str)], where 0 means cursor before string and strlen(str) cursor after string.
 

Detailed Description

A text metric.

Definition in file gp_text_metric.h.

Function Documentation

◆ gp_glyph_advance_x()

gp_size gp_glyph_advance_x ( const gp_text_style style,
uint32_t  ch 
)

Returns a letter advance in horizontal direction.

Parameters
styleA text style + font formatting
chAn unicode glyph.
Returns
Horizontal advance in pixels.

◆ gp_glyph_bearing_x()

gp_ssize gp_glyph_bearing_x ( const gp_text_style style,
uint32_t  ch 
)

Returns horizontal bearing.

Bearing is a distance to be added to the x coordinate before we start drawing a glyph bitmap. Bearing may be negative in some cases, typically for letter 'J' and 'j'.

Parameters
styleA text style + font formatting
chAn unicode glyph.
Returns
Horizontal bearing in pixels.

◆ gp_text_ascent()

gp_size gp_text_ascent ( const gp_text_style style)

Returns an ascent.

Returns an ascent, the height from the baseline to the top of characters, for the given text style.

Parameters
styleA text style + font formatting.
Returns
An ascent in pixels.

Referenced by gp_widget_size_units_get().

◆ gp_text_avg_width()

gp_size gp_text_avg_width ( const gp_text_style style,
unsigned int  len 
)

Counts average width for len characters.

Parameters
styleA text style + font formatting.
lenA number of glyphs to draw.
Returns
Width in pixels.

◆ gp_text_cur_pos()

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 string. The return value is between [0, strlen(str)], where 0 means cursor before string and strlen(str) cursor after string.

Parameters
styleA text style.
strAn UTF8 string.
x_offHorizontal offset in the rendered string in pixel.
Returns
A cursor position in the string.

◆ gp_text_descent()

gp_size gp_text_descent ( const gp_text_style style)

Returns a descent.

Returns a descend, the height from the baseline to the bottom of characters, for the given text style.

Parameters
styleA text style + font formatting.
Returns
A descent in pixels.

◆ gp_text_fit_width()

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.

Parameters
styleA text style.
strAn UTF-8 string.
widthWidth in pixels.
Returns
How many characters from the string will fit the space.

◆ gp_text_height()

gp_size gp_text_height ( const gp_text_style style)

Returns maximal text height.

Parameters
styleA text style + font formatting.
Returns
Height in pixels.

◆ gp_text_max_width()

gp_size gp_text_max_width ( const gp_text_style style,
unsigned int  len 
)

Counts maximal width for len characters.

Parameters
styleA text style + font formatting.
lenA number of glyphs to draw.
Returns
Width in pixels.

◆ gp_text_max_width_chars()

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.

First we find maximal width of an character from the given string, then we use that to compute maximal width. Note that first and last character needs special handling due to bearing and advance.

Parameters
styleA text style + font formatting.
charsAn UTF8 string.
lenA number of glyphs to draw.
Returns
Width in pixels.

◆ gp_text_wbbox()

static gp_size gp_text_wbbox ( const gp_text_style style,
const char *  str 
)
inlinestatic

Calculates bounding box width of the string drawn in the given style.

Parameters
styleA text style + font formatting.
strA string.
Returns
Width in pixels.

Definition at line 106 of file gp_text_metric.h.

References gp_text_width().

◆ gp_text_wbbox_len()

static gp_size gp_text_wbbox_len ( const gp_text_style style,
const char *  str,
size_t  len 
)
inlinestatic

Calculates bounding box width of the string drawn in the given style.

Parameters
styleA text style + font formatting.
strA string.
lenMaximal lenght of the string.
Returns
Width in pixels.

Definition at line 82 of file gp_text_metric.h.

References gp_text_width_len().

◆ gp_text_width()

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.

Parameters
styleA text style + font formatting.
typeSelect if we want a bounding box or advance.
strA string.
Returns
Width in pixels.

Referenced by gp_text_wbbox().

◆ gp_text_width_len()

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.

Parameters
styleA text style + font formatting.
typeSelect if we want a bounding box or advance.
strA string.
lenMaximal lenght of the string.
Returns
Width in pixels.

Referenced by gp_text_wbbox_len().