diff options
author | Tom Sepez <tsepez@chromium.org> | 2016-01-07 12:12:10 -0800 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2016-01-07 12:12:10 -0800 |
commit | 6a5f9662d1f36d1e67eb3431c0e628096e51aa15 (patch) | |
tree | b391fdbc20b9e6a72606d61885b82fa7702e3351 /core/src/fpdfapi | |
parent | aa0f69ae645455e9a290f13572a03f4387ec758a (diff) | |
download | pdfium-6a5f9662d1f36d1e67eb3431c0e628096e51aa15.tar.xz |
Merge to XFA: Make m_pStockMap a real map.
Original Review URL: https://codereview.chromium.org/1564783003 .
(cherry picked from commit a462162a76b3f487e76d8cc1b1f917f0937ea040)
TBR=thestig@chromium.org
Review URL: https://codereview.chromium.org/1566233002 .
Diffstat (limited to 'core/src/fpdfapi')
-rw-r--r-- | core/src/fpdfapi/fpdf_font/font_int.h | 29 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_font/fpdf_font.cpp | 109 |
2 files changed, 64 insertions, 74 deletions
diff --git a/core/src/fpdfapi/fpdf_font/font_int.h b/core/src/fpdfapi/fpdf_font/font_int.h index 5418ffd2c9..33fa926b2a 100644 --- a/core/src/fpdfapi/fpdf_font/font_int.h +++ b/core/src/fpdfapi/fpdf_font/font_int.h @@ -8,6 +8,7 @@ #define CORE_SRC_FPDFAPI_FPDF_FONT_FONT_INT_H_ #include <map> +#include <memory> #include "core/include/fpdfapi/fpdf_resource.h" #include "core/include/fxcrt/fx_basic.h" @@ -39,14 +40,31 @@ class CPDF_CMapManager { std::map<CFX_ByteString, CPDF_CMap*> m_CMaps; CPDF_CID2UnicodeMap* m_CID2UnicodeMaps[6]; }; + +class CFX_StockFontArray { + public: + CFX_StockFontArray(); + ~CFX_StockFontArray(); + + // Takes ownership of |pFont|. + void SetFont(int index, CPDF_Font* pFont); + CPDF_Font* GetFont(int index) const; + + private: + std::unique_ptr<CPDF_Font> m_StockFonts[14]; +}; + class CPDF_FontGlobals { public: CPDF_FontGlobals(); ~CPDF_FontGlobals(); - void ClearAll(); - void Clear(void* key); - CPDF_Font* Find(void* key, int index); - void Set(void* key, int index, CPDF_Font* pFont); + + void Clear(CPDF_Document* pDoc); + CPDF_Font* Find(CPDF_Document* pDoc, int index); + + // Takes ownership of |pFont|. + void Set(CPDF_Document* key, int index, CPDF_Font* pFont); + CPDF_CMapManager m_CMapManager; struct { const struct FXCMAP_CMap* m_pMapList; @@ -58,8 +76,7 @@ class CPDF_FontGlobals { } m_EmbeddedToUnicodes[CIDSET_NUM_SETS]; private: - CFX_MapPtrToPtr m_pStockMap; - uint8_t* m_pContrastRamps; + std::map<CPDF_Document*, std::unique_ptr<CFX_StockFontArray>> m_StockMap; }; struct CMap_CodeRange { diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp index 003825b898..b90d1147d6 100644 --- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp +++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp @@ -31,83 +31,56 @@ FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id) { } return FALSE; } -CPDF_FontGlobals::CPDF_FontGlobals() : m_pContrastRamps(NULL) { + +CFX_StockFontArray::CFX_StockFontArray() {} + +CFX_StockFontArray::~CFX_StockFontArray() { + for (size_t i = 0; i < FX_ArraySize(m_StockFonts); ++i) { + if (!m_StockFonts[i]) + continue; + CPDF_Dictionary* pFontDict = m_StockFonts[i]->GetFontDict(); + if (pFontDict) + pFontDict->Release(); + } +} + +CPDF_Font* CFX_StockFontArray::GetFont(int index) const { + if (index < 0 || index >= FX_ArraySize(m_StockFonts)) + return nullptr; + return m_StockFonts[index].get(); +} + +void CFX_StockFontArray::SetFont(int index, CPDF_Font* font) { + if (index < 0 || index >= FX_ArraySize(m_StockFonts)) + return; + m_StockFonts[index].reset(font); +} + +CPDF_FontGlobals::CPDF_FontGlobals() { FXSYS_memset(m_EmbeddedCharsets, 0, sizeof(m_EmbeddedCharsets)); FXSYS_memset(m_EmbeddedToUnicodes, 0, sizeof(m_EmbeddedToUnicodes)); } + CPDF_FontGlobals::~CPDF_FontGlobals() { - ClearAll(); - FX_Free(m_pContrastRamps); } -class CFX_StockFontArray { - public: - CFX_StockFontArray() { - FXSYS_memset(m_pStockFonts, 0, sizeof(m_pStockFonts)); - } - ~CFX_StockFontArray() { - for (size_t i = 0; i < FX_ArraySize(m_pStockFonts); i++) { - if (!m_pStockFonts[i]) - continue; - CPDF_Dictionary* pFontDict = m_pStockFonts[i]->GetFontDict(); - if (pFontDict) - pFontDict->Release(); - delete m_pStockFonts[i]; - } - } - CPDF_Font* GetFont(int index) const { - if (index < 0 || index >= FX_ArraySize(m_pStockFonts)) - return NULL; - return m_pStockFonts[index]; - } - void SetFont(int index, CPDF_Font* font) { - if (index < 0 || index >= FX_ArraySize(m_pStockFonts)) - return; - delete m_pStockFonts[index]; - m_pStockFonts[index] = font; - } - private: - CPDF_Font* m_pStockFonts[14]; -}; -CPDF_Font* CPDF_FontGlobals::Find(void* key, int index) { - void* value = NULL; - if (!m_pStockMap.Lookup(key, value)) { - return NULL; - } - if (!value) { - return NULL; - } - return static_cast<CFX_StockFontArray*>(value)->GetFont(index); -} -void CPDF_FontGlobals::Set(void* key, int index, CPDF_Font* pFont) { - void* value = NULL; - CFX_StockFontArray* font_array = NULL; - if (m_pStockMap.Lookup(key, value)) { - font_array = static_cast<CFX_StockFontArray*>(value); - } else { - font_array = new CFX_StockFontArray(); - m_pStockMap.SetAt(key, font_array); - } - font_array->SetFont(index, pFont); +CPDF_Font* CPDF_FontGlobals::Find(CPDF_Document* pDoc, int index) { + auto it = m_StockMap.find(pDoc); + if (it == m_StockMap.end()) + return nullptr; + return it->second ? it->second->GetFont(index) : nullptr; } -void CPDF_FontGlobals::Clear(void* key) { - void* value = NULL; - if (!m_pStockMap.Lookup(key, value)) { - return; - } - delete static_cast<CFX_StockFontArray*>(value); - m_pStockMap.RemoveKey(key); + +void CPDF_FontGlobals::Set(CPDF_Document* pDoc, int index, CPDF_Font* pFont) { + if (!pdfium::ContainsKey(m_StockMap, pDoc)) + m_StockMap[pDoc].reset(new CFX_StockFontArray); + m_StockMap[pDoc]->SetFont(index, pFont); } -void CPDF_FontGlobals::ClearAll() { - FX_POSITION pos = m_pStockMap.GetStartPosition(); - while (pos) { - void* key = NULL; - void* value = NULL; - m_pStockMap.GetNextAssoc(pos, key, value); - delete static_cast<CFX_StockFontArray*>(value); - m_pStockMap.RemoveKey(key); - } + +void CPDF_FontGlobals::Clear(CPDF_Document* pDoc) { + m_StockMap.erase(pDoc); } + CPDF_Font::CPDF_Font(int fonttype) : m_FontType(fonttype) { m_FontBBox.left = m_FontBBox.right = m_FontBBox.top = m_FontBBox.bottom = 0; m_StemV = m_Ascent = m_Descent = m_ItalicAngle = 0; |