Mercurial > MadButterfly
annotate src/shape_path.c @ 137:5dcfaafd1a9c
-
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 19 Sep 2008 09:53:17 +0800 |
parents | abb5511c23f7 |
children | 609ed47a58f2 |
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 | 8 /*! \brief Implement respective objects for SVG path tag. |
9 * | |
10 * In user_data or dev_data, 0x00 bytes are padding after commands. | |
11 * No commands other than 0x00 can resident after 0x00 itself. | |
12 * It means command processing code can skip commands after a 0x00. | |
12 | 13 * |
14 * Shapes should check if shape_t::geo is assigned. Once transformation | |
15 * matrics are changed, shape objects should update shape_t::geo if | |
16 * it is assigned. | |
8 | 17 */ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 typedef struct _sh_path { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
19 shape_t shape; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 int cmd_len; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
21 int arg_len; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
22 int fix_arg_len; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
23 char *user_data; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
24 char *dev_data; /* device space data */ |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
25 } sh_path_t; |
10 | 26 #define RESERVED_AIXS sizeof(co_aix[2]) |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
27 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
28 #define ASSERT(x) |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
29 #define SKIP_SPACE(x) while(*(x) && (isspace(*(x)) || *(x) == ',')) { (x)++; } |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
30 #define SKIP_NUM(x) \ |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
31 while(*(x) && \ |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
32 (isdigit(*(x)) || \ |
112
abb5511c23f7
Accept exponent of float point
Thinker K.F. Li <thinker@branda.to>
parents:
101
diff
changeset
|
33 *(x) == 'e' || \ |
abb5511c23f7
Accept exponent of float point
Thinker K.F. Li <thinker@branda.to>
parents:
101
diff
changeset
|
34 *(x) == 'E' || \ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
35 *(x) == '-' || \ |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
36 *(x) == '+' || \ |
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
37 *(x) == '.')) { \ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
38 (x)++; \ |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
39 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 #define OK 0 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
41 #define ERR -1 |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
42 #define PI 3.1415926 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
43 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
44 /* ============================================================ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
45 * Implement arc in path. |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
46 */ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
47 #include <math.h> |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
48 /*! \brief Calculate center of the ellipse of an arc. |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
49 * |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
50 * - ux0 = x0 / rx |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
51 * - uy0 = y0 / ry |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
52 * - ux = x / rx |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
53 * - uy = y / rx |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
54 * ux0, uy0, ux, yu are got by transforming (x0, y0) and (x, y) into points |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
55 * on the unit circle. The center of unit circle are (ucx, ucy): |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
56 * - umx = (ux0 + ux) / 2 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
57 * - umy = (uy0 + uy) / 2 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
58 * - udcx = ucx - umx |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
59 * - udcy = ucy - umy |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
60 * - udx = ux - umx |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
61 * - udy = uy - umy |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
62 * |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
63 * - udx * udcx + udy * udcy = 0 |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
64 * |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
65 * - udl2 = udx ** 2 + udy ** 2; |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
66 * - udx * udcy - udy * udcx = sqrt((1 - udl2) * udl2) |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
67 * |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
68 * - udcy = -udcx * udx / udy |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
69 * - -udcx * (udx ** 2) / udy - udy * udcx = sqrt((1 - udl2) * udl2) |
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
70 * - -udcx * ((udx ** 2) / udy + udy) = sqrt((1 - udl2) * udl2) |
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
71 * - udcx = -sqrt((1 - udl2) * udl2) / ((udx ** 2) / udy + udy) |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
72 * or |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
73 * - udcx = -udcy * udy / udx |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
74 * - udx * udcy + udcy * (udy ** 2) / udx = sqrt((1 - udl2) * udl2) |
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
75 * - udcy * (udx + (udy ** 2) / udx) = sqrt((1 - udl2) * udl2) |
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
76 * - udcy = sqrt((1 - udl2) * udl2) / (udx + (udy ** 2) / udx) |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
77 * |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
78 * - cx = rx * ucx |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
79 * - cx = rx * (udcx + umx) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
80 * - cy = ry * ucy |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
81 * - cy = ry * (udcy + umy) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
82 */ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
83 static int calc_center_and_x_aix(co_aix x0, co_aix y0, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
84 co_aix x, co_aix y, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
85 co_aix rx, co_aix ry, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
86 co_aix x_rotate, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
87 int large, int sweep, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
88 co_aix *cx, co_aix *cy, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
89 co_aix *xx, co_aix *xy) { |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
90 co_aix nrx, nry, nrx0, nry0; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
91 co_aix udx, udy, udx2, udy2; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
92 co_aix umx, umy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
93 co_aix udcx, udcy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
94 co_aix nrcx, nrcy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
95 co_aix udl2; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
96 float _sin = sinf(x_rotate); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
97 float _cos = cosf(x_rotate); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
98 int reflect; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
99 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
100 nrx = x * _cos + y * _sin; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
101 nry = x * -_sin + y * _cos; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
102 nrx0 = x0 * _cos + y0 * _sin; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
103 nry0 = x0 * -_sin + y0 * _cos; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
104 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
105 udx = (nrx - nrx0) / 2 / rx; /* ux - umx */ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
106 udy = (nry - nry0) / 2 / ry; /* uy - umy */ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
107 umx = (nrx + nrx0) / 2 / rx; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
108 umy = (nry + nry0) / 2 / ry; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
109 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
110 udx2 = udx * udx; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
111 udy2 = udy * udy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
112 udl2 = udx2 + udy2; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
113 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
114 if(udy != 0) { |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
115 udcx = -sqrtf((1 - udl2) * udl2) / (udy + udx2 / udy); |
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
116 udcy = -udcx * udx / udy; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
117 } else { |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
118 udcx = 0; |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
119 udcy = sqrtf((1 - udl2) * udl2) / udx; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
120 } |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
121 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
122 reflect = 0; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
123 if(large) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
124 reflect ^= 1; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
125 if(sweep != 1) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
126 reflect ^= 1; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
127 if(reflect) { |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
128 udcx = -udcx; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
129 udcy = -udcy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
130 } |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
131 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
132 nrcx = rx * (udcx + umx); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
133 nrcy = ry * (udcy + umy); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
134 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
135 *cx = nrcx * _cos - nrcy * _sin; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
136 *cy = nrcx * _sin + nrcy * _cos; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
137 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
138 *xx = rx * _cos + *cx; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
139 *xy = rx * _sin + *cy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
140 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
141 return OK; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
142 } |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
143 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
144 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
145 #define TAKE_NUM(r) do { \ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
146 SKIP_SPACE(p); \ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
147 old = p; \ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
148 SKIP_NUM(p); \ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
149 if(p == old) \ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
150 return ERR; \ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
151 r = atof(old); \ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
152 } while(0); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
153 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
154 static int sh_path_arc_cmd_arg_fill(char cmd, char **cmds_p, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
155 const char **data_p, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
156 co_aix **args_p, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
157 int **fix_args_p) { |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
158 co_aix rx, ry; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
159 co_aix x_rotate; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
160 int large, sweep; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
161 co_aix x, y, x0, y0, cx, cy, xx, xy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
162 co_aix *args = *args_p; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
163 const char *old; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
164 const char *p; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
165 char *cmds; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
166 int *fix_args; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
167 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
168 p = *data_p; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
169 cmds = *cmds_p; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
170 fix_args = *fix_args_p; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
171 while(*p) { |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
172 SKIP_SPACE(p); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
173 old = p; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
174 SKIP_NUM(p); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
175 if(p == old) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
176 break; |
99
4aa1c9673363
Arc in path pass the test in example svg2code_ex.
Thinker K.F. Li <thinker@branda.to>
parents:
98
diff
changeset
|
177 rx = atof(old); |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
178 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
179 TAKE_NUM(ry); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
180 TAKE_NUM(x_rotate); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
181 TAKE_NUM(large); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
182 TAKE_NUM(sweep); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
183 TAKE_NUM(x); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
184 TAKE_NUM(y) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
185 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
186 x0 = *(args - 2); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
187 y0 = *(args - 1); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
188 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
189 if(islower(cmd)) { |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
190 x += x0; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
191 y += y0; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
192 } |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
193 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
194 calc_center_and_x_aix(x0, y0, x, y, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
195 rx, ry, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
196 x_rotate, large, sweep, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
197 &cx, &cy, &xx, &xy); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
198 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
199 *(args++) = cx; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
200 *(args++) = cy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
201 *(args++) = xx; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
202 *(args++) = xy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
203 *(args++) = x; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
204 *(args++) = y; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
205 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
206 *cmds++ = toupper(cmd); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
207 *fix_args++ = sweep; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
208 } |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
209 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
210 *data_p = p; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
211 *args_p = args; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
212 *cmds_p = cmds; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
213 *fix_args_p = fix_args; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
214 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
215 return OK; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
216 } |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
217 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
218 #define INNER(x1, y1, x2, y2) ((x1) * (x2) + (y1) * (y2)) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
219 #define CROSS(x1, y1, x2, y2) ((x1) * (y2) - (y1) * (x2)) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
220 |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
221 /*! \brief Make path for arcs in a path. |
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
222 */ |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
223 void sh_path_arc_path(cairo_t *cr, const co_aix **args_p, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
224 const int **fix_args_p) { |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
225 co_aix cx, cy, x0, y0, x, y, xx, xy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
226 co_aix dx, dy, dx0, dy0, dxx, dxy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
227 co_aix xyratio; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
228 co_aix rx; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
229 co_aix rx2; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
230 co_aix inner0, cross0; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
231 co_aix circle_h0; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
232 co_aix inner, cross; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
233 co_aix angle, angle0; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
234 co_aix rotate; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
235 const co_aix *args = *args_p; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
236 const int *fix_args = *fix_args_p; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
237 int sweep; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
238 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
239 x0 = *(args - 2); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
240 y0 = *(args - 1); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
241 cx = *args++; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
242 cy = *args++; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
243 xx = *args++; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
244 xy = *args++; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
245 x = *args++; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
246 y = *args++; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
247 sweep = *fix_args++; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
248 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
249 dx = x - cx; |
99
4aa1c9673363
Arc in path pass the test in example svg2code_ex.
Thinker K.F. Li <thinker@branda.to>
parents:
98
diff
changeset
|
250 dy = y - cy; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
251 dx0 = x0 - cx; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
252 dy0 = y0 - cy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
253 dxx = xx - cx; |
99
4aa1c9673363
Arc in path pass the test in example svg2code_ex.
Thinker K.F. Li <thinker@branda.to>
parents:
98
diff
changeset
|
254 dxy = xy - cy; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
255 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
256 rx2 = dxx * dxx + dxy * dxy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
257 rx = sqrtf(rx2); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
258 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
259 /*! \note Why we calculate these numbers there? |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
260 * If we compute it when filling arguments, sh_path_arc_cmd_arg_fill(), |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
261 * we can avoid to recompute it for every drawing. But, transforming of |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
262 * coordinate can effect value of the numbers. |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
263 */ |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
264 inner0 = INNER(dxx, dxy, dx0, dy0); |
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
265 cross0 = CROSS(dxx, dxy, dx0, dy0); |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
266 circle_h0 = sqrtf(rx2 - inner0 * inner0 / rx2); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
267 xyratio = cross0 / rx / circle_h0; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
268 if(xyratio < 0) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
269 xyratio = -xyratio; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
270 |
99
4aa1c9673363
Arc in path pass the test in example svg2code_ex.
Thinker K.F. Li <thinker@branda.to>
parents:
98
diff
changeset
|
271 angle0 = acos(inner0 / rx2); |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
272 if(cross0 < 0) |
99
4aa1c9673363
Arc in path pass the test in example svg2code_ex.
Thinker K.F. Li <thinker@branda.to>
parents:
98
diff
changeset
|
273 angle0 = PI * 2 - angle0; /* 3rd, 4th Quadrant */ |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
274 |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
275 inner = INNER(dxx, dxy, dx, dy); |
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
276 cross = CROSS(dxx, dxy, dx, dy); |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
277 angle = acos(inner / rx2); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
278 if(cross < 0) |
99
4aa1c9673363
Arc in path pass the test in example svg2code_ex.
Thinker K.F. Li <thinker@branda.to>
parents:
98
diff
changeset
|
279 angle = PI * 2 - angle; /* 3rd, 4th Quadrant */ |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
280 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
281 /* Make a path for arc */ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
282 rotate = acos(dxx / rx); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
283 cairo_save(cr); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
284 cairo_translate(cr, cx, cy); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
285 cairo_rotate(cr, rotate); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
286 cairo_scale(cr, 1.0, xyratio); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
287 if(sweep) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
288 cairo_arc(cr, 0, 0, rx, angle0, angle); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
289 else |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
290 cairo_arc_negative(cr, 0, 0, rx, angle0, angle); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
291 cairo_restore(cr); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
292 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
293 *args_p = args; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
294 *fix_args_p = fix_args; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
295 } |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
296 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
297 /* ============================================================ */ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
298 |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
299 static void sh_path_free(shape_t *shape) { |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
300 sh_path_t *path = (sh_path_t *)shape; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
301 if(path->user_data) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
302 free(path->user_data); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
303 if(path->dev_data) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
304 free(path->dev_data); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
305 free(path); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
306 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
307 |
86
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
73
diff
changeset
|
308 /*! \brief Count number of arguments. |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
73
diff
changeset
|
309 * |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
73
diff
changeset
|
310 * \todo Notify programmers that syntax or value error of path data. |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
73
diff
changeset
|
311 */ |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
312 static int sh_path_cmd_arg_cnt(char *data, int *cmd_cntp, int *arg_cntp, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
313 int *fix_arg_cntp) { |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
314 char *p, *old; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
315 int cmd_cnt, arg_cnt, fix_arg_cnt; |
96 | 316 int i; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
317 |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
318 cmd_cnt = arg_cnt = fix_arg_cnt = 0; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
319 p = data; |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
320 SKIP_SPACE(p); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
321 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
322 switch(*p++) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
323 case 'c': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
324 case 'C': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
325 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
326 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
327 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
328 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
329 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
330 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
331 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
332 arg_cnt++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
333 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
334 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
335 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
336 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
337 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
338 return ERR; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
339 arg_cnt++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
340 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
341 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
342 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
343 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
344 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
345 return ERR; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
346 arg_cnt++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
347 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
348 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
349 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
350 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
351 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
352 return ERR; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
353 arg_cnt++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
354 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
355 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
356 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
357 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
358 return ERR; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
359 arg_cnt++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
360 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
361 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
362 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
363 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
364 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
365 return ERR; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
366 arg_cnt++; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
367 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
368 cmd_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
369 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
370 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
371 case 's': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
372 case 'S': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
373 case 'q': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
374 case 'Q': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
375 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
376 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
377 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
378 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
379 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
380 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
381 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
382 arg_cnt++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
383 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
384 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
385 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
386 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
387 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
388 return ERR; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
389 arg_cnt++; |
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 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
392 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
393 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
394 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
395 return ERR; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
396 arg_cnt++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
397 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
398 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
399 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
400 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
401 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
402 return ERR; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
403 arg_cnt++; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
404 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
405 cmd_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
406 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
407 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
408 case 'm': |
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 case 'l': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
411 case 'L': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
412 case 't': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
413 case 'T': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
414 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
415 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
416 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
417 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
418 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
419 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
420 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
421 arg_cnt++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
422 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
423 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
424 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
425 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
426 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
427 return ERR; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
428 arg_cnt++; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
429 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
430 cmd_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
431 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
432 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
433 case 'h': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
434 case 'H': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
435 case 'v': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
436 case 'V': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
437 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
438 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
439 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
440 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
441 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
442 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
443 arg_cnt += 2; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
444 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
445 cmd_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
446 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
447 break; |
96 | 448 case 'A': |
449 case 'a': | |
450 while(*p) { | |
451 SKIP_SPACE(p); | |
452 old = p; | |
453 SKIP_NUM(p); | |
454 if(p == old) | |
455 break; | |
456 | |
457 for(i = 0; i < 6; i++) { | |
458 SKIP_SPACE(p); | |
459 old = p; | |
460 SKIP_NUM(p); | |
461 if(p == old) | |
462 return ERR; | |
463 } | |
464 | |
465 arg_cnt += 6; | |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
466 fix_arg_cnt++; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
467 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
468 cmd_cnt++; |
96 | 469 } |
470 break; | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
471 case 'z': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
472 case 'Z': |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
473 cmd_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
474 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
475 default: |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
476 return ERR; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
477 } |
96 | 478 /*! \todo cmd_cnt should be increased for each implicit repeating. */ |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
479 SKIP_SPACE(p); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
480 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
481 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
482 *cmd_cntp = cmd_cnt; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
483 *arg_cntp = arg_cnt; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
484 *fix_arg_cntp = fix_arg_cnt; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
485 return OK; |
96 | 486 } |
487 | |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
488 #define TO_ABSX islower(cmd)? x + atof(old): atof(old) |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
489 #define TO_ABSY islower(cmd)? y + atof(old): atof(old) |
10 | 490 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
491 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
|
492 char *p, *old; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
493 char *cmds; |
7
569f3168ba53
Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents:
6
diff
changeset
|
494 char cmd; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
495 co_aix *args; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
496 int *fix_args; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
497 co_aix x, y; |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
498 int r; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
499 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
500 cmds = path->user_data; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
501 args = (co_aix *)(cmds + path->cmd_len); |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
502 fix_args = (int *)(cmds + path->cmd_len + |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
503 path->arg_len * sizeof(co_aix)); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
504 p = data; |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
505 SKIP_SPACE(p); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
506 while(*p) { |
7
569f3168ba53
Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents:
6
diff
changeset
|
507 /* Transform all relative to absolute, */ |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
508 x = *(args - 2); |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
509 y = *(args - 1); |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
510 |
7
569f3168ba53
Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents:
6
diff
changeset
|
511 switch((cmd = *p++)) { |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
512 case 'c': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
513 case 'C': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
514 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
515 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
516 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
517 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
518 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
519 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
520 break; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
521 *args = TO_ABSX; |
10 | 522 args++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
523 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
524 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
525 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
526 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
527 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
528 return ERR; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
529 *args = TO_ABSY; |
10 | 530 args++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
531 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
532 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
533 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
534 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
535 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
536 return ERR; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
537 *args = TO_ABSX; |
10 | 538 args++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
539 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
540 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
541 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
542 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
543 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
544 return ERR; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
545 *args = TO_ABSY; |
10 | 546 args++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
547 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
548 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
549 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
550 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
551 return ERR; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
552 *args = TO_ABSX; |
10 | 553 args++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
554 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
555 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
556 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
557 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
558 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
559 return ERR; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
560 *args = TO_ABSY; |
10 | 561 args++; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
562 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
563 *cmds++ = toupper(cmd); |
5
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 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
566 case 's': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
567 case 'S': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
568 case 'q': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
569 case 'Q': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
570 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
571 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
572 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
573 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
574 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
575 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
576 break; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
577 *args = TO_ABSX; |
10 | 578 args++; |
5
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 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
581 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
582 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
583 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
584 return ERR; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
585 *args = TO_ABSY; |
10 | 586 args++; |
5
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 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
589 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
590 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
591 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
592 return ERR; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
593 *args = TO_ABSX; |
10 | 594 args++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
595 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
596 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
597 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
598 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
599 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
600 return ERR; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
601 *args = TO_ABSY; |
10 | 602 args++; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
603 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
604 *cmds++ = toupper(cmd); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
605 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
606 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
607 case 'm': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
608 case 'M': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
609 case 'l': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
610 case 'L': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
611 case 't': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
612 case 'T': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
613 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
614 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
615 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
616 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
617 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
618 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
619 break; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
620 *args = TO_ABSX; |
10 | 621 args++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
622 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
623 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
624 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
625 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
626 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
627 return ERR; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
628 *args = TO_ABSY; |
10 | 629 args++; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
630 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
631 *cmds++ = toupper(cmd); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
632 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
633 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
634 case 'h': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
635 case 'H': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
636 case 'v': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
637 case 'V': |
58 | 638 /*! \todo implement h, H, v, V comamnds for path. */ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
639 return ERR; |
96 | 640 |
641 case 'A': | |
642 case 'a': | |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
643 r = sh_path_arc_cmd_arg_fill(cmd, &cmds, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
644 (const char **)&p, &args, |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
645 &fix_args); |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
646 if(r != OK) |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
647 return ERR; |
96 | 648 break; |
649 | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
650 case 'z': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
651 case 'Z': |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
652 *cmds++ = toupper(cmd); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
653 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
654 default: |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
655 return ERR; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
656 } |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
657 SKIP_SPACE(p); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
658 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
659 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
660 return OK; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
661 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
662 |
9 | 663 /*! \brief Create a path from value of 'data' of SVG path. |
664 */ | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
665 shape_t *sh_path_new(char *data) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
666 sh_path_t *path; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
667 int cmd_cnt, arg_cnt, fix_arg_cnt; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
668 int msz; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
669 int r; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
670 |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
671 r = sh_path_cmd_arg_cnt(data, &cmd_cnt, &arg_cnt, &fix_arg_cnt); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
672 if(r == ERR) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
673 return NULL; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
674 |
8 | 675 /* Align at 4's boundary and keep 2 unused co_aix space |
676 * to make logic of transformation from relative to absolute | |
677 * simple. | |
678 */ | |
10 | 679 cmd_cnt += RESERVED_AIXS; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
680 cmd_cnt = (cmd_cnt + 3) & ~0x3; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
681 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
682 path = (sh_path_t *)malloc(sizeof(sh_path_t)); |
12 | 683 memset(&path->shape, 0, sizeof(shape_t)); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
684 path->shape.sh_type = SHT_PATH; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
685 path->cmd_len = cmd_cnt; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
686 path->arg_len = arg_cnt; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
687 path->fix_arg_len = fix_arg_cnt; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
688 msz = cmd_cnt + sizeof(co_aix) * arg_cnt + sizeof(int) * fix_arg_cnt; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
689 path->user_data = (char *)malloc(msz); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
690 if(path->user_data == NULL) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
691 free(path); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
692 return NULL; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
693 } |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
694 path->dev_data = (char *)malloc(msz); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
695 if(path->dev_data == NULL) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
696 free(path->dev_data); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
697 free(path); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
698 return NULL; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
699 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
700 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
701 memset(path->user_data, 0, cmd_cnt); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
702 r = sh_path_cmd_arg_fill(data, path); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
703 if(r == ERR) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
704 free(path->user_data); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
705 free(path->dev_data); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
706 free(path); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
707 return NULL; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
708 } |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
709 memcpy(path->dev_data, path->user_data, msz); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
710 |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
711 path->shape.free = sh_path_free; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
712 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
713 return (shape_t *)path; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
714 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
715 |
9 | 716 /*! \brief Transform a path from user space to device space. |
717 * | |
718 */ | |
12 | 719 void sh_path_transform(shape_t *shape) { |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
720 sh_path_t *path; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
721 co_aix *user_args, *dev_args; |
12 | 722 co_aix (*poses)[2]; |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
723 area_t *area; |
12 | 724 int arg_len; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
725 int i; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
726 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
727 ASSERT(shape->type == SHT_PATH); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
728 ASSERT((shape->arg_len & 0x1) == 0); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
729 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
730 path = (sh_path_t *)shape; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
731 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
|
732 dev_args = (co_aix *)(path->dev_data + path->cmd_len); |
12 | 733 arg_len = path->arg_len; |
734 for(i = 0; i < arg_len; i += 2) { | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
735 dev_args[0] = *user_args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
736 dev_args[1] = *user_args++; |
12 | 737 coord_trans_pos(shape->coord, dev_args, dev_args + 1); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
738 dev_args += 2; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
739 } |
12 | 740 |
741 if(path->shape.geo) { | |
742 poses = (co_aix (*)[2])(path->dev_data + path->cmd_len); | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
743 geo_from_positions(path->shape.geo, arg_len / 2, poses); |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
744 area = shape->geo->cur_area; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
745 area->x -= shape->stroke_width/2 + 1; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
746 area->y -= shape->stroke_width/2 + 1; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
747 area->w += shape->stroke_width + 2; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
748 area->h += shape->stroke_width + 2; |
12 | 749 } |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
750 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
751 |
22 | 752 static void sh_path_path(shape_t *shape, cairo_t *cr) { |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
753 sh_path_t *path; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
754 int cmd_len; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
755 char *cmds, cmd; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
756 const co_aix *args; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
757 const int *fix_args; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
758 co_aix x, y, x1, y1, x2, y2; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
759 int i; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
760 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
761 ASSERT(shape->type == SHT_PATH); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
762 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
763 path = (sh_path_t *)shape; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
764 cmd_len = path->cmd_len; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
765 cmds = path->dev_data; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
766 args = (co_aix *)(cmds + cmd_len); |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
767 fix_args = (int *)(cmds + cmd_len + path->arg_len * sizeof(co_aix)); |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
12
diff
changeset
|
768 x = y = x1 = y1 = x2 = y2 = 0; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
769 for(i = 0; i < cmd_len; i++) { |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
770 /* All path commands and arguments are transformed |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
771 * to absoluted form. |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
772 */ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
773 cmd = *cmds++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
774 switch(cmd) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
775 case 'M': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
776 x = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
777 y = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
778 cairo_move_to(cr, x, y); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
779 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
780 case 'L': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
781 x = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
782 y = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
783 cairo_line_to(cr, x, y); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
784 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
785 case 'C': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
786 x1 = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
787 y1 = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
788 x2 = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
789 y2 = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
790 x = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
791 y = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
792 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
|
793 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
794 case 'S': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
795 x1 = x + x - x2; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
796 y1 = y + y - y2; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
797 x2 = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
798 y2 = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
799 x = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
800 y = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
801 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
|
802 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
803 case 'Q': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
804 x1 = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
805 y1 = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
806 x2 = x1; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
807 y2 = y1; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
808 x = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
809 y = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
810 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
|
811 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
812 case 'T': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
813 x1 = x + x - x2; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
814 y1 = y + y - y2; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
815 x2 = x1; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
816 y2 = y1; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
817 x = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
818 y = *args++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
819 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
|
820 break; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
821 case 'A': |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
822 sh_path_arc_path(cr, &args, &fix_args); |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
823 break; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
824 case 'Z': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
825 cairo_close_path(cr); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
826 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
827 case '\x0': |
8 | 828 i = cmd_len; /* padding! Skip remain ones. */ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
829 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
830 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
831 } |
22 | 832 } |
6
772511b8b9be
Cairo specify RGB values in range 0.0 ~ 1.0.
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
833 |
30
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
26
diff
changeset
|
834 void sh_path_draw(shape_t *shape, cairo_t *cr) { |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
26
diff
changeset
|
835 sh_path_path(shape, cr); |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
26
diff
changeset
|
836 } |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
26
diff
changeset
|
837 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
838 #ifdef UNITTEST |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
839 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
840 #include <CUnit/Basic.h> |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
841 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
842 void test_sh_path_new(void) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
843 sh_path_t *path; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
844 co_aix *args; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
845 |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
846 path = (sh_path_t *)sh_path_new("M 33 25l33 55c 33 87 44 22 55 99L33 77z"); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
847 CU_ASSERT(path != NULL); |
10 | 848 CU_ASSERT(path->cmd_len == ((5 + RESERVED_AIXS + 3) & ~0x3)); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
849 CU_ASSERT(path->arg_len == 12); |
9 | 850 CU_ASSERT(strcmp(path->user_data, "MLCLZ") == 0); |
851 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
|
852 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
853 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
|
854 CU_ASSERT(args[0] == 33); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
855 CU_ASSERT(args[1] == 25); |
9 | 856 CU_ASSERT(args[2] == 66); |
857 CU_ASSERT(args[3] == 80); | |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
858 CU_ASSERT(args[4] == 99); |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
859 CU_ASSERT(args[5] == 167); |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
860 CU_ASSERT(args[6] == 110); |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
861 CU_ASSERT(args[7] == 102); |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
862 CU_ASSERT(args[8] == 121); |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
863 CU_ASSERT(args[9] == 179); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
864 CU_ASSERT(args[10] == 33); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
865 CU_ASSERT(args[11] == 77); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
866 sh_path_free((shape_t *)path); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
867 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
868 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
869 void test_path_transform(void) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
870 sh_path_t *path; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
871 co_aix *args; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
872 coord_t coord; |
12 | 873 geo_t geo; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
874 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
875 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
|
876 CU_ASSERT(path != NULL); |
10 | 877 CU_ASSERT(path->cmd_len == ((5 + RESERVED_AIXS + 3) & ~0x3)); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
878 CU_ASSERT(path->arg_len == 12); |
9 | 879 CU_ASSERT(strcmp(path->user_data, "MLCLZ") == 0); |
880 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
|
881 |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
882 geo_init(&geo); |
12 | 883 path->shape.geo = &geo; |
884 geo.shape = (shape_t *)path; | |
885 | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
886 coord.aggr_matrix[0] = 1; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
887 coord.aggr_matrix[1] = 0; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
888 coord.aggr_matrix[2] = 1; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
889 coord.aggr_matrix[3] = 0; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
890 coord.aggr_matrix[4] = 2; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
891 coord.aggr_matrix[5] = 0; |
12 | 892 path->shape.coord = &coord; |
893 sh_path_transform((shape_t *)path); | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
894 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
895 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
|
896 CU_ASSERT(args[0] == 34); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
897 CU_ASSERT(args[1] == 50); |
9 | 898 CU_ASSERT(args[2] == 67); |
899 CU_ASSERT(args[3] == 160); | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
900 CU_ASSERT(args[4] == 34); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
901 CU_ASSERT(args[5] == 174); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
902 CU_ASSERT(args[6] == 45); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
903 CU_ASSERT(args[7] == 44); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
904 CU_ASSERT(args[8] == 56); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
905 CU_ASSERT(args[9] == 198); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
906 CU_ASSERT(args[10] == 34); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
907 CU_ASSERT(args[11] == 154); |
12 | 908 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
909 sh_path_free((shape_t *)path); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
910 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
911 |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
912 void test_spaces_head_tail(void) { |
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
913 sh_path_t *path; |
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
914 |
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
915 path = (sh_path_t *) |
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
916 sh_path_new(" M 33 25l33 55C 33 87 44 22 55 99L33 77z "); |
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
917 CU_ASSERT(path != NULL); |
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
918 sh_path_free((shape_t *)path); |
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
919 } |
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
920 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
921 CU_pSuite get_shape_path_suite(void) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
922 CU_pSuite suite; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
923 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
924 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
|
925 CU_ADD_TEST(suite, test_sh_path_new); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
926 CU_ADD_TEST(suite, test_path_transform); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
927 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
928 return suite; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
929 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
930 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
931 #endif /* UNITTEST */ |