Bug 1156742 Part 8: Change gfxWindowsSurface, so that a non-printing surface can be used when recording a print. r=roc
authorBob Owen <bobowencode@gmail.com>
Tue, 05 Jan 2016 10:08:57 +0000
changeset 318978 ced236c18d9d457fbc50bcd15e2c6364536e0223
parent 318977 d765b7934fae4c1389ec4d860988a21437aed075
child 318979 f9f91b619a87c5c7142a396b62a5f90145fb3811
push id8951
push userbenj@benj.me
push dateTue, 05 Jan 2016 13:08:54 +0000
reviewersroc
bugs1156742
milestone46.0a1
Bug 1156742 Part 8: Change gfxWindowsSurface, so that a non-printing surface can be used when recording a print. r=roc
gfx/thebes/gfxWindowsSurface.cpp
--- a/gfx/thebes/gfxWindowsSurface.cpp
+++ b/gfx/thebes/gfxWindowsSurface.cpp
@@ -203,16 +203,20 @@ gfxWindowsSurface::GetAsImageSurface()
 }
 
 nsresult
 gfxWindowsSurface::BeginPrinting(const nsAString& aTitle,
                                  const nsAString& aPrintToFileName)
 {
 #ifdef NS_PRINTING
 #define DOC_TITLE_LENGTH (MAX_PATH-1)
+    if (!mForPrinting) {
+        return NS_OK;
+    }
+
     DOCINFOW docinfo;
 
     nsString titleStr(aTitle);
     if (titleStr.Length() > DOC_TITLE_LENGTH) {
         titleStr.SetLength(DOC_TITLE_LENGTH-3);
         titleStr.AppendLiteral("...");
     }
 
@@ -230,58 +234,73 @@ gfxWindowsSurface::BeginPrinting(const n
     return NS_ERROR_FAILURE;
 #endif
 }
 
 nsresult
 gfxWindowsSurface::EndPrinting()
 {
 #ifdef NS_PRINTING
+    if (!mForPrinting) {
+        return NS_OK;
+    }
+
     int result = ::EndDoc(mDC);
     if (result <= 0)
         return NS_ERROR_FAILURE;
 
     return NS_OK;
 #else
     return NS_ERROR_FAILURE;
 #endif
 }
 
 nsresult
 gfxWindowsSurface::AbortPrinting()
 {
 #ifdef NS_PRINTING
+    if (!mForPrinting) {
+        return NS_OK;
+    }
+
     int result = ::AbortDoc(mDC);
     if (result <= 0)
         return NS_ERROR_FAILURE;
     return NS_OK;
 #else
     return NS_ERROR_FAILURE;
 #endif
 }
 
 nsresult
 gfxWindowsSurface::BeginPage()
 {
 #ifdef NS_PRINTING
+    if (!mForPrinting) {
+        return NS_OK;
+    }
+
     int result = ::StartPage(mDC);
     if (result <= 0)
         return NS_ERROR_FAILURE;
     return NS_OK;
 #else
     return NS_ERROR_FAILURE;
 #endif
 }
 
 nsresult
 gfxWindowsSurface::EndPage()
 {
 #ifdef NS_PRINTING
-    if (mForPrinting)
-        cairo_surface_show_page(CairoSurface());
+    if (!mForPrinting) {
+        return NS_OK;
+    }
+
+    cairo_surface_show_page(CairoSurface());
     int result = ::EndPage(mDC);
     if (result <= 0)
         return NS_ERROR_FAILURE;
     return NS_OK;
 #else
     return NS_ERROR_FAILURE;
 #endif
 }