| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
| 10 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" | 10 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 uint16_t m_codePage; | 29 uint16_t m_codePage; |
| 30 } g_fieldEncoding[] = { | 30 } g_fieldEncoding[] = { |
| 31 {"BigFive", 950}, | 31 {"BigFive", 950}, |
| 32 {"GBK", 936}, | 32 {"GBK", 936}, |
| 33 {"Shift-JIS", 932}, | 33 {"Shift-JIS", 932}, |
| 34 {"UHC", 949}, | 34 {"UHC", 949}, |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 CFX_WideString GetFieldValue(const CPDF_Dictionary& pFieldDict, | 37 CFX_WideString GetFieldValue(const CPDF_Dictionary& pFieldDict, |
| 38 const CFX_ByteString& bsEncoding) { | 38 const CFX_ByteString& bsEncoding) { |
| 39 const CFX_ByteString csBValue = pFieldDict.GetStringBy("V"); | 39 const CFX_ByteString csBValue = pFieldDict.GetStringFor("V"); |
| 40 for (const auto& encoding : g_fieldEncoding) { | 40 for (const auto& encoding : g_fieldEncoding) { |
| 41 if (bsEncoding == encoding.m_name) | 41 if (bsEncoding == encoding.m_name) |
| 42 return CFX_WideString::FromCodePage(csBValue.AsStringC(), | 42 return CFX_WideString::FromCodePage(csBValue.AsStringC(), |
| 43 encoding.m_codePage); | 43 encoding.m_codePage); |
| 44 } | 44 } |
| 45 CFX_ByteString csTemp = csBValue.Left(2); | 45 CFX_ByteString csTemp = csBValue.Left(2); |
| 46 if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF") | 46 if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF") |
| 47 return PDF_DecodeText(csBValue); | 47 return PDF_DecodeText(csBValue); |
| 48 return CFX_WideString::FromLocal(csBValue.AsStringC()); | 48 return CFX_WideString::FromLocal(csBValue.AsStringC()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void AddFont(CPDF_Dictionary*& pFormDict, | 51 void AddFont(CPDF_Dictionary*& pFormDict, |
| 52 CPDF_Document* pDocument, | 52 CPDF_Document* pDocument, |
| 53 const CPDF_Font* pFont, | 53 const CPDF_Font* pFont, |
| 54 CFX_ByteString& csNameTag); | 54 CFX_ByteString& csNameTag); |
| 55 | 55 |
| 56 void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { | 56 void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { |
| 57 if (!pDocument) | 57 if (!pDocument) |
| 58 return; | 58 return; |
| 59 | 59 |
| 60 if (!pFormDict) { | 60 if (!pFormDict) { |
| 61 pFormDict = new CPDF_Dictionary; | 61 pFormDict = new CPDF_Dictionary; |
| 62 uint32_t dwObjNum = pDocument->AddIndirectObject(pFormDict); | 62 uint32_t dwObjNum = pDocument->AddIndirectObject(pFormDict); |
| 63 CPDF_Dictionary* pRoot = pDocument->GetRoot(); | 63 CPDF_Dictionary* pRoot = pDocument->GetRoot(); |
| 64 pRoot->SetAtReference("AcroForm", pDocument, dwObjNum); | 64 pRoot->SetReferenceFor("AcroForm", pDocument, dwObjNum); |
| 65 } | 65 } |
| 66 | 66 |
| 67 CFX_ByteString csDA; | 67 CFX_ByteString csDA; |
| 68 if (!pFormDict->KeyExist("DR")) { | 68 if (!pFormDict->KeyExist("DR")) { |
| 69 CFX_ByteString csBaseName; | 69 CFX_ByteString csBaseName; |
| 70 CFX_ByteString csDefault; | 70 CFX_ByteString csDefault; |
| 71 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); | 71 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); |
| 72 CPDF_Font* pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); | 72 CPDF_Font* pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); |
| 73 if (pFont) { | 73 if (pFont) { |
| 74 AddFont(pFormDict, pDocument, pFont, csBaseName); | 74 AddFont(pFormDict, pDocument, pFont, csBaseName); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 if (pFont) | 89 if (pFont) |
| 90 csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf"; | 90 csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf"; |
| 91 } | 91 } |
| 92 if (!csDA.IsEmpty()) | 92 if (!csDA.IsEmpty()) |
| 93 csDA += " "; | 93 csDA += " "; |
| 94 | 94 |
| 95 csDA += "0 g"; | 95 csDA += "0 g"; |
| 96 if (!pFormDict->KeyExist("DA")) | 96 if (!pFormDict->KeyExist("DA")) |
| 97 pFormDict->SetAtString("DA", csDA); | 97 pFormDict->SetStringFor("DA", csDA); |
| 98 } | 98 } |
| 99 | 99 |
| 100 uint32_t CountFonts(CPDF_Dictionary* pFormDict) { | 100 uint32_t CountFonts(CPDF_Dictionary* pFormDict) { |
| 101 if (!pFormDict) | 101 if (!pFormDict) |
| 102 return 0; | 102 return 0; |
| 103 | 103 |
| 104 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); | 104 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
| 105 if (!pDR) | 105 if (!pDR) |
| 106 return 0; | 106 return 0; |
| 107 | 107 |
| 108 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); | 108 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
| 109 if (!pFonts) | 109 if (!pFonts) |
| 110 return 0; | 110 return 0; |
| 111 | 111 |
| 112 uint32_t dwCount = 0; | 112 uint32_t dwCount = 0; |
| 113 for (const auto& it : *pFonts) { | 113 for (const auto& it : *pFonts) { |
| 114 CPDF_Object* pObj = it.second; | 114 CPDF_Object* pObj = it.second; |
| 115 if (!pObj) | 115 if (!pObj) |
| 116 continue; | 116 continue; |
| 117 | 117 |
| 118 if (CPDF_Dictionary* pDirect = ToDictionary(pObj->GetDirect())) { | 118 if (CPDF_Dictionary* pDirect = ToDictionary(pObj->GetDirect())) { |
| 119 if (pDirect->GetStringBy("Type") == "Font") | 119 if (pDirect->GetStringFor("Type") == "Font") |
| 120 dwCount++; | 120 dwCount++; |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 return dwCount; | 123 return dwCount; |
| 124 } | 124 } |
| 125 | 125 |
| 126 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, | 126 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, |
| 127 CPDF_Document* pDocument, | 127 CPDF_Document* pDocument, |
| 128 uint32_t index, | 128 uint32_t index, |
| 129 CFX_ByteString& csNameTag) { | 129 CFX_ByteString& csNameTag) { |
| 130 if (!pFormDict) | 130 if (!pFormDict) |
| 131 return nullptr; | 131 return nullptr; |
| 132 | 132 |
| 133 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); | 133 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
| 134 if (!pDR) | 134 if (!pDR) |
| 135 return nullptr; | 135 return nullptr; |
| 136 | 136 |
| 137 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); | 137 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
| 138 if (!pFonts) | 138 if (!pFonts) |
| 139 return nullptr; | 139 return nullptr; |
| 140 | 140 |
| 141 uint32_t dwCount = 0; | 141 uint32_t dwCount = 0; |
| 142 for (const auto& it : *pFonts) { | 142 for (const auto& it : *pFonts) { |
| 143 const CFX_ByteString& csKey = it.first; | 143 const CFX_ByteString& csKey = it.first; |
| 144 CPDF_Object* pObj = it.second; | 144 CPDF_Object* pObj = it.second; |
| 145 if (!pObj) | 145 if (!pObj) |
| 146 continue; | 146 continue; |
| 147 | 147 |
| 148 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 148 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
| 149 if (!pElement) | 149 if (!pElement) |
| 150 continue; | 150 continue; |
| 151 if (pElement->GetStringBy("Type") != "Font") | 151 if (pElement->GetStringFor("Type") != "Font") |
| 152 continue; | 152 continue; |
| 153 if (dwCount == index) { | 153 if (dwCount == index) { |
| 154 csNameTag = csKey; | 154 csNameTag = csKey; |
| 155 return pDocument->LoadFont(pElement); | 155 return pDocument->LoadFont(pElement); |
| 156 } | 156 } |
| 157 dwCount++; | 157 dwCount++; |
| 158 } | 158 } |
| 159 return nullptr; | 159 return nullptr; |
| 160 } | 160 } |
| 161 | 161 |
| 162 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, | 162 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, |
| 163 CPDF_Document* pDocument, | 163 CPDF_Document* pDocument, |
| 164 CFX_ByteString csNameTag) { | 164 CFX_ByteString csNameTag) { |
| 165 CFX_ByteString csAlias = PDF_NameDecode(csNameTag); | 165 CFX_ByteString csAlias = PDF_NameDecode(csNameTag); |
| 166 if (!pFormDict || csAlias.IsEmpty()) | 166 if (!pFormDict || csAlias.IsEmpty()) |
| 167 return nullptr; | 167 return nullptr; |
| 168 | 168 |
| 169 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); | 169 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
| 170 if (!pDR) | 170 if (!pDR) |
| 171 return nullptr; | 171 return nullptr; |
| 172 | 172 |
| 173 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); | 173 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
| 174 if (!pFonts) | 174 if (!pFonts) |
| 175 return nullptr; | 175 return nullptr; |
| 176 | 176 |
| 177 CPDF_Dictionary* pElement = pFonts->GetDictBy(csAlias); | 177 CPDF_Dictionary* pElement = pFonts->GetDictFor(csAlias); |
| 178 if (!pElement) | 178 if (!pElement) |
| 179 return nullptr; | 179 return nullptr; |
| 180 | 180 |
| 181 if (pElement->GetStringBy("Type") == "Font") | 181 if (pElement->GetStringFor("Type") == "Font") |
| 182 return pDocument->LoadFont(pElement); | 182 return pDocument->LoadFont(pElement); |
| 183 return nullptr; | 183 return nullptr; |
| 184 } | 184 } |
| 185 | 185 |
| 186 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, | 186 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, |
| 187 CPDF_Document* pDocument, | 187 CPDF_Document* pDocument, |
| 188 CFX_ByteString csFontName, | 188 CFX_ByteString csFontName, |
| 189 CFX_ByteString& csNameTag) { | 189 CFX_ByteString& csNameTag) { |
| 190 if (!pFormDict || csFontName.IsEmpty()) | 190 if (!pFormDict || csFontName.IsEmpty()) |
| 191 return nullptr; | 191 return nullptr; |
| 192 | 192 |
| 193 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); | 193 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
| 194 if (!pDR) | 194 if (!pDR) |
| 195 return nullptr; | 195 return nullptr; |
| 196 | 196 |
| 197 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); | 197 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
| 198 if (!pFonts) | 198 if (!pFonts) |
| 199 return nullptr; | 199 return nullptr; |
| 200 | 200 |
| 201 for (const auto& it : *pFonts) { | 201 for (const auto& it : *pFonts) { |
| 202 const CFX_ByteString& csKey = it.first; | 202 const CFX_ByteString& csKey = it.first; |
| 203 CPDF_Object* pObj = it.second; | 203 CPDF_Object* pObj = it.second; |
| 204 if (!pObj) | 204 if (!pObj) |
| 205 continue; | 205 continue; |
| 206 | 206 |
| 207 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 207 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
| 208 if (!pElement) | 208 if (!pElement) |
| 209 continue; | 209 continue; |
| 210 if (pElement->GetStringBy("Type") != "Font") | 210 if (pElement->GetStringFor("Type") != "Font") |
| 211 continue; | 211 continue; |
| 212 | 212 |
| 213 CPDF_Font* pFind = pDocument->LoadFont(pElement); | 213 CPDF_Font* pFind = pDocument->LoadFont(pElement); |
| 214 if (!pFind) | 214 if (!pFind) |
| 215 continue; | 215 continue; |
| 216 | 216 |
| 217 CFX_ByteString csBaseFont; | 217 CFX_ByteString csBaseFont; |
| 218 csBaseFont = pFind->GetBaseFont(); | 218 csBaseFont = pFind->GetBaseFont(); |
| 219 csBaseFont.Remove(' '); | 219 csBaseFont.Remove(' '); |
| 220 if (csBaseFont == csFontName) { | 220 if (csBaseFont == csFontName) { |
| 221 csNameTag = csKey; | 221 csNameTag = csKey; |
| 222 return pFind; | 222 return pFind; |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 return nullptr; | 225 return nullptr; |
| 226 } | 226 } |
| 227 | 227 |
| 228 CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict, | 228 CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict, |
| 229 CPDF_Document* pDocument, | 229 CPDF_Document* pDocument, |
| 230 uint8_t charSet, | 230 uint8_t charSet, |
| 231 CFX_ByteString& csNameTag) { | 231 CFX_ByteString& csNameTag) { |
| 232 if (!pFormDict) | 232 if (!pFormDict) |
| 233 return nullptr; | 233 return nullptr; |
| 234 | 234 |
| 235 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); | 235 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
| 236 if (!pDR) | 236 if (!pDR) |
| 237 return nullptr; | 237 return nullptr; |
| 238 | 238 |
| 239 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); | 239 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
| 240 if (!pFonts) | 240 if (!pFonts) |
| 241 return nullptr; | 241 return nullptr; |
| 242 | 242 |
| 243 for (const auto& it : *pFonts) { | 243 for (const auto& it : *pFonts) { |
| 244 const CFX_ByteString& csKey = it.first; | 244 const CFX_ByteString& csKey = it.first; |
| 245 CPDF_Object* pObj = it.second; | 245 CPDF_Object* pObj = it.second; |
| 246 if (!pObj) | 246 if (!pObj) |
| 247 continue; | 247 continue; |
| 248 | 248 |
| 249 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 249 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
| 250 if (!pElement) | 250 if (!pElement) |
| 251 continue; | 251 continue; |
| 252 if (pElement->GetStringBy("Type") != "Font") | 252 if (pElement->GetStringFor("Type") != "Font") |
| 253 continue; | 253 continue; |
| 254 CPDF_Font* pFind = pDocument->LoadFont(pElement); | 254 CPDF_Font* pFind = pDocument->LoadFont(pElement); |
| 255 if (!pFind) | 255 if (!pFind) |
| 256 continue; | 256 continue; |
| 257 | 257 |
| 258 CFX_SubstFont* pSubst = pFind->GetSubstFont(); | 258 CFX_SubstFont* pSubst = pFind->GetSubstFont(); |
| 259 if (!pSubst) | 259 if (!pSubst) |
| 260 continue; | 260 continue; |
| 261 | 261 |
| 262 if (pSubst->m_Charset == (int)charSet) { | 262 if (pSubst->m_Charset == (int)charSet) { |
| 263 csNameTag = csKey; | 263 csNameTag = csKey; |
| 264 return pFind; | 264 return pFind; |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 return nullptr; | 267 return nullptr; |
| 268 } | 268 } |
| 269 | 269 |
| 270 CPDF_Font* GetDefaultFont(CPDF_Dictionary* pFormDict, | 270 CPDF_Font* GetDefaultFont(CPDF_Dictionary* pFormDict, |
| 271 CPDF_Document* pDocument) { | 271 CPDF_Document* pDocument) { |
| 272 if (!pFormDict) | 272 if (!pFormDict) |
| 273 return nullptr; | 273 return nullptr; |
| 274 | 274 |
| 275 CPDF_DefaultAppearance cDA(pFormDict->GetStringBy("DA")); | 275 CPDF_DefaultAppearance cDA(pFormDict->GetStringFor("DA")); |
| 276 CFX_ByteString csFontNameTag; | 276 CFX_ByteString csFontNameTag; |
| 277 FX_FLOAT fFontSize; | 277 FX_FLOAT fFontSize; |
| 278 cDA.GetFont(csFontNameTag, fFontSize); | 278 cDA.GetFont(csFontNameTag, fFontSize); |
| 279 return GetFont(pFormDict, pDocument, csFontNameTag); | 279 return GetFont(pFormDict, pDocument, csFontNameTag); |
| 280 } | 280 } |
| 281 | 281 |
| 282 FX_BOOL FindFont(CPDF_Dictionary* pFormDict, | 282 FX_BOOL FindFont(CPDF_Dictionary* pFormDict, |
| 283 const CPDF_Font* pFont, | 283 const CPDF_Font* pFont, |
| 284 CFX_ByteString& csNameTag) { | 284 CFX_ByteString& csNameTag) { |
| 285 if (!pFormDict || !pFont) | 285 if (!pFormDict || !pFont) |
| 286 return FALSE; | 286 return FALSE; |
| 287 | 287 |
| 288 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); | 288 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
| 289 if (!pDR) | 289 if (!pDR) |
| 290 return FALSE; | 290 return FALSE; |
| 291 | 291 |
| 292 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); | 292 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
| 293 if (!pFonts) | 293 if (!pFonts) |
| 294 return FALSE; | 294 return FALSE; |
| 295 | 295 |
| 296 for (const auto& it : *pFonts) { | 296 for (const auto& it : *pFonts) { |
| 297 const CFX_ByteString& csKey = it.first; | 297 const CFX_ByteString& csKey = it.first; |
| 298 CPDF_Object* pObj = it.second; | 298 CPDF_Object* pObj = it.second; |
| 299 if (!pObj) | 299 if (!pObj) |
| 300 continue; | 300 continue; |
| 301 | 301 |
| 302 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 302 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
| 303 if (!pElement) | 303 if (!pElement) |
| 304 continue; | 304 continue; |
| 305 if (pElement->GetStringBy("Type") != "Font") | 305 if (pElement->GetStringFor("Type") != "Font") |
| 306 continue; | 306 continue; |
| 307 if (pFont->GetFontDict() == pElement) { | 307 if (pFont->GetFontDict() == pElement) { |
| 308 csNameTag = csKey; | 308 csNameTag = csKey; |
| 309 return TRUE; | 309 return TRUE; |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 return FALSE; | 312 return FALSE; |
| 313 } | 313 } |
| 314 | 314 |
| 315 CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict, | 315 CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 329 } | 329 } |
| 330 | 330 |
| 331 FX_BOOL FindFont(CPDF_Dictionary* pFormDict, | 331 FX_BOOL FindFont(CPDF_Dictionary* pFormDict, |
| 332 CPDF_Document* pDocument, | 332 CPDF_Document* pDocument, |
| 333 CFX_ByteString csFontName, | 333 CFX_ByteString csFontName, |
| 334 CPDF_Font*& pFont, | 334 CPDF_Font*& pFont, |
| 335 CFX_ByteString& csNameTag) { | 335 CFX_ByteString& csNameTag) { |
| 336 if (!pFormDict) | 336 if (!pFormDict) |
| 337 return FALSE; | 337 return FALSE; |
| 338 | 338 |
| 339 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); | 339 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
| 340 if (!pDR) | 340 if (!pDR) |
| 341 return FALSE; | 341 return FALSE; |
| 342 | 342 |
| 343 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); | 343 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
| 344 if (!pFonts) | 344 if (!pFonts) |
| 345 return FALSE; | 345 return FALSE; |
| 346 if (csFontName.GetLength() > 0) | 346 if (csFontName.GetLength() > 0) |
| 347 csFontName.Remove(' '); | 347 csFontName.Remove(' '); |
| 348 | 348 |
| 349 for (const auto& it : *pFonts) { | 349 for (const auto& it : *pFonts) { |
| 350 const CFX_ByteString& csKey = it.first; | 350 const CFX_ByteString& csKey = it.first; |
| 351 CPDF_Object* pObj = it.second; | 351 CPDF_Object* pObj = it.second; |
| 352 if (!pObj) | 352 if (!pObj) |
| 353 continue; | 353 continue; |
| 354 | 354 |
| 355 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 355 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
| 356 if (!pElement) | 356 if (!pElement) |
| 357 continue; | 357 continue; |
| 358 if (pElement->GetStringBy("Type") != "Font") | 358 if (pElement->GetStringFor("Type") != "Font") |
| 359 continue; | 359 continue; |
| 360 | 360 |
| 361 pFont = pDocument->LoadFont(pElement); | 361 pFont = pDocument->LoadFont(pElement); |
| 362 if (!pFont) | 362 if (!pFont) |
| 363 continue; | 363 continue; |
| 364 | 364 |
| 365 CFX_ByteString csBaseFont; | 365 CFX_ByteString csBaseFont; |
| 366 csBaseFont = pFont->GetBaseFont(); | 366 csBaseFont = pFont->GetBaseFont(); |
| 367 csBaseFont.Remove(' '); | 367 csBaseFont.Remove(' '); |
| 368 if (csBaseFont == csFontName) { | 368 if (csBaseFont == csFontName) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 383 InitDict(pFormDict, pDocument); | 383 InitDict(pFormDict, pDocument); |
| 384 | 384 |
| 385 CFX_ByteString csTag; | 385 CFX_ByteString csTag; |
| 386 if (FindFont(pFormDict, pFont, csTag)) { | 386 if (FindFont(pFormDict, pFont, csTag)) { |
| 387 csNameTag = csTag; | 387 csNameTag = csTag; |
| 388 return; | 388 return; |
| 389 } | 389 } |
| 390 if (!pFormDict) | 390 if (!pFormDict) |
| 391 InitDict(pFormDict, pDocument); | 391 InitDict(pFormDict, pDocument); |
| 392 | 392 |
| 393 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); | 393 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
| 394 if (!pDR) { | 394 if (!pDR) { |
| 395 pDR = new CPDF_Dictionary; | 395 pDR = new CPDF_Dictionary; |
| 396 pFormDict->SetAt("DR", pDR); | 396 pFormDict->SetFor("DR", pDR); |
| 397 } | 397 } |
| 398 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); | 398 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
| 399 if (!pFonts) { | 399 if (!pFonts) { |
| 400 pFonts = new CPDF_Dictionary; | 400 pFonts = new CPDF_Dictionary; |
| 401 pDR->SetAt("Font", pFonts); | 401 pDR->SetFor("Font", pFonts); |
| 402 } | 402 } |
| 403 if (csNameTag.IsEmpty()) | 403 if (csNameTag.IsEmpty()) |
| 404 csNameTag = pFont->GetBaseFont(); | 404 csNameTag = pFont->GetBaseFont(); |
| 405 | 405 |
| 406 csNameTag.Remove(' '); | 406 csNameTag.Remove(' '); |
| 407 csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, | 407 csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, |
| 408 csNameTag.c_str()); | 408 csNameTag.c_str()); |
| 409 pFonts->SetAtReference(csNameTag, pDocument, pFont->GetFontDict()); | 409 pFonts->SetReferenceFor(csNameTag, pDocument, pFont->GetFontDict()); |
| 410 } | 410 } |
| 411 | 411 |
| 412 CPDF_Font* AddNativeFont(CPDF_Dictionary*& pFormDict, | 412 CPDF_Font* AddNativeFont(CPDF_Dictionary*& pFormDict, |
| 413 CPDF_Document* pDocument, | 413 CPDF_Document* pDocument, |
| 414 uint8_t charSet, | 414 uint8_t charSet, |
| 415 CFX_ByteString& csNameTag) { | 415 CFX_ByteString& csNameTag) { |
| 416 if (!pFormDict) | 416 if (!pFormDict) |
| 417 InitDict(pFormDict, pDocument); | 417 InitDict(pFormDict, pDocument); |
| 418 | 418 |
| 419 CFX_ByteString csTemp; | 419 CFX_ByteString csTemp; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 435 } | 435 } |
| 436 | 436 |
| 437 void RemoveFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont) { | 437 void RemoveFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont) { |
| 438 if (!pFormDict || !pFont) | 438 if (!pFormDict || !pFont) |
| 439 return; | 439 return; |
| 440 | 440 |
| 441 CFX_ByteString csTag; | 441 CFX_ByteString csTag; |
| 442 if (!FindFont(pFormDict, pFont, csTag)) | 442 if (!FindFont(pFormDict, pFont, csTag)) |
| 443 return; | 443 return; |
| 444 | 444 |
| 445 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); | 445 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
| 446 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); | 446 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
| 447 pFonts->RemoveAt(csTag); | 447 pFonts->RemoveFor(csTag); |
| 448 } | 448 } |
| 449 | 449 |
| 450 void RemoveFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) { | 450 void RemoveFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) { |
| 451 if (!pFormDict || csNameTag.IsEmpty()) | 451 if (!pFormDict || csNameTag.IsEmpty()) |
| 452 return; | 452 return; |
| 453 | 453 |
| 454 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); | 454 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
| 455 if (!pDR) | 455 if (!pDR) |
| 456 return; | 456 return; |
| 457 | 457 |
| 458 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); | 458 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
| 459 if (!pFonts) | 459 if (!pFonts) |
| 460 return; | 460 return; |
| 461 | 461 |
| 462 pFonts->RemoveAt(csNameTag); | 462 pFonts->RemoveFor(csNameTag); |
| 463 } | 463 } |
| 464 | 464 |
| 465 class CFieldNameExtractor { | 465 class CFieldNameExtractor { |
| 466 public: | 466 public: |
| 467 explicit CFieldNameExtractor(const CFX_WideString& full_name) | 467 explicit CFieldNameExtractor(const CFX_WideString& full_name) |
| 468 : m_FullName(full_name) { | 468 : m_FullName(full_name) { |
| 469 m_pCur = m_FullName.c_str(); | 469 m_pCur = m_FullName.c_str(); |
| 470 m_pEnd = m_pCur + m_FullName.GetLength(); | 470 m_pEnd = m_pCur + m_FullName.GetLength(); |
| 471 } | 471 } |
| 472 | 472 |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 | 808 |
| 809 CPDF_InterForm::CPDF_InterForm(CPDF_Document* pDocument) | 809 CPDF_InterForm::CPDF_InterForm(CPDF_Document* pDocument) |
| 810 : m_pDocument(pDocument), | 810 : m_pDocument(pDocument), |
| 811 m_pFormDict(nullptr), | 811 m_pFormDict(nullptr), |
| 812 m_pFieldTree(new CFieldTree), | 812 m_pFieldTree(new CFieldTree), |
| 813 m_pFormNotify(nullptr) { | 813 m_pFormNotify(nullptr) { |
| 814 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); | 814 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); |
| 815 if (!pRoot) | 815 if (!pRoot) |
| 816 return; | 816 return; |
| 817 | 817 |
| 818 m_pFormDict = pRoot->GetDictBy("AcroForm"); | 818 m_pFormDict = pRoot->GetDictFor("AcroForm"); |
| 819 if (!m_pFormDict) | 819 if (!m_pFormDict) |
| 820 return; | 820 return; |
| 821 | 821 |
| 822 CPDF_Array* pFields = m_pFormDict->GetArrayBy("Fields"); | 822 CPDF_Array* pFields = m_pFormDict->GetArrayFor("Fields"); |
| 823 if (!pFields) | 823 if (!pFields) |
| 824 return; | 824 return; |
| 825 | 825 |
| 826 for (size_t i = 0; i < pFields->GetCount(); i++) | 826 for (size_t i = 0; i < pFields->GetCount(); i++) |
| 827 LoadField(pFields->GetDictAt(i)); | 827 LoadField(pFields->GetDictAt(i)); |
| 828 } | 828 } |
| 829 | 829 |
| 830 CPDF_InterForm::~CPDF_InterForm() { | 830 CPDF_InterForm::~CPDF_InterForm() { |
| 831 for (auto it : m_ControlMap) | 831 for (auto it : m_ControlMap) |
| 832 delete it.second; | 832 delete it.second; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 while (m < iMinLen) { | 873 while (m < iMinLen) { |
| 874 csTmp += '0' + m % 10; | 874 csTmp += '0' + m % 10; |
| 875 m++; | 875 m++; |
| 876 } | 876 } |
| 877 } else { | 877 } else { |
| 878 m = iCount; | 878 m = iCount; |
| 879 } | 879 } |
| 880 if (!pResDict) | 880 if (!pResDict) |
| 881 return csTmp; | 881 return csTmp; |
| 882 | 882 |
| 883 CPDF_Dictionary* pDict = pResDict->GetDictBy(csType); | 883 CPDF_Dictionary* pDict = pResDict->GetDictFor(csType); |
| 884 if (!pDict) | 884 if (!pDict) |
| 885 return csTmp; | 885 return csTmp; |
| 886 | 886 |
| 887 int num = 0; | 887 int num = 0; |
| 888 CFX_ByteString bsNum; | 888 CFX_ByteString bsNum; |
| 889 while (TRUE) { | 889 while (TRUE) { |
| 890 CFX_ByteString csKey = csTmp + bsNum; | 890 CFX_ByteString csKey = csTmp + bsNum; |
| 891 if (!pDict->KeyExist(csKey)) | 891 if (!pDict->KeyExist(csKey)) |
| 892 return csKey; | 892 return csKey; |
| 893 if (m < iCount) | 893 if (m < iCount) |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 return nullptr; | 1124 return nullptr; |
| 1125 | 1125 |
| 1126 CFX_WideString csWName = FPDF_GetFullName(pFieldDict); | 1126 CFX_WideString csWName = FPDF_GetFullName(pFieldDict); |
| 1127 return m_pFieldTree->GetField(csWName); | 1127 return m_pFieldTree->GetField(csWName); |
| 1128 } | 1128 } |
| 1129 | 1129 |
| 1130 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage, | 1130 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage, |
| 1131 FX_FLOAT pdf_x, | 1131 FX_FLOAT pdf_x, |
| 1132 FX_FLOAT pdf_y, | 1132 FX_FLOAT pdf_y, |
| 1133 int* z_order) const { | 1133 int* z_order) const { |
| 1134 CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArrayBy("Annots"); | 1134 CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArrayFor("Annots"); |
| 1135 if (!pAnnotList) | 1135 if (!pAnnotList) |
| 1136 return nullptr; | 1136 return nullptr; |
| 1137 | 1137 |
| 1138 for (size_t i = pAnnotList->GetCount(); i > 0; --i) { | 1138 for (size_t i = pAnnotList->GetCount(); i > 0; --i) { |
| 1139 size_t annot_index = i - 1; | 1139 size_t annot_index = i - 1; |
| 1140 CPDF_Dictionary* pAnnot = pAnnotList->GetDictAt(annot_index); | 1140 CPDF_Dictionary* pAnnot = pAnnotList->GetDictAt(annot_index); |
| 1141 if (!pAnnot) | 1141 if (!pAnnot) |
| 1142 continue; | 1142 continue; |
| 1143 | 1143 |
| 1144 const auto it = m_ControlMap.find(pAnnot); | 1144 const auto it = m_ControlMap.find(pAnnot); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1157 return nullptr; | 1157 return nullptr; |
| 1158 } | 1158 } |
| 1159 | 1159 |
| 1160 CPDF_FormControl* CPDF_InterForm::GetControlByDict( | 1160 CPDF_FormControl* CPDF_InterForm::GetControlByDict( |
| 1161 const CPDF_Dictionary* pWidgetDict) const { | 1161 const CPDF_Dictionary* pWidgetDict) const { |
| 1162 const auto it = m_ControlMap.find(pWidgetDict); | 1162 const auto it = m_ControlMap.find(pWidgetDict); |
| 1163 return it != m_ControlMap.end() ? it->second : nullptr; | 1163 return it != m_ControlMap.end() ? it->second : nullptr; |
| 1164 } | 1164 } |
| 1165 | 1165 |
| 1166 FX_BOOL CPDF_InterForm::NeedConstructAP() const { | 1166 FX_BOOL CPDF_InterForm::NeedConstructAP() const { |
| 1167 return m_pFormDict && m_pFormDict->GetBooleanBy("NeedAppearances"); | 1167 return m_pFormDict && m_pFormDict->GetBooleanFor("NeedAppearances"); |
| 1168 } | 1168 } |
| 1169 | 1169 |
| 1170 int CPDF_InterForm::CountFieldsInCalculationOrder() { | 1170 int CPDF_InterForm::CountFieldsInCalculationOrder() { |
| 1171 if (!m_pFormDict) | 1171 if (!m_pFormDict) |
| 1172 return 0; | 1172 return 0; |
| 1173 | 1173 |
| 1174 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); | 1174 CPDF_Array* pArray = m_pFormDict->GetArrayFor("CO"); |
| 1175 return pArray ? pArray->GetCount() : 0; | 1175 return pArray ? pArray->GetCount() : 0; |
| 1176 } | 1176 } |
| 1177 | 1177 |
| 1178 CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) { | 1178 CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) { |
| 1179 if (!m_pFormDict || index < 0) | 1179 if (!m_pFormDict || index < 0) |
| 1180 return nullptr; | 1180 return nullptr; |
| 1181 | 1181 |
| 1182 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); | 1182 CPDF_Array* pArray = m_pFormDict->GetArrayFor("CO"); |
| 1183 if (!pArray) | 1183 if (!pArray) |
| 1184 return nullptr; | 1184 return nullptr; |
| 1185 | 1185 |
| 1186 CPDF_Dictionary* pElement = ToDictionary(pArray->GetDirectObjectAt(index)); | 1186 CPDF_Dictionary* pElement = ToDictionary(pArray->GetDirectObjectAt(index)); |
| 1187 return pElement ? GetFieldByDict(pElement) : nullptr; | 1187 return pElement ? GetFieldByDict(pElement) : nullptr; |
| 1188 } | 1188 } |
| 1189 | 1189 |
| 1190 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { | 1190 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { |
| 1191 if (!m_pFormDict || !pField) | 1191 if (!m_pFormDict || !pField) |
| 1192 return -1; | 1192 return -1; |
| 1193 | 1193 |
| 1194 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); | 1194 CPDF_Array* pArray = m_pFormDict->GetArrayFor("CO"); |
| 1195 if (!pArray) | 1195 if (!pArray) |
| 1196 return -1; | 1196 return -1; |
| 1197 | 1197 |
| 1198 for (size_t i = 0; i < pArray->GetCount(); i++) { | 1198 for (size_t i = 0; i < pArray->GetCount(); i++) { |
| 1199 CPDF_Object* pElement = pArray->GetDirectObjectAt(i); | 1199 CPDF_Object* pElement = pArray->GetDirectObjectAt(i); |
| 1200 if (pElement == pField->m_pDict) | 1200 if (pElement == pField->m_pDict) |
| 1201 return i; | 1201 return i; |
| 1202 } | 1202 } |
| 1203 return -1; | 1203 return -1; |
| 1204 } | 1204 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 RemoveFont(m_pFormDict, pFont); | 1259 RemoveFont(m_pFormDict, pFont); |
| 1260 } | 1260 } |
| 1261 | 1261 |
| 1262 void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) { | 1262 void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) { |
| 1263 RemoveFont(m_pFormDict, csNameTag); | 1263 RemoveFont(m_pFormDict, csNameTag); |
| 1264 } | 1264 } |
| 1265 | 1265 |
| 1266 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() { | 1266 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() { |
| 1267 if (!m_pFormDict) | 1267 if (!m_pFormDict) |
| 1268 return CPDF_DefaultAppearance(); | 1268 return CPDF_DefaultAppearance(); |
| 1269 return CPDF_DefaultAppearance(m_pFormDict->GetStringBy("DA")); | 1269 return CPDF_DefaultAppearance(m_pFormDict->GetStringFor("DA")); |
| 1270 } | 1270 } |
| 1271 | 1271 |
| 1272 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() { | 1272 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() { |
| 1273 return GetDefaultFont(m_pFormDict, m_pDocument); | 1273 return GetDefaultFont(m_pFormDict, m_pDocument); |
| 1274 } | 1274 } |
| 1275 | 1275 |
| 1276 int CPDF_InterForm::GetFormAlignment() { | 1276 int CPDF_InterForm::GetFormAlignment() { |
| 1277 return m_pFormDict ? m_pFormDict->GetIntegerBy("Q", 0) : 0; | 1277 return m_pFormDict ? m_pFormDict->GetIntegerFor("Q", 0) : 0; |
| 1278 } | 1278 } |
| 1279 | 1279 |
| 1280 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, | 1280 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, |
| 1281 bool bIncludeOrExclude, | 1281 bool bIncludeOrExclude, |
| 1282 bool bNotify) { | 1282 bool bNotify) { |
| 1283 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) | 1283 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) |
| 1284 return false; | 1284 return false; |
| 1285 | 1285 |
| 1286 int nCount = m_pFieldTree->m_Root.CountFields(); | 1286 int nCount = m_pFieldTree->m_Root.CountFields(); |
| 1287 for (int i = 0; i < nCount; ++i) { | 1287 for (int i = 0; i < nCount; ++i) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1314 return true; | 1314 return true; |
| 1315 } | 1315 } |
| 1316 | 1316 |
| 1317 void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) { | 1317 void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) { |
| 1318 if (nLevel > nMaxRecursion) | 1318 if (nLevel > nMaxRecursion) |
| 1319 return; | 1319 return; |
| 1320 if (!pFieldDict) | 1320 if (!pFieldDict) |
| 1321 return; | 1321 return; |
| 1322 | 1322 |
| 1323 uint32_t dwParentObjNum = pFieldDict->GetObjNum(); | 1323 uint32_t dwParentObjNum = pFieldDict->GetObjNum(); |
| 1324 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); | 1324 CPDF_Array* pKids = pFieldDict->GetArrayFor("Kids"); |
| 1325 if (!pKids) { | 1325 if (!pKids) { |
| 1326 AddTerminalField(pFieldDict); | 1326 AddTerminalField(pFieldDict); |
| 1327 return; | 1327 return; |
| 1328 } | 1328 } |
| 1329 | 1329 |
| 1330 CPDF_Dictionary* pFirstKid = pKids->GetDictAt(0); | 1330 CPDF_Dictionary* pFirstKid = pKids->GetDictAt(0); |
| 1331 if (!pFirstKid) | 1331 if (!pFirstKid) |
| 1332 return; | 1332 return; |
| 1333 | 1333 |
| 1334 if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) { | 1334 if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) { |
| 1335 for (size_t i = 0; i < pKids->GetCount(); i++) { | 1335 for (size_t i = 0; i < pKids->GetCount(); i++) { |
| 1336 CPDF_Dictionary* pChildDict = pKids->GetDictAt(i); | 1336 CPDF_Dictionary* pChildDict = pKids->GetDictAt(i); |
| 1337 if (pChildDict) { | 1337 if (pChildDict) { |
| 1338 if (pChildDict->GetObjNum() != dwParentObjNum) | 1338 if (pChildDict->GetObjNum() != dwParentObjNum) |
| 1339 LoadField(pChildDict, nLevel + 1); | 1339 LoadField(pChildDict, nLevel + 1); |
| 1340 } | 1340 } |
| 1341 } | 1341 } |
| 1342 } else { | 1342 } else { |
| 1343 AddTerminalField(pFieldDict); | 1343 AddTerminalField(pFieldDict); |
| 1344 } | 1344 } |
| 1345 } | 1345 } |
| 1346 | 1346 |
| 1347 FX_BOOL CPDF_InterForm::HasXFAForm() const { | 1347 FX_BOOL CPDF_InterForm::HasXFAForm() const { |
| 1348 return m_pFormDict && m_pFormDict->GetArrayBy("XFA"); | 1348 return m_pFormDict && m_pFormDict->GetArrayFor("XFA"); |
| 1349 } | 1349 } |
| 1350 | 1350 |
| 1351 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { | 1351 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { |
| 1352 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; | 1352 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; |
| 1353 if (!pPageDict) | 1353 if (!pPageDict) |
| 1354 return; | 1354 return; |
| 1355 | 1355 |
| 1356 CPDF_Array* pAnnots = pPageDict->GetArrayBy("Annots"); | 1356 CPDF_Array* pAnnots = pPageDict->GetArrayFor("Annots"); |
| 1357 if (!pAnnots) | 1357 if (!pAnnots) |
| 1358 return; | 1358 return; |
| 1359 | 1359 |
| 1360 for (size_t i = 0; i < pAnnots->GetCount(); i++) { | 1360 for (size_t i = 0; i < pAnnots->GetCount(); i++) { |
| 1361 CPDF_Dictionary* pAnnot = pAnnots->GetDictAt(i); | 1361 CPDF_Dictionary* pAnnot = pAnnots->GetDictAt(i); |
| 1362 if (pAnnot && pAnnot->GetStringBy("Subtype") == "Widget") | 1362 if (pAnnot && pAnnot->GetStringFor("Subtype") == "Widget") |
| 1363 LoadField(pAnnot); | 1363 LoadField(pAnnot); |
| 1364 } | 1364 } |
| 1365 } | 1365 } |
| 1366 | 1366 |
| 1367 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { | 1367 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { |
| 1368 if (!pFieldDict->KeyExist("T")) | 1368 if (!pFieldDict->KeyExist("T")) |
| 1369 return nullptr; | 1369 return nullptr; |
| 1370 | 1370 |
| 1371 CPDF_Dictionary* pDict = pFieldDict; | 1371 CPDF_Dictionary* pDict = pFieldDict; |
| 1372 CFX_WideString csWName = FPDF_GetFullName(pFieldDict); | 1372 CFX_WideString csWName = FPDF_GetFullName(pFieldDict); |
| 1373 if (csWName.IsEmpty()) | 1373 if (csWName.IsEmpty()) |
| 1374 return nullptr; | 1374 return nullptr; |
| 1375 | 1375 |
| 1376 CPDF_FormField* pField = nullptr; | 1376 CPDF_FormField* pField = nullptr; |
| 1377 pField = m_pFieldTree->GetField(csWName); | 1377 pField = m_pFieldTree->GetField(csWName); |
| 1378 if (!pField) { | 1378 if (!pField) { |
| 1379 CPDF_Dictionary* pParent = pFieldDict; | 1379 CPDF_Dictionary* pParent = pFieldDict; |
| 1380 if (!pFieldDict->KeyExist("T") && | 1380 if (!pFieldDict->KeyExist("T") && |
| 1381 pFieldDict->GetStringBy("Subtype") == "Widget") { | 1381 pFieldDict->GetStringFor("Subtype") == "Widget") { |
| 1382 pParent = pFieldDict->GetDictBy("Parent"); | 1382 pParent = pFieldDict->GetDictFor("Parent"); |
| 1383 if (!pParent) | 1383 if (!pParent) |
| 1384 pParent = pFieldDict; | 1384 pParent = pFieldDict; |
| 1385 } | 1385 } |
| 1386 | 1386 |
| 1387 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) { | 1387 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) { |
| 1388 if (pFieldDict->KeyExist("FT")) { | 1388 if (pFieldDict->KeyExist("FT")) { |
| 1389 CPDF_Object* pFTValue = pFieldDict->GetDirectObjectBy("FT"); | 1389 CPDF_Object* pFTValue = pFieldDict->GetDirectObjectFor("FT"); |
| 1390 if (pFTValue) | 1390 if (pFTValue) |
| 1391 pParent->SetAt("FT", pFTValue->Clone()); | 1391 pParent->SetFor("FT", pFTValue->Clone()); |
| 1392 } | 1392 } |
| 1393 | 1393 |
| 1394 if (pFieldDict->KeyExist("Ff")) { | 1394 if (pFieldDict->KeyExist("Ff")) { |
| 1395 CPDF_Object* pFfValue = pFieldDict->GetDirectObjectBy("Ff"); | 1395 CPDF_Object* pFfValue = pFieldDict->GetDirectObjectFor("Ff"); |
| 1396 if (pFfValue) | 1396 if (pFfValue) |
| 1397 pParent->SetAt("Ff", pFfValue->Clone()); | 1397 pParent->SetFor("Ff", pFfValue->Clone()); |
| 1398 } | 1398 } |
| 1399 } | 1399 } |
| 1400 | 1400 |
| 1401 pField = new CPDF_FormField(this, pParent); | 1401 pField = new CPDF_FormField(this, pParent); |
| 1402 CPDF_Object* pTObj = pDict->GetObjectBy("T"); | 1402 CPDF_Object* pTObj = pDict->GetObjectFor("T"); |
| 1403 if (ToReference(pTObj)) { | 1403 if (ToReference(pTObj)) { |
| 1404 CPDF_Object* pClone = pTObj->CloneDirectObject(); | 1404 CPDF_Object* pClone = pTObj->CloneDirectObject(); |
| 1405 if (pClone) | 1405 if (pClone) |
| 1406 pDict->SetAt("T", pClone); | 1406 pDict->SetFor("T", pClone); |
| 1407 else | 1407 else |
| 1408 pDict->SetAtName("T", ""); | 1408 pDict->SetNameFor("T", ""); |
| 1409 } | 1409 } |
| 1410 m_pFieldTree->SetField(csWName, pField); | 1410 m_pFieldTree->SetField(csWName, pField); |
| 1411 } | 1411 } |
| 1412 | 1412 |
| 1413 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); | 1413 CPDF_Array* pKids = pFieldDict->GetArrayFor("Kids"); |
| 1414 if (!pKids) { | 1414 if (!pKids) { |
| 1415 if (pFieldDict->GetStringBy("Subtype") == "Widget") | 1415 if (pFieldDict->GetStringFor("Subtype") == "Widget") |
| 1416 AddControl(pField, pFieldDict); | 1416 AddControl(pField, pFieldDict); |
| 1417 } else { | 1417 } else { |
| 1418 for (size_t i = 0; i < pKids->GetCount(); i++) { | 1418 for (size_t i = 0; i < pKids->GetCount(); i++) { |
| 1419 CPDF_Dictionary* pKid = pKids->GetDictAt(i); | 1419 CPDF_Dictionary* pKid = pKids->GetDictAt(i); |
| 1420 if (!pKid) | 1420 if (!pKid) |
| 1421 continue; | 1421 continue; |
| 1422 if (pKid->GetStringBy("Subtype") != "Widget") | 1422 if (pKid->GetStringFor("Subtype") != "Widget") |
| 1423 continue; | 1423 continue; |
| 1424 | 1424 |
| 1425 AddControl(pField, pKid); | 1425 AddControl(pField, pKid); |
| 1426 } | 1426 } |
| 1427 } | 1427 } |
| 1428 return pField; | 1428 return pField; |
| 1429 } | 1429 } |
| 1430 | 1430 |
| 1431 CPDF_FormControl* CPDF_InterForm::AddControl(CPDF_FormField* pField, | 1431 CPDF_FormControl* CPDF_InterForm::AddControl(CPDF_FormField* pField, |
| 1432 CPDF_Dictionary* pWidgetDict) { | 1432 CPDF_Dictionary* pWidgetDict) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1457 uint32_t dwFlags = pField->GetFieldFlags(); | 1457 uint32_t dwFlags = pField->GetFieldFlags(); |
| 1458 // TODO(thestig): Look up these magic numbers and add constants for them. | 1458 // TODO(thestig): Look up these magic numbers and add constants for them. |
| 1459 if (dwFlags & 0x04) | 1459 if (dwFlags & 0x04) |
| 1460 continue; | 1460 continue; |
| 1461 | 1461 |
| 1462 bool bFind = true; | 1462 bool bFind = true; |
| 1463 if (fields) | 1463 if (fields) |
| 1464 bFind = pdfium::ContainsValue(*fields, pField); | 1464 bFind = pdfium::ContainsValue(*fields, pField); |
| 1465 if (bIncludeOrExclude == bFind) { | 1465 if (bIncludeOrExclude == bFind) { |
| 1466 CPDF_Dictionary* pFieldDict = pField->m_pDict; | 1466 CPDF_Dictionary* pFieldDict = pField->m_pDict; |
| 1467 if ((dwFlags & 0x02) != 0 && pFieldDict->GetStringBy("V").IsEmpty()) | 1467 if ((dwFlags & 0x02) != 0 && pFieldDict->GetStringFor("V").IsEmpty()) |
| 1468 return pField; | 1468 return pField; |
| 1469 } | 1469 } |
| 1470 } | 1470 } |
| 1471 return nullptr; | 1471 return nullptr; |
| 1472 } | 1472 } |
| 1473 | 1473 |
| 1474 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, | 1474 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, |
| 1475 bool bSimpleFileSpec) const { | 1475 bool bSimpleFileSpec) const { |
| 1476 std::vector<CPDF_FormField*> fields; | 1476 std::vector<CPDF_FormField*> fields; |
| 1477 int nCount = m_pFieldTree->m_Root.CountFields(); | 1477 int nCount = m_pFieldTree->m_Root.CountFields(); |
| 1478 for (int i = 0; i < nCount; ++i) | 1478 for (int i = 0; i < nCount; ++i) |
| 1479 fields.push_back(m_pFieldTree->m_Root.GetField(i)); | 1479 fields.push_back(m_pFieldTree->m_Root.GetField(i)); |
| 1480 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); | 1480 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); |
| 1481 } | 1481 } |
| 1482 | 1482 |
| 1483 CFDF_Document* CPDF_InterForm::ExportToFDF( | 1483 CFDF_Document* CPDF_InterForm::ExportToFDF( |
| 1484 const CFX_WideStringC& pdf_path, | 1484 const CFX_WideStringC& pdf_path, |
| 1485 const std::vector<CPDF_FormField*>& fields, | 1485 const std::vector<CPDF_FormField*>& fields, |
| 1486 bool bIncludeOrExclude, | 1486 bool bIncludeOrExclude, |
| 1487 bool bSimpleFileSpec) const { | 1487 bool bSimpleFileSpec) const { |
| 1488 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); | 1488 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); |
| 1489 if (!pDoc) | 1489 if (!pDoc) |
| 1490 return nullptr; | 1490 return nullptr; |
| 1491 | 1491 |
| 1492 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictBy("FDF"); | 1492 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF"); |
| 1493 if (!pdf_path.IsEmpty()) { | 1493 if (!pdf_path.IsEmpty()) { |
| 1494 if (bSimpleFileSpec) { | 1494 if (bSimpleFileSpec) { |
| 1495 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); | 1495 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); |
| 1496 pMainDict->SetAtString("F", CFX_ByteString::FromUnicode(wsFilePath)); | 1496 pMainDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsFilePath)); |
| 1497 pMainDict->SetAtString("UF", PDF_EncodeText(wsFilePath)); | 1497 pMainDict->SetStringFor("UF", PDF_EncodeText(wsFilePath)); |
| 1498 } else { | 1498 } else { |
| 1499 CPDF_FileSpec filespec; | 1499 CPDF_FileSpec filespec; |
| 1500 filespec.SetFileName(pdf_path); | 1500 filespec.SetFileName(pdf_path); |
| 1501 pMainDict->SetAt("F", filespec.GetObj()); | 1501 pMainDict->SetFor("F", filespec.GetObj()); |
| 1502 } | 1502 } |
| 1503 } | 1503 } |
| 1504 | 1504 |
| 1505 CPDF_Array* pFields = new CPDF_Array; | 1505 CPDF_Array* pFields = new CPDF_Array; |
| 1506 pMainDict->SetAt("Fields", pFields); | 1506 pMainDict->SetFor("Fields", pFields); |
| 1507 int nCount = m_pFieldTree->m_Root.CountFields(); | 1507 int nCount = m_pFieldTree->m_Root.CountFields(); |
| 1508 for (int i = 0; i < nCount; i++) { | 1508 for (int i = 0; i < nCount; i++) { |
| 1509 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); | 1509 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); |
| 1510 if (!pField || pField->GetType() == CPDF_FormField::PushButton) | 1510 if (!pField || pField->GetType() == CPDF_FormField::PushButton) |
| 1511 continue; | 1511 continue; |
| 1512 | 1512 |
| 1513 uint32_t dwFlags = pField->GetFieldFlags(); | 1513 uint32_t dwFlags = pField->GetFieldFlags(); |
| 1514 if (dwFlags & 0x04) | 1514 if (dwFlags & 0x04) |
| 1515 continue; | 1515 continue; |
| 1516 | 1516 |
| 1517 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { | 1517 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { |
| 1518 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringBy("V").IsEmpty()) | 1518 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringFor("V").IsEmpty()) |
| 1519 continue; | 1519 continue; |
| 1520 | 1520 |
| 1521 CFX_WideString fullname = FPDF_GetFullName(pField->GetFieldDict()); | 1521 CFX_WideString fullname = FPDF_GetFullName(pField->GetFieldDict()); |
| 1522 CPDF_Dictionary* pFieldDict = new CPDF_Dictionary; | 1522 CPDF_Dictionary* pFieldDict = new CPDF_Dictionary; |
| 1523 pFieldDict->SetAt("T", new CPDF_String(fullname)); | 1523 pFieldDict->SetFor("T", new CPDF_String(fullname)); |
| 1524 if (pField->GetType() == CPDF_FormField::CheckBox || | 1524 if (pField->GetType() == CPDF_FormField::CheckBox || |
| 1525 pField->GetType() == CPDF_FormField::RadioButton) { | 1525 pField->GetType() == CPDF_FormField::RadioButton) { |
| 1526 CFX_WideString csExport = pField->GetCheckValue(FALSE); | 1526 CFX_WideString csExport = pField->GetCheckValue(FALSE); |
| 1527 CFX_ByteString csBExport = PDF_EncodeText(csExport); | 1527 CFX_ByteString csBExport = PDF_EncodeText(csExport); |
| 1528 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt"); | 1528 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt"); |
| 1529 if (pOpt) | 1529 if (pOpt) |
| 1530 pFieldDict->SetAtString("V", csBExport); | 1530 pFieldDict->SetStringFor("V", csBExport); |
| 1531 else | 1531 else |
| 1532 pFieldDict->SetAtName("V", csBExport); | 1532 pFieldDict->SetNameFor("V", csBExport); |
| 1533 } else { | 1533 } else { |
| 1534 CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V"); | 1534 CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V"); |
| 1535 if (pV) | 1535 if (pV) |
| 1536 pFieldDict->SetAt("V", pV->CloneDirectObject()); | 1536 pFieldDict->SetFor("V", pV->CloneDirectObject()); |
| 1537 } | 1537 } |
| 1538 pFields->Add(pFieldDict); | 1538 pFields->Add(pFieldDict); |
| 1539 } | 1539 } |
| 1540 } | 1540 } |
| 1541 return pDoc; | 1541 return pDoc; |
| 1542 } | 1542 } |
| 1543 | 1543 |
| 1544 void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, | 1544 void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, |
| 1545 const CFX_WideString& parent_name, | 1545 const CFX_WideString& parent_name, |
| 1546 FX_BOOL bNotify, | 1546 FX_BOOL bNotify, |
| 1547 int nLevel) { | 1547 int nLevel) { |
| 1548 CFX_WideString name; | 1548 CFX_WideString name; |
| 1549 if (!parent_name.IsEmpty()) | 1549 if (!parent_name.IsEmpty()) |
| 1550 name = parent_name + L"."; | 1550 name = parent_name + L"."; |
| 1551 | 1551 |
| 1552 name += pFieldDict->GetUnicodeTextBy("T"); | 1552 name += pFieldDict->GetUnicodeTextFor("T"); |
| 1553 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); | 1553 CPDF_Array* pKids = pFieldDict->GetArrayFor("Kids"); |
| 1554 if (pKids) { | 1554 if (pKids) { |
| 1555 for (size_t i = 0; i < pKids->GetCount(); i++) { | 1555 for (size_t i = 0; i < pKids->GetCount(); i++) { |
| 1556 CPDF_Dictionary* pKid = pKids->GetDictAt(i); | 1556 CPDF_Dictionary* pKid = pKids->GetDictAt(i); |
| 1557 if (!pKid) | 1557 if (!pKid) |
| 1558 continue; | 1558 continue; |
| 1559 if (nLevel <= nMaxRecursion) | 1559 if (nLevel <= nMaxRecursion) |
| 1560 FDF_ImportField(pKid, name, bNotify, nLevel + 1); | 1560 FDF_ImportField(pKid, name, bNotify, nLevel + 1); |
| 1561 } | 1561 } |
| 1562 return; | 1562 return; |
| 1563 } | 1563 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1578 iRet = m_pFormNotify->BeforeValueChange(pField, csWValue); | 1578 iRet = m_pFormNotify->BeforeValueChange(pField, csWValue); |
| 1579 | 1579 |
| 1580 if (iRet < 0) | 1580 if (iRet < 0) |
| 1581 return; | 1581 return; |
| 1582 } | 1582 } |
| 1583 | 1583 |
| 1584 pField->SetValue(csWValue); | 1584 pField->SetValue(csWValue); |
| 1585 CPDF_FormField::Type eType = pField->GetType(); | 1585 CPDF_FormField::Type eType = pField->GetType(); |
| 1586 if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) && | 1586 if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) && |
| 1587 pFieldDict->KeyExist("Opt")) { | 1587 pFieldDict->KeyExist("Opt")) { |
| 1588 pField->m_pDict->SetAt( | 1588 pField->m_pDict->SetFor( |
| 1589 "Opt", pFieldDict->GetDirectObjectBy("Opt")->CloneDirectObject()); | 1589 "Opt", pFieldDict->GetDirectObjectFor("Opt")->CloneDirectObject()); |
| 1590 } | 1590 } |
| 1591 | 1591 |
| 1592 if (bNotify && m_pFormNotify) { | 1592 if (bNotify && m_pFormNotify) { |
| 1593 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) | 1593 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) |
| 1594 m_pFormNotify->AfterCheckedStatusChange(pField); | 1594 m_pFormNotify->AfterCheckedStatusChange(pField); |
| 1595 else if (iType == FIELDTYPE_LISTBOX) | 1595 else if (iType == FIELDTYPE_LISTBOX) |
| 1596 m_pFormNotify->AfterSelectionChange(pField); | 1596 m_pFormNotify->AfterSelectionChange(pField); |
| 1597 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) | 1597 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) |
| 1598 m_pFormNotify->AfterValueChange(pField); | 1598 m_pFormNotify->AfterValueChange(pField); |
| 1599 } | 1599 } |
| 1600 } | 1600 } |
| 1601 | 1601 |
| 1602 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, | 1602 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, |
| 1603 FX_BOOL bNotify) { | 1603 FX_BOOL bNotify) { |
| 1604 if (!pFDF) | 1604 if (!pFDF) |
| 1605 return FALSE; | 1605 return FALSE; |
| 1606 | 1606 |
| 1607 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF"); | 1607 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictFor("FDF"); |
| 1608 if (!pMainDict) | 1608 if (!pMainDict) |
| 1609 return FALSE; | 1609 return FALSE; |
| 1610 | 1610 |
| 1611 CPDF_Array* pFields = pMainDict->GetArrayBy("Fields"); | 1611 CPDF_Array* pFields = pMainDict->GetArrayFor("Fields"); |
| 1612 if (!pFields) | 1612 if (!pFields) |
| 1613 return FALSE; | 1613 return FALSE; |
| 1614 | 1614 |
| 1615 m_bsEncoding = pMainDict->GetStringBy("Encoding"); | 1615 m_bsEncoding = pMainDict->GetStringFor("Encoding"); |
| 1616 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormImportData(this) < 0) | 1616 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormImportData(this) < 0) |
| 1617 return FALSE; | 1617 return FALSE; |
| 1618 | 1618 |
| 1619 for (size_t i = 0; i < pFields->GetCount(); i++) { | 1619 for (size_t i = 0; i < pFields->GetCount(); i++) { |
| 1620 CPDF_Dictionary* pField = pFields->GetDictAt(i); | 1620 CPDF_Dictionary* pField = pFields->GetDictAt(i); |
| 1621 if (!pField) | 1621 if (!pField) |
| 1622 continue; | 1622 continue; |
| 1623 | 1623 |
| 1624 FDF_ImportField(pField, L"", bNotify); | 1624 FDF_ImportField(pField, L"", bNotify); |
| 1625 } | 1625 } |
| 1626 if (bNotify && m_pFormNotify) | 1626 if (bNotify && m_pFormNotify) |
| 1627 m_pFormNotify->AfterFormImportData(this); | 1627 m_pFormNotify->AfterFormImportData(this); |
| 1628 return TRUE; | 1628 return TRUE; |
| 1629 } | 1629 } |
| 1630 | 1630 |
| 1631 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { | 1631 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { |
| 1632 m_pFormNotify = pNotify; | 1632 m_pFormNotify = pNotify; |
| 1633 } | 1633 } |
| OLD | NEW |