annotate src/shape_path.c @ 456:26c302b47de1

Change name of header files.
author Thinker K.F. Li <thinker@branda.to>
date Thu, 06 Aug 2009 15:38:04 +0800
parents 16116d84bc5e
children bb4f651090bf
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>
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
5 #include "mb_graph_engine.h"
186
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 185
diff changeset
6 #include "mb_types.h"
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 185
diff changeset
7 #include "mb_redraw_man.h"
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8
8
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
9 /*! \brief Implement respective objects for SVG path tag.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
10 *
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
11 * In user_data or dev_data, 0x00 bytes are padding after commands.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
12 * No commands other than 0x00 can resident after 0x00 itself.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
13 * 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
14 *
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
15 * 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
16 * 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
17 * it is assigned.
8
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
18 */
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 typedef struct _sh_path {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 shape_t shape;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 int cmd_len;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 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
23 int fix_arg_len;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 char *user_data;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 char *dev_data; /* device space data */
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 } sh_path_t;
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
27 #define RESERVED_AIXS sizeof(co_aix[2])
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 #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
30 #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
31 #define SKIP_NUM(x) \
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 while(*(x) && \
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 (isdigit(*(x)) || \
112
abb5511c23f7 Accept exponent of float point
Thinker K.F. Li <thinker@branda.to>
parents: 101
diff changeset
34 *(x) == 'e' || \
abb5511c23f7 Accept exponent of float point
Thinker K.F. Li <thinker@branda.to>
parents: 101
diff changeset
35 *(x) == 'E' || \
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 *(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
37 *(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
38 *(x) == '.')) { \
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 (x)++; \
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 #define OK 0
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 #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
43 #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
44
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
45 #ifdef UNITTEST
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
46 #undef rdman_shape_man
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
47 #define rdman_shape_man(x, y)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
48 #endif
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
49
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
50 /* ============================================================
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
51 * 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
52 */
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
53 #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
54 /*! \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
55 *
269
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
56 * Origin of our coordination is left-top corner, and y-axis are grown
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
57 * to down-side.
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
58 *
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
59 * Space of the arc is transformed to space that correspondent
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
60 * ellipse containing the arc is mapped into an unit circle.
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
61 * - 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
62 * - 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
63 * - ux = x / rx
269
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
64 * - uy = y / ry
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
65 * ux0, uy0, ux, uy are got by transforming (x0, y0) and (x, y) into points
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
66 * 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
67 * - 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
68 * - 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
69 * - 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
70 * - 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
71 * - 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
72 * - 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
73 *
100
1a1dda98730c Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents: 99
diff changeset
74 * - udx * 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
75 *
269
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
76 * - udl2 = udx ** 2 + udy ** 2
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
77 *
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
78 * For drawing small arc in clockwise
100
1a1dda98730c Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents: 99
diff changeset
79 * - 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
80 *
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
81 * - 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
82 * - -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
83 * - -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
84 * - 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
85 * or
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
86 * - 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
87 * - 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
88 * - 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
89 * - 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
90 *
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
91 * - 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
92 * - 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
93 * - 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
94 * - 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
95 */
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
96 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
97 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
98 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
99 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
100 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
101 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
102 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
103 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
104 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
105 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
106 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
107 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
108 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
109 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
110 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
111 int reflect;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
112
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
113 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
114 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
115 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
116 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
117
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
118 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
119 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
120 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
121 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
122
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
123 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
124 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
125 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
126
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
127 if(udy != 0) {
269
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
128 /* center is at left-side of arc */
100
1a1dda98730c Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents: 99
diff changeset
129 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
130 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
131 } else {
269
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
132 /* center is at down-side of arc */
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
133 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
134 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
135 }
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
136
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
137 reflect = 0;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
138 if(large)
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
139 reflect ^= 1;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
140 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
141 reflect ^= 1;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
142 if(reflect) {
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
143 udcx = -udcx;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
144 udcy = -udcy;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
145 }
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
146
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
147 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
148 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
149
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
150 *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
151 *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
152
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
153 *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
154 *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
155
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
156 return OK;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
157 }
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
158
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
159
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
160 #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
161 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
162 old = p; \
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
163 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
164 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
165 return ERR; \
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
166 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
167 } while(0);
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
168
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
169 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
170 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
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178 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
179 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
180 char *cmds;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
181 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
182
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
183 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
184 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
185 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
186 while(*p) {
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
187 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
188 old = p;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
189 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
190 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
191 break;
99
4aa1c9673363 Arc in path pass the test in example svg2code_ex.
Thinker K.F. Li <thinker@branda.to>
parents: 98
diff changeset
192 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
193
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
194 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
195 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
196 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
197 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
198 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
199 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
200
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
201 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
202 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
203
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
204 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
205 x += x0;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
206 y += y0;
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
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
209 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
210 rx, ry,
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
211 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
212 &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
213
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
214 *(args++) = cx;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
215 *(args++) = cy;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
216 *(args++) = xx;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
217 *(args++) = xy;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
218 *(args++) = x;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
219 *(args++) = y;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
220
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
221 *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
222 *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
223 }
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
224
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
225 *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
226 *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
227 *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
228 *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
229
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
230 return OK;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
231 }
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
232
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
233 #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
234 #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
235
100
1a1dda98730c Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents: 99
diff changeset
236 /*! \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
237 */
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
238 void sh_path_arc_path(mbe_t *cr, const co_aix **args_p,
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
239 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
240 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
241 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
242 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
243 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
244 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
245 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
246 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
247 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
248 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
249 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
250 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
251 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
252 int sweep;
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 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
255 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
256 cx = *args++;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
257 cy = *args++;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
258 xx = *args++;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
259 xy = *args++;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
260 x = *args++;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
261 y = *args++;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
262 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
263
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
264 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
265 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
266 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
267 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
268 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
269 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
270
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
271 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
272 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
273
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
274 /*! \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
275 * 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
276 * 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
277 * 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
278 */
100
1a1dda98730c Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents: 99
diff changeset
279 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
280 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
281 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
282 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
283 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
284 xyratio = -xyratio;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
285
99
4aa1c9673363 Arc in path pass the test in example svg2code_ex.
Thinker K.F. Li <thinker@branda.to>
parents: 98
diff changeset
286 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
287 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
288 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
289
100
1a1dda98730c Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents: 99
diff changeset
290 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
291 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
292 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
293 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
294 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
295
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
296 /* 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
297 rotate = acos(dxx / rx);
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
298 mbe_save(cr);
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
299 mbe_translate(cr, cx, cy);
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
300 mbe_rotate(cr, rotate);
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
301 mbe_scale(cr, 1.0, xyratio);
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
302 if(sweep)
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
303 mbe_arc(cr, 0, 0, rx, angle0, angle);
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
304 else
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
305 mbe_arc_negative(cr, 0, 0, rx, angle0, angle);
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
306 mbe_restore(cr);
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
307
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
308 *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
309 *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
310 }
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
311
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
312 /* ============================================================ */
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
313
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
314 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
315 sh_path_t *path = (sh_path_t *)shape;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
316 if(path->user_data)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
317 free(path->user_data);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
318 free(path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
319 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
320
86
7d0580f89468 Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
321 /*! \brief Count number of arguments.
7d0580f89468 Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
322 *
7d0580f89468 Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
323 * \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
324 */
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
325 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
326 int *fix_arg_cntp) {
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
327 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
328 int cmd_cnt, arg_cnt, fix_arg_cnt;
96
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
329 int i;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
330
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
331 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
332 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
333 SKIP_SPACE(p);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
334 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
335 switch(*p++) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
336 case 'c':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
337 case 'C':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
338 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
339 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
340 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
341 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
342 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
343 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
344 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
345 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
346
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
347 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
348 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
349 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
350 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
351 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
352 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
353
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
354 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
355 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
356 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
357 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
358 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
359 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
360
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
361 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
362 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
363 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
364 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
365 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
366 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
367 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
368 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
369 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
370 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
371 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
372 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
373
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
374 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
375 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
376 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
377 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
378 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
379 arg_cnt++;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
380
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
381 cmd_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
382 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
383 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
384 case 's':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
385 case 'S':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
386 case 'q':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
387 case 'Q':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
388 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
389 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
390 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
391 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
392 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
393 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
394 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
395 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
396
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
397 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
398 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
399 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
400 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
401 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
402 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
403
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
404 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
405 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
406 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
407 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
408 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
409 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
410
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
411 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
412 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
413 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
414 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
415 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
416 arg_cnt++;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
417
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
418 cmd_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
419 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
420 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
421 case 'm':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
422 case 'M':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
423 case 'l':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
424 case 'L':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
425 case 't':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
426 case 'T':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
427 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
428 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
429 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
430 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
431 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
432 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
433 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
434 arg_cnt++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
435
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 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
441 arg_cnt++;
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;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
446 case 'h':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
447 case 'H':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
448 case 'v':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
449 case 'V':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
450 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
451 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
452 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
453 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
454 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
455 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
456 arg_cnt += 2;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
457
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
458 cmd_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
459 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
460 break;
96
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
461 case 'A':
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
462 case 'a':
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
463 while(*p) {
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
464 SKIP_SPACE(p);
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
465 old = p;
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
466 SKIP_NUM(p);
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
467 if(p == old)
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
468 break;
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
469
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
470 for(i = 0; i < 6; i++) {
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
471 SKIP_SPACE(p);
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
472 old = p;
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
473 SKIP_NUM(p);
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
474 if(p == old)
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
475 return ERR;
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
476 }
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
477
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
478 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
479 fix_arg_cnt++;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
480
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
481 cmd_cnt++;
96
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
482 }
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
483 break;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
484 case 'z':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
485 case 'Z':
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
486 cmd_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
487 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
488 default:
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
489 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
490 }
96
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
491 /*! \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
492 SKIP_SPACE(p);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
493 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
494
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
495 *cmd_cntp = cmd_cnt;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
496 *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
497 *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
498 return OK;
96
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
499 }
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
500
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
501 #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
502 #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
503
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
504 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
505 char *p, *old;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
506 char *cmds;
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
507 char cmd;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
508 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
509 int *fix_args;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
510 co_aix x, y;
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
511 int r;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
512
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
513 cmds = path->user_data;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
514 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
515 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
516 path->arg_len * sizeof(co_aix));
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
517 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
518 SKIP_SPACE(p);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
519 while(*p) {
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
520 /* 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
521 x = *(args - 2);
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
522 y = *(args - 1);
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
523
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
524 switch((cmd = *p++)) {
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
525 case 'c':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
526 case 'C':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
527 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
528 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
529 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
530 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
531 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
532 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
533 break;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
534 *args = TO_ABSX;
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
535 args++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
536
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
537 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
538 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
539 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
540 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
541 return ERR;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
542 *args = TO_ABSY;
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
543 args++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
544
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
545 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++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
560 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
561 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
562 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
563 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
564 return ERR;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
565 *args = TO_ABSX;
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
566 args++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
567
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
568 SKIP_SPACE(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_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
571 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
572 return ERR;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
573 *args = TO_ABSY;
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
574 args++;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
575
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
576 *cmds++ = toupper(cmd);
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 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
579 case 's':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
580 case 'S':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
581 case 'q':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
582 case 'Q':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
583 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
584 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
585 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
586 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
587 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
588 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
589 break;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
590 *args = TO_ABSX;
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
591 args++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
592
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
593 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
594 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
595 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
596 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
597 return ERR;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
598 *args = TO_ABSY;
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
599 args++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
600
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
601 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
602 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
603 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
604 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
605 return ERR;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
606 *args = TO_ABSX;
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
607 args++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
608
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
609 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
610 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
611 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
612 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
613 return ERR;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
614 *args = TO_ABSY;
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
615 args++;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
616
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
617 *cmds++ = toupper(cmd);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
618 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
619 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
620 case 'm':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
621 case 'M':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
622 case 'l':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
623 case 'L':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
624 case 't':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
625 case 'T':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
626 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
627 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
628 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
629 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
630 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
631 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
632 break;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
633 *args = TO_ABSX;
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
634 args++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
635
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
636 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
637 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
638 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
639 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
640 return ERR;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
641 *args = TO_ABSY;
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
642 args++;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
643
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
644 *cmds++ = toupper(cmd);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
645 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
646 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
647 case 'h':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
648 case 'H':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
649 case 'v':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
650 case 'V':
58
Thinker K.F. Li <thinker@branda.to>
parents: 34
diff changeset
651 /*! \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
652 return ERR;
96
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
653
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
654 case 'A':
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
655 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
656 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
657 (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
658 &fix_args);
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
659 if(r != OK)
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
660 return ERR;
96
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
661 break;
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
662
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
663 case 'z':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
664 case 'Z':
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
665 *cmds++ = toupper(cmd);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
666 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
667 default:
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
668 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
669 }
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
670 SKIP_SPACE(p);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
671 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
672
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
673 return OK;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
674 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
675
9
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
676 /*! \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
677 */
159
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 149
diff changeset
678 shape_t *rdman_shape_path_new(redraw_man_t *rdman, char *data) {
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
679 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
680 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
681 int msz;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
682 int r;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
683
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
684 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
685 if(r == ERR)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
686 return NULL;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
687
8
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
688 /* Align at 4's boundary and keep 2 unused co_aix space
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
689 * to make logic of transformation from relative to absolute
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
690 * simple.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
691 */
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
692 cmd_cnt += RESERVED_AIXS;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
693 cmd_cnt = (cmd_cnt + 3) & ~0x3;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
694
149
Thinker K.F. Li <thinker@branda.to>
parents: 146
diff changeset
695 /*! \todo Use elmpool to manage sh_path_t objects. */
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
696 path = (sh_path_t *)malloc(sizeof(sh_path_t));
146
e96a584487af Use elmpool to manage paint_color_t objects.
Thinker K.F. Li <thinker@branda.to>
parents: 145
diff changeset
697 /*! \todo Remove this memset()? */
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
698 memset(&path->shape, 0, sizeof(shape_t));
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 202
diff changeset
699 mb_obj_init(path, MBO_PATH);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
700 path->cmd_len = cmd_cnt;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
701 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
702 path->fix_arg_len = fix_arg_cnt;
145
609ed47a58f2 Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents: 112
diff changeset
703
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
704 msz = cmd_cnt + sizeof(co_aix) * arg_cnt + sizeof(int) * fix_arg_cnt;
145
609ed47a58f2 Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents: 112
diff changeset
705 path->user_data = (char *)malloc(msz * 2);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
706 if(path->user_data == NULL) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
707 free(path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
708 return NULL;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
709 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
710
145
609ed47a58f2 Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents: 112
diff changeset
711 path->dev_data = path->user_data + msz;
609ed47a58f2 Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents: 112
diff changeset
712
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
713 r = sh_path_cmd_arg_fill(data, path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
714 if(r == ERR) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
715 free(path->user_data);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
716 free(path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
717 return NULL;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
718 }
100
1a1dda98730c Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents: 99
diff changeset
719 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
720
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
721 path->shape.free = sh_path_free;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
722
159
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 149
diff changeset
723 rdman_shape_man(rdman, (shape_t *)path);
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 149
diff changeset
724
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
725 return (shape_t *)path;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
726 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
727
197
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
728 shape_t *rdman_shape_path_new_from_binary(redraw_man_t *rdman, char *commands, co_aix *arg,int arg_cnt,int *fix_arg,int fix_arg_cnt) {
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
729 sh_path_t *path;
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
730 int msz;
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
731 int cmd_cnt = strlen(commands);
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
732
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
733 /*! \todo Use elmpool to manage sh_path_t objects. */
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
734 path = (sh_path_t *)malloc(sizeof(sh_path_t));
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
735 /*! \todo Remove this memset()? */
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
736 memset(&path->shape, 0, sizeof(shape_t));
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 202
diff changeset
737 mb_obj_init(path, MBO_PATH);
197
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
738 path->cmd_len = strlen(commands);
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
739 path->arg_len = arg_cnt;
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
740 path->fix_arg_len = fix_arg_cnt;
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
741 msz = cmd_cnt + sizeof(co_aix) * arg_cnt + sizeof(int) * fix_arg_cnt;
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
742 path->user_data = (char *)malloc(msz * 2);
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
743 if(path->user_data == NULL) {
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
744 free(path);
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
745 return NULL;
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
746 }
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
747
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
748 path->dev_data = path->user_data + msz;
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
749 memcpy(path->user_data,commands,cmd_cnt);
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
750 memcpy(path->user_data+cmd_cnt,arg, sizeof(co_aix)*arg_cnt);
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
751 memcpy(path->user_data+cmd_cnt+arg_cnt*sizeof(co_aix),fix_arg, sizeof(int)*fix_arg_cnt);
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
752 memcpy(path->dev_data, path->user_data, msz);
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
753
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
754 path->shape.free = sh_path_free;
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
755
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
756 rdman_shape_man(rdman, (shape_t *)path);
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
757
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
758 return (shape_t *)path;
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
759 }
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
760
bcad1ccdf45c Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents: 186
diff changeset
761
9
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
762 /*! \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
763 *
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
764 */
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
765 void sh_path_transform(shape_t *shape) {
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
766 sh_path_t *path;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
767 co_aix *user_args, *dev_args;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
768 co_aix (*poses)[2];
26
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
769 area_t *area;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
770 int arg_len;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
771 int i;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
772
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
773 ASSERT(shape->type == SHT_PATH);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
774 ASSERT((shape->arg_len & 0x1) == 0);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
775
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
776 path = (sh_path_t *)shape;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
777 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
778 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
779 arg_len = path->arg_len;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
780 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
781 dev_args[0] = *user_args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
782 dev_args[1] = *user_args++;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
783 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
784 dev_args += 2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
785 }
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
786
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
787 if(path->shape.geo) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
788 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
789 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
790 area = shape->geo->cur_area;
270
cd6af7da32c9 Fix the problem that clean_canvas() can not clean canvas cleanly.
Thinker K.F. Li <thinker@branda.to>
parents: 269
diff changeset
791 area->x -= shape->stroke_width / 2 + 0.5;
cd6af7da32c9 Fix the problem that clean_canvas() can not clean canvas cleanly.
Thinker K.F. Li <thinker@branda.to>
parents: 269
diff changeset
792 area->y -= shape->stroke_width / 2 + 0.5;
cd6af7da32c9 Fix the problem that clean_canvas() can not clean canvas cleanly.
Thinker K.F. Li <thinker@branda.to>
parents: 269
diff changeset
793 area->w += shape->stroke_width + 1;
cd6af7da32c9 Fix the problem that clean_canvas() can not clean canvas cleanly.
Thinker K.F. Li <thinker@branda.to>
parents: 269
diff changeset
794 area->h += shape->stroke_width + 1;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
795 }
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
796 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
797
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
798 static void sh_path_path(shape_t *shape, mbe_t *cr) {
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
799 sh_path_t *path;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
800 int cmd_len;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
801 char *cmds, cmd;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
802 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
803 const int *fix_args;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
804 co_aix x, y, x1, y1, x2, y2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
805 int i;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
806
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
807 ASSERT(shape->type == SHT_PATH);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
808
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
809 path = (sh_path_t *)shape;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
810 cmd_len = path->cmd_len;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
811 cmds = path->dev_data;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
812 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
813 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
814 x = y = x1 = y1 = x2 = y2 = 0;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
815 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
816 /* 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
817 * to absoluted form.
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
818 */
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
819 cmd = *cmds++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
820 switch(cmd) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
821 case 'M':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
822 x = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
823 y = *args++;
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
824 mbe_move_to(cr, x, y);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
825 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
826 case 'L':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
827 x = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
828 y = *args++;
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
829 mbe_line_to(cr, x, y);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
830 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
831 case 'C':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
832 x1 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
833 y1 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
834 x2 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
835 y2 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
836 x = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
837 y = *args++;
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
838 mbe_curve_to(cr, x1, y1, x2, y2, x, y);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
839 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
840 case 'S':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
841 x1 = x + x - x2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
842 y1 = y + y - y2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
843 x2 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
844 y2 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
845 x = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
846 y = *args++;
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
847 mbe_curve_to(cr, x1, y1, x2, y2, x, y);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
848 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
849 case 'Q':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
850 x1 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
851 y1 = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
852 x2 = x1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
853 y2 = y1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
854 x = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
855 y = *args++;
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
856 mbe_curve_to(cr, x1, y1, x2, y2, x, y);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
857 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
858 case 'T':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
859 x1 = x + x - x2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
860 y1 = y + y - y2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
861 x2 = x1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
862 y2 = y1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
863 x = *args++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
864 y = *args++;
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
865 mbe_curve_to(cr, x1, y1, x2, y2, x, y);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
866 break;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
867 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
868 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
869 break;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
870 case 'Z':
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
871 mbe_close_path(cr);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
872 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
873 case '\x0':
8
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
874 i = cmd_len; /* padding! Skip remain ones. */
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
875 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
876 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
877 }
22
8fcf2d878ecd shapes with stroke
Thinker K.F. Li <thinker@branda.to>
parents: 20
diff changeset
878 }
6
772511b8b9be Cairo specify RGB values in range 0.0 ~ 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
879
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
880 void sh_path_draw(shape_t *shape, mbe_t *cr) {
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
881 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
882 }
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
883
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
884 #ifdef UNITTEST
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
885
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
886 #include <CUnit/Basic.h>
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
887
159
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 149
diff changeset
888 void test_rdman_shape_path_new(void) {
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
889 sh_path_t *path;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
890 co_aix *args;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
891
159
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 149
diff changeset
892 path = (sh_path_t *)rdman_shape_path_new(NULL, "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
893 CU_ASSERT(path != NULL);
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
894 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
895 CU_ASSERT(path->arg_len == 12);
145
609ed47a58f2 Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents: 112
diff changeset
896 CU_ASSERT(strncmp(path->user_data, "MLCLZ", 5) == 0);
609ed47a58f2 Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents: 112
diff changeset
897 CU_ASSERT(strncmp(path->dev_data, "MLCLZ", 5) == 0);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
898
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
899 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
900 CU_ASSERT(args[0] == 33);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
901 CU_ASSERT(args[1] == 25);
9
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
902 CU_ASSERT(args[2] == 66);
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
903 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
904 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
905 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
906 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
907 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
908 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
909 CU_ASSERT(args[9] == 179);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
910 CU_ASSERT(args[10] == 33);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
911 CU_ASSERT(args[11] == 77);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
912 sh_path_free((shape_t *)path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
913 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
914
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
915 void test_path_transform(void) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
916 sh_path_t *path;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
917 co_aix *args;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
918 coord_t coord;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
919 geo_t geo;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
920
159
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 149
diff changeset
921 path = (sh_path_t *)rdman_shape_path_new(NULL, "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
922 CU_ASSERT(path != NULL);
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
923 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
924 CU_ASSERT(path->arg_len == 12);
145
609ed47a58f2 Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents: 112
diff changeset
925 CU_ASSERT(strncmp(path->user_data, "MLCLZ", 5) == 0);
609ed47a58f2 Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents: 112
diff changeset
926 CU_ASSERT(strncmp(path->dev_data, "MLCLZ", 5) == 0);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
927
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
928 geo_init(&geo);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
929 path->shape.geo = &geo;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
930 geo.shape = (shape_t *)path;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
931
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
932 coord.aggr_matrix[0] = 1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
933 coord.aggr_matrix[1] = 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
934 coord.aggr_matrix[2] = 1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
935 coord.aggr_matrix[3] = 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
936 coord.aggr_matrix[4] = 2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
937 coord.aggr_matrix[5] = 0;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
938 path->shape.coord = &coord;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
939 sh_path_transform((shape_t *)path);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
940
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
941 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
942 CU_ASSERT(args[0] == 34);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
943 CU_ASSERT(args[1] == 50);
9
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
944 CU_ASSERT(args[2] == 67);
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
945 CU_ASSERT(args[3] == 160);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
946 CU_ASSERT(args[4] == 34);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
947 CU_ASSERT(args[5] == 174);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
948 CU_ASSERT(args[6] == 45);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
949 CU_ASSERT(args[7] == 44);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
950 CU_ASSERT(args[8] == 56);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
951 CU_ASSERT(args[9] == 198);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
952 CU_ASSERT(args[10] == 34);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
953 CU_ASSERT(args[11] == 154);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
954
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
955 sh_path_free((shape_t *)path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
956 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
957
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
958 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
959 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
960
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
961 path = (sh_path_t *)
159
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 149
diff changeset
962 rdman_shape_path_new(NULL,
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 149
diff changeset
963 " M 33 25l33 55C 33 87 44 22 55 99L33 77z ");
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
964 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
965 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
966 }
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
967
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
968 CU_pSuite get_shape_path_suite(void) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
969 CU_pSuite suite;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
970
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
971 suite = CU_add_suite("Suite_shape_path", NULL, NULL);
159
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 149
diff changeset
972 CU_ADD_TEST(suite, test_rdman_shape_path_new);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
973 CU_ADD_TEST(suite, test_path_transform);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
974
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
975 return suite;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
976 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
977
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
978 #endif /* UNITTEST */