Convert CPDF_ColorSpaceMap to std::map.
[pdfium.git] / core / src / fpdfapi / fpdf_render / fpdf_render.cpp
index ab1ddb6..a98c57d 100644 (file)
@@ -59,15 +59,15 @@ void CPDF_DocRenderData::Clear(FX_BOOL bRelease)
 }
 FX_BOOL CPDF_DocRenderData::Initialize()
 {
-    m_pFontCache = FX_NEW CFX_FontCache;
+    m_pFontCache = new CFX_FontCache;
     return TRUE;
 }
 CPDF_Type3Cache* CPDF_DocRenderData::GetCachedType3(CPDF_Type3Font* pFont)
 {
     CPDF_CountedObject<CPDF_Type3Cache*>* pCache;
     if (!m_Type3FaceMap.Lookup(pFont, pCache)) {
-        CPDF_Type3Cache* pType3 = FX_NEW CPDF_Type3Cache(pFont);
-        pCache = FX_NEW CPDF_CountedObject<CPDF_Type3Cache*>;
+        CPDF_Type3Cache* pType3 = new CPDF_Type3Cache(pFont);
+        pCache = new CPDF_CountedObject<CPDF_Type3Cache*>;
         pCache->m_Obj = pType3;
         pCache->m_nCount = 1;
         m_Type3FaceMap.SetAt(pFont, pCache);
@@ -100,7 +100,7 @@ public:
     }
     virtual CPDF_PageRenderCache*      CreatePageCache(CPDF_Page* pPage)
     {
-        return FX_NEW CPDF_PageRenderCache(pPage);
+        return new CPDF_PageRenderCache(pPage);
     }
     virtual void       DestroyPageCache(CPDF_PageRenderCache* pCache);
     virtual CPDF_RenderConfig* GetConfig()
@@ -113,7 +113,7 @@ private:
 };
 CPDF_DocRenderData*    CPDF_RenderModule::CreateDocData(CPDF_Document* pDoc)
 {
-    CPDF_DocRenderData* pData = FX_NEW CPDF_DocRenderData(pDoc);
+    CPDF_DocRenderData* pData = new CPDF_DocRenderData(pDoc);
     pData->Initialize();
     return pData;
 }
@@ -133,10 +133,8 @@ void CPDF_RenderModule::DestroyPageCache(CPDF_PageRenderCache* pCache)
 }
 void CPDF_ModuleMgr::InitRenderModule()
 {
-    if (m_pRenderModule) {
-        delete m_pRenderModule;
-    }
-    m_pRenderModule = FX_NEW CPDF_RenderModule;
+    delete m_pRenderModule;
+    m_pRenderModule = new CPDF_RenderModule;
 }
 CPDF_RenderOptions::CPDF_RenderOptions()
     : m_ColorMode(RENDER_COLOR_NORMAL)
@@ -180,11 +178,14 @@ FX_ARGB CPDF_RenderOptions::TranslateColor(FX_ARGB argb) const
     b = (bb - fb) * gray / 255 + fb;
     return ArgbEncode(a, r, g, b);
 }
+
+// static
+int CPDF_RenderStatus::s_CurrentRecursionDepth = 0;
+
 CPDF_RenderStatus::CPDF_RenderStatus()
 {
     m_pContext = NULL;
     m_bStopped = FALSE;
-    m_Level = 0;
     m_pDevice = NULL;
     m_pCurObj = NULL;
     m_pStopObj = NULL;
@@ -203,13 +204,15 @@ CPDF_RenderStatus::CPDF_RenderStatus()
     m_pPageResource = NULL;
     m_curBlend = FXDIB_BLEND_NORMAL;
 }
+
 CPDF_RenderStatus::~CPDF_RenderStatus()
 {
     if (m_pObjectRenderer) {
         delete m_pObjectRenderer;
     }
 }
-FX_BOOL CPDF_RenderStatus::Initialize(int level, CPDF_RenderContext* pContext, CFX_RenderDevice* pDevice,
+
+FX_BOOL CPDF_RenderStatus::Initialize(CPDF_RenderContext* pContext, CFX_RenderDevice* pDevice,
                                       const CFX_AffineMatrix* pDeviceMatrix, const CPDF_PageObject* pStopObj,
                                       const CPDF_RenderStatus* pParentState, const CPDF_GraphicStates* pInitialStates,
                                       const CPDF_RenderOptions* pOptions, int transparency, FX_BOOL bDropObjects,
@@ -217,7 +220,6 @@ FX_BOOL CPDF_RenderStatus::Initialize(int level, CPDF_RenderContext* pContext, C
                                       FX_ARGB fill_color, FX_DWORD GroupFamily,
                                       FX_BOOL bLoadMask)
 {
-    m_Level = level;
     m_pContext = pContext;
     m_pDevice = pDevice;
     m_DitherBits = pDevice->GetDeviceCaps(FXDC_DITHER_BITS);
@@ -262,9 +264,6 @@ FX_BOOL CPDF_RenderStatus::Initialize(int level, CPDF_RenderContext* pContext, C
 }
 void CPDF_RenderStatus::RenderObjectList(const CPDF_PageObjects* pObjs, const CFX_AffineMatrix* pObj2Device)
 {
-    if (m_Level > 32) {
-        return;
-    }
     CFX_FloatRect clip_rect = m_pDevice->GetClipBox();
     CFX_AffineMatrix device2object;
     device2object.SetReverse(*pObj2Device);
@@ -293,14 +292,16 @@ void CPDF_RenderStatus::RenderObjectList(const CPDF_PageObjects* pObjs, const CF
 }
 void CPDF_RenderStatus::RenderSingleObject(const CPDF_PageObject* pObj, const CFX_AffineMatrix* pObj2Device)
 {
-    if (m_Level > 32) {
+    CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth);
+    if (++s_CurrentRecursionDepth > kRenderMaxRecursionDepth) {
         return;
     }
     m_pCurObj = pObj;
-    if (m_Options.m_pOCContext && pObj->m_ContentMark.NotNull())
+    if (m_Options.m_pOCContext && pObj->m_ContentMark.NotNull()) {
         if (!m_Options.m_pOCContext->CheckObjectVisible(pObj)) {
             return;
         }
+    }
     ProcessClipPath(pObj->m_ClipPath, pObj2Device);
     if (ProcessTransparency(pObj, pObj2Device)) {
         return;
@@ -346,11 +347,10 @@ FX_BOOL CPDF_RenderStatus::ContinueSingleObject(const CPDF_PageObject* pObj, con
 }
 IPDF_ObjectRenderer* IPDF_ObjectRenderer::Create(int type)
 {
-    IPDF_ObjectRenderer* pRenderer = NULL;
-    if (type == PDFPAGE_IMAGE) {
-        pRenderer = FX_NEW CPDF_ImageRenderer;
+    if (type != PDFPAGE_IMAGE) {
+        return NULL;
     }
-    return pRenderer;
+    return new CPDF_ImageRenderer;
 }
 FX_BOOL CPDF_RenderStatus::GetObjectClippedRect(const CPDF_PageObject* pObj, const CFX_AffineMatrix* pObj2Device, FX_BOOL bLogical, FX_RECT &rect) const
 {
@@ -361,10 +361,10 @@ FX_BOOL CPDF_RenderStatus::GetObjectClippedRect(const CPDF_PageObject* pObj, con
         FX_FLOAT a = FXSYS_fabs(dCTM.a);
         FX_FLOAT d = FXSYS_fabs(dCTM.d);
         if (a != 1.0f || d != 1.0f) {
-            rect.right = rect.left + (FX_INT32)FXSYS_ceil((FX_FLOAT)rect.Width() * a);
-            rect.bottom = rect.top + (FX_INT32)FXSYS_ceil((FX_FLOAT)rect.Height() * d);
-            rtClip.right = rtClip.left + (FX_INT32)FXSYS_ceil((FX_FLOAT)rtClip.Width() * a);
-            rtClip.bottom = rtClip.top + (FX_INT32)FXSYS_ceil((FX_FLOAT)rtClip.Height() * d);
+            rect.right = rect.left + (int32_t)FXSYS_ceil((FX_FLOAT)rect.Width() * a);
+            rect.bottom = rect.top + (int32_t)FXSYS_ceil((FX_FLOAT)rect.Height() * d);
+            rtClip.right = rtClip.left + (int32_t)FXSYS_ceil((FX_FLOAT)rtClip.Width() * a);
+            rtClip.bottom = rtClip.top + (int32_t)FXSYS_ceil((FX_FLOAT)rtClip.Height() * d);
         }
     }
     rect.Intersect(rtClip);
@@ -462,7 +462,7 @@ void CPDF_RenderStatus::DrawObjWithBackground(const CPDF_PageObject* pObj, const
         }
     }
     CPDF_RenderStatus status;
-    status.Initialize(m_Level + 1, m_pContext, buffer.GetDevice(), buffer.GetMatrix(), NULL, NULL, NULL, &m_Options, m_Transparency, m_bDropObjects, pFormResource);
+    status.Initialize(m_pContext, buffer.GetDevice(), buffer.GetMatrix(), NULL, NULL, NULL, &m_Options, m_Transparency, m_bDropObjects, pFormResource);
     status.RenderSingleObject(pObj, &matrix);
     buffer.OutputToDevice();
 }
@@ -479,7 +479,7 @@ FX_BOOL CPDF_RenderStatus::ProcessForm(CPDF_FormObject* pFormObj, const CFX_Affi
         pResources = pFormObj->m_pForm->m_pFormDict->GetDict(FX_BSTRC("Resources"));
     }
     CPDF_RenderStatus status;
-    status.Initialize(m_Level + 1, m_pContext, m_pDevice, NULL, m_pStopObj,
+    status.Initialize(m_pContext, m_pDevice, NULL, m_pStopObj,
                       this, pFormObj, &m_Options, m_Transparency, m_bDropObjects, pResources, FALSE);
     status.m_curBlend = m_curBlend;
     m_pDevice->SaveState();
@@ -568,7 +568,7 @@ FX_ARGB CPDF_RenderStatus::GetFillArgb(const CPDF_PageObject* pObj, FX_BOOL bTyp
     const CPDF_GeneralStateData* pGeneralData = pObj->m_GeneralState;
     int alpha;
     if (pGeneralData) {
-        alpha = (FX_INT32)(pGeneralData->m_FillAlpha * 255);
+        alpha = (int32_t)(pGeneralData->m_FillAlpha * 255);
         if (pGeneralData->m_pTR) {
             if (!pGeneralData->m_pTransferFunc) {
                 ((CPDF_GeneralStateData*)pGeneralData)->m_pTransferFunc = GetTransferFunc(pGeneralData->m_pTR);
@@ -597,7 +597,7 @@ FX_ARGB CPDF_RenderStatus::GetStrokeArgb(const CPDF_PageObject* pObj) const
     const CPDF_GeneralStateData* pGeneralData = pObj->m_GeneralState;
     int alpha;
     if (pGeneralData) {
-        alpha = (FX_INT32)(pGeneralData->m_StrokeAlpha * 255);
+        alpha = (int32_t)(pGeneralData->m_StrokeAlpha * 255);
         if (pGeneralData->m_pTR) {
             if (!pGeneralData->m_pTransferFunc) {
                 ((CPDF_GeneralStateData*)pGeneralData)->m_pTransferFunc = GetTransferFunc(pGeneralData->m_pTR);
@@ -665,7 +665,7 @@ void CPDF_RenderStatus::ProcessClipPath(CPDF_ClipPath ClipPath, const CFX_Affine
             }
         } else {
             if (pTextClippingPath == NULL) {
-                pTextClippingPath = FX_NEW CFX_PathData;
+                pTextClippingPath = new CFX_PathData;
             }
             ProcessText(pText, pObj2Device, pTextClippingPath);
         }
@@ -800,7 +800,7 @@ FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj,
     CFX_FxgeDevice bitmap_device;
     CFX_DIBitmap* oriDevice = NULL;
     if (!isolated && (m_pDevice->GetRenderCaps() & FXRC_GET_BITS)) {
-        oriDevice = FX_NEW CFX_DIBitmap;
+        oriDevice = new CFX_DIBitmap;
         if (!m_pDevice->CreateCompatibleBitmap(oriDevice, width, height)) {
             return TRUE;
         }
@@ -816,7 +816,7 @@ FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj,
     new_matrix.Scale(scaleX, scaleY);
     CFX_DIBitmap* pTextMask = NULL;
     if (bTextClip) {
-        pTextMask = FX_NEW CFX_DIBitmap;
+        pTextMask = new CFX_DIBitmap;
         if (!pTextMask->Create(width, height, FXDIB_8bppMask)) {
             delete pTextMask;
             return TRUE;
@@ -837,7 +837,7 @@ FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj,
         }
     }
     CPDF_RenderStatus bitmap_render;
-    bitmap_render.Initialize(m_Level + 1, m_pContext, &bitmap_device, NULL,
+    bitmap_render.Initialize(m_pContext, &bitmap_device, NULL,
                              m_pStopObj, NULL, NULL, &m_Options, 0, m_bDropObjects, pFormResource, TRUE);
     bitmap_render.ProcessObjectNoClip(pPageObj, &new_matrix);
     m_bStopped = bitmap_render.m_bStopped;
@@ -857,7 +857,7 @@ FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj,
         pTextMask = NULL;
     }
     if (Transparency & PDFTRANS_GROUP && group_alpha != 1.0f) {
-        bitmap->MultiplyAlpha((FX_INT32)(group_alpha * 255));
+        bitmap->MultiplyAlpha((int32_t)(group_alpha * 255));
     }
     Transparency = m_Transparency;
     if (pPageObj->m_Type == PDFPAGE_FORM) {
@@ -881,7 +881,7 @@ CFX_DIBitmap* CPDF_RenderStatus::GetBackdrop(const CPDF_PageObject* pObj, const
     FX_FLOAT scaleY = FXSYS_fabs(deviceCTM.d);
     int width = FXSYS_round(bbox.Width() * scaleX);
     int height = FXSYS_round(bbox.Height() * scaleY);
-    CFX_DIBitmap* pBackdrop = FX_NEW CFX_DIBitmap;
+    CFX_DIBitmap* pBackdrop = new CFX_DIBitmap;
     if (bBackAlphaRequired && !m_bDropObjects) {
         pBackdrop->Create(width, height, FXDIB_Argb);
     } else {
@@ -915,12 +915,9 @@ void CPDF_RenderContext::GetBackground(CFX_DIBitmap* pBuffer, const CPDF_PageObj
 {
     CFX_FxgeDevice device;
     device.Attach(pBuffer);
-    if (m_pBackgroundDraw) {
-        m_pBackgroundDraw->OnDrawBackground(&device, pFinalMatrix);
-    } else {
-        FX_RECT rect(0, 0, device.GetWidth(), device.GetHeight());
-        device.FillRect(&rect, 0xffffffff);
-    }
+
+    FX_RECT rect(0, 0, device.GetWidth(), device.GetHeight());
+    device.FillRect(&rect, 0xffffffff);
     Render(&device, pObj, pOptions, pFinalMatrix);
 }
 CPDF_GraphicStates* CPDF_RenderStatus::CloneObjStates(const CPDF_GraphicStates* pSrcStates, FX_BOOL bStroke)
@@ -928,10 +925,7 @@ CPDF_GraphicStates* CPDF_RenderStatus::CloneObjStates(const CPDF_GraphicStates*
     if (!pSrcStates) {
         return NULL;
     }
-    CPDF_GraphicStates* pStates = FX_NEW CPDF_GraphicStates;
-    if (!pStates) {
-        return NULL;
-    }
+    CPDF_GraphicStates* pStates = new CPDF_GraphicStates;
     pStates->CopyStates(*pSrcStates);
     CPDF_Color* pObjColor = bStroke ? pSrcStates->m_ColorState.GetStrokeColor() :
                             pSrcStates->m_ColorState.GetFillColor();
@@ -949,7 +943,6 @@ CPDF_RenderContext::CPDF_RenderContext()
 void CPDF_RenderContext::Create(CPDF_Document* pDoc, CPDF_PageRenderCache* pPageCache,
                                 CPDF_Dictionary* pPageResources, FX_BOOL bFirstLayer)
 {
-    m_pBackgroundDraw = NULL;
     m_pDocument = pDoc;
     m_pPageResources = pPageResources;
     m_pPageCache = pPageCache;
@@ -957,7 +950,6 @@ void CPDF_RenderContext::Create(CPDF_Document* pDoc, CPDF_PageRenderCache* pPage
 }
 void CPDF_RenderContext::Create(CPDF_Page* pPage, FX_BOOL bFirstLayer)
 {
-    m_pBackgroundDraw = NULL;
     m_pDocument = pPage->m_pDocument;
     m_pPageResources = pPage->m_pPageResources;
     m_pPageCache = pPage->GetRenderCache();
@@ -971,7 +963,6 @@ void CPDF_RenderContext::Clear()
     m_pDocument = NULL;
     m_pPageResources = NULL;
     m_pPageCache = NULL;
-    m_pBackgroundDraw = NULL;
     m_bFirstLayer = TRUE;
     m_ContentList.RemoveAll();
 }
@@ -1001,7 +992,7 @@ void CPDF_RenderContext::Render(CFX_RenderDevice* pDevice, const CPDF_PageObject
             CFX_AffineMatrix FinalMatrix = pItem->m_Matrix;
             FinalMatrix.Concat(*pLastMatrix);
             CPDF_RenderStatus status;
-            status.Initialize(0, this, pDevice, pLastMatrix, pStopObj, NULL, NULL, pOptions,
+            status.Initialize(this, pDevice, pLastMatrix, pStopObj, NULL, NULL, pOptions,
                               pItem->m_pObjectList->m_Transparency, FALSE, NULL);
             status.RenderObjectList(pItem->m_pObjectList, &FinalMatrix);
             if (status.m_Options.m_Flags & RENDER_LIMITEDIMAGECACHE) {
@@ -1013,7 +1004,7 @@ void CPDF_RenderContext::Render(CFX_RenderDevice* pDevice, const CPDF_PageObject
             }
         } else {
             CPDF_RenderStatus status;
-            status.Initialize(0, this, pDevice, NULL, pStopObj, NULL, NULL, pOptions,
+            status.Initialize(this, pDevice, NULL, pStopObj, NULL, NULL, pOptions,
                               pItem->m_pObjectList->m_Transparency, FALSE, NULL);
             status.RenderObjectList(pItem->m_pObjectList, &pItem->m_Matrix);
             if (status.m_Options.m_Flags & RENDER_LIMITEDIMAGECACHE) {
@@ -1116,8 +1107,8 @@ void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause)
         if (m_pRenderer == NULL) {
             m_ObjectPos = pItem->m_pObjectList->GetFirstObjectPosition();
             m_ObjectIndex = 0;
-            m_pRenderer = FX_NEW CPDF_RenderStatus();
-            m_pRenderer->Initialize(0, m_pContext, m_pDevice, NULL, NULL, NULL, NULL,
+            m_pRenderer = new CPDF_RenderStatus();
+            m_pRenderer->Initialize(m_pContext, m_pDevice, NULL, NULL, NULL, NULL,
                                     m_pOptions, pItem->m_pObjectList->m_Transparency, m_bDropObjects, NULL);
             m_pDevice->SaveState();
             m_ClipRect = m_pDevice->GetClipBox();
@@ -1218,9 +1209,9 @@ CPDF_TransferFunc* CPDF_DocRenderData::GetTransferFunc(CPDF_Object* pObj)
                 return NULL;
             }
         }
-        pTransfer = FX_NEW CPDF_TransferFunc;
+        pTransfer = new CPDF_TransferFunc;
         pTransfer->m_pPDFDoc = m_pPDFDoc;
-        pTransferCounter = FX_NEW CPDF_CountedObject<CPDF_TransferFunc*>;
+        pTransferCounter = new CPDF_CountedObject<CPDF_TransferFunc*>;
         pTransferCounter->m_nCount = 1;
         pTransferCounter->m_Obj = pTransfer;
         m_TransferFuncMap.SetAt(pObj, pTransferCounter);
@@ -1323,7 +1314,7 @@ FX_BOOL CPDF_DeviceBuffer::Initialize(CPDF_RenderContext* pContext, CFX_RenderDe
     CFX_FloatRect rect(*pRect);
     m_Matrix.TransformRect(rect);
     FX_RECT bitmap_rect = rect.GetOutterRect();
-    m_pBitmap = FX_NEW CFX_DIBitmap;
+    m_pBitmap = new CFX_DIBitmap;
     m_pBitmap->Create(bitmap_rect.Width(), bitmap_rect.Height(), FXDIB_Argb);
     return TRUE;
 }
@@ -1378,15 +1369,15 @@ FX_BOOL CPDF_ScaledRenderBuffer::Initialize(CPDF_RenderContext* pContext, CFX_Re
             m_Matrix.Scale(1.0f, (FX_FLOAT)(max_dpi) / (FX_FLOAT)dpiv);
         }
     }
-    m_pBitmapDevice = FX_NEW CFX_FxgeDevice;
+    m_pBitmapDevice = new CFX_FxgeDevice;
     FXDIB_Format dibFormat = FXDIB_Rgb;
-    FX_INT32 bpp = 24;
+    int32_t bpp = 24;
     if (m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_ALPHA_OUTPUT) {
         dibFormat = FXDIB_Argb;
         bpp = 32;
     }
     CFX_FloatRect rect;
-    FX_INT32 iWidth, iHeight, iPitch;
+    int32_t iWidth, iHeight, iPitch;
     while (1) {
         rect = *pRect;
         m_Matrix.TransformRect(rect);