// Class: openfl._internal.symbols.StaticTextSymbol

var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this

$global.Object.defineProperty(exports, "__esModule", {value: true});

var __map_reserved = {};

// Imports

var $hxClasses = require("./../../../hxClasses_stub").default;
var $import = require("./../../../import_stub").default;
var $extend = require("./../../../extend_stub").default;
function openfl__$internal_symbols_SWFSymbol() {return require("./../../../openfl/_internal/symbols/SWFSymbol");}
function openfl_text_StaticText() {return require("./../../../openfl/text/StaticText");}
function Type() {return require("./../../../Type");}

// Constructor

var StaticTextSymbol = function() {
	(openfl__$internal_symbols_SWFSymbol().default).call(this);
}

// Meta

StaticTextSymbol.__name__ = ["openfl","_internal","symbols","StaticTextSymbol"];
StaticTextSymbol.__super__ = (openfl__$internal_symbols_SWFSymbol().default);
StaticTextSymbol.prototype = $extend((openfl__$internal_symbols_SWFSymbol().default).prototype, {
	__createObject: function(swf) {
		var staticText = new (openfl_text_StaticText().default)();
		var graphics = staticText.__graphics;
		if(this.rendered != null) {
			staticText.text = this.rendered.text;
			graphics.copyFrom(this.rendered.__graphics);
			return staticText;
		}
		var text = "";
		if(this.records != null) {
			var font = null;
			var color = 16777215;
			var offsetX = this.matrix.tx;
			var offsetY = this.matrix.ty;
			var scale;
			var index;
			var code;
			var _g = 0;
			var _g1 = this.records;
			while(_g < _g1.length) {
				var record = _g1[_g];
				++_g;
				if(record.fontID != null) {
					font = swf.symbols.get(record.fontID);
				}
				if(record.offsetX != null) {
					offsetX = this.matrix.tx + record.offsetX * 0.05;
				}
				if(record.offsetY != null) {
					offsetY = this.matrix.ty + record.offsetY * 0.05;
				}
				if(record.color != null) {
					color = record.color;
				}
				if(font != null) {
					scale = record.fontHeight / 1024 * 0.05;
					var _g3 = 0;
					var _g2 = record.glyphs.length;
					while(_g3 < _g2) {
						var i = _g3++;
						index = record.glyphs[i];
						text += String.fromCharCode(font.codes[index]);
						var _g4 = 0;
						var _g5 = font.glyphs[index];
						while(_g4 < _g5.length) {
							var command = _g5[_g4];
							++_g4;
							switch((Type().default).enumIndex(command)) {
							case 1:
								var alpha = command[3];
								graphics.beginFill(color & 16777215,(color >> 24 & 255) / 255);
								break;
							case 3:
								var anchorY = command[5];
								var anchorX = command[4];
								var controlY = command[3];
								var controlX = command[2];
								graphics.curveTo(controlX * scale + offsetX,controlY * scale + offsetY,anchorX * scale + offsetX,anchorY * scale + offsetY);
								break;
							case 4:
								graphics.endFill();
								break;
							case 5:
								var miterLimit = command[9];
								var joints = command[8];
								var caps = command[7];
								var scaleMode = command[6];
								var pixelHinting = command[5];
								var alpha1 = command[4];
								var color1 = command[3];
								var thickness = command[2];
								if(thickness != null) {
									graphics.lineStyle(thickness,color1,alpha1,pixelHinting,scaleMode,caps,joints,miterLimit);
								} else {
									graphics.lineStyle();
								}
								break;
							case 6:
								var y = command[3];
								var x = command[2];
								graphics.lineTo(x * scale + offsetX,y * scale + offsetY);
								break;
							case 7:
								var y1 = command[3];
								var x1 = command[2];
								graphics.moveTo(x1 * scale + offsetX,y1 * scale + offsetY);
								break;
							default:
							}
						}
						offsetX += record.advances[i] * 0.05;
					}
				}
			}
		}
		staticText.text = text;
		this.records = null;
		this.rendered = new (openfl_text_StaticText().default)();
		this.rendered.text = text;
		this.rendered.__graphics.copyFrom(staticText.__graphics);
		return staticText;
	}
});
StaticTextSymbol.prototype.__class__ = StaticTextSymbol.prototype.constructor = $hxClasses["openfl._internal.symbols.StaticTextSymbol"] = StaticTextSymbol;

// Init



// Statics




// Export

exports.default = StaticTextSymbol;