diff --git a/src/main/kotlin/info/mking/k2zpl/command/BarCode.kt b/src/main/kotlin/info/mking/k2zpl/command/BarCode.kt index 4f7ed01..65497c8 100644 --- a/src/main/kotlin/info/mking/k2zpl/command/BarCode.kt +++ b/src/main/kotlin/info/mking/k2zpl/command/BarCode.kt @@ -2,6 +2,9 @@ package info.mking.k2zpl.command import info.mking.k2zpl.builder.ZplBuilder import info.mking.k2zpl.builder.command +import info.mking.k2zpl.builder.fieldData +import info.mking.k2zpl.builder.fieldOrigin +import info.mking.k2zpl.builder.fieldSeparator import info.mking.k2zpl.builder.toZplYesNo import info.mking.k2zpl.command.options.ZplBarcodeType import info.mking.k2zpl.command.options.ZplFieldOrientation @@ -31,31 +34,39 @@ internal data class BarCode( } /** - * Creates a Code 39 barcode. + * Creates a Code 39 barcode marker + * @param data data encoded in the barcode + * @param x horizontal position + * @param y vertical position * @param barcodeType Barcode type * @param orientation The orientation of the barcode. * @param checkDigit Whether to include a check digit. * @param height The height of the barcode. - * @param line The line thickness of the barcode. + * @param lineThickness The line thickness of the barcode. * @param lineAbove Whether to include a line above the barcode. */ fun ZplBuilder.barcode( + data: String, + x: Int, + y: Int, + height: Int, + lineThickness: Int, barcodeType: ZplBarcodeType = ZplBarcodeType.CODE_39, orientation: ZplFieldOrientation = ZplFieldOrientation.NORMAL, - checkDigit: Boolean, - height: Int, - line: Int, - lineAbove: Boolean + checkDigit: Boolean = false, + lineAbove: Boolean = false ) { + fieldOrigin(x, y) command( BarCode( type = barcodeType, orientation = orientation, checkDigit = checkDigit.toZplYesNo(), height = height, - line = line, + line = lineThickness, lineAbove = lineAbove.toZplYesNo() ) ) + fieldData(data) + fieldSeparator() } - diff --git a/src/test/kotlin/info/mking/k2zpl/command/BarCodeTest.kt b/src/test/kotlin/info/mking/k2zpl/command/BarCodeTest.kt index 22607d8..086cb04 100644 --- a/src/test/kotlin/info/mking/k2zpl/command/BarCodeTest.kt +++ b/src/test/kotlin/info/mking/k2zpl/command/BarCodeTest.kt @@ -68,9 +68,37 @@ class BarCodeTest : DescribeSpec({ describe("barcode extension") { it("outputs the correct command") { val result = k2zpl { - barcode(checkDigit = false, height = 10, line = 7, lineAbove = true) + barcode( + data = "1234567890", + x = 10, + y = 10, + height = 10, + lineThickness = 7, + barcodeType = ZplBarcodeType.CODE_39, + orientation = ZplFieldOrientation.NORMAL, + checkDigit = false, + lineAbove = true + ) } - result shouldBe "^B1N,N,10,7,Y\n" + result shouldBe """ + ^FO10,10 + ^B1N,N,10,7,Y + ^FD1234567890 + ^FS + + """.trimIndent() + } + it("uses default values") { + val result = k2zpl { + barcode(data = "1234567890", x = 10, y = 10, height = 10, lineThickness = 7) + } + result shouldBe """ + ^FO10,10 + ^B1N,N,10,7,N + ^FD1234567890 + ^FS + + """.trimIndent() } } })