Skip to content

Commit

Permalink
打印文字debug
Browse files Browse the repository at this point in the history
  • Loading branch information
song.chao committed Jan 18, 2024
1 parent 53e3c0f commit 8b96c54
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ public void run() {
int formatStyle = call.argument("style");
if (iminPrintUtils != null) {
iminPrintUtils.setPageFormat(formatStyle);
} else {
PrinterHelper.getInstance().setPageFormat(formatStyle);
}
result.success(true);
break;
Expand Down Expand Up @@ -534,67 +536,6 @@ public void run() {
Log.e("IminPrinter", e.getMessage());
}
break;
case "printBarCodeToBitmapFormat":
try {
// String barCodeFormatContent = call.argument("data");
// int barCodeFormatWidth = call.argument("width");
// int barCodeFormatHeight = call.argument("height");
// int barCodeFormat = call.argument("codeFormat");
// switch (barCodeFormat) {
// case 0:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.AZTEC);
// break;
// case 1:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.CODABAR);
// break;
// case 2:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.CODE_39);
// break;
// case 3:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.CODE_93);
// break;
// case 4:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.CODE_128);
// break;
// case 5:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.DATA_MATRIX);
// break;
// case 6:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.EAN_13);
// break;
// case 7:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.ITF);
// break;
// case 8:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.PDF_417);
// break;
// case 9:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.MAXICODE);
// break;
// case 10:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.QR_CODE);
// break;
// case 11:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.RSS_14);
// break;
// case 12:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.RSS_EXPANDED);
// break;
// case 13:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.UPC_A);
// break;
// case 14:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.UPC_E);
// break;
// case 15:
// iminPrintUtils.printBarCodeToBitmapFormat(barCodeFormatContent, barCodeFormatWidth, barCodeFormatHeight, CodeFormat.UPC_EAN_EXTENSION);
// break;
// }
result.success(true);
} catch (Exception e) {
Log.e("IminPrinter", e.getMessage());
}
break;
case "setDoubleQRSize":
int doubleQRSize = call.argument("size");
if (iminPrintUtils != null) {
Expand Down Expand Up @@ -707,6 +648,7 @@ public void run() {
List<String> fontCodepage = PrinterHelper.getInstance().getFontCodepage();
result.success(fontCodepage);
}
result.success(true);
break;
case "setFontCodepage":
if (iminPrintUtils == null) {
Expand All @@ -720,6 +662,7 @@ public void run() {
String curCodepage = PrinterHelper.getInstance().getCurCodepage();
result.success(curCodepage);
}
result.success(true);
break;

case "getEncodeList"://2. encode
Expand Down Expand Up @@ -760,7 +703,6 @@ public void run() {
result.success(PrinterHelper.getInstance().getPrinterDensity());
}
break;

case "getPrinterSpeedList"://4. speed
if (iminPrintUtils == null) {
List<String> printerSpeedList = PrinterHelper.getInstance().getPrinterSpeedList();
Expand All @@ -774,32 +716,23 @@ public void run() {
}
result.success(true);
break;
case "getPrinterSpeedList":
case "getPrinterSpeed":
if (iminPrintUtils == null) {
int printerSpeed = PrinterHelper.getInstance().getPrinterSpeed();
result.success(printerSpeed);
}
break;

case "getPrinterPaperTypeList"://5. Paper width
if (iminPrintUtils == null) {
List<String> printerPaperTypeList = PrinterHelper.getInstance().getPrinterPaperTypeList();
result.success(printerPaperTypeList);
}
break;
case "setPageFormat":
if (iminPrintUtils == null) {
int paperType = call.argument("paperType");
PrinterHelper.getInstance().setPageFormat(paperType);
}
result.success(true);
break;
case "getPrinterPaperType":
if (iminPrintUtils == null) {
result.success(PrinterHelper.getInstance().getPrinterPaperType());
}
break;

case "getPrinterSerialNumber":
if (iminPrintUtils == null) {
PrinterHelper.getInstance().getPrinterSerialNumber(new INeoPrinterCallback() {
Expand Down Expand Up @@ -1058,6 +991,7 @@ public void onPrintResult(int code, String msg) throws RemoteException {
case "setTextBitmapStyle":
if (iminPrintUtils == null) {
int textBitmapStyle = call.argument("style");
Log.d("setTextBitmapStyle", "setTextBitmapStyle: " + textBitmapStyle);
if (iminPrintUtils != null) {
PrinterHelper.getInstance().setTextBitmapStyle(textBitmapStyle);
}
Expand Down Expand Up @@ -1112,6 +1046,9 @@ public void onPrintResult(int code, String msg) throws RemoteException {
if (iminPrintUtils == null) {
String textBitmapString = call.argument("text");
int textBitmapAlign = call.argument("align");
Log.d("sdsd","打印文字对齐方式textBitmapString" + textBitmapString);
Log.d("sdsd","打印文字对齐方式textBitmapAlign" + textBitmapAlign);

PrinterHelper.getInstance().printTextBitmapWithAli(textBitmapString, textBitmapAlign, null);
}
result.success(true);
Expand Down Expand Up @@ -1179,22 +1116,6 @@ public void onPrintResult(int code, String msg) throws RemoteException {
}
result.success(true);
break;
// case "printBuffer"://事务打印测试用1,2,3
// if (iminPrintUtils == null) {
// int bufferIndex = call.argument("bufferIndex");
// Log.d(TAG, "bufferIndex " + bufferIndex);
// if (bufferIndex == 0) {

// PrinterHelper.getInstance().sendRAWData(BytesUtils.getBaiduTestBytes(), null);
// } else if (bufferIndex == 1) {

// PrinterHelper.getInstance().sendRAWData(BytesUtils.getErlmoData(), null);
// } else if (bufferIndex == 2) {
// PrinterHelper.getInstance().sendRAWData(BytesUtils.getMeituanBill(), null);
// }
// }
// result.success(true);
// break;
case "commitPrinterBuffer"://提交事务打印
if (iminPrintUtils == null) {
PrinterHelper.getInstance().commitPrinterBuffer(null);
Expand Down
42 changes: 28 additions & 14 deletions example/lib/pages/v2/print_sttings_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,40 @@ class _TextSettingComponentState extends State<TextSettingComponent> {
dynamic align;
dynamic typeface;
dynamic fontStyle;
final TextEditingController descController = TextEditingController();
String descriptionCount = '';
TextEditingController descController = TextEditingController();
String descriptionCount =
'iMin advocates the core values of "Integrity, Customer First, Invention&Creation, Patience”, using cloud-based technology to help businesses to get access to the Internet and also increases their data base, by providing more solutions so that their business can take a step further. Through their efficiency enhancement, cost improvement, service innovation, and better services for consumers, these aspect will drives the entire industry development.';
final focusNode = FocusNode();
String letterSpacing = '';
String lineHeight = '';
String fontSize = '';
@override
void initState() {
descController.text =
'iMin advocates the core values of "Integrity, Customer First, Invention&Creation, Patience”, using cloud-based technology to help businesses to get access to the Internet and also increases their data base, by providing more solutions so that their business can take a step further. Through their efficiency enhancement, cost improvement, service innovation, and better services for consumers, these aspect will drives the entire industry development.';
descController.selection =
TextSelection(baseOffset: 0, extentOffset: descController.text.length);
descController = TextEditingController.fromValue(TextEditingValue(
text: descriptionCount,
selection: TextSelection.fromPosition(
TextPosition(
offset: descriptionCount.length,
affinity: TextAffinity.downstream),
)));
focusNode.requestFocus();
// descController.selection =
// TextSelection(baseOffset: 0, extentOffset: descController.text.length);
super.initState();
init();
// init();
}

Future<void> init() async {
if (mounted) {
setState(() {
descriptionCount = descController.text;
});
}
// Future<void> init() async {
// if (mounted) {
// setState(() {
// descriptionCount = descController.text;
// });
// }
// }
@override
void dispose() {
focusNode.dispose(); // 释放资源
super.dispose();
}

@override
Expand All @@ -78,10 +91,11 @@ class _TextSettingComponentState extends State<TextSettingComponent> {
descriptionCount = value;
});
},
focusNode: focusNode,
decoration: InputDecoration(
hintText: 'Please enter the printed text',
prefixIcon: const Icon(Icons.description),
counterText: "${descriptionCount.length}/1000",
counterText: "${descController.text.length}/1000",
labelText: "Text"),
maxLines: 3,
maxLength: 1000,
Expand Down
46 changes: 45 additions & 1 deletion lib/imin_printer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ var logger = Logger();

class IminPrinter {
Future<void> listenerEvent(dynamic onEvent, {dynamic onError}) {
return IminPrinterPlatform.instance.listenerEvent(onEvent, onError: onEvent );
return IminPrinterPlatform.instance
.listenerEvent(onEvent, onError: onEvent);
}

/// Get what version of sdk is the current device using
///
/// {@tool snippet}
Expand Down Expand Up @@ -659,14 +661,56 @@ class IminPrinter {
Future<void> printColumnsString({required List<ColumnMaker> cols}) {
return IminPrinterPlatform.instance.printColumnsString(cols: cols);
}

Future<void> enterPrinterBuffer(bool isClean) {
return IminPrinterPlatform.instance.enterPrinterBuffer(isClean);
}

Future<void> commitPrinterBuffer() {
return IminPrinterPlatform.instance.commitPrinterBuffer();
}

Future<void> exitPrinterBuffer(bool isCommit) {
return IminPrinterPlatform.instance.exitPrinterBuffer(isCommit);
}

Future<List<String>?> getFontCodepage() {
return IminPrinterPlatform.instance.getFontCodepage();
}

Future<void> setFontCodepage(int codepage) {
return IminPrinterPlatform.instance.setFontCodepage(codepage);
}

Future<String?> getCurCodepage() {
return IminPrinterPlatform.instance.getCurCodepage();
}

Future<List<String>?> getEncodeList() {
return IminPrinterPlatform.instance.getEncodeList();
}

Future<String?> getCurEncode() {
return IminPrinterPlatform.instance.getCurEncode();
}

Future<List<String>?> getPrinterDensityList() {
return IminPrinterPlatform.instance.getPrinterDensityList();
}

Future<List<String>?> getPrinterSpeedList() {
return IminPrinterPlatform.instance.getPrinterSpeedList();
}

Future<void> setPrinterSpeed(int speed) {
return IminPrinterPlatform.instance.setPrinterSpeed(speed);
}

Future<int?> getPrinterSpeed() {
return IminPrinterPlatform.instance.getPrinterSpeed();
}

Future<List<String>?> getPrinterPaperTypeList() {
return IminPrinterPlatform.instance.getPrinterPaperTypeList();
}
}
53 changes: 52 additions & 1 deletion lib/imin_printer_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,60 @@ class MethodChannelIminPrinter extends IminPrinterPlatform {
Future<void> commitPrinterBuffer() async {
await methodChannel.invokeMethod<void>('commitPrinterBuffer');
}

@override
Future<void> exitPrinterBuffer(bool isCommit) async {
Map<String, dynamic> arguments = <String, dynamic>{"isCommit": isCommit };
Map<String, dynamic> arguments = <String, dynamic>{"isCommit": isCommit};
await methodChannel.invokeMethod<void>('exitPrinterBuffer', arguments);
}

@override
Future<List<String>?> getFontCodepage() async {
return await methodChannel.invokeMethod<List<String>>('getFontCodepage');
}

@override
Future<void> setFontCodepage(int codepage) async {
Map<String, dynamic> arguments = <String, dynamic>{"codepage": codepage};
return await methodChannel.invokeMethod<void>('setFontCodepage', arguments);
}

@override
Future<String?> getCurCodepage() async {
return await methodChannel.invokeMethod<String>('getCurCodepage');
}

@override
Future<List<String>?> getEncodeList() async {
return await methodChannel.invokeMethod<List<String>>('getEncodeList');
}

@override
Future<List<String>?> getPrinterDensityList() async {
return await methodChannel
.invokeMethod<List<String>>('getPrinterDensityList');
}

@override
Future<List<String>?> getPrinterSpeedList() async {
return await methodChannel
.invokeMethod<List<String>>('getPrinterSpeedList');
}

@override
Future<void> setPrinterSpeed(int speed) async {
Map<String, dynamic> arguments = <String, dynamic>{"speed": speed};
await methodChannel.invokeMethod<void>('setPrinterSpeed', arguments);
}

@override
Future<int?> getPrinterSpeed() async {
return await methodChannel.invokeMethod<int>('getPrinterSpeed');
}

@override
Future<List<String>?> getPrinterPaperTypeList() async {
return await methodChannel
.invokeMethod<List<String>>('getPrinterPaperTypeList');
}
}
Loading

0 comments on commit 8b96c54

Please sign in to comment.