Merge pull request #284 from treeform/fonts1

Fix selection rects align to pixel logic.
This commit is contained in:
treeform 2021-09-08 18:09:39 -07:00 committed by GitHub
commit fb232a8d4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 14 additions and 15 deletions

View file

@ -309,19 +309,6 @@ proc typeset*(
result.positions[i].x += xAdjustment
result.selectionRects[i].x += xAdjustment
block: # Nudge selection rects to pixel grid
var at = result.selectionRects[0]
at.x = round(at.x)
for rect in result.selectionRects.mitems:
if rect.y == at.y:
rect.x = at.x
rect.w = round(rect.w)
at.x = rect.x + rect.w
else:
rect.w = round(rect.w)
at.x = rect.w
at.y = rect.y
block: # Arrange the lines vertically
let initialY = block:
var maxInitialY: float32
@ -407,6 +394,18 @@ proc typeset*(
result.positions[i].y += yAdjustment
result.selectionRects[i].y += yAdjustment
block: # Nudge selection rects to pixel grid
for rect in result.selectionRects.mitems:
let
minX = round(rect.x)
maxX = round(rect.x + rect.w)
minY = round(rect.y)
maxY = round(rect.y + rect.h)
rect.x = minX
rect.w = maxX - minX
rect.y = minY
rect.h = maxY - minY
proc typeset*(
font: Font,
text: string,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8 KiB

After

Width:  |  Height:  |  Size: 8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

View file

@ -492,7 +492,7 @@ block:
ctx.font = "tests/fonts/Roboto-Regular_1.ttf"
let metrics = ctx.measureText("Hello world")
doAssert metrics.width == 61
doAssert metrics.width == 60
block:
let

View file

@ -17,7 +17,7 @@ block:
font.size = 24
let bounds = font.computeBounds("Word")
doAssert bounds == vec2(57, 28)
doAssert bounds == vec2(56, 28)
block:
var font = readFont("tests/fonts/Roboto-Regular_1.ttf")