OSDN Git Service

lineStyle Shaperecord の処理
authorYoshihiro Yamazaki <yoya@awm.jp>
Wed, 2 Jan 2013 11:15:22 +0000 (20:15 +0900)
committerYoshihiro Yamazaki <yoya@awm.jp>
Wed, 2 Jan 2013 11:15:22 +0000 (20:15 +0900)
src/shape.js

index 0cc6eb6..e12f3ca 100644 (file)
@@ -34,6 +34,7 @@ FlappShape.prototype = {
         var lineStyles = shape.lineStyles;
         var fillEdges = shape.edges.fillEdges;
         var lineEdges = shape.edges.lineEdges;
+        var factor = FlappSWFMatrix.maxAbsScaleSkew(this.absoluteMatrix);
         rca.push("var ctx = canvas.ctx;");
         for (var fillStyle in fillEdges) {
             // style
@@ -43,7 +44,6 @@ FlappShape.prototype = {
             //            console.log(fillStyle);
             //            console.log(fillStyles);
             var styleCode = null;
-            var factor = FlappSWFMatrix.maxAbsScaleSkew(this.absoluteMatrix);
             var edgeInfoList = fillEdges[fillStyle];
             var minX = edgeInfoList.minX;
             var maxX = edgeInfoList.maxX;
@@ -135,6 +135,32 @@ FlappShape.prototype = {
                 rca.push("ctx.restore();");
             }
         }
+        var m = [factor, 0, 0, factor, 0, 0];
+        rca.push("ctx.save()");
+        rca.push("ctx.setTransform("+m[0]+","+m[1]+","+m[2]+","+m[3]+","+m[4]+","+m[5]+");");
+        for (var lineStyle in lineEdges) {
+            var style = lineStyles[lineStyle - 1];
+            var edgeInfoList = fillEdges[fillStyle];
+            rca.push("ctx.lineWidth = "+style.width+";");
+            styleCode = '"'+FlappSWFRGBA.toCSS(style.color)+'"';
+            rca.push("ctx.strokeStyle = "+styleCode+";");
+            rca.push("ctx.beginPath();");
+           for (var i1 = 0, l1 = edgeInfoList.length ; i1 < l1 ; i1++) {
+                var edgeInfo = edgeInfoList[i1];
+                var types = edgeInfo.types;
+                var edges = edgeInfo.edges;
+               var types_index = 0;
+               for (var i2 = 0, l2 = edges.length ; i2 < l2 ; ) {
+                    if (types[types_index++] === 'C') {
+                        rca.push("ctx.quadraticCurveTo("+(edges[i2++]-minX)*factor+","+(edges[i2++]-minY)*factor+","+(edges[i2++]-minX)*factor+","+(edges[i2++]-minY)*factor+");");
+                    } else {
+                        rca.push("ctx.lineTo("+(edges[i2++]-minX)*factor+","+(edges[i2++]-minY)*factor+");");
+                        }
+               }
+           }
+            rca.push("ctx.stroke();");
+       }
+        rca.push("ctx.restore()");
         this.renderCode = rca.join("\n");
         console.debug(this.renderCode);
     },