Merge pull request #284 from treeform/fonts1
Fix selection rects align to pixel logic.
|
@ -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,
|
||||
|
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 8 KiB After Width: | Height: | Size: 8 KiB |
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 7.8 KiB |
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|