diff --git a/README.md b/README.md index a7bdcdd..b36482a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,61 @@ # text-wrap-fit-box -Word wrap text to fit a Graphics2D rectangle with options to find the optimum font size and/or overflow into additional rectangles + +![Sonatype Nexus (Release)](https://img.shields.io/nexus/r/https/oss.sonatype.org/net.kemitix/text-wrap-fit-box.svg?style=for-the-badge) +![Maven Central](https://img.shields.io/maven-central/v/net.kemitix/text-wrap-fit-box.svg?style=for-the-badge) + +Word wrap text to fit a Graphics2D rectangle with options to find the optimum +font size and/or overflow into additional rectangles. + +```xml + + net.kemitix + text-wrap-fit-box + ${text-wrap-fit-box.version} + +``` + +## Usage + +### Word Wrap + +Splits the input `String` into a `List` of `String`s that fits within the +`imageWidth` when drawn using the `font` onto the `graphics2D`. + +```java +import net.kemitix.fit.TextFit; +import net.kemitix.fit.WordWrapper; + +Font font = ... +Graphics2D graphics2D = ... +int imageWidth = ... + +String inputString = .... + +WordWrapper wrapper = TextFit.wrapper(); +List lines = wrapper.wrap(inputString, font, graphics2D, imageWidth); +``` + +### Box Fit + +Finds the optimum `fontSize` to fill the `box` with the `inputString` when drawn +using the `graphics2D`. + +```java +import net.kemitix.fit.TextFit; +import net.kemitix.fit.BoxFitter; + +Function fontFactory = size -> .... +Graphics2D graphics2D = ... +Rectangle2D box = new Rectangle(....); + +String inputString = .... + +BoxFitter fitter = TextFit.fitter(); +int fontSize = fitter.fit(inputString, fontFactory, graphics2D, box); + +Font font = fontFactory.apply(fontSize); +int imageWidth = (int) box.getWidth(); + +WordWrapper wrapper = TextFit.wrapper(); +List lines = wrapper.wrap(inputString, font, graphics2D, imageWidth); +```