woo-j / OkapiBarcode

Open-source barcode encoding program written in Java
http://www.okapibarcode.org.uk
Apache License 2.0
327 stars 97 forks source link

Rendering flag for XML header inclusion #66

Closed tzieleniewski closed 4 years ago

tzieleniewski commented 5 years ago

Hi,

I would be gr8 to add a feature to allow to indicate if symbol rendering should include XML declaration at the beginning of the output.

This could be done on the SymbolRenderer API/contract level by the addition of a new method or extension of the existing one with boolean flag parameter for this, i.e.

public interface SymbolRenderer {

    /**
     * Renders the specified symbology. This is equivalent to calling render(symbol, true).
     *
     * @param symbol the symbology to render
     * @throws IOException if there is an I/O error
     */
    void render(Symbol symbol) throws IOException;

    /**
     * Renders the specified symbology.
     *
     * @param symbol the symbology to render
     * @param xmlDeclaration the XML declaration flag
     * @throws IOException if there is an I/O error
     */
    void render(Symbol symbol, boolean xmlDeclaration) throws IOException;
}

Alternatively the SvgRenderer class could have a new constructor parameter for the XML declaration flag. Flag field would be analyzed and taken into account during rendering.

Any thoughts? ideas?

All the best TKZ

gredler commented 5 years ago

Can you provide some detail about your use case and why you need this feature? Also would be great if you could point to equivalent features in other barcode generator libraries (e.g. barcode4j). My main worry is that this feature may not be useful to other users, and I want to make sure that we aren't adding too many super-niche features.

tzieleniewski commented 5 years ago

Our case seems to be a quite common one. We are generating barcodes (svg elements) within XHTML documents. XHTML as XML document can contain only one XML declaration in the document prolog. It would be a useful feature to be capable to generate barcode without XML declaration.

We are only using OkapiBarcode, we don't have any comparison to alternative libraries.

gredler commented 5 years ago

Can you create a pull request? Please don't change the SymbolRenderer interface, since none of the other implementations care about this parameter. An additional SvgRenderer constructor parameter will do. Please also include a test (see SvgRendererTest).

Note: I assume this is about omitting the entire XML prolog (XML declaration + doctype), correct?