Lines Matching refs:self
25 def __init__(self, parent, width, height, context = "ctx"):
26 self.obj = context
27 self.code = [] #stores the code
28 self.style = {}
29 self.styleCache = {} #stores the previous style applied
30 self.parent = parent
31 self.width = width
32 self.height = height
34 def write(self, text):
35 self.code.append("\t" + text.replace("ctx", self.obj) + "\n")
37 def output(self):
54 return dedent(html) % (self.width, self.height, self.obj, "".join(self.code))
56 def equalStyle(self, style, key):
58 if key in self.styleCache:
62 return style[key] == self.styleCache[key]
64 def beginPath(self):
65 self.write("ctx.beginPath();")
67 def createLinearGradient(self, href, x1, y1, x2, y2):
69 self.write("var %s = \
72 def createRadialGradient(self, href, cx1, cy1, rx, cx2, cy2, ry):
74 self.write("var %s = ctx.createRadialGradient\
77 def addColorStop(self, href, pos, color):
78 self.write("%s.addColorStop(%f, %s);" % (href, pos, color))
80 def getColor(self, rgb, a):
88 def setGradient(self, href):
94 color = self.getColor(stop_color, opacity)
96 self.addColorStop(href, pos, color)
100 def setOpacity(self, value):
101 self.write("ctx.globalAlpha = %.1f;" % float(value))
103 def setFill(self, value):
105 alpha = self.style["fill-opacity"]
109 fill = self.getColor(value, alpha)
110 self.write("ctx.fillStyle = %s;" % fill)
112 def setStroke(self, value):
114 alpha = self.style["stroke-opacity"]
117 self.write("ctx.strokeStyle = %s;" % self.getColor(value, alpha))
119 def setStrokeWidth(self, value):
120 self.write("ctx.lineWidth = %f;" % self.parent.unittouu(value))
122 def setStrokeLinecap(self, value):
123 self.write("ctx.lineCap = '%s';" % value)
125 def setStrokeLinejoin(self, value):
126 self.write("ctx.lineJoin = '%s';" % value)
128 def setStrokeMiterlimit(self, value):
129 self.write("ctx.miterLimit = %s;" % value)
131 def setFont(self, value):
132 self.write("ctx.font = \"%s\";" % value)
134 def moveTo(self, x, y):
135 self.write("ctx.moveTo(%f, %f);" % (x, y))
137 def lineTo(self, x, y):
138 self.write("ctx.lineTo(%f, %f);" % (x, y))
140 def quadraticCurveTo(self, cpx, cpy, x, y):
142 self.write("ctx.quadraticCurveTo(%f, %f, %f, %f);" % data)
144 def bezierCurveTo(self, x1, y1, x2, y2, x, y):
146 self.write("ctx.bezierCurveTo(%f, %f, %f, %f, %f, %f);" % data)
148 def rect(self, x, y, w, h, rx = 0, ry = 0):
151 self.moveTo(x, y + ry)
152 self.lineTo(x, y+h-ry)
153 self.quadraticCurveTo(x, y+h, x+rx, y+h)
154 self.lineTo(x+w-rx, y+h)
155 self.quadraticCurveTo(x+w, y+h, x+w, y+h-ry)
156 self.lineTo(x+w, y+ry)
157 self.quadraticCurveTo(x+w, y, x+w-rx, y)
158 self.lineTo(x+rx, y)
159 self.quadraticCurveTo(x, y, x, y+ry)
161 self.write("ctx.rect(%f, %f, %f, %f);" % (x, y, w, h))
163 def arc(self, x, y, r, a1, a2, flag):
165 self.write("ctx.arc(%f, %f, %f, %f, %.8f, %d);" % data)
167 def fillText(self, text, x, y):
168 self.write("ctx.fillText(\"%s\", %f, %f);" % (text, x, y))
170 def translate(self, cx, cy):
171 self.write("ctx.translate(%f, %f);" % (cx, cy))
173 def rotate(self, angle):
174 self.write("ctx.rotate(%f);" % angle)
176 def scale(self, rx, ry):
177 self.write("ctx.scale(%f, %f);" % (rx, ry))
179 def transform(self, m11, m12, m21, m22, dx, dy):
181 self.write("ctx.transform(%f, %f, %f, %f, %f, %f);" % data)
183 def save(self):
184 self.write("ctx.save();")
186 def restore(self):
187 self.write("ctx.restore();")
189 def closePath(self):
190 if "fill" in self.style and self.style["fill"] != "none":
191 self.write("ctx.fill();")
192 if "stroke" in self.style and self.style["stroke"] != "none":
193 self.write("ctx.stroke();")
194 #self.write("%s.closePath();" % self.obj)