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 #include "Elm.h"
30 #include "velm.h"
31 
32 #ifndef _elm_text_h_
33 #define _elm_text_h_
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 typedef enum eElemType {
40     eElemTypeLinearGradient         = 0,
41     eElemTypePath                   = 1,
42     eElemTypeGroup                  = 2,
43     eElemTypeText                   = 3,
44     eElemTypeTspan                  = 4,
45     eElemTypeFont                   = 5,
46     eElemTypeTtfFont                = 6,
47     eElemTypeVectorFont             = 7,
48     eElemTypeTextFont               = 8,
49 } eElemType_t;
50 
51 typedef enum eFontVariant {
52     eFontVariantNormal      = 1,
53     eFontVariantSmallCaps   = 2,
54     eFontVariantInherit     = 3,
55 } eFontVariant_t;
56 
57 typedef enum eDisplayAlign {
58     eDisplayAlignBefore     = 1,
59     eDisplayAlignCenter     = 2,
60     eDisplayAlignAfter      = 3,
61     eDisplayAlignAuto       = 1,
62 } eDisplayAlign_t;
63 
64 typedef enum eFontFields {
65     HORIZ_ADV_X         = 0,
66     HORIZ_ORIGIN_X      = 1,
67     ASCENT              = 2,
68     ALPHABETIC          = 3,
69     BBOX                = 4,
70     CAP_HEIGHT          = 5,
71     DESCENT             = 6,
72     FONT_FAMILY         = 7,
73     FONT_SIZE           = 8,
74     FONT_STRETCH        = 9,
75     FONT_STYLE          = 10,
76     FONT_TYPE           = 11,
77     FONT_VARIANT        = 12,
78     FONT_WEIGHT         = 13,
79     SLOPE               = 14,
80     UNICODE_RANGE       = 15,
81     UNITS_PER_EM        = 16,
82     X_HEIGHT            = 17,
83     TEXT_ANCHOR         = 18,
84     MAX_FONT_ATTRIBUTES = 19,
85 } eFontFields_t;
86 
87 typedef struct glyph {
88     uint8_t     glyph_name;
89     uint8_t     unicode;
90     uint32_t    horiz_adv_x;
91     uint32_t    path_data_length;
92     void        *path_data;
93 } glyph_t;
94 
95 typedef struct glyph_table {
96     uint32_t    offset;
97     uint32_t    size;
98 } glyph_table_t;
99 
100 typedef union value_type {
101     uint32_t    i_value;
102     float       f_value;
103     char       *data;
104 } value_type_t;
105 
106 typedef struct font_field_info {
107     value_type_t    value;
108     eFontFields_t   eName;
109 } font_field_info_t;
110 
111 typedef struct font_fields {
112     font_field_info_t   info;
113     uint32_t            offset;
114     uint32_t            size;
115     unsigned char       *data;
116 } font_fields_t;
117 
118 typedef struct vector_font {
119     uint32_t        id;
120     eElemType_t     type;
121     uint32_t        num_fields;
122     font_fields_t   *fields;
123     glyph_table_t   *glyph_table;
124     glyph_t         *glyph_offset;
125 } vector_font_t;
126 
127 typedef struct ttf_font {
128     uint32_t        id;
129     eElemType_t     type;
130     uint32_t        num_fields;
131     font_fields_t   *fields;
132 } ttf_font_t;
133 
134 typedef struct font_prop {
135     uint32_t        num_props;
136     font_fields_t   *prop_values;
137 } font_prop_t;
138 
139 typedef struct font_block {
140     uint32_t        size;
141     eElemType_t     type;
142     uint32_t        num_ttf_fonts;
143     uint32_t        num_vector_fonts;
144     uint32_t        num_text_fonts;
145     uint32_t        ttf_fonts_block_offset;
146     uint32_t        ttf_fonts_block_length;
147     uint32_t        vector_fonts_block_offset;
148     uint32_t        vector_fonts_block_length;
149     uint32_t        text_fonts_block_offset;
150     uint32_t        text_fonts_block_length;
151     uint32_t        property_block_offset;
152     uint32_t        property_block_length;
153     font_prop_t     *font_prop;
154     unsigned int    *sizes_of_ttf_data;
155     unsigned int    *offsets_of_ttf_data;
156     ttf_font_t      *ttf_fonts;
157     unsigned int    *sizes_of_vector_data;
158     unsigned int    *offsets_of_vector_data;
159     vector_font_t   *vector_fonts;
160     unsigned int    *sizes_of_text_font_data;
161     unsigned int    *offsets_of_text_font_data;
162     ttf_font_t      *text_fonts;
163 } font_block_t;
164 
165 typedef struct {
166     el_Object           object;
167     el_Attribute        attribute;
168     el_Attribute        defaultAttrib;
169     uint32_t            tspan_has_dx_dy;
170     uint32_t            text_anchor;
171     uint32_t            font_size;
172     uint32_t            font_id;
173     uint32_t            x_pos;
174     uint32_t            y_pos;
175     unsigned char       *msg;
176 } el_Obj_TEXT;
177 
178 typedef enum eAppProperties {
179   eFontNameProperty,
180   eFontHeightProperty,
181   eFontWeightProperty,
182   eFontStretchProperty,
183   eFontStyleProperty,
184   eTextColorProperty,
185   eTextAlignProperty,
186   eMaxFontProperties,
187 } eAppProperties_t;
188 
189 vg_lite_error_t draw_text(el_Obj_Buffer *buff,
190                                  el_Obj_EVO *evo, vg_lite_matrix_t *mat);
191 
192 extern font_block_t *fontblockobj;
193 
194 int _load_font_data(uint8_t *data);
195 
196 ElmHandle _load_text_data(uint8_t *data, el_Obj_EVO *evo);
197 void _unload_text(el_Obj_EVO *evo);
198 void _init_transform(el_Transform *transform);
199 void initialize_elm_text(void);
200 void destroy_font_data();
201 void _release_default_text_parameters(void);
202 
203 #ifdef __cplusplus
204 }
205 #endif
206 
207 #endif /* _elm_text_h_ */
208