+bool wxWindowsPrintPreview::RenderPageIntoBitmapHQ(wxBitmap& bmp, int pageNum)
+{
+ wxLogTrace("printing", "rendering HQ preview of page %i", pageNum);
+
+ wxPrinterDC printerDC(m_printDialogData.GetPrintData());
+ if ( !printerDC.IsOk() )
+ return false;
+
+ // compute scale factor
+ const float scaleX = float(bmp.GetWidth()) / float(m_pageWidth);
+ const float scaleY = float(bmp.GetHeight()) / float(m_pageHeight);
+
+ wxMemoryDC bmpDC;
+ bmpDC.SelectObject(bmp);
+ bmpDC.Clear();
+
+ const int initialStep = ComputeFragmentSize(printerDC.GetDepth(),
+ m_pageWidth, m_pageHeight);
+
+ wxRect todo(0, 0, m_pageWidth, initialStep); // rect to render
+ int nextFinalLine = 0; // first not-yet-rendered output line
+
+ while ( todo.y < m_pageHeight )
+ {
+ todo.SetBottom(wxMin(todo.GetBottom(), m_pageHeight - 1));
+
+ if ( !RenderPageFragment(scaleX, scaleY,
+ &nextFinalLine,
+ printerDC,
+ bmpDC,
+ todo,
+ pageNum) )
+ {
+ if ( todo.height < 20 )
+ {
+ // something is very wrong if we can't render even at this
+ // slow space, let's bail out and fall back to low quality
+ // preview
+ wxLogTrace("printing",
+ "it seems that HQ preview doesn't work at all");
+ return false;
+ }
+
+ // it's possible our memory calculation was off, or conditions
+ // changed, or there's not enough _bitmap_ resources; try if using
+ // smaller bitmap would help:
+ todo.height /= 2;
+
+ wxLogTrace("printing",
+ "preview of fragment failed, reducing height to %ipx",
+ todo.height);
+
+ continue; // retry at the same position again
+ }
+
+ // move to the next segment
+ todo.Offset(0, todo.height);
+ }
+
+ return true;
+}
+
+bool wxWindowsPrintPreview::RenderPageIntoBitmap(wxBitmap& bmp, int pageNum)
+{
+ // try high quality rendering first:
+ if ( !m_hqPreviewFailed )
+ {
+ if ( RenderPageIntoBitmapHQ(bmp, pageNum) )
+ {
+ return true;
+ }
+ else
+ {
+ wxLogTrace("printing",
+ "high-quality preview failed, falling back to normal");
+ m_hqPreviewFailed = true; // don't bother re-trying
+ }
+ }
+
+ // if it fails, use the generic method that is less resource intensive,
+ // but inexact
+ return wxPrintPreviewBase::RenderPageIntoBitmap(bmp, pageNum);
+}
+
+#endif // wxUSE_HIGH_QUALITY_PREVIEW
+