TextElement.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import LetterProps from '../utils/text/LetterProps';
  2. import TextProperty from '../utils/text/TextProperty';
  3. import TextAnimatorProperty from '../utils/text/TextAnimatorProperty';
  4. import buildShapeString from '../utils/shapes/shapePathBuilder';
  5. function ITextElement() {
  6. }
  7. ITextElement.prototype.initElement = function (data, globalData, comp) {
  8. this.lettersChangedFlag = true;
  9. this.initFrame();
  10. this.initBaseData(data, globalData, comp);
  11. this.textProperty = new TextProperty(this, data.t, this.dynamicProperties);
  12. this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this);
  13. this.initTransform(data, globalData, comp);
  14. this.initHierarchy();
  15. this.initRenderable();
  16. this.initRendererElement();
  17. this.createContainerElements();
  18. this.createRenderableComponents();
  19. this.createContent();
  20. this.hide();
  21. this.textAnimator.searchProperties(this.dynamicProperties);
  22. };
  23. ITextElement.prototype.prepareFrame = function (num) {
  24. this._mdf = false;
  25. this.prepareRenderableFrame(num);
  26. this.prepareProperties(num, this.isInRange);
  27. };
  28. ITextElement.prototype.createPathShape = function (matrixHelper, shapes) {
  29. var j;
  30. var jLen = shapes.length;
  31. var pathNodes;
  32. var shapeStr = '';
  33. for (j = 0; j < jLen; j += 1) {
  34. if (shapes[j].ty === 'sh') {
  35. pathNodes = shapes[j].ks.k;
  36. shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper);
  37. }
  38. }
  39. return shapeStr;
  40. };
  41. ITextElement.prototype.updateDocumentData = function (newData, index) {
  42. this.textProperty.updateDocumentData(newData, index);
  43. };
  44. ITextElement.prototype.canResizeFont = function (_canResize) {
  45. this.textProperty.canResizeFont(_canResize);
  46. };
  47. ITextElement.prototype.setMinimumFontSize = function (_fontSize) {
  48. this.textProperty.setMinimumFontSize(_fontSize);
  49. };
  50. ITextElement.prototype.applyTextPropertiesToMatrix = function (documentData, matrixHelper, lineNumber, xPos, yPos) {
  51. if (documentData.ps) {
  52. matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0);
  53. }
  54. matrixHelper.translate(0, -documentData.ls, 0);
  55. switch (documentData.j) {
  56. case 1:
  57. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]), 0, 0);
  58. break;
  59. case 2:
  60. matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]) / 2, 0, 0);
  61. break;
  62. default:
  63. break;
  64. }
  65. matrixHelper.translate(xPos, yPos, 0);
  66. };
  67. ITextElement.prototype.buildColor = function (colorData) {
  68. return 'rgb(' + Math.round(colorData[0] * 255) + ',' + Math.round(colorData[1] * 255) + ',' + Math.round(colorData[2] * 255) + ')';
  69. };
  70. ITextElement.prototype.emptyProp = new LetterProps();
  71. ITextElement.prototype.destroy = function () {
  72. };
  73. ITextElement.prototype.validateText = function () {
  74. if (this.textProperty._mdf || this.textProperty._isFirstFrame) {
  75. this.buildNewText();
  76. this.textProperty._isFirstFrame = false;
  77. this.textProperty._mdf = false;
  78. }
  79. };
  80. export default ITextElement;