فهرست منبع

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

huwanxiao 1 سال پیش
والد
کامیت
1f0f81361c
1فایلهای تغییر یافته به همراه23 افزوده شده و 22 حذف شده
  1. 23 22
      app/src/main/java/com/naz/sdkdemo/MainActivity.java

+ 23 - 22
app/src/main/java/com/naz/sdkdemo/MainActivity.java

@@ -964,9 +964,10 @@ public class MainActivity extends BaseActivity {
     static int fontSizeMultiple = 2;//字体倍数
     static int fontSizeMultiple1 = 3;//字体倍数
     static int mOffsetY = 5;//打印开始点离左边的距离(Y轴),5mm
-    static int mOffsetX = mPaperWidth-5;//打印开始点离上边的距离(X轴),5mm
+    static int mOffsetX = mPaperWidth-6;//打印开始点离上边的距离(X轴),5mm
     static int mFontWidth = mWFont * fontSizeMultiple;//文字的宽度
     static int mFontHeight = mHFont * fontSizeMultiple;//文字的高度
+    static int mFontHeightDistanceHalf = mHFont * (fontSizeMultiple1 - fontSizeMultiple) / 2;//文字的高度
     static int mSpace = 4;//行列间隔-----5mm
     static int mTextSpace = 1;//换行间距----2mm
     static int mCodeSize = 30;//二维码宽高----30mm
@@ -1028,7 +1029,7 @@ public class MainActivity extends BaseActivity {
                     .reference(mPaperWidth*mPot, 0)  // 定义打印坐标原点
                     .direction(TSPLConst.DIRECTION_FORWARD)
                     .cls()
-                    .text(mOffsetX*mPot, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "订单号:")
+                    .text(mOffsetX*mPot - mFontHeightDistanceHalf / 2, 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);
@@ -1045,7 +1046,7 @@ public class MainActivity extends BaseActivity {
                 currentHeight = currentHeight-mFontHeight;
             }
             currentHeight = currentHeight-mSpace*mPot;
-            printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "花  色:")  // 花色 -> module.decor_code_show
+            printer.text(currentHeight - mFontHeightDistanceHalf, 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 = "第二花色  第二花色";
@@ -1053,7 +1054,7 @@ public class MainActivity extends BaseActivity {
                 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
+            printer.text(currentHeight - mFontHeightDistanceHalf, 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 = "第二工艺  第二工艺";
@@ -1061,20 +1062,20 @@ public class MainActivity extends BaseActivity {
                 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
+            printer.text(currentHeight - mFontHeightDistanceHalf, 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
+            printer.text(currentHeight - mFontHeightDistanceHalf, 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_num)
                     .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);
+                    .text(currentHeight - 3 * mFontHeight / 4, (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);
+            int qrX = (mOffsetX - 26)* mPot;
+            int qrY = (mPaperHeight - 5 - 28) * mPot;
+            printer.qrcode(qrX, qrY, TSPLConst.EC_LEVEL_H, 9, TSPLConst.QRCODE_MODE_MANUAL, TSPLConst.ROTATION_0, module.box_no);
             printer.print();
         }
     }
@@ -1135,7 +1136,7 @@ public class MainActivity extends BaseActivity {
                     .reference(mPaperWidth*mPot, 0)  // 定义打印坐标原点
                     .direction(TSPLConst.DIRECTION_FORWARD)
                     .cls()
-                    .text(mOffsetX*mPot, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "订单号:")
+                    .text(mOffsetX*mPot - mFontHeightDistanceHalf / 2, 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);
@@ -1152,36 +1153,36 @@ public class MainActivity extends BaseActivity {
                 currentHeight = currentHeight-mFontHeight;
             }
             currentHeight = currentHeight-mSpace*mPot;
-            printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "花  色:")  // 花色 -> module.decor_code_show
+            printer.text(currentHeight - mFontHeightDistanceHalf, 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 = "第二花色  第二花色";
+//            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
+            printer.text(currentHeight - mFontHeightDistanceHalf, 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 = "第二工艺  第二工艺";
+//            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
+            printer.text(currentHeight - mFontHeightDistanceHalf, 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
+            currentHeight = currentHeight - mFontHeight-mSpace*mPot/8;
+            printer.text(currentHeight - mFontHeightDistanceHalf, 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);
+                    .text(currentHeight - 3 * mFontHeight / 4, (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);
+            int qrX = (mOffsetX - 26)* mPot;
+            int qrY = (mPaperHeight - 5 - 28) * mPot;
+            printer.qrcode(qrX, qrY, TSPLConst.EC_LEVEL_H, 9, TSPLConst.QRCODE_MODE_MANUAL, TSPLConst.ROTATION_0, module.no);
             printer.print();
         }
     }