| 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 "fpdfsdk/formfiller/cba_fontmap.h" | 7 #include "fpdfsdk/formfiller/cba_fontmap.h" |
| 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_page/include/cpdf_page.h" | 10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 return; | 152 return; |
| 153 | 153 |
| 154 CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictBy("AP"); | 154 CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictBy("AP"); |
| 155 | 155 |
| 156 if (!pAPDict) { | 156 if (!pAPDict) { |
| 157 pAPDict = new CPDF_Dictionary; | 157 pAPDict = new CPDF_Dictionary; |
| 158 m_pAnnotDict->SetAt("AP", pAPDict); | 158 m_pAnnotDict->SetAt("AP", pAPDict); |
| 159 } | 159 } |
| 160 | 160 |
| 161 // to avoid checkbox and radiobutton | 161 // to avoid checkbox and radiobutton |
| 162 CPDF_Object* pObject = pAPDict->GetObjectBy(m_sAPType.AsStringC()); | 162 CPDF_Object* pObject = pAPDict->GetObjectBy(m_sAPType); |
| 163 if (ToDictionary(pObject)) | 163 if (ToDictionary(pObject)) |
| 164 return; | 164 return; |
| 165 | 165 |
| 166 CPDF_Stream* pStream = pAPDict->GetStreamBy(m_sAPType.AsStringC()); | 166 CPDF_Stream* pStream = pAPDict->GetStreamBy(m_sAPType); |
| 167 if (!pStream) { | 167 if (!pStream) { |
| 168 pStream = new CPDF_Stream(NULL, 0, NULL); | 168 pStream = new CPDF_Stream(NULL, 0, NULL); |
| 169 int32_t objnum = m_pDocument->AddIndirectObject(pStream); | 169 int32_t objnum = m_pDocument->AddIndirectObject(pStream); |
| 170 pAPDict->SetAtReference(m_sAPType.AsStringC(), m_pDocument, objnum); | 170 pAPDict->SetAtReference(m_sAPType.AsStringC(), m_pDocument, objnum); |
| 171 } | 171 } |
| 172 | 172 |
| 173 CPDF_Dictionary* pStreamDict = pStream->GetDict(); | 173 CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
| 174 | 174 |
| 175 if (!pStreamDict) { | 175 if (!pStreamDict) { |
| 176 pStreamDict = new CPDF_Dictionary; | 176 pStreamDict = new CPDF_Dictionary; |
| 177 pStream->InitStream(NULL, 0, pStreamDict); | 177 pStream->InitStream(NULL, 0, pStreamDict); |
| 178 } | 178 } |
| 179 | 179 |
| 180 if (pStreamDict) { | 180 if (pStreamDict) { |
| 181 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); | 181 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); |
| 182 if (!pStreamResList) { | 182 if (!pStreamResList) { |
| 183 pStreamResList = new CPDF_Dictionary(); | 183 pStreamResList = new CPDF_Dictionary(); |
| 184 pStreamDict->SetAt("Resources", pStreamResList); | 184 pStreamDict->SetAt("Resources", pStreamResList); |
| 185 } | 185 } |
| 186 | 186 |
| 187 if (pStreamResList) { | 187 if (pStreamResList) { |
| 188 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font"); | 188 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font"); |
| 189 if (!pStreamResFontList) { | 189 if (!pStreamResFontList) { |
| 190 pStreamResFontList = new CPDF_Dictionary; | 190 pStreamResFontList = new CPDF_Dictionary; |
| 191 int32_t objnum = m_pDocument->AddIndirectObject(pStreamResFontList); | 191 int32_t objnum = m_pDocument->AddIndirectObject(pStreamResFontList); |
| 192 pStreamResList->SetAtReference("Font", m_pDocument, objnum); | 192 pStreamResList->SetAtReference("Font", m_pDocument, objnum); |
| 193 } | 193 } |
| 194 if (!pStreamResFontList->KeyExist(sAlias.AsStringC())) | 194 if (!pStreamResFontList->KeyExist(sAlias)) |
| 195 pStreamResFontList->SetAtReference(sAlias.AsStringC(), m_pDocument, | 195 pStreamResFontList->SetAtReference(sAlias, m_pDocument, |
| 196 pFont->GetFontDict()); | 196 pFont->GetFontDict()); |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { | 201 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { |
| 202 CPDF_Dictionary* pAcroFormDict = NULL; | 202 CPDF_Dictionary* pAcroFormDict = NULL; |
| 203 const bool bWidget = (m_pAnnotDict->GetStringBy("Subtype") == "Widget"); | 203 const bool bWidget = (m_pAnnotDict->GetStringBy("Subtype") == "Widget"); |
| 204 if (bWidget) { | 204 if (bWidget) { |
| 205 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) | 205 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 221 CPDF_Dictionary* pFontDict = NULL; | 221 CPDF_Dictionary* pFontDict = NULL; |
| 222 | 222 |
| 223 if (!sDA.IsEmpty()) { | 223 if (!sDA.IsEmpty()) { |
| 224 CPDF_SimpleParser syntax(sDA.AsStringC()); | 224 CPDF_SimpleParser syntax(sDA.AsStringC()); |
| 225 syntax.FindTagParamFromStart("Tf", 2); | 225 syntax.FindTagParamFromStart("Tf", 2); |
| 226 CFX_ByteString sFontName = syntax.GetWord(); | 226 CFX_ByteString sFontName = syntax.GetWord(); |
| 227 sAlias = PDF_NameDecode(sFontName).Mid(1); | 227 sAlias = PDF_NameDecode(sFontName).Mid(1); |
| 228 | 228 |
| 229 if (CPDF_Dictionary* pDRDict = m_pAnnotDict->GetDictBy("DR")) | 229 if (CPDF_Dictionary* pDRDict = m_pAnnotDict->GetDictBy("DR")) |
| 230 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictBy("Font")) | 230 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictBy("Font")) |
| 231 pFontDict = pDRFontDict->GetDictBy(sAlias.AsStringC()); | 231 pFontDict = pDRFontDict->GetDictBy(sAlias); |
| 232 | 232 |
| 233 if (!pFontDict) | 233 if (!pFontDict) |
| 234 if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictBy("AP")) | 234 if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictBy("AP")) |
| 235 if (CPDF_Dictionary* pNormalDict = pAPDict->GetDictBy("N")) | 235 if (CPDF_Dictionary* pNormalDict = pAPDict->GetDictBy("N")) |
| 236 if (CPDF_Dictionary* pNormalResDict = | 236 if (CPDF_Dictionary* pNormalResDict = |
| 237 pNormalDict->GetDictBy("Resources")) | 237 pNormalDict->GetDictBy("Resources")) |
| 238 if (CPDF_Dictionary* pResFontDict = | 238 if (CPDF_Dictionary* pResFontDict = |
| 239 pNormalResDict->GetDictBy("Font")) | 239 pNormalResDict->GetDictBy("Font")) |
| 240 pFontDict = pResFontDict->GetDictBy(sAlias.AsStringC()); | 240 pFontDict = pResFontDict->GetDictBy(sAlias); |
| 241 | 241 |
| 242 if (bWidget) { | 242 if (bWidget) { |
| 243 if (!pFontDict) { | 243 if (!pFontDict) { |
| 244 if (pAcroFormDict) { | 244 if (pAcroFormDict) { |
| 245 if (CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR")) | 245 if (CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR")) |
| 246 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictBy("Font")) | 246 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictBy("Font")) |
| 247 pFontDict = pDRFontDict->GetDictBy(sAlias.AsStringC()); | 247 pFontDict = pDRFontDict->GetDictBy(sAlias); |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 | 252 |
| 253 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; | 253 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; |
| 254 } | 254 } |
| 255 | 255 |
| 256 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { | 256 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { |
| 257 m_sAPType = sAPType; | 257 m_sAPType = sAPType; |
| 258 | 258 |
| 259 Reset(); | 259 Reset(); |
| 260 Initialize(); | 260 Initialize(); |
| 261 } | 261 } |
| OLD | NEW |