Skip to content

Commit

Permalink
improved canvas text measurer
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Jun 7, 2023
1 parent 7ddb8ae commit 7f79c72
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions haxe/ui/backend/html5/text/TextMeasurer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,7 @@ private class CanvasTextMeasurer extends DivTextMeasurer {
}

private function normalizeText(text:String):String {
if (text == "-") {
return text;
}
return text.replace("_", " ").replace("-", " ");
return text.replace("_", " ");
}

private static function computeLinesDefault(text:String, max:Float):Array<String> {
Expand Down Expand Up @@ -270,6 +267,11 @@ private class CanvasTextMeasurer extends DivTextMeasurer {
if (line.length > 0) {
lines.push(line);
}
if (lines.length > 0) {
if (_ctx.measureText(lines[lines.length - 1]).width > max) {
lines.push("");
}
}

return lines;
}
Expand Down

0 comments on commit 7f79c72

Please sign in to comment.