21 # You should have received a copy of the GNU General Public License |
21 # You should have received a copy of the GNU General Public License |
22 # along with this program; if not, write to the Free Software |
22 # along with this program; if not, write to the Free Software |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
24 |
25 from __future__ import absolute_import |
25 from __future__ import absolute_import |
|
26 from __future__ import division |
26 import sys |
27 import sys |
27 from types import TupleType |
28 from types import TupleType |
28 import base64 |
29 import base64 |
29 from builtins import str as text |
30 from builtins import str as text |
30 |
31 |
199 for idx, tab in enumerate(tabs): |
200 for idx, tab in enumerate(tabs): |
200 if len(tab["pages"]) == 0: |
201 if len(tab["pages"]) == 0: |
201 raise ValueError("Not possible") |
202 raise ValueError("Not possible") |
202 if tab["size"][0] == rect.width: |
203 if tab["size"][0] == rect.width: |
203 if tab["pos"][1] == rect.y: |
204 if tab["pos"][1] == rect.y: |
204 split = (wx.TOP, float(tab["size"][1]) / float(rect.height)) |
205 split = (wx.TOP, tab["size"][1] / rect.height) |
205 split_rect = wx.Rect(rect.x, rect.y + tab["size"][1] + TAB_BORDER, |
206 split_rect = wx.Rect(rect.x, rect.y + tab["size"][1] + TAB_BORDER, |
206 rect.width, rect.height - tab["size"][1] - TAB_BORDER) |
207 rect.width, rect.height - tab["size"][1] - TAB_BORDER) |
207 elif tab["pos"][1] == rect.height + 1 - tab["size"][1]: |
208 elif tab["pos"][1] == rect.height + 1 - tab["size"][1]: |
208 split = (wx.BOTTOM, 1.0 - float(tab["size"][1]) / float(rect.height)) |
209 split = (wx.BOTTOM, 1.0 - tab["size"][1] / rect.height) |
209 split_rect = wx.Rect(rect.x, rect.y, |
210 split_rect = wx.Rect(rect.x, rect.y, |
210 rect.width, rect.height - tab["size"][1] - TAB_BORDER) |
211 rect.width, rect.height - tab["size"][1] - TAB_BORDER) |
211 split_id = idx |
212 split_id = idx |
212 break |
213 break |
213 elif tab["size"][1] == rect.height: |
214 elif tab["size"][1] == rect.height: |
214 if tab["pos"][0] == rect.x: |
215 if tab["pos"][0] == rect.x: |
215 split = (wx.LEFT, float(tab["size"][0]) / float(rect.width)) |
216 split = (wx.LEFT, tab["size"][0] / rect.width) |
216 split_rect = wx.Rect(rect.x + tab["size"][0] + TAB_BORDER, rect.y, |
217 split_rect = wx.Rect(rect.x + tab["size"][0] + TAB_BORDER, rect.y, |
217 rect.width - tab["size"][0] - TAB_BORDER, rect.height) |
218 rect.width - tab["size"][0] - TAB_BORDER, rect.height) |
218 elif tab["pos"][0] == rect.width + 1 - tab["size"][0]: |
219 elif tab["pos"][0] == rect.width + 1 - tab["size"][0]: |
219 split = (wx.RIGHT, 1.0 - float(tab["size"][0]) / float(rect.width)) |
220 split = (wx.RIGHT, 1.0 - tab["size"][0] / rect.width) |
220 split_rect = wx.Rect(rect.x, rect.y, |
221 split_rect = wx.Rect(rect.x, rect.y, |
221 rect.width - tab["size"][0] - TAB_BORDER, rect.height) |
222 rect.width - tab["size"][0] - TAB_BORDER, rect.height) |
222 split_id = idx |
223 split_id = idx |
223 break |
224 break |
224 if split is not None: |
225 if split is not None: |
2590 # Viewer Printout |
2591 # Viewer Printout |
2591 # ------------------------------------------------------------------------------- |
2592 # ------------------------------------------------------------------------------- |
2592 |
2593 |
2593 |
2594 |
2594 def UPPER_DIV(x, y): |
2595 def UPPER_DIV(x, y): |
2595 return (x / y) + {True: 0, False: 1}[(x % y) == 0] |
2596 return (x // y) + {True: 0, False: 1}[(x % y) == 0] |
2596 |
2597 |
2597 |
2598 |
2598 class GraphicPrintout(wx.Printout): |
2599 class GraphicPrintout(wx.Printout): |
2599 def __init__(self, viewer, page_size, margins, preview=False): |
2600 def __init__(self, viewer, page_size, margins, preview=False): |
2600 wx.Printout.__init__(self) |
2601 wx.Printout.__init__(self) |
2637 |
2638 |
2638 # Get the size of the DC in pixels |
2639 # Get the size of the DC in pixels |
2639 ppiPrinterX, ppiPrinterY = self.GetPPIPrinter() |
2640 ppiPrinterX, ppiPrinterY = self.GetPPIPrinter() |
2640 pw, ph = self.GetPageSizePixels() |
2641 pw, ph = self.GetPageSizePixels() |
2641 dw, dh = dc.GetSizeTuple() |
2642 dw, dh = dc.GetSizeTuple() |
2642 Xscale = (float(dw) * float(ppiPrinterX)) / (float(pw) * 25.4) |
2643 Xscale = (dw * ppiPrinterX) / (pw * 25.4) |
2643 Yscale = (float(dh) * float(ppiPrinterY)) / (float(ph) * 25.4) |
2644 Yscale = (dh * ppiPrinterY) / (ph * 25.4) |
2644 |
2645 |
2645 fontsize = self.FontSize * Yscale |
2646 fontsize = self.FontSize * Yscale |
2646 |
2647 |
2647 margin_left = self.Margins[0].x * Xscale |
2648 margin_left = self.Margins[0].x * Xscale |
2648 margin_top = self.Margins[0].y * Yscale |
2649 margin_top = self.Margins[0].y * Yscale |
2660 dc.DrawText(block_name, margin_left, margin_top - text_height - self.TextMargin) |
2661 dc.DrawText(block_name, margin_left, margin_top - text_height - self.TextMargin) |
2661 dc.DrawText(_("Page: %d") % page, margin_left, margin_top + area_height + self.TextMargin) |
2662 dc.DrawText(_("Page: %d") % page, margin_left, margin_top + area_height + self.TextMargin) |
2662 |
2663 |
2663 # Calculate the position on the DC for centering the graphic |
2664 # Calculate the position on the DC for centering the graphic |
2664 posX = area_width * ((page - 1) % self.PageGrid[0]) |
2665 posX = area_width * ((page - 1) % self.PageGrid[0]) |
2665 posY = area_height * ((page - 1) / self.PageGrid[0]) |
2666 posY = area_height * ((page - 1) // self.PageGrid[0]) |
2666 |
2667 |
2667 scaleX = float(area_width) / float(self.PageSize[0]) |
2668 scaleX = area_width / self.PageSize[0] |
2668 scaleY = float(area_height) / float(self.PageSize[1]) |
2669 scaleY = area_height / self.PageSize[1] |
2669 scale = min(scaleX, scaleY) |
2670 scale = min(scaleX, scaleY) |
2670 |
2671 |
2671 # Set the scale and origin |
2672 # Set the scale and origin |
2672 dc.SetDeviceOrigin(-posX + margin_left, -posY + margin_top) |
2673 dc.SetDeviceOrigin(-posX + margin_left, -posY + margin_top) |
2673 dc.SetClippingRegion(posX, posY, self.PageSize[0] * scale, self.PageSize[1] * scale) |
2674 dc.SetClippingRegion(posX, posY, self.PageSize[0] * scale, self.PageSize[1] * scale) |