| 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 <utility> |
| 10 |
| 9 #include "core/fpdfapi/font/cpdf_font.h" | 11 #include "core/fpdfapi/font/cpdf_font.h" |
| 10 #include "core/fpdfapi/page/cpdf_page.h" | 12 #include "core/fpdfapi/page/cpdf_page.h" |
| 11 #include "core/fpdfapi/parser/cpdf_document.h" | 13 #include "core/fpdfapi/parser/cpdf_document.h" |
| 12 #include "core/fpdfapi/parser/cpdf_reference.h" | 14 #include "core/fpdfapi/parser/cpdf_reference.h" |
| 13 #include "core/fpdfapi/parser/cpdf_simple_parser.h" | 15 #include "core/fpdfapi/parser/cpdf_simple_parser.h" |
| 14 #include "core/fpdfapi/parser/cpdf_stream.h" | 16 #include "core/fpdfapi/parser/cpdf_stream.h" |
| 15 #include "core/fpdfapi/parser/fpdf_parser_decode.h" | 17 #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
| 16 #include "core/fpdfdoc/cpdf_formfield.h" | 18 #include "core/fpdfdoc/cpdf_formfield.h" |
| 17 #include "core/fxge/cfx_substfont.h" | 19 #include "core/fxge/cfx_substfont.h" |
| 18 #include "fpdfsdk/cpdfsdk_annot.h" | 20 #include "fpdfsdk/cpdfsdk_annot.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 166 |
| 165 CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType); | 167 CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType); |
| 166 if (!pStream) { | 168 if (!pStream) { |
| 167 pStream = m_pDocument->NewIndirect<CPDF_Stream>(); | 169 pStream = m_pDocument->NewIndirect<CPDF_Stream>(); |
| 168 pAPDict->SetNewFor<CPDF_Reference>(m_sAPType, m_pDocument, | 170 pAPDict->SetNewFor<CPDF_Reference>(m_sAPType, m_pDocument, |
| 169 pStream->GetObjNum()); | 171 pStream->GetObjNum()); |
| 170 } | 172 } |
| 171 | 173 |
| 172 CPDF_Dictionary* pStreamDict = pStream->GetDict(); | 174 CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
| 173 if (!pStreamDict) { | 175 if (!pStreamDict) { |
| 174 pStreamDict = new CPDF_Dictionary(m_pDocument->GetByteStringPool()); | 176 auto pOwnedDict = |
| 175 pStream->InitStream(nullptr, 0, pStreamDict); | 177 pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool()); |
| 178 pStreamDict = pOwnedDict.get(); |
| 179 pStream->InitStream(nullptr, 0, std::move(pOwnedDict)); |
| 176 } | 180 } |
| 177 | 181 |
| 178 if (pStreamDict) { | 182 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); |
| 179 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); | 183 if (!pStreamResList) |
| 180 if (!pStreamResList) | 184 pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources"); |
| 181 pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources"); | 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->SetNewFor<CPDF_Reference>("Font", m_pDocument, |
| 185 pStreamResList->SetNewFor<CPDF_Reference>( | 189 pStreamResFontList->GetObjNum()); |
| 186 "Font", m_pDocument, pStreamResFontList->GetObjNum()); | 190 } |
| 187 } | 191 if (!pStreamResFontList->KeyExist(sAlias)) { |
| 188 if (!pStreamResFontList->KeyExist(sAlias)) { | 192 pStreamResFontList->SetNewFor<CPDF_Reference>( |
| 189 pStreamResFontList->SetNewFor<CPDF_Reference>( | 193 sAlias, m_pDocument, pFont->GetFontDict()->GetObjNum()); |
| 190 sAlias, m_pDocument, pFont->GetFontDict()->GetObjNum()); | |
| 191 } | |
| 192 } | 194 } |
| 193 } | 195 } |
| 194 | 196 |
| 195 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { | 197 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { |
| 196 CPDF_Dictionary* pAcroFormDict = nullptr; | 198 CPDF_Dictionary* pAcroFormDict = nullptr; |
| 197 const bool bWidget = (m_pAnnotDict->GetStringFor("Subtype") == "Widget"); | 199 const bool bWidget = (m_pAnnotDict->GetStringFor("Subtype") == "Widget"); |
| 198 if (bWidget) { | 200 if (bWidget) { |
| 199 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) | 201 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) |
| 200 pAcroFormDict = pRootDict->GetDictFor("AcroForm"); | 202 pAcroFormDict = pRootDict->GetDictFor("AcroForm"); |
| 201 } | 203 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 241 |
| 240 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; | 242 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; |
| 241 } | 243 } |
| 242 | 244 |
| 243 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { | 245 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { |
| 244 m_sAPType = sAPType; | 246 m_sAPType = sAPType; |
| 245 | 247 |
| 246 Reset(); | 248 Reset(); |
| 247 Initialize(); | 249 Initialize(); |
| 248 } | 250 } |
| OLD | NEW |