summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render.cpp201
-rw-r--r--core/src/fpdfapi/fpdf_render/render_int.h19
-rw-r--r--core/src/fpdfdoc/doc_ocg.cpp26
-rw-r--r--core/src/fxge/ge/fx_ge_text.cpp76
4 files changed, 163 insertions, 159 deletions
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
index 06c9ea614f..c4a9d7761b 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
@@ -11,43 +11,38 @@
#include "render_int.h"
CPDF_DocRenderData::CPDF_DocRenderData(CPDF_Document* pPDFDoc)
- : m_pPDFDoc(pPDFDoc)
- , m_pFontCache(NULL)
+ : m_pPDFDoc(pPDFDoc),
+ m_pFontCache(new CFX_FontCache)
{
}
+
CPDF_DocRenderData::~CPDF_DocRenderData()
{
Clear(TRUE);
}
+
void CPDF_DocRenderData::Clear(FX_BOOL bRelease)
{
- FX_POSITION pos;
- {
- pos = m_Type3FaceMap.GetStartPosition();
- while (pos) {
- CPDF_Font* pFont;
- CPDF_CountedObject<CPDF_Type3Cache>* cache;
- m_Type3FaceMap.GetNextAssoc(pos, pFont, cache);
- if (bRelease || cache->use_count() < 2) {
- delete cache->get();
- delete cache;
- m_Type3FaceMap.RemoveKey(pFont);
- }
+ for (auto it = m_Type3FaceMap.begin(); it != m_Type3FaceMap.end();) {
+ auto curr_it = it++;
+ CPDF_CountedObject<CPDF_Type3Cache>* cache = curr_it->second;
+ if (bRelease || cache->use_count() < 2) {
+ delete cache->get();
+ delete cache;
+ m_Type3FaceMap.erase(curr_it);
}
}
- {
- pos = m_TransferFuncMap.GetStartPosition();
- while (pos) {
- CPDF_Object* key;
- CPDF_CountedObject<CPDF_TransferFunc>* value;
- m_TransferFuncMap.GetNextAssoc(pos, key, value);
- if (bRelease || value->use_count() < 2) {
- delete value->get();
- delete value;
- m_TransferFuncMap.RemoveKey(key);
- }
+
+ for (auto it = m_TransferFuncMap.begin(); it != m_TransferFuncMap.end();) {
+ auto curr_it = it++;
+ CPDF_CountedObject<CPDF_TransferFunc>* value = curr_it->second;
+ if (bRelease || value->use_count() < 2) {
+ delete value->get();
+ delete value;
+ m_TransferFuncMap.erase(curr_it);
}
}
+
if (m_pFontCache) {
if (bRelease) {
delete m_pFontCache;
@@ -57,26 +52,26 @@ void CPDF_DocRenderData::Clear(FX_BOOL bRelease)
}
}
}
-FX_BOOL CPDF_DocRenderData::Initialize()
-{
- 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)) {
+ auto it = m_Type3FaceMap.find(pFont);
+ if (it == m_Type3FaceMap.end()) {
CPDF_Type3Cache* pType3 = new CPDF_Type3Cache(pFont);
pCache = new CPDF_CountedObject<CPDF_Type3Cache>(pType3);
- m_Type3FaceMap.SetAt(pFont, pCache);
+ m_Type3FaceMap[pFont] = pCache;
+ } else {
+ pCache = it->second;
}
return pCache->AddRef();
}
+
void CPDF_DocRenderData::ReleaseCachedType3(CPDF_Type3Font* pFont)
{
- CPDF_CountedObject<CPDF_Type3Cache>* pCache;
- if (m_Type3FaceMap.Lookup(pFont, pCache))
- pCache->RemoveRef();
+ auto it = m_Type3FaceMap.find(pFont);
+ if (it != m_Type3FaceMap.end())
+ it->second->RemoveRef();
}
class CPDF_RenderModule : public IPDF_RenderModule
@@ -114,9 +109,7 @@ private:
CPDF_DocRenderData* CPDF_RenderModule::CreateDocData(CPDF_Document* pDoc)
{
- CPDF_DocRenderData* pData = new CPDF_DocRenderData(pDoc);
- pData->Initialize();
- return pData;
+ return new CPDF_DocRenderData(pDoc);
}
void CPDF_RenderModule::DestroyDocData(CPDF_DocRenderData* pDocData)
{
@@ -1183,85 +1176,83 @@ int CPDF_ProgressiveRenderer::EstimateProgress()
}
CPDF_TransferFunc* CPDF_DocRenderData::GetTransferFunc(CPDF_Object* pObj)
{
- if (pObj == NULL) {
- return NULL;
+ if (!pObj)
+ return nullptr;
+
+ auto it = m_TransferFuncMap.find(pObj);
+ if (it != m_TransferFuncMap.end()) {
+ CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter = it->second;
+ return pTransferCounter->AddRef();
}
- CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter;
- if (!m_TransferFuncMap.Lookup(pObj, pTransferCounter)) {
- CPDF_TransferFunc* pTransfer = NULL;
- CPDF_Function* pFuncs[3] = {NULL, NULL, NULL};
- FX_BOOL bUniTransfer = TRUE;
- int i;
- FX_BOOL bIdentity = TRUE;
- if (pObj->GetType() == PDFOBJ_ARRAY) {
- bUniTransfer = FALSE;
- CPDF_Array* pArray = (CPDF_Array*)pObj;
- if (pArray->GetCount() < 3) {
- return NULL;
+
+ CPDF_Function* pFuncs[3] = { nullptr, nullptr, nullptr };
+ FX_BOOL bUniTransfer = TRUE;
+ FX_BOOL bIdentity = TRUE;
+ if (pObj->GetType() == PDFOBJ_ARRAY) {
+ bUniTransfer = FALSE;
+ CPDF_Array* pArray = (CPDF_Array*)pObj;
+ if (pArray->GetCount() < 3)
+ return nullptr;
+
+ for (FX_DWORD i = 0; i < 3; ++i) {
+ pFuncs[2 - i] = CPDF_Function::Load(pArray->GetElementValue(i));
+ if (!pFuncs[2 - i]) {
+ return nullptr;
}
- for (FX_DWORD i = 0; i < 3; i ++) {
- pFuncs[2 - i] = CPDF_Function::Load(pArray->GetElementValue(i));
- if (pFuncs[2 - i] == NULL) {
- return NULL;
- }
+ }
+ } else {
+ pFuncs[0] = CPDF_Function::Load(pObj);
+ if (!pFuncs[0]) {
+ return nullptr;
+ }
+ }
+ CPDF_TransferFunc* pTransfer = new CPDF_TransferFunc;
+ pTransfer->m_pPDFDoc = m_pPDFDoc;
+ CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter =
+ new CPDF_CountedObject<CPDF_TransferFunc>(pTransfer);
+ m_TransferFuncMap[pObj] = pTransferCounter;
+ static const int kMaxOutputs = 16;
+ FX_FLOAT output[kMaxOutputs];
+ FXSYS_memset(output, 0, sizeof(output));
+ FX_FLOAT input;
+ int noutput;
+ for (int v = 0; v < 256; ++v) {
+ input = (FX_FLOAT)v / 255.0f;
+ if (bUniTransfer) {
+ if (pFuncs[0] && pFuncs[0]->CountOutputs() <= kMaxOutputs)
+ pFuncs[0]->Call(&input, 1, output, noutput);
+ int o = FXSYS_round(output[0] * 255);
+ if (o != v)
+ bIdentity = FALSE;
+ for (int i = 0; i < 3; ++i) {
+ pTransfer->m_Samples[i * 256 + v] = o;
}
} else {
- pFuncs[0] = CPDF_Function::Load(pObj);
- if (pFuncs[0] == NULL) {
- return NULL;
- }
- }
- pTransfer = new CPDF_TransferFunc;
- pTransfer->m_pPDFDoc = m_pPDFDoc;
- pTransferCounter = new CPDF_CountedObject<CPDF_TransferFunc>(pTransfer);
- m_TransferFuncMap.SetAt(pObj, pTransferCounter);
- static const int kMaxOutputs = 16;
- FX_FLOAT output[kMaxOutputs];
- FXSYS_memset(output, 0, sizeof(output));
- FX_FLOAT input;
- int noutput;
- for (int v = 0; v < 256; v ++) {
- input = (FX_FLOAT)v / 255.0f;
- if (bUniTransfer) {
- if (pFuncs[0] && pFuncs[0]->CountOutputs() <= kMaxOutputs) {
- pFuncs[0]->Call(&input, 1, output, noutput);
- }
- int o = FXSYS_round(output[0] * 255);
- if (o != v) {
- bIdentity = FALSE;
- }
- for (i = 0; i < 3; i ++) {
+ for (int i = 0; i < 3; ++i) {
+ if (pFuncs[i] && pFuncs[i]->CountOutputs() <= kMaxOutputs) {
+ pFuncs[i]->Call(&input, 1, output, noutput);
+ int o = FXSYS_round(output[0] * 255);
+ if (o != v)
+ bIdentity = FALSE;
pTransfer->m_Samples[i * 256 + v] = o;
+ } else {
+ pTransfer->m_Samples[i * 256 + v] = v;
}
- } else
- for (i = 0; i < 3; i ++) {
- if (pFuncs[i] && pFuncs[i]->CountOutputs() <= kMaxOutputs) {
- pFuncs[i]->Call(&input, 1, output, noutput);
- int o = FXSYS_round(output[0] * 255);
- if (o != v) {
- bIdentity = FALSE;
- }
- pTransfer->m_Samples[i * 256 + v] = o;
- } else {
- pTransfer->m_Samples[i * 256 + v] = v;
- }
- }
- }
- for (i = 0; i < 3; i ++)
- if (pFuncs[i]) {
- delete pFuncs[i];
}
- pTransfer->m_bIdentity = bIdentity;
+ }
}
+ for (int i = 0; i < 3; ++i)
+ delete pFuncs[i];
+
+ pTransfer->m_bIdentity = bIdentity;
return pTransferCounter->AddRef();
}
+
void CPDF_DocRenderData::ReleaseTransferFunc(CPDF_Object* pObj)
{
- CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter;
- if (!m_TransferFuncMap.Lookup(pObj, pTransferCounter)) {
- return;
- }
- pTransferCounter->RemoveRef();
+ auto it = m_TransferFuncMap.find(pObj);
+ if (it != m_TransferFuncMap.end())
+ it->second->RemoveRef();
}
CPDF_RenderConfig::CPDF_RenderConfig()
{
diff --git a/core/src/fpdfapi/fpdf_render/render_int.h b/core/src/fpdfapi/fpdf_render/render_int.h
index 7aa8358b8d..77acb15902 100644
--- a/core/src/fpdfapi/fpdf_render/render_int.h
+++ b/core/src/fpdfapi/fpdf_render/render_int.h
@@ -7,6 +7,8 @@
#ifndef CORE_SRC_FPDFAPI_FPDF_RENDER_RENDER_INT_H_
#define CORE_SRC_FPDFAPI_FPDF_RENDER_RENDER_INT_H_
+#include <map>
+
#include "../../../../third_party/base/nonstd_unique_ptr.h"
#include "../../../include/fpdfapi/fpdf_pageobj.h"
@@ -52,14 +54,12 @@ public:
CFX_DIBSource* TranslateImage(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc);
FX_COLORREF TranslateColor(FX_COLORREF src);
};
-typedef CFX_MapPtrTemplate<CPDF_Font*, CPDF_CountedObject<CPDF_Type3Cache>*> CPDF_Type3CacheMap;
-typedef CFX_MapPtrTemplate<CPDF_Object*, CPDF_CountedObject<CPDF_TransferFunc>*> CPDF_TransferFuncMap;
+
class CPDF_DocRenderData
{
public:
CPDF_DocRenderData(CPDF_Document* pPDFDoc = NULL);
~CPDF_DocRenderData();
- FX_BOOL Initialize();
CPDF_Type3Cache* GetCachedType3(CPDF_Type3Font* pFont);
CPDF_TransferFunc* GetTransferFunc(CPDF_Object* pObj);
CFX_FontCache* GetFontCache()
@@ -70,10 +70,15 @@ public:
void ReleaseCachedType3(CPDF_Type3Font* pFont);
void ReleaseTransferFunc(CPDF_Object* pObj);
private:
- CPDF_Document* m_pPDFDoc;
- CFX_FontCache* m_pFontCache;
- CPDF_Type3CacheMap m_Type3FaceMap;
- CPDF_TransferFuncMap m_TransferFuncMap;
+ using CPDF_Type3CacheMap =
+ std::map<CPDF_Font*, CPDF_CountedObject<CPDF_Type3Cache>*>;
+ using CPDF_TransferFuncMap =
+ std::map<CPDF_Object*, CPDF_CountedObject<CPDF_TransferFunc>*> ;
+
+ CPDF_Document* m_pPDFDoc;
+ CFX_FontCache* m_pFontCache;
+ CPDF_Type3CacheMap m_Type3FaceMap;
+ CPDF_TransferFuncMap m_TransferFuncMap;
};
struct _PDF_RenderItem {
public:
diff --git a/core/src/fpdfdoc/doc_ocg.cpp b/core/src/fpdfdoc/doc_ocg.cpp
index 601b006f1a..8477cb85d0 100644
--- a/core/src/fpdfdoc/doc_ocg.cpp
+++ b/core/src/fpdfdoc/doc_ocg.cpp
@@ -99,7 +99,7 @@ CPDF_OCContext::CPDF_OCContext(CPDF_Document *pDoc, UsageType eUsageType)
}
CPDF_OCContext::~CPDF_OCContext()
{
- m_OCGStates.RemoveAll();
+ m_OCGStates.clear();
}
FX_BOOL CPDF_OCContext::LoadOCGStateFromConfig(const CFX_ByteStringC& csConfig, const CPDF_Dictionary *pOCGDict, FX_BOOL &bValidConfig) const
{
@@ -174,19 +174,21 @@ FX_BOOL CPDF_OCContext::LoadOCGState(const CPDF_Dictionary *pOCGDict) const
FX_BOOL bDefValid = FALSE;
return LoadOCGStateFromConfig(csState, pOCGDict, bDefValid);
}
-FX_BOOL CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary *pOCGDict)
+
+FX_BOOL CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary* pOCGDict)
{
- if (!pOCGDict) {
+ if (!pOCGDict)
return FALSE;
- }
- void* bState = NULL;
- if (m_OCGStates.Lookup(pOCGDict, bState)) {
- return (uintptr_t)bState != 0;
- }
- bState = (void*)(uintptr_t)LoadOCGState(pOCGDict);
- m_OCGStates.SetAt(pOCGDict, bState);
- return (uintptr_t)bState != 0;
+
+ const auto it = m_OCGStates.find(pOCGDict);
+ if (it != m_OCGStates.end())
+ return it->second;
+
+ FX_BOOL bState = LoadOCGState(pOCGDict);
+ m_OCGStates[pOCGDict] = bState;
+ return bState;
}
+
FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array *pExpression, FX_BOOL bFromConfig, int nLevel)
{
if (nLevel > 32) {
@@ -296,5 +298,5 @@ FX_BOOL CPDF_OCContext::CheckOCGVisible(const CPDF_Dictionary *pOCGDict)
}
void CPDF_OCContext::ResetOCContext()
{
- m_OCGStates.RemoveAll();
+ m_OCGStates.clear();
}
diff --git a/core/src/fxge/ge/fx_ge_text.cpp b/core/src/fxge/ge/fx_ge_text.cpp
index b55119b915..d15db7b43f 100644
--- a/core/src/fxge/ge/fx_ge_text.cpp
+++ b/core/src/fxge/ge/fx_ge_text.cpp
@@ -1002,64 +1002,70 @@ CFX_FontCache::~CFX_FontCache()
{
FreeCache(TRUE);
}
+
CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont)
{
- FX_BOOL bExternal = pFont->GetFace() == NULL;
- void* face = bExternal ? pFont->GetSubstFont()->m_ExtHandle : pFont->GetFace();
- CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap;
- CFX_CountedFaceCache* counted_face_cache = NULL;
- if (map.Lookup((FXFT_Face)face, counted_face_cache)) {
+ FXFT_Face internal_face = pFont->GetFace();
+ const FX_BOOL bExternal = internal_face == nullptr;
+ FXFT_Face face = bExternal ?
+ (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face;
+ CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap;
+ auto it = map.find(face);
+ if (it != map.end()) {
+ CFX_CountedFaceCache* counted_face_cache = it->second;
counted_face_cache->m_nCount++;
return counted_face_cache->m_Obj;
}
- CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? NULL : (FXFT_Face)face);
- counted_face_cache = new CFX_CountedFaceCache;
+
+ CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face);
+ CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache;
counted_face_cache->m_nCount = 2;
counted_face_cache->m_Obj = face_cache;
- map.SetAt((FXFT_Face)face, counted_face_cache);
+ map[face] = counted_face_cache;
return face_cache;
}
+
void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont)
{
- FX_BOOL bExternal = pFont->GetFace() == NULL;
- void* face = bExternal ? pFont->GetSubstFont()->m_ExtHandle : pFont->GetFace();
+ FXFT_Face internal_face = pFont->GetFace();
+ const FX_BOOL bExternal = internal_face == nullptr;
+ FXFT_Face face = bExternal ?
+ (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face;
CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap;
- CFX_CountedFaceCache* counted_face_cache = NULL;
- if (!map.Lookup((FXFT_Face)face, counted_face_cache)) {
+
+ auto it = map.find(face);
+ if (it == map.end())
return;
- }
+
+ CFX_CountedFaceCache* counted_face_cache = it->second;
if (counted_face_cache->m_nCount > 1) {
counted_face_cache->m_nCount--;
}
}
+
void CFX_FontCache::FreeCache(FX_BOOL bRelease)
{
- {
- FX_POSITION pos;
- pos = m_FTFaceMap.GetStartPosition();
- while (pos) {
- FXFT_Face face;
- CFX_CountedFaceCache* cache;
- m_FTFaceMap.GetNextAssoc(pos, face, cache);
- if (bRelease || cache->m_nCount < 2) {
- delete cache->m_Obj;
- delete cache;
- m_FTFaceMap.RemoveKey(face);
- }
+ for (auto it = m_FTFaceMap.begin(); it != m_FTFaceMap.end();) {
+ auto curr_it = it++;
+ CFX_CountedFaceCache* cache = curr_it->second;
+ if (bRelease || cache->m_nCount < 2) {
+ delete cache->m_Obj;
+ delete cache;
+ m_FTFaceMap.erase(curr_it);
}
- pos = m_ExtFaceMap.GetStartPosition();
- while (pos) {
- FXFT_Face face;
- CFX_CountedFaceCache* cache;
- m_ExtFaceMap.GetNextAssoc(pos, face, cache);
- if (bRelease || cache->m_nCount < 2) {
- delete cache->m_Obj;
- delete cache;
- m_ExtFaceMap.RemoveKey(face);
- }
+ }
+
+ for (auto it = m_ExtFaceMap.begin(); it != m_ExtFaceMap.end();) {
+ auto curr_it = it++;
+ CFX_CountedFaceCache* cache = curr_it->second;
+ if (bRelease || cache->m_nCount < 2) {
+ delete cache->m_Obj;
+ delete cache;
+ m_ExtFaceMap.erase(curr_it);
}
}
}
+
CFX_FaceCache::CFX_FaceCache(FXFT_Face face)
{
m_Face = face;