-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPrintout.py
58 lines (44 loc) · 1.93 KB
/
Printout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import wx
import copy
import cad
class Printout(wx.Printout):
def __init__(self):
wx.Printout.__init__(self, 'Heeks printout')
# overriding
def GetPageInfo(self):
return (1,1,1,1) # minPage, maxPage, pageFrom, pageTo
def HasPage(self, page):
return page == 1 or page == 2
def OnPrintPage(self, page):
wx.GetApp().frame.printout = self
dc = self.GetDC()
if dc:
self.SetUnitsFactor()
cad.SetGetLinesPixelsPerMm(1.0/self.scale)
for start, x, y, z in cad.GetApp().GetLines():
if not start:
self.GetDC().DrawLine(self.xoff + (px * self.logUnitsFactorx + 0.5), self.yoff - (py * self.logUnitsFactory + 0.5), self.xoff + (x * self.logUnitsFactorx + 0.5), self.yoff - (y * self.logUnitsFactory + 0.5))
px = x
py = y
return True
else:
return False
def SetUnitsFactor(self):
dc = self.GetDC()
ppiScreenX, ppiScreenY = self.GetPPIScreen()
ppiPrinterX, ppiPrinterY = self.GetPPIPrinter()
scalex = float(ppiPrinterX)/ppiScreenX
w, h = dc.GetSize()
pageWidth, pageHeight = self.GetPageSizePixels()
overallScalex = scalex * float(w) / pageWidth
self.logUnitsFactorx = float(ppiPrinterX) / 25.4 * float(w) / pageWidth
self.logUnitsFactory = float(ppiPrinterY) / 25.4 * float(h) / pageHeight
self.scale = overallScalex
fitRect = self.GetLogicalPageMarginsRect(wx.GetApp().pageSetupData)
self.xoff = fitRect.x + fitRect.width / 2
self.yoff = fitRect.y + fitRect.height / 2
def SetColor(self, c):
col = copy.copy(c)
if c == cad.Color(255, 255, 255): col = cad.Color(0,0,0)
pen = wx.Pen(col.ref(), self.scale + 0.99)
self.GetDC().SetPen(pen)