http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7af78c10/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/GraphicShape.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/GraphicShape.as 
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/GraphicShape.as
new file mode 100644
index 0000000..8f9e326
--- /dev/null
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/GraphicShape.as
@@ -0,0 +1,233 @@
+/**
+ * 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.svg
+{
+       COMPILE::SWF
+    {
+               import flash.display.Graphics;
+               import flash.display.Sprite;
+               import flash.geom.Point;
+               import flash.geom.Rectangle;
+               import org.apache.flex.core.WrappedSprite;
+    }
+    COMPILE::JS
+    {
+        import org.apache.flex.core.WrappedHTMLElement;
+    }
+
+    import org.apache.flex.core.IFlexJSElement;
+       import org.apache.flex.core.UIBase;
+       import org.apache.flex.graphics.IFill;
+       import org.apache.flex.graphics.IStroke;
+       import org.apache.flex.graphics.IGraphicShape;
+
+       public class GraphicShape extends UIBase implements IGraphicShape
+       {
+        
+               private var _fill:IFill;
+               private var _stroke:IStroke;
+
+               public function get stroke():IStroke
+               {
+                       return _stroke;
+               }
+
+               /**
+                *  A solid color fill.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 9
+                *  @playerversion AIR 1.1
+                *  @productversion FlexJS 0.0
+                */
+               public function set stroke(value:IStroke):void
+               {
+                       _stroke = value;
+               }
+
+               public function get fill():IFill
+               {
+                       return _fill;
+               }
+               /**
+                *  A solid color fill.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 9
+                *  @playerversion AIR 1.1
+                *  @productversion FlexJS 0.0
+                */
+               public function set fill(value:IFill):void
+               {
+                       _fill = value;
+               }
+
+               /**
+                * Constructor
+                *
+                * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement
+                */
+        public function GraphicShape()
+        {
+                       super();
+        }
+               
+               /**
+                * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement
+                */
+               COMPILE::JS
+               override protected function createElement():IFlexJSElement
+               {
+                       element = 
document.createElementNS('http://www.w3.org/2000/svg', 'svg') as 
WrappedHTMLElement;
+                       element.flexjs_wrapper = this;
+                       element.style.left = 0;
+                       element.style.top = 0;
+                       //element.offsetParent = null;
+                       positioner = element;
+                       positioner.style.position = 'relative';
+                       
+                       return element;
+               }
+
+
+        COMPILE::SWF
+               protected function applyStroke():void
+               {
+                       if(stroke)
+                       {
+                               stroke.apply($sprite.graphics);
+                       }
+               }
+
+        COMPILE::SWF
+               protected function 
beginFill(targetBounds:Rectangle,targetOrigin:Point):void
+               {
+                       if(fill)
+                       {
+                               fill.begin($sprite.graphics, 
targetBounds,targetOrigin);
+                       }
+               }
+
+        COMPILE::SWF
+               protected function endFill():void
+               {
+                       if(fill)
+                       {
+                               fill.end($sprite.graphics);
+                       }
+               }
+
+               /**
+                * This is where the drawing methods get called from
+                */
+               protected function draw():void
+               {
+                       //Overwrite in subclass
+               }
+
+               override public function addedToParent():void
+               {
+            super.addedToParent();
+                       draw();
+            COMPILE::JS
+            {
+                element.style.overflow = 'visible';
+            }
+               }
+
+        /**
+         * @return {string} The style attribute.
+         */
+        COMPILE::JS
+        public function getStyleStr():String
+        {
+            var fillStr:String;
+            if (fill)
+            {
+                fillStr = fill.addFillAttrib(this);
+            }
+            else
+            {
+                fillStr = 'fill:none';
+            }
+
+            var strokeStr:String;
+            if (stroke)
+            {
+                strokeStr = stroke.addStrokeAttrib(this);
+            }
+            else
+            {
+                strokeStr = 'stroke:none';
+            }
+
+
+            return fillStr + ';' + strokeStr;
+        }
+
+               COMPILE::JS
+               override protected function setClassName(value:String):void
+               {
+                       element.setAttribute('class', value);           
+               }
+
+
+        /**
+         * @param x X position.
+         * @param y Y position.
+         * @param bbox The bounding box of the svg element.
+         */
+        COMPILE::JS
+        public function resize(x:Number, y:Number, bbox:SVGRect):void
+        {
+            var useWidth:Number = Math.max(this.width, bbox.width);
+            var useHeight:Number = Math.max(this.height, bbox.height);
+
+            element.style.position = 'absolute';
+            if (!isNaN(x)) element.style.top = x;
+            if (!isNaN(y)) element.style.left = y;
+            element.style.width = useWidth;
+            element.style.height = useHeight;
+            element.style.left = x;
+            element.style.top = y;
+        }
+
+        COMPILE::JS
+        private var _x:Number;
+        COMPILE::JS
+        private var _y:Number;
+        COMPILE::JS
+        private var _xOffset:Number;
+        COMPILE::JS
+        private var _yOffset:Number;
+
+        /**
+         * @param x X position.
+         * @param y Y position.
+         * @param xOffset offset from x position.
+         * @param yOffset offset from y position.
+         */
+        COMPILE::JS
+        public function setPosition(x:Number, y:Number, xOffset:Number, 
yOffset:Number):void
+        {
+            _x = x;
+            _y = y;
+            _xOffset = xOffset;
+            _yOffset = yOffset;
+            element.style.left = xOffset;
+            element.style.top = yOffset;
+        }
+       }
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7af78c10/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/Path.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/Path.as 
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/Path.as
new file mode 100644
index 0000000..3369e47
--- /dev/null
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/Path.as
@@ -0,0 +1,133 @@
+/**
+ * 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.svg
+{
+    import org.apache.flex.graphics.IPath;
+    import org.apache.flex.graphics.PathBuilder;
+
+    COMPILE::SWF
+    {
+        import flash.display.GraphicsPath;
+        import flash.geom.Point;
+        import flash.geom.Rectangle;
+        import org.apache.flex.graphics.utils.PathHelper;
+    }
+    COMPILE::JS
+    {
+        import org.apache.flex.core.WrappedHTMLElement;
+    }
+
+
+    public class Path extends GraphicShape implements IPath
+    {
+
+        private var _data:String;
+
+        public function get data():String
+        {
+            return _data;
+        }
+
+        public function set data(value:String):void
+        {
+            _data = value;
+            _pathCommands = null;
+        }
+        
+        private var _pathCommands:PathBuilder;
+
+        public function get pathCommands():PathBuilder
+        {
+            return _pathCommands;
+        }
+
+        public function set pathCommands(value:PathBuilder):void
+        {
+            _pathCommands = value;
+            _data = _pathCommands.getPathString();
+        }
+
+        
+        COMPILE::JS
+        private var _path:WrappedHTMLElement;
+
+        /**
+         *  Draw the path.
+         *  @param data A PathBuilder object containing a vector of drawing 
commands.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         *  @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement
+         */
+        public function 
drawPathCommands(xp:Number,yp:Number,data:PathBuilder):void
+        {
+            drawStringPath(xp,yp,data.getPathString());
+        }
+
+        /**
+         *  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 drawStringPath(xp:Number,yp:Number,data:String):void
+        {
+            COMPILE::SWF
+            {
+                $sprite.graphics.clear();
+                applyStroke();
+                var bounds:Rectangle = PathHelper.getBounds(data);
+                this.width = bounds.width;
+                this.height = bounds.height;
+                beginFill(bounds,new Point(bounds.left + xp, bounds.top + yp) 
);
+                var graphicsPath:GraphicsPath = 
PathHelper.getSegments(data,xp,yp);
+                $sprite.graphics.drawPath(graphicsPath.commands, 
graphicsPath.data);
+                endFill();
+            }
+            COMPILE::JS
+            {
+                if (data == null || data.length === 0) return;
+                var style:String = getStyleStr();
+                if (_path == null) {
+                    _path = 
document.createElementNS('http://www.w3.org/2000/svg', 'path') as 
WrappedHTMLElement;
+                    _path.flexjs_wrapper = this;
+                    element.appendChild(_path);
+                }
+                _path.setAttribute('style', style);
+                _path.setAttribute('d', data);
+
+                resize(x, y, _path['getBBox']());
+
+            }
+        }
+
+        override protected function draw():void
+        {
+            drawStringPath(0, 0, data);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7af78c10/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/Rect.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/Rect.as 
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/Rect.as
new file mode 100644
index 0000000..14f153e
--- /dev/null
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/Rect.as
@@ -0,0 +1,156 @@
+/**
+ * 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.svg
+{
+       import org.apache.flex.graphics.IRect;
+
+    COMPILE::SWF
+    {
+        import flash.geom.Point;
+        import flash.geom.Rectangle;            
+    }
+    COMPILE::JS
+    {
+        import org.apache.flex.core.WrappedHTMLElement;
+    }
+
+       public class Rect extends GraphicShape implements IRect
+       {
+               /**
+                *  constructor.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.7
+                */
+               public function Rect(x:Number=0, y:Number=0, width:Number=0, 
height:Number=0,rx:Number=NaN,ry:Number=NaN)
+               {
+                       this.x = x;
+                       this.y = y;
+                       this.width = width;
+                       this.height = height;
+                       this.rx = rx;
+                       this.ry = ry;
+               }
+
+               COMPILE::JS
+               private var _rect:WrappedHTMLElement;
+               
+               private var _rx:Number;
+
+               /**
+                * The x axis radius for rounded corners 
+                * 
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.7
+                */
+               public function get rx():Number
+               {
+                       return _rx;
+               }
+
+               public function set rx(value:Number):void
+               {
+                       _rx = value;
+               }
+
+               private var _ry:Number;
+
+               /**
+                * The y axis radius for rounded corners 
+                * 
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.7
+                * 
+                */
+               public function get ry():Number
+               {
+                       return _ry;
+               }
+
+               public function set ry(value:Number):void
+               {
+                       _ry = value;
+               }
+
+               /**
+                *  Draw the rectangle.
+                *  @param xp The x position of the top-left corner of the 
rectangle.
+                *  @param yp 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
+         *  @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement
+                */
+               public function drawRect(xp:Number, yp:Number, width:Number, 
height:Number):void
+               {
+            COMPILE::SWF
+            {
+                $sprite.graphics.clear();
+                applyStroke();
+                beginFill(new Rectangle(xp, yp, width, height), new 
Point(xp,yp));
+                if(isNaN(rx))
+                    $sprite.graphics.drawRect(0, 0, width, height);
+                else
+                {
+                    var dx:Number = rx*2;
+                    var dy:Number = isNaN(ry) ? ry : ry*2;
+                    $sprite.graphics.drawRoundRect(0, 0, width, height,dx ,dy);
+                }
+                endFill();                    
+            }
+            COMPILE::JS
+            {
+                var style:String = this.getStyleStr();
+                               
+                               if (_rect == null) {
+                       _rect = 
document.createElementNS('http://www.w3.org/2000/svg', 'rect') as 
WrappedHTMLElement;
+                       _rect.flexjs_wrapper = this;
+                                       element.appendChild(_rect);
+                               }
+                _rect.setAttribute('style', style);
+                if (stroke)
+                {
+                                       _rect.setAttribute('x', stroke.weight / 
2);
+                                       _rect.setAttribute('y', stroke.weight / 
2);
+                }
+                else
+                {
+                                       _rect.setAttribute('x', 0);
+                                       _rect.setAttribute('y', 0);
+                }
+                               _rect.setAttribute('width', width);
+                               _rect.setAttribute('height', height);
+                
+                resize(x, y, _rect['getBBox']());
+            }
+               }
+               
+               override protected function draw():void
+               {
+                       drawRect(0,0,width,height);
+               }
+               
+       }
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7af78c10/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/Text.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/Text.as 
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/Text.as
new file mode 100644
index 0000000..51b8135
--- /dev/null
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/svg/Text.as
@@ -0,0 +1,150 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You 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.svg
+{
+       import org.apache.flex.graphics.IText;
+       import org.apache.flex.graphics.SolidColor;
+
+    COMPILE::SWF
+    {
+        import flash.text.TextFieldType;        
+        import org.apache.flex.core.CSSTextField;            
+    }
+    COMPILE::JS
+    {
+        import org.apache.flex.core.WrappedHTMLElement;
+    }
+       
+       /**
+        *  Draws a string of characters at a specific location using the stroke
+        *  value of color and alpha.
+        *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion FlexJS 0.0
+     *  // TODO (aharui) ignore imports of external linkage interfaces?
+     *  @flexjsignoreimport SVGLocatable
+        */
+       public class Text extends GraphicShape implements IText
+       {
+               /**
+                *  constructor.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.0
+                */
+               public function Text()
+               {
+                       super();
+                       
+            COMPILE::SWF
+            {
+                _textField = new CSSTextField();
+                $sprite.addChild(_textField);
+            }
+               }
+               
+
+        COMPILE::SWF
+               private var _textField:CSSTextField;
+               
+               COMPILE::JS
+               private var _text:WrappedHTMLElement;
+               
+               /**
+                *  @copy org.apache.flex.core.ITextModel#textField
+                *  
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.0
+                */
+        COMPILE::SWF
+               public function get textField() : CSSTextField
+               {
+                       return _textField;
+               }
+               
+               /**
+                *  Draws text at the given point.
+                *  @param value The string to draw.
+                *  @param xt The x position of the top-left corner of the 
rectangle.
+                *  @param yt The y position of the top-left corner.
+                *
+                *  @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
+         *  @flexjsignorecoercion SVGLocatable
+                */
+               public function drawText(value:String, xt:Number, 
yt:Number):void
+               {
+            COMPILE::SWF
+            {
+                textField.selectable = false;
+                textField.type = TextFieldType.DYNAMIC;
+                textField.mouseEnabled = false;
+                textField.autoSize = "left";
+                textField.text = value;
+                
+                var color:SolidColor = fill as SolidColor;
+                if (color) {
+                    textField.textColor = color.color;
+                    textField.alpha = color.alpha;
+                }
+                
+                textField.x = xt;
+                textField.y = yt;                    
+            }
+            COMPILE::JS
+            {
+                var style:String = this.getStyleStr();
+                               if (_text == null) {
+                       _text = 
document.createElementNS('http://www.w3.org/2000/svg', 'text') as 
WrappedHTMLElement;
+                       _text.flexjs_wrapper = this;
+                                       element.appendChild(_text);
+                               }
+                               else {
+                                       _text.removeChild(_text.childNodes[0]);
+                               }
+                _text.setAttribute('style', style);
+                _text.setAttribute('x', xt);
+                _text.setAttribute('y', yt);
+                               var textNode:Text = 
document.createTextNode(value) as Text;
+                               _text.appendChild(textNode as Node);
+                
+                resize(x, y, (_text as SVGLocatable).getBBox());
+
+            }
+               }
+        
+        COMPILE::JS
+        override protected function draw():void
+        {
+            
+        }
+
+       }
+}

Reply via email to