| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 m_sDefaultFontName = sFontName; | 75 m_sDefaultFontName = sFontName; |
| 76 | 76 |
| 77 int32_t nCharset = DEFAULT_CHARSET; | 77 int32_t nCharset = DEFAULT_CHARSET; |
| 78 if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont()) | 78 if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont()) |
| 79 nCharset = pSubstFont->m_Charset; | 79 nCharset = pSubstFont->m_Charset; |
| 80 AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset); | 80 AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset); |
| 81 } | 81 } |
| 82 | 82 |
| 83 CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, | 83 CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, |
| 84 int32_t nCharset) { | 84 int32_t nCharset) { |
| 85 if (m_pAnnotDict->GetStringBy("Subtype") != "Widget") | 85 if (m_pAnnotDict->GetStringFor("Subtype") != "Widget") |
| 86 return nullptr; | 86 return nullptr; |
| 87 | 87 |
| 88 CPDF_Document* pDocument = GetDocument(); | 88 CPDF_Document* pDocument = GetDocument(); |
| 89 CPDF_Dictionary* pRootDict = pDocument->GetRoot(); | 89 CPDF_Dictionary* pRootDict = pDocument->GetRoot(); |
| 90 if (!pRootDict) | 90 if (!pRootDict) |
| 91 return nullptr; | 91 return nullptr; |
| 92 | 92 |
| 93 CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictBy("AcroForm"); | 93 CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictFor("AcroForm"); |
| 94 if (!pAcroFormDict) | 94 if (!pAcroFormDict) |
| 95 return nullptr; | 95 return nullptr; |
| 96 | 96 |
| 97 CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR"); | 97 CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictFor("DR"); |
| 98 if (!pDRDict) | 98 if (!pDRDict) |
| 99 return nullptr; | 99 return nullptr; |
| 100 | 100 |
| 101 return FindResFontSameCharset(pDRDict, sFontAlias, nCharset); | 101 return FindResFontSameCharset(pDRDict, sFontAlias, nCharset); |
| 102 } | 102 } |
| 103 | 103 |
| 104 CPDF_Document* CBA_FontMap::GetDocument() { | 104 CPDF_Document* CBA_FontMap::GetDocument() { |
| 105 return m_pDocument; | 105 return m_pDocument; |
| 106 } | 106 } |
| 107 | 107 |
| 108 CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict, | 108 CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict, |
| 109 CFX_ByteString& sFontAlias, | 109 CFX_ByteString& sFontAlias, |
| 110 int32_t nCharset) { | 110 int32_t nCharset) { |
| 111 if (!pResDict) | 111 if (!pResDict) |
| 112 return nullptr; | 112 return nullptr; |
| 113 | 113 |
| 114 CPDF_Dictionary* pFonts = pResDict->GetDictBy("Font"); | 114 CPDF_Dictionary* pFonts = pResDict->GetDictFor("Font"); |
| 115 if (!pFonts) | 115 if (!pFonts) |
| 116 return nullptr; | 116 return nullptr; |
| 117 | 117 |
| 118 CPDF_Document* pDocument = GetDocument(); | 118 CPDF_Document* pDocument = GetDocument(); |
| 119 CPDF_Font* pFind = nullptr; | 119 CPDF_Font* pFind = nullptr; |
| 120 for (const auto& it : *pFonts) { | 120 for (const auto& it : *pFonts) { |
| 121 const CFX_ByteString& csKey = it.first; | 121 const CFX_ByteString& csKey = it.first; |
| 122 CPDF_Object* pObj = it.second; | 122 CPDF_Object* pObj = it.second; |
| 123 if (!pObj) | 123 if (!pObj) |
| 124 continue; | 124 continue; |
| 125 | 125 |
| 126 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 126 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
| 127 if (!pElement) | 127 if (!pElement) |
| 128 continue; | 128 continue; |
| 129 if (pElement->GetStringBy("Type") != "Font") | 129 if (pElement->GetStringFor("Type") != "Font") |
| 130 continue; | 130 continue; |
| 131 | 131 |
| 132 CPDF_Font* pFont = pDocument->LoadFont(pElement); | 132 CPDF_Font* pFont = pDocument->LoadFont(pElement); |
| 133 if (!pFont) | 133 if (!pFont) |
| 134 continue; | 134 continue; |
| 135 const CFX_SubstFont* pSubst = pFont->GetSubstFont(); | 135 const CFX_SubstFont* pSubst = pFont->GetSubstFont(); |
| 136 if (!pSubst) | 136 if (!pSubst) |
| 137 continue; | 137 continue; |
| 138 if (pSubst->m_Charset == nCharset) { | 138 if (pSubst->m_Charset == nCharset) { |
| 139 sFontAlias = csKey; | 139 sFontAlias = csKey; |
| 140 pFind = pFont; | 140 pFind = pFont; |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 return pFind; | 143 return pFind; |
| 144 } | 144 } |
| 145 | 145 |
| 146 void CBA_FontMap::AddedFont(CPDF_Font* pFont, | 146 void CBA_FontMap::AddedFont(CPDF_Font* pFont, |
| 147 const CFX_ByteString& sFontAlias) { | 147 const CFX_ByteString& sFontAlias) { |
| 148 AddFontToAnnotDict(pFont, sFontAlias); | 148 AddFontToAnnotDict(pFont, sFontAlias); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, | 151 void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, |
| 152 const CFX_ByteString& sAlias) { | 152 const CFX_ByteString& sAlias) { |
| 153 if (!pFont) | 153 if (!pFont) |
| 154 return; | 154 return; |
| 155 | 155 |
| 156 CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictBy("AP"); | 156 CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictFor("AP"); |
| 157 | 157 |
| 158 if (!pAPDict) { | 158 if (!pAPDict) { |
| 159 pAPDict = new CPDF_Dictionary; | 159 pAPDict = new CPDF_Dictionary; |
| 160 m_pAnnotDict->SetAt("AP", pAPDict); | 160 m_pAnnotDict->SetFor("AP", pAPDict); |
| 161 } | 161 } |
| 162 | 162 |
| 163 // to avoid checkbox and radiobutton | 163 // to avoid checkbox and radiobutton |
| 164 CPDF_Object* pObject = pAPDict->GetObjectBy(m_sAPType); | 164 CPDF_Object* pObject = pAPDict->GetObjectFor(m_sAPType); |
| 165 if (ToDictionary(pObject)) | 165 if (ToDictionary(pObject)) |
| 166 return; | 166 return; |
| 167 | 167 |
| 168 CPDF_Stream* pStream = pAPDict->GetStreamBy(m_sAPType); | 168 CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType); |
| 169 if (!pStream) { | 169 if (!pStream) { |
| 170 pStream = new CPDF_Stream(nullptr, 0, nullptr); | 170 pStream = new CPDF_Stream(nullptr, 0, nullptr); |
| 171 int32_t objnum = m_pDocument->AddIndirectObject(pStream); | 171 int32_t objnum = m_pDocument->AddIndirectObject(pStream); |
| 172 pAPDict->SetAtReference(m_sAPType, m_pDocument, objnum); | 172 pAPDict->SetReferenceFor(m_sAPType, m_pDocument, objnum); |
| 173 } | 173 } |
| 174 | 174 |
| 175 CPDF_Dictionary* pStreamDict = pStream->GetDict(); | 175 CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
| 176 | 176 |
| 177 if (!pStreamDict) { | 177 if (!pStreamDict) { |
| 178 pStreamDict = new CPDF_Dictionary; | 178 pStreamDict = new CPDF_Dictionary; |
| 179 pStream->InitStream(nullptr, 0, pStreamDict); | 179 pStream->InitStream(nullptr, 0, pStreamDict); |
| 180 } | 180 } |
| 181 | 181 |
| 182 if (pStreamDict) { | 182 if (pStreamDict) { |
| 183 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); | 183 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); |
| 184 if (!pStreamResList) { | 184 if (!pStreamResList) { |
| 185 pStreamResList = new CPDF_Dictionary(); | 185 pStreamResList = new CPDF_Dictionary(); |
| 186 pStreamDict->SetAt("Resources", pStreamResList); | 186 pStreamDict->SetFor("Resources", pStreamResList); |
| 187 } | 187 } |
| 188 | 188 |
| 189 if (pStreamResList) { | 189 if (pStreamResList) { |
| 190 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font"); | 190 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); |
| 191 if (!pStreamResFontList) { | 191 if (!pStreamResFontList) { |
| 192 pStreamResFontList = new CPDF_Dictionary; | 192 pStreamResFontList = new CPDF_Dictionary; |
| 193 int32_t objnum = m_pDocument->AddIndirectObject(pStreamResFontList); | 193 int32_t objnum = m_pDocument->AddIndirectObject(pStreamResFontList); |
| 194 pStreamResList->SetAtReference("Font", m_pDocument, objnum); | 194 pStreamResList->SetReferenceFor("Font", m_pDocument, objnum); |
| 195 } | 195 } |
| 196 if (!pStreamResFontList->KeyExist(sAlias)) | 196 if (!pStreamResFontList->KeyExist(sAlias)) |
| 197 pStreamResFontList->SetAtReference(sAlias, m_pDocument, | 197 pStreamResFontList->SetReferenceFor(sAlias, m_pDocument, |
| 198 pFont->GetFontDict()); | 198 pFont->GetFontDict()); |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { | 203 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { |
| 204 CPDF_Dictionary* pAcroFormDict = nullptr; | 204 CPDF_Dictionary* pAcroFormDict = nullptr; |
| 205 const bool bWidget = (m_pAnnotDict->GetStringBy("Subtype") == "Widget"); | 205 const bool bWidget = (m_pAnnotDict->GetStringFor("Subtype") == "Widget"); |
| 206 if (bWidget) { | 206 if (bWidget) { |
| 207 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) | 207 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) |
| 208 pAcroFormDict = pRootDict->GetDictBy("AcroForm"); | 208 pAcroFormDict = pRootDict->GetDictFor("AcroForm"); |
| 209 } | 209 } |
| 210 | 210 |
| 211 CFX_ByteString sDA; | 211 CFX_ByteString sDA; |
| 212 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pAnnotDict, "DA"); | 212 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pAnnotDict, "DA"); |
| 213 if (pObj) | 213 if (pObj) |
| 214 sDA = pObj->GetString(); | 214 sDA = pObj->GetString(); |
| 215 | 215 |
| 216 if (bWidget) { | 216 if (bWidget) { |
| 217 if (sDA.IsEmpty()) { | 217 if (sDA.IsEmpty()) { |
| 218 pObj = FPDF_GetFieldAttr(pAcroFormDict, "DA"); | 218 pObj = FPDF_GetFieldAttr(pAcroFormDict, "DA"); |
| 219 sDA = pObj ? pObj->GetString() : CFX_ByteString(); | 219 sDA = pObj ? pObj->GetString() : CFX_ByteString(); |
| 220 } | 220 } |
| 221 } | 221 } |
| 222 if (sDA.IsEmpty()) | 222 if (sDA.IsEmpty()) |
| 223 return nullptr; | 223 return nullptr; |
| 224 | 224 |
| 225 CPDF_SimpleParser syntax(sDA.AsStringC()); | 225 CPDF_SimpleParser syntax(sDA.AsStringC()); |
| 226 syntax.FindTagParamFromStart("Tf", 2); | 226 syntax.FindTagParamFromStart("Tf", 2); |
| 227 CFX_ByteString sFontName(syntax.GetWord()); | 227 CFX_ByteString sFontName(syntax.GetWord()); |
| 228 sAlias = PDF_NameDecode(sFontName).Mid(1); | 228 sAlias = PDF_NameDecode(sFontName).Mid(1); |
| 229 CPDF_Dictionary* pFontDict = nullptr; | 229 CPDF_Dictionary* pFontDict = nullptr; |
| 230 | 230 |
| 231 if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictBy("AP")) { | 231 if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictFor("AP")) { |
| 232 if (CPDF_Dictionary* pNormalDict = pAPDict->GetDictBy("N")) { | 232 if (CPDF_Dictionary* pNormalDict = pAPDict->GetDictFor("N")) { |
| 233 if (CPDF_Dictionary* pNormalResDict = | 233 if (CPDF_Dictionary* pNormalResDict = |
| 234 pNormalDict->GetDictBy("Resources")) { | 234 pNormalDict->GetDictFor("Resources")) { |
| 235 if (CPDF_Dictionary* pResFontDict = pNormalResDict->GetDictBy("Font")) | 235 if (CPDF_Dictionary* pResFontDict = pNormalResDict->GetDictFor("Font")) |
| 236 pFontDict = pResFontDict->GetDictBy(sAlias); | 236 pFontDict = pResFontDict->GetDictFor(sAlias); |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 | 240 |
| 241 if (bWidget && !pFontDict && pAcroFormDict) { | 241 if (bWidget && !pFontDict && pAcroFormDict) { |
| 242 if (CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR")) { | 242 if (CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictFor("DR")) { |
| 243 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictBy("Font")) | 243 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictFor("Font")) |
| 244 pFontDict = pDRFontDict->GetDictBy(sAlias); | 244 pFontDict = pDRFontDict->GetDictFor(sAlias); |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 | 247 |
| 248 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; | 248 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; |
| 249 } | 249 } |
| 250 | 250 |
| 251 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { | 251 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { |
| 252 m_sAPType = sAPType; | 252 m_sAPType = sAPType; |
| 253 | 253 |
| 254 Reset(); | 254 Reset(); |
| 255 Initialize(); | 255 Initialize(); |
| 256 } | 256 } |
| OLD | NEW |