Skip to content

Commit 3458e47

Browse files
authored
Bugfix: support decimal magnification values by rounding up (#111)
* When we tried to magnify using decimal value such as 1.2 the barcode image is 'cut' due to width being truncated a bit. This is fixed by converting width to near integer value using Math.ceil. Also, add test case to verify the same svg * To round off height in case of decimal values being used to magnify using Math.ceil
1 parent 2c35df3 commit 3458e47

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

src/main/java/uk/org/okapibarcode/output/SvgRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public SvgRenderer(OutputStream out, double magnification, Color paper, Color in
9191
public void render(Symbol symbol) throws IOException {
9292

9393
String content = symbol.getContent();
94-
int width = (int) (symbol.getWidth() * magnification);
95-
int height = (int) (symbol.getHeight() * magnification);
94+
int width = (int) Math.ceil(symbol.getWidth() * magnification);
95+
int height = (int) Math.ceil(symbol.getHeight() * magnification);
9696
int marginX = (int) (symbol.getQuietZoneHorizontal() * magnification);
9797
int marginY = (int) (symbol.getQuietZoneVertical() * magnification);
9898

src/test/java/uk/org/okapibarcode/output/SvgRendererTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.InputStream;
2525
import java.io.StringReader;
2626
import java.nio.charset.StandardCharsets;
27+
import java.util.ArrayList;
2728
import java.util.Locale;
2829

2930
import org.junit.jupiter.api.AfterEach;
@@ -214,6 +215,13 @@ public void testEan13WithAddOn() throws IOException {
214215
test(ean, 2, Color.WHITE, Color.BLACK, "ean-13-with-add-on.svg", true);
215216
}
216217

218+
@Test
219+
public void testCode93With1dot2Magnification() throws IOException {
220+
Code93 code93 = new Code93();
221+
code93.setContent("123456789");
222+
test(code93, 1.2, Color.WHITE, Color.BLACK, "code93-with-magnification-1.2.svg", true);
223+
}
224+
217225
private void test(Symbol symbol, double magnification, Color paper, Color ink, String expectationFile, boolean xmlProlog) throws IOException {
218226

219227
ByteArrayOutputStream baos = new ByteArrayOutputStream();
5.06 KB
Loading

src/test/resources/uk/org/okapibarcode/output/code93-with-magnification-1.2.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)