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

A text drawing functions. More...

#include <stdarg.h>
#include <core/gp_types.h>
#include <core/gp_compiler.h>
#include <text/gp_text_style.h>
#include <text/gp_text_metric.h>
#include <text/gp_fonts.h>

Go to the source code of this file.

Typedefs

typedef enum gp_text_flags gp_text_flags
 Text flags, mostly alignment.
 

Enumerations

enum  gp_text_flags {
  GP_ALIGN_LEFT = 0x01 , GP_ALIGN_CENTER = 0x02 , GP_ALIGN_RIGHT = 0x03 , GP_ALIGN_HORIZ = 0x03 ,
  GP_TEXT_BEARING = 0x04 , GP_VALIGN_ABOVE = 0x10 , GP_VALIGN_TOP = GP_VALIGN_ABOVE , GP_VALIGN_CENTER = 0x20 ,
  GP_VALIGN_BASELINE = 0x30 , GP_VALIGN_BELOW = 0x40 , GP_VALIGN_BOTTOM = GP_VALIGN_BELOW , GP_VALIGN_VERT = 0x70 ,
  GP_TEXT_NOBG = 0x80
}
 Text flags, mostly alignment. More...
 

Functions

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.
 
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_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.
 
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.
 
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.
 
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.
 
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.
 
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.
 

Detailed Description

A text drawing functions.

Definition in file gp_text.h.

Typedef Documentation

◆ gp_text_flags

Text flags, mostly alignment.

The alignment is relative to a specified point.

Enumeration Type Documentation

◆ gp_text_flags

Text flags, mostly alignment.

The alignment is relative to a specified point.

Enumerator
GP_ALIGN_LEFT 

Draws the text to the left of the point.

GP_ALIGN_CENTER 

Centers the text at the point horizontally.

GP_ALIGN_RIGHT 

Draws the text to the right of the point.

GP_ALIGN_HORIZ 

Horizontal alignment mask.

GP_TEXT_BEARING 

Apply bearing before start of the string.

GP_VALIGN_ABOVE 

Draws the text above the point.

GP_VALIGN_TOP 

Alias for GP_VALIGN_ABOVE.

GP_VALIGN_CENTER 

Centers the text vertically at the point.

GP_VALIGN_BASELINE 

Places the text baseline at the point.

GP_VALIGN_BELOW 

Draws the text below the point.

GP_VALIGN_BOTTOM 

Alias for GP_VALIGN_BELOW.

GP_VALIGN_VERT 

Vertical alignment mask.

GP_TEXT_NOBG 

Use pixmap background.

Mix the alpha pixels with data read from the pixmap rather than mixing them with bg_color (which is slightly slower). This has no effect for 1bpp fonts.

Definition at line 30 of file gp_text.h.

Function Documentation

◆ gp_glyph_draw()

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.

The x, y coordinates are the upper left corner of the glyph box. If you want to render on baseline, you have to add the ascend. The if GP_TEXT_BEARING is passed in the flags, bearing is applied before the glyph is rendered. Usually first letter in a line is rendered without bearing and the rest of them is rendered with bearing.

Parameters
pixmapA pixmap to draw the glyph into.
styleA text font and style.
xAn x coordinate inside the pixmap.
yAn y coordinate inside the pixmap.
flagsEither 0 or any combination of GP_TEXT_BEARING and GP_TEXT_NOBG and GP_VALIGN_*
fg_colorText color.
bg_colorBackground color. The background color is ignored for 1bpp font formats.
glyphAnd unicode glypth to draw.
Returns
Returns glyhp advance plus any style extra spacing, i.e. how much should x move for the next glyph.

◆ gp_print()

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.

This is the same as gp_text() only with a printf() like format and parameters.

Parameters
pixmapA pixmap to draw the glyph into.
styleA text font and style.
xAn x coordinate inside the pixmap.
yAn y coordinate inside the pixmap.
flagsEither 0 or any combination of GP_TEXT_BEARING and GP_TEXT_NOBG and GP_VALIGN_*
fg_colorText color.
bg_colorBackground color. The background color is ignored for 1bpp font formats.
fmtA printf like format.
...A printf like parameters.
Returns
A width of the rendered text.

◆ gp_print_xxy()

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,
  ... 
)
inlinestatic

Draws a string.

This is the same as gp_text_xxy() only with a printf() like format and parameters.

Parameters
pixmapA pixmap to draw the glyph into.
styleA text font and style.
x1An x1 coordinate inside the pixmap.
x2An x2 coordinate inside the pixmap.
yAn y coordinate inside the pixmap.
flagsEither 0 or any combination of GP_TEXT_BEARING and GP_TEXT_NOBG and GP_VALIGN_*.
fg_colorText color.
bg_colorBackground color. The background color is ignored for 1bpp font formats.
fmtA printf like format.
...A printf like parameters.
Returns
A width of the rendered text.

Definition at line 277 of file gp_text.h.

References GP_ALIGN_CENTER, GP_ALIGN_HORIZ, GP_ALIGN_LEFT, GP_ALIGN_RIGHT, and gp_vprint().

◆ gp_text()

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.

The string is rendered to pixmap (horizontally) with defined text style. The x and y coordinates determines point defined by aligment flags.

Parameters
pixmapA pixmap to draw the glyph into.
styleA text font and style.
xAn x coordinate inside the pixmap.
yAn y coordinate inside the pixmap.
flagsEither 0 or any combination of GP_TEXT_BEARING and GP_TEXT_NOBG and GP_VALIGN_*
fg_colorText color.
bg_colorBackground color. The background color is ignored for 1bpp font formats.
strAn UTF-8 string.
Returns
A width of the rendered text.

Referenced by gp_text_xxy().

◆ gp_text_clear()

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.

Parameters
pixmapA pixmap to draw the glyph into.
styleA text font and style.
xAn x coordinate inside the pixmap.
yAn y coordinate inside the pixmap.

◆ gp_text_raw()

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.

Attention
Raw version that doesn't use text aligment. Use gp_text() or gp_printf() instead.
Parameters
pixmapA pixmap to draw the glyph into.
styleA text font and style.
xAn x coordinate inside the pixmap.
yAn y coordinate inside the pixmap.
flagsEither 0 or any combination of GP_TEXT_BEARING and GP_TEXT_NOBG and GP_VALIGN_*.
fg_colorText color.
bg_colorBackground color. The background color is ignored for 1bpp font formats.
strAn UTF-8 string.
max_charsA maximum number of characters to draw, can be used to limit the number of characters to draw from str.
Returns
A width of the rendered text.

◆ gp_text_xxy()

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 
)
inlinestatic

Draws a string.

Aligns a string between x1 and x2 based ond horizontal aligment flags. The caller must make sure that the string will fit horizontally between x1 and x2.

Parameters
pixmapA pixmap to draw the glyph into.
styleA text font and style.
x1An x1 coordinate inside the pixmap.
x2An x2 coordinate inside the pixmap.
yAn y coordinate inside the pixmap.
flagsEither 0 or any combination of GP_TEXT_BEARING and GP_TEXT_NOBG and GP_VALIGN_*.
fg_colorText color.
bg_colorBackground color. The background color is ignored for 1bpp font formats.
strAn UTF-8 string.
Returns
A width of the rendered text.

Definition at line 162 of file gp_text.h.

References GP_ALIGN_CENTER, GP_ALIGN_HORIZ, GP_ALIGN_LEFT, GP_ALIGN_RIGHT, and gp_text().

◆ gp_vprint()

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.

This is va_arg variant of gp_print().

Parameters
pixmapA pixmap to draw the glyph into.
styleA text font and style.
xAn x coordinate inside the pixmap.
yAn y coordinate inside the pixmap.
flagsEither 0 or any combination of GP_TEXT_BEARING and GP_TEXT_NOBG and GP_VALIGN_*
fg_colorText color.
bg_colorBackground color. The background color is ignored for 1bpp font formats.
fmtA printf like format.
vaA printf like parameters.
Returns
A width of the rendered text.

Referenced by gp_print_xxy().