@galacean/effects 1.6.0-beta.1 → 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/alipay.js CHANGED
@@ -20278,32 +20278,37 @@ var TextLayout = /** @class */ (function () {
20278
20278
  this.textAlign = textAlign;
20279
20279
  this.lineHeight = lineHeight;
20280
20280
  }
20281
- TextLayout.prototype.getOffsetY = function (style) {
20282
- var offsetY = 0;
20283
- var offset = (style.fontSize + style.outlineWidth) * style.fontScale;
20281
+ TextLayout.prototype.getOffsetY = function (style, lineCount, lineHeight) {
20282
+ var offsetResult = 0;
20283
+ var fontSize = style.fontSize, outlineWidth = style.outlineWidth, fontScale = style.fontScale;
20284
+ // 计算基础偏移量
20285
+ var baseOffset = (fontSize + outlineWidth) * fontScale;
20286
+ // /3 计算Y轴偏移量,以匹配编辑器行为
20287
+ var offsetY = (lineHeight - fontSize) / 3;
20288
+ var commonCalculation = lineHeight * (lineCount - 1);
20284
20289
  switch (this.textBaseline) {
20285
- case 0:
20286
- offsetY = offset;
20290
+ case TextBaseline$1.top:
20291
+ offsetResult = baseOffset + offsetY;
20287
20292
  break;
20288
- case 1:
20289
- offsetY = (this.height + offset) / 2; // fonSize;
20293
+ case TextBaseline$1.middle:
20294
+ offsetResult = (this.height * fontScale - commonCalculation + baseOffset) / 2;
20290
20295
  break;
20291
- case 2:
20292
- offsetY = this.height - offset / 2;
20296
+ case TextBaseline$1.bottom:
20297
+ offsetResult = (this.height * fontScale - commonCalculation) - offsetY;
20293
20298
  break;
20294
20299
  }
20295
- return offsetY;
20300
+ return offsetResult;
20296
20301
  };
20297
20302
  TextLayout.prototype.getOffsetX = function (style, maxWidth) {
20298
20303
  var offsetX = 0;
20299
20304
  switch (this.textAlign) {
20300
- case 0:
20305
+ case TextAlignment$1.left:
20301
20306
  offsetX = style.outlineWidth * style.fontScale;
20302
20307
  break;
20303
- case 1:
20308
+ case TextAlignment$1.middle:
20304
20309
  offsetX = (this.width * style.fontScale - maxWidth) / 2;
20305
20310
  break;
20306
- case 2:
20311
+ case TextAlignment$1.right:
20307
20312
  offsetX = (this.width * style.fontScale - maxWidth);
20308
20313
  break;
20309
20314
  }
@@ -20326,6 +20331,10 @@ var TextItem = /** @class */ (function (_super) {
20326
20331
  function TextItem(props, opts, vfxItem) {
20327
20332
  var _this = _super.call(this, props, opts, vfxItem) || this;
20328
20333
  _this.isDirty = true;
20334
+ /**
20335
+ * 文本行数
20336
+ */
20337
+ _this.lineCount = 0;
20329
20338
  var options = props.options;
20330
20339
  _this.canvas = canvasPool.getCanvas();
20331
20340
  canvasPool.saveCanvas(_this.canvas);
@@ -20334,10 +20343,34 @@ var TextItem = /** @class */ (function (_super) {
20334
20343
  _this.textStyle = new TextStyle(options);
20335
20344
  _this.textLayout = new TextLayout(options);
20336
20345
  _this.text = options.text;
20346
+ _this.lineCount = _this.getLineCount(options.text, true);
20337
20347
  // Text
20338
20348
  _this.mesh = new TextMesh(_this.engine, _this.renderInfo, vfxItem.composition);
20339
20349
  return _this;
20340
20350
  }
20351
+ TextItem.prototype.getLineCount = function (text, init) {
20352
+ var _a, _b;
20353
+ var context = this.context;
20354
+ var letterSpace = this.textLayout.letterSpace;
20355
+ var fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
20356
+ var width = (this.textLayout.width + this.textStyle.fontOffset);
20357
+ var lineCount = 1;
20358
+ var x = 0;
20359
+ for (var i = 0; i < text.length; i++) {
20360
+ var str = text[i];
20361
+ 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;
20362
+ // 和浏览器行为保持一致
20363
+ x += letterSpace;
20364
+ if (((x + textMetrics) > width && i > 0) || str === '\n') {
20365
+ lineCount++;
20366
+ x = 0;
20367
+ }
20368
+ if (str !== '\n') {
20369
+ x += textMetrics;
20370
+ }
20371
+ }
20372
+ return lineCount;
20373
+ };
20341
20374
  /**
20342
20375
  * 设置字号大小
20343
20376
  * @param value - 字号
@@ -20387,6 +20420,7 @@ var TextItem = /** @class */ (function (_super) {
20387
20420
  return;
20388
20421
  }
20389
20422
  this.text = value;
20423
+ this.lineCount = this.getLineCount(value, false);
20390
20424
  this.isDirty = true;
20391
20425
  };
20392
20426
  /**
@@ -20537,7 +20571,7 @@ var TextItem = /** @class */ (function (_super) {
20537
20571
  var fontScale = style.fontScale;
20538
20572
  var width = (layout.width + style.fontOffset) * fontScale;
20539
20573
  var height = layout.height * fontScale;
20540
- var fontSize = style.fontSize * fontScale;
20574
+ style.fontSize * fontScale;
20541
20575
  var lineHeight = layout.lineHeight * fontScale;
20542
20576
  this.char = (this.text || '').split('');
20543
20577
  this.canvas.width = width;
@@ -20557,10 +20591,8 @@ var TextItem = /** @class */ (function (_super) {
20557
20591
  // 文本颜色
20558
20592
  context.fillStyle = "rgba(".concat(style.textColor[0], ", ").concat(style.textColor[1], ", ").concat(style.textColor[2], ", ").concat(style.textColor[3], ")");
20559
20593
  var charsInfo = [];
20560
- // /3 为了和编辑器行为保持一致
20561
- var offsetY = (lineHeight - fontSize) / 3;
20562
20594
  var x = 0;
20563
- var y = layout.getOffsetY(style) + offsetY;
20595
+ var y = layout.getOffsetY(style, this.lineCount, lineHeight);
20564
20596
  var charsArray = [];
20565
20597
  var charOffsetX = [];
20566
20598
  for (var i = 0; i < this.char.length; i++) {
@@ -30992,7 +31024,7 @@ Renderer.create = function (canvas, framework, renderOptions) {
30992
31024
  Engine.create = function (gl) {
30993
31025
  return new GLEngine(gl);
30994
31026
  };
30995
- var version = "1.6.0-beta.1";
31027
+ var version = "1.6.0";
30996
31028
  logger.info('player version: ' + version);
30997
31029
 
30998
31030
  exports.AbstractPlugin = AbstractPlugin;