26 "lighter",
"source-over",
"source-over",
"source-over",
"source-over",
27 "source-over",
"source-over",
"source-over",
"source-over",
"source-over",
28 "source-over",
"source-over",
29 "copy",
"source-in",
"source-out",
"source-atop",
30 "destination-over",
"destination-in",
"destination-out",
"destination-atop",
31 "xor",
"source-over",
"source-over" ];
33 #define _CGContextAddArcCanvas(aContext, x, y, radius, startAngle, endAngle, anticlockwise) aContext.arc(x, y, radius, startAngle, endAngle, anticlockwise)
34 #define _CGContextAddArcToPointCanvas(aContext, x1, y1, x2, y2, radius) aContext.arcTo(x1, y1, x2, y2, radius)
35 #define _CGContextAddCurveToPointCanvas(aContext, cp1x, cp1y, cp2x, cp2y, x, y) aContext.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
36 #define _CGContextAddQuadCurveToPointCanvas(aContext, cpx, cpy, x, y) aContext.quadraticCurveTo(cpx, cpy, x, y)
37 #define _CGContextAddLineToPointCanvas(aContext, x, y) aContext.lineTo(x, y)
38 #define _CGContextClosePathCanvas(aContext) aContext.closePath()
39 #define _CGContextMoveToPointCanvas(aContext, x, y) aContext.moveTo(x, y)
41 #define _CGContextAddRectCanvas(aContext, aRect) aContext.rect(_CGRectGetMinX(aRect), _CGRectGetMinY(aRect), _CGRectGetWidth(aRect), _CGRectGetHeight(aRect))
42 #define _CGContextBeginPathCanvas(aContext) aContext.beginPath()
43 #define _CGContextFillRectCanvas(aContext, aRect) aContext.fillRect(_CGRectGetMinX(aRect), _CGRectGetMinY(aRect), _CGRectGetWidth(aRect), _CGRectGetHeight(aRect))
44 #define _CGContextClipCanvas(aContext) aContext.clip()
68 aContext.lineWidth = aLineWidth;
73 aContext.miterLimit = aMiterLimit;
85 _CGContextAddArcCanvas(aContext, x, y, radius, startAngle, endAngle, !clockwise);
90 _CGContextAddArcToPointCanvas(aContext, x1, y1, x2, y2, radius);
95 _CGContextAddCurveToPointCanvas(aContext, cp1x, cp1y, cp2x, cp2y, x, y);
100 _CGContextAddLineToPointCanvas(aContext, x, y);
108 var elements = aPath.elements,
113 for (; i < count; ++i)
115 var element = elements[i],
126 case kCGPathElementAddCurveToPoint: _CGContextAddCurveToPointCanvas(aContext, element.cp1x, element.cp1y, element.cp2x, element.cp2y, element.x, element.y);
130 case kCGPathElementAddArc: _CGContextAddArcCanvas(aContext, element.x, element.y, element.radius, element.startAngle, element.endAngle, element.clockwise);
132 case kCGPathElementAddArcToPoint: _CGContextAddArcToPointCanvas(aContext, element.p1x, element.p1y, element.p2x, element.p2y, element.radius);
140 _CGContextAddRectCanvas(aContext, aRect);
148 var count = rects.length;
150 for (; i < count; ++i)
153 _CGContextAddRectCanvas(aContext, rect);
159 _CGContextBeginPathCanvas(aContext);
164 _CGContextClosePathCanvas(aContext);
169 _CGContextMoveToPointCanvas(aContext, x, y);
174 aContext.clearRect(_CGRectGetMinX(aRect), _CGRectGetMinY(aRect), _CGRectGetWidth(aRect), _CGRectGetHeight(aRect));
182 alert(
"not implemented!!!");
190 _CGContextFillRectCanvas(aContext, aRect);
198 var count = rects.length;
200 for (; i < count; ++i)
203 _CGContextFillRectCanvas(aContext, rect);
209 aContext.strokeRect(_CGRectGetMinX(aRect), _CGRectGetMinY(aRect), _CGRectGetWidth(aRect), _CGRectGetHeight(aRect));
214 _CGContextClipCanvas(aContext);
219 _CGContextBeginPathCanvas(aContext);
220 _CGContextAddRectCanvas(aContext, aRect);
221 _CGContextClosePathCanvas(aContext);
223 _CGContextClipCanvas(aContext);
229 var count = rects.length;
231 _CGContextBeginPathCanvas(aContext);
233 _CGContextClipCanvas(aContext);
238 aContext.globalAlpha = anAlpha;
243 if ([aColor patternImage])
245 var patternImg = [aColor patternImage],
246 size = [patternImg size],
250 img =
new Image(size.width, size.height);
254 img.src = [patternImg filename];
256 var pattern = aContext.createPattern(img,
"repeat");
258 aContext.fillStyle = pattern;
261 aContext.fillStyle = [aColor cssString];
266 aContext.strokeStyle = [aColor cssString];
271 aContext.shadowOffsetX = aSize.width;
272 aContext.shadowOffsetY = aSize.height;
273 aContext.shadowBlur = aBlur;
278 aContext.shadowOffsetX = aSize.width;
279 aContext.shadowOffsetY = aSize.height;
280 aContext.shadowBlur = aBlur;
281 aContext.shadowColor = [aColor cssString];
286 aContext.rotate(anAngle);
291 aContext.scale(sx, sy);
296 aContext.translate(
tx, ty);
299 #define scale_rotate(a, b, c, d) \
300 var sign = (a * d < 0.0 || b * c > 0.0) ? -1.0 : 1.0, \
301 a2 = (ATAN2(b, d) + ATAN2(-sign * c, sign * a)) / 2.0, \
320 sx = (abs_cos * a / cos + abs_sin * -c / sin) / (abs_cos + abs_sin);\
321 sy = (abs_cos * d / cos + abs_sin * b / sin) / (abs_cos + abs_sin);\
324 #define rotate_scale(a, b, c, d) \
325 var sign = (a * d < 0.0 || b * c > 0.0) ? -1.0 : 1.0;\
326 a1 = (ATAN2(sign * b, sign * a) + ATAN2(-c, d)) / 2.0,\
345 sx = (abs_cos * a / cos + abs_sin * b / sin) / (abs_cos + abs_sin);\
346 sy = (abs_cos * d / cos + abs_sin * -c / sin) / (abs_cos + abs_sin);\
351 alert(
"IMPLEMENT ME!");
360 aContext.transform(anAffineTransform.a, anAffineTransform.b, anAffineTransform.c, anAffineTransform.d, anAffineTransform.tx, anAffineTransform.ty);
369 var a = anAffineTransform.a,
370 b = anAffineTransform.b,
371 c = anAffineTransform.c,
372 d = anAffineTransform.d,
373 tx = anAffineTransform.tx,
374 ty = anAffineTransform.ty,
381 if (b == 0.0 && c == 0.0)
388 else if (a * b == -c * d)
394 else if (a * c == -b * d)
400 var transpose = CGAffineTransformMake(a, c, b, d, 0.0, 0.0),
401 u =
eigen(CGAffineTransformConcat(anAffineTransform, transpose)),
402 v =
eigen(CGAffineTransformConcat(transpose, anAffineTransform)),
403 U = CGAffineTransformMake(u.vector_1.x, u.vector_2.x, u.vector_1.y, u.vector_2.y, 0.0, 0.0),
404 VT = CGAffineTransformMake(v.vector_1.x, v.vector_1.y, v.vector_2.x, v.vector_2.y, 0.0, 0.0),
423 if (
tx != 0 || ty != 0)
427 if (sx != 1.0 || sy != 1.0)
437 aContext.drawImage(anImage._image, _CGRectGetMinX(aRect), _CGRectGetMinY(aRect), _CGRectGetWidth(aRect), _CGRectGetHeight(aRect));
442 return "rgba(" + ROUND(aColor.components[0] * 255) +
", " + ROUND(aColor.components[1] * 255) +
", " + ROUND(255 * aColor.components[2]) +
", " + aColor.components[3] +
")";
447 var colors = aGradient.colors,
448 count = colors.length,
450 linearGradient = aContext.createLinearGradient(aStartPoint.x, aStartPoint.y, anEndPoint.x, anEndPoint.y);
453 linearGradient.addColorStop(aGradient.locations[count],
to_string(colors[count]));
455 aContext.fillStyle = linearGradient;
461 var DOMElement = document.createElement(
"canvas"),
462 context = DOMElement.getContext(
"2d");
464 context.DOMElement = DOMElement;