You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ha...@apache.org on 2019/01/16 13:09:05 UTC
[royale-asjs] branch develop updated: Simplified SVG creation
This is an automated email from the ASF dual-hosted git repository.
harbs pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push:
new a4402d3 Simplified SVG creation
a4402d3 is described below
commit a4402d35dd439f7473bf4e6945b5763ef667dd29
Author: Harbs <ha...@in-tools.com>
AuthorDate: Wed Jan 16 15:08:54 2019 +0200
Simplified SVG creation
---
.../projects/Basic/src/main/royale/BasicClasses.as | 2 ++
.../royale/html/util/addSvgElementToWrapper.as | 37 ++++++++++++++++++++++
.../org/apache/royale/html/util/createSVG.as | 30 ++++++++++++++++++
.../main/royale/org/apache/royale/svg/Circle.as | 3 +-
.../org/apache/royale/svg/CompoundGraphic.as | 11 ++++---
.../royale/org/apache/royale/svg/DOMWrapper.as | 3 +-
.../main/royale/org/apache/royale/svg/Ellipse.as | 3 +-
.../org/apache/royale/svg/GraphicContainer.as | 12 ++++---
.../royale/org/apache/royale/svg/GraphicShape.as | 5 ++-
.../src/main/royale/org/apache/royale/svg/Image.as | 8 +++--
.../src/main/royale/org/apache/royale/svg/Path.as | 3 +-
.../src/main/royale/org/apache/royale/svg/Rect.as | 3 +-
.../src/main/royale/org/apache/royale/svg/Text.as | 3 +-
.../royale/svg/TransformableCompoundGraphic.as | 3 +-
14 files changed, 103 insertions(+), 23 deletions(-)
diff --git a/frameworks/projects/Basic/src/main/royale/BasicClasses.as b/frameworks/projects/Basic/src/main/royale/BasicClasses.as
index 4faef78..beabf2e 100644
--- a/frameworks/projects/Basic/src/main/royale/BasicClasses.as
+++ b/frameworks/projects/Basic/src/main/royale/BasicClasses.as
@@ -30,6 +30,8 @@ internal class BasicClasses
COMPILE::JS
{
import org.apache.royale.html.util.addElementToWrapper; addElementToWrapper;
+ import org.apache.royale.html.util.addSvgElementToWrapper; addSvgElementToWrapper;
+ import org.apache.royale.html.util.createSVG; createSVG;
}
import org.apache.royale.html.ToolTip; ToolTip;
import org.apache.royale.html.accessories.NumericOnlyTextInputBead; NumericOnlyTextInputBead;
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/util/addSvgElementToWrapper.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/util/addSvgElementToWrapper.as
new file mode 100644
index 0000000..76dfdf9
--- /dev/null
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/util/addSvgElementToWrapper.as
@@ -0,0 +1,37 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.royale.html.util
+{
+ COMPILE::JS
+ {
+ import org.apache.royale.core.UIBase;
+ import org.apache.royale.core.WrappedHTMLElement;
+ }
+
+ /**
+ * @royaleignorecoercion org.apache.royale.core.WrappedHTMLElement
+ */
+ COMPILE::JS
+ public function addSvgElementToWrapper(wrapper:UIBase,type:String):WrappedHTMLElement
+ {
+ var elem:WrappedHTMLElement = createSVG(type) as WrappedHTMLElement;
+ wrapper.element = elem;
+ return elem;
+ }
+}
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/util/createSVG.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/util/createSVG.as
new file mode 100644
index 0000000..2169bdb
--- /dev/null
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/util/createSVG.as
@@ -0,0 +1,30 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.royale.html.util
+{
+ /**
+ * Utility function for creating a new SVG Element
+ * @royaleignorecoercion SVGElement
+ */
+ COMPILE::JS
+ public function createSVG(type:String):SVGElement
+ {
+ return document.createElementNS('http://www.w3.org/2000/svg', type) as SVGElement;
+ }
+}
\ No newline at end of file
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Circle.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Circle.as
index 77abe08..f78fada 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Circle.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Circle.as
@@ -30,6 +30,7 @@ package org.apache.royale.svg
COMPILE::JS
{
import org.apache.royale.core.WrappedHTMLElement;
+ import org.apache.royale.html.util.createSVG;
}
public class Circle extends GraphicShape implements ICircle, IDrawable
@@ -92,7 +93,7 @@ package org.apache.royale.svg
var style:String = getStyleStr();
if (_circle == null) {
- _circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle') as WrappedHTMLElement;
+ _circle = createSVG('circle') as WrappedHTMLElement;
_circle.royale_wrapper = this;
element.appendChild(_circle);
}
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/CompoundGraphic.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/CompoundGraphic.as
index 7f80d4d..15d5fbf 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/CompoundGraphic.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/CompoundGraphic.as
@@ -39,6 +39,7 @@ package org.apache.royale.svg
COMPILE::JS
{
import org.apache.royale.core.WrappedHTMLElement;
+ import org.apache.royale.html.util.createSVG;
}
/**
@@ -186,7 +187,7 @@ package org.apache.royale.svg
radiusY = radiusX;
var style:String = getStyleStr();
- var rect:WrappedHTMLElement = document.createElementNS('http://www.w3.org/2000/svg', 'rect') as WrappedHTMLElement;
+ var rect:WrappedHTMLElement = createSVG('rect') as WrappedHTMLElement;
rect.royale_wrapper = this;
rect.style.left = x + "px";
rect.style.top = y + "px";
@@ -230,7 +231,7 @@ package org.apache.royale.svg
COMPILE::JS
{
var style:String = getStyleStr();
- var ellipse:WrappedHTMLElement = document.createElementNS('http://www.w3.org/2000/svg', 'ellipse') as WrappedHTMLElement;
+ var ellipse:WrappedHTMLElement = createSVG('ellipse') as WrappedHTMLElement;
ellipse.royale_wrapper = this;
ellipse.style.left = x + "px";
ellipse.style.top = y + "px";
@@ -267,7 +268,7 @@ package org.apache.royale.svg
COMPILE::JS
{
var style:String = getStyleStr();
- var circle:WrappedHTMLElement = document.createElementNS('http://www.w3.org/2000/svg', 'ellipse') as WrappedHTMLElement;
+ var circle:WrappedHTMLElement = createSVG('ellipse') as WrappedHTMLElement;
circle.royale_wrapper = this;
circle.style.left = x + "px";
circle.style.top = y + "px";
@@ -326,7 +327,7 @@ package org.apache.royale.svg
COMPILE::JS
{
var style:String = getStyleStr();
- var path:WrappedHTMLElement = document.createElementNS('http://www.w3.org/2000/svg', 'path') as WrappedHTMLElement;
+ var path:WrappedHTMLElement = createSVG('path') as WrappedHTMLElement;
path.royale_wrapper = this;
path.style.left = "0px";
path.style.top = "0px";
@@ -541,7 +542,7 @@ package org.apache.royale.svg
COMPILE::JS
{
var style:String = getTxtStyleStr();
- var text:WrappedHTMLElement = document.createElementNS('http://www.w3.org/2000/svg', 'text') as WrappedHTMLElement;
+ var text:WrappedHTMLElement = createSVG('text') as WrappedHTMLElement;
text.royale_wrapper = this;
text.style.left = x + "px";
text.style.top = y + "px";
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/DOMWrapper.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/DOMWrapper.as
index e4bcd76..f8d295e 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/DOMWrapper.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/DOMWrapper.as
@@ -21,6 +21,7 @@ package org.apache.royale.svg
COMPILE::JS
{
import org.apache.royale.core.WrappedHTMLElement;
+ import org.apache.royale.html.util.addSvgElementToWrapper;
}
import org.apache.royale.core.ContainerBase;
@@ -44,7 +45,7 @@ package org.apache.royale.svg
COMPILE::JS
override protected function createElement():WrappedHTMLElement
{
- element = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject') as WrappedHTMLElement;
+ element = addSvgElementToWrapper(this, 'foreignObject') as WrappedHTMLElement;
element.style.left = "0px";
element.style.top = "0px";
//element.offsetParent = null;
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Ellipse.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Ellipse.as
index 6391daa..8c7e63a 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Ellipse.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Ellipse.as
@@ -29,6 +29,7 @@ package org.apache.royale.svg
COMPILE::JS
{
import org.apache.royale.core.WrappedHTMLElement;
+ import org.apache.royale.html.util.createSVG;
}
public class Ellipse extends GraphicShape implements IEllipse, IDrawable
@@ -138,7 +139,7 @@ package org.apache.royale.svg
{
var style:String = getStyleStr();
if (_ellipse == null) {
- _ellipse = document.createElementNS('http://www.w3.org/2000/svg', 'ellipse') as WrappedHTMLElement;
+ _ellipse = createSVG('ellipse') as WrappedHTMLElement;
_ellipse.royale_wrapper = this;
element.appendChild(_ellipse);
}
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/GraphicContainer.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/GraphicContainer.as
index 96754bd..b619922 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/GraphicContainer.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/GraphicContainer.as
@@ -32,6 +32,7 @@ package org.apache.royale.svg
import org.apache.royale.core.IContainer;
import org.apache.royale.core.UIBase;
import org.apache.royale.events.Event;
+ import org.apache.royale.html.util.addSvgElementToWrapper;
}
/**
@@ -57,7 +58,7 @@ package org.apache.royale.svg
COMPILE::JS
override protected function createElement():org.apache.royale.core.WrappedHTMLElement
{
- element = document.createElementNS('http://www.w3.org/2000/svg', 'svg') as org.apache.royale.core.WrappedHTMLElement;
+ element = addSvgElementToWrapper(this,'svg');
// absolute positioned children need a non-null
// position value in the parent. It might
@@ -263,7 +264,10 @@ package org.apache.royale.svg
}
import org.apache.royale.core.GroupBase;
-
+COMPILE::JS
+{
+ import org.apache.royale.html.util.addSvgElementToWrapper;
+}
class GraphicGroup extends GroupBase
{
/**
@@ -272,7 +276,7 @@ class GraphicGroup extends GroupBase
COMPILE::JS
override protected function createElement():org.apache.royale.core.WrappedHTMLElement
{
- element = document.createElementNS('http://www.w3.org/2000/svg', 'g') as org.apache.royale.core.WrappedHTMLElement;
+ return addSvgElementToWrapper(this, 'g');
// absolute positioned children need a non-null
// position value in the parent. It might
@@ -284,7 +288,5 @@ class GraphicGroup extends GroupBase
runLayoutHandler);
addEventListener('elementRemoved',
runLayoutHandler);*/
-
- return element;
}
}
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/GraphicShape.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/GraphicShape.as
index 7245973..35022f8 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/GraphicShape.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/GraphicShape.as
@@ -29,6 +29,7 @@ package org.apache.royale.svg
COMPILE::JS
{
import org.apache.royale.core.WrappedHTMLElement;
+ import org.apache.royale.html.util.addSvgElementToWrapper;
}
import org.apache.royale.core.IRoyaleElement;
@@ -94,9 +95,7 @@ package org.apache.royale.svg
COMPILE::JS
override protected function createElement():WrappedHTMLElement
{
- element = document.createElementNS('http://www.w3.org/2000/svg', 'svg') as WrappedHTMLElement;
- //element.offsetParent = null;
- return element;
+ return addSvgElementToWrapper(this, 'svg');
}
/**
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Image.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Image.as
index 99ee089..f64d5ba 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Image.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Image.as
@@ -22,7 +22,9 @@ package org.apache.royale.svg
COMPILE::JS
{
- import org.apache.royale.core.WrappedHTMLElement;
+ import org.apache.royale.core.WrappedHTMLElement;
+ import org.apache.royale.html.util.addSvgElementToWrapper;
+ import org.apache.royale.html.util.createSVG;
}
public class Image extends ImageBase
{
@@ -45,7 +47,7 @@ package org.apache.royale.svg
COMPILE::JS
override protected function createElement():WrappedHTMLElement
{
- element = document.createElementNS('http://www.w3.org/2000/svg', 'svg') as WrappedHTMLElement;
+ addSvgElementToWrapper(this, 'svg') as WrappedHTMLElement;
element.setAttribute('x', 0);
element.setAttribute('y', 0);
//element.offsetParent = null;
@@ -63,7 +65,7 @@ package org.apache.royale.svg
protected function addImageElement():void
{
if (_image == null) {
- _image = document.createElementNS('http://www.w3.org/2000/svg', 'image') as WrappedHTMLElement;
+ _image = createSVG('image') as WrappedHTMLElement;
_image.setAttribute("width", "100%");
_image.setAttribute("height", "100%");
_image.royale_wrapper = this;
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Path.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Path.as
index 769b21d..d6f90ea 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Path.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Path.as
@@ -32,6 +32,7 @@ package org.apache.royale.svg
COMPILE::JS
{
import org.apache.royale.core.WrappedHTMLElement;
+ import org.apache.royale.html.util.createSVG;
}
@@ -118,7 +119,7 @@ package org.apache.royale.svg
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 = createSVG('path') as WrappedHTMLElement;
_path.royale_wrapper = this;
element.appendChild(_path);
}
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Rect.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Rect.as
index 58c352d..8e0c612 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Rect.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Rect.as
@@ -30,6 +30,7 @@ package org.apache.royale.svg
COMPILE::JS
{
import org.apache.royale.core.WrappedHTMLElement;
+ import org.apache.royale.html.util.createSVG;
}
public class Rect extends GraphicShape implements IRect, IDrawable, ITransformHost
@@ -131,7 +132,7 @@ package org.apache.royale.svg
var style:String = this.getStyleStr();
if (_rect == null) {
- _rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect') as WrappedHTMLElement;
+ _rect = createSVG('rect') as WrappedHTMLElement;
_rect.royale_wrapper = this;
element.appendChild(_rect);
}
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Text.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Text.as
index 61b499c..ca5f613 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Text.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/Text.as
@@ -30,6 +30,7 @@ package org.apache.royale.svg
COMPILE::JS
{
import org.apache.royale.core.WrappedHTMLElement;
+ import org.apache.royale.html.util.createSVG;
}
/**
@@ -132,7 +133,7 @@ package org.apache.royale.svg
{
var style:String = this.getStyleStr();
if (_textElem == null) {
- _textElem = document.createElementNS('http://www.w3.org/2000/svg', 'text') as WrappedHTMLElement;
+ _textElem = createSVG('text') as WrappedHTMLElement;
_textElem.royale_wrapper = this;
element.appendChild(_textElem);
}
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/TransformableCompoundGraphic.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/TransformableCompoundGraphic.as
index e23827f..b453ff2 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/TransformableCompoundGraphic.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/svg/TransformableCompoundGraphic.as
@@ -30,6 +30,7 @@ package org.apache.royale.svg
COMPILE::JS
{
import org.apache.royale.core.WrappedHTMLElement;
+ import org.apache.royale.html.util.createSVG;
}
public class TransformableCompoundGraphic extends CompoundGraphic
{
@@ -74,7 +75,7 @@ package org.apache.royale.svg
override protected function createElement():WrappedHTMLElement
{
super.createElement();
- _groupElement = document.createElementNS('http://www.w3.org/2000/svg', 'g') as WrappedHTMLElement;
+ _groupElement = createSVG('g') as WrappedHTMLElement;
element.appendChild(_groupElement);
return element;
}