´ÓsavedTransformsÊý×éÖÐÈ¥³ý×îºóÒ»¸ö¶ÔÏ󣬲¢½«Æ丳ֵµ½±äÁ¿xform£¬È»ºóµ÷ÓÃÔAPI·½·¨¡£
4 scale·½·¨ xform = xform.scaleNonUniform(sx, sy); return scale.call(ctx, sx, sy);ά»¤xform£¬½«ÆäËõ·Å£¬È»ºóµ÷ÓÃÔAPI·½·¨¡£
5 rotate·½·¨ ¡¡¡¡¡¡¡¡¡¡¡¡ var radians = deg * Math.PI / 180; xform = xform.rotate(deg); return rotate.call(ctx, radians);½«½Ç¶ÈתΪ»¡¶È£¬Î¬»¤xform½«Æä½øÐÐÐýת±ä»»£¬È»ºóµ÷ÓÃÔAPI·½·¨¡£
6 translate·½·¨ xform = xform.translate(dx, dy); return translate.call(ctx, dx, dy);ά»¤xform½«Æä½øÐÐƽÒƱ任£¬È»ºóµ÷ÓÃÔAPI·½·¨¡£
7 transform·½·¨ var m2 = svg.createSVGMatrix(); m2.a = a; m2.b = b; m2.c = c; m2.d = d; m2.e = e; m2.f = f; xform = xform.multiply(m2); return transform.call(ctx, a, b, c, d, e, f); Ê×ÏÈÉùÃ÷Ò»¸öеľØÕóm2£¬m2¸³ÖµÎªÒª½øÐб任µÄ6¸ö²ÎÊýÖµ£¬È»ºóxformºÍm2Ö´ÐоØÕó³Ë·¨ÔËË㣬ÔËËã½á¹û¸³Öµµ½xform½«Æäά»¤¡£È»ºóµ÷ÓÃÔAPI·½·¨¡£ 8 setTransform·½·¨ xform.a = a; xform.b = b; xform.c = c; xform.d = d; xform.e = e; xform.f = f; return setTransform.call(ctx, a, b, c, d, e, f);ά»¤xformµÄÖµ£¬È»ºóµ÷ÓÃÔAPI·½·¨¡£
9 clearRect·½·¨ ctx.save(); ctx.setTransform(1, 0, 0, 1, 0, 0); clearRect.call(ctx, x, y, w, h); ctx.restore();Ê×Ïȱ£´æcontextµÄµ±Ç°×´Ì¬£¬½«»²¼ÖØÖõ½Ôʼ״̬£¨¿ÉÒÔÀí½âΪ×ø±êϵÖØÖõ½Ä¬ÈÏ×ø±êϵ£©£¬È»ºóµ÷ÓÃÔAPI·½·¨Çå³ý»²¼Ö¸¶¨·¶Î§ÄÚÈÝ¡£Çå³ýºóµ÷ÓÃrestore»Ö¸´Canvas֮ǰ±£´æµÄ״̬¡£
10 getTeansform·½·¨ ctx.getTransform = function () { return xform; };½ÓÏÂÀ´½éÉܵÄÈý¸ö·½·¨¶¼ÊÇÔAPIûÓеġ£getTeansformÖ±½Ó·µ»Øxform£¬¿ÉÒÔ¿´µ½´ú±í»²¼¾ØÕóµÄ6¸öÖµabcdef¡£
11 transformedPoint·½·¨ 54 var pt = svg.createSVGPoint(); 55 //ͨ¹ýÔ×ø±êϵµãx£¬yÇó¶ÔÓ¦µ±Ç°×ø±êϵµÄ×ø±êÖµ 56 ctx.transformedPoint = function (x, y) { 57 pt.x = x; pt.y = y; 58 return pt.matrixTransform(xform.inverse()); 59 }ͨ¹ýÔ×ø±êϵµãx£¬yÇó¶ÔÓ¦µ±Ç°×ø±êϵµÄ×ø±êÖµ¡£
createSVGPoint´´½¨µÄµãΪ£¨0,0£©£¬xform.inverse()ÊÇÇóxformµÄÄæ¾ØÕó¡£MatrixTransformÔòÊÇͨ¹ýÒ»ÖÖ¾ØÕóËã·¨À´½øÐÐÔËËãµÃµ½ÏàÓ¦µÄ±äÐεÄЧ¹ûµÄ¡£¾ØÕóµÄһЩ»ù±¾Ëã·¨¾Í²»¶à×ܽáÁË£¬ÒÔÇ°ÉϿξÍѧ¹ýÁË£¬ÍøÉÏÒ²Óв»ÉÙ½²½â¡£
12 transformedPoint2·½·¨ 60 var pt2 = svg.createSVGPoint(); 61 //µ±Ç°×ø±êϵÖеĵÄxy»¹Ôµ½Ô×ø±êϵ×ø±êÖµ 62 ctx.transformedPoint2 = function (x, y) { 63 pt2.x = x; pt2.y = y; 64 return pt2.matrixTransform(xform); 65 }µ±Ç°×ø±êϵÖеĵÄx£¬y»¹Ôµ½Ô×ø±êϵ×ø±êÖµ¡£
¡¡