microvg  6.0.1
microvg
Macros | Functions | Variables
vg_helper.c File Reference

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

#include "vg_configuration.h"
#include <LLVG_MATRIX_impl.h>
#include "vg_helper.h"
#include "vg_trace.h"
#include "vg_drawing.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 VG_HELPER_initialize (void)
 
int VG_HELPER_get_utf (const 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...
 
const jfloat * VG_HELPER_check_matrix (const jfloat *matrix)
 
uint32_t VG_HELPER_apply_alpha (uint32_t color, uint32_t alpha)
 
void VG_HELPER_prepare_matrix (jfloat *dest, jfloat x, jfloat y, const jfloat *matrix)
 

Variables

int32_t VG_TRACE_group_id
 

Detailed Description

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

Author
MicroEJ Developer Team
Version
6.0.1

Definition in file vg_helper.c.

Function Documentation

◆ 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]offset: offset in the text buffer where to read UTF character. Updated to the next character position.
Returns
The decoded UTF character.

Definition at line 164 of file vg_helper.c.

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