microvg  2.1.0
microvg
LLVG_FONT_PAINTER_freetype_bitmap.c
Go to the documentation of this file.
1 /*
2  * C
3  *
4  * Copyright 2021-2022 MicroEJ Corp. All rights reserved.
5  * Use of this source code is governed by a BSD-style license that can be found with this software.
6  */
7 
15 #include "microvg_configuration.h"
16 
17 #if defined (VG_FEATURE_FONT) && defined (VG_FEATURE_FONT_FREETYPE_BITMAP) && (VG_FEATURE_FONT == VG_FEATURE_FONT_FREETYPE_BITMAP)
18 
19 // -----------------------------------------------------------------------------
20 // Includes
21 // -----------------------------------------------------------------------------
22 
23 #include <math.h>
24 #include "ft2build.h"
25 
26 #include <LLVG_impl.h>
27 #include <LLVG_PATH_impl.h>
28 #include <LLVG_GRADIENT_impl.h>
29 #include <LLVG_MATRIX_impl.h>
30 #include <LLVG_FONT_impl.h>
31 #include <LLVG_FONT_PAINTER_impl.h>
32 #include <sni.h>
33 
34 #include "microvg_font_freetype.h"
35 #include "microvg_helper.h"
36 #include "freetype_bitmap_helper.h"
37 #include "bsp_util.h"
38 
39 // -----------------------------------------------------------------------------
40 // Macros
41 // ---------------------------------------------------------------------------
42 
43 
44 // -----------------------------------------------------------------------------
45 // Types
46 // -----------------------------------------------------------------------------
47 
48 
49 // -----------------------------------------------------------------------------
50 // Extern variables
51 // -----------------------------------------------------------------------------
52 
53 extern FT_Library library;
54 extern FT_Renderer renderer;
55 
56 // -----------------------------------------------------------------------------
57 // Global Variables
58 // -----------------------------------------------------------------------------
59 
60 // -----------------------------------------------------------------------------
61 // Internal function definitions
62 // -----------------------------------------------------------------------------
63 
81 void __draw_string(MICROUI_GraphicsContext* gc, FT_Face face, jfloat size, jchar* text, jint length, jint x, jint y, jint alpha, jint blend, jfloat letterSpacing, SNI_callback callback);
82 
83 
84 // -----------------------------------------------------------------------------
85 // LLVG_FONT_PAINTER API functions
86 // -----------------------------------------------------------------------------
87 
88 
89 jint LLVG_FONT_PAINTER_IMPL_draw_string(MICROUI_GraphicsContext* gc, jchar* text, jint faceHandle, jfloat size, jfloat x, jfloat y, jfloat* matrix, jint alpha, jint blend, jfloat letterSpacing){
90  FT_Face face = (FT_Face) faceHandle;
91  int length = SNI_getArrayLength(text);
92 
93  // add matrix translation to x,y variables
94  int local_x = (int) (x + matrix[2]);
95  int local_y = (int) (y + matrix[5]);
96 
97  __draw_string(gc, face, size, text, length, (jint)local_x, (jint)local_y, alpha, blend, letterSpacing, (SNI_callback)&LLVG_FONT_PAINTER_IMPL_draw_string);
98 
99  return (jint)LLVG_SUCCESS;
100 }
101 
102 
103 jint LLVG_FONT_PAINTER_IMPL_draw_string_gradient(MICROUI_GraphicsContext* gc, jchar* text, jint faceHandle, jfloat size, jfloat x, jfloat y, jfloat* matrix, jint alpha, jint blend, jfloat letterSpacing, jint *gradientData, jfloat *gradientMatrix){
104  SNI_throwNativeException(FREETYPE_NOT_IMPLEMENTED, "Native not implemented");
105 
106  // Avoid unusued parameter in misra cppcheck
107  (void)(gc);
108  (void)(text);
109  (void)(faceHandle);
110  (void)(size);
111  (void)(x);
112  (void)(y);
113  (void)(matrix);
114  (void)(alpha);
115  (void)(blend);
116  (void)(letterSpacing);
117  (void)(gradientData);
118  (void)(gradientMatrix);
119 
120  return (jint)LLVG_DATA_INVALID;
121 }
122 
123 jint LLVG_FONT_PAINTER_IMPL_draw_string_on_circle(MICROUI_GraphicsContext* gc, jchar* text, jint faceHandle, jfloat size, jint x, jint y, jfloat* matrix, jint alpha, jint blend, jfloat letterSpacing, jfloat radius, jint direction){
124  SNI_throwNativeException(FREETYPE_NOT_IMPLEMENTED, "Native not implemented");
125 
126  // Avoid unusued parameter in misra cppcheck
127  (void)(gc);
128  (void)(text);
129  (void)(faceHandle);
130  (void)(size);
131  (void)(x);
132  (void)(y);
133  (void)(matrix);
134  (void)(alpha);
135  (void)(blend);
136  (void)(letterSpacing);
137  (void)(radius);
138  (void)(direction);
139 
140  return (jint)LLVG_DATA_INVALID;
141 }
142 
143 jint LLVG_FONT_PAINTER_IMPL_draw_string_on_circle_gradient(MICROUI_GraphicsContext* gc, jchar* text, jint faceHandle, jfloat size, jint x, jint y, jfloat* matrix, jint alpha, jint blend, jfloat letterSpacing, jfloat radius, jint direction, jint *gradientData, jfloat *gradientMatrix){
144  SNI_throwNativeException(FREETYPE_NOT_IMPLEMENTED, "Native not implemented");
145 
146  // Avoid unusued parameter in misra cppcheck
147  (void)(gc);
148  (void)(text);
149  (void)(faceHandle);
150  (void)(size);
151  (void)(x);
152  (void)(y);
153  (void)(matrix);
154  (void)(alpha);
155  (void)(blend);
156  (void)(letterSpacing);
157  (void)(radius);
158  (void)(direction);
159  (void)(gradientData);
160  (void)(gradientMatrix);
161 
162  return (jint)LLVG_DATA_INVALID;
163 }
164 
165 
166 // -----------------------------------------------------------------------------
167 // Internal functions
168 // -----------------------------------------------------------------------------
169 
170 void __draw_string(MICROUI_GraphicsContext* gc, FT_Face face, jfloat size, jchar* text, jint length, jint x, jint y, jint alpha, jint blend, jfloat letterSpacing, SNI_callback callback){
171  Freetype_context_type local_freetype_context;
172 
173  if(!LLUI_DISPLAY_requestDrawing(gc, callback)){
174  MEJ_LOG_INFO_MICROVG("request drawing declined \n");
175 
176  } else {
177 
178  local_freetype_context.library = library;
179  local_freetype_context.renderer = renderer;
180  local_freetype_context.face = face;
181 
182  int char_height = (int)size;
183  local_freetype_context.error = FT_Set_Pixel_Sizes( local_freetype_context.face, 0, char_height);
184  if(FT_ERR(Ok) != local_freetype_context.error){
185  MEJ_LOG_INFO_MICROVG("error while setting font face size: %d\n", local_freetype_context.error);
186  }
187 
188  // Update the y coordinate to match the wanted start position with the top-left of the string
189  jint y_adapt = (jint) LLVG_FONT_IMPL_get_baseline_position((jint)local_freetype_context.face, size);
190  MEJ_LOG_INFO_MICROVG("y_adapt = %d \n", y_adapt);
191 
192  jint font_color;
193  font_color = (gc->foreground_color & 0x00FFFFFF) + (alpha << 24);
194 
195  (void)ft_helper_print_jstring_clipped(gc, &local_freetype_context, text, length, x, y + y_adapt, font_color, alpha, size, blend, letterSpacing);
196  if(!LLUI_DISPLAY_setDrawingLimits(x, y, gc->clip_x2, y+char_height)){
197  MEJ_LOG_INFO_MICROVG("Warning, drawing area out of the given graphics context!\n");
198  }
199  LLUI_DISPLAY_setDrawingStatus(DRAWING_DONE);
200  }
201 }
202 
203 // -----------------------------------------------------------------------------
204 // EOF
205 // -----------------------------------------------------------------------------
206 
207 #endif // #if (VG_FEATURE_FONT == VG_FEATURE_FONT_FREETYPE_BITMAP)
MicroEJ MicroVG library low level API: helper to implement library natives methods.
#define FREETYPE_NOT_IMPLEMENTED
Data structure for pack all the variables required by freetype handler.
int ft_helper_print_jstring_clipped(MICROUI_GraphicsContext *gc, Freetype_context_type *freetype_context, jchar *string, jint s_size, jint x, jint y, jint color, jint alpha, jfloat size, jint blend, jfloat letterSpacing)
Prints a string in a buffer respecting the clipping area of the MicroUI Graphics Context.
MicroEJ MicroVG library low level API: implementation over FreeType.
Freetype bitmap helper implementation header for VectorGraphics Low Level API.
MicroEJ MicroVG library low level API: enable some features according to the hardware capacities...