Skip to content

Commit

Permalink
Update barcode extension function to add field data and origin values.
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmattking committed Jul 28, 2024
1 parent f845483 commit 96a77f9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
27 changes: 19 additions & 8 deletions src/main/kotlin/info/mking/k2zpl/command/BarCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}

32 changes: 30 additions & 2 deletions src/test/kotlin/info/mking/k2zpl/command/BarCodeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
})

0 comments on commit 96a77f9

Please sign in to comment.