Skip to content

Commit

Permalink
SDF: Fix word wrap on single char words
Browse files Browse the repository at this point in the history
This commit also fixes the reported width of SDF text to be more accurate.

Fixes #204
  • Loading branch information
frank-weindel committed Mar 25, 2024
1 parent 3b22fb7 commit 2366aef
Show file tree
Hide file tree
Showing 20 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/tests/text-contain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default async function test(settings: ExampleSettings) {
fontFamily: 'Ubuntu',
textRendererOverride: 'sdf',
fontSize: 20,
text: `Lorem ipsum dolor sit amet
text: `Lorem ipsum dolor sit e
Consectetur adipiscing elit. Vivamus id.
Suspendisse sollicitudin posuere felis.
Vivamus consectetur ex magna, non mollis.`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ export function layoutText(
charEndX >= lineVertexW &&
// There is a last word that we can break to the next line
lastWord.codepointIndex !== -1 &&
// We have advanced at least one character since the last word started
lastWord.codepointIndex < glyph.cluster &&
// Prevents infinite loop when a single word is longer than the width
lastWord.xStart > 0
) {
Expand Down Expand Up @@ -286,8 +284,8 @@ export function layoutText(
}

maxY = Math.max(maxY, quadY + glyph.height);
maxX = Math.max(maxX, quadX + glyph.width);
curX += glyph.xAdvance;
maxX = Math.max(maxX, curX);
}
} else {
// Unmapped character
Expand Down
Binary file modified visual-regression/certified-snapshots/chromium-ci/text-alpha-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2366aef

Please sign in to comment.