1 /**************************************************************************** 2 * 3 * The MIT License (MIT) 4 * 5 * Copyright 2020 NXP 6 * All Rights Reserved. 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining 9 * a copy of this software and associated documentation files (the 10 * 'Software'), to deal in the Software without restriction, including 11 * without limitation the rights to use, copy, modify, merge, publish, 12 * distribute, sub license, and/or sell copies of the Software, and to 13 * permit persons to whom the Software is furnished to do so, subject 14 * to the following conditions: 15 * 16 * The above copyright notice and this permission notice (including the 17 * next paragraph) shall be included in all copies or substantial 18 * portions of the Software. 19 * 20 * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 23 * IN NO EVENT SHALL VIVANTE AND/OR ITS SUPPLIERS BE LIABLE FOR ANY 24 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 * 28 *****************************************************************************/ 29 #ifndef _vg_lite_text_h_ 30 #define _vg_lite_text_h_ 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #include "vg_lite.h" 37 38 /* Macros *********************************************************************/ 39 40 #define MAX_FONT_NAME_LEN (64) 41 #define VG_LITE_INVALID_FONT (-1) 42 #define INVALID_FONT_PROPERTY_IDX (-1) 43 44 /* Types **********************************************************************/ 45 46 /*! 47 @abstract Font Type enumeration 48 49 @discussion 50 This enumeration defines supported high level font type type. 51 */ 52 typedef enum eFontType { 53 eFontTypeVector, 54 eFontTypeRaster 55 } eFontType_t; 56 57 /*! 58 @abstract Font weight enumeration 59 60 @discussion 61 This enumeration defines font weight that maps to css specification 62 */ 63 typedef enum eFontWeight { 64 eFontWeightThin = 100, /*! Thin, Hairline, Ultra-light, Extra-light */ 65 eFontWeightLight = 200, /*! Light */ 66 eFontWeightBook = 300, /*! Book */ 67 eFontWeightRegular = 400, /*! Regular, Normal, Plain, Roman, Standard */ 68 eFontWeightMedium = 500, /*! Medium */ 69 eFontWeightSemiBold = 600, /*! Semi-bold, Demi-bold */ 70 eFontWeightBold = 700, /*! Bold */ 71 eFontWeightHeavy = 800, /*! Heavy, Black, Extra-bold */ 72 eFontUltraBlack = 900, /*! Ultra-black, Extra-black, Ultra-bold, 73 Heavy-black, Fat, Poster */ 74 } eFontWeight_t; 75 76 /*! 77 @abstract Font stretch enumeration 78 79 @discussion 80 This enumeration defines font stretch that maps to css specification 81 */ 82 typedef enum eFontStretch { 83 eFontStretchUltraCondensed = 1, /*! ultra-condensed */ 84 eFontStretchExtraCondensed = 2, /*! extra-condensed */ 85 eFontStretchCondensed = 3, /*! condensed */ 86 eFontStretchSemiCondensed = 4, /*! semi-condensed */ 87 eFontStretchNormal = 5, /*! normal */ 88 eFontStretchSemiExpanded = 6, /*! semi-expanded */ 89 eFontStretchExpanded = 7, /*! expanded */ 90 eFontStretchExtraExpanded = 8, /*! extra-expanded */ 91 eFontStretchUltraExpanded = 9, /*! ultra-expanded */ 92 } eFontStretch_t; 93 94 /*! 95 @abstract Font style enumeration 96 97 @discussion 98 This enumeration defines font style that maps to css specification 99 */ 100 typedef enum eFontStyle { 101 eFontStyleNormal = 1, /*! normal */ 102 eFontStyleItalic = 2, /*! italic, oblique */ 103 } eFontStyle_t; 104 105 /*! 106 @abstract Text alignment enumeration 107 108 @discussion 109 This enumeration defines text alignment that maps to css specification 110 */ 111 typedef enum eTextAlign { 112 eTextAlignLeft, 113 eTextAlignCenter, 114 eTextAlignRight, 115 eTextAlignJustify, 116 } eTextAlign_t; 117 118 /* Structures *****************************************************************/ 119 120 /*! 121 @abstract Font parameters 122 123 @discussion 124 This datastructure specifies application font and its data. Application 125 can register as many font as required using vg_lite_register_font 126 And lateron refer them in vg_lite_draw_text API 127 128 for raster fonts mandatory fields are: 129 name, 130 font_weight, font_stretch, font_style, font_height 131 data, data_len 132 for vector fonts mandatory fields are: 133 name, 134 data, data_len 135 */ 136 typedef struct vg_lite_font_params 137 { 138 char name[MAX_FONT_NAME_LEN]; /*! font-family name */ 139 eFontType_t font_type; /*! Raster/Vector font */ 140 eFontWeight_t font_weight; /*! Font weight enum value */ 141 eFontStretch_t font_stretch; /*! Font stretch enum value */ 142 eFontStyle_t font_style; /*! Font style enum value */ 143 int font_height; /*! Font height in pixels */ 144 int data_len; /*! Font data buffer length */ 145 void *data; /*! the address where the actual font data is stored; it is the 146 * responsibility of the user/application to load it there */ 147 } vg_lite_font_params_t; 148 149 /*! 150 @abstract Opaque type for font descriptor 151 152 @discussion 153 This is an index of into font-table. Font table can have atmost 154 MAX_SYSTEM_FONTS font, registering more font results in an error. 155 */ 156 typedef uint32_t vg_lite_font_t; 157 158 /*! 159 @abstract Runtime parameter to render text using given font 160 161 @discussion 162 These parameters controls rendering of text using given font. 163 */ 164 typedef struct { 165 /* Application controllable parameters */ 166 int justify; /*! Equal justify given text in text display area */ 167 int alignment; /*! Ailgn text to left, center or right */ 168 169 int width; /*! Internal variable computed based on active font */ 170 int height; /*! Internal variable computed based on active font */ 171 172 unsigned int text_color; /*! Foreground text color */ 173 unsigned int bg_color; /*! Background text color */ 174 175 int tspan_has_dx_dy; /*! 0 means tspan element has x,y values 176 1 means tspan element has dx, dy values 177 so use last_x+dx for x, 178 last_y+dy for y 179 */ 180 int is_vector_font; /*! 1 when active font is vector font, 0 otherwise */ 181 182 int margin; /*! Left and right margin in pixels that should be skipped 183 by text rendering engine */ 184 int anchor; /*! Anchor text */ 185 int scale; /*! Flag that indicate if text rendering engine should 186 scale text */ 187 188 /* Internal parameters of text rendering engine. 189 Application code should not modify these parameters 190 */ 191 int font_height; /*! Font height in pixels, parameter from svg */ 192 int last_x; /*! Last x position of text element */ 193 int last_y; /*! Last y position of text element */ 194 int last_dx; /*! Horizontal width of text in pixels, for last text */ 195 } vg_lite_font_attributes_t; 196 197 /* API Function prototypes ****************************************************/ 198 199 /*! 200 @abstract Registers application specific font in vg_ltie driver. 201 202 @discussion 203 Using <code>vg_lite_register_font</code> application can register active 204 fonts that <code>vg_lite_draw_text</code> uses to render text. 205 206 for raster fonts mandatory fields of <code>vg_lite_font_params_t</code> are: 207 name, 208 font_weight, font_stretch, font_style, font_height 209 data, data_len 210 for vector fonts mandatory fields of <code>vg_lite_font_params_t</code> are: 211 name, 212 data, data_len 213 214 On successful registeration <code>font</code> poiter will get non-negative 215 application handle. 216 217 @param font 218 Pointer to font handle 219 220 @param params 221 Pointer to font parameters that are used by <code>vg_lite_find_font</code> 222 to select specific font for rendering text 223 224 @result 225 Returns the status as defined by <code>vg_lite_error_t</code>. 226 VG_LITE_SUCCESS when font registation is success 227 VG_LITE_INVALID_ARGUMENT When parameter pointer is invalid 228 VG_LITE_ALREADY_EXISTS if font name already exists 229 VG_LITE_OUT_OF_RESOURCES if active font exceeds MAX_SYSTEM_FONTS 230 */ 231 vg_lite_error_t vg_lite_register_font( 232 vg_lite_font_t *font, 233 vg_lite_font_params_t *params); 234 235 /*! 236 @abstract Un-registers application specific font in vg_ltie driver. 237 238 @discussion 239 <code>vg_lite_unregister_font</code> unregisters application speciific 240 font form vg_lite driver. This font can not be used lateron by 241 <code>vg_lite_draw_text</code> API. 242 243 @param font 244 Pointer to font handle 245 246 @result 247 Returns the status as defined by <code>vg_lite_error_t</code>. 248 VG_LITE_SUCCESS when font registation is success 249 VG_LITE_INVALID_ARGUMENT if font handle is invalid 250 */ 251 vg_lite_error_t vg_lite_unregister_font(vg_lite_font_t font); 252 253 254 /*! 255 @abstract Check if given font is vector/raster ? 256 257 @discussion 258 <code>vg_lite_is_vector_font</code> API lookups active fonts in 259 vg_lite driver and if font it found it return 1 if it points to vector font 260 otherwise it return 0; 261 262 @param font 263 Pointer to font handle 264 265 @result 266 Returns the status as defined by <code>vg_lite_error_t</code>. 267 VG_LITE_SUCCESS when font registation is success 268 VG_LITE_INVALID_ARGUMENT if font handle is invalid 269 */ 270 int vg_lite_is_vector_font(vg_lite_font_t font); 271 272 /*! 273 @abstract This API renders text with specified font on render target. 274 275 @discussion 276 This API can reder text using user supplied font. Text rendering can be 277 controlled by <code>vg_lite_font_attributes_t</code>. 278 279 @param target 280 Pointer to render target 281 282 @param text 283 ASCII text that needs to be rendered on render 284 285 @param font 286 Pointer to font handle 287 288 @param x 289 x position in pixels in X-axis for text rendering 290 291 @param y 292 y position in pixels in Y-axis for text rendering 293 294 @param matrix 295 Translation matrix that is used while rendering text. 296 @attention Scaling and rotation matrix are not supported. 297 298 @param blend 299 Specifies how text gets blened in text area. Typical value is ELM_BLEND_SRC_OVER 300 301 @param attributes 302 Font attributes that controls how text gets rendered in render buffer. 303 304 @result 305 Returns the status as defined by <code>vg_lite_error_t</code>. 306 VG_LITE_SUCCESS when font registation is success 307 VG_LITE_INVALID_ARGUMENT if input parameters have any issue 308 */ 309 vg_lite_error_t vg_lite_draw_text( 310 vg_lite_buffer_t *target, 311 char *text, 312 vg_lite_font_t font, 313 int x, 314 int y, 315 vg_lite_matrix_t *matrix, 316 vg_lite_blend_t blend, 317 vg_lite_font_attributes_t *attributes); 318 319 /*! 320 @abstract This API searches registered font for given name with 321 requested rendering capabilities. 322 323 @discussion 324 This API searches registered font for given name with 325 requested rendering capabilities. 326 327 for raster fonts following fields are compared 328 name, 329 font_weight, font_stretch, font_style, font_height 330 331 for vector fonts following fields are compared 332 name 333 334 @param font_name 335 Font name 336 337 @param font_weight 338 Font weight value from eFontWeight_t 339 340 @param font_stretch 341 Font stretch value from eFontStretch_t 342 343 @param font_style 344 Font style value from eFontStyle_t 345 346 @param font_height 347 Font height in pixels 348 349 If during font lookup a validate font is found then it retuns its handle. 350 351 @result 352 Returns valid font handle or an error code. 353 Valid font handle if input parameters matches any of registerd font. 354 INVALID_FONT if input parameters don't match registered fonts. 355 */ 356 vg_lite_font_t vg_lite_find_font( 357 char *font_name, 358 eFontWeight_t font_weight, 359 eFontStretch_t font_stretch, 360 eFontStyle_t font_style, 361 int font_height); 362 363 /*! 364 @abstract Initializes support for text drawing. 365 */ 366 void vg_lite_text_init(void); 367 368 #ifdef __cplusplus 369 } 370 #endif 371 372 #endif /* _vg_lite_text_h_ */ 373