//
//  TextTSPLDemo.swift
//  iOSPrinterDemo
//
//  Created by ios on 2017/12/21.
//  Copyright © 2017年 Mellow. All rights reserved.
//

import UIKit

class TextTSPLDemo: NSObject {
    
    
    func selfTextPage() {
        
        let cmd = PTCommandTSPL.init()
        cmd.setCLS()
        cmd.selfTest()
        PrinterPort.send(Data: cmd.cmdData as Data)
    }
    
    func testText() {
        
        let cmd = PTCommandTSPL.init()
        cmd.setCLS()
        cmd.setPrintAreaSizeWithWidth(100, height: 50)
        cmd.appendText(withXPos: 0, yPos: 0, fontSize: 28, rotation: 0, text: "Live beautifully, dream passionately, love completely")
        cmd.print(withSets: 1, copies: 1)
        //        cmd.setFormFeed()
        //        cmd.setPeelOFF()
        
        PrinterPort.send(Data: cmd.cmdData as Data)
    }
    
    func testQRcode() {
        let cmd = PTCommandTSPL.init()
        cmd.setCLS()
        cmd.printQRcode(withXPos: 100, yPos: 100, eccLevel: "H", cellWidth: 7, mode: "M", rotation: 0, model: "M1", mask: "S1", text: "Hello World")
        cmd.print(withSets: 1, copies: 1)
        PrinterPort.send(Data: cmd.cmdData as Data)
    }
    
    func testBarcode() {
        let cmd = PTCommandTSPL.init()
        cmd.setCLS()
        cmd.printBarcode(withXPos: 100, yPos: 100, type: "128", height: 100, humanReadable: 1, rotation: 0, narrow: 3, wide: 3, codeNumber: "1234567890")
        cmd.print(withSets: 1, copies: 1)
        PrinterPort.send(Data: cmd.cmdData as Data)
    }
    
    func testPrintBitmap1() {
        let cmd = PTCommandTSPL.init()
        cmd.setCLS()
        let image = UIImage.init(named: "logo_yt_print2.png")
        //处理后的图片数据
        var imageData = PTBitmap.getImageData(image?.cgImage, mode: PTBitmapMode.dithering, compress: PTBitmapCompressMode.none)
        //TSPL的位图数据需要取反
        imageData = PTBitmap.negativeData(imageData)
        
        cmd.setPrintAreaSizeWithWidth(200, height: 50)
        cmd.addBitmap(withXPos: 50, yPos: 50, width: Int((image?.size.width)!), height: Int((image?.size.height)!), mode: 2, imageData: imageData)
        cmd.print(withSets: 1, copies: 1)
        PrinterPort.send(Data: cmd.cmdData as Data)
    }
    
    func testPrintBitmap2() {
        let cmd = PTCommandTSPL.init()
        cmd.setCLS()
        
//                let bundle = Bundle.main.path(forResource: "PrinterResource.bundle/logo_sto", ofType: "png")
        let image = UIImage.init(named:"reprint.png")
        cmd.setPrintAreaSizeWithWidth(100, height: 50)
        var imageData = PTBitmap.getImageData(image?.cgImage, mode: PTBitmapMode.dithering, compress: PTBitmapCompressMode.none)
        imageData = PTBitmap.negativeData(imageData)
        
        cmd.addBitmap(withXPos: 50, yPos: 50, width: Int((image?.size.width)!), height: Int((image?.size.height)!), mode: 2, imageData: imageData)
        cmd.print(withSets: 1, copies: 1)
        //        cmd.setFormFeed()
        PrinterPort.send(Data: cmd.cmdData as Data)
    }
    
    func testPrintBox() {
        let cmd = PTCommandTSPL.init()
        cmd.setCLS()
        cmd.setBoxWithXStart(100, yStart: 100, xEnd: 500, yEnd: 500, thickness: 3)
        cmd.print(withSets: 1, copies: 1)
        //        cmd.setFormFeed()
        PrinterPort.send(Data: cmd.cmdData as Data)
    }
    
    func testPrintCircle() {
        let cmd = PTCommandTSPL.init()
        cmd.setCLS()
        cmd.setCircleWithXStart(100, yStart: 100, diameter: 500, thickness: 3)
        cmd.print(withSets: 1, copies: 1)
        //        cmd.setFormFeed()
        PrinterPort.send(Data: cmd.cmdData as Data)
    }
    
    func testPrintBar() {
        let cmd = PTCommandTSPL.init()
        cmd.setCLS()
        cmd.printBar(withXPos: 200, yPos: 200, width: 500, height: 10)
        cmd.print(withSets: 1, copies: 1)
        //        cmd.setFormFeed()
        PrinterPort.send(Data: cmd.cmdData as Data)
    }
    
}





