microvg  3.0.1
microvg
Macros | Functions
microvg_helper.c File Reference

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

#include <LLVG_MATRIX_impl.h>
#include <freetype/internal/ftobjs.h>
#include "microvg_helper.h"
#include "microvg_configuration.h"

Go to the source code of this file.

Macros

#define MIN_HIGH_SURROGATE   ((unsigned short)0xD800)
 
#define MAX_HIGH_SURROGATE   ((unsigned short)0xDBFF)
 
#define MIN_LOW_SURROGATE   ((unsigned short)0xDC00)
 
#define MAX_LOW_SURROGATE   ((unsigned short)0xDFFF)
 
#define MIN_SUPPLEMENTARY_CODE_POINT   0x010000
 
#define GET_NEXT_CHARACTER(t, l, o)   ((o) >= (l) ? (unsigned short)0 : (t)[o])
 
#define IS_SIMPLE_LAYOUT   true
 

Functions

void MICROVG_HELPER_initialize (void)
 
int MICROVG_HELPER_get_utf (unsigned short *textCharRam, 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 MICROVG_HELPER_layout_configure (int faceHandle, unsigned short *text, int length)
 
bool MICROVG_HELPER_layout_load_glyph (int *glyph_idx, int *x_advance, int *y_advance, int *x_offset, int *y_offset)
 
jfloat * MICROVG_HELPER_check_matrix (jfloat *matrix)
 
uint32_t MICROVG_HELPER_apply_alpha (uint32_t color, uint32_t alpha)
 

Detailed Description

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

Author
MicroEJ Developer Team
Version
3.0.1

Definition in file microvg_helper.c.

Macro Definition Documentation

§ MIN_HIGH_SURROGATE

#define MIN_HIGH_SURROGATE   ((unsigned short)0xD800)

Sanity check between the expected version of the configuration and the actual version of the configuration. If an error is raised here, it means that a new version of the CCO has been installed and the configuration microvg_configuration.h must be updated based on the one provided by the new CCO version.

Definition at line 55 of file microvg_helper.c.

Function Documentation

§ MICROVG_HELPER_get_utf()

int MICROVG_HELPER_get_utf ( 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.

Definition at line 101 of file microvg_helper.c.

101  {
102 
103  unsigned short highPart = GET_NEXT_CHARACTER(textCharRam, length, *offset);
104  int ret = 0; // means "error" (see doc)
105 
106  if ((highPart >= MIN_HIGH_SURROGATE) && (highPart <= MAX_HIGH_SURROGATE)) {
107 
108  if (*offset < (length - 1)) {
109 
110  unsigned short lowPart = GET_NEXT_CHARACTER(textCharRam, length, *(offset) + 1);
111 
112  if ((lowPart >= MIN_LOW_SURROGATE) && (lowPart <= MAX_LOW_SURROGATE)) {
113  *offset += 2;
114 
115  ret = 0;
116  ret += ((int)highPart - (int)MIN_HIGH_SURROGATE);
117  ret <<= (int)10;
118  ret += ((int)lowPart - (int)MIN_LOW_SURROGATE);
119  ret += (int)MIN_SUPPLEMENTARY_CODE_POINT;
120  }
121  // else: invalid surrogate pair
122  }
123  // else: missing second part of surrogate pair
124  }
125  else {
126  *offset += 1;
127 
128  // standard character
129  ret = 0x0000FFFF & (int)highPart;
130  }
131 
132  return ret;
133 }
#define MIN_HIGH_SURROGATE