lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [6350] Refactor image drawing (VZ)


From: Greg Chicares
Subject: [lmi-commits] [6350] Refactor image drawing (VZ)
Date: Sun, 11 Oct 2015 16:32:14 +0000

Revision: 6350
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=6350
Author:   chicares
Date:     2015-10-11 16:32:14 +0000 (Sun, 11 Oct 2015)
Log Message:
-----------
Refactor image drawing (VZ)

Modified Paths:
--------------
    lmi/trunk/group_quote_pdf_gen_wx.cpp

Modified: lmi/trunk/group_quote_pdf_gen_wx.cpp
===================================================================
--- lmi/trunk/group_quote_pdf_gen_wx.cpp        2015-10-11 16:08:43 UTC (rev 
6349)
+++ lmi/trunk/group_quote_pdf_gen_wx.cpp        2015-10-11 16:32:14 UTC (rev 
6350)
@@ -249,6 +249,54 @@
     return image;
 }
 
+/// Output an image at the given scale into the PDF.
+///
+/// The scale specifies how many times the image should be shrunk, i.e. scale >
+/// 1 makes the image smaller while scale < 1 makes it larger.
+///
+/// Updates pos_y by increasing it by the height of the specified image at the
+/// given scale.
+
+void output_image
+    (wxPdfDC&         pdf_dc
+    ,wxImage const&   image
+    ,char const*      image_name
+    ,double           scale
+    ,int              x
+    ,int*             pos_y
+    ,enum_output_mode output_mode = e_output_normal
+    )
+{
+    int const y = wxRound(image.GetHeight() / scale);
+
+    switch(output_mode)
+        {
+        case e_output_normal:
+            {
+            // Use wxPdfDocument API directly as wxDC doesn't provide a way to
+            // set the image scale at PDF level and also because passing via
+            // wxDC wastefully converts wxImage to wxBitmap only to convert it
+            // back to wxImage when embedding it into the PDF.
+            wxPdfDocument* const pdf_doc = pdf_dc.GetPdfDocument();
+            LMI_ASSERT(pdf_doc);
+
+            pdf_doc->SetImageScale(scale);
+            pdf_doc->Image(image_name, image, x, *pos_y);
+            pdf_doc->SetImageScale(1);
+            }
+            break;
+        case e_output_measure_only:
+            // Do nothing.
+            break;
+        default:
+            {
+            fatal_error() << "Case " << output_mode << " not found." << 
LMI_FLUSH;
+            }
+        }
+
+    *pos_y += y;
+}
+
 /// Render, or just pretend rendering in order to measure it, the given HTML
 /// contents at the specified position wrapping it at the given width.
 /// Return the height of the output (using this width).
@@ -861,25 +909,12 @@
         return;
         }
 
-    // Use wxPdfDocument API directly as wxDC doesn't provide a way to set the
-    // image scale at PDF level and also because passing via wxDC wastefully
-    // converts wxImage to wxBitmap only to convert it back to wxImage when
-    // embedding it into the PDF.
-    wxPdfDocument* const pdf_doc = pdf_dc.GetPdfDocument();
-    LMI_ASSERT(pdf_doc);
-
-    wxSize const image_size = banner_image.GetSize();
-
     // Set the scale to fit the image to the document width.
-    pdf_doc->SetImageScale
-        (static_cast<double>(image_size.x) / page_.total_size_.x
-        );
-    pdf_doc->Image("banner", banner_image, 0, *pos_y);
+    double const
+        scale = static_cast<double>(banner_image.GetWidth()) / 
page_.total_size_.x;
+    int const pos_top = *pos_y;
+    output_image(pdf_dc, banner_image, "banner", scale, 0, pos_y);
 
-    int const y = wxRound(image_size.y / pdf_doc->GetImageScale());
-
-    pdf_doc->SetImageScale(1);
-
     wxDCFontChanger set_bigger_font(pdf_dc, pdf_dc.GetFont().Scaled(1.5));
     wxDCTextColourChanger set_white_text(pdf_dc, *wxWHITE);
 
@@ -893,13 +928,11 @@
     pdf_dc.DrawLabel
         (image_text
         ,wxRect
-            (wxPoint(horz_margin, *pos_y + y / 2),
+            (wxPoint(horz_margin, (pos_top + *pos_y) / 2),
              pdf_dc.GetMultiLineTextExtent(image_text)
             )
         ,wxALIGN_CENTER_HORIZONTAL
         );
-
-    *pos_y += y;
 }
 
 void group_quote_pdf_generator_wx::output_document_header




reply via email to

[Prev in Thread] Current Thread [Next in Thread]