Expose additional flags for rasterization.
[pdfium.git] / fpdfsdk / src / fpdfview.cpp
index fba5d65..3207ebe 100644 (file)
@@ -10,7 +10,8 @@
 #include "../include/fsdk_rendercontext.h"
 #include "../include/fpdf_progressive.h"
 #include "../include/fpdf_ext.h"
-#include "../../third_party/numerics/safe_conversions_impl.h"
+#include "../../../core/src/fxcrt/fx_safe_types.h"
+#include "../../third_party/base/numerics/safe_conversions_impl.h"
 
 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess)
 {
@@ -23,7 +24,7 @@ FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, FX_FILESIZE offset, size_t si
     if (offset < 0) {
         return FALSE;
     }
-    FX_SAFE_FILESIZE newPos = base::checked_cast<FX_FILESIZE, size_t>(size);
+    FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE, size_t>(size);
     newPos += offset;
     if (!newPos.IsValid() || newPos.ValueOrDie() > m_FileAccess.m_FileLen) {
         return FALSE;
@@ -183,7 +184,7 @@ DLLEXPORT void      STDCALL FPDF_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable
 
 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BYTESTRING password)
 {
-       CPDF_Parser* pParser = FX_NEW CPDF_Parser;
+       CPDF_Parser* pParser = new CPDF_Parser;
        pParser->SetPassword(password);
 
        FX_DWORD err_code = pParser->StartParse((FX_LPCSTR)file_path);
@@ -197,7 +198,7 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BY
 
 extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code);
 
-class CMemFile FX_FINAL: public IFX_FileRead, public CFX_Object
+class CMemFile FX_FINAL: public IFX_FileRead
 {
 public:
        CMemFile(FX_BYTE* pBuf, FX_FILESIZE size):m_pBuf(pBuf),m_size(size) {}
@@ -209,7 +210,7 @@ public:
             if (offset < 0) {
                 return FALSE;
             }
-            FX_SAFE_FILESIZE newPos = base::checked_cast<FX_FILESIZE, size_t>(size);
+            FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE, size_t>(size);
             newPos += offset;
             if (!newPos.IsValid() || newPos.ValueOrDie() > (FX_DWORD)m_size) {
                 return FALSE;
@@ -223,9 +224,9 @@ private:
 };
 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int size, FPDF_BYTESTRING password)
 {
-       CPDF_Parser* pParser = FX_NEW CPDF_Parser;
+       CPDF_Parser* pParser = new CPDF_Parser;
        pParser->SetPassword(password);
-       CMemFile* pMemFile = FX_NEW CMemFile((FX_BYTE*)data_buf, size);
+       CMemFile* pMemFile = new CMemFile((FX_BYTE*)data_buf, size);
        FX_DWORD err_code = pParser->StartParse(pMemFile);
        if (err_code) {
                delete pParser;
@@ -240,9 +241,9 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int s
 
 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, FPDF_BYTESTRING password)
 {
-       CPDF_Parser* pParser = FX_NEW CPDF_Parser;
+       CPDF_Parser* pParser = new CPDF_Parser;
        pParser->SetPassword(password);
-       CPDF_CustomAccess* pFile = FX_NEW CPDF_CustomAccess(pFileAccess);
+       CPDF_CustomAccess* pFile = new CPDF_CustomAccess(pFileAccess);
        FX_DWORD err_code = pParser->StartParse(pFile);
        if (err_code) {
                delete pParser;
@@ -300,17 +301,14 @@ DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, int page_index
 {
        if (document == NULL) return NULL;
        if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) return NULL;
-//     CPDF_Parser* pParser = (CPDF_Parser*)document;
+
        CPDF_Document* pDoc = (CPDF_Document*)document;
        if (pDoc == NULL) return NULL;
        CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
        if (pDict == NULL) return NULL;
-       CPDF_Page* pPage = FX_NEW CPDF_Page;
+       CPDF_Page* pPage = new CPDF_Page;
        pPage->Load(pDoc, pDict);
        pPage->ParseContent();
-       
-//     CheckUnSupportError(pDoc, 0);
-
        return pPage;
 }
 
@@ -348,7 +346,7 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int
        if (page==NULL) return;
        CPDF_Page* pPage = (CPDF_Page*)page;
 
-       CRenderContext* pContext = FX_NEW CRenderContext;
+       CRenderContext* pContext = new CRenderContext;
        pPage->SetPrivateData((void*)1, pContext, DropContext);
 
 #ifndef _WIN32_WCE
@@ -358,19 +356,19 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int
        if (bBackgroundAlphaNeeded)
        {
                
-               pBitmap = FX_NEW CFX_DIBitmap;
+               pBitmap = new CFX_DIBitmap;
                pBitmap->Create(size_x, size_y, FXDIB_Argb);
                pBitmap->Clear(0x00ffffff);
 #ifdef _SKIA_SUPPORT_
-               pContext->m_pDevice = FX_NEW CFX_SkiaDevice;
+               pContext->m_pDevice = new CFX_SkiaDevice;
                ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pBitmap);
 #else
-               pContext->m_pDevice = FX_NEW CFX_FxgeDevice;
+               pContext->m_pDevice = new CFX_FxgeDevice;
                ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pBitmap);
 #endif
        }
        else
-           pContext->m_pDevice = FX_NEW CFX_WindowsDevice(dc);
+           pContext->m_pDevice = new CFX_WindowsDevice(dc);
 
        Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,TRUE,NULL);
 
@@ -382,7 +380,7 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int
                        
                        if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER)
                        {
-                               CFX_DIBitmap* pDst = FX_NEW CFX_DIBitmap;
+                               CFX_DIBitmap* pDst = new CFX_DIBitmap;
                                int pitch = pBitmap->GetPitch();
                                pDst->Create(size_x, size_y, FXDIB_Rgb32);
                                FXSYS_memset(pDst->GetBuffer(), -1, pitch*size_y);
@@ -410,7 +408,8 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int
 #ifdef DEBUG_TRACE
        {
                char str[128];
-               sprintf(str, "Rendering DIB %d x %d", width, height);
+               memset(str, 0, sizeof(str));
+               FXSYS_snprintf(str, sizeof(str) - 1, "Rendering DIB %d x %d", width, height);
                CPDF_ModuleMgr::Get()->ReportError(999, str);
        }
 #endif
@@ -428,7 +427,8 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int
        if (pContext->m_hBitmap == NULL) {
 #if defined(DEBUG) || defined(_DEBUG)
                char str[128];
-               sprintf(str, "Error CreateDIBSection: %d x %d, error code = %d", width, height, GetLastError());
+               memset(str, 0, sizeof(str));
+               FXSYS_snprintf(str, sizeof(str) - 1, "Error CreateDIBSection: %d x %d, error code = %d", width, height, GetLastError());
                CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str);
 #else
                CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL);
@@ -443,11 +443,11 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int
 #endif
 
        // Create a device with this external buffer
-       pContext->m_pBitmap = FX_NEW CFX_DIBitmap;
+       pContext->m_pBitmap = new CFX_DIBitmap;
        pContext->m_pBitmap->Create(width, height, FXDIB_Rgb, (FX_LPBYTE)pBuffer);
-       pContext->m_pDevice = FX_NEW CPDF_FxgeDevice;
+       pContext->m_pDevice = new CPDF_FxgeDevice;
        ((CPDF_FxgeDevice*)pContext->m_pDevice)->Attach(pContext->m_pBitmap);
-       
+
 #ifdef DEBUG_TRACE
        CPDF_ModuleMgr::Get()->ReportError(999, "Ready for PDF rendering");
 #endif
@@ -464,7 +464,8 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int
        if (hMemDC == NULL) {
 #if defined(DEBUG) || defined(_DEBUG)
                char str[128];
-               sprintf(str, "Error CreateCompatibleDC. Error code = %d", GetLastError());
+               memset(str, 0, sizeof(str));
+               FXSYS_snprintf(str, sizeof(str) - 1, "Error CreateCompatibleDC. Error code = %d", GetLastError());
                CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str);
 #else
                CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL);
@@ -504,17 +505,17 @@ DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, FPDF_PAGE page,
        CPDF_Page* pPage = (CPDF_Page*)page;
 
 
-       CRenderContext* pContext = FX_NEW CRenderContext;
+       CRenderContext* pContext = new CRenderContext;
        pPage->SetPrivateData((void*)1, pContext, DropContext);
 #ifdef _SKIA_SUPPORT_
-       pContext->m_pDevice = FX_NEW CFX_SkiaDevice;
+       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 = FX_NEW CFX_FxgeDevice;
+       pContext->m_pDevice = new CFX_FxgeDevice;
 
        if (flags & FPDF_REVERSE_BYTE_ORDER)
                ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);
@@ -596,7 +597,7 @@ DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, int start_x, int start_
 
 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, int height, int alpha)
 {
-       CFX_DIBitmap* pBitmap = FX_NEW CFX_DIBitmap;
+       CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
        pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32);
        return pBitmap;
 }
@@ -620,7 +621,7 @@ DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width, int height, int for
                default:
                        return NULL;
        }
-       CFX_DIBitmap* pBitmap = FX_NEW CFX_DIBitmap;
+       CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
        pBitmap->Create(width, height, fx_format, (FX_LPBYTE)first_scan, stride);
        return pBitmap;
 }
@@ -688,6 +689,12 @@ void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_
                pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE;
        if (flags & FPDF_RENDER_FORCEHALFTONE)
                pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE;
+       if (flags & FPDF_RENDER_NO_SMOOTHTEXT)
+               pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH;
+       if (flags & FPDF_RENDER_NO_SMOOTHIMAGE)
+               pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH;
+       if (flags & FPDF_RENDER_NO_SMOOTHPATH)
+               pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH;
        //Grayscale output
        if (flags & FPDF_GRAYSCALE)
        {
@@ -713,24 +720,22 @@ void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_
        pContext->m_pDevice->SaveState();
        pContext->m_pDevice->SetClip_Rect(&clip);
 
-       pContext->m_pContext = FX_NEW CPDF_RenderContext;
+       pContext->m_pContext = new CPDF_RenderContext;
        pContext->m_pContext->Create(pPage);
        pContext->m_pContext->AppendObjectList(pPage, &matrix);
 
        if (flags & FPDF_ANNOT) {
-               pContext->m_pAnnots = FX_NEW CPDF_AnnotList(pPage);
+               pContext->m_pAnnots = new CPDF_AnnotList(pPage);
                FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY;
                pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext, bPrinting, &matrix, TRUE, NULL);
        }
 
-       pContext->m_pRenderer = FX_NEW CPDF_ProgressiveRenderer;
+       pContext->m_pRenderer = new CPDF_ProgressiveRenderer;
        pContext->m_pRenderer->Start(pContext->m_pContext, pContext->m_pDevice, pContext->m_pOptions, pause);
        if (bNeedToRestore)
        {
          pContext->m_pDevice->RestoreState();
        }
-       
-//#endif
 }
 
 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_index, double* width, double* height)