annotate src/shape_path.c @ 940:652199a55802

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