import { StarXpandCommand } from '../../index'; import { StarXpandCommandParameterConverter } from './StarXpandCommandParameterConverter'; export class PrinterBaseBuilder { static addPrinterParameter(parameters: Map, printerParameter: StarXpandCommand.Printer.PrinterParameter) { let parameter = parameters.get("parameters")as Array>; if (printerParameter.templateExtension !== undefined) { parameter.push( new Map([ ["method", "Setting.TemplateExtension"], ["parameter", new Map([ ["enableArrayFieldData", printerParameter.templateExtension.enableArrayFieldData] ])] ]) ); } } static addPageModeParameter(parameters: Map, pageModeParameter: StarXpandCommand.Printer.PageModeParameter) { let parameter = parameters.get("parameters")as Array>; if (pageModeParameter.templateExtension !== undefined) { parameter.push( new Map([ ["method", "Setting.TemplateExtension"], ["parameter", new Map([ ["enableArrayFieldData", pageModeParameter.templateExtension.enableArrayFieldData] ])] ]) ); } } static styleAlignment(parameters: Map, position: StarXpandCommand.Printer.Alignment) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.Alignment"], ["parameter", new Map([ ["position", StarXpandCommandParameterConverter.convertAlignment(position)] ])] ]) ); } static styleFont(parameters: Map, type: StarXpandCommand.Printer.FontType) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.Font"], ["parameter", new Map([ ["type", StarXpandCommandParameterConverter.convertFontType(type)] ])] ]) ) } static styleBold(parameters: Map, enable: boolean) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.Bold"], ["parameter", new Map([ ["enable", enable] ])] ]) ) } static styleInvert(parameters: Map, enable: boolean) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.Invert"], ["parameter", new Map([ ["enable", enable] ])] ]) ) } static styleUnderLine(parameters: Map, enable: boolean) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.UnderLine"], ["parameter", new Map([ ["enable", enable] ])] ]) ) } static styleMagnification(parameters: Map, parameter: StarXpandCommand.MagnificationParameter) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.Magnification"], ["parameter", new Map([ ["width", Math.floor(parameter.width)], ["height", Math.floor(parameter.height)] ])] ]) ) } static styleBaseMagnification(parameters: Map, parameter: StarXpandCommand.Printer.BaseMagnificationParameter) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.BaseMagnification"], ["parameter", new Map([ ["text", StarXpandCommandParameterConverter.convertBaseMagnification(parameter.text)] ])] ]) ) } static styleCharacterSpace(parameters: Map, width: number) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.CharacterSpace"], ["parameter", new Map([ ["width", width] ])] ]) ) } static styleLineSpace(parameters: Map, height: number) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.LineSpace"], ["parameter", new Map([ ["height", height] ])] ]) ) } static styleHorizontalPositionTo(parameters: Map, position: number) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.HorizontalPositionTo"], ["parameter", new Map([ ["position", position] ])] ]) ) } static styleHorizontalPositionBy(parameters: Map, position: number) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.HorizontalPositionBy"], ["parameter", new Map([ ["position", position] ])] ]) ) } static styleHorizontalTabPositions(parameters: Map, positions: Array) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.HorizontalTabPositions"], ["parameter", new Map([ ["positions", positions] ])] ]) ) } static styleVerticalPositionTo(parameters: Map, position: number) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.VerticalPositionTo"], ["parameter", new Map([ ["position",position] ])] ]) ); } static styleVerticalPositionBy(parameters: Map, position: number) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.VerticalPositionBy"], ["parameter", new Map([ ["position",position] ])] ]) ); } static styleInternationalCharacter(parameters: Map, type: StarXpandCommand.Printer.InternationalCharacterType) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.InternationalCharacter"], ["parameter", new Map([ ["type", StarXpandCommandParameterConverter.convertPrinterInternationalCharacterType(type)] ])] ]) ) } static styleSecondPriorityCharacterEncoding(parameters: Map, type: StarXpandCommand.Printer.CharacterEncodingType) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.SecondPriorityCharacterEncoding"], ["parameter", new Map([ ["type", StarXpandCommandParameterConverter.convertPrinterCharacterEncodingType(type)] ])] ]) ) } static styleCjkCharacterPriority(parameters: Map, types: Array) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.CjkCharacterPriority"], ["parameter", new Map([ ["types", StarXpandCommandParameterConverter.convertCjkCharacterTypeArray(types)] ])] ]) ) } static stylePrintDirection(parameters: Map, PageModePrintDirection: StarXpandCommand.Printer.PageModePrintDirection) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.PrintDirection"], ["parameter", new Map([ ["direction", StarXpandCommandParameterConverter.convertPageModePrintDirection(PageModePrintDirection)] ])] ]) ); } static styleAmbiguousCharacterWidthType(parameters: Map, type: StarXpandCommand.Printer.AmbiguousCharacterWidthType) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Style.AmbiguousCharacterWidthType"], ["parameter", new Map([ ["type", StarXpandCommandParameterConverter.convertAmbiguousCharacterWidthType(type)] ])] ]) ); } static actionCut(parameters: Map, type: StarXpandCommand.Printer.CutType) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Action.Cut"], ["parameter", new Map([ ["type", StarXpandCommandParameterConverter.convertCutType(type)] ])] ]) ) } static actionFeed(parameters: Map, height: number) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Action.Feed.Unit"], ["parameter", new Map([ ["height", height] ])] ]) ) } static actionFeedLine(parameters: Map, lines: number) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Action.Feed.Line"], ["parameter", new Map([ ["lines", Math.floor(lines)] ])] ]) ) } static actionSeparatorFeed(parameters: Map) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Action.Feed.Separator"], ["parameter", new Map()] ]) ) } static actionPrintText(parameters: Map, content: string, parameter: StarXpandCommand.Printer.TextParameter | undefined) { let contents = parameters.get("contents") as Array>; let parameterMap = new Map([ ["content", StarXpandCommandParameterConverter.convertString(content)] ]); if (parameter?.width !== undefined) { parameterMap.set("width", parameter?.width); let widthParameter = parameter.widthParameter ?? new StarXpandCommand.Printer.TextWidthParameter() parameterMap.set("widthType", StarXpandCommandParameterConverter.convertTextWidthType(widthParameter.widthType)); parameterMap.set("alignment", StarXpandCommandParameterConverter.convertTextAlignment(widthParameter.alignment)); parameterMap.set("ellipsizeType", StarXpandCommandParameterConverter.convertTextEllipsizeType(widthParameter.ellipsizeType)); parameterMap.set("printType", StarXpandCommandParameterConverter.convertTextPrintType(widthParameter.printType)); } contents.push( new Map([ ["method", "Action.Print.Text"], ["parameter", parameterMap] ]) ); } static actionPrintLogo(parameters: Map, parameter: StarXpandCommand.Printer.LogoParameter) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Action.Print.Logo"], ["parameter", new Map([ ["key_code", StarXpandCommandParameterConverter.convertString(parameter.keyCode)] ])] ]) ) } static actionPrintBarcode(parameters: Map, parameter: StarXpandCommand.Printer.BarcodeParameter) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Action.Print.Barcode"], ["parameter", new Map([ ["content", StarXpandCommandParameterConverter.convertString(parameter.content)], ["symbology", StarXpandCommandParameterConverter.convertBarcodeSymbology(parameter.symbology)], ["bar_dots", Math.floor(parameter.barDots)], ["bar_ratio_level", StarXpandCommandParameterConverter.convertBarcodeBarRatioLevel(parameter.barRatioLevel)], ["height", parameter.height], ["print_hri", parameter.printHri] ])] ]) ) } static actionPrintPdf417(parameters: Map, parameter: StarXpandCommand.Printer.Pdf417Parameter) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Action.Print.Pdf417"], ["parameter", new Map([ ["content", StarXpandCommandParameterConverter.convertString(parameter.content)], ["column", Math.floor(parameter.column)], ["line", Math.floor(parameter.line)], ["module", Math.floor(parameter.module)], ["aspect", Math.floor(parameter.aspect)], ["level", StarXpandCommandParameterConverter.convertPdf417Level(parameter.level)] ])] ]) ) } static actionPrintQRCode(parameters: Map, parameter: StarXpandCommand.Printer.QRCodeParameter) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Action.Print.QRCode"], ["parameter", new Map([ ["content", StarXpandCommandParameterConverter.convertString(parameter.content)], ["model", StarXpandCommandParameterConverter.convertQRCodeModel(parameter.model)], ["level", StarXpandCommandParameterConverter.convertQRCodeLevel(parameter.level)], ["cell_size", Math.floor(parameter.cellSize)] ])] ]) ) } static actionPrintRuledLine(parameters: Map, RuledLineParameter: StarXpandCommand.Printer.RuledLineParameter) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Action.Print.RuledLine"], ["parameter", new Map([ ["x", RuledLineParameter.x], ["width", RuledLineParameter.width], ["thickness", RuledLineParameter.thickness], ["lineStyle", StarXpandCommandParameterConverter.convertLineStyle(RuledLineParameter.lineStyle)], ])] ]) ); } static stylePageModeArea(parameters: any, PageModeRectangleParameter: StarXpandCommand.Printer.PageModeAreaParameter) { let pageModeContents = parameters.get("parameters") as Array>; pageModeContents.unshift( new Map([ ["method", "Style.PageMode.Area"], ["parameter", new Map([ ["x", PageModeRectangleParameter.x], ["y", PageModeRectangleParameter.y], ["width", PageModeRectangleParameter.width], ["height", PageModeRectangleParameter.height] ])] ]) ); } static actionPrintPageModeRuledLine(parameters: Map, PageModeRuledLineParameter: StarXpandCommand.Printer.PageModeRuledLineParameter) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Action.Print.PageModeRuledLine"], ["parameter", new Map([ ["xStart", PageModeRuledLineParameter.xStart], ["yStart", PageModeRuledLineParameter.yStart], ["xEnd", PageModeRuledLineParameter.xEnd], ["yEnd", PageModeRuledLineParameter.yEnd], ["thickness", PageModeRuledLineParameter.thickness], ["lineStyle", StarXpandCommandParameterConverter.convertLineStyle(PageModeRuledLineParameter.lineStyle)], ])] ]) ); } static actionPrintRectangle(parameters: Map, PageModeRectangleParameter: StarXpandCommand.Printer.PageModeRectangleParameter) { let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Action.Print.PageModeRectangle"], ["parameter", new Map([ ["x", PageModeRectangleParameter.x], ["y", PageModeRectangleParameter.y], ["width", PageModeRectangleParameter.width], ["height", PageModeRectangleParameter.height], ["thickness", PageModeRectangleParameter.thickness], ["lineStyle", StarXpandCommandParameterConverter.convertLineStyle(PageModeRectangleParameter.lineStyle)], ["roundCorner", PageModeRectangleParameter.roundCorner], ["cornerRadius", PageModeRectangleParameter.cornerRadius], ])] ]) ); } static actionPrintImage(parameters: Map, source: string) { let printImageObject = JSON.parse(source); if (!printImageObject.hasOwnProperty('parameter')) { return; } let parameter = printImageObject.parameter; if (!parameter.hasOwnProperty('source') || !parameter.hasOwnProperty('width') || !parameter.hasOwnProperty('height')) { return; } let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Action.Print.Image"], ["parameter", new Map([ ["source", StarXpandCommandParameterConverter.convertString(parameter.source)], ["width", parameter.width], ["height", parameter.height] ])] ]) ); } static actionPrintPageModeImage(parameters: Map, source: string,x:number , y:number) { let printImageObject = JSON.parse(source); if (!printImageObject.hasOwnProperty('parameter')) { return; } let parameter = printImageObject.parameter; if (!parameter.hasOwnProperty('source') || !parameter.hasOwnProperty('width') || !parameter.hasOwnProperty('height')) { return; } let contents = parameters.get("contents") as Array>; contents.push( new Map([ ["method", "Action.Print.PageModeImage"], ["parameter", new Map([ ["source", StarXpandCommandParameterConverter.convertString(parameter.source)], ["x",x], ["y",y], ["width", parameter.width], ["height", parameter.height] ])] ]) ); } }