From 40b96a766252e7fd685cdf03781b4f8def063a8a Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 21 May 2020 08:27:21 +0100 Subject: [PATCH] WIP - failing tests for box fitting multiple boxes --- .../java/net/kemitix/text/fit/BoxFitter.java | 7 +++++ .../net/kemitix/text/fit/BoxFitterImpl.java | 10 +++++++ .../net/kemitix/text/fit/BoxFitterTest.java | 27 +++++++++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kemitix/text/fit/BoxFitter.java b/src/main/java/net/kemitix/text/fit/BoxFitter.java index d719608..3d68ba0 100644 --- a/src/main/java/net/kemitix/text/fit/BoxFitter.java +++ b/src/main/java/net/kemitix/text/fit/BoxFitter.java @@ -2,6 +2,7 @@ package net.kemitix.text.fit; import java.awt.*; import java.awt.geom.Rectangle2D; +import java.util.List; import java.util.function.Function; public interface BoxFitter { @@ -11,4 +12,10 @@ public interface BoxFitter { Graphics2D graphics2D, Rectangle2D box ); + int fit( + String text, + Function fontFactory, + Graphics2D graphics2D, + List box + ); } diff --git a/src/main/java/net/kemitix/text/fit/BoxFitterImpl.java b/src/main/java/net/kemitix/text/fit/BoxFitterImpl.java index e9b540a..9234e1f 100644 --- a/src/main/java/net/kemitix/text/fit/BoxFitterImpl.java +++ b/src/main/java/net/kemitix/text/fit/BoxFitterImpl.java @@ -33,6 +33,16 @@ class BoxFitterImpl implements BoxFitter { return fit; } + @Override + public int fit( + String text, + Function fontFactory, + Graphics2D graphics2D, + List box + ) { + return fit(text, fontFactory, graphics2D, box.get(0)); + } + private Integer fitMinMax( int min, int max, diff --git a/src/test/java/net/kemitix/text/fit/BoxFitterTest.java b/src/test/java/net/kemitix/text/fit/BoxFitterTest.java index 1379629..f90994f 100644 --- a/src/test/java/net/kemitix/text/fit/BoxFitterTest.java +++ b/src/test/java/net/kemitix/text/fit/BoxFitterTest.java @@ -12,9 +12,9 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; -import java.util.Collections; +import java.util.Arrays; +import java.util.List; import java.util.Map; -import java.util.function.BiConsumer; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -101,6 +101,29 @@ public class BoxFitterTest } } + @Nested + @DisplayName("Overflow boxes") + public class OverflowBoxes { + + private final int imageSize = 300; + private final Graphics2D graphics2D = graphics(imageSize, imageSize); + private Rectangle2D box = new Rectangle(imageSize, imageSize); + private List boxes = Arrays.asList(box, box); + + private int invoke(String longText) { + return boxFitter.fit(longText, fontFactory, graphics2D, boxes); + } + + @Test + @DisplayName("Text too long to fit single box - fits into two") + public void tooLongThrows() { + String longText = longStringGenerator(197); + int result = invoke(longText); + assertThat(result).isGreaterThan(3); + } + + } + private String longStringGenerator(int cycles) { String text = "This is a long piece of text that should result in an " + "attempt to render it at a font size on less than 2.";