| 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" |
| 11 #include "pageint.h" | 11 #include "pageint.h" |
| 12 class CPDF_PageModule : public CPDF_PageModuleDef | 12 class CPDF_PageModule : public CPDF_PageModuleDef { |
| 13 { | 13 public: |
| 14 public: | 14 CPDF_PageModule() |
| 15 CPDF_PageModule() : m_StockGrayCS(PDFCS_DEVICEGRAY), m_StockRGBCS(PDFCS_DEVI
CERGB), | 15 : m_StockGrayCS(PDFCS_DEVICEGRAY), |
| 16 m_StockRGBCS(PDFCS_DEVICERGB), |
| 16 m_StockCMYKCS(PDFCS_DEVICECMYK) {} | 17 m_StockCMYKCS(PDFCS_DEVICECMYK) {} |
| 17 virtual ~CPDF_PageModule() {} | 18 virtual ~CPDF_PageModule() {} |
| 18 virtual FX_BOOL» » Installed() | 19 virtual FX_BOOL Installed() { return TRUE; } |
| 19 { | 20 virtual CPDF_DocPageData* CreateDocData(CPDF_Document* pDoc) { |
| 20 return TRUE; | 21 return FX_NEW CPDF_DocPageData(pDoc); |
| 21 } | 22 } |
| 22 virtual CPDF_DocPageData*» CreateDocData(CPDF_Document* pDoc) | 23 virtual void ReleaseDoc(CPDF_Document* pDoc); |
| 23 { | 24 virtual void ClearDoc(CPDF_Document* pDoc); |
| 24 return FX_NEW CPDF_DocPageData(pDoc); | 25 virtual CPDF_FontGlobals* GetFontGlobals() { return &m_FontGlobals; } |
| 25 } | 26 virtual void ClearStockFont(CPDF_Document* pDoc) { |
| 26 virtual void» » ReleaseDoc(CPDF_Document* pDoc); | 27 m_FontGlobals.Clear(pDoc); |
| 27 virtual void» » ClearDoc(CPDF_Document* pDoc); | 28 } |
| 28 virtual CPDF_FontGlobals*» GetFontGlobals() | 29 virtual CPDF_ColorSpace* GetStockCS(int family); |
| 29 { | 30 virtual void NotifyCJKAvailable(); |
| 30 return &m_FontGlobals; | 31 CPDF_FontGlobals m_FontGlobals; |
| 31 } | 32 CPDF_DeviceCS m_StockGrayCS; |
| 32 virtual void» » » » ClearStockFont(CPDF_Document* pD
oc) | 33 CPDF_DeviceCS m_StockRGBCS; |
| 33 { | 34 CPDF_DeviceCS m_StockCMYKCS; |
| 34 m_FontGlobals.Clear(pDoc); | 35 CPDF_PatternCS m_StockPatternCS; |
| 35 } | |
| 36 virtual CPDF_ColorSpace*» GetStockCS(int family); | |
| 37 virtual void» » NotifyCJKAvailable(); | |
| 38 CPDF_FontGlobals» m_FontGlobals; | |
| 39 CPDF_DeviceCS» » m_StockGrayCS; | |
| 40 CPDF_DeviceCS» » m_StockRGBCS; | |
| 41 CPDF_DeviceCS» » m_StockCMYKCS; | |
| 42 CPDF_PatternCS» » m_StockPatternCS; | |
| 43 }; | 36 }; |
| 44 CPDF_ColorSpace* CPDF_PageModule::GetStockCS(int family) | 37 CPDF_ColorSpace* CPDF_PageModule::GetStockCS(int family) { |
| 45 { | 38 if (family == PDFCS_DEVICEGRAY) { |
| 46 if (family == PDFCS_DEVICEGRAY) { | 39 return &m_StockGrayCS; |
| 47 return &m_StockGrayCS; | 40 } |
| 48 } | 41 if (family == PDFCS_DEVICERGB) { |
| 49 if (family == PDFCS_DEVICERGB) { | 42 return &m_StockRGBCS; |
| 50 return &m_StockRGBCS; | 43 } |
| 51 } | 44 if (family == PDFCS_DEVICECMYK) { |
| 52 if (family == PDFCS_DEVICECMYK) { | 45 return &m_StockCMYKCS; |
| 53 return &m_StockCMYKCS; | 46 } |
| 54 } | 47 if (family == PDFCS_PATTERN) { |
| 55 if (family == PDFCS_PATTERN) { | 48 return &m_StockPatternCS; |
| 56 return &m_StockPatternCS; | 49 } |
| 57 } | 50 return NULL; |
| 58 return NULL; | 51 } |
| 59 } | 52 void CPDF_ModuleMgr::InitPageModule() { |
| 60 void CPDF_ModuleMgr::InitPageModule() | 53 if (m_pPageModule) { |
| 61 { | 54 delete m_pPageModule; |
| 62 if (m_pPageModule) { | 55 } |
| 63 delete m_pPageModule; | 56 CPDF_PageModule* pPageModule = FX_NEW CPDF_PageModule; |
| 64 } | 57 m_pPageModule = pPageModule; |
| 65 CPDF_PageModule* pPageModule = FX_NEW CPDF_PageModule; | 58 } |
| 66 m_pPageModule = pPageModule; | 59 void CPDF_PageModule::ReleaseDoc(CPDF_Document* pDoc) { |
| 67 } | 60 delete pDoc->GetPageData(); |
| 68 void CPDF_PageModule::ReleaseDoc(CPDF_Document* pDoc) | 61 } |
| 69 { | 62 void CPDF_PageModule::ClearDoc(CPDF_Document* pDoc) { |
| 70 delete pDoc->GetPageData(); | 63 pDoc->GetPageData()->Clear(FALSE); |
| 71 } | 64 } |
| 72 void CPDF_PageModule::ClearDoc(CPDF_Document* pDoc) | 65 void CPDF_PageModule::NotifyCJKAvailable() { |
| 73 { | 66 m_FontGlobals.m_CMapManager.ReloadAll(); |
| 74 pDoc->GetPageData()->Clear(FALSE); | 67 } |
| 75 } | 68 CPDF_Font* CPDF_Document::LoadFont(CPDF_Dictionary* pFontDict) { |
| 76 void CPDF_PageModule::NotifyCJKAvailable() | 69 if (!pFontDict) { |
| 77 { | 70 return NULL; |
| 78 m_FontGlobals.m_CMapManager.ReloadAll(); | 71 } |
| 79 } | 72 return GetValidatePageData()->GetFont(pFontDict, FALSE); |
| 80 CPDF_Font* CPDF_Document::LoadFont(CPDF_Dictionary* pFontDict) | 73 } |
| 81 { | 74 CPDF_Font* CPDF_Document::FindFont(CPDF_Dictionary* pFontDict) { |
| 82 if (!pFontDict) { | 75 if (!pFontDict) { |
| 83 return NULL; | 76 return NULL; |
| 84 } | 77 } |
| 85 return GetValidatePageData()->GetFont(pFontDict, FALSE); | 78 return GetValidatePageData()->GetFont(pFontDict, TRUE); |
| 86 } | 79 } |
| 87 CPDF_Font* CPDF_Document::FindFont(CPDF_Dictionary* pFontDict) | 80 CPDF_StreamAcc* CPDF_Document::LoadFontFile(CPDF_Stream* pStream) { |
| 88 { | 81 if (pStream == NULL) { |
| 89 if (!pFontDict) { | 82 return NULL; |
| 90 return NULL; | 83 } |
| 91 } | 84 return GetValidatePageData()->GetFontFileStreamAcc(pStream); |
| 92 return GetValidatePageData()->GetFont(pFontDict, TRUE); | |
| 93 } | |
| 94 CPDF_StreamAcc* CPDF_Document::LoadFontFile(CPDF_Stream* pStream) | |
| 95 { | |
| 96 if (pStream == NULL) { | |
| 97 return NULL; | |
| 98 } | |
| 99 return GetValidatePageData()->GetFontFileStreamAcc(pStream); | |
| 100 } | 85 } |
| 101 CPDF_ColorSpace* _CSFromName(const CFX_ByteString& name); | 86 CPDF_ColorSpace* _CSFromName(const CFX_ByteString& name); |
| 102 CPDF_ColorSpace* CPDF_Document::LoadColorSpace(CPDF_Object* pCSObj, CPDF_Diction
ary* pResources) | 87 CPDF_ColorSpace* CPDF_Document::LoadColorSpace(CPDF_Object* pCSObj, |
| 103 { | 88 CPDF_Dictionary* pResources) { |
| 104 return GetValidatePageData()->GetColorSpace(pCSObj, pResources); | 89 return GetValidatePageData()->GetColorSpace(pCSObj, pResources); |
| 105 } | 90 } |
| 106 CPDF_Pattern* CPDF_Document::LoadPattern(CPDF_Object* pPatternObj, FX_BOOL bShad
ing, const CFX_AffineMatrix* matrix) | 91 CPDF_Pattern* CPDF_Document::LoadPattern(CPDF_Object* pPatternObj, |
| 107 { | 92 FX_BOOL bShading, |
| 108 return GetValidatePageData()->GetPattern(pPatternObj, bShading, matrix); | 93 const CFX_AffineMatrix* matrix) { |
| 109 } | 94 return GetValidatePageData()->GetPattern(pPatternObj, bShading, matrix); |
| 110 CPDF_IccProfile* CPDF_Document::LoadIccProfile(CPDF_Stream* pStream, int nCompon
ents) | 95 } |
| 111 { | 96 CPDF_IccProfile* CPDF_Document::LoadIccProfile(CPDF_Stream* pStream, |
| 112 return GetValidatePageData()->GetIccProfile(pStream, nComponents); | 97 int nComponents) { |
| 113 } | 98 return GetValidatePageData()->GetIccProfile(pStream, nComponents); |
| 114 CPDF_Image* CPDF_Document::LoadImageF(CPDF_Object* pObj) | 99 } |
| 115 { | 100 CPDF_Image* CPDF_Document::LoadImageF(CPDF_Object* pObj) { |
| 116 if (!pObj) { | 101 if (!pObj) { |
| 117 return NULL; | 102 return NULL; |
| 118 } | 103 } |
| 119 FXSYS_assert(pObj->GetObjNum()); | 104 FXSYS_assert(pObj->GetObjNum()); |
| 120 return GetValidatePageData()->GetImage(pObj); | 105 return GetValidatePageData()->GetImage(pObj); |
| 121 } | 106 } |
| 122 void CPDF_Document::RemoveColorSpaceFromPageData(CPDF_Object* pCSObj) | 107 void CPDF_Document::RemoveColorSpaceFromPageData(CPDF_Object* pCSObj) { |
| 123 { | 108 if (!pCSObj) { |
| 124 if (!pCSObj) { | 109 return; |
| 125 return; | 110 } |
| 126 } | 111 GetPageData()->ReleaseColorSpace(pCSObj); |
| 127 GetPageData()->ReleaseColorSpace(pCSObj); | 112 } |
| 128 } | 113 CPDF_DocPageData::CPDF_DocPageData(CPDF_Document* pPDFDoc) |
| 129 CPDF_DocPageData::CPDF_DocPageData(CPDF_Document *pPDFDoc) | 114 : m_pPDFDoc(pPDFDoc), |
| 130 : m_pPDFDoc(pPDFDoc) | 115 m_FontMap(), |
| 131 , m_FontMap() | 116 m_ColorSpaceMap(), |
| 132 , m_ColorSpaceMap() | 117 m_PatternMap(), |
| 133 , m_PatternMap() | 118 m_ImageMap(), |
| 134 , m_ImageMap() | 119 m_IccProfileMap(), |
| 135 , m_IccProfileMap() | 120 m_FontFileMap() { |
| 136 , m_FontFileMap() | 121 m_FontMap.InitHashTable(64); |
| 137 { | 122 m_ColorSpaceMap.InitHashTable(32); |
| 138 m_FontMap.InitHashTable(64); | 123 m_PatternMap.InitHashTable(16); |
| 139 m_ColorSpaceMap.InitHashTable(32); | 124 m_ImageMap.InitHashTable(64); |
| 140 m_PatternMap.InitHashTable(16); | 125 m_IccProfileMap.InitHashTable(16); |
| 141 m_ImageMap.InitHashTable(64); | 126 m_FontFileMap.InitHashTable(32); |
| 142 m_IccProfileMap.InitHashTable(16); | 127 } |
| 143 m_FontFileMap.InitHashTable(32); | 128 CPDF_DocPageData::~CPDF_DocPageData() { |
| 144 } | 129 Clear(FALSE); |
| 145 CPDF_DocPageData::~CPDF_DocPageData() | 130 Clear(TRUE); |
| 146 { | 131 } |
| 147 Clear(FALSE); | 132 void CPDF_DocPageData::Clear(FX_BOOL bRelease) { |
| 148 Clear(TRUE); | 133 FX_POSITION pos; |
| 149 } | 134 FX_DWORD nCount; |
| 150 void CPDF_DocPageData::Clear(FX_BOOL bRelease) | 135 { |
| 151 { | 136 pos = m_PatternMap.GetStartPosition(); |
| 152 FX_POSITION pos; | |
| 153 FX_DWORD» nCount; | |
| 154 { | |
| 155 pos = m_PatternMap.GetStartPosition(); | |
| 156 while (pos) { | |
| 157 CPDF_Object* ptObj; | |
| 158 CPDF_CountedObject<CPDF_Pattern*>* ptData; | |
| 159 m_PatternMap.GetNextAssoc(pos, ptObj, ptData); | |
| 160 nCount = ptData->m_nCount; | |
| 161 if (bRelease || nCount < 2) { | |
| 162 delete ptData->m_Obj; | |
| 163 ptData->m_Obj = NULL; | |
| 164 } | |
| 165 } | |
| 166 } | |
| 167 { | |
| 168 pos = m_FontMap.GetStartPosition(); | |
| 169 while (pos) { | |
| 170 CPDF_Dictionary* fontDict; | |
| 171 CPDF_CountedObject<CPDF_Font*>* fontData; | |
| 172 m_FontMap.GetNextAssoc(pos, fontDict, fontData); | |
| 173 nCount = fontData->m_nCount; | |
| 174 if (bRelease || nCount < 2) { | |
| 175 delete fontData->m_Obj; | |
| 176 fontData->m_Obj = NULL; | |
| 177 } | |
| 178 } | |
| 179 } | |
| 180 { | |
| 181 pos = m_ImageMap.GetStartPosition(); | |
| 182 while (pos) { | |
| 183 FX_DWORD objNum; | |
| 184 CPDF_CountedObject<CPDF_Image*>* imageData; | |
| 185 m_ImageMap.GetNextAssoc(pos, objNum, imageData); | |
| 186 nCount = imageData->m_nCount; | |
| 187 if (bRelease || nCount < 2) { | |
| 188 delete imageData->m_Obj; | |
| 189 delete imageData; | |
| 190 m_ImageMap.RemoveKey(objNum); | |
| 191 } | |
| 192 } | |
| 193 } | |
| 194 { | |
| 195 pos = m_ColorSpaceMap.GetStartPosition(); | |
| 196 while (pos) { | |
| 197 CPDF_Object* csKey; | |
| 198 CPDF_CountedObject<CPDF_ColorSpace*>* csData; | |
| 199 m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData); | |
| 200 nCount = csData->m_nCount; | |
| 201 if (bRelease || nCount < 2) { | |
| 202 csData->m_Obj->ReleaseCS(); | |
| 203 csData->m_Obj = NULL; | |
| 204 } | |
| 205 } | |
| 206 } | |
| 207 { | |
| 208 pos = m_IccProfileMap.GetStartPosition(); | |
| 209 while (pos) { | |
| 210 CPDF_Stream* ipKey; | |
| 211 CPDF_CountedObject<CPDF_IccProfile*>* ipData; | |
| 212 m_IccProfileMap.GetNextAssoc(pos, ipKey, ipData); | |
| 213 nCount = ipData->m_nCount; | |
| 214 if (bRelease || nCount < 2) { | |
| 215 FX_POSITION pos2 = m_HashProfileMap.GetStartPosition(); | |
| 216 while (pos2) { | |
| 217 CFX_ByteString bsKey; | |
| 218 CPDF_Stream* pFindStream = NULL; | |
| 219 m_HashProfileMap.GetNextAssoc(pos2, bsKey, (void*&)pFindStre
am); | |
| 220 if (ipKey == pFindStream) { | |
| 221 m_HashProfileMap.RemoveKey(bsKey); | |
| 222 break; | |
| 223 } | |
| 224 } | |
| 225 delete ipData->m_Obj; | |
| 226 delete ipData; | |
| 227 m_IccProfileMap.RemoveKey(ipKey); | |
| 228 } | |
| 229 } | |
| 230 } | |
| 231 { | |
| 232 pos = m_FontFileMap.GetStartPosition(); | |
| 233 while (pos) { | |
| 234 CPDF_Stream* ftKey; | |
| 235 CPDF_CountedObject<CPDF_StreamAcc*>* ftData; | |
| 236 m_FontFileMap.GetNextAssoc(pos, ftKey, ftData); | |
| 237 nCount = ftData->m_nCount; | |
| 238 if (bRelease || nCount < 2) { | |
| 239 delete ftData->m_Obj; | |
| 240 delete ftData; | |
| 241 m_FontFileMap.RemoveKey(ftKey); | |
| 242 } | |
| 243 } | |
| 244 } | |
| 245 } | |
| 246 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnl
y) | |
| 247 { | |
| 248 if (!pFontDict) { | |
| 249 return NULL; | |
| 250 } | |
| 251 if (findOnly) { | |
| 252 CPDF_CountedObject<CPDF_Font*>* fontData; | |
| 253 if (m_FontMap.Lookup(pFontDict, fontData)) { | |
| 254 if (!fontData->m_Obj) { | |
| 255 return NULL; | |
| 256 } | |
| 257 fontData->m_nCount ++; | |
| 258 return fontData->m_Obj; | |
| 259 } | |
| 260 return NULL; | |
| 261 } | |
| 262 CPDF_CountedObject<CPDF_Font*>* fontData = NULL; | |
| 263 if (m_FontMap.Lookup(pFontDict, fontData)) { | |
| 264 if (fontData->m_Obj) { | |
| 265 fontData->m_nCount ++; | |
| 266 return fontData->m_Obj; | |
| 267 } | |
| 268 } | |
| 269 FX_BOOL bNew = FALSE; | |
| 270 if (!fontData) { | |
| 271 fontData = FX_NEW CPDF_CountedObject<CPDF_Font*>; | |
| 272 bNew = TRUE; | |
| 273 if (!fontData) { | |
| 274 return NULL; | |
| 275 } | |
| 276 } | |
| 277 CPDF_Font* pFont = CPDF_Font::CreateFontF(m_pPDFDoc, pFontDict); | |
| 278 if (!pFont) { | |
| 279 if (bNew) { | |
| 280 delete fontData; | |
| 281 } | |
| 282 return NULL; | |
| 283 } | |
| 284 fontData->m_nCount = 2; | |
| 285 fontData->m_Obj = pFont; | |
| 286 m_FontMap.SetAt(pFontDict, fontData); | |
| 287 return pFont; | |
| 288 } | |
| 289 CPDF_Font* CPDF_DocPageData::GetStandardFont(FX_BSTR fontName, CPDF_FontEncoding
* pEncoding) | |
| 290 { | |
| 291 if (fontName.IsEmpty()) { | |
| 292 return NULL; | |
| 293 } | |
| 294 FX_POSITION pos = m_FontMap.GetStartPosition(); | |
| 295 while (pos) { | 137 while (pos) { |
| 296 CPDF_Dictionary* fontDict; | 138 CPDF_Object* ptObj; |
| 297 CPDF_CountedObject<CPDF_Font*>* fontData; | 139 CPDF_CountedObject<CPDF_Pattern*>* ptData; |
| 298 m_FontMap.GetNextAssoc(pos, fontDict, fontData); | 140 m_PatternMap.GetNextAssoc(pos, ptObj, ptData); |
| 299 CPDF_Font* pFont = fontData->m_Obj; | 141 nCount = ptData->m_nCount; |
| 300 if (!pFont) { | 142 if (bRelease || nCount < 2) { |
| 301 continue; | 143 delete ptData->m_Obj; |
| 302 } | 144 ptData->m_Obj = NULL; |
| 303 if (pFont->GetBaseFont() != fontName) { | 145 } |
| 304 continue; | 146 } |
| 305 } | 147 } |
| 306 if (pFont->IsEmbedded()) { | 148 { |
| 307 continue; | 149 pos = m_FontMap.GetStartPosition(); |
| 308 } | 150 while (pos) { |
| 309 if (pFont->GetFontType() != PDFFONT_TYPE1) { | 151 CPDF_Dictionary* fontDict; |
| 310 continue; | 152 CPDF_CountedObject<CPDF_Font*>* fontData; |
| 311 } | 153 m_FontMap.GetNextAssoc(pos, fontDict, fontData); |
| 312 if (pFont->GetFontDict()->KeyExist(FX_BSTRC("Widths"))) { | 154 nCount = fontData->m_nCount; |
| 313 continue; | 155 if (bRelease || nCount < 2) { |
| 314 } | |
| 315 CPDF_Type1Font* pT1Font = pFont->GetType1Font(); | |
| 316 if (pEncoding && !pT1Font->GetEncoding()->IsIdentical(pEncoding)) { | |
| 317 continue; | |
| 318 } | |
| 319 fontData->m_nCount ++; | |
| 320 return pFont; | |
| 321 } | |
| 322 CPDF_Dictionary* pDict = FX_NEW CPDF_Dictionary; | |
| 323 pDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Font")); | |
| 324 pDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Type1")); | |
| 325 pDict->SetAtName(FX_BSTRC("BaseFont"), fontName); | |
| 326 if (pEncoding) { | |
| 327 pDict->SetAt(FX_BSTRC("Encoding"), pEncoding->Realize()); | |
| 328 } | |
| 329 m_pPDFDoc->AddIndirectObject(pDict); | |
| 330 CPDF_CountedObject<CPDF_Font*>* fontData = FX_NEW CPDF_CountedObject<CPDF_Fo
nt*>; | |
| 331 if (!fontData) { | |
| 332 return NULL; | |
| 333 } | |
| 334 CPDF_Font* pFont = CPDF_Font::CreateFontF(m_pPDFDoc, pDict); | |
| 335 if (!pFont) { | |
| 336 delete fontData; | |
| 337 return NULL; | |
| 338 } | |
| 339 fontData->m_nCount = 2; | |
| 340 fontData->m_Obj = pFont; | |
| 341 m_FontMap.SetAt(pDict, fontData); | |
| 342 return pFont; | |
| 343 } | |
| 344 void CPDF_DocPageData::ReleaseFont(CPDF_Dictionary* pFontDict) | |
| 345 { | |
| 346 if (!pFontDict) { | |
| 347 return; | |
| 348 } | |
| 349 CPDF_CountedObject<CPDF_Font*>* fontData; | |
| 350 if (!m_FontMap.Lookup(pFontDict, fontData)) { | |
| 351 return; | |
| 352 } | |
| 353 if (fontData->m_Obj && --fontData->m_nCount == 0) { | |
| 354 delete fontData->m_Obj; | 156 delete fontData->m_Obj; |
| 355 fontData->m_Obj = NULL; | 157 fontData->m_Obj = NULL; |
| 356 } | 158 } |
| 357 } | 159 } |
| 358 CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace(CPDF_Object* pCSObj, CPDF_Dicti
onary* pResources) | 160 } |
| 359 { | 161 { |
| 360 if (!pCSObj) { | 162 pos = m_ImageMap.GetStartPosition(); |
| 361 return NULL; | 163 while (pos) { |
| 362 } | 164 FX_DWORD objNum; |
| 363 if (pCSObj->GetType() == PDFOBJ_NAME) { | 165 CPDF_CountedObject<CPDF_Image*>* imageData; |
| 364 CFX_ByteString name = pCSObj->GetConstString(); | 166 m_ImageMap.GetNextAssoc(pos, objNum, imageData); |
| 365 CPDF_ColorSpace* pCS = _CSFromName(name); | 167 nCount = imageData->m_nCount; |
| 366 if (!pCS && pResources) { | 168 if (bRelease || nCount < 2) { |
| 367 CPDF_Dictionary* pList = pResources->GetDict(FX_BSTRC("ColorSpace"))
; | 169 delete imageData->m_Obj; |
| 368 if (pList) { | 170 delete imageData; |
| 369 pCSObj = pList->GetElementValue(name); | 171 m_ImageMap.RemoveKey(objNum); |
| 370 return GetColorSpace(pCSObj, NULL); | 172 } |
| 371 } | 173 } |
| 372 } | 174 } |
| 373 if (pCS == NULL || pResources == NULL) { | 175 { |
| 374 return pCS; | 176 pos = m_ColorSpaceMap.GetStartPosition(); |
| 375 } | 177 while (pos) { |
| 376 CPDF_Dictionary* pColorSpaces = pResources->GetDict(FX_BSTRC("ColorSpace
")); | 178 CPDF_Object* csKey; |
| 377 if (pColorSpaces == NULL) { | 179 CPDF_CountedObject<CPDF_ColorSpace*>* csData; |
| 378 return pCS; | 180 m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData); |
| 379 } | 181 nCount = csData->m_nCount; |
| 380 CPDF_Object* pDefaultCS = NULL; | 182 if (bRelease || nCount < 2) { |
| 381 switch (pCS->GetFamily()) { | |
| 382 case PDFCS_DEVICERGB: | |
| 383 pDefaultCS = pColorSpaces->GetElementValue(FX_BSTRC("DefaultRGB"
)); | |
| 384 break; | |
| 385 case PDFCS_DEVICEGRAY: | |
| 386 pDefaultCS = pColorSpaces->GetElementValue(FX_BSTRC("DefaultGray
")); | |
| 387 break; | |
| 388 case PDFCS_DEVICECMYK: | |
| 389 pDefaultCS = pColorSpaces->GetElementValue(FX_BSTRC("DefaultCMYK
")); | |
| 390 break; | |
| 391 } | |
| 392 if (pDefaultCS == NULL) { | |
| 393 return pCS; | |
| 394 } | |
| 395 return GetColorSpace(pDefaultCS, NULL); | |
| 396 } | |
| 397 if (pCSObj->GetType() != PDFOBJ_ARRAY) { | |
| 398 return NULL; | |
| 399 } | |
| 400 CPDF_Array* pArray = (CPDF_Array*)pCSObj; | |
| 401 if (pArray->GetCount() == 0) { | |
| 402 return NULL; | |
| 403 } | |
| 404 if (pArray->GetCount() == 1) { | |
| 405 return GetColorSpace(pArray->GetElementValue(0), pResources); | |
| 406 } | |
| 407 CPDF_CountedObject<CPDF_ColorSpace*>* csData = NULL; | |
| 408 if (m_ColorSpaceMap.Lookup(pCSObj, csData)) { | |
| 409 if (csData->m_Obj) { | |
| 410 csData->m_nCount++; | |
| 411 return csData->m_Obj; | |
| 412 } | |
| 413 } | |
| 414 FX_BOOL bNew = FALSE; | |
| 415 if (!csData) { | |
| 416 csData = FX_NEW CPDF_CountedObject<CPDF_ColorSpace*>; | |
| 417 if (!csData) { | |
| 418 return NULL; | |
| 419 } | |
| 420 bNew = TRUE; | |
| 421 } | |
| 422 CPDF_ColorSpace* pCS = CPDF_ColorSpace::Load(m_pPDFDoc, pArray); | |
| 423 if (!pCS) { | |
| 424 if (bNew) { | |
| 425 delete csData; | |
| 426 } | |
| 427 return NULL; | |
| 428 } | |
| 429 csData->m_nCount = 2; | |
| 430 csData->m_Obj = pCS; | |
| 431 m_ColorSpaceMap.SetAt(pCSObj, csData); | |
| 432 return pCS; | |
| 433 } | |
| 434 CPDF_ColorSpace* CPDF_DocPageData::GetCopiedColorSpace(CPDF_Object* pCSObj) | |
| 435 { | |
| 436 if (!pCSObj) { | |
| 437 return NULL; | |
| 438 } | |
| 439 CPDF_CountedObject<CPDF_ColorSpace*>* csData; | |
| 440 if (!m_ColorSpaceMap.Lookup(pCSObj, csData)) { | |
| 441 return NULL; | |
| 442 } | |
| 443 if (!csData->m_Obj) { | |
| 444 return NULL; | |
| 445 } | |
| 446 csData->m_nCount ++; | |
| 447 return csData->m_Obj; | |
| 448 } | |
| 449 void CPDF_DocPageData::ReleaseColorSpace(CPDF_Object* pColorSpace) | |
| 450 { | |
| 451 if (!pColorSpace) { | |
| 452 return; | |
| 453 } | |
| 454 CPDF_CountedObject<CPDF_ColorSpace*>* csData; | |
| 455 if (!m_ColorSpaceMap.Lookup(pColorSpace, csData)) { | |
| 456 return; | |
| 457 } | |
| 458 if (csData->m_Obj && --csData->m_nCount == 0) { | |
| 459 csData->m_Obj->ReleaseCS(); | 183 csData->m_Obj->ReleaseCS(); |
| 460 csData->m_Obj = NULL; | 184 csData->m_Obj = NULL; |
| 461 } | 185 } |
| 462 } | 186 } |
| 463 CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, FX_BOOL bSh
ading, const CFX_AffineMatrix* matrix) | 187 } |
| 464 { | 188 { |
| 465 if (!pPatternObj) { | 189 pos = m_IccProfileMap.GetStartPosition(); |
| 190 while (pos) { |
| 191 CPDF_Stream* ipKey; |
| 192 CPDF_CountedObject<CPDF_IccProfile*>* ipData; |
| 193 m_IccProfileMap.GetNextAssoc(pos, ipKey, ipData); |
| 194 nCount = ipData->m_nCount; |
| 195 if (bRelease || nCount < 2) { |
| 196 FX_POSITION pos2 = m_HashProfileMap.GetStartPosition(); |
| 197 while (pos2) { |
| 198 CFX_ByteString bsKey; |
| 199 CPDF_Stream* pFindStream = NULL; |
| 200 m_HashProfileMap.GetNextAssoc(pos2, bsKey, (void*&)pFindStream); |
| 201 if (ipKey == pFindStream) { |
| 202 m_HashProfileMap.RemoveKey(bsKey); |
| 203 break; |
| 204 } |
| 205 } |
| 206 delete ipData->m_Obj; |
| 207 delete ipData; |
| 208 m_IccProfileMap.RemoveKey(ipKey); |
| 209 } |
| 210 } |
| 211 } |
| 212 { |
| 213 pos = m_FontFileMap.GetStartPosition(); |
| 214 while (pos) { |
| 215 CPDF_Stream* ftKey; |
| 216 CPDF_CountedObject<CPDF_StreamAcc*>* ftData; |
| 217 m_FontFileMap.GetNextAssoc(pos, ftKey, ftData); |
| 218 nCount = ftData->m_nCount; |
| 219 if (bRelease || nCount < 2) { |
| 220 delete ftData->m_Obj; |
| 221 delete ftData; |
| 222 m_FontFileMap.RemoveKey(ftKey); |
| 223 } |
| 224 } |
| 225 } |
| 226 } |
| 227 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, |
| 228 FX_BOOL findOnly) { |
| 229 if (!pFontDict) { |
| 230 return NULL; |
| 231 } |
| 232 if (findOnly) { |
| 233 CPDF_CountedObject<CPDF_Font*>* fontData; |
| 234 if (m_FontMap.Lookup(pFontDict, fontData)) { |
| 235 if (!fontData->m_Obj) { |
| 466 return NULL; | 236 return NULL; |
| 467 } | 237 } |
| 468 CPDF_CountedObject<CPDF_Pattern*>* ptData = NULL; | 238 fontData->m_nCount++; |
| 469 if (m_PatternMap.Lookup(pPatternObj, ptData)) { | 239 return fontData->m_Obj; |
| 470 if (ptData->m_Obj) { | 240 } |
| 471 ptData->m_nCount++; | 241 return NULL; |
| 472 return ptData->m_Obj; | 242 } |
| 473 } | 243 CPDF_CountedObject<CPDF_Font*>* fontData = NULL; |
| 474 } | 244 if (m_FontMap.Lookup(pFontDict, fontData)) { |
| 475 FX_BOOL bNew = FALSE; | 245 if (fontData->m_Obj) { |
| 246 fontData->m_nCount++; |
| 247 return fontData->m_Obj; |
| 248 } |
| 249 } |
| 250 FX_BOOL bNew = FALSE; |
| 251 if (!fontData) { |
| 252 fontData = FX_NEW CPDF_CountedObject<CPDF_Font*>; |
| 253 bNew = TRUE; |
| 254 if (!fontData) { |
| 255 return NULL; |
| 256 } |
| 257 } |
| 258 CPDF_Font* pFont = CPDF_Font::CreateFontF(m_pPDFDoc, pFontDict); |
| 259 if (!pFont) { |
| 260 if (bNew) { |
| 261 delete fontData; |
| 262 } |
| 263 return NULL; |
| 264 } |
| 265 fontData->m_nCount = 2; |
| 266 fontData->m_Obj = pFont; |
| 267 m_FontMap.SetAt(pFontDict, fontData); |
| 268 return pFont; |
| 269 } |
| 270 CPDF_Font* CPDF_DocPageData::GetStandardFont(FX_BSTR fontName, |
| 271 CPDF_FontEncoding* pEncoding) { |
| 272 if (fontName.IsEmpty()) { |
| 273 return NULL; |
| 274 } |
| 275 FX_POSITION pos = m_FontMap.GetStartPosition(); |
| 276 while (pos) { |
| 277 CPDF_Dictionary* fontDict; |
| 278 CPDF_CountedObject<CPDF_Font*>* fontData; |
| 279 m_FontMap.GetNextAssoc(pos, fontDict, fontData); |
| 280 CPDF_Font* pFont = fontData->m_Obj; |
| 281 if (!pFont) { |
| 282 continue; |
| 283 } |
| 284 if (pFont->GetBaseFont() != fontName) { |
| 285 continue; |
| 286 } |
| 287 if (pFont->IsEmbedded()) { |
| 288 continue; |
| 289 } |
| 290 if (pFont->GetFontType() != PDFFONT_TYPE1) { |
| 291 continue; |
| 292 } |
| 293 if (pFont->GetFontDict()->KeyExist(FX_BSTRC("Widths"))) { |
| 294 continue; |
| 295 } |
| 296 CPDF_Type1Font* pT1Font = pFont->GetType1Font(); |
| 297 if (pEncoding && !pT1Font->GetEncoding()->IsIdentical(pEncoding)) { |
| 298 continue; |
| 299 } |
| 300 fontData->m_nCount++; |
| 301 return pFont; |
| 302 } |
| 303 CPDF_Dictionary* pDict = FX_NEW CPDF_Dictionary; |
| 304 pDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Font")); |
| 305 pDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Type1")); |
| 306 pDict->SetAtName(FX_BSTRC("BaseFont"), fontName); |
| 307 if (pEncoding) { |
| 308 pDict->SetAt(FX_BSTRC("Encoding"), pEncoding->Realize()); |
| 309 } |
| 310 m_pPDFDoc->AddIndirectObject(pDict); |
| 311 CPDF_CountedObject<CPDF_Font*>* fontData = |
| 312 FX_NEW CPDF_CountedObject<CPDF_Font*>; |
| 313 if (!fontData) { |
| 314 return NULL; |
| 315 } |
| 316 CPDF_Font* pFont = CPDF_Font::CreateFontF(m_pPDFDoc, pDict); |
| 317 if (!pFont) { |
| 318 delete fontData; |
| 319 return NULL; |
| 320 } |
| 321 fontData->m_nCount = 2; |
| 322 fontData->m_Obj = pFont; |
| 323 m_FontMap.SetAt(pDict, fontData); |
| 324 return pFont; |
| 325 } |
| 326 void CPDF_DocPageData::ReleaseFont(CPDF_Dictionary* pFontDict) { |
| 327 if (!pFontDict) { |
| 328 return; |
| 329 } |
| 330 CPDF_CountedObject<CPDF_Font*>* fontData; |
| 331 if (!m_FontMap.Lookup(pFontDict, fontData)) { |
| 332 return; |
| 333 } |
| 334 if (fontData->m_Obj && --fontData->m_nCount == 0) { |
| 335 delete fontData->m_Obj; |
| 336 fontData->m_Obj = NULL; |
| 337 } |
| 338 } |
| 339 CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace(CPDF_Object* pCSObj, |
| 340 CPDF_Dictionary* pResources) { |
| 341 if (!pCSObj) { |
| 342 return NULL; |
| 343 } |
| 344 if (pCSObj->GetType() == PDFOBJ_NAME) { |
| 345 CFX_ByteString name = pCSObj->GetConstString(); |
| 346 CPDF_ColorSpace* pCS = _CSFromName(name); |
| 347 if (!pCS && pResources) { |
| 348 CPDF_Dictionary* pList = pResources->GetDict(FX_BSTRC("ColorSpace")); |
| 349 if (pList) { |
| 350 pCSObj = pList->GetElementValue(name); |
| 351 return GetColorSpace(pCSObj, NULL); |
| 352 } |
| 353 } |
| 354 if (pCS == NULL || pResources == NULL) { |
| 355 return pCS; |
| 356 } |
| 357 CPDF_Dictionary* pColorSpaces = pResources->GetDict(FX_BSTRC("ColorSpace")); |
| 358 if (pColorSpaces == NULL) { |
| 359 return pCS; |
| 360 } |
| 361 CPDF_Object* pDefaultCS = NULL; |
| 362 switch (pCS->GetFamily()) { |
| 363 case PDFCS_DEVICERGB: |
| 364 pDefaultCS = pColorSpaces->GetElementValue(FX_BSTRC("DefaultRGB")); |
| 365 break; |
| 366 case PDFCS_DEVICEGRAY: |
| 367 pDefaultCS = pColorSpaces->GetElementValue(FX_BSTRC("DefaultGray")); |
| 368 break; |
| 369 case PDFCS_DEVICECMYK: |
| 370 pDefaultCS = pColorSpaces->GetElementValue(FX_BSTRC("DefaultCMYK")); |
| 371 break; |
| 372 } |
| 373 if (pDefaultCS == NULL) { |
| 374 return pCS; |
| 375 } |
| 376 return GetColorSpace(pDefaultCS, NULL); |
| 377 } |
| 378 if (pCSObj->GetType() != PDFOBJ_ARRAY) { |
| 379 return NULL; |
| 380 } |
| 381 CPDF_Array* pArray = (CPDF_Array*)pCSObj; |
| 382 if (pArray->GetCount() == 0) { |
| 383 return NULL; |
| 384 } |
| 385 if (pArray->GetCount() == 1) { |
| 386 return GetColorSpace(pArray->GetElementValue(0), pResources); |
| 387 } |
| 388 CPDF_CountedObject<CPDF_ColorSpace*>* csData = NULL; |
| 389 if (m_ColorSpaceMap.Lookup(pCSObj, csData)) { |
| 390 if (csData->m_Obj) { |
| 391 csData->m_nCount++; |
| 392 return csData->m_Obj; |
| 393 } |
| 394 } |
| 395 FX_BOOL bNew = FALSE; |
| 396 if (!csData) { |
| 397 csData = FX_NEW CPDF_CountedObject<CPDF_ColorSpace*>; |
| 398 if (!csData) { |
| 399 return NULL; |
| 400 } |
| 401 bNew = TRUE; |
| 402 } |
| 403 CPDF_ColorSpace* pCS = CPDF_ColorSpace::Load(m_pPDFDoc, pArray); |
| 404 if (!pCS) { |
| 405 if (bNew) { |
| 406 delete csData; |
| 407 } |
| 408 return NULL; |
| 409 } |
| 410 csData->m_nCount = 2; |
| 411 csData->m_Obj = pCS; |
| 412 m_ColorSpaceMap.SetAt(pCSObj, csData); |
| 413 return pCS; |
| 414 } |
| 415 CPDF_ColorSpace* CPDF_DocPageData::GetCopiedColorSpace(CPDF_Object* pCSObj) { |
| 416 if (!pCSObj) { |
| 417 return NULL; |
| 418 } |
| 419 CPDF_CountedObject<CPDF_ColorSpace*>* csData; |
| 420 if (!m_ColorSpaceMap.Lookup(pCSObj, csData)) { |
| 421 return NULL; |
| 422 } |
| 423 if (!csData->m_Obj) { |
| 424 return NULL; |
| 425 } |
| 426 csData->m_nCount++; |
| 427 return csData->m_Obj; |
| 428 } |
| 429 void CPDF_DocPageData::ReleaseColorSpace(CPDF_Object* pColorSpace) { |
| 430 if (!pColorSpace) { |
| 431 return; |
| 432 } |
| 433 CPDF_CountedObject<CPDF_ColorSpace*>* csData; |
| 434 if (!m_ColorSpaceMap.Lookup(pColorSpace, csData)) { |
| 435 return; |
| 436 } |
| 437 if (csData->m_Obj && --csData->m_nCount == 0) { |
| 438 csData->m_Obj->ReleaseCS(); |
| 439 csData->m_Obj = NULL; |
| 440 } |
| 441 } |
| 442 CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, |
| 443 FX_BOOL bShading, |
| 444 const CFX_AffineMatrix* matrix) { |
| 445 if (!pPatternObj) { |
| 446 return NULL; |
| 447 } |
| 448 CPDF_CountedObject<CPDF_Pattern*>* ptData = NULL; |
| 449 if (m_PatternMap.Lookup(pPatternObj, ptData)) { |
| 450 if (ptData->m_Obj) { |
| 451 ptData->m_nCount++; |
| 452 return ptData->m_Obj; |
| 453 } |
| 454 } |
| 455 FX_BOOL bNew = FALSE; |
| 456 if (!ptData) { |
| 457 ptData = FX_NEW CPDF_CountedObject<CPDF_Pattern*>; |
| 458 bNew = TRUE; |
| 476 if (!ptData) { | 459 if (!ptData) { |
| 477 ptData = FX_NEW CPDF_CountedObject<CPDF_Pattern*>; | 460 return NULL; |
| 478 bNew = TRUE; | 461 } |
| 479 if (!ptData) { | 462 } |
| 480 return NULL; | 463 CPDF_Pattern* pPattern = NULL; |
| 481 } | 464 if (bShading) { |
| 482 } | 465 pPattern = |
| 483 CPDF_Pattern* pPattern = NULL; | 466 FX_NEW CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, bShading, matrix); |
| 484 if (bShading) { | 467 } else { |
| 485 pPattern = FX_NEW CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, bShading,
matrix); | 468 CPDF_Dictionary* pDict = pPatternObj ? pPatternObj->GetDict() : NULL; |
| 486 } else { | 469 if (pDict) { |
| 487 CPDF_Dictionary* pDict = pPatternObj ? pPatternObj->GetDict() : NULL; | 470 int type = pDict->GetInteger(FX_BSTRC("PatternType")); |
| 488 if (pDict) { | 471 if (type == 1) { |
| 489 int type = pDict->GetInteger(FX_BSTRC("PatternType")); | 472 pPattern = FX_NEW CPDF_TilingPattern(m_pPDFDoc, pPatternObj, matrix); |
| 490 if (type == 1) { | 473 } else if (type == 2) { |
| 491 pPattern = FX_NEW CPDF_TilingPattern(m_pPDFDoc, pPatternObj, mat
rix); | 474 pPattern = |
| 492 } else if (type == 2) { | 475 FX_NEW CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, FALSE, matrix); |
| 493 pPattern = FX_NEW CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, FA
LSE, matrix); | 476 } |
| 494 } | 477 } |
| 495 } | 478 } |
| 496 } | 479 if (!pPattern) { |
| 497 if (!pPattern) { | 480 if (bNew) { |
| 498 if (bNew) { | 481 delete ptData; |
| 499 delete ptData; | 482 } |
| 500 } | 483 return NULL; |
| 501 return NULL; | 484 } |
| 502 } | 485 ptData->m_nCount = 2; |
| 503 ptData->m_nCount = 2; | 486 ptData->m_Obj = pPattern; |
| 504 ptData->m_Obj = pPattern; | 487 m_PatternMap.SetAt(pPatternObj, ptData); |
| 505 m_PatternMap.SetAt(pPatternObj, ptData); | 488 return pPattern; |
| 506 return pPattern; | 489 } |
| 507 } | 490 void CPDF_DocPageData::ReleasePattern(CPDF_Object* pPatternObj) { |
| 508 void CPDF_DocPageData::ReleasePattern(CPDF_Object* pPatternObj) | 491 if (!pPatternObj) { |
| 509 { | 492 return; |
| 510 if (!pPatternObj) { | 493 } |
| 511 return; | 494 CPDF_CountedObject<CPDF_Pattern*>* ptData; |
| 512 } | 495 if (!m_PatternMap.Lookup(pPatternObj, ptData)) { |
| 513 CPDF_CountedObject<CPDF_Pattern*>* ptData; | 496 return; |
| 514 if (!m_PatternMap.Lookup(pPatternObj, ptData)) { | 497 } |
| 515 return; | 498 if (ptData->m_Obj && --ptData->m_nCount == 0) { |
| 516 } | 499 delete ptData->m_Obj; |
| 517 if (ptData->m_Obj && --ptData->m_nCount == 0) { | 500 ptData->m_Obj = NULL; |
| 518 delete ptData->m_Obj; | 501 } |
| 519 ptData->m_Obj = NULL; | 502 } |
| 520 } | 503 CPDF_Image* CPDF_DocPageData::GetImage(CPDF_Object* pImageStream) { |
| 521 } | 504 if (!pImageStream) { |
| 522 CPDF_Image* CPDF_DocPageData::GetImage(CPDF_Object* pImageStream) | 505 return NULL; |
| 523 { | 506 } |
| 524 if (!pImageStream) { | 507 FX_DWORD dwImageObjNum = pImageStream->GetObjNum(); |
| 525 return NULL; | 508 CPDF_CountedObject<CPDF_Image*>* imageData; |
| 526 } | 509 if (m_ImageMap.Lookup(dwImageObjNum, imageData)) { |
| 527 FX_DWORD dwImageObjNum = pImageStream->GetObjNum(); | 510 imageData->m_nCount++; |
| 528 CPDF_CountedObject<CPDF_Image*>* imageData; | 511 return imageData->m_Obj; |
| 529 if (m_ImageMap.Lookup(dwImageObjNum, imageData)) { | 512 } |
| 530 imageData->m_nCount ++; | 513 imageData = FX_NEW CPDF_CountedObject<CPDF_Image*>; |
| 531 return imageData->m_Obj; | 514 if (!imageData) { |
| 532 } | 515 return NULL; |
| 533 imageData = FX_NEW CPDF_CountedObject<CPDF_Image*>; | 516 } |
| 534 if (!imageData) { | 517 CPDF_Image* pImage = FX_NEW CPDF_Image(m_pPDFDoc); |
| 535 return NULL; | 518 if (!pImage) { |
| 536 } | 519 delete imageData; |
| 537 CPDF_Image* pImage = FX_NEW CPDF_Image(m_pPDFDoc); | 520 return NULL; |
| 538 if (!pImage) { | 521 } |
| 539 delete imageData; | 522 pImage->LoadImageF((CPDF_Stream*)pImageStream, FALSE); |
| 540 return NULL; | 523 imageData->m_nCount = 2; |
| 541 } | 524 imageData->m_Obj = pImage; |
| 542 pImage->LoadImageF((CPDF_Stream*)pImageStream, FALSE); | 525 m_ImageMap.SetAt(dwImageObjNum, imageData); |
| 543 imageData->m_nCount = 2; | 526 return pImage; |
| 544 imageData->m_Obj = pImage; | 527 } |
| 545 m_ImageMap.SetAt(dwImageObjNum, imageData); | 528 void CPDF_DocPageData::ReleaseImage(CPDF_Object* pImageStream) { |
| 546 return pImage; | 529 if (!pImageStream) { |
| 547 } | 530 return; |
| 548 void CPDF_DocPageData::ReleaseImage(CPDF_Object* pImageStream) | 531 } |
| 549 { | 532 PDF_DocPageData_Release<FX_DWORD, CPDF_Image*>( |
| 550 if (!pImageStream) { | 533 m_ImageMap, pImageStream->GetObjNum(), NULL); |
| 551 return; | 534 } |
| 552 } | 535 CPDF_IccProfile* CPDF_DocPageData::GetIccProfile(CPDF_Stream* pIccProfileStream, |
| 553 PDF_DocPageData_Release<FX_DWORD, CPDF_Image*>(m_ImageMap, pImageStream->Get
ObjNum(), NULL); | 536 FX_INT32 nComponents) { |
| 554 } | 537 if (!pIccProfileStream) { |
| 555 CPDF_IccProfile* CPDF_DocPageData::GetIccProfile(CPDF_Stream* pIccProfileStream,
FX_INT32 nComponents) | 538 return NULL; |
| 556 { | 539 } |
| 557 if (!pIccProfileStream) { | 540 CPDF_CountedObject<CPDF_IccProfile*>* ipData = NULL; |
| 558 return NULL; | 541 if (m_IccProfileMap.Lookup(pIccProfileStream, ipData)) { |
| 559 } | 542 ipData->m_nCount++; |
| 560 CPDF_CountedObject<CPDF_IccProfile*>* ipData = NULL; | 543 return ipData->m_Obj; |
| 561 if (m_IccProfileMap.Lookup(pIccProfileStream, ipData)) { | 544 } |
| 562 ipData->m_nCount++; | 545 CPDF_StreamAcc stream; |
| 563 return ipData->m_Obj; | 546 stream.LoadAllData(pIccProfileStream, FALSE); |
| 564 } | 547 FX_BYTE digest[20]; |
| 565 CPDF_StreamAcc stream; | 548 CPDF_Stream* pCopiedStream = NULL; |
| 566 stream.LoadAllData(pIccProfileStream, FALSE); | 549 CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest); |
| 567 FX_BYTE digest[20]; | 550 if (m_HashProfileMap.Lookup(CFX_ByteStringC(digest, 20), |
| 568 CPDF_Stream* pCopiedStream = NULL; | 551 (void*&)pCopiedStream)) { |
| 569 CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest); | 552 m_IccProfileMap.Lookup(pCopiedStream, ipData); |
| 570 if (m_HashProfileMap.Lookup(CFX_ByteStringC(digest, 20), (void*&)pCopiedStre
am)) { | 553 ipData->m_nCount++; |
| 571 m_IccProfileMap.Lookup(pCopiedStream, ipData); | 554 return ipData->m_Obj; |
| 572 ipData->m_nCount++; | 555 } |
| 573 return ipData->m_Obj; | 556 CPDF_IccProfile* pProfile = |
| 574 } | 557 FX_NEW CPDF_IccProfile(stream.GetData(), stream.GetSize(), nComponents); |
| 575 CPDF_IccProfile* pProfile = FX_NEW CPDF_IccProfile(stream.GetData(), stream.
GetSize(), nComponents); | 558 if (!pProfile) { |
| 576 if (!pProfile) { | 559 return NULL; |
| 577 return NULL; | 560 } |
| 578 } | 561 ipData = FX_NEW CPDF_CountedObject<CPDF_IccProfile*>; |
| 579 ipData = FX_NEW CPDF_CountedObject<CPDF_IccProfile*>; | 562 if (!ipData) { |
| 580 if (!ipData) { | 563 delete pProfile; |
| 581 delete pProfile; | 564 return NULL; |
| 582 return NULL; | 565 } |
| 583 } | 566 ipData->m_nCount = 2; |
| 584 ipData->m_nCount = 2; | 567 ipData->m_Obj = pProfile; |
| 585 ipData->m_Obj = pProfile; | 568 m_IccProfileMap.SetAt(pIccProfileStream, ipData); |
| 586 m_IccProfileMap.SetAt(pIccProfileStream, ipData); | 569 m_HashProfileMap.SetAt(CFX_ByteStringC(digest, 20), pIccProfileStream); |
| 587 m_HashProfileMap.SetAt(CFX_ByteStringC(digest, 20), pIccProfileStream); | 570 return pProfile; |
| 588 return pProfile; | 571 } |
| 589 } | 572 void CPDF_DocPageData::ReleaseIccProfile(CPDF_Stream* pIccProfileStream, |
| 590 void CPDF_DocPageData::ReleaseIccProfile(CPDF_Stream* pIccProfileStream, CPDF_Ic
cProfile* pIccProfile) | 573 CPDF_IccProfile* pIccProfile) { |
| 591 { | 574 if (!pIccProfileStream && !pIccProfile) { |
| 592 if (!pIccProfileStream && !pIccProfile) { | 575 return; |
| 593 return; | 576 } |
| 594 } | 577 CPDF_CountedObject<CPDF_IccProfile*>* ipData = NULL; |
| 595 CPDF_CountedObject<CPDF_IccProfile*>* ipData = NULL; | 578 if (m_IccProfileMap.Lookup(pIccProfileStream, ipData) && |
| 596 if (m_IccProfileMap.Lookup(pIccProfileStream, ipData) && ipData->m_nCount <
2) { | 579 ipData->m_nCount < 2) { |
| 597 FX_POSITION pos = m_HashProfileMap.GetStartPosition(); | 580 FX_POSITION pos = m_HashProfileMap.GetStartPosition(); |
| 598 while (pos) { | 581 while (pos) { |
| 599 CFX_ByteString key; | 582 CFX_ByteString key; |
| 600 CPDF_Stream* pFindStream = NULL; | 583 CPDF_Stream* pFindStream = NULL; |
| 601 m_HashProfileMap.GetNextAssoc(pos, key, (void*&)pFindStream); | 584 m_HashProfileMap.GetNextAssoc(pos, key, (void*&)pFindStream); |
| 602 if (pIccProfileStream == pFindStream) { | 585 if (pIccProfileStream == pFindStream) { |
| 603 m_HashProfileMap.RemoveKey(key); | 586 m_HashProfileMap.RemoveKey(key); |
| 604 break; | 587 break; |
| 605 } | 588 } |
| 606 } | 589 } |
| 607 } | 590 } |
| 608 PDF_DocPageData_Release<CPDF_Stream*, CPDF_IccProfile*>(m_IccProfileMap, pIc
cProfileStream, pIccProfile); | 591 PDF_DocPageData_Release<CPDF_Stream*, CPDF_IccProfile*>( |
| 609 } | 592 m_IccProfileMap, pIccProfileStream, pIccProfile); |
| 610 CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc(CPDF_Stream* pFontStream) | 593 } |
| 611 { | 594 CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc( |
| 612 if (!pFontStream) { | 595 CPDF_Stream* pFontStream) { |
| 613 return NULL; | 596 if (!pFontStream) { |
| 614 } | 597 return NULL; |
| 615 CPDF_CountedObject<CPDF_StreamAcc*>* ftData; | 598 } |
| 616 if (m_FontFileMap.Lookup(pFontStream, ftData)) { | 599 CPDF_CountedObject<CPDF_StreamAcc*>* ftData; |
| 617 ftData->m_nCount ++; | 600 if (m_FontFileMap.Lookup(pFontStream, ftData)) { |
| 618 return ftData->m_Obj; | 601 ftData->m_nCount++; |
| 619 } | 602 return ftData->m_Obj; |
| 620 ftData = FX_NEW CPDF_CountedObject<CPDF_StreamAcc*>; | 603 } |
| 621 if (!ftData) { | 604 ftData = FX_NEW CPDF_CountedObject<CPDF_StreamAcc*>; |
| 622 return NULL; | 605 if (!ftData) { |
| 623 } | 606 return NULL; |
| 624 CPDF_StreamAcc* pFontFile = FX_NEW CPDF_StreamAcc; | 607 } |
| 625 if (!pFontFile) { | 608 CPDF_StreamAcc* pFontFile = FX_NEW CPDF_StreamAcc; |
| 626 delete ftData; | 609 if (!pFontFile) { |
| 627 return NULL; | 610 delete ftData; |
| 628 } | 611 return NULL; |
| 629 CPDF_Dictionary* pFontDict = pFontStream->GetDict(); | 612 } |
| 630 FX_INT32 org_size = pFontDict->GetInteger(FX_BSTRC("Length1")) + pFontDict->
GetInteger(FX_BSTRC("Length2")) + pFontDict->GetInteger(FX_BSTRC("Length3")); | 613 CPDF_Dictionary* pFontDict = pFontStream->GetDict(); |
| 631 if (org_size < 0) { | 614 FX_INT32 org_size = pFontDict->GetInteger(FX_BSTRC("Length1")) + |
| 632 org_size = 0; | 615 pFontDict->GetInteger(FX_BSTRC("Length2")) + |
| 633 } | 616 pFontDict->GetInteger(FX_BSTRC("Length3")); |
| 634 pFontFile->LoadAllData(pFontStream, FALSE, org_size); | 617 if (org_size < 0) { |
| 635 ftData->m_nCount = 2; | 618 org_size = 0; |
| 636 ftData->m_Obj = pFontFile; | 619 } |
| 637 m_FontFileMap.SetAt(pFontStream, ftData); | 620 pFontFile->LoadAllData(pFontStream, FALSE, org_size); |
| 638 return pFontFile; | 621 ftData->m_nCount = 2; |
| 639 } | 622 ftData->m_Obj = pFontFile; |
| 640 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO
L bForce) | 623 m_FontFileMap.SetAt(pFontStream, ftData); |
| 641 { | 624 return pFontFile; |
| 642 if (!pFontStream) { | 625 } |
| 643 return; | 626 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, |
| 644 } | 627 FX_BOOL bForce) { |
| 645 PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>(m_FontFileMap, pFontS
tream, NULL, bForce); | 628 if (!pFontStream) { |
| 646 } | 629 return; |
| 630 } |
| 631 PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>( |
| 632 m_FontFileMap, pFontStream, NULL, bForce); |
| 633 } |
| OLD | NEW |