Skip to content

Commit

Permalink
New output size: QR code with quiet zone
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbl committed Oct 12, 2022
1 parent 91fea8f commit 77c820e
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,13 @@ public enum OutputSize {
* optionally for the scissors.
* </p>
*/
QR_BILL_EXTRA_SPACE
QR_BILL_EXTRA_SPACE,

/**
* QR code only with 5mm of white space on all sides (56 by 56 mm).
* <p>
* This format applies a white background (as opposed to a transparent one).
* </p>
*/
QR_CODE_WITH_QUIET_ZONE
}
25 changes: 25 additions & 0 deletions generator/src/main/java/net/codecrete/qrbill/generator/QRBill.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ public class QRBill {
*/
public static final double QR_CODE_HEIGHT = 46;

/**
* The width of the QR code with quiet zone, in mm
*
* @see OutputSize#QR_CODE_WITH_QUIET_ZONE
*/
public static final double QR_CODE_WITH_QUIET_ZONE_WIDTH = 56;

/**
* The height of the QR code with quiet zone, in mm
*
* @see OutputSize#QR_CODE_WITH_QUIET_ZONE
*/
public static final double QR_CODE_WITH_QUIET_ZONE_HEIGHT = 56;

private QRBill() {
// do not instantiate
Expand Down Expand Up @@ -208,6 +221,14 @@ private static void validateAndGenerate(Bill bill, Canvas canvas) throws IOExcep
if (bill.getFormat().getOutputSize() == OutputSize.QR_CODE_ONLY) {
QRCode qrCode = new QRCode(cleanedBill);
qrCode.draw(canvas, 0, 0);

} else if (bill.getFormat().getOutputSize() == OutputSize.QR_CODE_WITH_QUIET_ZONE) {
QRCode qrCode = new QRCode(cleanedBill);
canvas.startPath();
canvas.addRectangle(0, 0, QR_CODE_WITH_QUIET_ZONE_WIDTH, QR_CODE_WITH_QUIET_ZONE_HEIGHT);
canvas.fillPath(0xffffff, false);
qrCode.draw(canvas, 5, 5);

} else {
BillLayout layout = new BillLayout(cleanedBill, canvas);
layout.draw();
Expand Down Expand Up @@ -278,6 +299,10 @@ private static Canvas createCanvas(BillFormat format) throws IOException {
drawingWidth = QR_CODE_WIDTH;
drawingHeight = QR_CODE_HEIGHT;
break;
case QR_CODE_WITH_QUIET_ZONE:
drawingWidth = QR_CODE_WITH_QUIET_ZONE_WIDTH;
drawingHeight = QR_CODE_WITH_QUIET_ZONE_HEIGHT;
break;
case A4_PORTRAIT_SHEET:
default:
drawingWidth = A4_PORTRAIT_WIDTH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,13 @@ void qrCodeAsSVG4() {
byte[] svg = QRBill.generate(bill);
FileComparison.assertFileContentsEqual(svg, "qrcode_ex4.svg");
}

@Test
void qrCodeWithQuietZone() {
Bill bill = SampleData.getExample3();
bill.getFormat().setOutputSize(OutputSize.QR_CODE_WITH_QUIET_ZONE);
bill.getFormat().setGraphicsFormat(GraphicsFormat.SVG);
byte[] svg = QRBill.generate(bill);
FileComparison.assertFileContentsEqual(svg, "qrcode_quiet_zone.svg");
}
}
135 changes: 135 additions & 0 deletions generator/src/test/resources/qrcode_quiet_zone.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 77c820e

Please sign in to comment.