Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: core/src/fpdfapi/fpdf_font/fpdf_font.cpp

Issue 1094763002: Make CFX_StockFontArray more robust. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "../../../include/fpdfapi/fpdf_page.h" 7 #include "../../../include/fpdfapi/fpdf_page.h"
8 #include "../../../include/fpdfapi/fpdf_module.h" 8 #include "../../../include/fpdfapi/fpdf_module.h"
9 #include "../../../include/fpdfapi/fpdf_pageobj.h" 9 #include "../../../include/fpdfapi/fpdf_pageobj.h"
10 #include "font_int.h" 10 #include "font_int.h"
11 #include "../fpdf_page/pageint.h" 11 #include "../fpdf_page/pageint.h"
12 #include "../../../include/fxge/fx_freetype.h" 12 #include "../../../include/fxge/fx_freetype.h"
13
13 FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id) 14 FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id)
14 { 15 {
15 for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i ++) { 16 for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i ++) {
16 if (FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]) == plat form_id && 17 if (FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]) == plat form_id &&
17 FXFT_Get_Charmap_EncodingID(FXFT_Get_Face_Charmaps(face)[i]) == encoding_id) { 18 FXFT_Get_Charmap_EncodingID(FXFT_Get_Face_Charmaps(face)[i]) == encoding_id) {
18 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[i]); 19 FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[i]);
19 return TRUE; 20 return TRUE;
20 } 21 }
21 } 22 }
22 return FALSE; 23 return FALSE;
23 } 24 }
24 extern const FX_WORD* PDF_UnicodesForPredefinedCharSet(int); 25 extern const FX_WORD* PDF_UnicodesForPredefinedCharSet(int);
25 CPDF_FontGlobals::CPDF_FontGlobals() 26 CPDF_FontGlobals::CPDF_FontGlobals()
27 : m_pContrastRamps(NULL)
26 { 28 {
27 FXSYS_memset32(m_EmbeddedCharsets, 0, sizeof m_EmbeddedCharsets); 29 FXSYS_memset32(m_EmbeddedCharsets, 0, sizeof(m_EmbeddedCharsets));
28 FXSYS_memset32(m_EmbeddedToUnicodes, 0, sizeof m_EmbeddedToUnicodes); 30 FXSYS_memset32(m_EmbeddedToUnicodes, 0, sizeof(m_EmbeddedToUnicodes));
29 m_pContrastRamps = NULL;
30 } 31 }
31 CPDF_FontGlobals::~CPDF_FontGlobals() 32 CPDF_FontGlobals::~CPDF_FontGlobals()
32 { 33 {
33 ClearAll(); 34 ClearAll();
34 if (m_pContrastRamps) { 35 if (m_pContrastRamps) {
35 FX_Free(m_pContrastRamps); 36 FX_Free(m_pContrastRamps);
36 } 37 }
37 } 38 }
38 class CFX_StockFontArray 39 class CFX_StockFontArray
39 { 40 {
40 public: 41 public:
41 CFX_StockFontArray() 42 CFX_StockFontArray()
42 { 43 {
43 FXSYS_memset32(m_pStockFonts, 0, sizeof(CPDF_Font*) * 14); 44 FXSYS_memset32(m_pStockFonts, 0, sizeof(m_pStockFonts));
44 } 45 }
45 CPDF_Font*» » » m_pStockFonts[14]; 46 ~CFX_StockFontArray()
47 {
48 for (int 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)
Tom Sepez 2015/04/16 22:50:01 nit: this is probably a const method.
Lei Zhang 2015/04/16 23:48:19 Done.
58 {
59 if (index < 0 || index >= FX_ArraySize(m_pStockFonts))
60 return NULL;
61 return m_pStockFonts[index];
62 }
63 void SetFont(int index, CPDF_Font* font)
64 {
65 if (index < 0 || index >= FX_ArraySize(m_pStockFonts))
66 return;
67 delete m_pStockFonts[index];
68 m_pStockFonts[index] = font;
69 }
70 private:
71 CPDF_Font* m_pStockFonts[14];
46 }; 72 };
47 CPDF_Font* CPDF_FontGlobals::Find(void* key, int index) 73 CPDF_Font* CPDF_FontGlobals::Find(void* key, int index)
48 { 74 {
49 void* value = NULL; 75 void* value = NULL;
50 if (!m_pStockMap.Lookup(key, value)) { 76 if (!m_pStockMap.Lookup(key, value)) {
51 return NULL; 77 return NULL;
52 } 78 }
53 if (!value) { 79 if (!value) {
54 return NULL; 80 return NULL;
55 } 81 }
56 return ((CFX_StockFontArray*)value)->m_pStockFonts[index]; 82 return static_cast<CFX_StockFontArray*>(value)->GetFont(index);
57 } 83 }
58 void CPDF_FontGlobals::Set(void* key, int index, CPDF_Font* pFont) 84 void CPDF_FontGlobals::Set(void* key, int index, CPDF_Font* pFont)
59 { 85 {
60 void* value = NULL; 86 void* value = NULL;
87 CFX_StockFontArray* font_array = NULL;
61 if (m_pStockMap.Lookup(key, value)) { 88 if (m_pStockMap.Lookup(key, value)) {
62 ((CFX_StockFontArray*)value)->m_pStockFonts[index] = pFont; 89 font_array = static_cast<CFX_StockFontArray*>(value);
63 return; 90 } else {
91 font_array = new CFX_StockFontArray();
92 m_pStockMap.SetAt(key, font_array);
64 } 93 }
65 CFX_StockFontArray* pFonts = new CFX_StockFontArray(); 94 font_array->SetFont(index, pFont);
66 pFonts->m_pStockFonts[index] = pFont;
67 m_pStockMap.SetAt(key, pFonts);
68 } 95 }
69 void CPDF_FontGlobals::Clear(void* key) 96 void CPDF_FontGlobals::Clear(void* key)
70 { 97 {
71 void* value = NULL; 98 void* value = NULL;
72 if (!m_pStockMap.Lookup(key, value)) { 99 if (!m_pStockMap.Lookup(key, value)) {
73 return; 100 return;
74 } 101 }
75 if (value) { 102 delete static_cast<CFX_StockFontArray*>(value);
76 CFX_StockFontArray* pStockFonts = (CFX_StockFontArray*)value;
77 for (int i = 0; i < 14; i ++) {
78 if (pStockFonts->m_pStockFonts[i]) {
79 CPDF_Dictionary* pFontDict = pStockFonts->m_pStockFonts[i]->GetF ontDict();
80 if (pFontDict)
81 pFontDict->Release();
82 delete pStockFonts->m_pStockFonts[i];
83 }
84 }
85 delete pStockFonts;
86 }
87 m_pStockMap.RemoveKey(key); 103 m_pStockMap.RemoveKey(key);
88 } 104 }
89 void CPDF_FontGlobals::ClearAll() 105 void CPDF_FontGlobals::ClearAll()
90 { 106 {
91 FX_POSITION pos = m_pStockMap.GetStartPosition(); 107 FX_POSITION pos = m_pStockMap.GetStartPosition();
92 while (pos) { 108 while (pos) {
93 void *key = NULL; 109 void* key = NULL;
94 void* value = NULL; 110 void* value = NULL;
95 m_pStockMap.GetNextAssoc(pos, key, value); 111 m_pStockMap.GetNextAssoc(pos, key, value);
96 if (value) { 112 delete static_cast<CFX_StockFontArray*>(value);
97 CFX_StockFontArray* pStockFonts = (CFX_StockFontArray*)value;
98 for (int i = 0; i < 14; i ++) {
99 if (pStockFonts->m_pStockFonts[i]) {
100 CPDF_Dictionary* pFontDict = pStockFonts->m_pStockFonts[i]-> GetFontDict();
101 if (pFontDict)
102 pFontDict->Release();
103 delete pStockFonts->m_pStockFonts[i];
104 }
105 }
106 delete pStockFonts;
107 }
108 m_pStockMap.RemoveKey(key); 113 m_pStockMap.RemoveKey(key);
109 } 114 }
110 } 115 }
111 CPDF_Font::CPDF_Font() 116 CPDF_Font::CPDF_Font()
112 { 117 {
113 m_FontType = 0; 118 m_FontType = 0;
114 m_FontBBox.left = m_FontBBox.right = m_FontBBox.top = m_FontBBox.bottom = 0; 119 m_FontBBox.left = m_FontBBox.right = m_FontBBox.top = m_FontBBox.bottom = 0;
115 m_StemV = m_Ascent = m_Descent = m_ItalicAngle = 0; 120 m_StemV = m_Ascent = m_Descent = m_ItalicAngle = 0;
116 m_pFontFile = NULL; 121 m_pFontFile = NULL;
117 m_Flags = 0; 122 m_Flags = 0;
(...skipping 1639 matching lines...) Expand 10 before | Expand all | Expand 10 after
1757 } 1762 }
1758 CPDF_Type3Char::~CPDF_Type3Char() 1763 CPDF_Type3Char::~CPDF_Type3Char()
1759 { 1764 {
1760 if (m_pForm) { 1765 if (m_pForm) {
1761 delete m_pForm; 1766 delete m_pForm;
1762 } 1767 }
1763 if (m_pBitmap) { 1768 if (m_pBitmap) {
1764 delete m_pBitmap; 1769 delete m_pBitmap;
1765 } 1770 }
1766 } 1771 }
OLDNEW
« core/src/fpdfapi/fpdf_font/font_int.h ('K') | « core/src/fpdfapi/fpdf_font/font_int.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698