1 """
2 * Copyright 2008 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http:#www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 """
16
17 import math
18
19 """*
20 * Simple Path String generator class.
21 """
22
23 """*
24 * Path Constants.
25 """
26 ARC = " ar"
27 CLOSE = " x"
28 END = " e"
29 LINETO = " l"
30 MOVETO = " m"
31 CUBIC = " c"
32
33 -def arc(x, y, radius, startAngle, endAngle, antiClockwise, canvas):
34
35 matrix = canvas.matrix
36 context = canvas.context
37
38 if not antiClockwise:
39 realStartAngle = endAngle
40 realEndAngle = startAngle
41 else:
42 realStartAngle = startAngle
43 realEndAngle = endAngle
44
45 ar = radius * 10
46 startX = (x + math.cos(realStartAngle) * ar - 5)
47 startY = (y + math.sin(realStartAngle) * ar - 5)
48 endX = (x + math.cos(realEndAngle) * ar - 5)
49 endY = (y + math.sin(realEndAngle) * ar - 5)
50 if startX == endX and not antiClockwise:
51 startX += 0.125
52
53
54 cx = canvas.getCoordX(matrix, x, y)
55 cy = canvas.getCoordY(matrix, x, y)
56 arcX = (context.arcScaleX * ar)
57 arcY = (context.arcScaleY * ar)
58 return (ARC + str(int(math.floor((cx - arcX + 0.5)))) + ","
59 + str(int(math.floor(cy + arcY + 0.5))) + " "
60 + str(int(math.floor(cx + arcX + 0.5))) + ","
61 + str(int(math.floor(cy - arcY + 0.5))) + " "
62 + str(canvas.getCoordX(matrix, startX, startY)) + ","
63 + str(canvas.getCoordY(matrix, startX, startY)) + " "
64 + str(canvas.getCoordX(matrix, endX, endY)) + ","
65 + str(canvas.getCoordY(matrix, endX, endY)))
66
67
69 matrix = canvas.matrix
70 return (CUBIC + str(canvas.getCoordX(matrix, c1x, c1y)) + ","
71 + str(canvas.getCoordY(matrix, c1x, c1y)) + ","
72 + str(canvas.getCoordX(matrix, c2x, c2y)) + ","
73 + str(canvas.getCoordY(matrix, c2x, c2y)) + ","
74 + str(canvas.getCoordX(matrix, x, y)) + ","
75 + str(canvas.getCoordY(matrix, x, y)))
76
77
80
81
83 matrix = canvas.matrix
84 return (LINETO + str(canvas.getCoordX(matrix, x, y)) + ","
85 + str(canvas.getCoordY(matrix, x, y)))
86
87
89 matrix = canvas.matrix
90 return (MOVETO + str(canvas.getCoordX(matrix, x, y)) + ","
91 + str(canvas.getCoordY(matrix, x, y)))
92