Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix text error for set text to "" and set enableWrapping to true #1634

Merged
merged 3 commits into from
Jul 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/core/src/2d/text/TextUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ export class TextUtils {
}

static measureTextWithWrap(renderer: TextRenderer): TextMetrics {
if (renderer.text === "") {
return {
width: 0,
height: 0,
lines: [""],
lineWidths: [0],
lineHeight: 0,
lineMaxSizes: [{ ascent: 0, descent: 0, size: 0 }]
};
}

const subFont = renderer._subFont;
const fontString = subFont.nativeFontString;
const fontSizeInfo = TextUtils.measureFont(fontString);
Expand Down Expand Up @@ -269,8 +280,8 @@ export class TextUtils {
for (let i = 0; i < lineCount; ++i) {
const line = lines[i];
let curWidth = 0;
let maxAscent = -1;
let maxDescent = -1;
let maxAscent = 0;
let maxDescent = 0;

for (let j = 0, m = line.length; j < m; ++j) {
const charInfo = TextUtils._getCharInfo(line[j], fontString, subFont);
Expand Down