diff --git a/src/pixie/fonts.nim b/src/pixie/fonts.nim index 538aa34..38d91f4 100644 --- a/src/pixie/fonts.nim +++ b/src/pixie/fonts.nim @@ -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, diff --git a/tests/fonts/diffs/cff_strikethrough.png b/tests/fonts/diffs/cff_strikethrough.png index a037a16..4a78403 100644 Binary files a/tests/fonts/diffs/cff_strikethrough.png and b/tests/fonts/diffs/cff_strikethrough.png differ diff --git a/tests/fonts/diffs/cff_underline.png b/tests/fonts/diffs/cff_underline.png index d77ca9e..e78a15c 100644 Binary files a/tests/fonts/diffs/cff_underline.png and b/tests/fonts/diffs/cff_underline.png differ diff --git a/tests/fonts/diffs/selection_rects1.png b/tests/fonts/diffs/selection_rects1.png index 9a2a151..65a836b 100644 Binary files a/tests/fonts/diffs/selection_rects1.png and b/tests/fonts/diffs/selection_rects1.png differ diff --git a/tests/fonts/diffs/selection_rects2.png b/tests/fonts/diffs/selection_rects2.png index ffaef24..b96503a 100644 Binary files a/tests/fonts/diffs/selection_rects2.png and b/tests/fonts/diffs/selection_rects2.png differ diff --git a/tests/fonts/diffs/selection_rects3.png b/tests/fonts/diffs/selection_rects3.png index 34e30f1..cc2fc29 100644 Binary files a/tests/fonts/diffs/selection_rects3.png and b/tests/fonts/diffs/selection_rects3.png differ diff --git a/tests/fonts/diffs/spans6.png b/tests/fonts/diffs/spans6.png index f8a226a..ad818aa 100644 Binary files a/tests/fonts/diffs/spans6.png and b/tests/fonts/diffs/spans6.png differ diff --git a/tests/fonts/diffs/strikethrough3.png b/tests/fonts/diffs/strikethrough3.png index 2fbe162..e90e3c3 100644 Binary files a/tests/fonts/diffs/strikethrough3.png and b/tests/fonts/diffs/strikethrough3.png differ diff --git a/tests/fonts/diffs/underline3.png b/tests/fonts/diffs/underline3.png index c169d93..cc5f019 100644 Binary files a/tests/fonts/diffs/underline3.png and b/tests/fonts/diffs/underline3.png differ diff --git a/tests/fonts/rendered/cff_strikethrough.png b/tests/fonts/rendered/cff_strikethrough.png index a7a380c..d4ce8ff 100644 Binary files a/tests/fonts/rendered/cff_strikethrough.png and b/tests/fonts/rendered/cff_strikethrough.png differ diff --git a/tests/fonts/rendered/cff_underline.png b/tests/fonts/rendered/cff_underline.png index a9271eb..930df43 100644 Binary files a/tests/fonts/rendered/cff_underline.png and b/tests/fonts/rendered/cff_underline.png differ diff --git a/tests/fonts/rendered/selection_rects1.png b/tests/fonts/rendered/selection_rects1.png index 44ffe5b..a8b06f6 100644 Binary files a/tests/fonts/rendered/selection_rects1.png and b/tests/fonts/rendered/selection_rects1.png differ diff --git a/tests/fonts/rendered/selection_rects2.png b/tests/fonts/rendered/selection_rects2.png index 74fc315..11354bf 100644 Binary files a/tests/fonts/rendered/selection_rects2.png and b/tests/fonts/rendered/selection_rects2.png differ diff --git a/tests/fonts/rendered/selection_rects3.png b/tests/fonts/rendered/selection_rects3.png index 06ff77e..54fdb28 100644 Binary files a/tests/fonts/rendered/selection_rects3.png and b/tests/fonts/rendered/selection_rects3.png differ diff --git a/tests/fonts/rendered/spans6.png b/tests/fonts/rendered/spans6.png index 3164950..5b81cb3 100644 Binary files a/tests/fonts/rendered/spans6.png and b/tests/fonts/rendered/spans6.png differ diff --git a/tests/fonts/rendered/strikethrough3.png b/tests/fonts/rendered/strikethrough3.png index ff6d87e..5406bf6 100644 Binary files a/tests/fonts/rendered/strikethrough3.png and b/tests/fonts/rendered/strikethrough3.png differ diff --git a/tests/fonts/rendered/underline3.png b/tests/fonts/rendered/underline3.png index f7dec25..7400ce2 100644 Binary files a/tests/fonts/rendered/underline3.png and b/tests/fonts/rendered/underline3.png differ diff --git a/tests/test_contexts.nim b/tests/test_contexts.nim index c27aa99..b60042b 100644 --- a/tests/test_contexts.nim +++ b/tests/test_contexts.nim @@ -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 diff --git a/tests/test_fonts.nim b/tests/test_fonts.nim index 03b0b46..3af378f 100644 --- a/tests/test_fonts.nim +++ b/tests/test_fonts.nim @@ -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")