1114 margins = (self.PageSetupData.GetMarginTopLeft(), self.PageSetupData.GetMarginBottomRight()) |
1114 margins = (self.PageSetupData.GetMarginTopLeft(), self.PageSetupData.GetMarginBottomRight()) |
1115 printout = GraphicPrintout(window, page_size, margins, True) |
1115 printout = GraphicPrintout(window, page_size, margins, True) |
1116 printout2 = GraphicPrintout(window, page_size, margins, True) |
1116 printout2 = GraphicPrintout(window, page_size, margins, True) |
1117 preview = wx.PrintPreview(printout, printout2, data) |
1117 preview = wx.PrintPreview(printout, printout2, data) |
1118 |
1118 |
1119 if preview.Ok(): |
1119 if preview.IsOk(): |
1120 preview_frame = wx.PreviewFrame(preview, self, _("Print preview"), style=wx.DEFAULT_FRAME_STYLE | wx.FRAME_FLOAT_ON_PARENT) |
1120 preview_frame = wx.PreviewFrame(preview, self, _("Print preview"), style=wx.DEFAULT_FRAME_STYLE | wx.FRAME_FLOAT_ON_PARENT) |
1121 |
1121 |
1122 preview_frame.Initialize() |
1122 preview_frame.Initialize() |
1123 |
1123 |
1124 preview_canvas = preview.GetCanvas() |
1124 preview_canvas = preview.GetCanvas() |
2597 wx.Printout.__init__(self) |
2597 wx.Printout.__init__(self) |
2598 self.Viewer = viewer |
2598 self.Viewer = viewer |
2599 self.PageSize = page_size |
2599 self.PageSize = page_size |
2600 if self.PageSize[0] == 0 or self.PageSize[1] == 0: |
2600 if self.PageSize[0] == 0 or self.PageSize[1] == 0: |
2601 self.PageSize = (1050, 1485) |
2601 self.PageSize = (1050, 1485) |
2602 self.Preview = preview |
2602 self.IsPreview = lambda *_x : preview |
2603 self.Margins = margins |
2603 self.Margins = margins |
2604 self.FontSize = 5 |
2604 self.FontSize = 5 |
2605 self.TextMargin = 3 |
2605 self.TextMargin = 3 |
2606 |
2606 |
2607 maxx, maxy = viewer.GetMaxSize() |
2607 maxx, maxy = viewer.GetMaxSize() |
2618 page_number = self.GetPageNumber() |
2618 page_number = self.GetPageNumber() |
2619 return (1, page_number, 1, page_number) |
2619 return (1, page_number, 1, page_number) |
2620 |
2620 |
2621 def OnBeginDocument(self, startPage, endPage): |
2621 def OnBeginDocument(self, startPage, endPage): |
2622 dc = self.GetDC() |
2622 dc = self.GetDC() |
2623 if not self.Preview and isinstance(dc, wx.PostScriptDC): |
2623 if not self.IsPreview() and isinstance(dc, wx.PostScriptDC): |
2624 dc.SetResolution(720) |
2624 dc.SetResolution(720) |
2625 super(GraphicPrintout, self).OnBeginDocument(startPage, endPage) |
2625 return super(GraphicPrintout, self).OnBeginDocument(startPage, endPage) |
2626 |
2626 |
2627 def OnPrintPage(self, page): |
2627 def OnPrintPage(self, page): |
2628 dc = self.GetDC() |
2628 dc = self.GetDC() |
2629 dc.SetBackground(wx.WHITE_BRUSH) |
2629 dc.SetBackground(wx.WHITE_BRUSH) |
2630 dc.Clear() |
2630 dc.Clear() |
2631 dc.SetUserScale(1.0, 1.0) |
2631 dc.SetUserScale(1.0, 1.0) |
2632 dc.SetDeviceOrigin(0, 0) |
2632 dc.SetDeviceOrigin(0, 0) |
2633 dc.printing = not self.Preview |
2633 dc.printing = not self.IsPreview() |
2634 |
2634 |
2635 # Get the size of the DC in pixels |
2635 # Get the size of the DC in pixels |
2636 ppiPrinterX, ppiPrinterY = self.GetPPIPrinter() |
2636 ppiPrinterX, ppiPrinterY = self.GetPPIPrinter() |
2637 pw, ph = self.GetPageSizePixels() |
2637 pw, ph = self.GetPageSizePixels() |
2638 dw, dh = dc.GetSizeTuple() |
2638 dw, dh = dc.GetSize().Get() |
2639 Xscale = (dw * ppiPrinterX) / (pw * 25.4) |
2639 Xscale = (dw * ppiPrinterX) / (pw * 25.4) |
2640 Yscale = (dh * ppiPrinterY) / (ph * 25.4) |
2640 Yscale = (dh * ppiPrinterY) / (ph * 25.4) |
2641 |
2641 |
2642 fontsize = self.FontSize * Yscale |
2642 fontsize = round(self.FontSize * Yscale) |
2643 |
2643 |
2644 margin_left = self.Margins[0].x * Xscale |
2644 margin_left = round(self.Margins[0].x * Xscale) |
2645 margin_top = self.Margins[0].y * Yscale |
2645 margin_top = round(self.Margins[0].y * Yscale) |
2646 area_width = dw - self.Margins[1].x * Xscale - margin_left |
2646 area_width = dw - round(self.Margins[1].x * Xscale) - margin_left |
2647 area_height = dh - self.Margins[1].y * Yscale - margin_top |
2647 area_height = dh - round(self.Margins[1].y * Yscale) - margin_top |
2648 |
2648 |
2649 dc.SetPen(MiterPen(wx.BLACK)) |
2649 dc.SetPen(MiterPen(wx.BLACK)) |
2650 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
2650 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
2651 dc.DrawRectangle(margin_left, margin_top, area_width, area_height) |
2651 dc.DrawRectangle(margin_left, margin_top, area_width, area_height) |
2652 |
2652 |
2665 scaleY = area_height / self.PageSize[1] |
2665 scaleY = area_height / self.PageSize[1] |
2666 scale = min(scaleX, scaleY) |
2666 scale = min(scaleX, scaleY) |
2667 |
2667 |
2668 # Set the scale and origin |
2668 # Set the scale and origin |
2669 dc.SetDeviceOrigin(-posX + margin_left, -posY + margin_top) |
2669 dc.SetDeviceOrigin(-posX + margin_left, -posY + margin_top) |
2670 dc.SetClippingRegion(posX, posY, self.PageSize[0] * scale, self.PageSize[1] * scale) |
2670 dc.SetClippingRegion(posX, posY, round(self.PageSize[0] * scale), round(self.PageSize[1] * scale)) |
2671 dc.SetUserScale(scale, scale) |
2671 dc.SetUserScale(scale, scale) |
2672 |
2672 |
2673 self.Viewer.DoDrawing(dc, True) |
2673 self.Viewer.DoDrawing(dc, True) |
2674 |
2674 |
2675 return True |
2675 return True |