diff options
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/fpdfapi/fpdf_font/font_int.h | 16 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp | 51 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp | 21 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/pageint.h | 3 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp | 19 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_render/render_int.h | 11 | ||||
-rw-r--r-- | core/src/fxcodec/codec/codec_int.h | 15 | ||||
-rw-r--r-- | core/src/fxcodec/codec/fx_codec_icc.cpp | 29 | ||||
-rw-r--r-- | core/src/fxcrt/fx_basic_maps.cpp | 192 | ||||
-rw-r--r-- | core/src/fxge/ge/fx_ge_fontmap.cpp | 113 | ||||
-rw-r--r-- | core/src/fxge/ge/fx_ge_linux.cpp | 47 | ||||
-rw-r--r-- | core/src/fxge/ge/fx_ge_text.cpp | 21 |
12 files changed, 168 insertions, 370 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 5927511ebf..ca6c04fef9 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 bc03c3b5e6..6bec07268c 100644 --- a/core/src/fpdfapi/fpdf_page/pageint.h +++ b/core/src/fpdfapi/fpdf_page/pageint.h @@ -422,9 +422,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: diff --git a/core/src/fxcodec/codec/codec_int.h b/core/src/fxcodec/codec/codec_int.h index ec558bea28..4bcdeed7ad 100644 --- a/core/src/fxcodec/codec/codec_int.h +++ b/core/src/fxcodec/codec/codec_int.h @@ -9,11 +9,15 @@ #include <limits.h> #include <list> +#include <map> #include "../../../../third_party/libopenjpeg20/openjpeg.h" // For OPJ_SIZE_T. #include "../../../include/fxcodec/fx_codec.h" #include "../jbig2/JBig2_Context.h" +class CFX_IccProfileCache; +class CFX_IccTransformCache; + class CCodec_BasicModule : public ICodec_BasicModule { public: virtual FX_BOOL RunLengthEncode(const uint8_t* src_buf, @@ -225,18 +229,19 @@ class CCodec_IccModule : public ICodec_IccModule { virtual ~CCodec_IccModule(); protected: - CFX_MapByteStringToPtr m_MapTranform; - CFX_MapByteStringToPtr m_MapProfile; - FX_DWORD m_nComponents; - typedef enum { + enum Icc_CLASS { Icc_CLASS_INPUT = 0, Icc_CLASS_OUTPUT, Icc_CLASS_PROOF, Icc_CLASS_MAX - } Icc_CLASS; + }; void* CreateProfile(ICodec_IccModule::IccParam* pIccParam, Icc_CLASS ic, CFX_BinaryBuf* pTransformKey); + + FX_DWORD m_nComponents; + std::map<CFX_ByteString, CFX_IccTransformCache*> m_MapTranform; + std::map<CFX_ByteString, CFX_IccProfileCache*> m_MapProfile; }; class CCodec_JpxModule : public ICodec_JpxModule { diff --git a/core/src/fxcodec/codec/fx_codec_icc.cpp b/core/src/fxcodec/codec/fx_codec_icc.cpp index dad880a936..2a8ccc364c 100644 --- a/core/src/fxcodec/codec/fx_codec_icc.cpp +++ b/core/src/fxcodec/codec/fx_codec_icc.cpp @@ -434,7 +434,8 @@ void* CCodec_IccModule::CreateProfile(ICodec_IccModule::IccParam* pIccParam, CFX_ByteString ProfileKey(key.GetBuffer(), key.GetSize()); ASSERT(pTransformKey); pTransformKey->AppendBlock(ProfileKey.GetBuffer(0), ProfileKey.GetLength()); - if (!m_MapProfile.Lookup(ProfileKey, (void*&)pCache)) { + auto it = m_MapProfile.find(ProfileKey); + if (it == m_MapProfile.end()) { pCache = new CFX_IccProfileCache; switch (pIccParam->dwProfileType) { case Icc_PARAMTYPE_BUFFER: @@ -456,8 +457,9 @@ void* CCodec_IccModule::CreateProfile(ICodec_IccModule::IccParam* pIccParam, default: break; } - m_MapProfile.SetAt(ProfileKey, pCache); + m_MapProfile[ProfileKey] = pCache; } else { + pCache = it->second; pCache->m_dwRate++; } return pCache->m_pProfile; @@ -496,7 +498,8 @@ void* CCodec_IccModule::CreateTransform( << (pProofProfile != NULL) << dwPrfIntent << dwPrfFlag; CFX_ByteStringC TransformKey(key.GetBuffer(), key.GetSize()); CFX_IccTransformCache* pTransformCache; - if (!m_MapTranform.Lookup(TransformKey, (void*&)pTransformCache)) { + auto it = m_MapTranform.find(TransformKey); + if (it == m_MapTranform.end()) { pCmm = FX_Alloc(CLcmsCmm, 1); pCmm->m_nSrcComponents = T_CHANNELS(dwInputProfileType); pCmm->m_nDstComponents = T_CHANNELS(dwOutputProfileType); @@ -512,26 +515,22 @@ void* CCodec_IccModule::CreateTransform( dwOutputProfileType, dwIntent, dwFlag); } pCmm->m_hTransform = pTransformCache->m_pIccTransform; - m_MapTranform.SetAt(TransformKey, pTransformCache); + m_MapTranform[TransformKey] = pTransformCache; } else { + pTransformCache = it->second; pTransformCache->m_dwRate++; } return pTransformCache->m_pCmm; } CCodec_IccModule::~CCodec_IccModule() { - FX_POSITION pos = m_MapProfile.GetStartPosition(); - CFX_ByteString key; - CFX_IccProfileCache* pProfileCache; - while (pos) { - m_MapProfile.GetNextAssoc(pos, key, (void*&)pProfileCache); - delete pProfileCache; + for (const auto& pair : m_MapProfile) { + delete pair.second; } - pos = m_MapTranform.GetStartPosition(); - CFX_IccTransformCache* pTransformCache; - while (pos) { - m_MapTranform.GetNextAssoc(pos, key, (void*&)pTransformCache); - delete pTransformCache; + m_MapProfile.clear(); + for (const auto& pair : m_MapTranform) { + delete pair.second; } + m_MapTranform.clear(); } void* CCodec_IccModule::CreateTransform_sRGB(const uint8_t* pProfileData, FX_DWORD dwProfileSize, diff --git a/core/src/fxcrt/fx_basic_maps.cpp b/core/src/fxcrt/fx_basic_maps.cpp index 1558ae6f75..6bcb91546a 100644 --- a/core/src/fxcrt/fx_basic_maps.cpp +++ b/core/src/fxcrt/fx_basic_maps.cpp @@ -7,12 +7,6 @@ #include "../../include/fxcrt/fx_basic.h" #include "plex.h" -static void ConstructElement(CFX_ByteString* pNewData) { - new (pNewData) CFX_ByteString(); -} -static void DestructElement(CFX_ByteString* pOldData) { - pOldData->~CFX_ByteString(); -} CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize) : m_pHashTable(NULL), m_nHashTableSize(17), @@ -165,192 +159,6 @@ void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc) { RemoveAll(); } } -CFX_MapByteStringToPtr::CFX_MapByteStringToPtr(int nBlockSize) - : m_pHashTable(NULL), - m_nHashTableSize(17), - m_nCount(0), - m_pFreeList(NULL), - m_pBlocks(NULL), - m_nBlockSize(nBlockSize) { - ASSERT(m_nBlockSize > 0); -} -void CFX_MapByteStringToPtr::RemoveAll() { - if (m_pHashTable != NULL) { - for (FX_DWORD nHash = 0; nHash < m_nHashTableSize; nHash++) { - CAssoc* pAssoc; - for (pAssoc = m_pHashTable[nHash]; pAssoc != NULL; - pAssoc = pAssoc->pNext) { - DestructElement(&pAssoc->key); - } - } - FX_Free(m_pHashTable); - m_pHashTable = NULL; - } - m_nCount = 0; - m_pFreeList = NULL; - m_pBlocks->FreeDataChain(); - m_pBlocks = NULL; -} -CFX_MapByteStringToPtr::~CFX_MapByteStringToPtr() { - RemoveAll(); - ASSERT(m_nCount == 0); -} -void CFX_MapByteStringToPtr::GetNextAssoc(FX_POSITION& rNextPosition, - CFX_ByteString& rKey, - void*& rValue) const { - ASSERT(m_pHashTable != NULL); - CAssoc* pAssocRet = (CAssoc*)rNextPosition; - ASSERT(pAssocRet != NULL); - if (pAssocRet == (CAssoc*)-1) { - for (FX_DWORD nBucket = 0; nBucket < m_nHashTableSize; nBucket++) - if ((pAssocRet = m_pHashTable[nBucket]) != NULL) { - break; - } - ASSERT(pAssocRet != NULL); - } - CAssoc* pAssocNext; - if ((pAssocNext = pAssocRet->pNext) == NULL) { - for (FX_DWORD nBucket = pAssocRet->nHashValue + 1; - nBucket < m_nHashTableSize; nBucket++) - if ((pAssocNext = m_pHashTable[nBucket]) != NULL) { - break; - } - } - rNextPosition = (FX_POSITION)pAssocNext; - rKey = pAssocRet->key; - rValue = pAssocRet->value; -} -void* CFX_MapByteStringToPtr::GetNextValue(FX_POSITION& rNextPosition) const { - ASSERT(m_pHashTable != NULL); - CAssoc* pAssocRet = (CAssoc*)rNextPosition; - ASSERT(pAssocRet != NULL); - if (pAssocRet == (CAssoc*)-1) { - for (FX_DWORD nBucket = 0; nBucket < m_nHashTableSize; nBucket++) - if ((pAssocRet = m_pHashTable[nBucket]) != NULL) { - break; - } - ASSERT(pAssocRet != NULL); - } - CAssoc* pAssocNext; - if ((pAssocNext = pAssocRet->pNext) == NULL) { - for (FX_DWORD nBucket = pAssocRet->nHashValue + 1; - nBucket < m_nHashTableSize; nBucket++) - if ((pAssocNext = m_pHashTable[nBucket]) != NULL) { - break; - } - } - rNextPosition = (FX_POSITION)pAssocNext; - return pAssocRet->value; -} -void*& CFX_MapByteStringToPtr::operator[](const CFX_ByteStringC& key) { - FX_DWORD nHash; - CAssoc* pAssoc; - if ((pAssoc = GetAssocAt(key, nHash)) == NULL) { - if (m_pHashTable == NULL) { - InitHashTable(m_nHashTableSize); - } - pAssoc = NewAssoc(); - pAssoc->nHashValue = nHash; - pAssoc->key = key; - pAssoc->pNext = m_pHashTable[nHash]; - m_pHashTable[nHash] = pAssoc; - } - return pAssoc->value; -} -CFX_MapByteStringToPtr::CAssoc* CFX_MapByteStringToPtr::NewAssoc() { - if (m_pFreeList == NULL) { - CFX_Plex* newBlock = CFX_Plex::Create( - m_pBlocks, m_nBlockSize, sizeof(CFX_MapByteStringToPtr::CAssoc)); - CFX_MapByteStringToPtr::CAssoc* pAssoc = - (CFX_MapByteStringToPtr::CAssoc*)newBlock->data(); - pAssoc += m_nBlockSize - 1; - for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) { - pAssoc->pNext = m_pFreeList; - m_pFreeList = pAssoc; - } - } - ASSERT(m_pFreeList != NULL); - CFX_MapByteStringToPtr::CAssoc* pAssoc = m_pFreeList; - m_pFreeList = m_pFreeList->pNext; - m_nCount++; - ASSERT(m_nCount > 0); - ConstructElement(&pAssoc->key); - pAssoc->value = 0; - return pAssoc; -} -void CFX_MapByteStringToPtr::FreeAssoc(CFX_MapByteStringToPtr::CAssoc* pAssoc) { - DestructElement(&pAssoc->key); - pAssoc->pNext = m_pFreeList; - m_pFreeList = pAssoc; - m_nCount--; - ASSERT(m_nCount >= 0); - if (m_nCount == 0) { - RemoveAll(); - } -} -CFX_MapByteStringToPtr::CAssoc* CFX_MapByteStringToPtr::GetAssocAt( - const CFX_ByteStringC& key, - FX_DWORD& nHash) const { - nHash = HashKey(key) % m_nHashTableSize; - if (m_pHashTable == NULL) { - return NULL; - } - CAssoc* pAssoc; - for (pAssoc = m_pHashTable[nHash]; pAssoc != NULL; pAssoc = pAssoc->pNext) { - if (pAssoc->key == key) { - return pAssoc; - } - } - return NULL; -} -FX_BOOL CFX_MapByteStringToPtr::Lookup(const CFX_ByteStringC& key, - void*& rValue) const { - FX_DWORD nHash; - CAssoc* pAssoc = GetAssocAt(key, nHash); - if (pAssoc == NULL) { - return FALSE; - } - rValue = pAssoc->value; - return TRUE; -} -void CFX_MapByteStringToPtr::InitHashTable(FX_DWORD nHashSize, - FX_BOOL bAllocNow) { - ASSERT(m_nCount == 0); - ASSERT(nHashSize > 0); - FX_Free(m_pHashTable); - m_pHashTable = NULL; - if (bAllocNow) { - m_pHashTable = FX_Alloc(CAssoc*, nHashSize); - } - m_nHashTableSize = nHashSize; -} -inline FX_DWORD CFX_MapByteStringToPtr::HashKey( - const CFX_ByteStringC& key) const { - FX_DWORD nHash = 0; - int len = key.GetLength(); - const uint8_t* buf = key.GetPtr(); - for (int i = 0; i < len; i++) { - nHash = (nHash << 5) + nHash + buf[i]; - } - return nHash; -} -FX_BOOL CFX_MapByteStringToPtr::RemoveKey(const CFX_ByteStringC& key) { - if (m_pHashTable == NULL) { - return FALSE; - } - CAssoc** ppAssocPrev; - ppAssocPrev = &m_pHashTable[HashKey(key) % m_nHashTableSize]; - CAssoc* pAssoc; - for (pAssoc = *ppAssocPrev; pAssoc != NULL; pAssoc = pAssoc->pNext) { - if (pAssoc->key == key) { - *ppAssocPrev = pAssoc->pNext; - FreeAssoc(pAssoc); - return TRUE; - } - ppAssocPrev = &pAssoc->pNext; - } - return FALSE; -} struct _CompactString { uint8_t m_CompactLen; uint8_t m_LenHigh; diff --git a/core/src/fxge/ge/fx_ge_fontmap.cpp b/core/src/fxge/ge/fx_ge_fontmap.cpp index 100688c4e0..f4091e0136 100644 --- a/core/src/fxge/ge/fx_ge_fontmap.cpp +++ b/core/src/fxge/ge/fx_ge_fontmap.cpp @@ -9,9 +9,31 @@ #include "../../../include/fxge/fx_ge.h" #include "../../../include/fxge/fx_freetype.h" #include "text_int.h" + #define GET_TT_SHORT(w) (FX_WORD)(((w)[0] << 8) | (w)[1]) #define GET_TT_LONG(w) \ (FX_DWORD)(((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3]) + +namespace { + +CFX_ByteString KeyNameFromFace(const CFX_ByteString& face_name, + int weight, + FX_BOOL bItalic) { + CFX_ByteString key(face_name); + key += ','; + key += CFX_ByteString::FormatInteger(weight); + key += bItalic ? 'I' : 'N'; + return key; +} + +CFX_ByteString KeyNameFromSize(int ttc_size, FX_DWORD checksum) { + CFX_ByteString key; + key.Format("%d:%d", ttc_size, checksum); + return key; +} + +} // namespace + CFX_SubstFont::CFX_SubstFont() { m_ExtHandle = NULL; m_Charset = 0; @@ -74,14 +96,10 @@ void CFX_FontMgr::InitFTLibrary() { } } void CFX_FontMgr::FreeCache() { - FX_POSITION pos = m_FaceMap.GetStartPosition(); - while (pos) { - CFX_ByteString Key; - CTTFontDesc* face; - m_FaceMap.GetNextAssoc(pos, Key, (void*&)face); - delete face; - } - m_FaceMap.RemoveAll(); + for (const auto& pair : m_FaceMap) { + delete pair.second; + } + m_FaceMap.clear(); } void CFX_FontMgr::SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo) { m_pBuiltinMapper->SetSystemFontInfo(pFontInfo); @@ -103,18 +121,14 @@ FXFT_Face CFX_FontMgr::GetCachedFace(const CFX_ByteString& face_name, int weight, FX_BOOL bItalic, uint8_t*& pFontData) { - CFX_ByteString key(face_name); - key += ','; - key += CFX_ByteString::FormatInteger(weight); - key += bItalic ? 'I' : 'N'; - CTTFontDesc* pFontDesc = NULL; - m_FaceMap.Lookup(key, (void*&)pFontDesc); - if (pFontDesc) { - pFontData = pFontDesc->m_pFontData; - pFontDesc->m_RefCount++; - return pFontDesc->m_SingleFace.m_pFace; - } - return NULL; + auto it = m_FaceMap.find(KeyNameFromFace(face_name, weight, bItalic)); + if (it == m_FaceMap.end()) + return nullptr; + + CTTFontDesc* pFontDesc = it->second; + pFontData = pFontDesc->m_pFontData; + pFontDesc->m_RefCount++; + return pFontDesc->m_SingleFace.m_pFace; } FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name, int weight, @@ -145,11 +159,7 @@ FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name, delete pFontDesc; return NULL; } - CFX_ByteString key(face_name); - key += ','; - key += CFX_ByteString::FormatInteger(weight); - key += bItalic ? 'I' : 'N'; - m_FaceMap.SetAt(key, pFontDesc); + m_FaceMap[KeyNameFromFace(face_name, weight, bItalic)] = pFontDesc; return pFontDesc->m_SingleFace.m_pFace; } const FX_CHAR* const g_Base14FontNames[14] = { @@ -302,17 +312,15 @@ FXFT_Face CFX_FontMgr::GetCachedTTCFace(int ttc_size, FX_DWORD checksum, int font_offset, uint8_t*& pFontData) { - CFX_ByteString key; - key.Format("%d:%d", ttc_size, checksum); - CTTFontDesc* pFontDesc = NULL; - m_FaceMap.Lookup(key, (void*&)pFontDesc); - if (pFontDesc == NULL) { - return NULL; - } + auto it = m_FaceMap.find(KeyNameFromSize(ttc_size, checksum)); + if (it == m_FaceMap.end()) + return nullptr; + + CTTFontDesc* pFontDesc = it->second; pFontData = pFontDesc->m_pFontData; pFontDesc->m_RefCount++; int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset); - if (pFontDesc->m_TTCFace.m_pFaces[face_index] == NULL) { + if (!pFontDesc->m_TTCFace.m_pFaces[face_index]) { pFontDesc->m_TTCFace.m_pFaces[face_index] = GetFixedFace(pFontDesc->m_pFontData, ttc_size, face_index); } @@ -323,8 +331,6 @@ FXFT_Face CFX_FontMgr::AddCachedTTCFace(int ttc_size, uint8_t* pData, FX_DWORD size, int font_offset) { - CFX_ByteString key; - key.Format("%d:%d", ttc_size, checksum); CTTFontDesc* pFontDesc = new CTTFontDesc; pFontDesc->m_Type = 2; pFontDesc->m_pFontData = pData; @@ -332,8 +338,7 @@ FXFT_Face CFX_FontMgr::AddCachedTTCFace(int ttc_size, pFontDesc->m_TTCFace.m_pFaces[i] = NULL; } pFontDesc->m_RefCount++; - key.Format("%d:%d", ttc_size, checksum); - m_FaceMap.SetAt(key, pFontDesc); + m_FaceMap[KeyNameFromSize(ttc_size, checksum)] = pFontDesc; int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset); pFontDesc->m_TTCFace.m_pFaces[face_index] = GetFixedFace(pFontDesc->m_pFontData, ttc_size, face_index); @@ -376,16 +381,14 @@ FXFT_Face CFX_FontMgr::GetFileFace(const FX_CHAR* filename, int face_index) { return face; } void CFX_FontMgr::ReleaseFace(FXFT_Face face) { - if (face == NULL) { + if (!face) { return; } - FX_POSITION pos = m_FaceMap.GetStartPosition(); - while (pos) { - CFX_ByteString Key; - CTTFontDesc* ttface; - m_FaceMap.GetNextAssoc(pos, Key, (void*&)ttface); - if (ttface->ReleaseFace(face)) { - m_FaceMap.RemoveKey(Key); + auto it = m_FaceMap.begin(); + while (it != m_FaceMap.end()) { + auto temp = it++; + if (temp->second->ReleaseFace(face)) { + m_FaceMap.erase(temp); } } } @@ -1274,12 +1277,8 @@ IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault(const char** pUnused) { #endif CFX_FolderFontInfo::CFX_FolderFontInfo() {} CFX_FolderFontInfo::~CFX_FolderFontInfo() { - FX_POSITION pos = m_FontList.GetStartPosition(); - while (pos) { - CFX_ByteString key; - void* value; - m_FontList.GetNextAssoc(pos, key, value); - delete (CFX_FontFaceInfo*)value; + for (const auto& pair : m_FontList) { + delete pair.second; } } void CFX_FolderFontInfo::AddPath(const CFX_ByteStringC& path) { @@ -1389,8 +1388,7 @@ void CFX_FolderFontInfo::ReportFace(CFX_ByteString& path, if (style != "Regular") { facename += " " + style; } - void* p; - if (m_FontList.Lookup(facename, p)) { + if (m_FontList.find(facename) != m_FontList.end()) { return; } CFX_FontFaceInfo* pInfo = @@ -1434,7 +1432,7 @@ void CFX_FolderFontInfo::ReportFace(CFX_ByteString& path, if (facename.Find(FX_BSTRC("Serif")) > -1) { pInfo->m_Styles |= FXFONT_SERIF; } - m_FontList.SetAt(facename, pInfo); + m_FontList[facename] = pInfo; } void* CFX_FolderFontInfo::MapFont(int weight, FX_BOOL bItalic, @@ -1445,11 +1443,8 @@ void* CFX_FolderFontInfo::MapFont(int weight, return NULL; } void* CFX_FolderFontInfo::GetFont(const FX_CHAR* face) { - void* p; - if (!m_FontList.Lookup(face, p)) { - return NULL; - } - return p; + auto it = m_FontList.find(face); + return it != m_FontList.end() ? it->second : nullptr; } FX_DWORD CFX_FolderFontInfo::GetFontData(void* hFont, FX_DWORD table, diff --git a/core/src/fxge/ge/fx_ge_linux.cpp b/core/src/fxge/ge/fx_ge_linux.cpp index 8ff0a4e5b1..065fd124bb 100644 --- a/core/src/fxge/ge/fx_ge_linux.cpp +++ b/core/src/fxge/ge/fx_ge_linux.cpp @@ -105,7 +105,6 @@ void* CFX_LinuxFontInfo::MapFont(int weight, if (iBaseFont < 12) { return GetFont(face); } - void* p = NULL; FX_BOOL bCJK = TRUE; switch (charset) { case FXFONT_SHIFTJIS_CHARSET: { @@ -113,34 +112,36 @@ void* CFX_LinuxFontInfo::MapFont(int weight, if (index < 0) { break; } - for (int32_t i = 0; i < LINUX_GPNAMESIZE; i++) - if (m_FontList.Lookup(LinuxGpFontList[index].NameArr[i], p)) { - return p; + for (int32_t i = 0; i < LINUX_GPNAMESIZE; i++) { + auto it = m_FontList.find(LinuxGpFontList[index].NameArr[i]); + if (it != m_FontList.end()) { + return it->second; } + } } break; case FXFONT_GB2312_CHARSET: { - static int32_t s_gbCount = - sizeof(g_LinuxGbFontList) / sizeof(const FX_CHAR*); - for (int32_t i = 0; i < s_gbCount; i++) - if (m_FontList.Lookup(g_LinuxGbFontList[i], p)) { - return p; + for (int32_t i = 0; i < FX_ArraySize(g_LinuxGbFontList); ++i) { + auto it = m_FontList.find(g_LinuxGbFontList[i]); + if (it != m_FontList.end()) { + return it->second; } + } } break; case FXFONT_CHINESEBIG5_CHARSET: { - static int32_t s_b5Count = - sizeof(g_LinuxB5FontList) / sizeof(const FX_CHAR*); - for (int32_t i = 0; i < s_b5Count; i++) - if (m_FontList.Lookup(g_LinuxB5FontList[i], p)) { - return p; + for (int32_t i = 0; i < FX_ArraySize(g_LinuxB5FontList); ++i) { + auto it = m_FontList.find(g_LinuxB5FontList[i]); + if (it != m_FontList.end()) { + return it->second; } + } } break; case FXFONT_HANGEUL_CHARSET: { - static int32_t s_hgCount = - sizeof(g_LinuxHGFontList) / sizeof(const FX_CHAR*); - for (int32_t i = 0; i < s_hgCount; i++) - if (m_FontList.Lookup(g_LinuxHGFontList[i], p)) { - return p; + for (int32_t i = 0; i < FX_ArraySize(g_LinuxHGFontList); ++i) { + auto it = m_FontList.find(g_LinuxHGFontList[i]); + if (it != m_FontList.end()) { + return it->second; } + } } break; default: bCJK = FALSE; @@ -201,11 +202,9 @@ void* CFX_LinuxFontInfo::FindFont(int weight, CFX_FontFaceInfo* pFind = NULL; FX_DWORD charset_flag = _LinuxGetCharset(charset); int32_t iBestSimilar = 0; - FX_POSITION pos = m_FontList.GetStartPosition(); - while (pos) { - CFX_ByteString bsName; - CFX_FontFaceInfo* pFont = NULL; - m_FontList.GetNextAssoc(pos, bsName, (void*&)pFont); + for (const auto& it : m_FontList) { + const CFX_ByteString& bsName = it.first; + CFX_FontFaceInfo* pFont = it.second; if (!(pFont->m_Charsets & charset_flag) && charset != FXFONT_DEFAULT_CHARSET) { continue; diff --git a/core/src/fxge/ge/fx_ge_text.cpp b/core/src/fxge/ge/fx_ge_text.cpp index 0d4e9d5359..1b839e0080 100644 --- a/core/src/fxge/ge/fx_ge_text.cpp +++ b/core/src/fxge/ge/fx_ge_text.cpp @@ -1232,15 +1232,11 @@ CFX_FaceCache::CFX_FaceCache(FXFT_Face face) { m_Face = face; } CFX_FaceCache::~CFX_FaceCache() { - FX_POSITION pos = m_SizeMap.GetStartPosition(); - CFX_ByteString Key; - CFX_SizeGlyphCache* pSizeCache = NULL; - while (pos) { - m_SizeMap.GetNextAssoc(pos, Key, (void*&)pSizeCache); - delete pSizeCache; + for (const auto& pair : m_SizeMap) { + delete pair.second; } - m_SizeMap.RemoveAll(); - pos = m_PathMap.GetStartPosition(); + m_SizeMap.clear(); + FX_POSITION pos = m_PathMap.GetStartPosition(); void* key1; CFX_PathData* pPath; while (pos) { @@ -1260,10 +1256,13 @@ CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap( FX_BOOL bFontStyle, int dest_width, int anti_alias) { - CFX_SizeGlyphCache* pSizeCache = NULL; - if (!m_SizeMap.Lookup(FaceGlyphsKey, (void*&)pSizeCache)) { + CFX_SizeGlyphCache* pSizeCache; + auto it = m_SizeMap.find(FaceGlyphsKey); + if (it == m_SizeMap.end()) { pSizeCache = new CFX_SizeGlyphCache; - m_SizeMap.SetAt(FaceGlyphsKey, pSizeCache); + m_SizeMap[FaceGlyphsKey] = pSizeCache; + } else { + pSizeCache = it->second; } CFX_GlyphBitmap* pGlyphBitmap = NULL; if (pSizeCache->m_GlyphMap.Lookup((void*)(uintptr_t)glyph_index, |