Fix computeBounds with \n at the end.
This commit is contained in:
parent
bf322e1d33
commit
190eb92ef8
|
@ -427,10 +427,14 @@ proc computeBounds*(arrangement: Arrangement): Vec2 {.raises: [].} =
|
|||
if arrangement.runes.len > 0:
|
||||
for i in 0 ..< arrangement.runes.len:
|
||||
if arrangement.runes[i] != LF:
|
||||
# Don't add width of a new line rune.
|
||||
let rect = arrangement.selectionRects[i]
|
||||
result.x = max(result.x, rect.x + rect.w)
|
||||
let finalRect = arrangement.selectionRects[^1]
|
||||
result.y = finalRect.y + finalRect.h
|
||||
if arrangement.runes[^1] == LF:
|
||||
# If the text ends with a new line, we need add another line height.
|
||||
result.y += finalRect.h
|
||||
|
||||
proc computeBounds*(font: Font, text: string): Vec2 {.inline, raises: [].} =
|
||||
## Computes the width and height of the text in pixels.
|
||||
|
|
|
@ -19,6 +19,13 @@ block:
|
|||
let bounds = font.computeBounds("Word")
|
||||
doAssert bounds == vec2(56, 28)
|
||||
|
||||
block:
|
||||
var font = readFont("tests/fonts/Roboto-Regular_1.ttf")
|
||||
font.size = 24
|
||||
|
||||
let bounds = font.computeBounds("Word\n")
|
||||
doAssert bounds == vec2(56, 56)
|
||||
|
||||
block:
|
||||
var font = readFont("tests/fonts/Roboto-Regular_1.ttf")
|
||||
font.size = 64
|
||||
|
|
Loading…
Reference in a new issue