summaryrefslogtreecommitdiff
path: root/bsp/nxp/imx/imxrt/libraries/drivers/vglite/inc/vg_lite_text.h
blob: 3c519b1e56feb562de04eea98193b79c28bce058 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/****************************************************************************
*
*    The MIT License (MIT)
*
*    Copyright 2020 NXP
*    All Rights Reserved.
*
*    Permission is hereby granted, free of charge, to any person obtaining
*    a copy of this software and associated documentation files (the
*    'Software'), to deal in the Software without restriction, including
*    without limitation the rights to use, copy, modify, merge, publish,
*    distribute, sub license, and/or sell copies of the Software, and to
*    permit persons to whom the Software is furnished to do so, subject
*    to the following conditions:
*
*    The above copyright notice and this permission notice (including the
*    next paragraph) shall be included in all copies or substantial
*    portions of the Software.
*
*    THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
*    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
*    IN NO EVENT SHALL VIVANTE AND/OR ITS SUPPLIERS BE LIABLE FOR ANY
*    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
*    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
*    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*****************************************************************************/
#ifndef _vg_lite_text_h_
#define _vg_lite_text_h_

#ifdef __cplusplus
extern "C" {
#endif

#include "vg_lite.h"

/* Macros *********************************************************************/

#define MAX_FONT_NAME_LEN               (64)
#define VG_LITE_INVALID_FONT            (-1)
#define INVALID_FONT_PROPERTY_IDX       (-1)

/* Types **********************************************************************/

    /*!
     @abstract Font Type enumeration

     @discussion
     This enumeration defines supported high level font type type.
     */
    typedef enum eFontType {
      eFontTypeVector,
      eFontTypeRaster
    } eFontType_t;

    /*!
     @abstract Font weight enumeration

     @discussion
     This enumeration defines font weight that maps to css specification
     */
    typedef enum eFontWeight {
        eFontWeightThin     = 100, /*! Thin, Hairline, Ultra-light, Extra-light */
        eFontWeightLight    = 200, /*! Light */
        eFontWeightBook     = 300, /*! Book */
        eFontWeightRegular  = 400, /*! Regular, Normal, Plain, Roman, Standard */
        eFontWeightMedium   = 500, /*! Medium */
        eFontWeightSemiBold = 600, /*! Semi-bold, Demi-bold */
        eFontWeightBold     = 700, /*! Bold */
        eFontWeightHeavy    = 800, /*! Heavy, Black, Extra-bold */
        eFontUltraBlack     = 900, /*! Ultra-black, Extra-black, Ultra-bold,
                                      Heavy-black, Fat, Poster */
    } eFontWeight_t;

    /*!
     @abstract Font stretch enumeration

     @discussion
     This enumeration defines font stretch that maps to css specification
     */
    typedef enum eFontStretch {
        eFontStretchUltraCondensed  = 1, /*! ultra-condensed */
        eFontStretchExtraCondensed  = 2, /*! extra-condensed */
        eFontStretchCondensed       = 3, /*! condensed */
        eFontStretchSemiCondensed   = 4, /*! semi-condensed */
        eFontStretchNormal          = 5, /*! normal */
        eFontStretchSemiExpanded    = 6, /*! semi-expanded */
        eFontStretchExpanded        = 7, /*! expanded */
        eFontStretchExtraExpanded   = 8, /*! extra-expanded */
        eFontStretchUltraExpanded   = 9, /*! ultra-expanded */
    } eFontStretch_t;

    /*!
     @abstract Font style enumeration

     @discussion
     This enumeration defines font style that maps to css specification
     */
    typedef enum eFontStyle {
        eFontStyleNormal  = 1, /*! normal */
        eFontStyleItalic  = 2, /*! italic, oblique */
    } eFontStyle_t;

    /*!
     @abstract Text alignment enumeration

     @discussion
     This enumeration defines text alignment that maps to css specification
     */
    typedef enum eTextAlign {
      eTextAlignLeft,
      eTextAlignCenter,
      eTextAlignRight,
      eTextAlignJustify,
    } eTextAlign_t;

/* Structures *****************************************************************/

    /*!
     @abstract Font parameters

     @discussion
     This datastructure specifies application font and its data. Application
     can register as many font as required using vg_lite_register_font
     And lateron refer them in vg_lite_draw_text API

     for raster fonts mandatory fields are:
       name,
       font_weight, font_stretch, font_style, font_height
       data, data_len
     for vector fonts mandatory fields are:
       name,
       data, data_len
     */
    typedef struct vg_lite_font_params
    {
        char name[MAX_FONT_NAME_LEN]; /*! font-family name */
        eFontType_t    font_type;     /*! Raster/Vector font */
        eFontWeight_t   font_weight;  /*! Font weight enum value */
        eFontStretch_t  font_stretch; /*! Font stretch enum value */
        eFontStyle_t    font_style;   /*! Font style enum value */
        int font_height;              /*! Font height in pixels */
        int data_len;                 /*! Font data buffer length */
        void *data; /*! the address where the actual font data is stored; it is the
                     * responsibility of the user/application to load it there */
    } vg_lite_font_params_t;

    /*!
     @abstract Opaque type for font descriptor

     @discussion
     This is an index of into font-table. Font table can have atmost
     MAX_SYSTEM_FONTS font, registering more font results in an error.
     */
    typedef uint32_t vg_lite_font_t;

    /*!
     @abstract Runtime parameter to render text using given font

     @discussion
     These parameters controls rendering of text using given font.
     */
    typedef struct {
        /* Application controllable parameters */
        int justify; /*! Equal justify given text in text display area */
        int alignment; /*! Ailgn text to left, center or right */

        int width;  /*! Internal variable computed based on active font */
        int height; /*! Internal variable computed based on active font */

        unsigned int text_color; /*! Foreground text color */
        unsigned int bg_color;   /*! Background text color */

        int tspan_has_dx_dy; /*! 0 means tspan element has x,y values
                              1 means tspan element has dx, dy values
                                so use last_x+dx for x,
                                       last_y+dy for y
                           */
        int is_vector_font; /*! 1 when active font is vector font, 0 otherwise */

        int margin; /*! Left and right margin in pixels that should be skipped
                       by text rendering engine */
        int anchor; /*! Anchor text */
        int scale;  /*! Flag that indicate if text rendering engine should
                        scale text */

        /* Internal parameters of text rendering engine.
           Application code should not modify these parameters
        */
        int font_height; /*! Font height in pixels, parameter from svg */
        int last_x;      /*! Last x position of text element */
        int last_y;      /*! Last y position of text element */
        int last_dx;     /*! Horizontal width of text in pixels, for last text */
    } vg_lite_font_attributes_t;

  /* API Function prototypes ****************************************************/

    /*!
     @abstract Registers application specific font in vg_ltie driver.

     @discussion
     Using <code>vg_lite_register_font</code> application can register active
     fonts that <code>vg_lite_draw_text</code> uses to render text.

     for raster fonts mandatory fields of <code>vg_lite_font_params_t</code> are:
       name,
       font_weight, font_stretch, font_style, font_height
       data, data_len
     for vector fonts mandatory fields of <code>vg_lite_font_params_t</code> are:
       name,
       data, data_len

     On successful registeration <code>font</code> poiter will get non-negative
     application handle.

     @param font
     Pointer to font handle

     @param params
     Pointer to font parameters that are used by <code>vg_lite_find_font</code>
     to select specific font for rendering text

     @result
     Returns the status as defined by <code>vg_lite_error_t</code>.
        VG_LITE_SUCCESS when font registation is success
        VG_LITE_INVALID_ARGUMENT When parameter pointer is invalid
        VG_LITE_ALREADY_EXISTS if font name already exists
        VG_LITE_OUT_OF_RESOURCES if active font exceeds MAX_SYSTEM_FONTS
     */
    vg_lite_error_t vg_lite_register_font(
                      vg_lite_font_t *font,
                      vg_lite_font_params_t *params);

    /*!
     @abstract Un-registers application specific font in vg_ltie driver.

     @discussion
     <code>vg_lite_unregister_font</code> unregisters application speciific
     font form vg_lite driver. This font can not be used lateron by
     <code>vg_lite_draw_text</code> API.

     @param font
     Pointer to font handle

     @result
     Returns the status as defined by <code>vg_lite_error_t</code>.
        VG_LITE_SUCCESS when font registation is success
        VG_LITE_INVALID_ARGUMENT if font handle is invalid
     */
    vg_lite_error_t vg_lite_unregister_font(vg_lite_font_t font);


    /*!
     @abstract Check if given font is vector/raster ?

     @discussion
     <code>vg_lite_is_vector_font</code> API lookups active fonts in
     vg_lite driver and if font it found it return 1 if it points to vector font
     otherwise it return 0;

     @param font
     Pointer to font handle

     @result
     Returns the status as defined by <code>vg_lite_error_t</code>.
        VG_LITE_SUCCESS when font registation is success
        VG_LITE_INVALID_ARGUMENT if font handle is invalid
     */
    int vg_lite_is_vector_font(vg_lite_font_t font);

    /*!
     @abstract This API renders text with specified font on render target.

     @discussion
     This API can reder text using user supplied font. Text rendering can be
     controlled by <code>vg_lite_font_attributes_t</code>.

     @param target
     Pointer to render target

     @param text
     ASCII text that needs to be rendered on render

     @param font
     Pointer to font handle

     @param x
     x position in pixels in X-axis for text rendering

     @param y
     y position in pixels in Y-axis for text rendering

     @param matrix
     Translation matrix that is used while rendering text.
     @attention Scaling and rotation matrix are not supported.

     @param blend
     Specifies how text gets blened in text area. Typical value is ELM_BLEND_SRC_OVER

     @param attributes
     Font attributes that controls how text gets rendered in render buffer.

     @result
     Returns the status as defined by <code>vg_lite_error_t</code>.
        VG_LITE_SUCCESS when font registation is success
        VG_LITE_INVALID_ARGUMENT if input parameters have any issue
     */
    vg_lite_error_t vg_lite_draw_text(
                      vg_lite_buffer_t *target,
                      char *text,
                      vg_lite_font_t font,
                      int x,
                      int y,
                      vg_lite_matrix_t *matrix,
                      vg_lite_blend_t blend,
                      vg_lite_font_attributes_t *attributes);

    /*!
     @abstract This API searches registered font for given name with
     requested rendering capabilities.

     @discussion
     This API searches registered font for given name with
     requested rendering capabilities.

     for raster fonts following fields are compared
       name,
       font_weight, font_stretch, font_style, font_height

     for vector fonts following fields are compared
       name

     @param font_name
     Font name

     @param font_weight
     Font weight value from eFontWeight_t

     @param font_stretch
     Font stretch value from eFontStretch_t

     @param font_style
     Font style value from eFontStyle_t

     @param font_height
     Font height in pixels

     If during font lookup a validate font is found then it retuns its handle.

     @result
     Returns valid font handle or an error code.
        Valid font handle if input parameters matches any of registerd font.
        INVALID_FONT if input parameters don't match registered fonts.
     */
    vg_lite_font_t vg_lite_find_font(
        char *font_name,
        eFontWeight_t  font_weight,
        eFontStretch_t font_stretch,
        eFontStyle_t   font_style,
        int font_height);

    /*!
     @abstract Initializes support for text drawing.
     */
    void vg_lite_text_init(void);

#ifdef __cplusplus
}
#endif

#endif /* _vg_lite_text_h_ */