CPDFDoc_Environment::GetAnnotHandlerMgr() never returns nullptr.
[pdfium.git] / fpdfsdk / src / fpdf_progressive.cpp
index 29496e0..b13eb55 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include "../include/fpdf_progressive.h"\r
-#include "../include/fsdk_define.h"\r
-#include "../include/fpdfview.h"\r
-#include "../include/fsdk_rendercontext.h"\r
-\r
-extern void (*Func_RenderPage)( CRenderContext*, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,\r
-                                               int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter * pause );\r
-\r
-extern void DropContext(void* data);\r
-\r
-DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start( FPDF_BITMAP bitmap, FPDF_PAGE page, \r
-                                                                                                       int start_x, int start_y, int size_x,\r
-                                                                                                   int size_y, int rotate, int flags,\r
-                                                                                                       IFSDK_PAUSE * pause )\r
-{\r
-       if (bitmap == NULL || page == NULL)\r
-               return FPDF_RENDER_FAILED;\r
-\r
-       if (!pause)\r
-               return FPDF_RENDER_FAILED;\r
-\r
-       if (pause->version !=1)\r
-               return FPDF_RENDER_FAILED;\r
-\r
-       CPDF_Page* pPage = (CPDF_Page*)page;\r
-       \r
-//     FXMT_CSLOCK_OBJ(&pPage->m_PageLock);\r
-       \r
-       CRenderContext* pContext = FX_NEW CRenderContext;\r
-       pPage->SetPrivateData((void*)1, pContext, DropContext );\r
-#ifdef _SKIA_SUPPORT_\r
-       pContext->m_pDevice = FX_NEW CFX_SkiaDevice;\r
-       if (flags & FPDF_REVERSE_BYTE_ORDER)\r
-               ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);\r
-       else\r
-               ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);\r
-#else\r
-       pContext->m_pDevice = FX_NEW CFX_FxgeDevice;\r
-       if (flags & FPDF_REVERSE_BYTE_ORDER)\r
-               ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);\r
-       else\r
-               ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);\r
-#endif\r
-       IFSDK_PAUSE_Adapter IPauseAdapter(pause);\r
-       \r
-       if (flags & FPDF_NO_CATCH)\r
-               Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,FALSE, &IPauseAdapter);\r
-       else {\r
-               try {\r
-                       Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,FALSE, &IPauseAdapter);\r
-                       }\r
-               catch (...){}\r
-       }\r
-\r
-       if ( pContext->m_pRenderer )\r
-       {\r
-               CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed;\r
-               status = pContext->m_pRenderer->GetStatus();\r
-               return status;\r
-       }\r
-       return FPDF_RENDER_FAILED;\r
-}\r
-\r
-DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,IFSDK_PAUSE * pause)\r
-{\r
-       if (page == NULL)\r
-               return FPDF_RENDER_FAILED;\r
-\r
-       if (!pause)\r
-               return FPDF_RENDER_FAILED;\r
-       \r
-       if (pause->version !=1)\r
-               return FPDF_RENDER_FAILED;\r
-\r
-       CPDF_Page* pPage = (CPDF_Page*)page;\r
-\r
-//     FXMT_CSLOCK_OBJ(&pPage->m_PageLock);\r
-\r
-       CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);\r
-       if (pContext && pContext->m_pRenderer)\r
-       {\r
-               IFSDK_PAUSE_Adapter IPauseAdapter(pause);\r
-               pContext->m_pRenderer->Continue(&IPauseAdapter);\r
-\r
-               CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed;\r
-               status = pContext->m_pRenderer->GetStatus();\r
-               return status;\r
-       }\r
-       return FPDF_RENDER_FAILED;\r
-}\r
-\r
-\r
-DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page)\r
-{\r
-       if (page == NULL) return;\r
-       CPDF_Page* pPage = (CPDF_Page*)page;\r
-\r
-//     FXMT_CSLOCK_OBJ(&pPage->m_PageLock);\r
-\r
-       CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);\r
-       if (pContext)\r
-       {\r
-               pContext->m_pDevice->RestoreState();\r
-               delete pContext;\r
-               pPage->RemovePrivateData((void*)1);\r
-       }\r
-}\r
-\r
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../public/fpdf_progressive.h"
+#include "../../public/fpdfview.h"
+#include "../include/fsdk_define.h"
+#include "../include/fsdk_rendercontext.h"
+
+DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap,
+                                                  FPDF_PAGE page,
+                                                  int start_x,
+                                                  int start_y,
+                                                  int size_x,
+                                                  int size_y,
+                                                  int rotate,
+                                                  int flags,
+                                                  IFSDK_PAUSE* pause) {
+  if (!bitmap || !pause || pause->version != 1)
+    return FPDF_RENDER_FAILED;
+
+  CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
+  if (!pPage)
+    return FPDF_RENDER_FAILED;
+
+  CRenderContext* pContext = new CRenderContext;
+  pPage->SetPrivateData((void*)1, pContext, DropContext);
+#ifdef _SKIA_SUPPORT_
+  pContext->m_pDevice = new CFX_SkiaDevice;
+  if (flags & FPDF_REVERSE_BYTE_ORDER)
+    ((CFX_SkiaDevice*)pContext->m_pDevice)
+        ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE);
+  else
+    ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
+#else
+  pContext->m_pDevice = new CFX_FxgeDevice;
+  if (flags & FPDF_REVERSE_BYTE_ORDER)
+    ((CFX_FxgeDevice*)pContext->m_pDevice)
+        ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE);
+  else
+    ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
+#endif
+  IFSDK_PAUSE_Adapter IPauseAdapter(pause);
+
+  FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
+                         rotate, flags, FALSE, &IPauseAdapter);
+
+  if (pContext->m_pRenderer)
+    return CPDF_ProgressiveRenderer::ToFPDFStatus(
+        pContext->m_pRenderer->GetStatus());
+
+  return FPDF_RENDER_FAILED;
+}
+
+DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,
+                                               IFSDK_PAUSE* pause) {
+  if (!pause || pause->version != 1)
+    return FPDF_RENDER_FAILED;
+
+  CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
+  if (!pPage)
+    return FPDF_RENDER_FAILED;
+
+  CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
+  if (pContext && pContext->m_pRenderer) {
+    IFSDK_PAUSE_Adapter IPauseAdapter(pause);
+    pContext->m_pRenderer->Continue(&IPauseAdapter);
+    return CPDF_ProgressiveRenderer::ToFPDFStatus(
+        pContext->m_pRenderer->GetStatus());
+  }
+  return FPDF_RENDER_FAILED;
+}
+
+DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) {
+  CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
+  if (!pPage)
+    return;
+
+  CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
+  if (!pContext)
+    return;
+
+  pContext->m_pDevice->RestoreState();
+  delete pContext;
+  pPage->RemovePrivateData((void*)1);
+}