@galacean/effects 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/alipay.js CHANGED
@@ -20278,13 +20278,21 @@ var TextLayout = /** @class */ (function () {
20278
20278
  this.textAlign = textAlign;
20279
20279
  this.lineHeight = lineHeight;
20280
20280
  }
20281
- TextLayout.prototype.getOffsetY = function (style, lineCount, lineHeight) {
20281
+ /**
20282
+ * 获取初始的行高偏移值
20283
+ * @param style - 字体基础数据
20284
+ * @param lineCount - 渲染行数
20285
+ * @param lineHeight - 渲染时的字体行高
20286
+ * @param fontSize - 渲染时的字体大小
20287
+ * @returns - 行高偏移值
20288
+ */
20289
+ TextLayout.prototype.getOffsetY = function (style, lineCount, lineHeight, fontSize) {
20282
20290
  var offsetResult = 0;
20283
- var fontSize = style.fontSize, outlineWidth = style.outlineWidth, fontScale = style.fontScale;
20284
- // 计算基础偏移量
20285
- var baseOffset = (fontSize + outlineWidth) * fontScale;
20291
+ var outlineWidth = style.outlineWidth, fontScale = style.fontScale;
20286
20292
  // /3 计算Y轴偏移量,以匹配编辑器行为
20287
20293
  var offsetY = (lineHeight - fontSize) / 3;
20294
+ // 计算基础偏移量
20295
+ var baseOffset = fontSize + outlineWidth * fontScale;
20288
20296
  var commonCalculation = lineHeight * (lineCount - 1);
20289
20297
  switch (this.textBaseline) {
20290
20298
  case TextBaseline$1.top:
@@ -20331,6 +20339,10 @@ var TextItem = /** @class */ (function (_super) {
20331
20339
  function TextItem(props, opts, vfxItem) {
20332
20340
  var _this = _super.call(this, props, opts, vfxItem) || this;
20333
20341
  _this.isDirty = true;
20342
+ /**
20343
+ * 文本行数
20344
+ */
20345
+ _this.lineCount = 0;
20334
20346
  var options = props.options;
20335
20347
  _this.canvas = canvasPool.getCanvas();
20336
20348
  canvasPool.saveCanvas(_this.canvas);
@@ -20339,10 +20351,34 @@ var TextItem = /** @class */ (function (_super) {
20339
20351
  _this.textStyle = new TextStyle(options);
20340
20352
  _this.textLayout = new TextLayout(options);
20341
20353
  _this.text = options.text;
20354
+ _this.lineCount = _this.getLineCount(options.text, true);
20342
20355
  // Text
20343
20356
  _this.mesh = new TextMesh(_this.engine, _this.renderInfo, vfxItem.composition);
20344
20357
  return _this;
20345
20358
  }
20359
+ TextItem.prototype.getLineCount = function (text, init) {
20360
+ var _a, _b;
20361
+ var context = this.context;
20362
+ var letterSpace = this.textLayout.letterSpace;
20363
+ var fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
20364
+ var width = (this.textLayout.width + this.textStyle.fontOffset);
20365
+ var lineCount = 1;
20366
+ var x = 0;
20367
+ for (var i = 0; i < text.length; i++) {
20368
+ var str = text[i];
20369
+ 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;
20370
+ // 和浏览器行为保持一致
20371
+ x += letterSpace;
20372
+ if (((x + textMetrics) > width && i > 0) || str === '\n') {
20373
+ lineCount++;
20374
+ x = 0;
20375
+ }
20376
+ if (str !== '\n') {
20377
+ x += textMetrics;
20378
+ }
20379
+ }
20380
+ return lineCount;
20381
+ };
20346
20382
  /**
20347
20383
  * 设置字号大小
20348
20384
  * @param value - 字号
@@ -20392,6 +20428,7 @@ var TextItem = /** @class */ (function (_super) {
20392
20428
  return;
20393
20429
  }
20394
20430
  this.text = value;
20431
+ this.lineCount = this.getLineCount(value, false);
20395
20432
  this.isDirty = true;
20396
20433
  };
20397
20434
  /**
@@ -20542,7 +20579,7 @@ var TextItem = /** @class */ (function (_super) {
20542
20579
  var fontScale = style.fontScale;
20543
20580
  var width = (layout.width + style.fontOffset) * fontScale;
20544
20581
  var height = layout.height * fontScale;
20545
- style.fontSize * fontScale;
20582
+ var fontSize = style.fontSize * fontScale;
20546
20583
  var lineHeight = layout.lineHeight * fontScale;
20547
20584
  this.char = (this.text || '').split('');
20548
20585
  this.canvas.width = width;
@@ -20563,8 +20600,7 @@ var TextItem = /** @class */ (function (_super) {
20563
20600
  context.fillStyle = "rgba(".concat(style.textColor[0], ", ").concat(style.textColor[1], ", ").concat(style.textColor[2], ", ").concat(style.textColor[3], ")");
20564
20601
  var charsInfo = [];
20565
20602
  var x = 0;
20566
- var lineCount = this.text.split('\n').length;
20567
- var y = layout.getOffsetY(style, lineCount, lineHeight);
20603
+ var y = layout.getOffsetY(style, this.lineCount, lineHeight, fontSize);
20568
20604
  var charsArray = [];
20569
20605
  var charOffsetX = [];
20570
20606
  for (var i = 0; i < this.char.length; i++) {
@@ -30996,7 +31032,7 @@ Renderer.create = function (canvas, framework, renderOptions) {
30996
31032
  Engine.create = function (gl) {
30997
31033
  return new GLEngine(gl);
30998
31034
  };
30999
- var version = "1.6.0-beta.2";
31035
+ var version = "1.6.1";
31000
31036
  logger.info('player version: ' + version);
31001
31037
 
31002
31038
  exports.AbstractPlugin = AbstractPlugin;