-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvg.h
148 lines (120 loc) · 3.91 KB
/
svg.h
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
/*
* moto-design SGV utils.
*/
#if ! defined(_MD_GENERATOR_SVG_H)
#define _MD_GENERATOR_SVG_H
#include <stdio.h>
#include "color.h"
#include "geometry.h"
struct svg_fill {
char color[hex_color_len];
};
struct svg_stroke {
char color[hex_color_len];
unsigned int width;
};
struct svg_style {
struct svg_fill fill;
struct svg_stroke stroke;
};
struct svg_transform {
struct point_c translate;
struct scale scale;
struct rotation rotation;
};
static const struct svg_transform null_svg_transform = {
.translate = {HUGE_VALF, HUGE_VALF},
.scale = {HUGE_VALF, HUGE_VALF},
.rotation = {0.0, {HUGE_VALF, HUGE_VALF}},
};
struct svg_line {
struct point_c a;
struct point_c b;
};
struct svg_rect {
float width; // size.
float height;
float x; // position.
float y;
float rx; // corner radius.
float ry;
};
static const struct svg_style svg_style_royal_no_stroke = {
.fill.color = _hex_color_royal,
.stroke.color = _hex_color_null,
.stroke.width = 0,
};
static const struct svg_style svg_style_light_gray_no_stroke = {
.fill.color = _hex_color_light_gray,
.stroke.color = _hex_color_null,
.stroke.width = 0,
};
static const struct svg_style svg_style_gray_no_stroke = {
.fill.color = _hex_color_gray,
.stroke.color = _hex_color_null,
.stroke.width = 0,
};
static const struct svg_style svg_style_red_red = {
.fill.color = _hex_color_red,
.stroke.color = _hex_color_red,
.stroke.width = 1,
};
static const struct svg_style svg_style_yellow_blue = {
.fill.color = _hex_color_yellow,
.stroke.color = _hex_color_blue,
.stroke.width = 1,
};
static const struct svg_style svg_style_light_green_light_green = {
.fill.color = _hex_color_light_green,
.stroke.color = _hex_color_light_green,
.stroke.width = 1,
};
static const struct svg_style svg_style_black_black = {
.fill.color = _hex_color_black,
.stroke.color = _hex_color_black,
.stroke.width = 1,
};
static const struct svg_style svg_style_white_white = {
.fill.color = _hex_color_white,
.stroke.color = _hex_color_white,
.stroke.width = 1,
};
FILE *svg_debug_stream(void);
void svg_debug_stream_set(FILE *stream);
struct svg_fill *svg_fill_set(struct svg_fill *fill, const char *color);
struct svg_stroke *svg_stroke_set(struct svg_stroke *stroke, const char *color,
unsigned int width);
static inline struct svg_style *svg_style_set(struct svg_style *style, const char *fill_color,
const char *stroke_color, unsigned int stroke_width)
{
svg_fill_set(&style->fill, fill_color);
svg_stroke_set(&style->stroke, stroke_color, stroke_width);
return style;
}
void svg_open_svg(FILE *stream, const struct svg_rect *background_rect);
void svg_close_svg(FILE *stream);
void svg_write_comment(FILE *stream, const char *text);
void svg_open_group(FILE *stream, const struct svg_style *style,
const struct svg_transform *transform, const char *id);
void svg_close_group(FILE *stream);
void svg_open_object(FILE *stream, const struct svg_style *style,
const struct svg_transform *transform, const char *id, const char *type);
void svg_close_object(FILE *stream);
void svg_open_path(FILE *stream, const struct svg_style *style,
const struct svg_transform *transform, const char *id);
void svg_open_polygon(FILE *stream, const struct svg_style *style,
const struct svg_transform *transform, const char *id);
void svg_close_polygon(FILE *stream);
void svg_write_line(FILE *stream, const struct svg_style *style,
const struct svg_transform *transform, const char *id,
const struct svg_line *line);
void svg_write_rect(FILE *stream, const struct svg_style *style,
const struct svg_transform *transform, const char *id,
const struct svg_rect *rect);
void svg_write_background(FILE *stream, const struct svg_style *style,
const struct svg_transform *transform,
const struct svg_rect *background_rect);
void svg_write_star(FILE *stream, const struct svg_style *style,
const struct svg_transform *transform, const char *id,
const struct star_params *star_params);
#endif /* _MD_GENERATOR_SVG_H */