The upcoming 6.0 release of ScroogeXHTML for the Java™ platform introduces useful new features. Here is a short overview:
Embedding images with HTML Data URI scheme
The traditional MemoryPictureAdapter class in ScroogeXHTML for the Java platform generates image link elements which point to a resource location <img src=”…”>. This keeps the document small, but requires making the image resources accessible for the web browser at the given location.
In some cases however, it is useful to embed the whole image in-line in the web page as if they were external resources.
The new MemoryPictureAdapterBase64 class returns Data URIs for small JPEG and PNG images. By default, the size threshold is set to 32 kB.
scrooge = new ScroogeXHTML(); scrooge.setConvertPictures(true); PictureAdapter adapter = new MemoryPictureAdapterBase64(); scrooge.setPictureAdapter(adapter);
The new class inherits from the old MemoryPictureAdapter, and will return the inherited result for images which exceed the size limit.
Event listeners for DOM post processing
The converter internally uses a XML DOM tree to create the HTML document structure. Before converting the DOM to the result HTML5 String, the converter calls a sequence of post processing handlers, which apply optimizations and custom modifications on the DOM tree. Post processing handlers must implement the PostProcessListener interface.
The converter stores the event handlers in its PostProcessListeners property which is a list of PostProcessListener implementations. By default, the converter library creates and assigns post process handlers to perform these tasks
- strip empty (whitespace-only) text nodes
- strip empty span nodes
- strip attribute-less span nodes
- replace empty paragraph (<p>) nodes with <br> nodes
Application code may create and add more post process listeners as needed.
The new demo page https://www.scroogexhtml.com/sxd6snap/ allows to upload and convert RTF files.