annotate src/shape_path.c @ 107:069868161f63

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