func RunPr2Engine(s string, pr2 driverlayer.IPr2Print, pin *driverlayer.DriverArg) error { var pc PrintCurState pf, e := ParserPrintXml(s) if e != nil { utils.Error("parse xml file error %s", e.Error()) } else { utils.Info("parse xml file success") } ps := pf.S pi := pf.V pc.BottomMargin = ps.ps.Bottommargin pc.LeftMargin = ps.ps.Leftmargin pc.PageHeight = ps.ps.Height pc.PageWidth = ps.ps.Width pc.TopMargin = ps.ps.Topmargin pc.RightMargin = ps.ps.Rightmargin pc.CurX = 0 pc.CurY = 0 pc.CurPage = 1 pc.Flags = 0 pc.LineInterval = ps.ps.LineInterval pc.ColInterval = ps.ps.ColInterval RecurCalcExtent(pi, &pc) utils.Info("RecurCalcExtent success") fl := GeneratePrintLine(pi) utils.Debug("begin print printline----------------------------") PrintPrintLine(fl) utils.Debug("end print printline----------------------------") pr2.BeginPrintJob(pin, 20) defer pr2.EndPrinterJob() RunRealPrinter(ps, fl, pr2) return nil }
//执行实际的打印操作,至此,PrintLine都是排好序的 func RunRealPrinter(ps *PrintSetting, pi *PrintLine, pr2 driverlayer.IPr2Print) { var pl *PrintLine pl = pi var ( X float32 Y float32 ftmp int64 curflag int64 curbflag int64 remain int64 ) //首先是各种预设参数的打印 pr2.Init() pr2.SetLineInterval(ps.ps.LineInterval) pr2.SetColInterval(ps.ps.ColInterval) pr2.SetLeftMargin(ps.ps.Leftmargin) pr2.SetRightMargin(ps.ps.Width - ps.ps.Rightmargin) pr2.SetTop(ps.ps.Topmargin) // pr2.SetPageBottom(ps.ps.Height, ps.ps.Bottommargin) // pr2.AdvanceOneLine() //pr2需要先进纸至少一行 //然后是打印文字 for { if pl == nil { utils.Trace("end of PrintLine,print success") //清除所有标志位 remain = PRINT_FORMAT_BOLD for { if remain >= PRINT_MAX_FLAG { break } curbflag = curflag & remain //标志改变了 if curbflag >= 1 { switch curbflag { case PRINT_FORMAT_BOLD: pr2.CancelBold() break case PRINT_FORMAT_UNDERLINE: pr2.CancelUnderline() break case PRINT_FORMAT_SUP: pr2.CancelSuperline() break case PRINT_FORMAT_SUB: pr2.CancelSubline() break case PRINT_FORMAT_DOUBLEHEIGHT: pr2.CancelDoublePrintHeight() break case PRINT_FORMAT_DOUBLEWIDTH: pr2.CancelDoublePrintWidth() break case PRINT_FORMAT_TRIPLEHEIGHT: case PRINT_FORMAT_TRIPLEWIDTH: default: } } remain = remain << 1 } //进行退纸操作 pr2.EjectPaper() return } if Y != pl.PrY { //推进列 pr2.SeekColPos(pl.PrY-Y, Y) pr2.Carriage() X = 0 Y = pl.PrY } //进行打印 if X != pl.PrX { //推进行 pr2.SeekLinePos(pl.PrX-X, X) X = pl.PrX } //处理特效的事情,对当前标志和所需要的标志进行异或处理 ftmp = curflag ^ pl.Flags utils.Debug("get current flag [%d]", ftmp) remain = PRINT_FORMAT_BOLD for { if remain >= PRINT_MAX_FLAG { break } curbflag = ftmp & remain //标志改变了 if curbflag >= 1 { if (pl.Flags & curbflag) >= 1 { //表明是置位操作 switch curbflag { case PRINT_FORMAT_BOLD: pr2.SetBold() break case PRINT_FORMAT_UNDERLINE: pr2.SetUnderline() break case PRINT_FORMAT_SUP: pr2.SetSuperline() break case PRINT_FORMAT_SUB: pr2.SetSubline() break case PRINT_FORMAT_DOUBLEHEIGHT: pr2.DoublePrintHeight() break case PRINT_FORMAT_DOUBLEWIDTH: pr2.DoublePrintWidth() break case PRINT_FORMAT_TRIPLEHEIGHT: break case PRINT_FORMAT_TRIPLEWIDTH: break case PRINT_FORMAT_TURNPAGE: pr2.EjectPaper() default: } SetPrintInsFlag(&curflag, curbflag) } else { //清除位操作 switch curbflag { case PRINT_FORMAT_BOLD: pr2.CancelBold() break case PRINT_FORMAT_UNDERLINE: pr2.CancelUnderline() break case PRINT_FORMAT_SUP: pr2.CancelSuperline() break case PRINT_FORMAT_SUB: pr2.CancelSubline() break case PRINT_FORMAT_DOUBLEHEIGHT: pr2.CancelDoublePrintHeight() break case PRINT_FORMAT_DOUBLEWIDTH: pr2.CancelDoublePrintWidth() break case PRINT_FORMAT_TRIPLEHEIGHT: case PRINT_FORMAT_TRIPLEWIDTH: case PRINT_FORMAT_TURNPAGE: default: } ClearPrintInsFlag(&curflag, curbflag) } } remain = remain << 1 } if pl.PrContent != "" { pr2.OutputString(pl.PrContent) X += float32(pl.clen) * ps.ps.ColInterval utils.Trace("After print text,X change to %f", X) //调整水平距离 } pl = pl.PrNext } }