@@ -13,6 +13,9 @@ import de.tillhub.printengine.data.PrintingPaperSpec
13
13
import de.tillhub.printengine.data.RawPrinterData
14
14
import de.tillhub.printengine.barcode.BarcodeEncoder
15
15
import de.tillhub.printengine.barcode.BarcodeType
16
+ import de.tillhub.printengine.verifone.VerifoneUtils.FEED_PAPER
17
+ import de.tillhub.printengine.verifone.VerifoneUtils.generateImageHtml
18
+ import de.tillhub.printengine.verifone.VerifoneUtils.monospaceText
16
19
import de.tillhub.printengine.verifone.VerifoneUtils.singleLineCenteredText
17
20
import de.tillhub.printengine.verifone.VerifoneUtils.transformToHtml
18
21
import kotlinx.coroutines.flow.MutableStateFlow
@@ -26,7 +29,7 @@ class VerifonePrintController(
26
29
* If this field is set to false each print command is handled separately.
27
30
* If it is set to true the print commands are grouped and handled when start() is called
28
31
*/
29
- private val batchPrint : Boolean = true
32
+ private val batchPrint : Boolean = BATCH_PRINT_DEFAULT
30
33
) : PrinterController {
31
34
32
35
private val batchSB = StringBuilder ()
@@ -67,17 +70,15 @@ class VerifonePrintController(
67
70
68
71
override fun observePrinterState (): StateFlow <PrinterState > = printerState
69
72
70
- override fun setFontSize (fontSize : PrintingFontType ) {
71
- // Not supported
72
- }
73
+ override fun setFontSize (fontSize : PrintingFontType ) = Unit // Not supported
73
74
74
75
override fun printText (text : String ) {
75
76
if (batchPrint) {
76
- batchSB.append( text).append( " \n " )
77
+ batchSB.appendLine(monospaceText( text))
77
78
} else {
78
79
printManager.printString(
79
80
printListener,
80
- transformToHtml(text),
81
+ transformToHtml(monospaceText( text) ),
81
82
Printer .PRINTER_NO_CUTTER_LINE_FEED
82
83
)
83
84
}
@@ -98,16 +99,16 @@ class VerifonePrintController(
98
99
}
99
100
100
101
override fun printImage (image : Bitmap ) {
101
- if (batchPrint && batchSB.isNotEmpty()) {
102
- printBatchedString()
102
+ if (batchPrint) {
103
+ batchSB.append(generateImageHtml(image))
104
+ } else {
105
+ printManager.printBitmap(printListener, image, Printer .PRINTER_NO_CUTTER_LINE_FEED )
103
106
}
104
-
105
- printManager.printBitmap(printListener, image, Printer .PRINTER_NO_CUTTER_LINE_FEED )
106
107
}
107
108
108
109
override fun feedPaper () {
109
110
if (batchPrint) {
110
- batchSB.append(" \n\n\n " )
111
+ batchSB.append(FEED_PAPER )
111
112
} else {
112
113
printManager.printString(printListener, " " , Printer .PRINTER_NO_CUT )
113
114
}
@@ -121,20 +122,17 @@ class VerifonePrintController(
121
122
}
122
123
}
123
124
124
- override fun setIntensity (intensity : PrintingIntensity ) {
125
- // Not supported
126
- }
125
+ override fun setIntensity (intensity : PrintingIntensity ) = Unit // Not supported
127
126
128
127
override fun start () {
129
- if (batchPrint) {
130
- if (batchSB.isNotEmpty()) {
131
- printBatchedString()
132
- }
133
-
134
- if (useCutter) {
135
- printManager.printString(printListener, " " , Printer .PRINTER_FULL_CUT )
136
- }
128
+ if (batchPrint && batchSB.isNotEmpty()) {
129
+ printManager.printString(
130
+ printListener,
131
+ transformToHtml(batchSB.toString()),
132
+ if (useCutter) Printer .PRINTER_FULL_CUT else Printer .PRINTER_NO_CUTTER_LINE_FEED
133
+ )
137
134
135
+ batchSB.clear()
138
136
useCutter = false
139
137
}
140
138
}
@@ -144,25 +142,15 @@ class VerifonePrintController(
144
142
serialNumber = " n/a" ,
145
143
deviceModel = " Verifone T630c" ,
146
144
printerVersion = " n/a" ,
147
- printerPaperSpec = PrintingPaperSpec .PAX_PAPER_56MM ,
145
+ printerPaperSpec = PrintingPaperSpec .VERIFONE_PAPER_58MM ,
148
146
printingFontType = PrintingFontType .DEFAULT_FONT_SIZE ,
149
147
printerHead = " n/a" ,
150
148
printedDistance = 0 ,
151
149
serviceVersion = PrinterServiceVersion .Unknown
152
150
)
153
151
154
- private fun printBatchedString () {
155
- val payload = batchSB.toString()
156
-
157
- printManager.printString(
158
- printListener,
159
- transformToHtml(payload),
160
- Printer .PRINTER_NO_CUTTER_LINE_FEED
161
- )
162
- batchSB.clear()
163
- }
164
-
165
152
companion object {
153
+ private const val BATCH_PRINT_DEFAULT = true
166
154
private const val BARCODE_HEIGHT = 140
167
155
private const val BARCODE_WIDTH = 420
168
156
private const val QR_CODE_SIZE = 420
0 commit comments