woo-j / OkapiBarcode

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

How to Change MaxiCode width an height? #101

Closed taimingkang closed 1 year ago

taimingkang commented 1 year ago

May I ask how to change the width and height of this MaxiCode 2D barcode? Or to scale it proportionally? Below is the code I use to generate MaxiCode,

 MaxiCode maxicode = new MaxiCode();
        maxicode.setMode(4);
        maxicode.setContent("Hello_wold");
        maxicode.setModuleWidth(50);
        maxicode.setBarHeight(50);
        System.out.println(maxicode.getHeight()+";"+maxicode.getWidth()+";"+maxicode.getModuleWidth()+";"+maxicode.getBarHeight());
72;74;50;50

and I've noticed that the settings for these two 'setModuleWidth' and 'setBarHeight' properties don't seem to have any effect. When I print the actual width and height of the MaxiCode object through the console, I see that they are still fixed at ' 72, 74' . Upon inspecting the MaxiCode source code, it appears that these 'symbol_height = 72;' and 'symbol_width = 74;' ,This comes from the void plotSymbol() method in MaxiCode() properties are fixed. Is this the reason why my width and height settings are not taking effect?

gredler commented 1 year ago

MaxiCode symbols are meant to be a single physical size. From the spec: "Each symbol, including the quiet zone, is of a fixed physical size, nominally 28.14mm wide x 26.91mm high." I believe the hardcoded values in plotSymbol() are the pixel dimensions matching these physical dimensions, assuming the PDF-standard 72 DPI. The various renderers (e.g. Java2DRenderer) have magnification factors available which might be helpful if you need to adjust the sizes up or down (but keep in mind the spec size restriction mentioned above or you might create a non-compliant symbol).

taimingkang commented 1 year ago

Thank you very much for your proactive and detailed response. Are you saying that maxiCode itself does not provide the functionality to modify its width or height or perform proportional scaling, and that these adjustments can only be made when generating the image?

gredler commented 1 year ago

That's correct. Per the spec it's supposed to be a fixed physical side, which is reflected in the code as a fixed pixel size (but with an option to scale during rendering).