Repository: flex-asjs
Updated Branches:
  refs/heads/develop 1e67bacde -> c383fa729


Added svg drawing APIs


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/c383fa72
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/c383fa72
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/c383fa72

Branch: refs/heads/develop
Commit: c383fa72950e95168c1478acd9470deb94d034e7
Parents: 1e67bac
Author: Harbs <ha...@in-tools.com>
Authored: Tue Jul 26 00:03:16 2016 +0300
Committer: Harbs <ha...@in-tools.com>
Committed: Tue Jul 26 00:03:16 2016 +0300

----------------------------------------------------------------------
 .../Graphics/src/main/flex/GraphicsClasses.as   |  11 +
 .../flex/org/apache/flex/graphics/CubicCurve.as |  56 +++
 .../apache/flex/graphics/ICompoundGraphic.as    |   6 +-
 .../org/apache/flex/graphics/IPathCommand.as    |  16 +
 .../flex/org/apache/flex/graphics/LineTo.as     |  47 +++
 .../flex/org/apache/flex/graphics/MoveTo.as     |  47 +++
 .../org/apache/flex/graphics/PathBuilder.as     | 292 +++++++++++++
 .../org/apache/flex/graphics/QuadraticCurve.as  |  51 +++
 .../flex/org/apache/flex/svg/CompoundGraphic.as | 419 +++++++++++++------
 9 files changed, 819 insertions(+), 126 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c383fa72/frameworks/projects/Graphics/src/main/flex/GraphicsClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Graphics/src/main/flex/GraphicsClasses.as 
b/frameworks/projects/Graphics/src/main/flex/GraphicsClasses.as
index 0cc1db9..551c4a4 100644
--- a/frameworks/projects/Graphics/src/main/flex/GraphicsClasses.as
+++ b/frameworks/projects/Graphics/src/main/flex/GraphicsClasses.as
@@ -39,6 +39,17 @@ internal class GraphicsClasses
        import org.apache.flex.svg.Text; Text;
        import org.apache.flex.svg.CompoundGraphic; CompoundGraphic;
        import org.apache.flex.svg.LinearGradient; LinearGradient;
+       import org.apache.flex.graphics.CubicCurve; CubicCurve;
+       import org.apache.flex.graphics.ICompoundGraphic; ICompoundGraphic;
+       import org.apache.flex.graphics.IGraphicShape; IGraphicShape;
+       import org.apache.flex.graphics.IPathCommand; IPathCommand;
+       import org.apache.flex.graphics.LineStyle; LineStyle;
+       import org.apache.flex.graphics.LineTo; LineTo;
+       import org.apache.flex.graphics.MoveTo; MoveTo;
+       import org.apache.flex.graphics.PathBuilder; PathBuilder;
+       import org.apache.flex.graphics.QuadraticCurve; QuadraticCurve;
+       import org.apache.flex.svg.DOMWrapper; DOMWrapper;
+       
 }
 
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c383fa72/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/CubicCurve.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/CubicCurve.as
 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/CubicCurve.as
new file mode 100644
index 0000000..1727e52
--- /dev/null
+++ 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/CubicCurve.as
@@ -0,0 +1,56 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ package org.apache.flex.graphics
+{
+    COMPILE::SWF
+    {
+        import flash.display.Graphics;
+    }
+    
+    public class CubicCurve implements IPathCommand
+    {
+        public function CubicCurve(controlX1:Number, controlY1:Number, 
controlX2:Number, controlY2:Number, anchorX:Number, anchorY:Number)
+        {
+            _controlX1 = controlX1;
+            _controlY1 = controlY1;
+            _controlX2 = controlX2;
+            _controlY2 = controlY2;
+            _anchorX = anchorX;
+            _anchorY = anchorY;
+        }
+        private var _controlX1:Number;
+        private var _controlY1:Number;
+        private var _controlX2:Number;
+        private var _controlY2:Number;
+        private var _anchorX:Number;
+        private var _anchorY:Number;
+        
+        public function toString():String
+        {
+            return 
["C",_controlX1,_controlY1,_controlX2,_controlY2,_anchorX,_anchorY].join(" ");
+        }
+        COMPILE::SWF
+        public function execute(g:Graphics):void
+        {
+            
g.cubicCurveTo(_controlX1,_controlY1,_controlX2,_controlY2,_anchorX,_anchorY);
+        }
+        COMPILE::JS
+        public function execute(ctx:Object):void
+        {
+            //ctx should be a canvas context. Not sure what the type is.
+            
ctx.bezierCurveTo(_controlX1,_controlY1,_controlX2,_controlY2,_anchorX,_anchorY);
+        }
+        
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c383fa72/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/ICompoundGraphic.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/ICompoundGraphic.as
 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/ICompoundGraphic.as
index 95a7dcd..20f7a74 100644
--- 
a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/ICompoundGraphic.as
+++ 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/ICompoundGraphic.as
@@ -22,7 +22,9 @@ package org.apache.flex.graphics
                function drawCircle(x:Number, y:Number, radius:Number):void;
                function drawPath(data:String):void;
                function drawText(value:String, x:Number, y:Number):Object;
-               function get textColor():IFill;
-               function set textColor(value:IFill):void;
+               function get textFill():IFill;
+               function set textFill(value:IFill):void;
+               function get textStroke():IStroke;
+               function set textStroke(value:IStroke):void;
        }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c383fa72/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/IPathCommand.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/IPathCommand.as
 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/IPathCommand.as
new file mode 100644
index 0000000..100d3ce
--- /dev/null
+++ 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/IPathCommand.as
@@ -0,0 +1,16 @@
+package org.apache.flex.graphics
+{
+       COMPILE::SWF
+       {
+               import flash.display.Graphics;
+       }
+
+       public interface IPathCommand
+       {
+               function toString():String;
+               COMPILE::SWF
+               function execute(g:Graphics):void;
+               COMPILE::JS
+               function execute(ctx:Object):void;
+       }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c383fa72/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/LineTo.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/LineTo.as 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/LineTo.as
new file mode 100644
index 0000000..3a86530
--- /dev/null
+++ 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/LineTo.as
@@ -0,0 +1,47 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ package org.apache.flex.graphics
+{
+       COMPILE::SWF
+       {
+               import flash.display.Graphics;
+       }
+    public class LineTo implements IPathCommand
+    {
+        public function LineTo(x:Number, y:Number)
+        {
+            _x = x;
+            _y = y;
+        }
+        private var _x:Number;
+        private var _y:Number;
+        
+        public function toString():String
+        {
+            return ["L",_x,_y].join(" ");
+        }
+        COMPILE::SWF
+        public function execute(g:Graphics):void
+        {
+            g.lineTo(_x,_y);
+        }
+        COMPILE::JS
+        public function execute(ctx:Object):void
+        {
+            //ctx should be a canvas context. Not sure what the type is.
+            ctx.lineTo(_x,_y);
+        }
+        
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c383fa72/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/MoveTo.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/MoveTo.as 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/MoveTo.as
new file mode 100644
index 0000000..7835cdd
--- /dev/null
+++ 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/MoveTo.as
@@ -0,0 +1,47 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ package org.apache.flex.graphics
+{
+       COMPILE::SWF
+       {
+               import flash.display.Graphics;
+       }
+    public class MoveTo implements IPathCommand
+    {
+        public function MoveTo(x:Number, y:Number)
+        {
+            _x = x;
+            _y = y;
+        }
+        private var _x:Number;
+        private var _y:Number;
+        
+        public function toString():String
+        {
+            return ["M",_x,_y].join(" ");
+        }
+        COMPILE::SWF
+        public function execute(g:Graphics):void
+        {
+            g.moveTo(_x,_y);
+        }
+        COMPILE::JS
+        public function execute(ctx:Object):void
+        {
+            //ctx should be a canvas context. Not sure what the type is.
+            ctx.moveTo(_x,_y);
+        }
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c383fa72/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/PathBuilder.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/PathBuilder.as
 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/PathBuilder.as
new file mode 100644
index 0000000..3b376c7
--- /dev/null
+++ 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/PathBuilder.as
@@ -0,0 +1,292 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flex.graphics
+{
+    import flash.display.Graphics;
+
+    public class PathBuilder
+    {
+
+        /**
+         *  Constructor.
+         *
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 9
+         *  @playerversion AIR 1.1
+         *  @productversion Flex 3
+         */
+        public function PathBuilder()
+        {
+            commands = new Vector.<IPathCommand>();
+        }
+
+        public function getPathString():String
+        {
+            return commands.join(" ");
+        }
+        COMPILE::SWF
+        public function draw(g:Graphics):void
+        {
+            //TODO we can probably make this more efficient by doing all the 
drawing commands at once.
+            var i:int = -1;
+            var len:int = commands.length;
+            while(++i<len)
+            {
+                commands[i].execute(g);
+            }
+
+        }
+        COMPILE::JS
+        public function draw(ctx:Object):void
+        {
+            var i:int = -1;
+            var len:int = commands.length;
+            while(++i<len)
+            {
+                commands[i].execute(ctx);
+            }
+            
+        }
+
+        private var commands:Vector.<IPathCommand>;
+        
+        public function lineTo(x:Number, y:Number):void
+        {
+            commands.push(new LineTo(x,y));
+        }
+        
+        public function moveTo(x:Number, y:Number):void
+        {
+            commands.push(new MoveTo(x,y));
+        }
+        
+        public function quadraticCurveTo(controlX:Number, controlY:Number, 
anchorX:Number, anchorY:Number):void
+        {
+            commands.push(new 
QuadraticCurve(controlX,controlY,anchorX,anchorY));
+        }
+        
+        public function cubicCurveTo(controlX1:Number, controlY1:Number, 
controlX2:Number, controlY2:Number, anchorX:Number, anchorY:Number):void
+        {
+            commands.push(new CubicCurve(controlX1, controlY1, controlX2, 
controlY2, anchorX, anchorY));
+        }
+
+        public function drawRoundRectComplex(x:Number, y:Number, 
+                                                    width:Number, 
height:Number, 
+                                                    topLeftRadius:Number, 
topRightRadius:Number, 
+                                                    bottomLeftRadius:Number, 
bottomRightRadius:Number):void
+        {
+            var b:Array = [];
+            var xw:Number = x + width;
+            var yh:Number = y + height;
+            
+            // Make sure none of the radius values are greater than w/h.
+            // These are all inlined to avoid function calling overhead
+            var minSize:Number = width < height ? width * 2 : height * 2;
+            topLeftRadius = topLeftRadius < minSize ? topLeftRadius : minSize;
+            topRightRadius = topRightRadius < minSize ? topRightRadius : 
minSize;
+            bottomLeftRadius = bottomLeftRadius < minSize ? bottomLeftRadius : 
minSize;
+            bottomRightRadius = bottomRightRadius < minSize ? 
bottomRightRadius : minSize;
+            
+            // Math.sin and Math,tan values for optimal performance.
+            // Math.rad = Math.PI / 180 = 0.0174532925199433
+            // r * Math.sin(45 * Math.rad) =  (r * 0.707106781186547);
+            // r * Math.tan(22.5 * Math.rad) = (r * 0.414213562373095);
+            //
+            // We can save further cycles by precalculating
+            // 1.0 - 0.707106781186547 = 0.292893218813453 and
+            // 1.0 - 0.414213562373095 = 0.585786437626905
+            
+            // bottom-right corner
+            var a:Number = bottomRightRadius * 0.292893218813453;       // 
radius - anchor pt;
+            var s:Number = bottomRightRadius * 0.585786437626905;   // radius 
- control pt;
+            commands.push(new MoveTo(xw, yh - bottomRightRadius));
+            commands.push(new QuadraticCurve(xw, yh - s, xw - a, yh - a));
+            commands.push(new QuadraticCurve(xw - s, yh, xw - 
bottomRightRadius, yh));
+            
+            // bottom-left corner
+            a = bottomLeftRadius * 0.292893218813453;
+            s = bottomLeftRadius * 0.585786437626905;
+            commands.push(new LineTo(x + bottomLeftRadius, yh));
+            commands.push(new QuadraticCurve(x + s, yh, x + a, yh - a));
+            commands.push(new QuadraticCurve(x, yh - s, x, yh - 
bottomLeftRadius));
+            
+            // top-left corner
+            a = topLeftRadius * 0.292893218813453;
+            s = topLeftRadius * 0.585786437626905;
+            commands.push(new LineTo(x, y + topLeftRadius));
+            commands.push(new QuadraticCurve(x, y + s, x + a, y + a));
+            commands.push(new QuadraticCurve(x + s, y, x + topLeftRadius, y));
+            
+            // top-right corner
+            a = topRightRadius * 0.292893218813453;
+            s = topRightRadius * 0.585786437626905;
+            commands.push(new LineTo(xw - topRightRadius, y));
+            commands.push(new QuadraticCurve(xw - s, y, xw - a, y + a));
+            commands.push(new QuadraticCurve(xw, y + s, xw, y + 
topRightRadius));
+            commands.push(new LineTo(xw, yh - bottomRightRadius));
+        }
+        /**
+         * Draws a rounded rectangle using the size of individual x and y 
radii to 
+         * draw the rounded corners. 
+         * 
+         * @param x The horizontal position relative to the 
+         * registration point of the parent display object, in pixels.
+         * 
+         * @param y The vertical position relative to the 
+         * registration point of the parent display object, in pixels.
+         * 
+         * @param width The width of the round rectangle, in pixels.
+         * 
+         * @param height The height of the round rectangle, in pixels.
+         * 
+         * @param radiusX The default radiusX to use, if corner-specific 
values are not specified.
+         * This value must be specified.
+         * 
+         * @param radiusY The default radiusY to use, if corner-specific 
values are not specified. 
+         * If 0, the value of radiusX is used.
+         * 
+         * @param topLeftRadiusX The x radius of the upper-left corner, in 
pixels. If NaN, 
+         * the value of radiusX is used.
+         * 
+         * @param topLeftRadiusY The y radius of the upper-left corner, in 
pixels. If NaN,
+         * the value of topLeftRadiusX is used.
+         * 
+         * @param topRightRadiusX The x radius of the upper-right corner, in 
pixels. If NaN,
+         * the value of radiusX is used.
+         * 
+         * @param topRightRadiusY The y radius of the upper-right corner, in 
pixels. If NaN,
+         * the value of topRightRadiusX is used.
+         * 
+         * @param bottomLeftRadiusX The x radius of the bottom-left corner, in 
pixels. If NaN,
+         * the value of radiusX is used.
+         * 
+         * @param bottomLeftRadiusY The y radius of the bottom-left corner, in 
pixels. If NaN,
+         * the value of bottomLeftRadiusX is used.
+         * 
+         * @param bottomRightRadiusX The x radius of the bottom-right corner, 
in pixels. If NaN,
+         * the value of radiusX is used.
+         * 
+         * @param bottomRightRadiusY The y radius of the bottom-right corner, 
in pixels. If NaN,
+         * the value of bottomRightRadiusX is used.
+         * 
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10
+         *  @playerversion AIR 1.5
+         *  @productversion Flex 4
+         */
+        public function drawRoundRectComplex2(x:Number, y:Number, 
+                                              width:Number, height:Number, 
+                                              radiusX:Number, radiusY:Number,
+                                              topLeftRadiusX:Number, 
topLeftRadiusY:Number,
+                                              topRightRadiusX:Number, 
topRightRadiusY:Number,
+                                              bottomLeftRadiusX:Number, 
bottomLeftRadiusY:Number,
+                                              bottomRightRadiusX:Number, 
bottomRightRadiusY:Number):void
+        {
+            var xw:Number = x + width;
+            var yh:Number = y + height;
+            var maxXRadius:Number = width / 2;
+            var maxYRadius:Number = height / 2;
+            
+            // Rules for determining radius for each corner:
+            //  - If explicit nnnRadiusX value is set, use it. Otherwise use 
radiusX.
+            //  - If explicit nnnRadiusY value is set, use it. Otherwise use 
corresponding nnnRadiusX.
+            if (radiusY == 0)
+                radiusY = radiusX;
+            if (isNaN(topLeftRadiusX))
+                topLeftRadiusX = radiusX;
+            if (isNaN(topLeftRadiusY))
+                topLeftRadiusY = topLeftRadiusX;
+            if (isNaN(topRightRadiusX))
+                topRightRadiusX = radiusX;
+            if (isNaN(topRightRadiusY))
+                topRightRadiusY = topRightRadiusX;
+            if (isNaN(bottomLeftRadiusX))
+                bottomLeftRadiusX = radiusX;
+            if (isNaN(bottomLeftRadiusY))
+                bottomLeftRadiusY = bottomLeftRadiusX;
+            if (isNaN(bottomRightRadiusX))
+                bottomRightRadiusX = radiusX;
+            if (isNaN(bottomRightRadiusY))
+                bottomRightRadiusY = bottomRightRadiusX;
+            
+            // Pin radius values to half of the width/height
+            if (topLeftRadiusX > maxXRadius)
+                topLeftRadiusX = maxXRadius;
+            if (topLeftRadiusY > maxYRadius)
+                topLeftRadiusY = maxYRadius;
+            if (topRightRadiusX > maxXRadius)
+                topRightRadiusX = maxXRadius;
+            if (topRightRadiusY > maxYRadius)
+                topRightRadiusY = maxYRadius;
+            if (bottomLeftRadiusX > maxXRadius)
+                bottomLeftRadiusX = maxXRadius;
+            if (bottomLeftRadiusY > maxYRadius)
+                bottomLeftRadiusY = maxYRadius;
+            if (bottomRightRadiusX > maxXRadius)
+                bottomRightRadiusX = maxXRadius;
+            if (bottomRightRadiusY > maxYRadius)
+                bottomRightRadiusY = maxYRadius;
+            
+            // Math.sin and Math,tan values for optimal performance.
+            // Math.rad = Math.PI / 180 = 0.0174532925199433
+            // r * Math.sin(45 * Math.rad) =  (r * 0.707106781186547);
+            // r * Math.tan(22.5 * Math.rad) = (r * 0.414213562373095);
+            //
+            // We can save further cycles by precalculating
+            // 1.0 - 0.707106781186547 = 0.292893218813453 and
+            // 1.0 - 0.414213562373095 = 0.585786437626905
+            
+            // bottom-right corner
+            var aX:Number = bottomRightRadiusX * 0.292893218813453;     // 
radius - anchor pt;
+            var aY:Number = bottomRightRadiusY * 0.292893218813453;     // 
radius - anchor pt;
+            var sX:Number = bottomRightRadiusX * 0.585786437626905;     // 
radius - control pt;
+            var sY:Number = bottomRightRadiusY * 0.585786437626905;     // 
radius - control pt;
+            commands.push(new MoveTo(xw, yh - bottomRightRadiusY));
+            commands.push(new QuadraticCurve(xw, yh - sY, xw - aX, yh - aY));
+            commands.push(new QuadraticCurve(xw - sX, yh, xw - 
bottomRightRadiusX, yh));
+            
+            // bottom-left corner
+            aX = bottomLeftRadiusX * 0.292893218813453;
+            aY = bottomLeftRadiusY * 0.292893218813453;
+            sX = bottomLeftRadiusX * 0.585786437626905;
+            sY = bottomLeftRadiusY * 0.585786437626905;
+            commands.push(new LineTo(x + bottomLeftRadiusX, yh));
+            commands.push(new QuadraticCurve(x + sX, yh, x + aX, yh - aY));
+            commands.push(new QuadraticCurve(x, yh - sY, x, yh - 
bottomLeftRadiusY));
+            
+            // top-left corner
+            aX = topLeftRadiusX * 0.292893218813453;
+            aY = topLeftRadiusY * 0.292893218813453;
+            sX = topLeftRadiusX * 0.585786437626905;
+            sY = topLeftRadiusY * 0.585786437626905;
+            commands.push(new LineTo(x, y + topLeftRadiusY));
+            commands.push(new QuadraticCurve(x, y + sY, x + aX, y + aY));
+            commands.push(new QuadraticCurve(x + sX, y, x + topLeftRadiusX, 
y));
+            
+            // top-right corner
+            aX = topRightRadiusX * 0.292893218813453;
+            aY = topRightRadiusY * 0.292893218813453;
+            sX = topRightRadiusX * 0.585786437626905;
+            sY = topRightRadiusY * 0.585786437626905;
+            commands.push(new LineTo(xw - topRightRadiusX, y));
+            commands.push(new QuadraticCurve(xw - sX, y, xw - aX, y + aY));
+            commands.push(new QuadraticCurve(xw, y + sY, xw, y + 
topRightRadiusY));
+            commands.push(new LineTo(xw, yh - bottomRightRadiusY));
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c383fa72/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/QuadraticCurve.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/QuadraticCurve.as
 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/QuadraticCurve.as
new file mode 100644
index 0000000..68bec93
--- /dev/null
+++ 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/graphics/QuadraticCurve.as
@@ -0,0 +1,51 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ package org.apache.flex.graphics
+{
+    COMPILE::SWF
+    {
+        import flash.display.Graphics;
+    }
+    public class QuadraticCurve implements IPathCommand
+    {
+        public function QuadraticCurve(controlX:Number, controlY:Number, 
anchorX:Number, anchorY:Number)
+        {
+            _controlX = controlX;
+            _controlY = controlY;
+            _anchorX = anchorX;
+            _anchorY = anchorY;
+        }
+        private var _controlX:Number;
+        private var _controlY:Number;
+        private var _anchorX:Number;
+        private var _anchorY:Number;
+        
+        public function toString():String
+        {
+            return ["Q",_controlX,_controlY,_anchorX,_anchorY].join(" ");
+        }
+        COMPILE::SWF
+        public function execute(g:Graphics):void
+        {
+            g.curveTo(_controlX,_controlY,_anchorX,_anchorY);
+        }
+        COMPILE::JS
+        public function execute(ctx:Object):void
+        {
+            //ctx should be a canvas context. Not sure what the type is.
+            ctx.quadraticCurveTo(_controlX,_controlY,_anchorX,_anchorY);
+        }
+        
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c383fa72/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/CompoundGraphic.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/CompoundGraphic.as
 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/CompoundGraphic.as
index 02f3aa5..9cb3865 100644
--- 
a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/CompoundGraphic.as
+++ 
b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/CompoundGraphic.as
@@ -14,9 +14,11 @@
 
 package org.apache.flex.svg
 {
-       import org.apache.flex.graphics.ICompoundGraphic;
-       import org.apache.flex.graphics.IFill;
-       import org.apache.flex.graphics.SolidColor;
+    import org.apache.flex.graphics.ICompoundGraphic;
+    import org.apache.flex.graphics.IFill;
+    import org.apache.flex.graphics.IStroke;
+    import org.apache.flex.graphics.PathBuilder;
+    import org.apache.flex.graphics.SolidColor;
 
     COMPILE::SWF
     {
@@ -35,21 +37,21 @@ package org.apache.flex.svg
         import org.apache.flex.core.WrappedHTMLElement;
     }
 
-       /**
-        * CompoundGraphic is a surface on which you can
-        * draw various graphic elements such as Rect, Circle,
-        * Ellipse, Path etc.
-        * Use this class if you want to draw multiple graphic
-        * shapes on a single container.
-        *
-        */
-       public class CompoundGraphic extends GraphicShape implements 
ICompoundGraphic
-       {
-        private var _textColor:IFill;
-
-        public function get textColor():IFill
+    /**
+     * CompoundGraphic is a surface on which you can
+     * draw various graphic elements such as Rect, Circle,
+     * Ellipse, Path etc.
+     * Use this class if you want to draw multiple graphic
+     * shapes on a single container.
+     *
+     */
+    public class CompoundGraphic extends GraphicShape implements 
ICompoundGraphic
+    {
+        private var _textFill:IFill;
+
+        public function get textFill():IFill
         {
-            return _textColor;
+            return _textFill;
         }
         /**
          *  The color of the text.
@@ -59,21 +61,40 @@ package org.apache.flex.svg
          *  @playerversion AIR 1.1
          *  @productversion FlexJS 0.0
          */
-        public function set textColor(value:IFill):void
+        public function set textFill(value:IFill):void
         {
-            _textColor = value;
+            _textFill = value;
         }
 
-               /**
-                *  Removes all of the drawn elements of the container.
-                *
-                *  @langversion 3.0
-                *  @playerversion Flash 10.2
-                *  @playerversion AIR 2.6
-                *  @productversion FlexJS 0.0.3
-                */
-               public function removeAllElements():void
-               {
+        private var _textStroke:IStroke;
+
+        public function get textStroke():IStroke
+        {
+            return _textStroke;
+        }
+        /**
+         *  The stroke color of the text.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 9
+         *  @playerversion AIR 1.1
+         *  @productversion FlexJS 0.0
+         */
+        public function set textStroke(value:IStroke):void
+        {
+            _textStroke = value;
+        }
+
+        /**
+         *  Removes all of the drawn elements of the container.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0.3
+         */
+        public function removeAllElements():void
+        {
             clear();
         }
         
@@ -100,21 +121,21 @@ package org.apache.flex.svg
             }
         }
 
-               /**
-                *  Draw the rectangle.
-                *  @param x The x position of the top-left corner of the 
rectangle.
-                *  @param y The y position of the top-left corner.
-                *  @param width The width of the rectangle.
-                *  @param height The height of the rectangle.
-                *
-                *  @langversion 3.0
-                *  @playerversion Flash 10.2
-                *  @playerversion AIR 2.6
-                *  @productversion FlexJS 0.0.3
+        /**
+         *  Draw the rectangle.
+         *  @param x The x position of the top-left corner of the rectangle.
+         *  @param y The y position of the top-left corner.
+         *  @param width The width of the rectangle.
+         *  @param height The height of the rectangle.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0.3
          *  @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement
-                */
-               public function drawRect(x:Number, y:Number, width:Number, 
height:Number):void
-               {
+         */
+        public function drawRect(x:Number, y:Number, width:Number, 
height:Number):void
+        {
             COMPILE::SWF
             {
                 applyStroke();
@@ -136,23 +157,23 @@ package org.apache.flex.svg
                 rect.setAttribute('height', String(height) + 'px');
                 element.appendChild(rect);
             }
-               }
-
-               /**
-                *  Draw the ellipse.
-                *  @param x The x position of the top-left corner of the 
bounding box of the ellipse.
-                *  @param y The y position of the top-left corner of the 
bounding box of the ellipse.
-                *  @param width The width of the ellipse.
-                *  @param height The height of the ellipse.
-                *
-                *  @langversion 3.0
-                *  @playerversion Flash 10.2
-                *  @playerversion AIR 2.6
-                *  @productversion FlexJS 0.0.3
+        }
+
+        /**
+         *  Draw the ellipse.
+         *  @param x The x position of the top-left corner of the bounding box 
of the ellipse.
+         *  @param y The y position of the top-left corner of the bounding box 
of the ellipse.
+         *  @param width The width of the ellipse.
+         *  @param height The height of the ellipse.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0.3
          *  @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement
-                */
-               public function drawEllipse(x:Number, y:Number, width:Number, 
height:Number):void
-               {
+         */
+        public function drawEllipse(x:Number, y:Number, width:Number, 
height:Number):void
+        {
             COMPILE::SWF
             {
                 applyStroke();
@@ -174,22 +195,22 @@ package org.apache.flex.svg
                 ellipse.setAttribute('ry', String(height / 2));
                 element.appendChild(ellipse);
             }
-               }
-
-               /**
-                *  Draw the circle.
-                *  @param x The x location of the center of the circle
-                *  @param y The y location of the center of the circle.
-                *  @param radius The radius of the circle.
-                *
-                *  @langversion 3.0
-                *  @playerversion Flash 10.2
-                *  @playerversion AIR 2.6
-                *  @productversion FlexJS 0.0
+        }
+
+        /**
+         *  Draw the circle.
+         *  @param x The x location of the center of the circle
+         *  @param y The y location of the center of the circle.
+         *  @param radius The radius of the circle.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
          *  @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement
-                */
-               public function drawCircle(x:Number, y:Number, 
radius:Number):void
-               {
+         */
+        public function drawCircle(x:Number, y:Number, radius:Number):void
+        {
             COMPILE::SWF
             {
                 applyStroke();
@@ -212,26 +233,26 @@ package org.apache.flex.svg
                 element.appendChild(circle);
 
             }
-               }
-
-               /**
-                *  Draw the path.
-                *  @param data A string containing a compact represention of 
the path segments.
-                *  The value is a space-delimited string describing each path 
segment. Each
-                *  segment entry has a single character which denotes the 
segment type and
-                *  two or more segment parameters.
-                *
-                *  If the segment command is upper-case, the parameters are 
absolute values.
-                *  If the segment command is lower-case, the parameters are 
relative values.
-                *
-                *  @langversion 3.0
-                *  @playerversion Flash 10.2
-                *  @playerversion AIR 2.6
-                *  @productversion FlexJS 0.0
+        }
+
+        /**
+         *  Draw the path.
+         *  @param data A string containing a compact represention of the path 
segments.
+         *  The value is a space-delimited string describing each path 
segment. Each
+         *  segment entry has a single character which denotes the segment 
type and
+         *  two or more segment parameters.
+         *
+         *  If the segment command is upper-case, the parameters are absolute 
values.
+         *  If the segment command is lower-case, the parameters are relative 
values.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
          *  @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement
-                */
-               public function drawPath(data:String):void
-               {
+         */
+        public function drawPath(data:String):void
+        {
             COMPILE::SWF
             {
                 applyStroke();
@@ -252,34 +273,187 @@ package org.apache.flex.svg
                 path.setAttribute('d', data);
                 element.appendChild(path);
             }
-               }
+        }
+
+        public function drawLine():void
+        {
+
+        }
+
+        public function drawPolygon():void
+        {
 
-               public function drawLine():void
-               {
+        }
+
+
+        /**
+         * Draws a rounded rectangle using the size of a radius to draw the 
rounded corners. 
+         * You must set the line style, fill, or both 
+         * on the Graphics object before 
+         * you call the <code>drawRoundRectComplex()</code> method 
+         * by calling the <code>linestyle()</code>, 
+         * <code>lineGradientStyle()</code>, <code>beginFill()</code>, 
+         * <code>beginGradientFill()</code>, or 
+         * <code>beginBitmapFill()</code> method.
+         * 
+         * @param graphics The Graphics object that draws the rounded 
rectangle.
+         *
+         * @param x The horizontal position relative to the 
+         * registration point of the parent display object, in pixels.
+         * 
+         * @param y The vertical position relative to the 
+         * registration point of the parent display object, in pixels.
+         * 
+         * @param width The width of the round rectangle, in pixels.
+         * 
+         * @param height The height of the round rectangle, in pixels.
+         * 
+         * @param topLeftRadius The radius of the upper-left corner, in pixels.
+         * 
+         * @param topRightRadius The radius of the upper-right corner, in 
pixels.
+         * 
+         * @param bottomLeftRadius The radius of the bottom-left corner, in 
pixels.
+         * 
+         * @param bottomRightRadius The radius of the bottom-right corner, in 
pixels.
+         *
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 9
+         *  @playerversion AIR 1.1
+         *  @productversion Flex 3
+         */
+        public function drawRoundRectComplex(x:Number, y:Number, 
+                                                    width:Number, 
height:Number, 
+                                                    topLeftRadius:Number, 
topRightRadius:Number, 
+                                                    bottomLeftRadius:Number, 
bottomRightRadius:Number):void
+        {
+            COMPILE::SWF
+            {
+                applyStroke();
+                beginFill(new Rectangle(x,y,width,height), new Point(x,y));
+                
graphics.drawRoundRectComplex(x,y,width,height,topLeftRadius,topRightRadius,bottomLeftRadius,bottomRightRadius);
+                endFill();
+            }
+            COMPILE::JS
+            {
+                var builder:PathBuilder = new PathBuilder();
+                builder.drawRoundRectComplex(x, y, width, height, 
topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
+                drawPath(builder.getPathString());
+            }
 
-               }
 
-               public function drawPolygon():void
-               {
+    }
+    
+    /**
+     * Draws a rounded rectangle using the size of individual x and y radii to 
+     * draw the rounded corners. 
+     * You must set the line style, fill, or both 
+     * on the Graphics object before 
+     * you call the <code>drawRoundRectComplex2()</code> method 
+     * by calling the <code>linestyle()</code>, 
+     * <code>lineGradientStyle()</code>, <code>beginFill()</code>, 
+     * <code>beginGradientFill()</code>, or 
+     * <code>beginBitmapFill()</code> method.
+     * 
+     * @param graphics The Graphics object that draws the rounded rectangle.
+     *
+     * @param x The horizontal position relative to the 
+     * registration point of the parent display object, in pixels.
+     * 
+     * @param y The vertical position relative to the 
+     * registration point of the parent display object, in pixels.
+     * 
+     * @param width The width of the round rectangle, in pixels.
+     * 
+     * @param height The height of the round rectangle, in pixels.
+     * 
+     * @param radiusX The default radiusX to use, if corner-specific values 
are not specified.
+     * This value must be specified.
+     * 
+     * @param radiusY The default radiusY to use, if corner-specific values 
are not specified. 
+     * If 0, the value of radiusX is used.
+     * 
+     * @param topLeftRadiusX The x radius of the upper-left corner, in pixels. 
If NaN, 
+     * the value of radiusX is used.
+     * 
+     * @param topLeftRadiusY The y radius of the upper-left corner, in pixels. 
If NaN,
+     * the value of topLeftRadiusX is used.
+     * 
+     * @param topRightRadiusX The x radius of the upper-right corner, in 
pixels. If NaN,
+     * the value of radiusX is used.
+     * 
+     * @param topRightRadiusY The y radius of the upper-right corner, in 
pixels. If NaN,
+     * the value of topRightRadiusX is used.
+     * 
+     * @param bottomLeftRadiusX The x radius of the bottom-left corner, in 
pixels. If NaN,
+     * the value of radiusX is used.
+     * 
+     * @param bottomLeftRadiusY The y radius of the bottom-left corner, in 
pixels. If NaN,
+     * the value of bottomLeftRadiusX is used.
+     * 
+     * @param bottomRightRadiusX The x radius of the bottom-right corner, in 
pixels. If NaN,
+     * the value of radiusX is used.
+     * 
+     * @param bottomRightRadiusY The y radius of the bottom-right corner, in 
pixels. If NaN,
+     * the value of bottomRightRadiusX is used.
+     * 
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 10
+     *  @playerversion AIR 1.5
+     *  @productversion Flex 4
+     */
+    public function drawRoundRectComplex2(x:Number, y:Number, 
+                                                width:Number, height:Number, 
+                                                radiusX:Number, radiusY:Number,
+                                                topLeftRadiusX:Number, 
topLeftRadiusY:Number,
+                                                topRightRadiusX:Number, 
topRightRadiusY:Number,
+                                                bottomLeftRadiusX:Number, 
bottomLeftRadiusY:Number,
+                                                bottomRightRadiusX:Number, 
bottomRightRadiusY:Number):void
+    {
+        var builder:PathBuilder = new PathBuilder();
+        builder.drawRoundRectComplex2(x, y, width, height, radiusX, 
radiusY,topLeftRadiusX, topLeftRadiusY,topRightRadiusX, 
topRightRadiusY,bottomLeftRadiusX, bottomLeftRadiusY,bottomRightRadiusX, 
bottomRightRadiusY);
 
-               }
+        COMPILE::SWF
+        {
+            applyStroke();
+            beginFill(new Rectangle(x,y,width,height), new Point(x,y));
+            builder.draw(graphics);
+            endFill();
+        }
+        COMPILE::JS
+        {
+            drawPath(builder.getPathString());
+        }
+    }
+    
+        /*
+        What about these?
+        beginBitmapFill
+        beginFill
+        beginGradientFill
+        beginShaderFill
+        drawGraphicsData
+        drawRoundRect
+        drawTriangles
+        */
 
-               /**
-                *  Draw a string of characters.
-                *  @param value The string to draw.
-                *  @param x The x location of the center of the circle
-                *  @param y The y location of the center of the circle.
-                *
-                *  @langversion 3.0
-                *  @playerversion Flash 10.2
-                *  @playerversion AIR 2.6
-                *  @productversion FlexJS 0.0
+        /**
+         *  Draw a string of characters.
+         *  @param value The string to draw.
+         *  @param x The x location of the center of the circle
+         *  @param y The y location of the center of the circle.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
          *  @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement
          *  @flexjsignorecoercion Text
          *  @flexjsignorecoercion Node
-                */
-               public function drawText(value:String, x:Number, 
y:Number):Object
-               {
+         */
+        public function drawText(value:String, x:Number, y:Number):Object
+        {
             COMPILE::SWF
             {
                 var textField:CSSTextField = new CSSTextField();
@@ -291,7 +465,7 @@ package org.apache.flex.svg
                 textField.autoSize = "left";
                 textField.text = value;
 
-                var color:SolidColor = textColor as SolidColor;
+                var color:SolidColor = textFill as SolidColor;
                 if (color) {
                     textField.textColor = color.color;
                     textField.alpha = color.alpha;
@@ -318,7 +492,7 @@ package org.apache.flex.svg
                 element.appendChild(text);
                 return text;
             }
-               }
+        }
 
                 /**
          * @return {string} The style attribute.
@@ -327,31 +501,28 @@ package org.apache.flex.svg
         public function getTxtStyleStr():String
         {
             var fillStr:String;
-            if (textColor)
+            if (textFill)
             {
-                fillStr = textColor.addFillAttrib(this);
+                fillStr = textFill.addFillAttrib(this);
             }
             else
             {
                 fillStr = 'fill:none';
             }
-            return fillStr;
 
-            // Not supporting text strokes for now.
-/*
             var strokeStr:String;
-            if (stroke)
+            if (textStroke)
             {
-                strokeStr = stroke.addStrokeAttrib(this);
+                strokeStr = textStroke.addStrokeAttrib(this);
             }
             else
             {
                 strokeStr = 'stroke:none';
             }
             return fillStr + ';' + strokeStr;
-*/
+
 
         }
 
-       }
+    }
 }

Reply via email to