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

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.js 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.1
7
7
  */
8
8
 
9
9
  'use strict';
@@ -20284,13 +20284,21 @@ var TextLayout = /** @class */ (function () {
20284
20284
  this.textAlign = textAlign;
20285
20285
  this.lineHeight = lineHeight;
20286
20286
  }
20287
- TextLayout.prototype.getOffsetY = function (style, lineCount, lineHeight) {
20287
+ /**
20288
+ * 获取初始的行高偏移值
20289
+ * @param style - 字体基础数据
20290
+ * @param lineCount - 渲染行数
20291
+ * @param lineHeight - 渲染时的字体行高
20292
+ * @param fontSize - 渲染时的字体大小
20293
+ * @returns - 行高偏移值
20294
+ */
20295
+ TextLayout.prototype.getOffsetY = function (style, lineCount, lineHeight, fontSize) {
20288
20296
  var offsetResult = 0;
20289
- var fontSize = style.fontSize, outlineWidth = style.outlineWidth, fontScale = style.fontScale;
20290
- // 计算基础偏移量
20291
- var baseOffset = (fontSize + outlineWidth) * fontScale;
20297
+ var outlineWidth = style.outlineWidth, fontScale = style.fontScale;
20292
20298
  // /3 计算Y轴偏移量,以匹配编辑器行为
20293
20299
  var offsetY = (lineHeight - fontSize) / 3;
20300
+ // 计算基础偏移量
20301
+ var baseOffset = fontSize + outlineWidth * fontScale;
20294
20302
  var commonCalculation = lineHeight * (lineCount - 1);
20295
20303
  switch (this.textBaseline) {
20296
20304
  case TextBaseline$1.top:
@@ -20337,6 +20345,10 @@ var TextItem = /** @class */ (function (_super) {
20337
20345
  function TextItem(props, opts, vfxItem) {
20338
20346
  var _this = _super.call(this, props, opts, vfxItem) || this;
20339
20347
  _this.isDirty = true;
20348
+ /**
20349
+ * 文本行数
20350
+ */
20351
+ _this.lineCount = 0;
20340
20352
  var options = props.options;
20341
20353
  _this.canvas = canvasPool.getCanvas();
20342
20354
  canvasPool.saveCanvas(_this.canvas);
@@ -20345,10 +20357,34 @@ var TextItem = /** @class */ (function (_super) {
20345
20357
  _this.textStyle = new TextStyle(options);
20346
20358
  _this.textLayout = new TextLayout(options);
20347
20359
  _this.text = options.text;
20360
+ _this.lineCount = _this.getLineCount(options.text, true);
20348
20361
  // Text
20349
20362
  _this.mesh = new TextMesh(_this.engine, _this.renderInfo, vfxItem.composition);
20350
20363
  return _this;
20351
20364
  }
20365
+ TextItem.prototype.getLineCount = function (text, init) {
20366
+ var _a, _b;
20367
+ var context = this.context;
20368
+ var letterSpace = this.textLayout.letterSpace;
20369
+ var fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
20370
+ var width = (this.textLayout.width + this.textStyle.fontOffset);
20371
+ var lineCount = 1;
20372
+ var x = 0;
20373
+ for (var i = 0; i < text.length; i++) {
20374
+ var str = text[i];
20375
+ 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;
20376
+ // 和浏览器行为保持一致
20377
+ x += letterSpace;
20378
+ if (((x + textMetrics) > width && i > 0) || str === '\n') {
20379
+ lineCount++;
20380
+ x = 0;
20381
+ }
20382
+ if (str !== '\n') {
20383
+ x += textMetrics;
20384
+ }
20385
+ }
20386
+ return lineCount;
20387
+ };
20352
20388
  /**
20353
20389
  * 设置字号大小
20354
20390
  * @param value - 字号
@@ -20398,6 +20434,7 @@ var TextItem = /** @class */ (function (_super) {
20398
20434
  return;
20399
20435
  }
20400
20436
  this.text = value;
20437
+ this.lineCount = this.getLineCount(value, false);
20401
20438
  this.isDirty = true;
20402
20439
  };
20403
20440
  /**
@@ -20548,7 +20585,7 @@ var TextItem = /** @class */ (function (_super) {
20548
20585
  var fontScale = style.fontScale;
20549
20586
  var width = (layout.width + style.fontOffset) * fontScale;
20550
20587
  var height = layout.height * fontScale;
20551
- style.fontSize * fontScale;
20588
+ var fontSize = style.fontSize * fontScale;
20552
20589
  var lineHeight = layout.lineHeight * fontScale;
20553
20590
  this.char = (this.text || '').split('');
20554
20591
  this.canvas.width = width;
@@ -20569,8 +20606,7 @@ var TextItem = /** @class */ (function (_super) {
20569
20606
  context.fillStyle = "rgba(".concat(style.textColor[0], ", ").concat(style.textColor[1], ", ").concat(style.textColor[2], ", ").concat(style.textColor[3], ")");
20570
20607
  var charsInfo = [];
20571
20608
  var x = 0;
20572
- var lineCount = this.text.split('\n').length;
20573
- var y = layout.getOffsetY(style, lineCount, lineHeight);
20609
+ var y = layout.getOffsetY(style, this.lineCount, lineHeight, fontSize);
20574
20610
  var charsArray = [];
20575
20611
  var charOffsetX = [];
20576
20612
  for (var i = 0; i < this.char.length; i++) {