[gnue] r9489 - trunk/gnue-forms/src/uidrivers/wx26/widgets

[email protected]
Newsgroups gmane.comp.cms.gnue.cvs
Message-ID <[email protected]>
Author: reinhard
Date: 2007-04-11 04:57:21 -0500 (Wed, 11 Apr 2007)
New Revision: 9489

Modified:
   trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py
Log:
Fixed scaling of printout.


Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py	2007-04-11 09:04:57 UTC (rev 9488)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/form.py	2007-04-11 09:57:21 UTC (rev 9489)
@@ -588,17 +588,18 @@
 
     def _ui_printout_(self, title, subtitle, user):
 
-        # Store the content of the form in a bitmap DC
+        # Store the content of the form in a bitmap DC, because later parts of
+        # the form are hidden behind the print dialog, which breaks the form
+        # DC.
         window_dc = wx.ClientDC(self.main_window)
         w, h = self.main_window.GetClientSizeTuple()
-        bmp = wx.EmptyBitmap(w, h)
+        bitmap = wx.EmptyBitmap(w, h)
         form_dc = wx.MemoryDC()
-        form_dc.SelectObject(bmp)
+        form_dc.SelectObject(bitmap)
         form_dc.Blit(0,0, w, h, window_dc, 0, 0)
-        image = wx.ImageFromBitmap(bmp)
 
-        wx.Printer().Print(self.main_window,
-                _Printout(title, subtitle, user, image))
+        printout = _Printout(title, subtitle, user, bitmap)
+        wx.Printer().Print(self.main_window, printout)
 
 
     # -------------------------------------------------------------------------
@@ -633,11 +634,11 @@
     # Constructor
     # -------------------------------------------------------------------------
 
-    def __init__(self, title, subtitle, login, image):
+    def __init__(self, title, subtitle, login, bitmap):
         self.__title = title
         self.__subtitle = subtitle or ''
         self.__login = login
-        self.__image = image
+        self.__bitmap = bitmap
         wx.Printout.__init__(self, title)
 
 
@@ -706,8 +707,8 @@
         canvas_h = canvas_bottom - canvas_top
 
         # If necessary, adjust scale factor to fit on page
-        w = self.__image.GetWidth()
-        h = self.__image.GetHeight()
+        w = self.__bitmap.GetWidth()
+        h = self.__bitmap.GetHeight()
         if w * scale_x > canvas_w:
             scale_y = float(scale_y) / (w * scale_x / canvas_w)
             scale_x = float(canvas_w) / w
@@ -715,23 +716,15 @@
             scale_x = float(scale_x) / (h * scale_y / canvas_h)
             scale_y = float(canvas_h) / h
 
-        # and now, scale by factor
-        w = int (w * scale_x + 0.5)
-        h = int (h * scale_y + 0.5)
+        # the actual screenshot with border
+        dc.SetUserScale(scale_x, scale_y)
+        x = (page_left + canvas_w / 2) / scale_x - w / 2
+        y = (canvas_top + canvas_h / 2) / scale_y - h / 2
+        dc.DrawBitmap(self.__bitmap, x, y)
+        dc.DrawRectangle(x, y, w, h)
+        dc.SetUserScale(1, 1)
 
-        # the actual screenshot
-        dc.DrawBitmap(
-                wx.BitmapFromImage(self.__image.Scale(w, h)),
-                int((canvas_w - w) / 2) + page_left,
-                int((canvas_h - h) / 2) + canvas_top)
 
-        # border
-        dc.DrawRectangle(
-                int((canvas_w - w) / 2) + page_left,
-                int((canvas_h - h) / 2) + canvas_top,
-                w, h)
-
-
     # -------------------------------------------------------------------------
     # Draw text and calculate new y position
     # -------------------------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.