annotate src/shape_path.c @ 9:6eecdd331fe7

Fix bug in testcase
author Thinker K.F. Li <thinker@branda.to>
date Sat, 26 Jul 2008 04:27:52 +0800
parents 94b4b5bd8810
children 7cfecdce94cc
rev   line source
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include <stdlib.h>
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include <ctype.h>
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include <string.h>
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #include <cairo.h>
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 #include "mb_types.h"
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7
8
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
8 /*! \brief Implement respective objects for SVG path tag.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
9 *
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
10 * In user_data or dev_data, 0x00 bytes are padding after commands.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
11 * No commands other than 0x00 can resident after 0x00 itself.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
12 * It means command processing code can skip commands after a 0x00.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
13 */
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 typedef struct _sh_path {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 shape_t shape;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 int cmd_len;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 int arg_len;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 char *user_data;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 char *dev_data; /* device space data */
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 } sh_path_t;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 #define ASSERT(x)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 #define SKIP_SPACE(x) while(*(x) && isspace(*(x))) { (x)++; }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 #define SKIP_NUM(x) \
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 while(*(x) && \
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 (isdigit(*(x)) || \
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 *(x) == '-' || \
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 *(x) == '+')) { \
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 (x)++; \
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 #define OK 0
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 #define ERR -1
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 void sh_path_free(shape_t *shape) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 sh_path_t *path = (sh_path_t *)shape;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 if(path->user_data)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 free(path->user_data);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 if(path->dev_data)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 free(path->dev_data);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 free(path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 static int sh_path_cmd_arg_cnt(char *data, int *cmd_cntp, int *arg_cntp) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 char *p, *old;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 int cmd_cnt, arg_cnt;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 cmd_cnt = arg_cnt = 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 p = data;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 switch(*p++) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 case 'c':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 case 'C':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
84 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
96 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99 case 's':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100 case 'S':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101 case 'q':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102 case 'Q':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
103 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
108 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
110 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
111
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
112 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
113 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
114 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
115 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
116 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
117 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
118
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
119 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
120 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
121 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
122 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
123 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
124 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
125
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
126 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
127 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
128 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
129 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
130 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
131 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
132 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
133 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
134 case 'm':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
135 case 'M':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
136 case 'l':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
137 case 'L':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
138 case 't':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
139 case 'T':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
140 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
141 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
142 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
143 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
144 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
145 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
146 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
147 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
148
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
149 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
150 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
151 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
152 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
153 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
154 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
155 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
156 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
157 case 'h':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
158 case 'H':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
159 case 'v':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
160 case 'V':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
161 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
162 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
163 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
164 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
165 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
166 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
167 arg_cnt += 2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
168 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
169 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
170 case 'z':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
171 case 'Z':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
172 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
173 default:
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
174 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
175 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
176 cmd_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
177 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
178
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
179 *cmd_cntp = cmd_cnt;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
180 *arg_cntp = arg_cnt;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
181 return OK;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
182 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
183
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
184 static int sh_path_cmd_arg_fill(char *data, sh_path_t *path) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
185 char *p, *old;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
186 char *cmds;
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
187 char cmd;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
188 co_aix *args;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
189
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
190 cmds = path->user_data;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
191 args = (co_aix *)(cmds + path->cmd_len);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
192 p = data;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
193 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
194 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
195
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
196 /* Transform all relative to absolute, */
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
197 *cmds++ = toupper(*p);
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
198 switch((cmd = *p++)) {
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
199 case 'c':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
200 case 'C':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
201 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
202 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
203 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
204 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
205 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
206 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
207 break;
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
208 *args++ = islower(cmd)? *(args - 2) + atof(old): atof(old);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
209
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
210 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
211 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
212 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
213 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
214 return ERR;
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
215 *args++ = islower(cmd)? *(args - 2) + atof(old): atof(old);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
216
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
217 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
218 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
219 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
220 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
221 return ERR;
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
222 *args++ = islower(cmd)? *(args - 2) + atof(old): atof(old);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
223
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
224 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
225 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
226 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
227 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
228 return ERR;
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
229 *args++ = islower(cmd)? *(args - 2) + atof(old): atof(old);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
230 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
231 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
232 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
233 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
234 return ERR;
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
235 *args++ = islower(cmd)? *(args - 2) + atof(old): atof(old);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
236
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
237 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
238 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
239 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
240 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
241 return ERR;
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
242 *args++ = islower(cmd)? *(args - 2) + atof(old): atof(old);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
243 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
244 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
245 case 's':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
246 case 'S':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
247 case 'q':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
248 case 'Q':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
249 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
250 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
251 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
252 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
253 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
254 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
255 break;
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
256 *args++ = islower(cmd)? *(args - 2) + atof(old): atof(old);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
257
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
258 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
259 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
260 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
261 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
262 return ERR;
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
263 *args++ = islower(cmd)? *(args - 2) + atof(old): atof(old);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
264
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
265 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
266 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
267 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
268 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
269 return ERR;
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
270 *args++ = islower(cmd)? *(args - 2) + atof(old): atof(old);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
271
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
272 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
273 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
274 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
275 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
276 return ERR;
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
277 *args++ = islower(cmd)? *(args - 2) + atof(old): atof(old);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
278 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
279 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
280 case 'm':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
281 case 'M':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
282 case 'l':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
283 case 'L':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
284 case 't':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
285 case 'T':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
286 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
287 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
288 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
289 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
290 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
291 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
292 break;
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
293 *args++ = islower(cmd)? *(args - 2) + atof(old): atof(old);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
294
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
295 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
296 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
297 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
298 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
299 return ERR;
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
300 *args++ = islower(cmd)? *(args - 2) + atof(old): atof(old);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
301 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
302 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
303 case 'h':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
304 case 'H':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
305 case 'v':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
306 case 'V':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
307 /* TODO: implement h, H, v, V comamnds for path. */
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
308 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
309 case 'z':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
310 case 'Z':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
311 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
312 default:
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
313 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
314 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
315 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
316
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
317 return OK;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
318 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
319
9
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
320 /*! \brief Create a path from value of 'data' of SVG path.
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
321 */
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
322 shape_t *sh_path_new(char *data) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
323 sh_path_t *path;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
324 int cmd_cnt, arg_cnt;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
325 int r;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
326
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
327 r = sh_path_cmd_arg_cnt(data, &cmd_cnt, &arg_cnt);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
328 if(r == ERR)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
329 return NULL;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
330
8
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
331 /* Align at 4's boundary and keep 2 unused co_aix space
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
332 * to make logic of transformation from relative to absolute
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
333 * simple.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
334 */
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
335 cmd_cnt += sizeof(co_aix) * 2;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
336 cmd_cnt = (cmd_cnt + 3) & ~0x3;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
337
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
338 path = (sh_path_t *)malloc(sizeof(sh_path_t));
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
339 path->shape.sh_type = SHT_PATH;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
340 path->cmd_len = cmd_cnt;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
341 path->arg_len = arg_cnt;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
342 path->user_data = (char *)malloc(cmd_cnt + sizeof(co_aix) * arg_cnt);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
343 if(path->user_data == NULL) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
344 free(path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
345 return NULL;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
346 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
347 path->dev_data = (char *)malloc(cmd_cnt + sizeof(co_aix) * arg_cnt);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
348 if(path->dev_data == NULL) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
349 free(path->dev_data);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
350 free(path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
351 return NULL;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
352 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
353
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
354 memset(path->user_data, 0, cmd_cnt);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
355 r = sh_path_cmd_arg_fill(data, path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
356 if(r == ERR) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
357 free(path->user_data);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
358 free(path->dev_data);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
359 free(path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
360 return NULL;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
361 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
362 memcpy(path->dev_data, path->user_data, cmd_cnt);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
363
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
364 return (shape_t *)path;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
365 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
366
9
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
367 /*! \brief Transform a path from user space to device space.
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
368 *
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
369 * TODO: associate coord_t with shape objects and transform them
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
370 * automatically.
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
371 */
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
372 void sh_path_transform(shape_t *shape, coord_t *coord) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
373 sh_path_t *path;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
374 co_aix *user_args, *dev_args;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
375 int i;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
376
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
377 ASSERT(shape->type == SHT_PATH);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
378 ASSERT((shape->arg_len & 0x1) == 0);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
379
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
380 path = (sh_path_t *)shape;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
381 user_args = (co_aix *)(path->user_data + path->cmd_len);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
382 dev_args = (co_aix *)(path->dev_data + path->cmd_len);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
383 for(i = 0; i < path->arg_len; i += 2) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
384 dev_args[0] = *user_args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
385 dev_args[1] = *user_args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
386 coord_trans_pos(coord, dev_args, dev_args + 1);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
387 dev_args += 2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
388 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
389 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
390
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
391 void sh_path_draw(shape_t *shape, cairo_t *cr) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
392 sh_path_t *path;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
393 int cmd_len;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
394 char *cmds, cmd;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
395 co_aix *args;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
396 co_aix x, y, x1, y1, x2, y2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
397 int i;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
398
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
399 ASSERT(shape->type == SHT_PATH);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
400
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
401 path = (sh_path_t *)shape;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
402 cmd_len = path->cmd_len;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
403 cmds = path->dev_data;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
404 args = (co_aix *)(cmds + cmd_len);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
405 x = y = 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
406 for(i = 0; i < cmd_len; i++) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
407 cmd = *cmds++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
408 switch(cmd) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
409 case 'm':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
410 x = x + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
411 y = y + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
412 cairo_move_to(cr, x, y);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
413 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
414 case 'M':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
415 x = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
416 y = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
417 cairo_move_to(cr, x, y);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
418 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
419 case 'l':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
420 x = x + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
421 y = y + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
422 cairo_line_to(cr, x, y);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
423 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
424 case 'L':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
425 x = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
426 y = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
427 cairo_line_to(cr, x, y);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
428 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
429 case 'c':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
430 x1 = x + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
431 y1 = y + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
432 x2 = x1 + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
433 y2 = y1 + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
434 x = x2 + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
435 y = y2 + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
436 cairo_curve_to(cr, x1, y1, x2, y2, x, y);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
437 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
438 case 'C':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
439 x1 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
440 y1 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
441 x2 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
442 y2 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
443 x = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
444 y = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
445 cairo_curve_to(cr, x1, y1, x2, y2, x, y);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
446 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
447 case 's':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
448 x1 = x + x - x2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
449 y1 = y + y - y2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
450 x2 = x1 + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
451 y2 = y1 + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
452 x = x2 + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
453 y = y2 + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
454 cairo_curve_to(cr, x1, y1, x2, y2, x, y);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
455 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
456 case 'S':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
457 x1 = x + x - x2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
458 y1 = y + y - y2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
459 x2 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
460 y2 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
461 x = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
462 y = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
463 cairo_curve_to(cr, x1, y1, x2, y2, x, y);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
464 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
465 case 'q':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
466 x1 = x + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
467 y1 = y + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
468 x2 = x1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
469 y2 = y1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
470 x = x2 + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
471 y = y2 + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
472 cairo_curve_to(cr, x1, y1, x2, y2, x, y);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
473 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
474 case 'Q':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
475 x1 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
476 y1 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
477 x2 = x1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
478 y2 = y1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
479 x = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
480 y = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
481 cairo_curve_to(cr, x1, y1, x2, y2, x, y);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
482 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
483 case 't':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
484 x1 = x + x - x2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
485 y1 = y + y - y2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
486 x2 = x1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
487 y2 = y1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
488 x = x2 + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
489 y = y2 + *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
490 cairo_curve_to(cr, x1, y1, x2, y2, x, y);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
491 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
492 case 'T':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
493 x1 = x + x - x2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
494 y1 = y + y - y2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
495 x2 = x1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
496 y2 = y1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
497 x = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
498 y = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
499 cairo_curve_to(cr, x1, y1, x2, y2, x, y);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
500 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
501 case 'Z':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
502 case 'z':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
503 cairo_close_path(cr);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
504 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
505 case '\x0':
8
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
506 i = cmd_len; /* padding! Skip remain ones. */
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
507 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
508 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
509 }
6
772511b8b9be Cairo specify RGB values in range 0.0 ~ 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
510
772511b8b9be Cairo specify RGB values in range 0.0 ~ 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
511 cairo_fill(cr);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
512 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
513
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
514 #ifdef UNITTEST
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
515
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
516 #include <CUnit/Basic.h>
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
517
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
518 void test_sh_path_new(void) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
519 sh_path_t *path;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
520 co_aix *args;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
521
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
522 path = (sh_path_t *)sh_path_new("M 33 25l33 55C 33 87 44 22 55 99L33 77z");
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
523 CU_ASSERT(path != NULL);
9
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
524 CU_ASSERT(path->cmd_len == ((5 + sizeof(co_aix) * 2 + 3) & ~0x3));
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
525 CU_ASSERT(path->arg_len == 12);
9
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
526 CU_ASSERT(strcmp(path->user_data, "MLCLZ") == 0);
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
527 CU_ASSERT(strcmp(path->dev_data, "MLCLZ") == 0);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
528
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
529 args = (co_aix *)(path->user_data + path->cmd_len);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
530 CU_ASSERT(args[0] == 33);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
531 CU_ASSERT(args[1] == 25);
9
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
532 CU_ASSERT(args[2] == 66);
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
533 CU_ASSERT(args[3] == 80);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
534 CU_ASSERT(args[4] == 33);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
535 CU_ASSERT(args[5] == 87);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
536 CU_ASSERT(args[6] == 44);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
537 CU_ASSERT(args[7] == 22);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
538 CU_ASSERT(args[8] == 55);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
539 CU_ASSERT(args[9] == 99);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
540 CU_ASSERT(args[10] == 33);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
541 CU_ASSERT(args[11] == 77);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
542 sh_path_free((shape_t *)path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
543 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
544
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
545 void test_path_transform(void) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
546 sh_path_t *path;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
547 co_aix *args;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
548 coord_t coord;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
549
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
550 path = (sh_path_t *)sh_path_new("M 33 25l33 55C 33 87 44 22 55 99L33 77z");
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
551 CU_ASSERT(path != NULL);
9
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
552 CU_ASSERT(path->cmd_len == ((5 + sizeof(co_aix) * 2 + 3) & ~0x3));
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
553 CU_ASSERT(path->arg_len == 12);
9
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
554 CU_ASSERT(strcmp(path->user_data, "MLCLZ") == 0);
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
555 CU_ASSERT(strcmp(path->dev_data, "MLCLZ") == 0);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
556
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
557 coord.aggr_matrix[0] = 1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
558 coord.aggr_matrix[1] = 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
559 coord.aggr_matrix[2] = 1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
560 coord.aggr_matrix[3] = 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
561 coord.aggr_matrix[4] = 2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
562 coord.aggr_matrix[5] = 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
563 sh_path_transform((shape_t *)path, &coord);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
564
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
565 args = (co_aix *)(path->dev_data + path->cmd_len);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
566 CU_ASSERT(args[0] == 34);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
567 CU_ASSERT(args[1] == 50);
9
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
568 CU_ASSERT(args[2] == 67);
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
569 CU_ASSERT(args[3] == 160);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
570 CU_ASSERT(args[4] == 34);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
571 CU_ASSERT(args[5] == 174);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
572 CU_ASSERT(args[6] == 45);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
573 CU_ASSERT(args[7] == 44);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
574 CU_ASSERT(args[8] == 56);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
575 CU_ASSERT(args[9] == 198);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
576 CU_ASSERT(args[10] == 34);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
577 CU_ASSERT(args[11] == 154);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
578 sh_path_free((shape_t *)path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
579 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
580
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
581 CU_pSuite get_shape_path_suite(void) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
582 CU_pSuite suite;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
583
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
584 suite = CU_add_suite("Suite_shape_path", NULL, NULL);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
585 CU_ADD_TEST(suite, test_sh_path_new);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
586 CU_ADD_TEST(suite, test_path_transform);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
587
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
588 return suite;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
589 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
590
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
591 #endif /* UNITTEST */