annotate src/shape_path.c @ 847:dfe28355bded

Fix the location of the text elements.
author wycc
date Sun, 19 Sep 2010 19:28:33 +0800
parents 586e50f82c1f
children 48df0f97f09e
rev   line source
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
2 // vim: sw=4:ts=8:sts=4
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include <stdio.h>
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include <stdlib.h>
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #include <ctype.h>
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 #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
7 #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
8 #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
9 #include "mb_redraw_man.h"
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10
8
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
11 /*! \brief Implement respective objects for SVG path tag.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
12 *
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
13 * In user_data or dev_data, 0x00 bytes are padding after commands.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
14 * No commands other than 0x00 can resident after 0x00 itself.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
15 * 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
16 *
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
17 * 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
18 * 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
19 * it is assigned.
8
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
20 */
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 typedef struct _sh_path {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 shape_t shape;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 int cmd_len;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
24 int pnt_len;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
25 int float_arg_len;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 char *user_data;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 char *dev_data; /* device space data */
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 } sh_path_t;
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
29 #define RESERVED_AIXS sizeof(co_aix[2])
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 #define 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
32 #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
33 #define SKIP_NUM(x) \
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 while(*(x) && \
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 (isdigit(*(x)) || \
112
abb5511c23f7 Accept exponent of float point
Thinker K.F. Li <thinker@branda.to>
parents: 101
diff changeset
36 *(x) == 'e' || \
abb5511c23f7 Accept exponent of float point
Thinker K.F. Li <thinker@branda.to>
parents: 101
diff changeset
37 *(x) == 'E' || \
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 *(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
39 *(x) == '+' || \
709
920c9e6e4214 Make code clear
Thinker K.F. Li <thinker@branda.to>
parents: 707
diff changeset
40 *(x) == '.')) { \
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 (x)++; \
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 #define OK 0
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 #define ERR -1
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
45 #define PI 3.1415926535897931
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
46
235
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
47 #ifdef UNITTEST
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
48 #undef rdman_shape_man
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
49 #define rdman_shape_man(x, y)
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
50 #endif
65cabbdd5284 termporary revision
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
51
98
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 * 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
54 */
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
55 #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
56 /*! \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
57 *
269
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
58 * 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
59 * to down-side.
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
60 *
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
61 * 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
62 * 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
63 * - 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
64 * - 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
65 * - 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
66 * - uy = y / ry
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
67 * 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
68 * 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
69 * - 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
70 * - 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
71 * - 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
72 * - 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
73 * - 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
74 * - 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
75 *
100
1a1dda98730c Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents: 99
diff changeset
76 * - 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
77 *
269
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
78 * - 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
79 *
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
80 * 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
81 * - 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
82 *
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
83 * - 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
84 * - -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
85 * - -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
86 * - 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
87 * or
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
88 * - 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
89 * - 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
90 * - 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
91 * - 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
92 *
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
93 * - 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
94 * - 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
95 * - 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
96 * - 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
97 */
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
98 static int _calc_center(co_aix x0, co_aix y0,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
99 co_aix x, co_aix y,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
100 co_aix rx, co_aix ry,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
101 co_aix x_rotate,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
102 int large, int sweep,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
103 co_aix *cx, co_aix *cy) {
98
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 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
105 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
106 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
107 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
108 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
109 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
110 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
111 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
112 int reflect;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
113
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
114 /* Compute center of the ellipse */
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
115 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
116 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
117 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
118 nry0 = x0 * -_sin + y0 * _cos;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
119
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
120 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
121 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
122 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
123 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
124
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
125 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
126 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
127 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
128
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
129 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
130 /* 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
131 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
132 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
133 } else {
269
c96f38ad4bb6 Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents: 235
diff changeset
134 /* 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
135 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
136 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
137 }
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
138
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
139 reflect = 0;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
140 if(large)
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(sweep != 1)
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
143 reflect ^= 1;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
144 if(reflect) {
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
145 udcx = -udcx;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
146 udcy = -udcy;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
147 }
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
148
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
149 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
150 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
151
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
152 *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
153 *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
154
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
155 return OK;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
156 }
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
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
159 static co_aix _angle_rotated_ellipse(co_aix x, co_aix y,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
160 co_aix rx, co_aix ry,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
161 co_aix x_rotate) {
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
162 co_aix nrx, nry;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
163 co_aix _sin, _cos;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
164 co_aix xy_tan;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
165 co_aix angle;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
166
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
167 _sin = sinf(x_rotate);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
168 _cos = cosf(x_rotate);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
169
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
170 nrx = (x * _cos + y * _sin) / rx;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
171 nry = (-x * _sin + y * _cos) / ry;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
172 xy_tan = nry / nrx;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
173
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
174 angle = atan(xy_tan);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
175
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
176 if(nrx < 0)
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
177 angle = PI + angle;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
178
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
179 return angle;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
180 }
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
181
459
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
182 static void _rotate(co_aix *x, co_aix *y, co_aix _sin, co_aix _cos) {
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
183 co_aix nx, ny;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
184
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
185 nx = *x * _cos - *y * _sin;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
186 ny = *x * _sin + *y * _cos;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
187
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
188 *x = nx;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
189 *y = ny;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
190 }
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
191
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
192 #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
193 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
194 old = p; \
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
195 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
196 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
197 return ERR; \
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
198 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
199 } while(0);
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
200
459
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
201 static int _sh_path_arc_cmd_arg_fill(char cmd, char **cmds_p,
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
202 const char **data_p,
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
203 co_aix **pnts_p,
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
204 co_aix **float_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
205 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
206 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
207 int large, sweep;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
208 co_aix x, y, x0, y0, cx, cy;
459
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
209 co_aix corners[4][2];
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
210 co_aix angle_start, angle_stop;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
211 co_aix *pnts = *pnts_p;
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
212 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
213 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
214 char *cmds;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
215 co_aix *float_args;
459
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
216 co_aix _sin, _cos;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
217 int i;
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
218
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
219 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
220 cmds = *cmds_p;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
221 float_args = *float_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
222 while(*p) {
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
223 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
224 old = p;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
225 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
226 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
227 break;
99
4aa1c9673363 Arc in path pass the test in example svg2code_ex.
Thinker K.F. Li <thinker@branda.to>
parents: 98
diff changeset
228 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
229
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
230 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
231 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
232 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
233 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
234 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
235 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
236
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
237 x0 = *(pnts - 2);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
238 y0 = *(pnts - 1);
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
239
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
240 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
241 x += x0;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
242 y += y0;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
243 }
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
244
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
245 _calc_center(x0, y0, x, y, rx, ry, x_rotate, large,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
246 sweep, &cx, &cy);
459
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
247
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
248 /* Compute positions for four corners.
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
249 * These four corners form a bounding box for the arc.
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
250 */
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
251 _sin = sinf(x_rotate);
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
252 _cos = cosf(x_rotate);
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
253 corners[0][0] = -rx;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
254 corners[0][1] = -ry;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
255 corners[1][0] = rx;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
256 corners[1][1] = -ry;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
257 corners[2][0] = rx;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
258 corners[2][1] = ry;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
259 corners[3][0] = -rx;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
260 corners[3][1] = ry;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
261 for(i = 0; i < 4; i++) {
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
262 _rotate(&corners[i][0], &corners[i][1], _sin, _cos);
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
263 *pnts++ = corners[i][0] + cx;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
264 *pnts++ = corners[i][1] + cy;
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
265 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
266
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
267 *(pnts++) = x;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
268 *(pnts++) = y;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
269
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
270 angle_start = _angle_rotated_ellipse(x0 - cx, y0 - cy,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
271 rx, ry, x_rotate);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
272 angle_stop = _angle_rotated_ellipse(x - cx, y - cy,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
273 rx, ry, x_rotate);
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
274
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
275 if(sweep && angle_start > angle_stop)
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
276 angle_stop += 2 * PI;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
277 else if((!sweep) && angle_start < angle_stop)
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
278 angle_start += 2 * PI;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
279
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
280 *float_args++ = cx;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
281 *float_args++ = cy;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
282 *float_args++ = rx;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
283 *float_args++ = ry;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
284 *float_args++ = angle_start;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
285 *float_args++ = angle_stop;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
286 *float_args++ = x_rotate;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
287
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
288 *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
289 }
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
290
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
291 *data_p = p;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
292 *pnts_p = pnts;
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
293 *cmds_p = cmds;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
294 *float_args_p = float_args;
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 return OK;
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
297 }
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
298
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
299 #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
300 #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
301
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
302 static co_aix distance_pow2(co_aix x, co_aix y) {
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
303 return x * x + y * y;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
304 }
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
305
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
306 static co_aix angle_diff(co_aix sx, co_aix sy, co_aix dx, co_aix dy) {
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
307 co_aix inner, cross;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
308 co_aix angle;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
309 co_aix rd2, rd;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
310
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
311 rd2 = distance_pow2(dx, dy);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
312 rd = sqrtf(rd2);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
313
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
314 inner = INNER(sx, sy, dx, dy);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
315 cross = CROSS(sx, sy, dx, dy);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
316 angle = acos(inner / rd);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
317 if(cross < 0)
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
318 angle = 2 * PI - angle;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
319
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
320 return angle;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
321 }
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
322
100
1a1dda98730c Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents: 99
diff changeset
323 /*! \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
324 */
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
325 void _sh_path_arc_path(mbe_t *cr, sh_path_t *path, const co_aix **pnts_p,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
326 const co_aix **float_args_p) {
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
327 co_aix cx, cy, x0, y0, x, y;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
328 co_aix rx, ry;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
329 co_aix xyratio;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
330 co_aix angle_start, angle_stop;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
331 co_aix x_rotate;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
332 const co_aix *pnts;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
333 const co_aix *float_args;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
334 co_aix matrix[6];
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
335 co_aix dev_matrix[6];
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
336 co_aix *aggr;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
337 co_aix _sin, _cos;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
338
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
339 pnts = *pnts_p;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
340 float_args = *float_args_p;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
341 x0 = *(pnts - 2);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
342 y0 = *(pnts - 1);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
343 pnts += 8;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
344 x = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
345 y = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
346
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
347 cx = *float_args++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
348 cy = *float_args++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
349 rx = *float_args++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
350 ry = *float_args++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
351 angle_start = *float_args++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
352 angle_stop = *float_args++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
353 x_rotate = *float_args++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
354
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
355 _sin = sinf(x_rotate);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
356 _cos = cosf(x_rotate);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
357
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
358 xyratio = ry / rx;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
359 aggr = sh_get_aggr_matrix((shape_t *)path);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
360 matrix[0] = _cos;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
361 matrix[1] = -_sin * xyratio;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
362 matrix[2] = cx;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
363 matrix[3] = _sin;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
364 matrix[4] = _cos * xyratio;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
365 matrix[5] = cy;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
366
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
367 matrix_mul(aggr, matrix, dev_matrix);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
368 mbe_save(cr);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
369 mbe_transform(cr, dev_matrix);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
370 mbe_arc(cr, 0, 0, rx, angle_start, angle_stop);
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
371 mbe_restore(cr);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
372
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
373 *pnts_p = pnts;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
374 *float_args_p = float_args;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
375 }
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
376
98
688f76b8e71c Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents: 97
diff changeset
377 /* ============================================================ */
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
378
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
379 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
380 sh_path_t *path = (sh_path_t *)shape;
770
abd9bbf24545 mb_obj_destroy for sh_path_t
Thinker K.F. Li <thinker@codemud.net>
parents: 711
diff changeset
381
abd9bbf24545 mb_obj_destroy for sh_path_t
Thinker K.F. Li <thinker@codemud.net>
parents: 711
diff changeset
382 mb_obj_destroy(path);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
383 if(path->user_data)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
384 free(path->user_data);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
385 free(path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
386 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
387
86
7d0580f89468 Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
388 /*! \brief Count number of arguments.
7d0580f89468 Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
389 *
7d0580f89468 Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
390 * \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
391 */
492
e95598916dfb Make path data constant.
Thinker K.F. Li <thinker@branda.to>
parents: 460
diff changeset
392 static int sh_path_cmd_arg_cnt(const char *data, int *cmd_cntp, int *pnt_cntp,
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
393 int *float_arg_cntp) {
492
e95598916dfb Make path data constant.
Thinker K.F. Li <thinker@branda.to>
parents: 460
diff changeset
394 const char *p, *old;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
395 int cmd_cnt, pnt_cnt, float_arg_cnt;
96
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
396 int i;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
397
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
398 cmd_cnt = pnt_cnt = float_arg_cnt = 0;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
399 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
400 SKIP_SPACE(p);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
401 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
402 switch(*p++) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
403 case 'c':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
404 case 'C':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
405 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
406 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
407 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
408 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
409 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
410 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
411 break;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
412 pnt_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
413
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
414 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
415 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
416 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
417 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
418 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
419 pnt_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
420
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
421 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
422 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
423 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
424 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
425 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
426 pnt_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
427
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
428 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
429 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
430 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
431 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
432 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
433 pnt_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
434 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
435 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
436 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
437 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
438 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
439 pnt_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
440
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
441 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
442 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
443 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
444 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
445 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
446 pnt_cnt++;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
447
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
448 cmd_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
449 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
450 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
451 case 's':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
452 case 'S':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
453 case 'q':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
454 case 'Q':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
455 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
456 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
457 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
458 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
459 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
460 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
461 break;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
462 pnt_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
463
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
464 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
465 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
466 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
467 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
468 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
469 pnt_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
470
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
471 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
472 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
473 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
474 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
475 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
476 pnt_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
477
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
478 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
479 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
480 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
481 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
482 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
483 pnt_cnt++;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
484
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
485 cmd_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
486 }
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 case 'm':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
489 case 'M':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
490 case 'l':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
491 case 'L':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
492 case 't':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
493 case 'T':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
494 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
495 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
496 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
497 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
498 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
499 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
500 break;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
501 pnt_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
502
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
503 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
504 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
505 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
506 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
507 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
508 pnt_cnt++;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
509
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
510 cmd_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
511 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
512 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
513 case 'h':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
514 case 'H':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
515 case 'v':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
516 case 'V':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
517 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
518 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
519 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
520 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
521 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
522 break;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
523 pnt_cnt += 2;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
524
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
525 cmd_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
526 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
527 break;
96
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
528 case 'A':
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
529 case 'a':
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
530 while(*p) {
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
531 SKIP_SPACE(p);
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
532 old = p;
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
533 SKIP_NUM(p);
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
534 if(p == old)
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
535 break;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
536
96
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
537 for(i = 0; i < 6; i++) {
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
538 SKIP_SPACE(p);
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
539 old = p;
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
540 SKIP_NUM(p);
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
541 if(p == old)
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
542 return ERR;
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
543 }
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
544
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
545 pnt_cnt += 10;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
546 float_arg_cnt += 7;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
547
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
548 cmd_cnt++;
96
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
549 }
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
550 break;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
551 case 'z':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
552 case 'Z':
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
553 cmd_cnt++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
554 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
555 default:
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
556 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
557 }
96
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
558 /*! \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
559 SKIP_SPACE(p);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
560 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
561
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
562 *cmd_cntp = cmd_cnt;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
563 *pnt_cntp = pnt_cnt;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
564 *float_arg_cntp = float_arg_cnt;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
565 return OK;
96
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
566 }
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
567
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
568 #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
569 #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
570
492
e95598916dfb Make path data constant.
Thinker K.F. Li <thinker@branda.to>
parents: 460
diff changeset
571 static int sh_path_cmd_arg_fill(const char *data, sh_path_t *path) {
e95598916dfb Make path data constant.
Thinker K.F. Li <thinker@branda.to>
parents: 460
diff changeset
572 const char *p, *old;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
573 char *cmds;
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
574 char cmd;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
575 co_aix *pnts;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
576 co_aix *float_args;
711
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
577 co_aix sx = 0, sy = 0;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
578 co_aix x, y;
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
579 int r;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
580
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
581 cmds = path->user_data;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
582 pnts = (co_aix *)(cmds + path->cmd_len);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
583 float_args = (co_aix *)(cmds + path->cmd_len +
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
584 path->pnt_len * sizeof(co_aix));
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
585 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
586 SKIP_SPACE(p);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
587 while(*p) {
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
588 /* Transform all relative to absolute, */
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
589 x = *(pnts - 2);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
590 y = *(pnts - 1);
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
591
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
592 switch((cmd = *p++)) {
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
593 case 'c':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
594 case 'C':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
595 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
596 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
597 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
598 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
599 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
600 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
601 break;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
602 *pnts = TO_ABSX;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
603 pnts++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
604
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
605 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
606 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
607 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
608 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
609 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
610 *pnts = TO_ABSY;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
611 pnts++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
612
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
613 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
614 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
615 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
616 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
617 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
618 *pnts = TO_ABSX;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
619 pnts++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
620
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
621 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
622 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
623 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
624 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
625 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
626 *pnts = TO_ABSY;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
627 pnts++;
5
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 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
633 *pnts = TO_ABSX;
707
594827d0f3e5 Fix issue of relative path data.
Thinker K.F. Li <thinker@branda.to>
parents: 492
diff changeset
634 x = *pnts;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
635 pnts++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
636
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
637 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
638 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
639 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
640 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
641 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
642 *pnts = TO_ABSY;
707
594827d0f3e5 Fix issue of relative path data.
Thinker K.F. Li <thinker@branda.to>
parents: 492
diff changeset
643 y = *pnts;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
644 pnts++;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
645
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
646 *cmds++ = toupper(cmd);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
647 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
648 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
649 case 's':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
650 case 'S':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
651 case 'q':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
652 case 'Q':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
653 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
654 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
655 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
656 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
657 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
658 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
659 break;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
660 *pnts = TO_ABSX;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
661 pnts++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
662
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
663 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
664 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
665 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
666 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
667 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
668 *pnts = TO_ABSY;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
669 pnts++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
670
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
671 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
672 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
673 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
674 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
675 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
676 *pnts = TO_ABSX;
707
594827d0f3e5 Fix issue of relative path data.
Thinker K.F. Li <thinker@branda.to>
parents: 492
diff changeset
677 x = *pnts;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
678 pnts++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
679
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
680 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
681 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
682 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
683 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
684 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
685 *pnts = TO_ABSY;
707
594827d0f3e5 Fix issue of relative path data.
Thinker K.F. Li <thinker@branda.to>
parents: 492
diff changeset
686 y = *pnts;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
687 pnts++;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
688
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
689 *cmds++ = toupper(cmd);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
690 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
691 break;
711
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
692
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
693 case 'm':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
694 case 'M':
711
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
695 while(*p) {
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
696 old = p;
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
697 SKIP_SPACE(p);
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
698 old = p;
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
699 SKIP_NUM(p);
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
700 if(p == old)
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
701 break;
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
702 *pnts = TO_ABSX;
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
703 x = *pnts;
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
704 pnts++;
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
705
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
706 SKIP_SPACE(p);
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
707 old = p;
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
708 SKIP_NUM(p);
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
709 if(p == old)
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
710 return ERR;
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
711 *pnts = TO_ABSY;
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
712 y = *pnts;
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
713 pnts++;
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
714
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
715 *cmds++ = toupper(cmd);
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
716
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
717 /* save initial point of a subpath */
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
718 sx = x;
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
719 sy = y;
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
720 }
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
721 break;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
722
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
723 case 'l':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
724 case 'L':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
725 case 't':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
726 case 'T':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
727 while(*p) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
728 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
729 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
730 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
731 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
732 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
733 break;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
734 *pnts = TO_ABSX;
707
594827d0f3e5 Fix issue of relative path data.
Thinker K.F. Li <thinker@branda.to>
parents: 492
diff changeset
735 x = *pnts;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
736 pnts++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
737
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
738 SKIP_SPACE(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
739 old = p;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
740 SKIP_NUM(p);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
741 if(p == old)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
742 return ERR;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
743 *pnts = TO_ABSY;
707
594827d0f3e5 Fix issue of relative path data.
Thinker K.F. Li <thinker@branda.to>
parents: 492
diff changeset
744 y = *pnts;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
745 pnts++;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
746
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
747 *cmds++ = toupper(cmd);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
748 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
749 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
750 case 'h':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
751 case 'H':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
752 case 'v':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
753 case 'V':
58
Thinker K.F. Li <thinker@branda.to>
parents: 34
diff changeset
754 /*! \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
755 return ERR;
96
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
756
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
757 case 'A':
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
758 case 'a':
459
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
759 r = _sh_path_arc_cmd_arg_fill(cmd, &cmds,
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
760 (const char **)&p, &pnts,
8b155b77fa14 Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents: 458
diff changeset
761 &float_args);
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
762 if(r != OK)
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
763 return ERR;
96
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
764 break;
Thinker K.F. Li <thinker@branda.to>
parents: 86
diff changeset
765
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
766 case 'z':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
767 case 'Z':
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
768 *cmds++ = toupper(cmd);
711
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
769 /* Go back to initial point of a subpath */
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
770 x = sx;
da794f4fe96c save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents: 709
diff changeset
771 y = sy;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
772 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
773 default:
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
774 return ERR;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
775 }
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
776 SKIP_SPACE(p);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
777 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
778
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
779 return OK;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
780 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
781
9
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
782 /*! \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
783 */
492
e95598916dfb Make path data constant.
Thinker K.F. Li <thinker@branda.to>
parents: 460
diff changeset
784 shape_t *rdman_shape_path_new(redraw_man_t *rdman, const char *data) {
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
785 sh_path_t *path;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
786 int cmd_cnt, pnt_cnt, float_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
787 int msz;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
788 int r;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
789
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
790 r = sh_path_cmd_arg_cnt(data, &cmd_cnt, &pnt_cnt,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
791 &float_arg_cnt);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
792 if(r == ERR)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
793 return NULL;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
794
8
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
795 /* Align at 4's boundary and keep 2 unused co_aix space
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
796 * to make logic of transformation from relative to absolute
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
797 * simple.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
798 */
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
799 cmd_cnt += RESERVED_AIXS;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
800 cmd_cnt = (cmd_cnt + 3) & ~0x3;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
801
149
Thinker K.F. Li <thinker@branda.to>
parents: 146
diff changeset
802 /*! \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
803 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
804 /*! \todo Remove this memset()? */
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
805 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
806 mb_obj_init(path, MBO_PATH);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
807 path->cmd_len = cmd_cnt;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
808 path->pnt_len = pnt_cnt;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
809 path->float_arg_len = float_arg_cnt;
145
609ed47a58f2 Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents: 112
diff changeset
810
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
811 msz = cmd_cnt + sizeof(co_aix) * pnt_cnt +
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
812 sizeof(co_aix) * float_arg_cnt;
145
609ed47a58f2 Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents: 112
diff changeset
813 path->user_data = (char *)malloc(msz * 2);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
814 if(path->user_data == NULL) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
815 free(path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
816 return NULL;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
817 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
818
145
609ed47a58f2 Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents: 112
diff changeset
819 path->dev_data = path->user_data + msz;
609ed47a58f2 Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents: 112
diff changeset
820
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
821 r = sh_path_cmd_arg_fill(data, path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
822 if(r == ERR) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
823 free(path->user_data);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
824 free(path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
825 return NULL;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
826 }
100
1a1dda98730c Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents: 99
diff changeset
827 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
828
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
829 path->shape.free = sh_path_free;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
830
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
831 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
832
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
833 return (shape_t *)path;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
834 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
835
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
836 shape_t *rdman_shape_path_new_from_binary(redraw_man_t *rdman,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
837 char *commands,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
838 co_aix *pnts, int pnt_cnt,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
839 co_aix *float_args,
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
840 int float_arg_cnt) {
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
841 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
842 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
843 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
844
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
845 /*! \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
846 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
847 /*! \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
848 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
849 mb_obj_init(path, MBO_PATH);
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
850 cmd_cnt = (cmd_cnt + 3) & ~0x3;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
851 path->cmd_len = cmd_cnt;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
852 path->pnt_len = pnt_cnt;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
853 path->float_arg_len = float_arg_cnt;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
854 msz = cmd_cnt + sizeof(co_aix) * pnt_cnt +
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
855 sizeof(co_aix) * float_arg_cnt;
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
856 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
857 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
858 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
859 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
860 }
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
861
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
862 path->dev_data = path->user_data + msz;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
863 memcpy(path->user_data, commands, strlen(commands));
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
864 memcpy(path->user_data + cmd_cnt, pnts, sizeof(co_aix) * pnt_cnt);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
865 memcpy(path->user_data + cmd_cnt + pnt_cnt * sizeof(co_aix),
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
866 float_args, sizeof(co_aix) * float_arg_cnt);
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
867 memcpy(path->dev_data, path->user_data, msz);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
868
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
869 path->shape.free = sh_path_free;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 770
diff changeset
870
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
871 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
872
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
873 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
874 }
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
875
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
876
9
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
877 /*! \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
878 *
6eecdd331fe7 Fix bug in testcase
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
879 */
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
880 void sh_path_transform(shape_t *shape) {
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
881 sh_path_t *path;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
882 co_aix *pnts, *dev_pnts;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
883 co_aix (*poses)[2];
26
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
884 area_t *area;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
885 int pnt_len;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
886 int i;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
887
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
888 ASSERT(shape->type == SHT_PATH);
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
889 ASSERT((shape->pnt_len & 0x1) == 0);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
890
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
891 path = (sh_path_t *)shape;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
892 pnts = (co_aix *)(path->user_data + path->cmd_len);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
893 dev_pnts = (co_aix *)(path->dev_data + path->cmd_len);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
894 pnt_len = path->pnt_len;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
895 for(i = 0; i < pnt_len; i += 2) {
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
896 dev_pnts[0] = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
897 dev_pnts[1] = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
898 coord_trans_pos(shape->coord, dev_pnts, dev_pnts + 1);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
899 dev_pnts += 2;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
900 }
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
901
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
902 if(path->shape.geo) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
903 poses = (co_aix (*)[2])(path->dev_data + path->cmd_len);
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
904 geo_from_positions(path->shape.geo, pnt_len / 2, poses);
26
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
905 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
906 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
907 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
908 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
909 area->h += shape->stroke_width + 1;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
910 }
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
911 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
912
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
913 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
914 sh_path_t *path;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
915 int cmd_len;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
916 char *cmds, cmd;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
917 const co_aix *pnts;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
918 const co_aix *float_args;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
919 co_aix x, y, x1, y1, x2, y2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
920 int i;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
921
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
922 ASSERT(shape->type == SHT_PATH);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
923
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
924 path = (sh_path_t *)shape;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
925 cmd_len = path->cmd_len;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
926 cmds = path->dev_data;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
927 pnts = (co_aix *)(cmds + cmd_len);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
928 float_args = (co_aix *)(cmds + cmd_len + path->pnt_len * sizeof(co_aix));
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
929 x = y = x1 = y1 = x2 = y2 = 0;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
930 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
931 /* 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
932 * to absoluted form.
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
933 */
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
934 cmd = *cmds++;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
935 switch(cmd) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
936 case 'M':
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
937 x = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
938 y = *pnts++;
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
939 mbe_move_to(cr, x, y);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
940 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
941 case 'L':
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
942 x = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
943 y = *pnts++;
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
944 mbe_line_to(cr, x, y);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
945 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
946 case 'C':
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
947 x1 = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
948 y1 = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
949 x2 = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
950 y2 = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
951 x = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
952 y = *pnts++;
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
953 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
954 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
955 case 'S':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
956 x1 = x + x - x2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
957 y1 = y + y - y2;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
958 x2 = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
959 y2 = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
960 x = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
961 y = *pnts++;
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
962 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
963 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
964 case 'Q':
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
965 x1 = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
966 y1 = *pnts++;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
967 x2 = x1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
968 y2 = y1;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
969 x = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
970 y = *pnts++;
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
971 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
972 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
973 case 'T':
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
974 x1 = x + x - x2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
975 y1 = y + y - y2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
976 x2 = x1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
977 y2 = y1;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
978 x = *pnts++;
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
979 y = *pnts++;
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
980 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
981 break;
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
982 case 'A':
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
983 _sh_path_arc_path(cr, path, &pnts, &float_args);
97
9453e68092b5 Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents: 96
diff changeset
984 break;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
985 case 'Z':
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
986 mbe_close_path(cr);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
987 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
988 case '\x0':
8
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
989 i = cmd_len; /* padding! Skip remain ones. */
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
990 break;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
991 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
992 }
22
8fcf2d878ecd shapes with stroke
Thinker K.F. Li <thinker@branda.to>
parents: 20
diff changeset
993 }
6
772511b8b9be Cairo specify RGB values in range 0.0 ~ 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
994
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
995 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
996 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
997 }
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
998
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
999 #ifdef UNITTEST
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1000
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1001 #include <CUnit/Basic.h>
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1002
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
1003 void test_rdman_shape_path_new(void) {
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1004 sh_path_t *path;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1005 co_aix *pnts;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1006
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
1007 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
1008 CU_ASSERT(path != NULL);
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
1009 CU_ASSERT(path->cmd_len == ((5 + RESERVED_AIXS + 3) & ~0x3));
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1010 CU_ASSERT(path->pnt_len == 12);
145
609ed47a58f2 Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents: 112
diff changeset
1011 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
1012 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
1013
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1014 pnts = (co_aix *)(path->user_data + path->cmd_len);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1015 CU_ASSERT(pnts[0] == 33);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1016 CU_ASSERT(pnts[1] == 25);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1017 CU_ASSERT(pnts[2] == 66);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1018 CU_ASSERT(pnts[3] == 80);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1019 CU_ASSERT(pnts[4] == 99);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1020 CU_ASSERT(pnts[5] == 167);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1021 CU_ASSERT(pnts[6] == 110);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1022 CU_ASSERT(pnts[7] == 102);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1023 CU_ASSERT(pnts[8] == 121);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1024 CU_ASSERT(pnts[9] == 179);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1025 CU_ASSERT(pnts[10] == 33);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1026 CU_ASSERT(pnts[11] == 77);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1027 sh_path_free((shape_t *)path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1028 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1029
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1030 void test_path_transform(void) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1031 sh_path_t *path;
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1032 co_aix *pnts;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1033 coord_t coord;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
1034 geo_t geo;
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1035
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
1036 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
1037 CU_ASSERT(path != NULL);
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
1038 CU_ASSERT(path->cmd_len == ((5 + RESERVED_AIXS + 3) & ~0x3));
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1039 CU_ASSERT(path->pnt_len == 12);
145
609ed47a58f2 Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents: 112
diff changeset
1040 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
1041 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
1042
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1043 geo_init(&geo);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
1044 path->shape.geo = &geo;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
1045 geo.shape = (shape_t *)path;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
1046
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1047 coord.aggr_matrix[0] = 1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1048 coord.aggr_matrix[1] = 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1049 coord.aggr_matrix[2] = 1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1050 coord.aggr_matrix[3] = 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1051 coord.aggr_matrix[4] = 2;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1052 coord.aggr_matrix[5] = 0;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
1053 path->shape.coord = &coord;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
1054 sh_path_transform((shape_t *)path);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1055
458
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1056 pnts = (co_aix *)(path->dev_data + path->cmd_len);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1057 CU_ASSERT(pnts[0] == 34);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1058 CU_ASSERT(pnts[1] == 50);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1059 CU_ASSERT(pnts[2] == 67);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1060 CU_ASSERT(pnts[3] == 160);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1061 CU_ASSERT(pnts[4] == 34);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1062 CU_ASSERT(pnts[5] == 174);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1063 CU_ASSERT(pnts[6] == 45);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1064 CU_ASSERT(pnts[7] == 44);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1065 CU_ASSERT(pnts[8] == 56);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1066 CU_ASSERT(pnts[9] == 198);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1067 CU_ASSERT(pnts[10] == 34);
bb4f651090bf Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents: 448
diff changeset
1068 CU_ASSERT(pnts[11] == 154);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
1069
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1070 sh_path_free((shape_t *)path);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1071 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1072
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
1073 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
1074 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
1075
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
1076 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
1077 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
1078 " 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
1079 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
1080 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
1081 }
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
1082
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1083 CU_pSuite get_shape_path_suite(void) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1084 CU_pSuite suite;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1085
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1086 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
1087 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
1088 CU_ADD_TEST(suite, test_path_transform);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1089
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1090 return suite;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1091 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1092
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1093 #endif /* UNITTEST */