microvg  8.0.3
microvg
Typedefs | Functions
vg_freetype.h File Reference

MicroEJ MicroVG library low level API: implementation over FreeType. More...

#include "vg_configuration.h"
#include "vg_path.h"

Go to the source code of this file.

Typedefs

typedef jint(* VG_FREETYPE_draw_glyph_t) (VG_PATH_HEADER_t *path, jfloat *matrix, uint32_t color, bool fill_rule_even_odd, void *user_data)
 Function to draw a character element: a glyph. A glyph is a vectorial path. More...
 

Functions

void VG_FREETYPE_initialize (void)
 Initializes the lowlevel font library.
 
bool VG_FREETYPE_string_span (const jchar *text, jint length, jint face_handle, jfloat letter_spacing_font_units, jfloat *left, jfloat *right)
 Folds the ink of a string and returns its two extreme edges. More...
 
jfloat VG_FREETYPE_string_width (jchar *text, jint length, jint face_handle, jfloat size, jfloat letter_spacing)
 Measures the width of a text for the specified font and size. More...
 
jfloat VG_FREETYPE_get_scale (jint face_handle, jfloat size)
 Computes the scale that converts font units to pixels at the given size. More...
 
jint VG_FREETYPE_draw_string (VG_FREETYPE_draw_glyph_t drawer, const jchar *text, jint length, jint face_handle, jfloat size, const jfloat *matrix, uint32_t color, jfloat letter_spacing, jfloat radius, jint direction, void *user_data)
 Draws a string using the Freetype engine along a line or a circle, with a color or a linear gradient. The implementation does not draw, it calls the drawer function for each glyph: VG_FREETYPE_draw_glyph_t. More...
 
jint VG_FREETYPE_IMPL_convert_color (jint color)
 

Detailed Description

MicroEJ MicroVG library low level API: implementation over FreeType.

Author
MicroEJ Developer Team
Version
8.0.3

Definition in file vg_freetype.h.

Typedef Documentation

◆ VG_FREETYPE_draw_glyph_t

typedef jint(* VG_FREETYPE_draw_glyph_t) ( VG_PATH_HEADER_t *path, jfloat *matrix, uint32_t color, bool fill_rule_even_odd, void *user_data)

Function to draw a character element: a glyph. A glyph is a vectorial path.

This function is called by VG_FREETYPE_draw_string(). Two implementations are required: one that draws the path with a color and one that draws the path with a gradient.

The list of the drawing parameters is reduced to the elements that the Freetype engine changes for each glyph: the glyph's path, the transformation to apply on the glyph, the glyph color (useful for colored glyphs like emoji), the glyph's outine.

All others elements required by the drawer (if any) have to be listed in the dedicated structure user_data.

Returns
: the MicroVG error code

Definition at line 56 of file vg_freetype.h.

Function Documentation

◆ VG_FREETYPE_draw_string()

jint VG_FREETYPE_draw_string ( VG_FREETYPE_draw_glyph_t  drawer,
const jchar *  text,
jint  length,
jint  face_handle,
jfloat  size,
const jfloat *  matrix,
uint32_t  color,
jfloat  letter_spacing,
jfloat  radius,
jint  direction,
void *  user_data 
)

Draws a string using the Freetype engine along a line or a circle, with a color or a linear gradient. The implementation does not draw, it calls the drawer function for each glyph: VG_FREETYPE_draw_glyph_t.

Parameters
[in]drawerthe function to draw a glyph.
[in]textthe array of characters to draw.
[in]lengththe length of the array
[in]face_handlethe font reference handle.
[in]sizethe height of the font in pixels.
[in]matrixthe transformation to apply.
[in]colorthe 32-bit color to apply (useless when drawing with a gradient).
[in]letter_spacingthe extra letter spacing to use.
[in]radiusthe radius of the circle (0 to draw along a line).
[in]directionthe direction of the text along the circle (0 to draw along a line).
[in]user_datathe data used by the drawer; may be null.
Returns
LLVG_SUCCESS if something has been drawn, an different value otherwise

◆ VG_FREETYPE_get_scale()

jfloat VG_FREETYPE_get_scale ( jint  face_handle,
jfloat  size 
)

Computes the scale that converts font units to pixels at the given size.

LLVG_FONT_IMPL_load_font() refuses a face whose EM size is 0, so the division is always defined.

Parameters
[in]face_handlethe font reference handle.
[in]sizethe height of the font in pixels.
Returns
the size of one font unit, in pixels.

◆ VG_FREETYPE_string_span()

bool VG_FREETYPE_string_span ( const jchar *  text,
jint  length,
jint  face_handle,
jfloat  letter_spacing_font_units,
jfloat *  left,
jfloat *  right 
)

Folds the ink of a string and returns its two extreme edges.

Every glyph is placed at its own pen position, and a glyph that draws nothing contributes no edge at either end. The pen carries the letter spacing, so a string that draws no glyph has no span whatever the spacing is.

Returns the two extreme edges of the ink; the caller decides what to do with them.

A caller that passes NULL for the right edge asks for the left one alone. The fold then stops as soon as no remaining glyph can reach further left, so it reads a few glyphs instead of the whole string. It returns the same left edge as a full fold as long as no glyph is placed more than one EM to the left of its own pen position, which is the margin the stop keeps; a letter spacing below zero and an advance seen to be negative each disable the stop instead of narrowing that margin.

The function leaves no iteration open, so a caller that iterates afterwards must call VG_HELPER_layout_configure() again.

Parameters
[in]textthe array of characters to fold.
[in]lengththe length of the array.
[in]face_handlethe font reference handle.
[in]letter_spacing_font_unitsthe extra letter spacing, in font units.
[out]leftthe left edge of the ink, in font units; untouched when no glyph draws.
[out]rightthe right edge of the ink, in font units; untouched when no glyph draws. NULL asks for the left edge alone, which lets the fold stop before the end of the string.
Returns
true when at least one glyph draws, false when none does.

◆ VG_FREETYPE_string_width()

jfloat VG_FREETYPE_string_width ( jchar *  text,
jint  length,
jint  face_handle,
jfloat  size,
jfloat  letter_spacing 
)

Measures the width of a text for the specified font and size.

The width is the union of the ink of every glyph, each at its own pen position: the leftmost pixel any glyph draws to the rightmost, whichever glyphs those are. A character that draws nothing contributes nothing, at either end.

Parameters
[in]textthe array of characters to draw.
[in]lengththe length of the array
[in]face_handlethe font reference handle
[in]sizethe height of the font in pixels.
[in]letter_spacingthe extra letter spacing to use
Returns
the width of the specified string, in pixels, never negative.