From 0361670dd7d84b9262285694dc374a2b1625ff6d Mon Sep 17 00:00:00 2001 From: Tobias Schneider Date: Fri, 17 Jan 2014 13:42:08 -0800 Subject: [PATCH] Render text (as shapes for now) --- src/flash/text/StaticText.js | 31 +++++++++++++++++++++++++++++++ src/flash/text/TextField.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/src/flash/text/StaticText.js b/src/flash/text/StaticText.js index a39c68406..d88f3f8b0 100644 --- a/src/flash/text/StaticText.js +++ b/src/flash/text/StaticText.js @@ -16,6 +16,8 @@ * limitations under the License. */ +var StaticTextCache = { }; + var StaticTextDefinition = (function () { var def = { __class__: 'flash.text.StaticText', @@ -24,6 +26,35 @@ var StaticTextDefinition = (function () { var s = this.symbol; if (s) { this.draw = s.draw; + + var renderable = StaticTextCache[s.symbolId]; + + var bounds = this.getBounds(null); + var rect = new Shumway.Geometry.Rectangle(bounds.xMin / 20, + bounds.yMin / 20, + (bounds.xMax - bounds.xMin) / 20, + (bounds.yMax - bounds.yMin) / 20); + + if (!renderable) { + renderable = { + source: this, + getBounds: function () { + return rect; + }, + properties: { }, + render: function (ctx) { + ctx.save(); + ctx.translate(-rect.x, -rect.y); + this.source.draw(ctx, 0, new RenderingColorTransform()); + ctx.restore(); + } + }; + + StaticTextCache[s.symbolId] = renderable; + } + + this._layer = new Shumway.Layers.Shape(renderable); + this._layer.origin = new Shumway.Geometry.Point(rect.x, rect.y); } }, diff --git a/src/flash/text/TextField.js b/src/flash/text/TextField.js index 616df4592..7a263722f 100644 --- a/src/flash/text/TextField.js +++ b/src/flash/text/TextField.js @@ -18,6 +18,8 @@ /*global avm1lib, rgbaObjToStr, rgbIntAlphaToStr, warning, FontDefinition, Errors, throwError */ +var TextFieldCache = { }; + var TextFieldDefinition = (function () { var htmlParser = document.createElement('p'); @@ -581,6 +583,35 @@ var TextFieldDefinition = (function () { } else { this.text = ''; } + + var renderable = TextFieldCache[s.symbolId]; + + var bounds = this.getBounds(null); + var rect = new Shumway.Geometry.Rectangle(bounds.xMin / 20, + bounds.yMin / 20, + (bounds.xMax - bounds.xMin) / 20, + (bounds.yMax - bounds.yMin) / 20); + + if (!renderable) { + renderable = { + source: this, + getBounds: function () { + return rect; + }, + properties: { }, + render: function (ctx) { + ctx.save(); + ctx.translate(-rect.x, -rect.y); + this.source.draw(ctx, 0, new RenderingColorTransform()); + ctx.restore(); + } + }; + + TextFieldCache[s.symbolId] = renderable; + } + + this._layer = new Shumway.Layers.Shape(renderable); + this._layer.origin = new Shumway.Geometry.Point(rect.x, rect.y); }, _getAS2Object: function () {