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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
|
/***************************************************************
SVGC.H
This file containt declarations of SVG C lib functions.
***************************************************************/
#ifndef __SVGC_H__
#define __SVGC_H__
#if defined( __cplusplus )
extern "C"
{
#endif
#include <svgc-dlist.h>
typedef struct __svg_point __svg_point;
struct __svg_point
{
double x, y;
};
typedef struct __svg_points __svg_points;
struct __svg_points
{
int count;
struct svgc_dlist *plist;
};
extern void __svg_free_point( void *data );
extern void __svg_free_points( struct __svg_points *p );
extern struct __svg_points *__svg_new_points( void );
extern int __svg_add_point( struct __svg_points *ps, double x, double y );
/***************************************************************
PATH CMDS:
***************************************************************/
typedef struct __svg_cmd __svg_cmd;
struct __svg_cmd
{
char cmd;
struct __svg_points *points;
};
typedef struct __svg_cmds __svg_cmds;
struct __svg_cmds
{
int count;
struct svgc_dlist *plist;
};
extern void __svg_free_cmd( void *data );
extern void __svg_free_cmds( struct __svg_cmds *cmds );
extern struct __svg_cmd *__svg_new_cmd( char cmd, struct __svg_points *ps );
extern struct __svg_cmds *__svg_new_cmds( void );
extern int __svg_add_cmd( struct __svg_cmds *cmds, struct __svg_cmd *cmd );
#define ABSOLUTE 1
#define RELATIVE 0
extern int
__svg_add_moveto_cmd( struct __svg_cmds *cmds,
int abs,
double x,
double y );
extern int
__svg_add_lineto_cmd( struct __svg_cmds *cmds,
int abs,
double x,
double y );
extern int
__svg_add_hlineto_cmd( struct __svg_cmds *cmds,
int abs,
double x );
extern int
__svg_add_vlineto_cmd( struct __svg_cmds *cmds,
int abs,
double y );
extern int
__svg_add_curveto_cmd( struct __svg_cmds *cmds,
int abs,
double x1,
double y1,
double x2,
double y2,
double x,
double y );
extern int
__svg_add_short_curveto_cmd( struct __svg_cmds *cmds,
int abs,
double x2,
double y2,
double x,
double y );
extern int
__svg_add_quadro_curveto_cmd( struct __svg_cmds *cmds,
int abs,
double x1,
double y1,
double x,
double y );
extern int
__svg_add_short_quadro_curveto_cmd( struct __svg_cmds *cmds,
int abs,
double x,
double y );
extern int
__svg_add_arc_cmd( struct __svg_cmds *cmds,
int abs,
double rx,
double ry,
double x_axis_rotation,
int large_arc_flag,
int sweep_flag,
double x,
double y );
extern int
__svg_add_closepath_cmd( struct __svg_cmds *cmds,
int abs );
/***************************************************************
STYLE:
***************************************************************/
typedef struct __svg_rgb __svg_rgb;
struct __svg_rgb
{
int r, g, b;
};
#define STROKE_DEFAULT "black"
#define LINECAP_BUTT "butt"
#define LINECAP_ROUND "round"
#define LINECAP_SQUARE "square"
#define LINECAP_DEFAULT "round"
#define LINEJOIN_MITER "miter"
#define LINEJOIN_ROUND "round"
#define LINEJOIN_BEVEL "bevel"
#define LINEJOIN_DEFAULT "round"
#define DASHARRAY_DEFAULT "none"
typedef struct __svg_stroke __svg_stroke;
struct __svg_stroke
{
struct __svg_rgb stroke;
char *use_stroke;
double stroke_width;
char *stroke_linecap;
char *stroke_linejoin;
char *stroke_dasharray;
};
#define FILL_DEFAULT "none"
typedef struct __svg_fill __svg_fill;
struct __svg_fill
{
struct __svg_rgb fill;
char *use_fill;
};
#define STOP_COLOR_DEFAULT "black"
typedef struct __svg_stop_color __svg_stop_color;
struct __svg_stop_color
{
struct __svg_rgb stop_color;
char *use_stop_color;
};
#define STOP_OPACITY_DEFAULT 1.0
typedef struct __svg_stop_opacity __svg_stop_opacity;
struct __svg_stop_opacity
{
double stop_opacity;
};
typedef struct __svg_style __svg_style;
struct __svg_style
{
struct __svg_stroke *stroke;
struct __svg_fill *fill;
struct __svg_stop_color *stop_color;
struct __svg_stop_opacity *stop_opacity;
};
#define TEXT_FILL_DEFAULT "black"
#define TEXT_FONT_FAMILY_DEFAULT "Verdana"
#define TEXT_FONT_SIZE_DEFAULT 12
extern char *__svg_str_dup( const char *s );
extern struct __svg_stroke *__svg_new_stroke( void );
extern void __svg_free_stroke( struct __svg_stroke *s );
extern struct __svg_fill *__svg_new_fill( void );
extern void __svg_free_fill( struct __svg_fill *f );
extern struct __svg_stop_color *__svg_new_stop_color( void );
extern void __svg_free_stop_color( struct __svg_stop_color *sc );
extern struct __svg_stop_opacity *__svg_new_stop_opacity( void );
extern void __svg_free_stop_opacity( struct __svg_stop_opacity *so );
extern struct __svg_style *__svg_new_style( void );
extern void __svg_free_style( struct __svg_style *style );
/* NODE: */
#define SVG_SHEET 1
#define SVG_LINE 2
#define SVG_RECT 3
#define SVG_CIRCLE 4
#define SVG_ELLIPSE 5
#define SVG_POLYGON 6
#define SVG_POLYLINE 7
#define SVG_PATH 8
#define SVG_TEXT 9
#define SVG_IMAGE 10
#define SVG_L_GRADIENT 11
#define SVG_R_GRADIENT 12
#define SVG_CSS 13
#define SVG_STOP 14
#define SVG_SCRIPT 15
typedef struct __svg_node __svg_node;
struct __svg_node
{
int type;
char *id;
struct __svg_style *style;
};
/* The MAIN svg nide is SHEET: */
typedef struct __svg_sheet __svg_sheet;
struct __svg_sheet
{
int type;
char *id;
struct __svg_style *style;
struct svgc_dlist *defs;
double width, height;
double left_margin;
double right_margin;
double top_margin;
double bottom_margin;
};
/***************************************************************
SVG primitives:
***************************************************************/
typedef struct __svg_line __svg_line;
struct __svg_line
{
int type;
char *id;
struct __svg_style *style;
double x1, y1;
double x2, y2;
};
typedef struct __svg_rect __svg_rect;
struct __svg_rect
{
int type;
char *id;
struct __svg_style *style;
double x, y;
double width, height;
double rx, ry;
};
typedef struct __svg_circle __svg_circle;
struct __svg_circle
{
int type;
char *id;
struct __svg_style *style;
double cx, cy, r;
};
typedef struct __svg_ellipse __svg_ellipse;
struct __svg_ellipse
{
int type;
char *id;
struct __svg_style *style;
double cx, cy, rx, ry;
};
typedef struct __svg_polygon __svg_polygon;
struct __svg_polygon
{
int type;
char *id;
struct __svg_style *style;
struct __svg_points *points;
};
typedef struct __svg_polyline __svg_polyline;
struct __svg_polyline
{
int type;
char *id;
struct __svg_style *style;
struct __svg_points *points;
};
typedef struct __svg_path __svg_path;
struct __svg_path
{
int type;
char *id;
struct __svg_style *style;
struct __svg_cmds *cmds;
};
typedef struct __svg_text __svg_text;
struct __svg_text
{
int type;
char *id;
struct __svg_style *style;
double x, y;
char *text;
int font_size;
char *font_family;
char *fill;
};
typedef struct __svg_image __svg_image;
struct __svg_image
{
int type;
char *id;
struct __svg_style *style;
double x, y;
int width, height;
char *href;
char *title;
};
/* NOTE: this is common gradient struct */
typedef struct __svg_gradient __svg_gradient;
struct __svg_gradient
{
int type;
char *id;
struct __svg_style *style;
struct svgc_dlist *stops;
};
/* NOTE: gradients are added into sheet list as defs */
typedef struct __svg_l_gradient __svg_l_gradient;
struct __svg_l_gradient
{
int type;
char *id;
struct __svg_style *style;
struct svgc_dlist *stops;
char *units;
char *spread;
double x1, y1;
double x2, y2;
};
typedef struct __svg_r_gradient __svg_r_gradient;
struct __svg_r_gradient
{
int type;
char *id;
struct __svg_style *style;
struct svgc_dlist *stops;
char *units;
char *spread;
double cx, cy;
double r;
double fx, fy;
};
/* NOTE: only for gradients */
typedef struct __svg_stop __svg_stop;
struct __svg_stop
{
int type;
char *id;
struct __svg_style *style;
double offset;
};
/***************************************************************
SCENE is the list of SVG primitives.
***************************************************************/
typedef struct __svg_scene __svg_scene;
struct __svg_scene
{
struct svgc_dlist *plist;
};
extern void __svg_free_scene( struct __svg_scene *scene );
extern struct __svg_scene *__svg_new_scene( struct __svg_sheet *sheet );
/***************************************************************
FREE and ADD SVG primitives.
***************************************************************/
extern void __svg_free_node( void *data );
/* SVG sheet should be created before SCENE */
extern struct __svg_node *__svg_new_sheet( double width,
double height,
double left_margin,
double right_margin,
double top_margin,
double bottom_margin );
extern int __svg_sheet_add_definition( void *sheet,
struct __svg_node *definition );
/* Insert the contents of a UTF-8 CSS file into sheet <defs>.
Return 1 on success, 0 on read/allocation/encoding failure, -1 on
invalid arguments. Relative url(...) references are resolved by the
SVG viewer against the generated SVG file, not against fname. */
extern int __svg_sheet_add_css_file( struct __svg_sheet *sheet,
const char *fname );
/* Insert the contents of a UTF-8 JavaScript file into sheet <defs>.
The caller supplies JavaScript source, without XML, script tags or CDATA.
Return values and ownership follow __svg_sheet_add_css_file().
Script execution depends on the viewer; SVG used as <img> is inert. */
extern int __svg_sheet_add_script_file( struct __svg_sheet *sheet,
const char *fname );
/***************************************************************
Creation of SVG primirives:
***************************************************************/
extern struct __svg_node *__svg_new_line( double x1,
double y1,
double x2,
double y2 );
extern struct __svg_node *__svg_new_rect( double x,
double y,
double width,
double height,
double rx,
double ry );
extern struct __svg_node *__svg_new_circle( double cx,
double cy,
double r );
extern struct __svg_node *__svg_new_ellipse( double cx,
double cy,
double rx,
double ry );
extern struct __svg_node *__svg_new_polygon ( struct __svg_points *ps );
extern struct __svg_node *__svg_new_polyline( struct __svg_points *ps );
extern struct __svg_node *__svg_new_path( struct __svg_cmds *cmds );
extern struct __svg_node *__svg_new_text( double x,
double y,
const char *text,
const char *font_family,
int font_size );
extern struct __svg_node *__svg_new_image( double x,
double y,
int width,
int height,
char *href,
char *title );
extern struct __svg_node *__svg_new_l_gradient( const char *units, /* objectBoundingBox | userSpaceOnUse */
const char *spread, /* pad | reflect | repeat */
double x1,
double y1,
double x2,
double y2 );
extern struct __svg_node *__svg_new_r_gradient( const char *units, /* objectBoundingBox | userSpaceOnUse */
const char *spread, /* pad | reflect | repeat */
double cx,
double cy,
double r,
double fx,
double fy );
extern struct __svg_node *__svg_new_stop( double offset );
extern int __svg_gradient_add_stop( void *gradient,
struct __svg_stop *stop );
/***************************************************************
Adding some primitive to SCENE:
***************************************************************/
extern int
__svg_scene_add_node( struct __svg_scene *scene, struct __svg_node *node );
/***************************************************************
Style controls:
***************************************************************/
extern int __svg_set_stroke( struct __svg_node *node, const char *stroke );
extern int __svg_set_stroke_rgb( struct __svg_node *node, int r, int g, int b );
extern int __svg_set_stroke_width( struct __svg_node *node, double width );
extern int __svg_set_stroke_linecap( struct __svg_node *node, const char *linecap );
extern int __svg_set_stroke_linejoin( struct __svg_node *node, const char *linejoin );
extern int __svg_set_stroke_dasharray( struct __svg_node *node, const char *dasharray );
extern int __svg_set_fill( struct __svg_node *node, const char *fill );
extern int __svg_set_fill_rgb( struct __svg_node *node, int r, int g, int b );
extern int __svg_set_stop_color( struct __svg_node *node, const char *stop_color );
extern int __svg_set_stop_color_rgb( struct __svg_node *node, int r, int g, int b );
extern int __svg_set_stop_opacity( struct __svg_node *node, double stop_opacity );
extern int __svg_set_text_text( struct __svg_node *node, const char *text );
extern int __svg_set_text_fill( struct __svg_node *node, const char *fill );
extern int __svg_set_text_fill_rgb( struct __svg_node *node, int r, int g, int b );
extern int __svg_set_text_font_family( struct __svg_node *node, const char *family );
extern int __svg_set_text_font_size( struct __svg_node *node, int size );
/* Set Global Default Values: */
extern void __svg_set_scene_default_style( void );
extern void __svg_set_scene_stroke( const char *stroke );
extern void __svg_set_scene_stroke_rgb( int r, int g, int b );
extern void __svg_set_scene_stroke_width( double width );
extern void __svg_set_scene_stroke_linecap( const char *linecap );
extern void __svg_set_scene_stroke_linejoin( const char *linejoin );
extern void __svg_set_scene_stroke_dasharray( const char *dasharray );
extern void __svg_set_scene_fill( const char *fill );
extern void __svg_set_scene_fill_rgb( int r, int g, int b );
extern void __svg_set_scene_stop_color( const char *stop_color );
extern void __svg_set_scene_stop_color_rgb( int r, int g, int b );
extern void __svg_set_scene_stop_opacity( double stop_opacity );
extern void __svg_set_scene_text_fill( const char *fill );
extern void __svg_set_scene_text_fill_rgb( int r, int g, int b );
extern void __svg_set_scene_text_font_family( const char *family );
extern void __svg_set_scene_text_font_size( int size );
/* Get node ID: */
extern const char *__svg_get_node_id( struct __svg_node *node );
extern char *__svg_create_node_url( struct __svg_node *node );
/***************************************************************
OUTPUT:
***************************************************************/
extern void __svg_paint_scene( struct __svg_scene *scene,
int group,
char *fname );
extern int _svgc_get_major_version( void );
extern int _svgc_get_minor_version( void );
extern int _svgc_get_micro_version( void );
#if defined( __cplusplus )
} /* extern "C" */
#endif
#endif /* __SVGC_H__ */
|