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

An in-memory font description. More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  gp_glyph
 A data describing single Glyph. More...
 
struct  gp_glyphs
 An unicode glyphs block. More...
 
struct  gp_font_face_ops
 Font loader callback. More...
 
struct  gp_font_face
 A font face. More...
 
struct  gp_font_family
 A font family. More...
 

Typedefs

typedef struct gp_glyph gp_glyph
 A data describing single Glyph.
 
typedef enum gp_font_bitmap_format gp_font_bitmap_format
 Glyph bitmap data format.
 
typedef enum gp_font_style gp_font_style
 Font style bitflags.
 
typedef struct gp_glyphs gp_glyphs
 An unicode glyphs block.
 
typedef struct gp_font_face_ops gp_font_face_ops
 Font loader callback.
 
typedef enum gp_font_ucode_block gp_font_ucode_block
 Unicode block ids.
 
typedef struct gp_font_family gp_font_family
 A font family.
 

Enumerations

enum  gp_font_bitmap_format { GP_FONT_BITMAP_1BPP , GP_FONT_BITMAP_8BPP }
 Glyph bitmap data format. More...
 
enum  gp_font_style {
  GP_FONT_REGULAR = 0x00 , GP_FONT_MONO = 0x01 , GP_FONT_BOLD = 0x02 , GP_FONT_ITALIC = 0x04 ,
  GP_FONT_STYLE_MASK = 0x0f , GP_FONT_FALLBACK = 0x10
}
 Font style bitflags. More...
 
enum  gp_font_ucode_block {
  GP_UCODE_LATIN_BASIC = 0x0001 , GP_UCODE_LATIN_SUP = 0x0002 , GP_UCODE_LATIN_EXT_A = 0x0004 , GP_UCODE_GREEK = 0x0008 ,
  GP_UCODE_CYRILIC = 0x0010 , GP_UCODE_HIRAGANA = 0x0020 , GP_UCODE_KATAKANA = 0x0030
}
 Unicode block ids. More...
 

Functions

static unsigned int gp_font_height (const gp_font_face *font)
 Returns font height.
 
static unsigned int gp_font_ascent (const gp_font_face *font)
 Returns font ascent.
 
static unsigned int gp_font_descent (const gp_font_face *font)
 Returns font ascent.
 
static unsigned int gp_font_max_width (const gp_font_face *font)
 Returns maximal glyph width.
 
static unsigned int gp_font_max_advance_x (const gp_font_face *font)
 Returns maximal glyph advance.
 
static unsigned int gp_font_avg_advance_x (const gp_font_face *font)
 Returns average glyph advance.
 
static const char * gp_font_family_name (const gp_font_face *font)
 Returns font family name.
 
const char * gp_font_style_name (gp_font_style style)
 Returns font style name.
 
gp_glyphgp_glyph_get (const gp_font_face *font, uint32_t ch)
 Looks up a glyph in a font.
 
gp_font_facegp_font_face_load (const char *path, uint32_t width, uint32_t height)
 Load a font face from a file.
 
gp_font_facegp_font_face_fc_load (const char *name, uint32_t width, uint32_t height)
 Uses fontconfig to lookup font file.
 
void gp_font_face_free (gp_font_face *self)
 Frees the font face memory.
 

Detailed Description

An in-memory font description.

Definition in file gp_font.h.

Typedef Documentation

◆ gp_font_bitmap_format

Glyph bitmap data format.

Defines depth for the gp_glyph::bitmap.

◆ gp_font_face_ops

Font loader callback.

When TrueType font is loaded the ASCII part is pre-rendered into the memory, any other characters are loaded on-demand when needed.

◆ gp_font_family

A font family.

Font family is a group of font faces of the same family and size but different style i.e. monospace, bold, italic...

The fonts array is NULL terminated.

◆ gp_font_style

Font style bitflags.

The monospace and regular font flags can be bitwise combined with bold and italic.

◆ gp_font_ucode_block

Unicode block ids.

All fonts must include LATIN_BASIC and it has to be the first table in the font.

◆ gp_glyph

typedef struct gp_glyph gp_glyph

A data describing single Glyph.

Note that glyph do not necessarily correspond to one character (for example ligature is a glyph but corresponds to at least two characters).

The glyphs are rendered to horizontal baseline, vertical rendering is not supported.

The structure could contain glyphs of different BPP and information about the bitmap format is stored in the font structure. The bitmap lines are byte aligned.

Enumeration Type Documentation

◆ gp_font_bitmap_format

Glyph bitmap data format.

Defines depth for the gp_glyph::bitmap.

Enumerator
GP_FONT_BITMAP_1BPP 

1 bit per pixel.

GP_FONT_BITMAP_8BPP 

8 bit per pixel.

Definition at line 67 of file gp_font.h.

◆ gp_font_style

Font style bitflags.

The monospace and regular font flags can be bitwise combined with bold and italic.

Enumerator
GP_FONT_REGULAR 

Regular font.

GP_FONT_MONO 

Monospace font.

GP_FONT_BOLD 

Bold font.

GP_FONT_ITALIC 

Italic font.

GP_FONT_STYLE_MASK 

Font style mask.

GP_FONT_FALLBACK 

A fallback flag.

If passed the font lookup functions always return some font possibly the default compiled-in font

Definition at line 80 of file gp_font.h.

◆ gp_font_ucode_block

Unicode block ids.

All fonts must include LATIN_BASIC and it has to be the first table in the font.

Enumerator
GP_UCODE_LATIN_BASIC 

ASCII block 0x20 - 0x7f.

GP_UCODE_LATIN_SUP 

Latin suplement 0xa0 - 0xff.

GP_UCODE_LATIN_EXT_A 

Latin extended A 0x100 - 0x17e.

GP_UCODE_GREEK 

Greek 0x384 - 0x3ce.

GP_UCODE_CYRILIC 

Cyrilic 0x340 - 0x45f.

GP_UCODE_HIRAGANA 

Hiragan 0x3041 - 0x3096.

GP_UCODE_KATAKANA 

Katakana 0x30a0 - 0x30aff.

Definition at line 240 of file gp_font.h.

Function Documentation

◆ gp_font_ascent()

static unsigned int gp_font_ascent ( const gp_font_face font)
inlinestatic

Returns font ascent.

Attention
This call returns font ascent, the rendered text height may be different due to gp_text_style. In most cases you should use gp_text_ascent() instead.
Parameters
fontA font face.
Returns
A font ascent.

Definition at line 301 of file gp_font.h.

References gp_font_face::ascent.

◆ gp_font_avg_advance_x()

static unsigned int gp_font_avg_advance_x ( const gp_font_face font)
inlinestatic

Returns average glyph advance.

For monospace fonts all advances are the same.

Parameters
fontA font face.
Returns
A maximal glyph width.

Definition at line 359 of file gp_font.h.

References gp_font_face::avg_glyph_advance, and gp_font_face::max_glyph_advance.

◆ gp_font_descent()

static unsigned int gp_font_descent ( const gp_font_face font)
inlinestatic

Returns font ascent.

Attention
This call returns font descent, the rendered text height may be different due to gp_text_style. In most cases you should use gp_text_descent() instead.
Parameters
fontA font face.
Returns
A font ascent.

Definition at line 317 of file gp_font.h.

References gp_font_face::descent.

◆ gp_font_face_fc_load()

gp_font_face * gp_font_face_fc_load ( const char *  name,
uint32_t  width,
uint32_t  height 
)

Uses fontconfig to lookup font file.

Looks up a font path given a font name and loads it with gp_font_face_load().

Parameters
nameA font name such as "Arial".
widthA width passed to the gp_font_face_load().
heightA height passed to the gp_font_face_load().
Returns
A font or NULL in a case of a failure.

◆ gp_font_face_free()

void gp_font_face_free ( gp_font_face self)

Frees the font face memory.

Frees the font face memory, closes FreeType hanles, etc.

Parameters
selfA font face.

◆ gp_font_face_load()

gp_font_face * gp_font_face_load ( const char *  path,
uint32_t  width,
uint32_t  height 
)

Load a font face from a file.

Loads a font using FreeType library. Only one of the width and height should be non-zero, to keep the correct aspect ratio for the glyph.

Parameters
pathA path to a font file.
widthA requested width.
heightA requested height.
Returns
A font or NULL in a case of a failure.

◆ gp_font_family_name()

static const char * gp_font_family_name ( const gp_font_face font)
inlinestatic

Returns font family name.

Parameters
fontA font face.
Returns
A font family name.

Definition at line 375 of file gp_font.h.

References gp_font_face::family_name.

◆ gp_font_height()

static unsigned int gp_font_height ( const gp_font_face font)
inlinestatic

Returns font height.

Attention
This call returns font height, the rendered text height may be different due to gp_text_style. In most cases you should use gp_text_height() instead.
Parameters
fontA font face.
Returns
A font height, eg. ascent + descent.

Definition at line 285 of file gp_font.h.

References gp_font_face::ascent, and gp_font_face::descent.

◆ gp_font_max_advance_x()

static unsigned int gp_font_max_advance_x ( const gp_font_face font)
inlinestatic

Returns maximal glyph advance.

For monospace fonts all advances are the same.

Parameters
fontA font face.
Returns
A maximal glyph width.

Definition at line 345 of file gp_font.h.

References gp_font_face::max_glyph_advance.

◆ gp_font_max_width()

static unsigned int gp_font_max_width ( const gp_font_face font)
inlinestatic

Returns maximal glyph width.

For monospace fonts all letter widths are the same.

Parameters
fontA font face.
Returns
A maximal glyph width.

Definition at line 331 of file gp_font.h.

References gp_font_face::max_glyph_width.

◆ gp_font_style_name()

const char * gp_font_style_name ( gp_font_style  style)

Returns font style name.

Returns font style name for a bitwise combination of the GP_FONT_STYLE_MASK bits.

Parameters
styleA font style.
Returns
A font style name.

◆ gp_glyph_get()

gp_glyph * gp_glyph_get ( const gp_font_face font,
uint32_t  ch 
)

Looks up a glyph in a font.

Parameters
fontA font face.
chAn unicode glyph.
Returns
A glyph structure.