John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | edbb319 | 2016-03-21 09:08:24 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/formfiller/cba_fontmap.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 8 | |
tsepez | 9e05ee1 | 2016-11-21 13:19:10 -0800 | [diff] [blame] | 9 | #include <utility> |
| 10 | |
dsinclair | bc5e6d2 | 2016-10-04 11:08:49 -0700 | [diff] [blame] | 11 | #include "core/fpdfapi/font/cpdf_font.h" |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/page/cpdf_page.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/parser/cpdf_document.h" |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 14 | #include "core/fpdfapi/parser/cpdf_reference.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 15 | #include "core/fpdfapi/parser/cpdf_simple_parser.h" |
| 16 | #include "core/fpdfapi/parser/cpdf_stream.h" |
| 17 | #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 18 | #include "core/fpdfdoc/cpdf_formfield.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 19 | #include "core/fxge/cfx_substfont.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 20 | #include "fpdfsdk/cpdfsdk_annot.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 21 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 22 | CBA_FontMap::CBA_FontMap(CPDFSDK_Annot* pAnnot, |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 23 | CFX_SystemHandler* pSystemHandler) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 24 | : CPWL_FontMap(pSystemHandler), |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 25 | m_pDocument(nullptr), |
| 26 | m_pAnnotDict(nullptr), |
| 27 | m_pDefaultFont(nullptr), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 28 | m_sAPType("N") { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 29 | CPDF_Page* pPage = pAnnot->GetPDFPage(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | |
Tom Sepez | 4cb82ee | 2017-05-22 15:15:30 -0700 | [diff] [blame] | 31 | m_pDocument = pPage->m_pDocument.Get(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 32 | m_pAnnotDict = pAnnot->GetPDFAnnot()->GetAnnotDict(); |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 33 | Initialize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 36 | CBA_FontMap::~CBA_FontMap() {} |
| 37 | |
| 38 | void CBA_FontMap::Reset() { |
| 39 | Empty(); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 40 | m_pDefaultFont = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 41 | m_sDefaultFontName = ""; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 44 | void CBA_FontMap::Initialize() { |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 45 | int32_t nCharset = FX_CHARSET_Default; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 46 | |
| 47 | if (!m_pDefaultFont) { |
Tom Sepez | ec8ff7d | 2017-04-07 16:58:00 -0700 | [diff] [blame] | 48 | m_pDefaultFont = GetAnnotDefaultFont(&m_sDefaultFontName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 49 | if (m_pDefaultFont) { |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 50 | if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 51 | nCharset = pSubstFont->m_Charset; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 52 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 53 | if (m_sDefaultFontName == "Wingdings" || |
| 54 | m_sDefaultFontName == "Wingdings2" || |
| 55 | m_sDefaultFontName == "Wingdings3" || |
| 56 | m_sDefaultFontName == "Webdings") |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 57 | nCharset = FX_CHARSET_Symbol; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 58 | else |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 59 | nCharset = FX_CHARSET_ANSI; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 60 | } |
Tom Sepez | dc8a2b7 | 2017-05-24 13:45:11 -0700 | [diff] [blame] | 61 | AddFontData(m_pDefaultFont.Get(), m_sDefaultFontName, nCharset); |
| 62 | AddFontToAnnotDict(m_pDefaultFont.Get(), m_sDefaultFontName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 66 | if (nCharset != FX_CHARSET_ANSI) |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 67 | CPWL_FontMap::Initialize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | void CBA_FontMap::SetDefaultFont(CPDF_Font* pFont, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 71 | const ByteString& sFontName) { |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 72 | ASSERT(pFont); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 73 | |
| 74 | if (m_pDefaultFont) |
| 75 | return; |
| 76 | |
| 77 | m_pDefaultFont = pFont; |
| 78 | m_sDefaultFontName = sFontName; |
| 79 | |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 80 | int32_t nCharset = FX_CHARSET_Default; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 81 | if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont()) |
| 82 | nCharset = pSubstFont->m_Charset; |
Tom Sepez | dc8a2b7 | 2017-05-24 13:45:11 -0700 | [diff] [blame] | 83 | AddFontData(m_pDefaultFont.Get(), m_sDefaultFontName, nCharset); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 86 | CPDF_Font* CBA_FontMap::FindFontSameCharset(ByteString* sFontAlias, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | int32_t nCharset) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 88 | if (m_pAnnotDict->GetStringFor("Subtype") != "Widget") |
thestig | 907a522 | 2016-06-21 14:38:27 -0700 | [diff] [blame] | 89 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 90 | |
thestig | 907a522 | 2016-06-21 14:38:27 -0700 | [diff] [blame] | 91 | CPDF_Document* pDocument = GetDocument(); |
Lei Zhang | 0158106 | 2017-08-30 14:19:26 -0700 | [diff] [blame] | 92 | const CPDF_Dictionary* pRootDict = pDocument->GetRoot(); |
thestig | 907a522 | 2016-06-21 14:38:27 -0700 | [diff] [blame] | 93 | if (!pRootDict) |
| 94 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 95 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 96 | CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictFor("AcroForm"); |
thestig | 907a522 | 2016-06-21 14:38:27 -0700 | [diff] [blame] | 97 | if (!pAcroFormDict) |
| 98 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 99 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 100 | CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictFor("DR"); |
thestig | 907a522 | 2016-06-21 14:38:27 -0700 | [diff] [blame] | 101 | if (!pDRDict) |
| 102 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 103 | |
thestig | 907a522 | 2016-06-21 14:38:27 -0700 | [diff] [blame] | 104 | return FindResFontSameCharset(pDRDict, sFontAlias, nCharset); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 107 | CPDF_Document* CBA_FontMap::GetDocument() { |
Tom Sepez | dc8a2b7 | 2017-05-24 13:45:11 -0700 | [diff] [blame] | 108 | return m_pDocument.Get(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 111 | CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 112 | ByteString* sFontAlias, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 113 | int32_t nCharset) { |
| 114 | if (!pResDict) |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 115 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 116 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 117 | CPDF_Dictionary* pFonts = pResDict->GetDictFor("Font"); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 118 | if (!pFonts) |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 119 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 120 | |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 121 | CPDF_Document* pDocument = GetDocument(); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 122 | CPDF_Font* pFind = nullptr; |
Oliver Chang | 3f1c71f | 2016-01-11 08:45:31 -0800 | [diff] [blame] | 123 | for (const auto& it : *pFonts) { |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 124 | const ByteString& csKey = it.first; |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 125 | if (!it.second) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 126 | continue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 127 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 128 | CPDF_Dictionary* pElement = ToDictionary(it.second->GetDirect()); |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 129 | if (!pElement) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 130 | continue; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 131 | if (pElement->GetStringFor("Type") != "Font") |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 132 | continue; |
| 133 | |
| 134 | CPDF_Font* pFont = pDocument->LoadFont(pElement); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 135 | if (!pFont) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 136 | continue; |
| 137 | const CFX_SubstFont* pSubst = pFont->GetSubstFont(); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 138 | if (!pSubst) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 139 | continue; |
| 140 | if (pSubst->m_Charset == nCharset) { |
Tom Sepez | ec8ff7d | 2017-04-07 16:58:00 -0700 | [diff] [blame] | 141 | *sFontAlias = csKey; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 142 | pFind = pFont; |
| 143 | } |
| 144 | } |
| 145 | return pFind; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 148 | void CBA_FontMap::AddedFont(CPDF_Font* pFont, const ByteString& sFontAlias) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 149 | AddFontToAnnotDict(pFont, sFontAlias); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 152 | void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 153 | const ByteString& sAlias) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 154 | if (!pFont) |
| 155 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 156 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 157 | CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictFor("AP"); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 158 | if (!pAPDict) |
| 159 | pAPDict = m_pAnnotDict->SetNewFor<CPDF_Dictionary>("AP"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 160 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 161 | // to avoid checkbox and radiobutton |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 162 | CPDF_Object* pObject = pAPDict->GetObjectFor(m_sAPType); |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 163 | if (ToDictionary(pObject)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 164 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 165 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 166 | CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 167 | if (!pStream) { |
tsepez | 70c4afd | 2016-11-15 11:33:44 -0800 | [diff] [blame] | 168 | pStream = m_pDocument->NewIndirect<CPDF_Stream>(); |
Tom Sepez | dc8a2b7 | 2017-05-24 13:45:11 -0700 | [diff] [blame] | 169 | pAPDict->SetNewFor<CPDF_Reference>(m_sAPType, m_pDocument.Get(), |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 170 | pStream->GetObjNum()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 171 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 172 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 173 | CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 174 | if (!pStreamDict) { |
tsepez | 9e05ee1 | 2016-11-21 13:19:10 -0800 | [diff] [blame] | 175 | auto pOwnedDict = |
| 176 | pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool()); |
| 177 | pStreamDict = pOwnedDict.get(); |
| 178 | pStream->InitStream(nullptr, 0, std::move(pOwnedDict)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 179 | } |
| 180 | |
tsepez | 9e05ee1 | 2016-11-21 13:19:10 -0800 | [diff] [blame] | 181 | CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); |
| 182 | if (!pStreamResList) |
| 183 | pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources"); |
| 184 | CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); |
| 185 | if (!pStreamResFontList) { |
| 186 | pStreamResFontList = m_pDocument->NewIndirect<CPDF_Dictionary>(); |
Tom Sepez | dc8a2b7 | 2017-05-24 13:45:11 -0700 | [diff] [blame] | 187 | pStreamResList->SetNewFor<CPDF_Reference>("Font", m_pDocument.Get(), |
tsepez | 9e05ee1 | 2016-11-21 13:19:10 -0800 | [diff] [blame] | 188 | pStreamResFontList->GetObjNum()); |
| 189 | } |
| 190 | if (!pStreamResFontList->KeyExist(sAlias)) { |
| 191 | pStreamResFontList->SetNewFor<CPDF_Reference>( |
Tom Sepez | dc8a2b7 | 2017-05-24 13:45:11 -0700 | [diff] [blame] | 192 | sAlias, m_pDocument.Get(), pFont->GetFontDict()->GetObjNum()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 193 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 196 | CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(ByteString* sAlias) { |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 197 | CPDF_Dictionary* pAcroFormDict = nullptr; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 198 | const bool bWidget = (m_pAnnotDict->GetStringFor("Subtype") == "Widget"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 199 | if (bWidget) { |
Lei Zhang | 0158106 | 2017-08-30 14:19:26 -0700 | [diff] [blame] | 200 | const CPDF_Dictionary* pRootDict = m_pDocument->GetRoot(); |
| 201 | if (pRootDict) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 202 | pAcroFormDict = pRootDict->GetDictFor("AcroForm"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 205 | ByteString sDA; |
Tom Sepez | dc8a2b7 | 2017-05-24 13:45:11 -0700 | [diff] [blame] | 206 | CPDF_Object* pObj = FPDF_GetFieldAttr(m_pAnnotDict.Get(), "DA"); |
Wei Li | d4e8f12 | 2016-03-21 11:20:44 -0700 | [diff] [blame] | 207 | if (pObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 208 | sDA = pObj->GetString(); |
| 209 | |
| 210 | if (bWidget) { |
| 211 | if (sDA.IsEmpty()) { |
| 212 | pObj = FPDF_GetFieldAttr(pAcroFormDict, "DA"); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 213 | sDA = pObj ? pObj->GetString() : ByteString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 214 | } |
| 215 | } |
npm | 860a2d0 | 2016-09-12 15:02:28 -0700 | [diff] [blame] | 216 | if (sDA.IsEmpty()) |
| 217 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 218 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 219 | CPDF_SimpleParser syntax(sDA.AsStringView()); |
npm | 860a2d0 | 2016-09-12 15:02:28 -0700 | [diff] [blame] | 220 | syntax.FindTagParamFromStart("Tf", 2); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 221 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 222 | ByteString sFontName(syntax.GetWord()); |
| 223 | ByteString sDecodedFontName = PDF_NameDecode(sFontName); |
Ryan Harrison | e7a99de | 2017-07-28 14:07:04 -0400 | [diff] [blame] | 224 | *sAlias = sDecodedFontName.Right(sDecodedFontName.GetLength() - 1); |
Tom Sepez | ec8ff7d | 2017-04-07 16:58:00 -0700 | [diff] [blame] | 225 | |
| 226 | CPDF_Dictionary* pFontDict = nullptr; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 227 | if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictFor("AP")) { |
| 228 | if (CPDF_Dictionary* pNormalDict = pAPDict->GetDictFor("N")) { |
npm | 860a2d0 | 2016-09-12 15:02:28 -0700 | [diff] [blame] | 229 | if (CPDF_Dictionary* pNormalResDict = |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 230 | pNormalDict->GetDictFor("Resources")) { |
| 231 | if (CPDF_Dictionary* pResFontDict = pNormalResDict->GetDictFor("Font")) |
Tom Sepez | ec8ff7d | 2017-04-07 16:58:00 -0700 | [diff] [blame] | 232 | pFontDict = pResFontDict->GetDictFor(*sAlias); |
npm | 860a2d0 | 2016-09-12 15:02:28 -0700 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | } |
npm | 860a2d0 | 2016-09-12 15:02:28 -0700 | [diff] [blame] | 236 | if (bWidget && !pFontDict && pAcroFormDict) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 237 | if (CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictFor("DR")) { |
| 238 | if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictFor("Font")) |
Tom Sepez | ec8ff7d | 2017-04-07 16:58:00 -0700 | [diff] [blame] | 239 | pFontDict = pDRFontDict->GetDictFor(*sAlias); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 240 | } |
| 241 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 242 | return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 245 | void CBA_FontMap::SetAPType(const ByteString& sAPType) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 246 | m_sAPType = sAPType; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 247 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 248 | Reset(); |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 249 | Initialize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 250 | } |