14 start_element (void *closure,
18 struct trace *trace = closure;
20 if (strcmp (element, "surface") == 0) {
21 const char *content = "COLOR_ALPHA";
22 const char *width = NULL;
23 const char *height = NULL;
26 if (strcmp (*attr, "content") == 0) {
28 } else if (strcmp (*attr, "width") == 0) {
30 } else if (strcmp (*attr, "height") == 0) {
33 fprintf (stderr, "unknown surface attribute '%s'\n", *attr);
39 fprintf (trace->stream, "<< /content //%s", content);
40 if (width != NULL && height != NULL) {
41 fprintf (trace->stream,
42 " /width %s /height %s",
45 if (trace->surface_depth++ == 0)
46 fprintf (trace->stream, " >> surface context\n");
48 fprintf (trace->stream, " >> surface dup context\n");
49 } else if (strcmp (element, "image") == 0) {
50 const char *format = "ARGB24";
51 const char *width = NULL;
52 const char *height = NULL;
55 if (strcmp (*attr, "format") == 0) {
57 } else if (strcmp (*attr, "width") == 0) {
59 } else if (strcmp (*attr, "height") == 0) {
62 fprintf (stderr, "unknown image attribute '%s'\n", *attr);
68 fprintf (trace->stream,
69 "<< /format //%s /width %s /height %s /mime-type (image/png) /source <{",
70 format, width, height);
71 assert (trace->tail == NULL);
72 trace->tail = "}> >> image pattern\n";
73 } else if (strcmp (element, "solid") == 0) {
74 trace->tail = " rgba\n";
75 } else if (strcmp (element, "linear") == 0) {
76 const char *x1 = NULL;
77 const char *x2 = NULL;
78 const char *y1 = NULL;
79 const char *y2 = NULL;
82 if (strcmp (*attr, "x1") == 0) {
84 } else if (strcmp (*attr, "x2") == 0) {
86 } else if (strcmp (*attr, "y1") == 0) {
88 } else if (strcmp (*attr, "y2") == 0) {
91 fprintf (stderr, "unknown linear attribute '%s'\n", *attr);
97 fprintf (trace->stream, "%s %s %s %s linear\n", x1, y1, x2, y2);
98 } else if (strcmp (element, "radial") == 0) {
99 const char *x1 = NULL;
100 const char *y1 = NULL;
101 const char *r1 = NULL;
102 const char *y2 = NULL;
103 const char *x2 = NULL;
104 const char *r2 = NULL;
107 if (strcmp (*attr, "x1") == 0) {
109 } else if (strcmp (*attr, "y1") == 0) {
111 } else if (strcmp (*attr, "r1") == 0) {
113 } else if (strcmp (*attr, "x2") == 0) {
115 } else if (strcmp (*attr, "y2") == 0) {
117 } else if (strcmp (*attr, "r2") == 0) {
120 fprintf (stderr, "unknown radial attribute '%s'\n", *attr);
126 fprintf (trace->stream,
127 "%s %s %s %s %s %s radial\n",
128 x1, y1, r1, x2, y2, r2);
129 } else if (strcmp (element, "matrix") == 0) {
130 fprintf (trace->stream, "[ ");
131 trace->tail = " ] set-matrix\n";
132 } else if (strcmp (element, "extend") == 0) {
133 trace->tail = " set-extend\n";
134 } else if (strcmp (element, "filter") == 0) {
135 trace->tail = " set-filter\n";
136 } else if (strcmp (element, "operator") == 0) {
137 trace->tail = " set-operator\n";
138 } else if (strcmp (element, "tolerance") == 0) {
139 trace->tail = " set-tolerance\n";
140 } else if (strcmp (element, "fill-rule") == 0) {
141 trace->tail = " set-fill-rule\n";
142 } else if (strcmp (element, "line-cap") == 0) {
143 trace->tail = " set-line-cap\n";
144 } else if (strcmp (element, "line-join") == 0) {
145 trace->tail = " set-line-join\n";
146 } else if (strcmp (element, "line-width") == 0) {
147 trace->tail = " set-line-width\n";
148 } else if (strcmp (element, "miter-limit") == 0) {
149 trace->tail = " set-miter-limit\n";
150 } else if (strcmp (element, "antialias") == 0) {
151 trace->tail = " set-antialias\n";
152 } else if (strcmp (element, "color-stop") == 0) {
153 trace->tail = " add-color-stop\n";
154 } else if (strcmp (element, "path") == 0) {
155 /* need to reset the matrix to identity before the path */
156 fprintf (trace->stream, "identity set-matrix ");
158 } else if (strcmp (element, "dash") == 0) {
159 const char *offset = "0";
162 if (strcmp (*attr, "offset") == 0) {
168 fprintf (trace->stream, "[");
169 sprintf (trace->tail_buf, "] %s set-dash\n", offset);
170 trace->tail = trace->tail_buf;
176 cdata (void *closure,
180 struct trace *trace = closure;
183 fwrite (s, len, 1, trace->stream);
187 end_element (void *closure,
190 struct trace *trace = closure;
193 fprintf (trace->stream, "%s", trace->tail);
197 if (strcmp (element, "paint") == 0) {
198 fprintf (trace->stream, "paint\n");
199 } else if (strcmp (element, "mask") == 0) {
200 fprintf (trace->stream, "mask\n");
201 } else if (strcmp (element, "stroke") == 0) {
202 fprintf (trace->stream, "stroke\n");
203 } else if (strcmp (element, "fill") == 0) {
204 fprintf (trace->stream, "fill\n");
205 } else if (strcmp (element, "glyphs") == 0) {
206 fprintf (trace->stream, "show-glyphs\n");
207 } else if (strcmp (element, "clip") == 0) {
208 fprintf (trace->stream, "clip\n");
209 } else if (strcmp (element, "source-pattern") == 0) {
210 fprintf (trace->stream, "set-source\n");
211 } else if (strcmp (element, "mask-pattern") == 0) {
212 } else if (strcmp (element, "surface") == 0) {
213 if (--trace->surface_depth == 0)
214 fprintf (trace->stream, "pop\n");
216 fprintf (trace->stream, "pop pattern\n");
221 main (int argc, char **argv)
229 trace.stream = stdout;
231 trace.surface_depth = 0;
233 if (argc >= 2 && strcmp (argv[1], "-"))
234 in = fopen (argv[1], "r");
235 if (argc >= 3 && strcmp (argv[2], "-"))
236 trace.stream = fopen (argv[2], "w");
238 p = XML_ParserCreate (NULL);
239 XML_SetUserData (p, &trace);
240 XML_SetElementHandler (p, start_element, end_element);
241 XML_SetCharacterDataHandler (p, cdata);
245 len = fread (buf, 1, sizeof (buf), in);
248 if (XML_Parse (p, buf, len, done) == XML_STATUS_ERROR) {
249 fprintf (stderr, "Parse error at line %ld:\n%s\n",
250 XML_GetCurrentLineNumber (p),
251 XML_ErrorString (XML_GetErrorCode (p)));
259 if (trace.stream != stdout)
260 fclose (trace.stream);