def OnPrintPage(self, page):
dc = self.GetDC() # allows using floats for certain functions
# Note PPIScreen does not give the correct number
# Calulate everything for printer and then scale for preview
PPIPrinter = self.GetPPIPrinter() # printer dots/inch (w,h)
# PPIScreen= self.GetPPIScreen() # screen dots/inch (w,h)
dcSize = dc.GetSize() # DC size
if self.graph._antiAliasingEnabled and not isinstance(dc, wx.GCDC):
try:
dc = wx.GCDC(dc)
except Exception:
pass
else:
if self.graph._hiResEnabled:
# high precision - each logical unit is 1/20 of a point
dc.SetMapMode(wx.MM_TWIPS)
pageSize = self.GetPageSizePixels() # page size in terms of pixcels
clientDcSize = self.graph.GetClientSize()
# find what the margins are (mm)
margLeftSize, margTopSize = self.graph.pageSetupData.GetMarginTopLeft()
margRightSize, margBottomSize = self.graph.pageSetupData.GetMarginBottomRight()
# calculate offset and scale for dc
pixLeft = margLeftSize * PPIPrinter[0] / 25.4 # mm*(dots/in)/(mm/in)
pixRight = margRightSize * PPIPrinter[0] / 25.4
pixTop = margTopSize * PPIPrinter[1] / 25.4
pixBottom = margBottomSize * PPIPrinter[1] / 25.4
plotAreaW = pageSize[0] - (pixLeft + pixRight)
plotAreaH = pageSize[1] - (pixTop + pixBottom)
# ratio offset and scale to screen size if preview
if self.IsPreview():
ratioW = float(dcSize[0]) / pageSize[0]
ratioH = float(dcSize[1]) / pageSize[1]
pixLeft *= ratioW
pixTop *= ratioH
plotAreaW *= ratioW
plotAreaH *= ratioH
# rescale plot to page or preview plot area
self.graph._setSize(plotAreaW, plotAreaH)
# Set offset and scale
dc.SetDeviceOrigin(pixLeft, pixTop)
# Thicken up pens and increase marker size for printing
ratioW = float(plotAreaW) / clientDcSize[0]
ratioH = float(plotAreaH) / clientDcSize[1]
aveScale = (ratioW + ratioH) / 2
if self.graph._antiAliasingEnabled and not self.IsPreview():
scale = dc.GetUserScale()
dc.SetUserScale(
scale[0] / self.graph._pointSize[0], scale[1] / self.graph._pointSize[1])
self.graph._setPrinterScale(aveScale) # tickens up pens for printing
self.graph._printDraw(dc)
# rescale back to original
self.graph._setSize()
self.graph._setPrinterScale(1)
self.graph.Redraw() # to get point label scale and shift correct
return True
#----------------------------------------------------------------------
评论列表
文章目录