Skip to content

0.8.0

Choose a tag to compare

@ronison ronison released this 11 Nov 18:23
· 34 commits to main since this release

What's Changed

New: inline HTML/SVG embedding (toHtml)

Every registered format (1D and 2D) can now be rendered as an SVG snippet ready to be pasted directly into a web page — no XML prologue, no generator comment, no fallback text — with a viewBox (so it scales with its container), role="img" and an aria-label:

String html = BarcodeGenerator.of("EAN13").toHtml("789100031550");
// paste directly inside <body>...</body>

String sized = BarcodeGenerator.of("CODE128").toHtml("Bars4J-128", 300, 100); // explicit px size

The drawing markup inside the snippet is byte-for-byte identical to the validated toSvg output (guarded by a parity test across all 24 formats). toSvg and the raster output are unchanged.

Fixed

  • Encoder bugs across the 1D and matrix encoders: null-text handling now throws the library's checked exceptions, EANEncoder.charToInt no longer leaks a NumberFormatException, Code 11 check-digit pairs and the Code 39 full-ASCII shift handling are corrected.
  • The orphan moveto in the width-coded SVG path (zm2 0 0h1 → zm2 0h1) is fixed.
  • &, < and > are now escaped in the human-readable SVG text (Code 128's charset allows them, which used to break the markup).

Improved

  • The RenderSpec colours are honoured end-to-end — raster, SVG and human-readable text (previously ignored for linear formats).
  • DPI metadata: PNG embeds a pHYs chunk and JPEG a JFIF density tag, so generated images carry their true physical size (GIF has no DPI support).
  • BarcodeComponent (Swing): null text is rejected, state is validated before mutation, getPreferredSize() derives from the rendered image and the last valid image is kept on failure.
  • Resource hygiene: dispose() on every Graphics2D, holder idiom across the legacy painters, a synchronized immutable BarcodeRegistry and try-with-resources in the demo.

Tests

  • 77 new tests covering the HTML snippet (structure, parity with toSvg, spec colours, escaping), encoder spec vectors (Code 11, PostNet, UPC-E, Code 39 Extended, PDF417, ECI/GBK, QR fullwidth), raster/SVG colour conformance and the Swing component — 717 unit tests + the performance integration test, all green.

Full Changelog: pr-0.7.3...pr-0.8.0