|
@@ -10,6 +10,8 @@ import com.snbc.sdk.LabelPrinter;
|
10
|
10
|
|
11
|
11
|
import java.io.ByteArrayOutputStream;
|
12
|
12
|
import java.nio.ByteBuffer;
|
|
13
|
+import java.util.ArrayList;
|
|
14
|
+import java.util.List;
|
13
|
15
|
|
14
|
16
|
import io.flutter.plugin.common.MethodChannel;
|
15
|
17
|
|
|
@@ -73,13 +75,130 @@ public class BTPPrintUtil {
|
73
|
75
|
result.success(code == 0 ? true : false);
|
74
|
76
|
}
|
75
|
77
|
|
76
|
|
- public static void printBarCodeWithText(String barCode, String text, @NonNull MethodChannel.Result result) {
|
|
78
|
+ public static void printText(ArrayList<String> textList,@NonNull MethodChannel.Result result) {
|
|
79
|
+
|
|
80
|
+ int width = 560;
|
|
81
|
+ int height = 640;
|
|
82
|
+ getInstance().SetLabelSize(width,height);
|
|
83
|
+
|
|
84
|
+ int marginX = 2;
|
|
85
|
+ int marginY = 40;
|
|
86
|
+ //矩形框类型
|
|
87
|
+ int rectangleWidth = width - marginX * 2;
|
|
88
|
+ int rectangleHeight = height - marginY * 2;
|
|
89
|
+ int lineWidth = 1;
|
|
90
|
+
|
|
91
|
+ int lineHeight = rectangleHeight / 6;
|
|
92
|
+
|
|
93
|
+ int titleWidth = rectangleWidth / 2;
|
|
94
|
+
|
|
95
|
+ float fontSize = 3;
|
|
96
|
+ // 设置初始偏移量
|
|
97
|
+ int offsetY = 0;
|
|
98
|
+ int offsetX = 0;
|
|
99
|
+ // 计算绘制线条的 y 坐标
|
|
100
|
+ int secondLineY = marginY + lineHeight * 2 - lineWidth + offsetY;
|
|
101
|
+ int thirdLineY = marginY + lineHeight * 3 - lineWidth + offsetY;
|
|
102
|
+ int fourthLineY = marginY + lineHeight * 4 - lineWidth + offsetY;
|
|
103
|
+ int fiveLineY = marginY + lineHeight * 5 - lineWidth + offsetY;
|
|
104
|
+
|
|
105
|
+ int textAlignHorizontal = 0; // 左对齐
|
|
106
|
+
|
|
107
|
+ labelPrinter.PrintText(marginX * 2 + offsetX, marginY + offsetY, "3", textList.get(0), 0, 7, 0, 0);
|
|
108
|
+ labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, marginY + offsetY, "3", textList.get(1), 0, 7, 0, 0);
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+ labelPrinter.PrintText(marginX * 2 + offsetX, marginY + lineHeight - lineWidth + offsetY, "3", textList.get(2), 0, 7, 0, 0);
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+ labelPrinter.PrintText(marginX * 2 + offsetX, secondLineY, "3", textList.get(3), 0, 7, 0, 0);
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+ labelPrinter.PrintText(marginX * 2 + offsetX, thirdLineY, "3", textList.get(4), 0, 7, 0, 0);
|
|
118
|
+ labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, thirdLineY, "3", textList.get(5), 0, 7, 0, 0);
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+ labelPrinter.PrintText(marginX * 2 + offsetX, fourthLineY, "3", textList.get(6), 0, 7, 0, 0);
|
|
122
|
+ labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, fourthLineY, "3", textList.get(7), 0, 7, 0, 0);
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+ labelPrinter.PrintText(marginX * 2 + offsetX, fiveLineY, "3", textList.get(8), 0, 7, 0, 0);
|
|
126
|
+ labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, fiveLineY, "3", textList.get(9), 0, 7, 0, 0);
|
|
127
|
+
|
77
|
128
|
|
78
|
|
- getInstance().SetLabelSize(560,640);
|
79
|
|
- labelPrinter.PrintBarcodeQR(80, 20, 0, "SHXM2024007404", 'H', 18, 2);
|
80
|
|
- labelPrinter.PrintText(100, 500, "8", "SHXM2024007404", 0, 7, 3, 0);
|
81
|
129
|
int code = getInstance().PrintLabel(1,1);
|
82
|
130
|
result.success(code == 0 ? true : false);
|
83
|
131
|
}
|
84
|
132
|
|
|
133
|
+ // BTP打印机同时打印图标和标签只能调这个,依次printBitMap再printText会导致偶发printText不走。
|
|
134
|
+ public static void PrintBitMapAndText(Bitmap bitmap, String deviceName, ArrayList<String> textList,@NonNull MethodChannel.Result result) {
|
|
135
|
+ int x = 0;
|
|
136
|
+ if(deviceName.contains("BTP-UP321")) {
|
|
137
|
+ x = 0;
|
|
138
|
+ } else if(deviceName.contains("BTP-P398PLUS")) {
|
|
139
|
+ x = 40;
|
|
140
|
+ }
|
|
141
|
+ int bytes = bitmap.getByteCount();
|
|
142
|
+ ByteBuffer buf = ByteBuffer.allocate(bytes);
|
|
143
|
+ bitmap.copyPixelsToBuffer(buf);
|
|
144
|
+ ByteArrayOutputStream LionData=new ByteArrayOutputStream();
|
|
145
|
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, LionData);
|
|
146
|
+
|
|
147
|
+ getInstance().SetLabelSize(560,640*2);
|
|
148
|
+ int code = getInstance().PrintImageData(x, 0, LionData.toByteArray());
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+ int width = 560;
|
|
152
|
+ int height = 640;
|
|
153
|
+
|
|
154
|
+ int marginX = 2;
|
|
155
|
+ int marginY = 80;
|
|
156
|
+ //矩形框类型
|
|
157
|
+ int rectangleWidth = width - marginX * 2;
|
|
158
|
+ int rectangleHeight = height - marginY * 2;
|
|
159
|
+ int lineWidth = 1;
|
|
160
|
+
|
|
161
|
+ int lineHeight = rectangleHeight / 6;
|
|
162
|
+
|
|
163
|
+ int titleWidth = rectangleWidth / 2;
|
|
164
|
+
|
|
165
|
+ float fontSize = 3;
|
|
166
|
+ // 设置初始偏移量
|
|
167
|
+ int offsetY = 680;
|
|
168
|
+ int offsetX = 0;
|
|
169
|
+ // 计算绘制线条的 y 坐标
|
|
170
|
+ int secondLineY = marginY + lineHeight * 2 - lineWidth + offsetY;
|
|
171
|
+ int thirdLineY = marginY + lineHeight * 3 - lineWidth + offsetY;
|
|
172
|
+ int fourthLineY = marginY + lineHeight * 4 - lineWidth + offsetY;
|
|
173
|
+ int fiveLineY = marginY + lineHeight * 5 - lineWidth + offsetY;
|
|
174
|
+
|
|
175
|
+ int textAlignHorizontal = 0; // 左对齐
|
|
176
|
+
|
|
177
|
+ labelPrinter.PrintText(marginX * 2 + offsetX, marginY + offsetY, "3", textList.get(0), 0, 7, 0, 0);
|
|
178
|
+ labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, marginY + offsetY, "3", textList.get(1), 0, 7, 0, 0);
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+ labelPrinter.PrintText(marginX * 2 + offsetX, marginY + lineHeight - lineWidth + offsetY, "3", textList.get(2), 0, 7, 0, 0);
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+ labelPrinter.PrintText(marginX * 2 + offsetX, secondLineY, "3", textList.get(3), 0, 7, 0, 0);
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+ labelPrinter.PrintText(marginX * 2 + offsetX, thirdLineY, "3", textList.get(4), 0, 7, 0, 0);
|
|
188
|
+ labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, thirdLineY, "3", textList.get(5), 0, 7, 0, 0);
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+ labelPrinter.PrintText(marginX * 2 + offsetX, fourthLineY, "3", textList.get(6), 0, 7, 0, 0);
|
|
192
|
+ labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, fourthLineY, "3", textList.get(7), 0, 7, 0, 0);
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+ labelPrinter.PrintText(marginX * 2 + offsetX, fiveLineY, "3", textList.get(8), 0, 7, 0, 0);
|
|
196
|
+ labelPrinter.PrintText(marginX * 2 + titleWidth + offsetX, fiveLineY, "3", textList.get(9), 0, 7, 0, 0);
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+ getInstance().PrintLabel(1,1);
|
|
202
|
+ result.success(code == 0 ? true : false);
|
|
203
|
+ }
|
85
|
204
|
}
|