Repository navigation
Java Library
Server/Java builds a Java 17 library for protocol 2.0. Its Maven coordinates are solutions.trp:json-paper:1.0.0-SNAPSHOT.
From Server/Java:
./gradlew test
./gradlew publishToMavenLocalUse gradlew.bat on Windows. Add the dependency to a consuming Gradle project:
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation 'solutions.trp:json-paper:1.0.0-SNAPSHOT'
}import solutions.trp.jsonpaper.Color;
import solutions.trp.jsonpaper.Display;
import solutions.trp.jsonpaper.TextBox;
import solutions.trp.jsonpaper.TextSpan;
Display display = new Display()
.clear(Color.WHITE)
.text(TextBox.builder(20, 20, 740, 70)
.span(TextSpan.builder("Hello, JSON Paper!")
.family("helvetica")
.size(32)
.build())
.build());
String json = display.toJson();document() returns an immutable DisplayDocument, suitable for Jackson serialization from a Spring controller. toJson() and toPrettyJson() serialize directly and enforce the 128 KiB limit. If another framework serializes document(), enforce the response limit there too. The library itself does not depend on Spring.
The committed API includes primitive drawing, pie slices, rich text, and images. It does not yet expose dedicated helpers for set_rotate, set_mirroring, or set_pixel, although the renderer supports those commands. TextBox and TextSpan builders configure text bounds and styles. Specify helvetica explicitly for device text; the committed span default is sans.
Images can come from BufferedImage or filesystem paths. SVG loading uses Apache Batik. Opaque pixels are mapped to the nearest supported palette color; alpha below 50% becomes transparent. Raster text uses server-side fonts and emits image commands.
RichTextSample.create() demonstrates styled spans, and DashboardSample.create(Path) builds a dashboard using a supplied logo. See the module README for full examples, and Draw Text for actual renderer limits.