소스 검색

update: 按照需求更改打印纸内容排版

huwanxiao 1 년 전
부모
커밋
30f5abd228
1개의 변경된 파일132개의 추가작업 그리고 4개의 파일을 삭제
  1. 132 4
      app/src/main/java/com/naz/sdkdemo/MainActivity.java

+ 132 - 4
app/src/main/java/com/naz/sdkdemo/MainActivity.java

@@ -439,7 +439,8 @@ public class MainActivity extends BaseActivity {
             if (data == null) {
                 return;
             }
-            startPrint(data);
+            // startPrint(data);
+            startPrint_1(data);
         }
 
         @JavascriptInterface
@@ -452,7 +453,7 @@ public class MainActivity extends BaseActivity {
             if (data == null) {
                 return;
             }
-            startPrint2(data);
+            startPrint2_1(data);
         }
 
         @JavascriptInterface
@@ -1020,7 +1021,63 @@ public class MainActivity extends BaseActivity {
             printer.print();
         }
     }
-
+    private void startPrint_1(List<PrintModule> data) {
+        for (PrintModule module:data) {
+            printer.sizeMm(mPaperWidth, mPaperHeight)  // 纸张尺寸
+                    .density(15)   // 字体颜色浓淡
+                    .reference(mPaperWidth*mPot, 0)  // 定义打印坐标原点
+                    .direction(TSPLConst.DIRECTION_FORWARD)
+                    .cls()
+                    .text(mOffsetX*mPot, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "订单号:")
+                    .text(mOffsetX*mPot, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.exe_sale_order_b.no)
+                    .text((mOffsetX-mSpace)*mPot-mFontHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "产  品:");
+            String[] productName = getStrs(module.material_code_show, (mPaperHeight-2*mOffsetY-mSpace-mCodeSize)*mPot-5*mFontWidth);
+            printer.text((mOffsetX-mSpace)*mPot-mFontHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, productName[0]);
+            int currentHeight = (mOffsetX-mSpace)*mPot-2*mFontHeight;
+            if (!TextUtils.isEmpty(productName[1])){
+                currentHeight = currentHeight-mTextSpace*mPot;
+                printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, productName[1]);
+                currentHeight = currentHeight-mFontHeight;
+            }
+            if (!TextUtils.isEmpty(productName[2])){
+                currentHeight = currentHeight-mTextSpace*mPot;
+                printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, productName[2]);
+                currentHeight = currentHeight-mFontHeight;
+            }
+            currentHeight = currentHeight-mSpace*mPot;
+            printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "花  色:")  // 花色 -> module.decor_code_show
+                    .text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.decor_code_show);
+            // 测试用
+            //module.box_order_product.color_two = "第二花色  第二花色";
+            if (module.decor_two_code_show !=null){
+                printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth)+getStrLength2(module.decor_code_show)+mSpace*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.decor_two_code_show);
+            }
+            currentHeight = currentHeight-mFontHeight-mSpace*mPot;
+            printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "工  艺:")       // 工艺 -> module.craft_type_code_show
+                    .text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.craft_type_code_show);
+            // 测试用
+            //module.box_order_product.process_title_two = "第二工艺  第二工艺";
+            if (module.craft_type_two_code_show!=null){
+                printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth)+getStrLength2(module.craft_type_code_show)+mSpace*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.craft_type_two_code_show);
+            }
+            currentHeight = currentHeight-mFontHeight-mSpace*mPot;
+            printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "经销商:")  // 经销商: ->  module.exe_sale_order_b.customer_name
+                    .text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.exe_sale_order_b.customer_name);
+            currentHeight = currentHeight-mFontHeight-mSpace*mPot;
+            currentHeight = currentHeight-mFontHeight-mSpace*mPot/8;
+            printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "包装数量:")    // 包装数量 -> module.box_num
+                    .text(currentHeight, mOffsetY*mPot+(5*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.exe_sale_order_b.customer_name)
+                    .text(currentHeight + mFontHeight/2, (mPaperHeight-5)*mPot-getStrLength(module.box_no)-getStrLength("包装单号: "), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "包装单号:  ")  // 包装单号 -> module.box_no
+                    .text(currentHeight+ mFontHeight/2, (mPaperHeight-5)*mPot-getStrLength(module.box_no), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.box_no)
+                    .text(currentHeight - mFontHeight/2, (mPaperHeight-5)*mPot-getStrLength(module.box_no)-getStrLength("包装单号: "), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.now_date);
+            // 二维码   qrX:32  qrY:30  cellWidth:10
+            // 二维码   qrX:25  qrY:25  cellWidth:8
+            int qrX = (mOffsetX - 25)* mPot;
+            int qrY = (mPaperHeight - 5 - 21) * mPot;
+            printer.qrcode(qrX, qrY, TSPLConst.EC_LEVEL_H, 8, TSPLConst.QRCODE_MODE_MANUAL, TSPLConst.ROTATION_0, module.box_no);
+            printer.print();
+        }
+    }
     private void startPrint2(List<PrintModule2> data) {
         for (PrintModule2 module:data) {
             printer.sizeMm(mPaperWidth, mPaperHeight)
@@ -1071,6 +1128,63 @@ public class MainActivity extends BaseActivity {
             printer.print();
         }
     }
+    private void startPrint2_1(List<PrintModule2> data) {
+        for (PrintModule2 module:data) {
+            printer.sizeMm(mPaperWidth, mPaperHeight)  // 纸张尺寸
+                    .density(15)   // 字体颜色浓淡
+                    .reference(mPaperWidth*mPot, 0)  // 定义打印坐标原点
+                    .direction(TSPLConst.DIRECTION_FORWARD)
+                    .cls()
+                    .text(mOffsetX*mPot, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "订单号:")
+                    .text(mOffsetX*mPot, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.box_order_product.order_no)
+                    .text((mOffsetX-mSpace)*mPot-mFontHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "产  品:");
+            String[] productName = getStrs(module.box_order_product.material_title, (mPaperHeight-2*mOffsetY-mSpace-mCodeSize)*mPot-5*mFontWidth);
+            printer.text((mOffsetX-mSpace)*mPot-mFontHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, productName[0]);
+            int currentHeight = (mOffsetX-mSpace)*mPot-2*mFontHeight;
+            if (!TextUtils.isEmpty(productName[1])){
+                currentHeight = currentHeight-mTextSpace*mPot;
+                printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, productName[1]);
+                currentHeight = currentHeight-mFontHeight;
+            }
+            if (!TextUtils.isEmpty(productName[2])){
+                currentHeight = currentHeight-mTextSpace*mPot;
+                printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, productName[2]);
+                currentHeight = currentHeight-mFontHeight;
+            }
+            currentHeight = currentHeight-mSpace*mPot;
+            printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "花  色:")  // 花色 -> module.decor_code_show
+                    .text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.box_order_product.color);
+            // 测试用
+            //module.box_order_product.color_two = "第二花色  第二花色";
+            if (module.box_order_product.color_two !=null){
+                printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth)+getStrLength2(module.box_order_product.color)+mSpace*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.box_order_product.color_two);
+            }
+            currentHeight = currentHeight-mFontHeight-mSpace*mPot;
+            printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "工  艺:")       // 工艺 -> module.craft_type_code_show
+                    .text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.box_order_product.process_title);
+            // 测试用
+            //module.box_order_product.process_title_two = "第二工艺  第二工艺";
+            if (module.box_order_product.process_title_two!=null){
+                printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth)+getStrLength2(module.box_order_product.process_title)+mSpace*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.box_order_product.process_title_two);
+            }
+            currentHeight = currentHeight-mFontHeight-mSpace*mPot;
+            printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "经销商:")  // 经销商: ->  module.exe_sale_order_b.customer_name
+                    .text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.box_order_product.customer_name);
+            currentHeight = currentHeight-mFontHeight-mSpace*mPot;
+            currentHeight = currentHeight-mFontHeight-mSpace*mPot/8;
+            printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "包装数量:")    // 包装数量 -> module.box_num
+                    .text(currentHeight, mOffsetY*mPot+(5*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.box_order_product.box_num)
+                    .text(currentHeight + mFontHeight/2, (mPaperHeight-5)*mPot-getStrLength(module.no)-getStrLength("包装单号: "), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "包装单号:  ")  // 包装单号 -> module.box_no
+                    .text(currentHeight+ mFontHeight/2, (mPaperHeight-5)*mPot-getStrLength(module.no), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.no)
+                    .text(currentHeight - mFontHeight/2, (mPaperHeight-5)*mPot-getStrLength(module.no)-getStrLength("包装单号: "), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.now_date);
+            // 二维码   qrX:32  qrY:30  cellWidth:10
+            // 二维码   qrX:25  qrY:25  cellWidth:8
+            int qrX = (mOffsetX - 25)* mPot;
+            int qrY = (mPaperHeight - 5 - 21) * mPot;
+            printer.qrcode(qrX, qrY, TSPLConst.EC_LEVEL_H, 8, TSPLConst.QRCODE_MODE_MANUAL, TSPLConst.ROTATION_0, module.no);
+            printer.print();
+        }
+    }
 
     private void startPrint3(List<PrintModule3> data) {
         for (PrintModule3 module:data) {
@@ -1100,7 +1214,7 @@ public class MainActivity extends BaseActivity {
             printer.text(currentHeight, (mPaperHeight-5)*mPot-getStrLength(module.roll_qr_code), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.roll_qr_code);
             currentHeight = currentHeight-mFontHeight-mSpace*mPot;
             printer.text(currentHeight - 2, (mPaperHeight-5)*mPot-getStrLength(module.now_date), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.now_date);
-            int qrX = (mOffsetX - 37) * mPot;
+            int qrX = (mOffsetX - 30) * mPot;
             int qrY = (mPaperHeight - 5 - 30) * mPot;
             printer.qrcode(qrX, qrY, TSPLConst.EC_LEVEL_H, 10, TSPLConst.QRCODE_MODE_MANUAL, TSPLConst.ROTATION_0, module.roll_qr_code);
             printer.print();
@@ -1121,6 +1235,20 @@ public class MainActivity extends BaseActivity {
         return xmLength;
     }
 
+    public static int getStrLength2(String xm){
+        int xmLength = 0;
+        for (int i = 0; i < xm.length(); i++) {
+            char chr = xm.charAt(i);
+            if (isChinese(chr)){
+                xmLength+=(mWFont*fontSizeMultiple1);
+            }else {
+                xmLength+=(mWFont*fontSizeMultiple1/2);
+            }
+        }
+        Log.e("------->","----->xmStrLength="+xmLength);
+        return xmLength;
+    }
+
     public static String[] getStrs(String xm, int maxLength){
         Log.e("------->","----->maxLength="+maxLength);
         String[] resultStrs = new String[3];