From 08f209f902f5c0f06a2d0e1c82ff44373cfe9321 Mon Sep 17 00:00:00 2001 From: Timon Date: Mon, 14 Aug 2023 22:33:27 +0200 Subject: [PATCH 1/2] fix: Lines in textlog were sometimes cut off due to a rounding error --- CHANGELOG.md | 1 + .../src/main/java/nl/weeaboo/vn/impl/text/TextRenderer.java | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c57b9e20..1062e98b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Attempting to `quickLoad` a save slot which doesn't exist now logs a warning instead of throwing an exception. - fix: Initial window size limits are now properly applied when the window is (almost) larger than the screen. - fix: The default choice screen displays previously selected choices in a different color. If you saved at a choice, the colors wouldn't update when loading. +- fix: Parts of lines would sometimes be cut off or missing from the text log due to a rounding error. # v4.9.6 - fix: File permissions were broken for Linux/Mac builds when building on a file system which doesn't support permissions (e.g. NTFS on Windows) diff --git a/core/src/main/java/nl/weeaboo/vn/impl/text/TextRenderer.java b/core/src/main/java/nl/weeaboo/vn/impl/text/TextRenderer.java index bdfbfd5d..b5096adf 100644 --- a/core/src/main/java/nl/weeaboo/vn/impl/text/TextRenderer.java +++ b/core/src/main/java/nl/weeaboo/vn/impl/text/TextRenderer.java @@ -167,11 +167,11 @@ public void setMaxSize(double w, double h) { } private int getLayoutMaxWidth() { - return (int)Math.floor(getMaxWidth()); + return (int)Math.round(getMaxWidth()); } private int getLayoutMaxHeight() { - return (int)Math.floor(getMaxHeight()); + return (int)Math.round(getMaxHeight()); } @Override @@ -341,7 +341,7 @@ public void setRightToLeft(boolean rtl) { @Override public void setSize(double w, double h) { - setMaxSize((int)Math.floor(w), (int)Math.floor(h)); + setMaxSize((int)Math.ceil(w), (int)Math.ceil(h)); super.setSize(w, h); } From 8cf9883dda9efbd3a2902c3b3ad473107e6211c2 Mon Sep 17 00:00:00 2001 From: Timon Date: Sat, 9 Sep 2023 10:26:40 +0200 Subject: [PATCH 2/2] Add unit test for maxSize change --- .../weeaboo/vn/impl/text/TextRendererTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/src/test/java/nl/weeaboo/vn/impl/text/TextRendererTest.java b/core/src/test/java/nl/weeaboo/vn/impl/text/TextRendererTest.java index c39af56a..1be350ac 100644 --- a/core/src/test/java/nl/weeaboo/vn/impl/text/TextRendererTest.java +++ b/core/src/test/java/nl/weeaboo/vn/impl/text/TextRendererTest.java @@ -12,6 +12,7 @@ import nl.weeaboo.test.RectAssert; import nl.weeaboo.vn.core.VerticalAlign; import nl.weeaboo.vn.impl.core.StaticEnvironment; +import nl.weeaboo.vn.layout.ILayoutElem; public class TextRendererTest { @@ -132,6 +133,17 @@ public void testLineBounds() { assertLineBounds(0, Rect2D.EMPTY); } + /** + * Calculation of max width/height for {@link ILayoutElem} purposes. + */ + @Test + public void testMaxWidth() { + textRenderer.setText("one\ntwo\nthree"); + textRenderer.setSize(63.999, 12.34); + + assertMaxSize(64.0, 13.0); + } + private void assertLineBounds(int lineIndex, Rect2D expectedBounds) { Rect2D actualBounds = textRenderer.getLineBounds(lineIndex); RectAssert.assertEquals(expectedBounds, actualBounds, 0.0); @@ -154,4 +166,9 @@ private void assertFinalLineFullyVisible(boolean expected) { Assert.assertEquals(expected, textRenderer.isFinalLineFullyVisible()); } + private void assertMaxSize(double expectedW, double expectedH) { + Assert.assertEquals(expectedW, textRenderer.getMaxWidth(), 0.0); + Assert.assertEquals(expectedH, textRenderer.getMaxHeight(), 0.0); + } + }