1 /**
2  * @file lv_svg_render.h
3  *
4  */
5 
6 #ifndef LV_SVG_RENDER_H
7 #define LV_SVG_RENDER_H
8 
9 /*********************
10  *      INCLUDES
11  *********************/
12 #include "../../lv_conf_internal.h"
13 
14 #if LV_USE_SVG
15 #if !LV_USE_VECTOR_GRAPHIC
16     #error "LV_USE_SVG requires LV_USE_VECTOR_GRAPHIC = 1"
17 #endif
18 
19 #include "lv_svg.h"
20 #include "../../misc/lv_types.h"
21 #include "../../draw/lv_draw_vector_private.h"
22 
23 /*********************
24  *      DEFINES
25  *********************/
26 
27 #define LV_SVG_RENDER_OBJ(n) ((lv_svg_render_obj_t*)(n))
28 
29 /**********************
30  *      TYPEDEFS
31  **********************/
32 
33 typedef struct _lv_svg_render_obj {
34     struct _lv_svg_render_obj * next;
35     uint32_t flags;
36     char * id;
37     lv_vector_draw_dsc_t dsc;
38     lv_matrix_t matrix;
39 
40     /* for url(XXX) reference */
41     struct _lv_svg_render_obj * head;
42     char * fill_ref;
43     char * stroke_ref;
44     void (*set_paint_ref)(struct _lv_svg_render_obj * obj, lv_vector_draw_dsc_t * dsc,
45                           const struct _lv_svg_render_obj * target_obj, bool fill);
46 
47     void (*init)(struct _lv_svg_render_obj * obj, const lv_svg_node_t * node);
48     void (*render)(const struct _lv_svg_render_obj * obj, lv_vector_dsc_t * dsc, const lv_matrix_t * matrix);
49     void (*set_attr)(struct _lv_svg_render_obj * obj, lv_vector_draw_dsc_t * dsc, const lv_svg_attr_t * attr);
50     void (*get_bounds)(const struct _lv_svg_render_obj * obj, lv_area_t * area);
51     void (*destroy)(struct _lv_svg_render_obj * obj);
52 } lv_svg_render_obj_t;
53 
54 typedef struct _lv_svg_render_hal {
55     void (*load_image)(const char * image_url, lv_draw_image_dsc_t * img_dsc);
56     const char * (*get_font_path)(const char * font_family);
57 } lv_svg_render_hal_t;
58 
59 /**********************
60  * GLOBAL PROTOTYPES
61  **********************/
62 
63 /**
64  * @brief Initialize the SVG render
65  * @param hal pointer to a structure with rendering functions
66  */
67 void lv_svg_render_init(const lv_svg_render_hal_t * hal);
68 
69 /**
70  * @brief Create a new SVG render from an SVG document
71  * @param svg_doc pointer to the SVG document
72  * @return pointer to the new SVG render object
73  */
74 lv_svg_render_obj_t * lv_svg_render_create(const lv_svg_node_t * svg_doc);
75 
76 /**
77  * @brief Delete an SVG render object
78  * @param render pointer to the SVG render object to delete
79  */
80 void lv_svg_render_delete(lv_svg_render_obj_t * render);
81 
82 /**
83  * @brief Render an SVG object to a vector graphics
84  * @param dsc pointer to the vector graphics descriptor
85  * @param render pointer to the SVG render object to render
86  */
87 void lv_draw_svg_render(lv_vector_dsc_t * dsc, const lv_svg_render_obj_t * render);
88 
89 /**
90  * @brief Draw an SVG document to a layer
91  * @param layer pointer to the target layer
92  * @param svg_doc pointer to the SVG document to draw
93  */
94 void lv_draw_svg(lv_layer_t * layer, const lv_svg_node_t * svg_doc);
95 
96 /**********************
97  *      MACROS
98  **********************/
99 
100 #endif /*LV_USE_SVG*/
101 
102 #endif /*LV_SVG_RENDER_H*/
103