summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/fpdfapi')
-rw-r--r--core/src/fpdfapi/fpdf_font/font_int.h16
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp51
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp21
-rw-r--r--core/src/fpdfapi/fpdf_page/pageint.h3
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp19
-rw-r--r--core/src/fpdfapi/fpdf_render/render_int.h11
6 files changed, 57 insertions, 64 deletions
diff --git a/core/src/fpdfapi/fpdf_font/font_int.h b/core/src/fpdfapi/fpdf_font/font_int.h
index d7cbe1b0b5..30223ad63a 100644
--- a/core/src/fpdfapi/fpdf_font/font_int.h
+++ b/core/src/fpdfapi/fpdf_font/font_int.h
@@ -3,10 +3,22 @@
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
#ifndef CORE_SRC_FPDFAPI_FPDF_FONT_FONT_INT_H_
#define CORE_SRC_FPDFAPI_FPDF_FONT_FONT_INT_H_
+#include <map>
+
+#include "../../../include/fxcrt/fx_basic.h"
+#include "../../../include/fpdfapi/fpdf_resource.h"
+
+class CPDF_CID2UnicodeMap;
+class CPDF_CMap;
+class CPDF_Font;
+class CPDF_Stream;
+
typedef void* FXFT_Library;
+
class CPDF_CMapManager {
public:
CPDF_CMapManager();
@@ -19,9 +31,9 @@ class CPDF_CMapManager {
private:
CPDF_CMap* LoadPredefinedCMap(const CFX_ByteString& name, FX_BOOL bPrompt);
CPDF_CID2UnicodeMap* LoadCID2UnicodeMap(int charset, FX_BOOL bPrompt);
- void DropAll(FX_BOOL bReload);
+
FX_BOOL m_bPrompted;
- CFX_MapByteStringToPtr m_CMaps;
+ std::map<CFX_ByteString, CPDF_CMap*> m_CMaps;
CPDF_CID2UnicodeMap* m_CID2UnicodeMaps[6];
};
class CPDF_FontGlobals {
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
index 6c728242e6..ebb99fad63 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
@@ -22,19 +22,24 @@ CPDF_CMapManager::CPDF_CMapManager() {
FXSYS_memset(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps);
}
CPDF_CMapManager::~CPDF_CMapManager() {
- DropAll(FALSE);
+ for (const auto& pair : m_CMaps) {
+ delete pair.second;
+ }
+ m_CMaps.clear();
+ for (int i = 0; i < FX_ArraySize(m_CID2UnicodeMaps); ++i) {
+ delete m_CID2UnicodeMaps[i];
+ }
}
CPDF_CMap* CPDF_CMapManager::GetPredefinedCMap(const CFX_ByteString& name,
FX_BOOL bPromptCJK) {
- CPDF_CMap* pCMap;
- if (m_CMaps.Lookup(name, (void*&)pCMap)) {
- return pCMap;
+ auto it = m_CMaps.find(name);
+ if (it != m_CMaps.end()) {
+ return it->second;
}
- pCMap = LoadPredefinedCMap(name, bPromptCJK);
- if (name.IsEmpty()) {
- return pCMap;
+ CPDF_CMap* pCMap = LoadPredefinedCMap(name, bPromptCJK);
+ if (!name.IsEmpty()) {
+ m_CMaps[name] = pCMap;
}
- m_CMaps.SetAt(name, pCMap);
return pCMap;
}
CPDF_CMap* CPDF_CMapManager::LoadPredefinedCMap(const CFX_ByteString& name,
@@ -59,33 +64,13 @@ int _CharsetFromOrdering(const CFX_ByteString& Ordering) {
return CIDSET_UNKNOWN;
}
void CPDF_CMapManager::ReloadAll() {
- DropAll(TRUE);
-}
-void CPDF_CMapManager::DropAll(FX_BOOL bReload) {
- FX_POSITION pos = m_CMaps.GetStartPosition();
- while (pos) {
- CFX_ByteString name;
- CPDF_CMap* pCMap;
- m_CMaps.GetNextAssoc(pos, name, (void*&)pCMap);
- if (pCMap == NULL) {
- continue;
- }
- if (bReload) {
- pCMap->LoadPredefined(this, name, FALSE);
- } else {
- delete pCMap;
- }
+ for (const auto& pair : m_CMaps) {
+ CPDF_CMap* pCMap = pair.second;
+ pCMap->LoadPredefined(this, pair.first, FALSE);
}
- for (int i = 0; i < sizeof m_CID2UnicodeMaps / sizeof(CPDF_CID2UnicodeMap*);
- i++) {
- CPDF_CID2UnicodeMap* pMap = m_CID2UnicodeMaps[i];
- if (pMap == NULL) {
- continue;
- }
- if (bReload) {
+ for (int i = 0; i < FX_ArraySize(m_CID2UnicodeMaps); ++i) {
+ if (CPDF_CID2UnicodeMap* pMap = m_CID2UnicodeMaps[i]) {
pMap->Load(this, i, FALSE);
- } else {
- delete pMap;
}
}
}
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
index 74e33b56a9..210d5433be 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
@@ -171,14 +171,10 @@ void CPDF_DocPageData::Clear(FX_BOOL bForceRelease) {
continue;
if (bForceRelease || ipData->use_count() < 2) {
- CPDF_Stream* ipKey = curr_it->first;
- FX_POSITION pos2 = m_HashProfileMap.GetStartPosition();
- while (pos2) {
- CFX_ByteString bsKey;
- CPDF_Stream* pFindStream = nullptr;
- m_HashProfileMap.GetNextAssoc(pos2, bsKey, (void*&)pFindStream);
- if (ipKey == pFindStream) {
- m_HashProfileMap.RemoveKey(bsKey);
+ for (auto hash_it = m_HashProfileMap.begin();
+ hash_it != m_HashProfileMap.end(); ++hash_it) {
+ if (curr_it->first == hash_it->second) {
+ m_HashProfileMap.erase(hash_it);
break;
}
}
@@ -519,18 +515,17 @@ CPDF_IccProfile* CPDF_DocPageData::GetIccProfile(
CPDF_StreamAcc stream;
stream.LoadAllData(pIccProfileStream, FALSE);
uint8_t digest[20];
- CPDF_Stream* pCopiedStream = nullptr;
CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest);
- if (m_HashProfileMap.Lookup(CFX_ByteStringC(digest, 20),
- (void*&)pCopiedStream)) {
- auto it_copied_stream = m_IccProfileMap.find(pCopiedStream);
+ auto hash_it = m_HashProfileMap.find(CFX_ByteStringC(digest, 20));
+ if (hash_it != m_HashProfileMap.end()) {
+ auto it_copied_stream = m_IccProfileMap.find(hash_it->second);
return it_copied_stream->second->AddRef();
}
CPDF_IccProfile* pProfile =
new CPDF_IccProfile(stream.GetData(), stream.GetSize());
CPDF_CountedIccProfile* ipData = new CPDF_CountedIccProfile(pProfile);
m_IccProfileMap[pIccProfileStream] = ipData;
- m_HashProfileMap.SetAt(CFX_ByteStringC(digest, 20), pIccProfileStream);
+ m_HashProfileMap[CFX_ByteStringC(digest, 20)] = pIccProfileStream;
return ipData->AddRef();
}
diff --git a/core/src/fpdfapi/fpdf_page/pageint.h b/core/src/fpdfapi/fpdf_page/pageint.h
index c931af7eb2..4f60cf5baa 100644
--- a/core/src/fpdfapi/fpdf_page/pageint.h
+++ b/core/src/fpdfapi/fpdf_page/pageint.h
@@ -423,9 +423,8 @@ class CPDF_DocPageData {
using CPDF_PatternMap = std::map<CPDF_Object*, CPDF_CountedPattern*>;
CPDF_Document* const m_pPDFDoc;
- CFX_MapByteStringToPtr m_HashProfileMap;
FX_BOOL m_bForceClear;
-
+ std::map<CFX_ByteString, CPDF_Stream*> m_HashProfileMap;
CPDF_ColorSpaceMap m_ColorSpaceMap;
CPDF_FontFileMap m_FontFileMap;
CPDF_FontMap m_FontMap;
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp
index d36125e1b8..50388332f8 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp
@@ -11,14 +11,10 @@
#include "render_int.h"
extern FX_BOOL IsAvailableMatrix(const CFX_AffineMatrix& matrix);
CPDF_Type3Cache::~CPDF_Type3Cache() {
- FX_POSITION pos = m_SizeMap.GetStartPosition();
- CFX_ByteString Key;
- CPDF_Type3Glyphs* pSizeCache = NULL;
- while (pos) {
- pSizeCache = (CPDF_Type3Glyphs*)m_SizeMap.GetNextValue(pos);
- delete pSizeCache;
+ for (const auto& pair : m_SizeMap) {
+ delete pair.second;
}
- m_SizeMap.RemoveAll();
+ m_SizeMap.clear();
}
CFX_GlyphBitmap* CPDF_Type3Cache::LoadGlyph(FX_DWORD charcode,
const CFX_AffineMatrix* pMatrix,
@@ -29,10 +25,13 @@ CFX_GlyphBitmap* CPDF_Type3Cache::LoadGlyph(FX_DWORD charcode,
4, FXSYS_round(pMatrix->a * 10000), FXSYS_round(pMatrix->b * 10000),
FXSYS_round(pMatrix->c * 10000), FXSYS_round(pMatrix->d * 10000));
CFX_ByteStringC FaceGlyphsKey(keygen.m_Key, keygen.m_KeyLen);
- CPDF_Type3Glyphs* pSizeCache = NULL;
- if (!m_SizeMap.Lookup(FaceGlyphsKey, (void*&)pSizeCache)) {
+ CPDF_Type3Glyphs* pSizeCache;
+ auto it = m_SizeMap.find(FaceGlyphsKey);
+ if (it == m_SizeMap.end()) {
pSizeCache = new CPDF_Type3Glyphs;
- m_SizeMap.SetAt(FaceGlyphsKey, pSizeCache);
+ m_SizeMap[FaceGlyphsKey] = pSizeCache;
+ } else {
+ pSizeCache = it->second;
}
CFX_GlyphBitmap* pGlyphBitmap;
if (pSizeCache->m_GlyphMap.Lookup((void*)(uintptr_t)charcode,
diff --git a/core/src/fpdfapi/fpdf_render/render_int.h b/core/src/fpdfapi/fpdf_render/render_int.h
index 733e24cbcf..e195472ac1 100644
--- a/core/src/fpdfapi/fpdf_render/render_int.h
+++ b/core/src/fpdfapi/fpdf_render/render_int.h
@@ -12,8 +12,11 @@
#include "../../../../third_party/base/nonstd_unique_ptr.h"
#include "../../../include/fpdfapi/fpdf_pageobj.h"
+class CFX_GlyphBitmap;
class CPDF_QuickStretcher;
+
#define TYPE3_MAX_BLUES 16
+
class CPDF_Type3Glyphs {
public:
CPDF_Type3Glyphs() {
@@ -30,11 +33,11 @@ class CPDF_Type3Glyphs {
int m_TopBlue[TYPE3_MAX_BLUES], m_BottomBlue[TYPE3_MAX_BLUES];
int m_TopBlueCount, m_BottomBlueCount;
};
-class CFX_GlyphBitmap;
class CPDF_Type3Cache {
public:
- CPDF_Type3Cache(CPDF_Type3Font* pFont) { m_pFont = pFont; }
+ explicit CPDF_Type3Cache(CPDF_Type3Font* pFont) : m_pFont(pFont) {}
~CPDF_Type3Cache();
+
CFX_GlyphBitmap* LoadGlyph(FX_DWORD charcode,
const CFX_AffineMatrix* pMatrix,
FX_FLOAT retinaScaleX = 1.0f,
@@ -46,8 +49,8 @@ class CPDF_Type3Cache {
const CFX_AffineMatrix* pMatrix,
FX_FLOAT retinaScaleX = 1.0f,
FX_FLOAT retinaScaleY = 1.0f);
- CPDF_Type3Font* m_pFont;
- CFX_MapByteStringToPtr m_SizeMap;
+ CPDF_Type3Font* const m_pFont;
+ std::map<CFX_ByteString, CPDF_Type3Glyphs*> m_SizeMap;
};
class CPDF_TransferFunc {
public: