vg_lite_text.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. #include "vg_lite.h"
  35. /* Macros *********************************************************************/
  36. #define MAX_FONT_NAME_LEN (64)
  37. #define VG_LITE_INVALID_FONT (-1)
  38. #define INVALID_FONT_PROPERTY_IDX (-1)
  39. /* Types **********************************************************************/
  40. /*!
  41. @abstract Font Type enumeration
  42. @discussion
  43. This enumeration defines supported high level font type type.
  44. */
  45. typedef enum eFontType {
  46. eFontTypeVector,
  47. eFontTypeRaster
  48. } eFontType_t;
  49. /*!
  50. @abstract Font weight enumeration
  51. @discussion
  52. This enumeration defines font weight that maps to css specification
  53. */
  54. typedef enum eFontWeight {
  55. eFontWeightThin = 100, /*! Thin, Hairline, Ultra-light, Extra-light */
  56. eFontWeightLight = 200, /*! Light */
  57. eFontWeightBook = 300, /*! Book */
  58. eFontWeightRegular = 400, /*! Regular, Normal, Plain, Roman, Standard */
  59. eFontWeightMedium = 500, /*! Medium */
  60. eFontWeightSemiBold = 600, /*! Semi-bold, Demi-bold */
  61. eFontWeightBold = 700, /*! Bold */
  62. eFontWeightHeavy = 800, /*! Heavy, Black, Extra-bold */
  63. eFontUltraBlack = 900, /*! Ultra-black, Extra-black, Ultra-bold,
  64. Heavy-black, Fat, Poster */
  65. } eFontWeight_t;
  66. /*!
  67. @abstract Font stretch enumeration
  68. @discussion
  69. This enumeration defines font stretch that maps to css specification
  70. */
  71. typedef enum eFontStretch {
  72. eFontStretchUltraCondensed = 1, /*! ultra-condensed */
  73. eFontStretchExtraCondensed = 2, /*! extra-condensed */
  74. eFontStretchCondensed = 3, /*! condensed */
  75. eFontStretchSemiCondensed = 4, /*! semi-condensed */
  76. eFontStretchNormal = 5, /*! normal */
  77. eFontStretchSemiExpanded = 6, /*! semi-expanded */
  78. eFontStretchExpanded = 7, /*! expanded */
  79. eFontStretchExtraExpanded = 8, /*! extra-expanded */
  80. eFontStretchUltraExpanded = 9, /*! ultra-expanded */
  81. } eFontStretch_t;
  82. /*!
  83. @abstract Font style enumeration
  84. @discussion
  85. This enumeration defines font style that maps to css specification
  86. */
  87. typedef enum eFontStyle {
  88. eFontStyleNormal = 1, /*! normal */
  89. eFontStyleItalic = 2, /*! italic, oblique */
  90. } eFontStyle_t;
  91. /*!
  92. @abstract Text alignment enumeration
  93. @discussion
  94. This enumeration defines text alignment that maps to css specification
  95. */
  96. typedef enum eTextAlign {
  97. eTextAlignLeft,
  98. eTextAlignCenter,
  99. eTextAlignRight,
  100. eTextAlignJustify,
  101. } eTextAlign_t;
  102. /* Structures *****************************************************************/
  103. /*!
  104. @abstract Font parameters
  105. @discussion
  106. This datastructure specifies application font and its data. Application
  107. can register as many font as required using vg_lite_register_font
  108. And lateron refer them in vg_lite_draw_text API
  109. for raster fonts mandatory fields are:
  110. name,
  111. font_weight, font_stretch, font_style, font_height
  112. data, data_len
  113. for vector fonts mandatory fields are:
  114. name,
  115. data, data_len
  116. */
  117. typedef struct vg_lite_font_params
  118. {
  119. char name[MAX_FONT_NAME_LEN]; /*! font-family name */
  120. eFontType_t font_type; /*! Raster/Vector font */
  121. eFontWeight_t font_weight; /*! Font weight enum value */
  122. eFontStretch_t font_stretch; /*! Font stretch enum value */
  123. eFontStyle_t font_style; /*! Font style enum value */
  124. int font_height; /*! Font height in pixels */
  125. int data_len; /*! Font data buffer length */
  126. void *data; /*! the address where the actual font data is stored; it is the
  127. * responsibility of the user/application to load it there */
  128. } vg_lite_font_params_t;
  129. /*!
  130. @abstract Opaque type for font descriptor
  131. @discussion
  132. This is an index of into font-table. Font table can have atmost
  133. MAX_SYSTEM_FONTS font, registering more font results in an error.
  134. */
  135. typedef uint32_t vg_lite_font_t;
  136. /*!
  137. @abstract Runtime parameter to render text using given font
  138. @discussion
  139. These parameters controls rendering of text using given font.
  140. */
  141. typedef struct {
  142. /* Application controllable parameters */
  143. int justify; /*! Equal justify given text in text display area */
  144. int alignment; /*! Ailgn text to left, center or right */
  145. int width; /*! Internal variable computed based on active font */
  146. int height; /*! Internal variable computed based on active font */
  147. unsigned int text_color; /*! Foreground text color */
  148. unsigned int bg_color; /*! Background text color */
  149. int tspan_has_dx_dy; /*! 0 means tspan element has x,y values
  150. 1 means tspan element has dx, dy values
  151. so use last_x+dx for x,
  152. last_y+dy for y
  153. */
  154. int is_vector_font; /*! 1 when active font is vector font, 0 otherwise */
  155. int margin; /*! Left and right margin in pixels that should be skipped
  156. by text rendering engine */
  157. int anchor; /*! Anchor text */
  158. int scale; /*! Flag that indicate if text rendering engine should
  159. scale text */
  160. /* Internal parameters of text rendering engine.
  161. Application code should not modify these parameters
  162. */
  163. int font_height; /*! Font height in pixels, parameter from svg */
  164. int last_x; /*! Last x position of text element */
  165. int last_y; /*! Last y position of text element */
  166. int last_dx; /*! Horizontal width of text in pixels, for last text */
  167. } vg_lite_font_attributes_t;
  168. /* API Function prototypes ****************************************************/
  169. /*!
  170. @abstract Registers application specific font in vg_ltie driver.
  171. @discussion
  172. Using <code>vg_lite_register_font</code> application can register active
  173. fonts that <code>vg_lite_draw_text</code> uses to render text.
  174. for raster fonts mandatory fields of <code>vg_lite_font_params_t</code> are:
  175. name,
  176. font_weight, font_stretch, font_style, font_height
  177. data, data_len
  178. for vector fonts mandatory fields of <code>vg_lite_font_params_t</code> are:
  179. name,
  180. data, data_len
  181. On successful registeration <code>font</code> poiter will get non-negative
  182. application handle.
  183. @param font
  184. Pointer to font handle
  185. @param params
  186. Pointer to font parameters that are used by <code>vg_lite_find_font</code>
  187. to select specific font for rendering text
  188. @result
  189. Returns the status as defined by <code>vg_lite_error_t</code>.
  190. VG_LITE_SUCCESS when font registation is success
  191. VG_LITE_INVALID_ARGUMENT When parameter pointer is invalid
  192. VG_LITE_ALREADY_EXISTS if font name already exists
  193. VG_LITE_OUT_OF_RESOURCES if active font exceeds MAX_SYSTEM_FONTS
  194. */
  195. vg_lite_error_t vg_lite_register_font(
  196. vg_lite_font_t *font,
  197. vg_lite_font_params_t *params);
  198. /*!
  199. @abstract Un-registers application specific font in vg_ltie driver.
  200. @discussion
  201. <code>vg_lite_unregister_font</code> unregisters application speciific
  202. font form vg_lite driver. This font can not be used lateron by
  203. <code>vg_lite_draw_text</code> API.
  204. @param font
  205. Pointer to font handle
  206. @result
  207. Returns the status as defined by <code>vg_lite_error_t</code>.
  208. VG_LITE_SUCCESS when font registation is success
  209. VG_LITE_INVALID_ARGUMENT if font handle is invalid
  210. */
  211. vg_lite_error_t vg_lite_unregister_font(vg_lite_font_t font);
  212. /*!
  213. @abstract Check if given font is vector/raster ?
  214. @discussion
  215. <code>vg_lite_is_vector_font</code> API lookups active fonts in
  216. vg_lite driver and if font it found it return 1 if it points to vector font
  217. otherwise it return 0;
  218. @param font
  219. Pointer to font handle
  220. @result
  221. Returns the status as defined by <code>vg_lite_error_t</code>.
  222. VG_LITE_SUCCESS when font registation is success
  223. VG_LITE_INVALID_ARGUMENT if font handle is invalid
  224. */
  225. int vg_lite_is_vector_font(vg_lite_font_t font);
  226. /*!
  227. @abstract This API renders text with specified font on render target.
  228. @discussion
  229. This API can reder text using user supplied font. Text rendering can be
  230. controlled by <code>vg_lite_font_attributes_t</code>.
  231. @param target
  232. Pointer to render target
  233. @param text
  234. ASCII text that needs to be rendered on render
  235. @param font
  236. Pointer to font handle
  237. @param x
  238. x position in pixels in X-axis for text rendering
  239. @param y
  240. y position in pixels in Y-axis for text rendering
  241. @param matrix
  242. Translation matrix that is used while rendering text.
  243. @attention Scaling and rotation matrix are not supported.
  244. @param blend
  245. Specifies how text gets blened in text area. Typical value is ELM_BLEND_SRC_OVER
  246. @param attributes
  247. Font attributes that controls how text gets rendered in render buffer.
  248. @result
  249. Returns the status as defined by <code>vg_lite_error_t</code>.
  250. VG_LITE_SUCCESS when font registation is success
  251. VG_LITE_INVALID_ARGUMENT if input parameters have any issue
  252. */
  253. vg_lite_error_t vg_lite_draw_text(
  254. vg_lite_buffer_t *target,
  255. char *text,
  256. vg_lite_font_t font,
  257. int x,
  258. int y,
  259. vg_lite_matrix_t *matrix,
  260. vg_lite_blend_t blend,
  261. vg_lite_font_attributes_t *attributes);
  262. /*!
  263. @abstract This API searches registered font for given name with
  264. requested rendering capabilities.
  265. @discussion
  266. This API searches registered font for given name with
  267. requested rendering capabilities.
  268. for raster fonts following fields are compared
  269. name,
  270. font_weight, font_stretch, font_style, font_height
  271. for vector fonts following fields are compared
  272. name
  273. @param font_name
  274. Font name
  275. @param font_weight
  276. Font weight value from eFontWeight_t
  277. @param font_stretch
  278. Font stretch value from eFontStretch_t
  279. @param font_style
  280. Font style value from eFontStyle_t
  281. @param font_height
  282. Font height in pixels
  283. If during font lookup a validate font is found then it retuns its handle.
  284. @result
  285. Returns valid font handle or an error code.
  286. Valid font handle if input parameters matches any of registerd font.
  287. INVALID_FONT if input parameters don't match registered fonts.
  288. */
  289. vg_lite_font_t vg_lite_find_font(
  290. char *font_name,
  291. eFontWeight_t font_weight,
  292. eFontStretch_t font_stretch,
  293. eFontStyle_t font_style,
  294. int font_height);
  295. /*!
  296. @abstract Initializes support for text drawing.
  297. */
  298. void vg_lite_text_init(void);
  299. #ifdef __cplusplus
  300. }
  301. #endif
  302. #endif /* _vg_lite_text_h_ */