seven365-zyprinter 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,6 +13,15 @@ import ExternalAccessory
13
13
 
14
14
  @objc public class ZywellSDK: NSObject {
15
15
 
16
+ // MARK: - Printer Configuration
17
+
18
+ /// Default printer width in characters (for 80mm thermal paper)
19
+ /// Common widths: 32 chars (58mm paper), 48 chars (80mm paper)
20
+ private let printerWidth: Int = 48
21
+
22
+ /// Character separator character
23
+ private let separatorChar: String = "-"
24
+
16
25
  private var bleManager: POSBLEManager?
17
26
  private var wifiManagers: [String: POSWIFIManager] = [:]
18
27
  private var discoveredPeripherals: [CBPeripheral] = []
@@ -454,19 +463,39 @@ import ExternalAccessory
454
463
  // Left align (ESC a 0)
455
464
  printData.append(Data([0x1B, 0x61, 0x00]))
456
465
 
457
- // Separator
458
- if let separatorData = ("--------------------------------\n").data(using: .utf8) {
466
+ // Separator (normal font size)
467
+ if let separatorData = generateSeparator().data(using: .utf8) {
459
468
  printData.append(separatorData)
460
469
  }
461
470
 
462
471
  // ========== ORDER INFO SECTION ==========
463
- // Template type (e.g., "Kitchen Tickets")
472
+ // Template type (e.g., "Kitchen Tickets") - normal size
464
473
  if let orderType = getString(template["order_type"]),
465
474
  let orderTypeData = (orderType + "\n").data(using: .utf8) {
466
475
  printData.append(orderTypeData)
467
476
  }
468
477
 
469
- // Table and order number with prefix
478
+ // Table and order number - Read formatting from order_info or use defaults
479
+ var orderInfoSizeCode: UInt8 = 0x22 // Default to 3x (xlarge)
480
+ var orderInfoBold = true // Default to bold
481
+
482
+ if let orderInfo = template["order_info"] as? [String: Any] {
483
+ if let size = orderInfo["size"] {
484
+ orderInfoSizeCode = mapHeaderSizeToCode(size)
485
+ }
486
+ if let bold = orderInfo["bold"] as? Bool {
487
+ orderInfoBold = bold
488
+ }
489
+ }
490
+
491
+ // Apply order info formatting
492
+ if orderInfoBold {
493
+ printData.append(Data([0x1B, 0x45, 0x01])) // Bold on
494
+ }
495
+ if orderInfoSizeCode != 0x00 {
496
+ printData.append(Data([0x1D, 0x21, orderInfoSizeCode])) // Set size from config
497
+ }
498
+
470
499
  var orderInfoLine = ""
471
500
  if let tableName = getString(template["table_name"]) {
472
501
  orderInfoLine += tableName
@@ -482,9 +511,18 @@ import ExternalAccessory
482
511
  printData.append(orderInfoData)
483
512
  }
484
513
 
514
+ // Reset formatting back to normal
515
+ if orderInfoSizeCode != 0x00 {
516
+ printData.append(Data([0x1D, 0x21, 0x00])) // Normal size
517
+ }
518
+ if orderInfoBold {
519
+ printData.append(Data([0x1B, 0x45, 0x00])) // Bold off
520
+ }
485
521
 
486
- // Separator for items section
487
- if let separatorData = ("--------------------------------\n").data(using: .utf8) {
522
+
523
+
524
+ // Separator for items section (normal font size)
525
+ if let separatorData = generateSeparator().data(using: .utf8) {
488
526
  printData.append(separatorData)
489
527
  }
490
528
 
@@ -608,8 +646,8 @@ import ExternalAccessory
608
646
  }
609
647
 
610
648
  // ========== TOTAL SECTION ==========
611
- // Separator before total
612
- if let separatorData = ("--------------------------------\n").data(using: .utf8) {
649
+ // Separator before total (normal font size)
650
+ if let separatorData = generateSeparator().data(using: .utf8) {
613
651
  printData.append(separatorData)
614
652
  }
615
653
 
@@ -636,8 +674,8 @@ import ExternalAccessory
636
674
 
637
675
  // ========== TOTAL SECTION (NEW STRUCTURE) ==========
638
676
  if let total = getString(template["total"]) {
639
- // Separator
640
- if let separatorData = ("--------------------------------\n").data(using: .utf8) {
677
+ // Separator (may need to account for total font size)
678
+ if let separatorData = generateSeparator().data(using: .utf8) {
641
679
  printData.append(separatorData)
642
680
  }
643
681
 
@@ -675,8 +713,8 @@ import ExternalAccessory
675
713
  }
676
714
  }
677
715
 
678
- // Separator
679
- if let separatorData = ("--------------------------------\n").data(using: .utf8) {
716
+ // Separator (normal font size)
717
+ if let separatorData = generateSeparator().data(using: .utf8) {
680
718
  printData.append(separatorData)
681
719
  }
682
720
 
@@ -686,8 +724,8 @@ import ExternalAccessory
686
724
  printData.append(paymentData)
687
725
  }
688
726
 
689
- // Separator
690
- if let separatorData = ("--------------------------------\n").data(using: .utf8) {
727
+ // Separator (normal font size)
728
+ if let separatorData = generateSeparator().data(using: .utf8) {
691
729
  printData.append(separatorData)
692
730
  }
693
731
 
@@ -741,32 +779,40 @@ import ExternalAccessory
741
779
  // MARK: - Helper Functions
742
780
 
743
781
  private func mapHeaderSizeToCode(_ size: Any) -> UInt8 {
782
+ var resultCode: UInt8 = 0x00
783
+
744
784
  if let sizeInt = size as? Int {
745
785
  switch sizeInt {
746
- case 1: return 0x00
747
- case 2: return 0x11
748
- case 3: return 0x22
749
- case 4: return 0x33
750
- default: return 0x00
786
+ case 1: resultCode = 0x00
787
+ case 2: resultCode = 0x11
788
+ case 3: resultCode = 0x22
789
+ case 4: resultCode = 0x33
790
+ default: resultCode = 0x00
751
791
  }
792
+ print("ZywellSDK: Mapped size Int(\(sizeInt)) → 0x\(String(format: "%02X", resultCode))")
752
793
  } else if let sizeStr = size as? String {
753
794
  switch sizeStr.lowercased() {
754
- case "normal", "1": return 0x00
755
- case "large", "2": return 0x11
756
- case "xlarge", "3": return 0x22
757
- case "4": return 0x33
758
- default: return 0x00
795
+ case "normal", "1": resultCode = 0x00
796
+ case "large", "2": resultCode = 0x11
797
+ case "xlarge", "3": resultCode = 0x22
798
+ case "4": resultCode = 0x33
799
+ default: resultCode = 0x00
759
800
  }
801
+ print("ZywellSDK: Mapped size String(\"\(sizeStr)\") → 0x\(String(format: "%02X", resultCode))")
760
802
  } else if let sizeNum = size as? NSNumber {
761
803
  switch sizeNum.intValue {
762
- case 1: return 0x00
763
- case 2: return 0x11
764
- case 3: return 0x22
765
- case 4: return 0x33
766
- default: return 0x00
804
+ case 1: resultCode = 0x00
805
+ case 2: resultCode = 0x11
806
+ case 3: resultCode = 0x22
807
+ case 4: resultCode = 0x33
808
+ default: resultCode = 0x00
767
809
  }
810
+ print("ZywellSDK: Mapped size NSNumber(\(sizeNum.intValue)) → 0x\(String(format: "%02X", resultCode))")
811
+ } else {
812
+ print("ZywellSDK: Unknown size type: \(type(of: size)), defaulting to 0x00")
768
813
  }
769
- return 0x00
814
+
815
+ return resultCode
770
816
  }
771
817
 
772
818
  private func getBool(_ value: Any?) -> Bool {
@@ -788,6 +834,34 @@ import ExternalAccessory
788
834
  return String(describing: value)
789
835
  }
790
836
 
837
+ /**
838
+ * Generates a separator line based on current printer width and font magnification
839
+ * - Parameter sizeCode: The current font size code (0x00, 0x11, 0x22, 0x33)
840
+ * - Returns: A separator string with appropriate width
841
+ *
842
+ * Font magnification affects character width:
843
+ * - 0x00 (normal): 1x width
844
+ * - 0x11 (2x2): 2x width (half as many characters fit)
845
+ * - 0x22 (3x3): 3x width (one-third as many characters fit)
846
+ * - 0x33 (4x4): 4x width (one-quarter as many characters fit)
847
+ */
848
+ private func generateSeparator(forSizeCode sizeCode: UInt8 = 0x00) -> String {
849
+ // Calculate width divisor based on font magnification
850
+ let widthMultiplier: Int
851
+ switch sizeCode {
852
+ case 0x11: widthMultiplier = 2 // 2x width
853
+ case 0x22: widthMultiplier = 3 // 3x width
854
+ case 0x33: widthMultiplier = 4 // 4x width
855
+ default: widthMultiplier = 1 // Normal width
856
+ }
857
+
858
+ // Calculate actual character count that fits on the line
859
+ let effectiveWidth = printerWidth / widthMultiplier
860
+
861
+ // Generate separator string
862
+ return String(repeating: separatorChar, count: effectiveWidth) + "\n"
863
+ }
864
+
791
865
  // MARK: - Callback Storage
792
866
 
793
867
  private var discoveryCompletion: (([[String: Any]], String?) -> Void)?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seven365-zyprinter",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Capacitor plugin for Zywell/Zyprint thermal printer integration with Bluetooth and WiFi support",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",