diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-12-10 15:39:28 -0800 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-12-10 15:39:28 -0800 |
commit | d2cfdd5c72be670aff556c44aaff53df66b23ea6 (patch) | |
tree | de7fce67d473f019174e554790b403a069c59eb5 /core/src | |
parent | 60d909e9d4444b2b8582275624ee97734d331a38 (diff) | |
download | pdfium-d2cfdd5c72be670aff556c44aaff53df66b23ea6.tar.xz |
Merge to XFA: Replace several more CFX_MapPtrToPtr with std::set or std::map
Original Review URL: https://codereview.chromium.org/1520643002 .
(cherry picked from commit 7db2a535f163e7ce5995da12161ebd0214f0f75a)
Original Review URL: https://codereview.chromium.org/1511413008 .
(cherry picked from commit 168cfb7ee0f2abbd2bddb7e7d8b430a6d8c6c120)
TBR=thestig@chromium.org
Review URL: https://codereview.chromium.org/1515613006 .
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp | 8 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp | 22 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_render/render_int.h | 13 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_annot.cpp | 18 | ||||
-rw-r--r-- | core/src/fxge/ge/fx_ge_text.cpp | 86 | ||||
-rw-r--r-- | core/src/fxge/ge/text_int.h | 6 |
6 files changed, 66 insertions, 87 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp index f91ddfa5dc..ad4038d71b 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp @@ -227,11 +227,11 @@ CPDF_Object* CPDF_Object::GetDirect() const { return pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum()); } CPDF_Object* CPDF_Object::Clone(FX_BOOL bDirect) const { - CFX_MapPtrToPtr visited; + std::set<FX_DWORD> visited; return CloneInternal(bDirect, &visited); } CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, - CFX_MapPtrToPtr* visited) const { + std::set<FX_DWORD>* visited) const { switch (m_Type) { case PDFOBJ_BOOLEAN: return new CPDF_Boolean(AsBoolean()->m_bValue); @@ -285,8 +285,8 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, case PDFOBJ_REFERENCE: { const CPDF_Reference* pRef = AsReference(); FX_DWORD obj_num = pRef->GetRefObjNum(); - if (bDirect && !visited->GetValueAt((void*)(uintptr_t)obj_num)) { - visited->SetAt((void*)(uintptr_t)obj_num, (void*)1); + if (bDirect && visited->find(obj_num) == visited->end()) { + visited->insert(obj_num); if (!pRef->GetDirect()) return nullptr; diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp index 47876a2280..227a208080 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp @@ -34,24 +34,18 @@ CFX_GlyphBitmap* CPDF_Type3Cache::LoadGlyph(FX_DWORD charcode, } else { pSizeCache = it->second; } - CFX_GlyphBitmap* pGlyphBitmap; - if (pSizeCache->m_GlyphMap.Lookup((void*)(uintptr_t)charcode, - (void*&)pGlyphBitmap)) { - return pGlyphBitmap; - } - pGlyphBitmap = + auto it2 = pSizeCache->m_GlyphMap.find(charcode); + if (it2 != pSizeCache->m_GlyphMap.end()) + return it2->second; + + CFX_GlyphBitmap* pGlyphBitmap = RenderGlyph(pSizeCache, charcode, pMatrix, retinaScaleX, retinaScaleY); - pSizeCache->m_GlyphMap.SetAt((void*)(uintptr_t)charcode, pGlyphBitmap); + pSizeCache->m_GlyphMap[charcode] = pGlyphBitmap; return pGlyphBitmap; } CPDF_Type3Glyphs::~CPDF_Type3Glyphs() { - FX_POSITION pos = m_GlyphMap.GetStartPosition(); - void* Key; - CFX_GlyphBitmap* pGlyphBitmap; - while (pos) { - m_GlyphMap.GetNextAssoc(pos, Key, (void*&)pGlyphBitmap); - delete pGlyphBitmap; - } + for (const auto& pair : m_GlyphMap) + delete pair.second; } static int _AdjustBlue(FX_FLOAT pos, int& count, int blues[]) { FX_FLOAT min_distance = 1000000.0f * 1.0f; diff --git a/core/src/fpdfapi/fpdf_render/render_int.h b/core/src/fpdfapi/fpdf_render/render_int.h index d173f47b7c..d348b48dfd 100644 --- a/core/src/fpdfapi/fpdf_render/render_int.h +++ b/core/src/fpdfapi/fpdf_render/render_int.h @@ -21,19 +21,18 @@ class CPDF_QuickStretcher; class CPDF_Type3Glyphs { public: - CPDF_Type3Glyphs() { - m_GlyphMap.InitHashTable(253); - m_TopBlueCount = m_BottomBlueCount = 0; - } + CPDF_Type3Glyphs() : m_TopBlueCount(0), m_BottomBlueCount(0) {} ~CPDF_Type3Glyphs(); - CFX_MapPtrToPtr m_GlyphMap; void AdjustBlue(FX_FLOAT top, FX_FLOAT bottom, int& top_line, int& bottom_line); - int m_TopBlue[TYPE3_MAX_BLUES], m_BottomBlue[TYPE3_MAX_BLUES]; - int m_TopBlueCount, m_BottomBlueCount; + std::map<FX_DWORD, CFX_GlyphBitmap*> m_GlyphMap; + int m_TopBlue[TYPE3_MAX_BLUES]; + int m_BottomBlue[TYPE3_MAX_BLUES]; + int m_TopBlueCount; + int m_BottomBlueCount; }; class CPDF_Type3Cache { public: diff --git a/core/src/fpdfdoc/doc_annot.cpp b/core/src/fpdfdoc/doc_annot.cpp index 0765acdf6e..26ea45fd9d 100644 --- a/core/src/fpdfdoc/doc_annot.cpp +++ b/core/src/fpdfdoc/doc_annot.cpp @@ -124,14 +124,10 @@ CPDF_Annot::~CPDF_Annot() { ClearCachedAP(); } void CPDF_Annot::ClearCachedAP() { - FX_POSITION pos = m_APMap.GetStartPosition(); - while (pos) { - void* pForm; - void* pObjects; - m_APMap.GetNextAssoc(pos, pForm, pObjects); - delete (CPDF_PageObjects*)pObjects; + for (const auto& pair : m_APMap) { + delete pair.second; } - m_APMap.RemoveAll(); + m_APMap.clear(); } CFX_ByteString CPDF_Annot::GetSubType() const { return m_sSubtype; @@ -192,14 +188,14 @@ CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode) { if (!pStream) return nullptr; - void* pForm; - if (m_APMap.Lookup(pStream, pForm)) - return static_cast<CPDF_Form*>(pForm); + auto it = m_APMap.find(pStream); + if (it != m_APMap.end()) + return it->second; CPDF_Form* pNewForm = new CPDF_Form(m_pList->GetDocument(), pPage->m_pResources, pStream); pNewForm->ParseContent(nullptr, nullptr, nullptr, nullptr); - m_APMap.SetAt(pStream, pNewForm); + m_APMap[pStream] = pNewForm; return pNewForm; } diff --git a/core/src/fxge/ge/fx_ge_text.cpp b/core/src/fxge/ge/fx_ge_text.cpp index 5e7773e300..d330576433 100644 --- a/core/src/fxge/ge/fx_ge_text.cpp +++ b/core/src/fxge/ge/fx_ge_text.cpp @@ -1238,14 +1238,10 @@ CFX_FaceCache::~CFX_FaceCache() { delete pair.second; } m_SizeMap.clear(); - FX_POSITION pos = m_PathMap.GetStartPosition(); - void* key1; - CFX_PathData* pPath; - while (pos) { - m_PathMap.GetNextAssoc(pos, key1, (void*&)pPath); - delete pPath; - } - m_PathMap.RemoveAll(); + for (const auto& pair : m_PathMap) { + delete pair.second; + } + m_PathMap.clear(); } #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ void CFX_FaceCache::InitPlatform() {} @@ -1266,17 +1262,16 @@ CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap( } else { pSizeCache = it->second; } - CFX_GlyphBitmap* pGlyphBitmap = NULL; - if (pSizeCache->m_GlyphMap.Lookup((void*)(uintptr_t)glyph_index, - (void*&)pGlyphBitmap)) { - return pGlyphBitmap; - } - pGlyphBitmap = RenderGlyph(pFont, glyph_index, bFontStyle, pMatrix, - dest_width, anti_alias); - if (pGlyphBitmap == NULL) { - return NULL; - } - pSizeCache->m_GlyphMap.SetAt((void*)(uintptr_t)glyph_index, pGlyphBitmap); + auto it2 = pSizeCache->m_GlyphMap.find(glyph_index); + if (it2 != pSizeCache->m_GlyphMap.end()) + return it2->second; + + CFX_GlyphBitmap* pGlyphBitmap = RenderGlyph(pFont, glyph_index, bFontStyle, + pMatrix, dest_width, anti_alias); + if (!pGlyphBitmap) + return nullptr; + + pSizeCache->m_GlyphMap[glyph_index] = pGlyphBitmap; return pGlyphBitmap; } const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(CFX_Font* pFont, @@ -1338,14 +1333,14 @@ const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(CFX_Font* pFont, auto it = m_SizeMap.find(FaceGlyphsKey); if (it != m_SizeMap.end()) { CFX_SizeGlyphCache* pSizeCache = it->second; - if (pSizeCache->m_GlyphMap.Lookup((void*)(uintptr_t)glyph_index, - (void*&)pGlyphBitmap)) { - return pGlyphBitmap; - } + auto it2 = pSizeCache->m_GlyphMap.find(glyph_index); + if (it2 != pSizeCache->m_GlyphMap.end()) + return it2->second; + pGlyphBitmap = RenderGlyph_Nativetext(pFont, glyph_index, pMatrix, dest_width, anti_alias); if (pGlyphBitmap) { - pSizeCache->m_GlyphMap.SetAt((void*)(uintptr_t)glyph_index, pGlyphBitmap); + pSizeCache->m_GlyphMap[glyph_index] = pGlyphBitmap; return pGlyphBitmap; } } else { @@ -1354,7 +1349,7 @@ const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(CFX_Font* pFont, if (pGlyphBitmap) { CFX_SizeGlyphCache* pSizeCache = new CFX_SizeGlyphCache; m_SizeMap[FaceGlyphsKey] = pSizeCache; - pSizeCache->m_GlyphMap.SetAt((void*)(uintptr_t)glyph_index, pGlyphBitmap); + pSizeCache->m_GlyphMap[glyph_index] = pGlyphBitmap; return pGlyphBitmap; } } @@ -1374,14 +1369,10 @@ const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(CFX_Font* pFont, #endif } CFX_SizeGlyphCache::~CFX_SizeGlyphCache() { - FX_POSITION pos = m_GlyphMap.GetStartPosition(); - void* Key; - CFX_GlyphBitmap* pGlyphBitmap = NULL; - while (pos) { - m_GlyphMap.GetNextAssoc(pos, Key, (void*&)pGlyphBitmap); - delete pGlyphBitmap; - } - m_GlyphMap.RemoveAll(); + for (const auto& pair : m_GlyphMap) { + delete pair.second; + } + m_GlyphMap.clear(); } #define CONTRAST_RAMP_STEP 1 void CFX_Font::AdjustMMParams(int glyph_index, int dest_width, int weight) { @@ -1652,24 +1643,21 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(CFX_Font* pFont, const CFX_PathData* CFX_FaceCache::LoadGlyphPath(CFX_Font* pFont, FX_DWORD glyph_index, int dest_width) { - if (m_Face == NULL || glyph_index == (FX_DWORD)-1) { - return NULL; - } - CFX_PathData* pGlyphPath = NULL; - void* key; + if (!m_Face || glyph_index == (FX_DWORD)-1) + return nullptr; + + FX_DWORD key = glyph_index; if (pFont->GetSubstFont()) { - key = (void*)(uintptr_t)( - glyph_index + ((pFont->GetSubstFont()->m_Weight / 16) << 15) + - ((pFont->GetSubstFont()->m_ItalicAngle / 2) << 21) + - ((dest_width / 16) << 25) + (pFont->IsVertical() << 31)); - } else { - key = (void*)(uintptr_t)glyph_index; + key += (((pFont->GetSubstFont()->m_Weight / 16) << 15) + + ((pFont->GetSubstFont()->m_ItalicAngle / 2) << 21) + + ((dest_width / 16) << 25) + (pFont->IsVertical() << 31)); } - if (m_PathMap.Lookup(key, (void*&)pGlyphPath)) { - return pGlyphPath; - } - pGlyphPath = pFont->LoadGlyphPath(glyph_index, dest_width); - m_PathMap.SetAt(key, pGlyphPath); + auto it = m_PathMap.find(key); + if (it != m_PathMap.end()) + return it->second; + + CFX_PathData* pGlyphPath = pFont->LoadGlyphPath(glyph_index, dest_width); + m_PathMap[key] = pGlyphPath; return pGlyphPath; } typedef struct { diff --git a/core/src/fxge/ge/text_int.h b/core/src/fxge/ge/text_int.h index 1b96cfbdd2..5a691671be 100644 --- a/core/src/fxge/ge/text_int.h +++ b/core/src/fxge/ge/text_int.h @@ -7,6 +7,8 @@ #ifndef CORE_SRC_FXGE_GE_TEXT_INT_H_ #define CORE_SRC_FXGE_GE_TEXT_INT_H_ +#include <map> + #include "core/include/fxge/fx_font.h" #include "core/include/fxge/fx_freetype.h" @@ -17,9 +19,9 @@ struct _CFX_UniqueKeyGen { }; class CFX_SizeGlyphCache { public: - CFX_SizeGlyphCache() { m_GlyphMap.InitHashTable(253); } + CFX_SizeGlyphCache() {} ~CFX_SizeGlyphCache(); - CFX_MapPtrToPtr m_GlyphMap; + std::map<FX_DWORD, CFX_GlyphBitmap*> m_GlyphMap; }; class CTTFontDesc { public: |