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
|
/** \file
* \brief Cairo SVG Driver
*
* See Copyright Notice in cd.h
*/
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include "cd.h"
#include "cdcairo.h"
#include "cdcairoctx.h"
#include <cairo-svg.h>
static void cdflush(cdCtxCanvas *ctxcanvas)
{
(void)ctxcanvas;
/* does nothing in SVG */
}
static void cdkillcanvas (cdCtxCanvas *ctxcanvas)
{
cdcairoKillCanvas(ctxcanvas);
}
static void cdcreatecanvas(cdCanvas* canvas, void* data)
{
cdCtxCanvas* ctxcanvas;
char* strdata = (char*)data;
char filename[10240] = "";
double w_mm = INT_MAX*3.78, h_mm = INT_MAX*3.78, res = 3.78;
cairo_surface_t *surface;
/* Starting parameters */
if (strdata == NULL)
return;
strdata += cdGetFileName(strdata, filename);
if (filename[0] == 0)
return;
sscanf(strdata, "%lgx%lg %lg", &w_mm, &h_mm, &res);
/* update canvas context */
canvas->w = (int)(w_mm * res);
canvas->h = (int)(h_mm * res);
canvas->w_mm = w_mm;
canvas->h_mm = h_mm;
canvas->bpp = 24;
canvas->xres = res;
canvas->yres = res;
surface = cairo_svg_surface_create(filename, CD_MM2PT*w_mm, CD_MM2PT*h_mm);
/* Starting Cairo driver */
ctxcanvas = cdcairoCreateCanvas(canvas, cairo_create(surface));
cairo_surface_destroy(surface);
}
static void cdinittable(cdCanvas* canvas)
{
cdcairoInitTable(canvas);
canvas->cxKillCanvas = cdkillcanvas;
canvas->cxFlush = cdflush;
}
static cdContext cdCairoSVGContext =
{
CD_CAP_ALL & ~(CD_CAP_PLAY | CD_CAP_YAXIS | CD_CAP_REGION | CD_CAP_WRITEMODE | CD_CAP_PALETTE),
CD_CTX_FILE, /* not a plus driver */
cdcreatecanvas,
cdinittable,
NULL,
NULL
};
cdContext* cdContextCairoSVG(void)
{
return &cdCairoSVGContext;
}
|