-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [#14] Update barcode helper Breaks out `BarCode` into abstract class and creates `BarCode39` and `BarCode128`. Further bar code definitions should use `BarCode` as the base class. * [#14] Update barcode helper PR feedback: - Make `BarCode` an `interface` - Use `table` entries for tests - Doc consistency fixes
- Loading branch information
1 parent
c659615
commit 686f45a
Showing
12 changed files
with
288 additions
and
72 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/sainsburys/k2zpl/command/barcode/BarCode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.sainsburys.k2zpl.command.barcode | ||
|
||
import com.sainsburys.k2zpl.command.ZplCommand | ||
import com.sainsburys.k2zpl.command.options.ZplFieldOrientation | ||
|
||
internal interface BarCode : ZplCommand { | ||
val orientation: ZplFieldOrientation | ||
val height: Int | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/kotlin/com/sainsburys/k2zpl/command/barcode/BarCode128.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.sainsburys.k2zpl.command.barcode | ||
|
||
import com.sainsburys.k2zpl.builder.ZplBuilder | ||
import com.sainsburys.k2zpl.builder.toZplYesNo | ||
import com.sainsburys.k2zpl.command.ZplParameters | ||
import com.sainsburys.k2zpl.command.fieldData | ||
import com.sainsburys.k2zpl.command.fieldOrigin | ||
import com.sainsburys.k2zpl.command.fieldSeparator | ||
import com.sainsburys.k2zpl.command.options.ZplBarCode128Mode | ||
import com.sainsburys.k2zpl.command.options.ZplFieldOrientation | ||
import com.sainsburys.k2zpl.command.options.ZplYesNo | ||
import com.sainsburys.k2zpl.command.zplParameters | ||
|
||
internal data class BarCode128( | ||
override val orientation: ZplFieldOrientation, | ||
override val height: Int, | ||
val line: ZplYesNo, | ||
val lineAbove: ZplYesNo, | ||
val checkDigit: ZplYesNo, | ||
val mode: ZplBarCode128Mode | ||
) : BarCode { | ||
|
||
init { | ||
require(height in 1..32000) { "Height must be between 1 and 32000" } | ||
} | ||
|
||
override val command = "^BC" | ||
|
||
override val parameters: ZplParameters = zplParameters( | ||
"o" to orientation.code, | ||
"h" to height, | ||
"l" to line, | ||
"la" to lineAbove.toString(), | ||
"c" to checkDigit.toString(), | ||
"m" to mode.toString() | ||
) | ||
} | ||
|
||
/** | ||
* Creates a Code 128 barcode marker | ||
* @param data data encoded in the barcode | ||
* @param x horizontal position | ||
* @param y vertical position | ||
* @param orientation The orientation of the barcode | ||
* @param height the height of the barcode | ||
* @param interpretationLine print interpretation line | ||
* @param lineAbove print interpretation line above code | ||
* @param checkDigit whether to include a UCC check digit | ||
* @param mode barcode mode | ||
*/ | ||
fun ZplBuilder.barcode128( | ||
data: String, | ||
x: Int, | ||
y: Int, | ||
height: Int, | ||
orientation: ZplFieldOrientation = ZplFieldOrientation.NORMAL, | ||
interpretationLine: Boolean = false, | ||
lineAbove: Boolean = false, | ||
checkDigit: Boolean = false, | ||
mode: ZplBarCode128Mode = ZplBarCode128Mode.NONE | ||
) { | ||
fieldOrigin(x, y) | ||
command( | ||
BarCode128( | ||
orientation = orientation, | ||
height = height, | ||
line = interpretationLine.toZplYesNo(), | ||
lineAbove = lineAbove.toZplYesNo(), | ||
checkDigit = checkDigit.toZplYesNo(), | ||
mode = mode | ||
) | ||
) | ||
fieldData(data) | ||
fieldSeparator() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/com/sainsburys/k2zpl/command/options/ZplBarCode128Mode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.sainsburys.k2zpl.command.options | ||
|
||
enum class ZplBarCode128Mode(val value: String) { | ||
NONE("N"), | ||
UCC("U"), | ||
AUTOMATIC("A"), | ||
UCC_EAN("D"); | ||
|
||
override fun toString(): String { | ||
return value | ||
} | ||
} |
7 changes: 0 additions & 7 deletions
7
src/main/kotlin/com/sainsburys/k2zpl/command/options/ZplBarcodeType.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
package com.sainsburys.k2zpl | ||
|
||
import com.sainsburys.k2zpl.command.ZplCommand | ||
import io.kotest.data.row | ||
import kotlin.enums.EnumEntries | ||
|
||
fun ZplCommand.testBuildString() = buildString { build(this) } | ||
|
||
inline fun <reified T : Enum<T>> EnumEntries<T>.toRows() = map(::row) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.