@galacean/effects-core 1.6.0-beta.2 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime core for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v1.6.0-beta.2
6
+ * Version: v1.6.0
7
7
  */
8
8
 
9
9
  /******************************************************************************
@@ -20333,6 +20333,10 @@ var TextItem = /** @class */ (function (_super) {
20333
20333
  function TextItem(props, opts, vfxItem) {
20334
20334
  var _this = _super.call(this, props, opts, vfxItem) || this;
20335
20335
  _this.isDirty = true;
20336
+ /**
20337
+ * 文本行数
20338
+ */
20339
+ _this.lineCount = 0;
20336
20340
  var options = props.options;
20337
20341
  _this.canvas = canvasPool.getCanvas();
20338
20342
  canvasPool.saveCanvas(_this.canvas);
@@ -20341,10 +20345,34 @@ var TextItem = /** @class */ (function (_super) {
20341
20345
  _this.textStyle = new TextStyle(options);
20342
20346
  _this.textLayout = new TextLayout(options);
20343
20347
  _this.text = options.text;
20348
+ _this.lineCount = _this.getLineCount(options.text, true);
20344
20349
  // Text
20345
20350
  _this.mesh = new TextMesh(_this.engine, _this.renderInfo, vfxItem.composition);
20346
20351
  return _this;
20347
20352
  }
20353
+ TextItem.prototype.getLineCount = function (text, init) {
20354
+ var _a, _b;
20355
+ var context = this.context;
20356
+ var letterSpace = this.textLayout.letterSpace;
20357
+ var fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
20358
+ var width = (this.textLayout.width + this.textStyle.fontOffset);
20359
+ var lineCount = 1;
20360
+ var x = 0;
20361
+ for (var i = 0; i < text.length; i++) {
20362
+ var str = text[i];
20363
+ var textMetrics = ((_b = (_a = context === null || context === void 0 ? void 0 : context.measureText(str)) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 0) * fontScale;
20364
+ // 和浏览器行为保持一致
20365
+ x += letterSpace;
20366
+ if (((x + textMetrics) > width && i > 0) || str === '\n') {
20367
+ lineCount++;
20368
+ x = 0;
20369
+ }
20370
+ if (str !== '\n') {
20371
+ x += textMetrics;
20372
+ }
20373
+ }
20374
+ return lineCount;
20375
+ };
20348
20376
  /**
20349
20377
  * 设置字号大小
20350
20378
  * @param value - 字号
@@ -20394,6 +20422,7 @@ var TextItem = /** @class */ (function (_super) {
20394
20422
  return;
20395
20423
  }
20396
20424
  this.text = value;
20425
+ this.lineCount = this.getLineCount(value, false);
20397
20426
  this.isDirty = true;
20398
20427
  };
20399
20428
  /**
@@ -20565,8 +20594,7 @@ var TextItem = /** @class */ (function (_super) {
20565
20594
  context.fillStyle = "rgba(".concat(style.textColor[0], ", ").concat(style.textColor[1], ", ").concat(style.textColor[2], ", ").concat(style.textColor[3], ")");
20566
20595
  var charsInfo = [];
20567
20596
  var x = 0;
20568
- var lineCount = this.text.split('\n').length;
20569
- var y = layout.getOffsetY(style, lineCount, lineHeight);
20597
+ var y = layout.getOffsetY(style, this.lineCount, lineHeight);
20570
20598
  var charsArray = [];
20571
20599
  var charOffsetX = [];
20572
20600
  for (var i = 0; i < this.char.length; i++) {