| function SVGTextElement(data,parentContainer,globalData,comp, placeholder){ |
| this.textSpans = []; |
| this.renderType = 'svg'; |
| this._parent.constructor.call(this,data,parentContainer,globalData,comp, placeholder); |
| } |
| createElement(SVGBaseElement, SVGTextElement); |
| |
| SVGTextElement.prototype.init = ITextElement.prototype.init; |
| SVGTextElement.prototype.createPathShape = ITextElement.prototype.createPathShape; |
| SVGTextElement.prototype.getMeasures = ITextElement.prototype.getMeasures; |
| SVGTextElement.prototype.prepareFrame = ITextElement.prototype.prepareFrame; |
| SVGTextElement.prototype.buildShapeString = ITextElement.prototype.buildShapeString; |
| |
| SVGTextElement.prototype.createElements = function(){ |
| |
| this._parent.createElements.call(this); |
| |
| |
| if(this.data.ln){ |
| this.layerElement.setAttribute('id',this.data.ln); |
| } |
| if(this.data.cl){ |
| this.layerElement.setAttribute('class',this.data.cl); |
| } |
| }; |
| |
| SVGTextElement.prototype.buildNewText = function(){ |
| var i, len; |
| |
| var documentData = this.currentTextDocumentData; |
| this.renderedLetters = Array.apply(null,{length:this.currentTextDocumentData.l ? this.currentTextDocumentData.l.length : 0}); |
| if(documentData.fc) { |
| this.layerElement.setAttribute('fill', 'rgb(' + Math.round(documentData.fc[0]*255) + ',' + Math.round(documentData.fc[1]*255) + ',' + Math.round(documentData.fc[2]*255) + ')'); |
| }else{ |
| this.layerElement.setAttribute('fill', 'rgba(0,0,0,0)'); |
| } |
| if(documentData.sc){ |
| this.layerElement.setAttribute('stroke', 'rgb(' + Math.round(documentData.sc[0]*255) + ',' + Math.round(documentData.sc[1]*255) + ',' + Math.round(documentData.sc[2]*255) + ')'); |
| this.layerElement.setAttribute('stroke-width', documentData.sw); |
| } |
| this.layerElement.setAttribute('font-size', documentData.s); |
| var fontData = this.globalData.fontManager.getFontByName(documentData.f); |
| if(fontData.fClass){ |
| this.layerElement.setAttribute('class',fontData.fClass); |
| } else { |
| this.layerElement.setAttribute('font-family', fontData.fFamily); |
| var fWeight = documentData.fWeight, fStyle = documentData.fStyle; |
| this.layerElement.setAttribute('font-style', fStyle); |
| this.layerElement.setAttribute('font-weight', fWeight); |
| } |
| |
| |
| |
| var letters = documentData.l || []; |
| len = letters.length; |
| if(!len){ |
| return; |
| } |
| var tSpan; |
| var matrixHelper = this.mHelper; |
| var shapes, shapeStr = '', singleShape = this.data.singleShape; |
| if (singleShape) { |
| var xPos = 0, yPos = 0, lineWidths = documentData.lineWidths, boxWidth = documentData.boxWidth, firstLine = true; |
| } |
| var cnt = 0; |
| for (i = 0;i < len ;i += 1) { |
| if(this.globalData.fontManager.chars){ |
| if(!singleShape || i === 0){ |
| tSpan = this.textSpans[cnt] ? this.textSpans[cnt] : document.createElementNS(svgNS,'path'); |
| } |
| }else{ |
| tSpan = this.textSpans[cnt] ? this.textSpans[cnt] : document.createElementNS(svgNS,'text'); |
| } |
| tSpan.style.display = 'inherit'; |
| tSpan.setAttribute('stroke-linecap', 'butt'); |
| tSpan.setAttribute('stroke-linejoin','round'); |
| tSpan.setAttribute('stroke-miterlimit','4'); |
| //tSpan.setAttribute('visibility', 'hidden'); |
| if(singleShape && letters[i].n) { |
| xPos = 0; |
| yPos += documentData.yOffset; |
| yPos += firstLine ? 1 : 0; |
| firstLine = false; |
| } |
| matrixHelper.reset(); |
| if(this.globalData.fontManager.chars) { |
| matrixHelper.scale(documentData.s / 100, documentData.s / 100); |
| } |
| if (singleShape) { |
| if(documentData.ps){ |
| matrixHelper.translate(documentData.ps[0],documentData.ps[1] + documentData.ascent,0); |
| } |
| matrixHelper.translate(0,-documentData.ls,0); |
| switch(documentData.j){ |
| case 1: |
| matrixHelper.translate(documentData.justifyOffset + (boxWidth - lineWidths[letters[i].line]),0,0); |
| break; |
| case 2: |
| matrixHelper.translate(documentData.justifyOffset + (boxWidth - lineWidths[letters[i].line])/2,0,0); |
| break; |
| } |
| matrixHelper.translate(xPos, yPos, 0); |
| } |
| if(this.globalData.fontManager.chars){ |
| var charData = this.globalData.fontManager.getCharData(documentData.t.charAt(i), fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily); |
| var shapeData; |
| if(charData){ |
| shapeData = charData.data; |
| } else { |
| shapeData = null; |
| } |
| if(shapeData && shapeData.shapes){ |
| shapes = shapeData.shapes[0].it; |
| if(!singleShape){ |
| shapeStr = ''; |
| } |
| shapeStr += this.createPathShape(matrixHelper,shapes); |
| if(!singleShape){ |
| |
| tSpan.setAttribute('d',shapeStr); |
| } |
| } |
| if(!singleShape){ |
| this.layerElement.appendChild(tSpan); |
| } |
| }else{ |
| tSpan.textContent = letters[i].val; |
| tSpan.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space","preserve"); |
| this.layerElement.appendChild(tSpan); |
| if(singleShape){ |
| tSpan.setAttribute('transform',matrixHelper.to2dCSS()); |
| } |
| } |
| if(singleShape) { |
| xPos += letters[i].l || 0; |
| xPos += documentData.tr/1000*documentData.s; |
| } |
| // |
| this.textSpans[cnt] = tSpan; |
| cnt += 1; |
| } |
| if(!singleShape){ |
| while(cnt < this.textSpans.length){ |
| this.textSpans[cnt].style.display = 'none'; |
| cnt += 1; |
| } |
| } |
| if(singleShape && this.globalData.fontManager.chars){ |
| tSpan.setAttribute('d',shapeStr); |
| this.layerElement.appendChild(tSpan); |
| } |
| } |
| |
| SVGTextElement.prototype.renderFrame = function(parentMatrix){ |
| |
| var renderParent = this._parent.renderFrame.call(this,parentMatrix); |
| if(renderParent===false){ |
| this.hide(); |
| return; |
| } |
| if(this.hidden){ |
| this.show(); |
| } |
| |
| if(this.data.singleShape){ |
| return; |
| } |
| this.getMeasures(); |
| if(!this.lettersChangedFlag){ |
| return; |
| } |
| var i,len; |
| var renderedLetters = this.renderedLetters; |
| |
| var letters = this.currentTextDocumentData.l; |
| |
| len = letters.length; |
| var renderedLetter; |
| for(i=0;i<len;i+=1){ |
| if(letters[i].n){ |
| continue; |
| } |
| renderedLetter = renderedLetters[i]; |
| this.textSpans[i].setAttribute('transform',renderedLetter.m); |
| this.textSpans[i].setAttribute('opacity',renderedLetter.o); |
| if(renderedLetter.sw){ |
| this.textSpans[i].setAttribute('stroke-width',renderedLetter.sw); |
| } |
| if(renderedLetter.sc){ |
| this.textSpans[i].setAttribute('stroke',renderedLetter.sc); |
| } |
| if(renderedLetter.fc){ |
| this.textSpans[i].setAttribute('fill',renderedLetter.fc); |
| } |
| } |
| if(this.firstFrame) { |
| this.firstFrame = false; |
| } |
| } |
| |
| |
| SVGTextElement.prototype.destroy = function(){ |
| this._parent.destroy.call(this._parent); |
| }; |