microvg  8.0.3
microvg
Macros | Functions
vg_helper.h File Reference

MicroEJ MicroVG library low level API: helper to implement library natives methods. More...

#include <sni.h>
#include "vg_configuration.h"

Go to the source code of this file.

Macros

#define VG_LOG_ERROR(fmt, ...)   VG_LOG_ERROR_PRINT(fmt, ## __VA_ARGS__)
 Logs an error. The format has no trailing line return. More...
 
#define VG_LOG_INFO(fmt, ...)
 Logs an informative message. The format has no trailing line return. More...
 
#define MEJ_LOG_ERROR_MICROVG(fmt, ...)   VG_LOG_ERROR(fmt, ## __VA_ARGS__)
 Deprecated, use VG_LOG_ERROR(). Kept for the Abstraction Layers that build on this one.
 
#define MEJ_LOG_INFO_MICROVG(fmt, ...)   VG_LOG_INFO(fmt, ## __VA_ARGS__)
 Deprecated, use VG_LOG_INFO(). Kept for the Abstraction Layers that build on this one.
 
#define VG_HELPER_NULL_GRADIENT   0
 Set this define to monitor freetype heap evolution. It needs VG_LOG_INFO_ENABLED to print the heap logs. More...
 
#define FT_FACE_FLAG_COMPLEX_LAYOUT   (((uint32_t)1) << 31)
 Freetype supplementary flag for complex layout Uses a free bit in freetype face flags to convey the complex layout mode information with the freetype face. freetype.h must be checked on freetype update to ensure that this bit is still free.
 
#define M_PI   3.1415926535
 
#define RAD_TO_DEG(r)   ((r) * (180.0f / M_PI))
 
#define DEG_TO_RAD(d)   (((d) * M_PI) / 180.0f)
 
#define JFLOAT_TO_UINT32_t(f)   (*(uint32_t *)&(f))
 
#define UINT32_t_TO_JFLOAT(i)   (*(float *)&(i))
 
#define REGISTERDESC(desc, buf, buf_len)   if ((buf_len) >= sizeof(desc)) { (void)memcpy((buf), (desc), sizeof(desc)); }
 Registers the description of a SNI close function.
 

Functions

void LLUI_DISPLAY_waitAsynchronousDrawingEnd (void)
 Waits until the end of current asynchronous drawing. More...
 
int VG_HELPER_get_utf (const unsigned short *text, int length, int *offset)
 Gets the UTF character from a text buffer at the given offset and updates the offset to point to the next character. More...
 
void VG_HELPER_layout_configure (int faceHandle, const unsigned short *text, int length)
 Configures the font layouter with a font and a text. More...
 
void VG_HELPER_layout_dispose (int faceHandle)
 Releases the font layouter's state built from a font face, when that face is about to be freed. Does nothing when the layouter holds no state for this face. More...
 
bool VG_HELPER_layout_load_glyph (uint32_t *glyph_idx, int *x_advance, int *y_advance, int *x_offset, int *y_offset)
 Loads the next layouted glyph and gets index and positions. More...
 
void VG_HELPER_layout_stop (void)
 Releases what the layouter still holds for the current iteration. Does nothing when there is nothing to release, so a caller that may or may not have stopped early calls it either way, and calling it twice is safe. More...
 
const jfloat * VG_HELPER_check_matrix (const jfloat *matrix)
 Checks if the matrix is null. In that case, returns an identity matrix. This allows to prevent to make some checks on the matrix in the algorithms. More...
 
uint32_t VG_HELPER_apply_alpha (uint32_t color, uint32_t alpha)
 Applies the global opacity on given color. More...
 
void VG_HELPER_prepare_matrix (jfloat *dest, jfloat x, jfloat y, const jfloat *matrix)
 Converts a MicroVG matrix in another MicroVG matrix applying a translation. More...
 

Detailed Description

MicroEJ MicroVG library low level API: helper to implement library natives methods.

Author
MicroEJ Developer Team
Version
8.0.3

Definition in file vg_helper.h.

Macro Definition Documentation

◆ VG_HELPER_NULL_GRADIENT

#define VG_HELPER_NULL_GRADIENT   0

Set this define to monitor freetype heap evolution. It needs VG_LOG_INFO_ENABLED to print the heap logs.

NULL Gradient value

Definition at line 75 of file vg_helper.h.

◆ VG_LOG_ERROR

#define VG_LOG_ERROR (   fmt,
  ... 
)    VG_LOG_ERROR_PRINT(fmt, ## __VA_ARGS__)

Logs an error. The format has no trailing line return.

The errors are always compiled. The printer is VG_LOG_ERROR_PRINT() (see vg_configuration.h).

Definition at line 42 of file vg_helper.h.

◆ VG_LOG_INFO

#define VG_LOG_INFO (   fmt,
  ... 
)

Logs an informative message. The format has no trailing line return.

Compiled only when VG_LOG_INFO_ENABLED is 1. The printer is VG_LOG_INFO_PRINT() (see vg_configuration.h).

Definition at line 53 of file vg_helper.h.

Function Documentation

◆ LLUI_DISPLAY_waitAsynchronousDrawingEnd()

void LLUI_DISPLAY_waitAsynchronousDrawingEnd ( void  )

Waits until the end of current asynchronous drawing.

To avoid potential side effects from the release of objects (images, fonts) retained by a feature during the killing of that feature, ensure that no third-party components (e.g., GPU) are using these objects at the time of the kill.

UI packs with versions higher than 14.5.1 provide the blocking API LLUI_DISPLAY_waitAsynchronousDrawingEnd(). This API is stubbed on the VG Pack for backward compatibility issues between VG Pack 1.8.0 and UI Packs [14.4.0, 14.5.1]. However, it is highly recommended to use a UI Pack version greater than 14.5.1.

Definition at line 157 of file vg_helper.c.

157  {
158  // cannot wait the end of drawing with UI packs [14.4.0-14.5.1]
159 }

◆ VG_HELPER_apply_alpha()

uint32_t VG_HELPER_apply_alpha ( uint32_t  color,
uint32_t  alpha 
)

Applies the global opacity on given color.

Parameters
[in]colorthe 32-bit color.
[in]alphathe opacity.
Returns
the new color.

Definition at line 352 of file vg_helper.c.

352  {
353  uint32_t color_alpha = (((color >> 24) & (uint32_t)0xff) * alpha) / (uint32_t)255;
354  return (color & (uint32_t)0xffffff) | (color_alpha << 24);
355 }

◆ VG_HELPER_check_matrix()

const jfloat* VG_HELPER_check_matrix ( const jfloat *  matrix)

Checks if the matrix is null. In that case, returns an identity matrix. This allows to prevent to make some checks on the matrix in the algorithms.

The identity matrix can be used several times by the same algorithm. The caller must not modify it (read-only matrix).

Parameters
[in]matrixthe matrix to check
Returns
the matrix or an identity matrix

Definition at line 347 of file vg_helper.c.

347  {
348  return (NULL == matrix) ? g_identity_matrix : matrix;
349 }

◆ VG_HELPER_get_utf()

int VG_HELPER_get_utf ( const unsigned short *  text,
int  length,
int *  offset 
)

Gets the UTF character from a text buffer at the given offset and updates the offset to point to the next character.

Some characters have some special values; they are made up of two Unicode characters in two specific ranges such that the first Unicode character is in one range (for example 0xD800-0xD8FF) and the second Unicode character is in the second range (for example 0xDC00-0xDCFF). This is called a surrogate pair.

If a surrogate pair is incomplete (missing second character), this function returns "0" (error) and does not update the offset.

Parameters
[in]texttext buffer encoded in UTF16 where to read UTF character.
[in]lengthlenght of the text buffer.
[in,out]offsetoffset in the text buffer where to read UTF character. Updated to the next character position.
Returns
The decoded UTF character.

Definition at line 166 of file vg_helper.c.

166  {
167  unsigned short highPart = GET_NEXT_CHARACTER(textCharRam, length, *offset);
168  int ret = 0; // means "error" (see doc)
169 
170  if ((highPart >= MIN_HIGH_SURROGATE) && (highPart <= MAX_HIGH_SURROGATE)) {
171  if (*offset < (length - 1)) {
172  unsigned short lowPart = GET_NEXT_CHARACTER(textCharRam, length, *(offset) + 1);
173 
174  if ((lowPart >= MIN_LOW_SURROGATE) && (lowPart <= MAX_LOW_SURROGATE)) {
175  *offset += 2;
176 
177  ret = 0;
178  ret += ((int)highPart - (int)MIN_HIGH_SURROGATE);
179  ret <<= (int)10;
180  ret += ((int)lowPart - (int)MIN_LOW_SURROGATE);
181  ret += (int)MIN_SUPPLEMENTARY_CODE_POINT;
182  }
183  // else: invalid surrogate pair
184  }
185  // else: missing second part of surrogate pair
186  } else {
187  *offset += 1;
188 
189  // standard character
190  ret = 0x0000FFFF & (int)highPart;
191  }
192 
193  return ret;
194 }

◆ VG_HELPER_layout_configure()

void VG_HELPER_layout_configure ( int  faceHandle,
const unsigned short *  text,
int  length 
)

Configures the font layouter with a font and a text.

Releases what an iteration left open, as VG_HELPER_layout_stop() does, so a caller that stops before the end of its own iteration costs the next caller nothing.

Parameters
[in]faceHandlehandle on font face.
[in]texttext buffer encoded in UTF16 where to read UTF character.
[in]lengthtext buffer length.

◆ VG_HELPER_layout_dispose()

void VG_HELPER_layout_dispose ( int  faceHandle)

Releases the font layouter's state built from a font face, when that face is about to be freed. Does nothing when the layouter holds no state for this face.

Must be called before the face itself is freed: the state holds the face and reads through it for its whole life.

Parameters
[in]faceHandlehandle on the font face being freed.

◆ VG_HELPER_layout_load_glyph()

bool VG_HELPER_layout_load_glyph ( uint32_t *  glyph_idx,
int *  x_advance,
int *  y_advance,
int *  x_offset,
int *  y_offset 
)

Loads the next layouted glyph and gets index and positions.

Parameters
[out]glyph_idxnext glyph index.
[out]x_advancethe horizontal advance to add to the cursor position after drawing the glyph.
[out]y_advancethe vertical advance to add to thecursor after drawing the glyph.
[out]x_offsetthe hozizontal offset of the glyph, does not affect the cursor position.
[out]y_offsetthe vertical offset of the glyph, does not affect the cursor position.
Returns
true if a glyph is available otherwise false.

◆ VG_HELPER_layout_stop()

void VG_HELPER_layout_stop ( void  )

Releases what the layouter still holds for the current iteration. Does nothing when there is nothing to release, so a caller that may or may not have stopped early calls it either way, and calling it twice is safe.

It does not reset the reading position, so the next iteration starts with VG_HELPER_layout_configure() as it always did.

◆ VG_HELPER_prepare_matrix()

void VG_HELPER_prepare_matrix ( jfloat *  dest,
jfloat  x,
jfloat  y,
const jfloat *  matrix 
)

Converts a MicroVG matrix in another MicroVG matrix applying a translation.

Parameters
[out]destthe MicroVG matrix to set
[in]xthe X translation to apply
[in]ythe Y translation to apply
[in]matrixthe MicroVG transformation to apply (can be null)

Definition at line 358 of file vg_helper.c.

358  {
359  const jfloat *local_matrix = VG_HELPER_check_matrix(matrix);
360 
361  if ((0 != x) || (0 != y)) {
362  // Create translate matrix for initial x,y translation from graphicscontext.
363  LLVG_MATRIX_IMPL_setTranslate(dest, x, y);
364  LLVG_MATRIX_IMPL_concatenate(dest, local_matrix);
365  } else {
366  // use original matrix
367  LLVG_MATRIX_IMPL_copy(dest, local_matrix);
368  }
369 }
const jfloat * VG_HELPER_check_matrix(const jfloat *matrix)
Checks if the matrix is null. In that case, returns an identity matrix. This allows to prevent to mak...
Definition: vg_helper.c:347