| 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/font/cpdf_font.h" | 9 #include "core/fpdfapi/font/cpdf_font.h" |
| 10 #include "core/fpdfapi/page/cpdf_page.h" | 10 #include "core/fpdfapi/page/cpdf_page.h" |
| 11 #include "core/fpdfapi/parser/cpdf_document.h" | 11 #include "core/fpdfapi/parser/cpdf_document.h" |
| 12 #include "core/fpdfapi/parser/cpdf_reference.h" |
| 12 #include "core/fpdfapi/parser/cpdf_simple_parser.h" | 13 #include "core/fpdfapi/parser/cpdf_simple_parser.h" |
| 13 #include "core/fpdfapi/parser/cpdf_stream.h" | 14 #include "core/fpdfapi/parser/cpdf_stream.h" |
| 14 #include "core/fpdfapi/parser/fpdf_parser_decode.h" | 15 #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
| 15 #include "core/fpdfdoc/cpdf_formfield.h" | 16 #include "core/fpdfdoc/cpdf_formfield.h" |
| 16 #include "core/fxge/cfx_substfont.h" | 17 #include "core/fxge/cfx_substfont.h" |
| 17 #include "fpdfsdk/cpdfsdk_annot.h" | 18 #include "fpdfsdk/cpdfsdk_annot.h" |
| 18 | 19 |
| 19 CBA_FontMap::CBA_FontMap(CPDFSDK_Annot* pAnnot, | 20 CBA_FontMap::CBA_FontMap(CPDFSDK_Annot* pAnnot, |
| 20 CFX_SystemHandler* pSystemHandler) | 21 CFX_SystemHandler* pSystemHandler) |
| 21 : CPWL_FontMap(pSystemHandler), | 22 : CPWL_FontMap(pSystemHandler), |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 return nullptr; | 113 return nullptr; |
| 113 | 114 |
| 114 CPDF_Dictionary* pFonts = pResDict->GetDictFor("Font"); | 115 CPDF_Dictionary* pFonts = pResDict->GetDictFor("Font"); |
| 115 if (!pFonts) | 116 if (!pFonts) |
| 116 return nullptr; | 117 return nullptr; |
| 117 | 118 |
| 118 CPDF_Document* pDocument = GetDocument(); | 119 CPDF_Document* pDocument = GetDocument(); |
| 119 CPDF_Font* pFind = nullptr; | 120 CPDF_Font* pFind = nullptr; |
| 120 for (const auto& it : *pFonts) { | 121 for (const auto& it : *pFonts) { |
| 121 const CFX_ByteString& csKey = it.first; | 122 const CFX_ByteString& csKey = it.first; |
| 122 CPDF_Object* pObj = it.second; | 123 if (!it.second) |
| 123 if (!pObj) | |
| 124 continue; | 124 continue; |
| 125 | 125 |
| 126 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 126 CPDF_Dictionary* pElement = ToDictionary(it.second->GetDirect()); |
| 127 if (!pElement) | 127 if (!pElement) |
| 128 continue; | 128 continue; |
| 129 if (pElement->GetStringFor("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) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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->GetDictFor("AP"); | 156 CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictFor("AP"); |
| 157 if (!pAPDict) { | 157 if (!pAPDict) |
| 158 pAPDict = new CPDF_Dictionary(m_pDocument->GetByteStringPool()); | 158 pAPDict = m_pAnnotDict->SetNewFor<CPDF_Dictionary>("AP"); |
| 159 m_pAnnotDict->SetFor("AP", pAPDict); | |
| 160 } | |
| 161 | 159 |
| 162 // to avoid checkbox and radiobutton | 160 // to avoid checkbox and radiobutton |
| 163 CPDF_Object* pObject = pAPDict->GetObjectFor(m_sAPType); | 161 CPDF_Object* pObject = pAPDict->GetObjectFor(m_sAPType); |
| 164 if (ToDictionary(pObject)) | 162 if (ToDictionary(pObject)) |
| 165 return; | 163 return; |
| 166 | 164 |
| 167 CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType); | 165 CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType); |
| 168 if (!pStream) { | 166 if (!pStream) { |
| 169 pStream = m_pDocument->NewIndirect<CPDF_Stream>(); | 167 pStream = m_pDocument->NewIndirect<CPDF_Stream>(); |
| 170 pAPDict->SetReferenceFor(m_sAPType, m_pDocument, pStream); | 168 pAPDict->SetNewFor<CPDF_Reference>(m_sAPType, m_pDocument, |
| 169 pStream->GetObjNum()); |
| 171 } | 170 } |
| 172 | 171 |
| 173 CPDF_Dictionary* pStreamDict = pStream->GetDict(); | 172 CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
| 174 if (!pStreamDict) { | 173 if (!pStreamDict) { |
| 175 pStreamDict = new CPDF_Dictionary(m_pDocument->GetByteStringPool()); | 174 pStreamDict = new CPDF_Dictionary(m_pDocument->GetByteStringPool()); |
| 176 pStream->InitStream(nullptr, 0, pStreamDict); | 175 pStream->InitStream(nullptr, 0, pStreamDict); |
| 177 } | 176 } |
| 178 | 177 |
| 179 if (pStreamDict) { | 178 if (pStreamDict) { |
| 180 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); | 179 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); |
| 181 if (!pStreamResList) { | 180 if (!pStreamResList) |
| 182 pStreamResList = new CPDF_Dictionary(m_pDocument->GetByteStringPool()); | 181 pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources"); |
| 183 pStreamDict->SetFor("Resources", pStreamResList); | |
| 184 } | |
| 185 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); | 182 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); |
| 186 if (!pStreamResFontList) { | 183 if (!pStreamResFontList) { |
| 187 pStreamResFontList = m_pDocument->NewIndirect<CPDF_Dictionary>(); | 184 pStreamResFontList = m_pDocument->NewIndirect<CPDF_Dictionary>(); |
| 188 pStreamResList->SetReferenceFor("Font", m_pDocument, pStreamResFontList); | 185 pStreamResList->SetNewFor<CPDF_Reference>( |
| 186 "Font", m_pDocument, pStreamResFontList->GetObjNum()); |
| 189 } | 187 } |
| 190 if (!pStreamResFontList->KeyExist(sAlias)) { | 188 if (!pStreamResFontList->KeyExist(sAlias)) { |
| 191 pStreamResFontList->SetReferenceFor(sAlias, m_pDocument, | 189 pStreamResFontList->SetNewFor<CPDF_Reference>( |
| 192 pFont->GetFontDict()->GetObjNum()); | 190 sAlias, m_pDocument, pFont->GetFontDict()->GetObjNum()); |
| 193 } | 191 } |
| 194 } | 192 } |
| 195 } | 193 } |
| 196 | 194 |
| 197 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { | 195 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { |
| 198 CPDF_Dictionary* pAcroFormDict = nullptr; | 196 CPDF_Dictionary* pAcroFormDict = nullptr; |
| 199 const bool bWidget = (m_pAnnotDict->GetStringFor("Subtype") == "Widget"); | 197 const bool bWidget = (m_pAnnotDict->GetStringFor("Subtype") == "Widget"); |
| 200 if (bWidget) { | 198 if (bWidget) { |
| 201 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) | 199 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) |
| 202 pAcroFormDict = pRootDict->GetDictFor("AcroForm"); | 200 pAcroFormDict = pRootDict->GetDictFor("AcroForm"); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 239 |
| 242 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; | 240 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; |
| 243 } | 241 } |
| 244 | 242 |
| 245 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { | 243 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { |
| 246 m_sAPType = sAPType; | 244 m_sAPType = sAPType; |
| 247 | 245 |
| 248 Reset(); | 246 Reset(); |
| 249 Initialize(); | 247 Initialize(); |
| 250 } | 248 } |
| OLD | NEW |