@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.js +31 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -3
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/text/text-item.d.ts +5 -0
- package/package.json +1 -1
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
|
|
6
|
+
* Version: v1.6.0
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -20337,6 +20337,10 @@ var TextItem = /** @class */ (function (_super) {
|
|
|
20337
20337
|
function TextItem(props, opts, vfxItem) {
|
|
20338
20338
|
var _this = _super.call(this, props, opts, vfxItem) || this;
|
|
20339
20339
|
_this.isDirty = true;
|
|
20340
|
+
/**
|
|
20341
|
+
* 文本行数
|
|
20342
|
+
*/
|
|
20343
|
+
_this.lineCount = 0;
|
|
20340
20344
|
var options = props.options;
|
|
20341
20345
|
_this.canvas = canvasPool.getCanvas();
|
|
20342
20346
|
canvasPool.saveCanvas(_this.canvas);
|
|
@@ -20345,10 +20349,34 @@ var TextItem = /** @class */ (function (_super) {
|
|
|
20345
20349
|
_this.textStyle = new TextStyle(options);
|
|
20346
20350
|
_this.textLayout = new TextLayout(options);
|
|
20347
20351
|
_this.text = options.text;
|
|
20352
|
+
_this.lineCount = _this.getLineCount(options.text, true);
|
|
20348
20353
|
// Text
|
|
20349
20354
|
_this.mesh = new TextMesh(_this.engine, _this.renderInfo, vfxItem.composition);
|
|
20350
20355
|
return _this;
|
|
20351
20356
|
}
|
|
20357
|
+
TextItem.prototype.getLineCount = function (text, init) {
|
|
20358
|
+
var _a, _b;
|
|
20359
|
+
var context = this.context;
|
|
20360
|
+
var letterSpace = this.textLayout.letterSpace;
|
|
20361
|
+
var fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
|
|
20362
|
+
var width = (this.textLayout.width + this.textStyle.fontOffset);
|
|
20363
|
+
var lineCount = 1;
|
|
20364
|
+
var x = 0;
|
|
20365
|
+
for (var i = 0; i < text.length; i++) {
|
|
20366
|
+
var str = text[i];
|
|
20367
|
+
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;
|
|
20368
|
+
// 和浏览器行为保持一致
|
|
20369
|
+
x += letterSpace;
|
|
20370
|
+
if (((x + textMetrics) > width && i > 0) || str === '\n') {
|
|
20371
|
+
lineCount++;
|
|
20372
|
+
x = 0;
|
|
20373
|
+
}
|
|
20374
|
+
if (str !== '\n') {
|
|
20375
|
+
x += textMetrics;
|
|
20376
|
+
}
|
|
20377
|
+
}
|
|
20378
|
+
return lineCount;
|
|
20379
|
+
};
|
|
20352
20380
|
/**
|
|
20353
20381
|
* 设置字号大小
|
|
20354
20382
|
* @param value - 字号
|
|
@@ -20398,6 +20426,7 @@ var TextItem = /** @class */ (function (_super) {
|
|
|
20398
20426
|
return;
|
|
20399
20427
|
}
|
|
20400
20428
|
this.text = value;
|
|
20429
|
+
this.lineCount = this.getLineCount(value, false);
|
|
20401
20430
|
this.isDirty = true;
|
|
20402
20431
|
};
|
|
20403
20432
|
/**
|
|
@@ -20569,8 +20598,7 @@ var TextItem = /** @class */ (function (_super) {
|
|
|
20569
20598
|
context.fillStyle = "rgba(".concat(style.textColor[0], ", ").concat(style.textColor[1], ", ").concat(style.textColor[2], ", ").concat(style.textColor[3], ")");
|
|
20570
20599
|
var charsInfo = [];
|
|
20571
20600
|
var x = 0;
|
|
20572
|
-
var
|
|
20573
|
-
var y = layout.getOffsetY(style, lineCount, lineHeight);
|
|
20601
|
+
var y = layout.getOffsetY(style, this.lineCount, lineHeight);
|
|
20574
20602
|
var charsArray = [];
|
|
20575
20603
|
var charOffsetX = [];
|
|
20576
20604
|
for (var i = 0; i < this.char.length; i++) {
|