OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "font_int.h" | 7 #include "font_int.h" |
8 | 8 |
9 #include "core/src/fpdfapi/fpdf_page/pageint.h" | 9 #include "core/src/fpdfapi/fpdf_page/pageint.h" |
10 #include "core/include/fpdfapi/fpdf_module.h" | 10 #include "core/include/fpdfapi/fpdf_module.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 if (FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]) == | 24 if (FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]) == |
25 platform_id && | 25 platform_id && |
26 FXFT_Get_Charmap_EncodingID(FXFT_Get_Face_Charmaps(face)[i]) == | 26 FXFT_Get_Charmap_EncodingID(FXFT_Get_Face_Charmaps(face)[i]) == |
27 encoding_id) { | 27 encoding_id) { |
28 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[i]); | 28 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[i]); |
29 return TRUE; | 29 return TRUE; |
30 } | 30 } |
31 } | 31 } |
32 return FALSE; | 32 return FALSE; |
33 } | 33 } |
34 CPDF_FontGlobals::CPDF_FontGlobals() : m_pContrastRamps(NULL) { | 34 |
| 35 CFX_StockFontArray::CFX_StockFontArray() {} |
| 36 |
| 37 CFX_StockFontArray::~CFX_StockFontArray() { |
| 38 for (size_t i = 0; i < FX_ArraySize(m_StockFonts); ++i) { |
| 39 if (!m_StockFonts[i]) |
| 40 continue; |
| 41 CPDF_Dictionary* pFontDict = m_StockFonts[i]->GetFontDict(); |
| 42 if (pFontDict) |
| 43 pFontDict->Release(); |
| 44 } |
| 45 } |
| 46 |
| 47 CPDF_Font* CFX_StockFontArray::GetFont(int index) const { |
| 48 if (index < 0 || index >= FX_ArraySize(m_StockFonts)) |
| 49 return nullptr; |
| 50 return m_StockFonts[index].get(); |
| 51 } |
| 52 |
| 53 void CFX_StockFontArray::SetFont(int index, CPDF_Font* font) { |
| 54 if (index < 0 || index >= FX_ArraySize(m_StockFonts)) |
| 55 return; |
| 56 m_StockFonts[index].reset(font); |
| 57 } |
| 58 |
| 59 CPDF_FontGlobals::CPDF_FontGlobals() { |
35 FXSYS_memset(m_EmbeddedCharsets, 0, sizeof(m_EmbeddedCharsets)); | 60 FXSYS_memset(m_EmbeddedCharsets, 0, sizeof(m_EmbeddedCharsets)); |
36 FXSYS_memset(m_EmbeddedToUnicodes, 0, sizeof(m_EmbeddedToUnicodes)); | 61 FXSYS_memset(m_EmbeddedToUnicodes, 0, sizeof(m_EmbeddedToUnicodes)); |
37 } | 62 } |
| 63 |
38 CPDF_FontGlobals::~CPDF_FontGlobals() { | 64 CPDF_FontGlobals::~CPDF_FontGlobals() { |
39 ClearAll(); | |
40 FX_Free(m_pContrastRamps); | |
41 } | 65 } |
42 class CFX_StockFontArray { | |
43 public: | |
44 CFX_StockFontArray() { | |
45 FXSYS_memset(m_pStockFonts, 0, sizeof(m_pStockFonts)); | |
46 } | |
47 ~CFX_StockFontArray() { | |
48 for (size_t i = 0; i < FX_ArraySize(m_pStockFonts); i++) { | |
49 if (!m_pStockFonts[i]) | |
50 continue; | |
51 CPDF_Dictionary* pFontDict = m_pStockFonts[i]->GetFontDict(); | |
52 if (pFontDict) | |
53 pFontDict->Release(); | |
54 delete m_pStockFonts[i]; | |
55 } | |
56 } | |
57 CPDF_Font* GetFont(int index) const { | |
58 if (index < 0 || index >= FX_ArraySize(m_pStockFonts)) | |
59 return NULL; | |
60 return m_pStockFonts[index]; | |
61 } | |
62 void SetFont(int index, CPDF_Font* font) { | |
63 if (index < 0 || index >= FX_ArraySize(m_pStockFonts)) | |
64 return; | |
65 delete m_pStockFonts[index]; | |
66 m_pStockFonts[index] = font; | |
67 } | |
68 | 66 |
69 private: | 67 CPDF_Font* CPDF_FontGlobals::Find(CPDF_Document* pDoc, int index) { |
70 CPDF_Font* m_pStockFonts[14]; | 68 auto it = m_StockMap.find(pDoc); |
71 }; | 69 if (it == m_StockMap.end()) |
72 CPDF_Font* CPDF_FontGlobals::Find(void* key, int index) { | 70 return nullptr; |
73 void* value = NULL; | 71 return it->second ? it->second->GetFont(index) : nullptr; |
74 if (!m_pStockMap.Lookup(key, value)) { | |
75 return NULL; | |
76 } | |
77 if (!value) { | |
78 return NULL; | |
79 } | |
80 return static_cast<CFX_StockFontArray*>(value)->GetFont(index); | |
81 } | 72 } |
82 void CPDF_FontGlobals::Set(void* key, int index, CPDF_Font* pFont) { | 73 |
83 void* value = NULL; | 74 void CPDF_FontGlobals::Set(CPDF_Document* pDoc, int index, CPDF_Font* pFont) { |
84 CFX_StockFontArray* font_array = NULL; | 75 if (!pdfium::ContainsKey(m_StockMap, pDoc)) |
85 if (m_pStockMap.Lookup(key, value)) { | 76 m_StockMap[pDoc].reset(new CFX_StockFontArray); |
86 font_array = static_cast<CFX_StockFontArray*>(value); | 77 m_StockMap[pDoc]->SetFont(index, pFont); |
87 } else { | |
88 font_array = new CFX_StockFontArray(); | |
89 m_pStockMap.SetAt(key, font_array); | |
90 } | |
91 font_array->SetFont(index, pFont); | |
92 } | 78 } |
93 void CPDF_FontGlobals::Clear(void* key) { | 79 |
94 void* value = NULL; | 80 void CPDF_FontGlobals::Clear(CPDF_Document* pDoc) { |
95 if (!m_pStockMap.Lookup(key, value)) { | 81 m_StockMap.erase(pDoc); |
96 return; | |
97 } | |
98 delete static_cast<CFX_StockFontArray*>(value); | |
99 m_pStockMap.RemoveKey(key); | |
100 } | 82 } |
101 void CPDF_FontGlobals::ClearAll() { | 83 |
102 FX_POSITION pos = m_pStockMap.GetStartPosition(); | |
103 while (pos) { | |
104 void* key = NULL; | |
105 void* value = NULL; | |
106 m_pStockMap.GetNextAssoc(pos, key, value); | |
107 delete static_cast<CFX_StockFontArray*>(value); | |
108 m_pStockMap.RemoveKey(key); | |
109 } | |
110 } | |
111 CPDF_Font::CPDF_Font(int fonttype) : m_FontType(fonttype) { | 84 CPDF_Font::CPDF_Font(int fonttype) : m_FontType(fonttype) { |
112 m_FontBBox.left = m_FontBBox.right = m_FontBBox.top = m_FontBBox.bottom = 0; | 85 m_FontBBox.left = m_FontBBox.right = m_FontBBox.top = m_FontBBox.bottom = 0; |
113 m_StemV = m_Ascent = m_Descent = m_ItalicAngle = 0; | 86 m_StemV = m_Ascent = m_Descent = m_ItalicAngle = 0; |
114 m_pFontFile = NULL; | 87 m_pFontFile = NULL; |
115 m_Flags = 0; | 88 m_Flags = 0; |
116 m_pToUnicodeMap = NULL; | 89 m_pToUnicodeMap = NULL; |
117 m_bToUnicodeLoaded = FALSE; | 90 m_bToUnicodeLoaded = FALSE; |
118 m_pCharMap = new CPDF_FontCharMap(this); | 91 m_pCharMap = new CPDF_FontCharMap(this); |
119 } | 92 } |
120 CPDF_Font::~CPDF_Font() { | 93 CPDF_Font::~CPDF_Font() { |
(...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 rect = pChar->m_BBox; | 1734 rect = pChar->m_BBox; |
1762 } | 1735 } |
1763 | 1736 |
1764 CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm) | 1737 CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm) |
1765 : m_pForm(pForm), m_pBitmap(nullptr), m_bColored(FALSE) {} | 1738 : m_pForm(pForm), m_pBitmap(nullptr), m_bColored(FALSE) {} |
1766 | 1739 |
1767 CPDF_Type3Char::~CPDF_Type3Char() { | 1740 CPDF_Type3Char::~CPDF_Type3Char() { |
1768 delete m_pForm; | 1741 delete m_pForm; |
1769 delete m_pBitmap; | 1742 delete m_pBitmap; |
1770 } | 1743 } |
OLD | NEW |