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 "../../../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/fdrm/fx_crypt.h" | 9 #include "../../../include/fdrm/fx_crypt.h" |
10 #include "../fpdf_font/font_int.h" | 10 #include "../fpdf_font/font_int.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 GetPageData()->ReleaseColorSpace(pCSObj); | 127 GetPageData()->ReleaseColorSpace(pCSObj); |
128 } | 128 } |
129 CPDF_DocPageData::CPDF_DocPageData(CPDF_Document *pPDFDoc) | 129 CPDF_DocPageData::CPDF_DocPageData(CPDF_Document *pPDFDoc) |
130 : m_pPDFDoc(pPDFDoc) | 130 : m_pPDFDoc(pPDFDoc) |
131 , m_FontMap() | 131 , m_FontMap() |
132 , m_ColorSpaceMap() | 132 , m_ColorSpaceMap() |
133 , m_PatternMap() | 133 , m_PatternMap() |
134 , m_ImageMap() | 134 , m_ImageMap() |
135 , m_IccProfileMap() | 135 , m_IccProfileMap() |
136 , m_FontFileMap() | 136 , m_FontFileMap() |
| 137 , m_bForceClear(FALSE) |
137 { | 138 { |
138 m_FontMap.InitHashTable(64); | 139 m_FontMap.InitHashTable(64); |
139 m_ColorSpaceMap.InitHashTable(32); | 140 m_ColorSpaceMap.InitHashTable(32); |
140 m_PatternMap.InitHashTable(16); | 141 m_PatternMap.InitHashTable(16); |
141 m_ImageMap.InitHashTable(64); | 142 m_ImageMap.InitHashTable(64); |
142 m_IccProfileMap.InitHashTable(16); | 143 m_IccProfileMap.InitHashTable(16); |
143 m_FontFileMap.InitHashTable(32); | 144 m_FontFileMap.InitHashTable(32); |
144 } | 145 } |
145 CPDF_DocPageData::~CPDF_DocPageData() | 146 CPDF_DocPageData::~CPDF_DocPageData() |
146 { | 147 { |
147 Clear(FALSE); | 148 Clear(FALSE); |
148 Clear(TRUE); | 149 Clear(TRUE); |
149 } | 150 } |
150 void CPDF_DocPageData::Clear(FX_BOOL bRelease) | 151 void CPDF_DocPageData::Clear(FX_BOOL bForceRelease) |
151 { | 152 { |
152 FX_POSITION pos; | 153 FX_POSITION pos; |
153 FX_DWORD nCount; | 154 FX_DWORD nCount; |
154 { | 155 |
155 pos = m_PatternMap.GetStartPosition(); | 156 m_bForceClear = bForceRelease; |
156 while (pos) { | 157 pos = m_PatternMap.GetStartPosition(); |
157 CPDF_Object* ptObj; | 158 while (pos) { |
158 CPDF_CountedObject<CPDF_Pattern*>* ptData; | 159 CPDF_Object* ptObj; |
159 m_PatternMap.GetNextAssoc(pos, ptObj, ptData); | 160 CPDF_CountedObject<CPDF_Pattern*>* ptData; |
160 nCount = ptData->m_nCount; | 161 m_PatternMap.GetNextAssoc(pos, ptObj, ptData); |
161 if (bRelease || nCount < 2) { | 162 nCount = ptData->m_nCount; |
162 delete ptData->m_Obj; | 163 if (bForceRelease || nCount < 2) { |
163 ptData->m_Obj = NULL; | 164 delete ptData->m_Obj; |
164 } | 165 ptData->m_Obj = NULL; |
165 } | 166 } |
166 } | 167 } |
167 { | 168 pos = m_FontMap.GetStartPosition(); |
168 pos = m_FontMap.GetStartPosition(); | 169 while (pos) { |
169 while (pos) { | 170 CPDF_Dictionary* fontDict; |
170 CPDF_Dictionary* fontDict; | 171 CPDF_CountedObject<CPDF_Font*>* fontData; |
171 CPDF_CountedObject<CPDF_Font*>* fontData; | 172 m_FontMap.GetNextAssoc(pos, fontDict, fontData); |
172 m_FontMap.GetNextAssoc(pos, fontDict, fontData); | 173 nCount = fontData->m_nCount; |
173 nCount = fontData->m_nCount; | 174 if (bForceRelease || nCount < 2) { |
174 if (bRelease || nCount < 2) { | 175 delete fontData->m_Obj; |
175 delete fontData->m_Obj; | 176 fontData->m_Obj = NULL; |
176 fontData->m_Obj = NULL; | |
177 } | |
178 } | 177 } |
179 } | 178 } |
180 { | 179 pos = m_ImageMap.GetStartPosition(); |
181 pos = m_ImageMap.GetStartPosition(); | 180 while (pos) { |
182 while (pos) { | 181 FX_DWORD objNum; |
183 FX_DWORD objNum; | 182 CPDF_CountedObject<CPDF_Image*>* imageData; |
184 CPDF_CountedObject<CPDF_Image*>* imageData; | 183 m_ImageMap.GetNextAssoc(pos, objNum, imageData); |
185 m_ImageMap.GetNextAssoc(pos, objNum, imageData); | 184 nCount = imageData->m_nCount; |
186 nCount = imageData->m_nCount; | 185 if (bForceRelease || nCount < 2) { |
187 if (bRelease || nCount < 2) { | 186 delete imageData->m_Obj; |
188 delete imageData->m_Obj; | 187 delete imageData; |
189 delete imageData; | 188 m_ImageMap.RemoveKey(objNum); |
190 m_ImageMap.RemoveKey(objNum); | |
191 } | |
192 } | 189 } |
193 } | 190 } |
194 { | 191 pos = m_ColorSpaceMap.GetStartPosition(); |
195 pos = m_ColorSpaceMap.GetStartPosition(); | 192 while (pos) { |
196 while (pos) { | 193 CPDF_Object* csKey; |
197 CPDF_Object* csKey; | 194 CPDF_CountedObject<CPDF_ColorSpace*>* csData; |
198 CPDF_CountedObject<CPDF_ColorSpace*>* csData; | 195 m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData); |
199 m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData); | 196 nCount = csData->m_nCount; |
200 nCount = csData->m_nCount; | 197 if (bForceRelease || nCount < 2) { |
201 if (bRelease || nCount < 2) { | 198 csData->m_Obj->ReleaseCS(); |
202 csData->m_Obj->ReleaseCS(); | 199 csData->m_Obj = NULL; |
203 csData->m_Obj = NULL; | |
204 } | |
205 } | 200 } |
206 } | 201 } |
207 { | 202 pos = m_IccProfileMap.GetStartPosition(); |
208 pos = m_IccProfileMap.GetStartPosition(); | 203 while (pos) { |
209 while (pos) { | 204 CPDF_Stream* ipKey; |
210 CPDF_Stream* ipKey; | 205 CPDF_CountedObject<CPDF_IccProfile*>* ipData; |
211 CPDF_CountedObject<CPDF_IccProfile*>* ipData; | 206 m_IccProfileMap.GetNextAssoc(pos, ipKey, ipData); |
212 m_IccProfileMap.GetNextAssoc(pos, ipKey, ipData); | 207 nCount = ipData->m_nCount; |
213 nCount = ipData->m_nCount; | 208 if (bForceRelease || nCount < 2) { |
214 if (bRelease || nCount < 2) { | 209 FX_POSITION pos2 = m_HashProfileMap.GetStartPosition(); |
215 FX_POSITION pos2 = m_HashProfileMap.GetStartPosition(); | 210 while (pos2) { |
216 while (pos2) { | 211 CFX_ByteString bsKey; |
217 CFX_ByteString bsKey; | 212 CPDF_Stream* pFindStream = NULL; |
218 CPDF_Stream* pFindStream = NULL; | 213 m_HashProfileMap.GetNextAssoc(pos2, bsKey, (void*&)pFindStream); |
219 m_HashProfileMap.GetNextAssoc(pos2, bsKey, (void*&)pFindStre
am); | 214 if (ipKey == pFindStream) { |
220 if (ipKey == pFindStream) { | 215 m_HashProfileMap.RemoveKey(bsKey); |
221 m_HashProfileMap.RemoveKey(bsKey); | 216 break; |
222 break; | |
223 } | |
224 } | 217 } |
225 delete ipData->m_Obj; | |
226 delete ipData; | |
227 m_IccProfileMap.RemoveKey(ipKey); | |
228 } | 218 } |
| 219 delete ipData->m_Obj; |
| 220 delete ipData; |
| 221 m_IccProfileMap.RemoveKey(ipKey); |
229 } | 222 } |
230 } | 223 } |
231 { | 224 pos = m_FontFileMap.GetStartPosition(); |
232 pos = m_FontFileMap.GetStartPosition(); | 225 while (pos) { |
233 while (pos) { | 226 CPDF_Stream* ftKey; |
234 CPDF_Stream* ftKey; | 227 CPDF_CountedObject<CPDF_StreamAcc*>* ftData; |
235 CPDF_CountedObject<CPDF_StreamAcc*>* ftData; | 228 m_FontFileMap.GetNextAssoc(pos, ftKey, ftData); |
236 m_FontFileMap.GetNextAssoc(pos, ftKey, ftData); | 229 nCount = ftData->m_nCount; |
237 nCount = ftData->m_nCount; | 230 if (bForceRelease || nCount < 2) { |
238 if (bRelease || nCount < 2) { | 231 delete ftData->m_Obj; |
239 delete ftData->m_Obj; | 232 delete ftData; |
240 delete ftData; | 233 m_FontFileMap.RemoveKey(ftKey); |
241 m_FontFileMap.RemoveKey(ftKey); | |
242 } | |
243 } | 234 } |
244 } | 235 } |
245 } | 236 } |
246 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnl
y) | 237 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnl
y) |
247 { | 238 { |
248 if (!pFontDict) { | 239 if (!pFontDict) { |
249 return NULL; | 240 return NULL; |
250 } | 241 } |
251 if (findOnly) { | 242 if (findOnly) { |
252 CPDF_CountedObject<CPDF_Font*>* fontData; | 243 CPDF_CountedObject<CPDF_Font*>* fontData; |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 m_FontFileMap.SetAt(pFontStream, ftData); | 628 m_FontFileMap.SetAt(pFontStream, ftData); |
638 return pFontFile; | 629 return pFontFile; |
639 } | 630 } |
640 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO
L bForce) | 631 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO
L bForce) |
641 { | 632 { |
642 if (!pFontStream) { | 633 if (!pFontStream) { |
643 return; | 634 return; |
644 } | 635 } |
645 PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>(m_FontFileMap, pFontS
tream, NULL, bForce); | 636 PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>(m_FontFileMap, pFontS
tream, NULL, bForce); |
646 } | 637 } |
OLD | NEW |