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 | |
dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame] | 9 | #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 10 | #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 11 | #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 12 | #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" |
dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame] | 13 | #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 14 | #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" |
| 15 | #include "core/fpdfdoc/include/cpdf_formfield.h" |
npm | 81ee14d | 2016-08-29 09:35:12 -0700 | [diff] [blame] | 16 | #include "core/fxge/include/cfx_substfont.h" |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 17 | #include "fpdfsdk/include/cpdfsdk_annot.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 18 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 19 | CBA_FontMap::CBA_FontMap(CPDFSDK_Annot* pAnnot, |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 20 | CFX_SystemHandler* pSystemHandler) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 21 | : CPWL_FontMap(pSystemHandler), |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 22 | m_pDocument(nullptr), |
| 23 | m_pAnnotDict(nullptr), |
| 24 | m_pDefaultFont(nullptr), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 25 | m_sAPType("N") { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 26 | CPDF_Page* pPage = pAnnot->GetPDFPage(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 27 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 28 | m_pDocument = pPage->m_pDocument; |
| 29 | m_pAnnotDict = pAnnot->GetPDFAnnot()->GetAnnotDict(); |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 30 | Initialize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | CBA_FontMap::~CBA_FontMap() {} |
| 34 | |
| 35 | void CBA_FontMap::Reset() { |
| 36 | Empty(); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 37 | m_pDefaultFont = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 38 | m_sDefaultFontName = ""; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 41 | void CBA_FontMap::Initialize() { |
npm | ea3c3be | 2016-09-19 07:24:33 -0700 | [diff] [blame] | 42 | int32_t nCharset = FXFONT_DEFAULT_CHARSET; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 43 | |
| 44 | if (!m_pDefaultFont) { |
| 45 | m_pDefaultFont = GetAnnotDefaultFont(m_sDefaultFontName); |
| 46 | if (m_pDefaultFont) { |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 47 | if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | nCharset = pSubstFont->m_Charset; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 49 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | if (m_sDefaultFontName == "Wingdings" || |
| 51 | m_sDefaultFontName == "Wingdings2" || |
| 52 | m_sDefaultFontName == "Wingdings3" || |
| 53 | m_sDefaultFontName == "Webdings") |
npm | ea3c3be | 2016-09-19 07:24:33 -0700 | [diff] [blame] | 54 | nCharset = FXFONT_SYMBOL_CHARSET; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | else |
npm | ea3c3be | 2016-09-19 07:24:33 -0700 | [diff] [blame] | 56 | nCharset = FXFONT_ANSI_CHARSET; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | } |
| 58 | AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset); |
| 59 | AddFontToAnnotDict(m_pDefaultFont, m_sDefaultFontName); |
| 60 | } |
| 61 | } |
| 62 | |
npm | ea3c3be | 2016-09-19 07:24:33 -0700 | [diff] [blame] | 63 | if (nCharset != FXFONT_ANSI_CHARSET) |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 64 | CPWL_FontMap::Initialize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | void CBA_FontMap::SetDefaultFont(CPDF_Font* pFont, |
| 68 | const CFX_ByteString& sFontName) { |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 69 | ASSERT(pFont); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | |
| 71 | if (m_pDefaultFont) |
| 72 | return; |
| 73 | |
| 74 | m_pDefaultFont = pFont; |
| 75 | m_sDefaultFontName = sFontName; |
| 76 | |
npm | ea3c3be | 2016-09-19 07:24:33 -0700 | [diff] [blame] | 77 | int32_t nCharset = FXFONT_DEFAULT_CHARSET; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 78 | if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont()) |
| 79 | nCharset = pSubstFont->m_Charset; |
| 80 | AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, |
| 84 | int32_t nCharset) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 85 | if (m_pAnnotDict->GetStringFor("Subtype") != "Widget") |
thestig | 907a522 | 2016-06-21 14:38:27 -0700 | [diff] [blame] | 86 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | |
thestig | 907a522 | 2016-06-21 14:38:27 -0700 | [diff] [blame] | 88 | CPDF_Document* pDocument = GetDocument(); |
| 89 | CPDF_Dictionary* pRootDict = pDocument->GetRoot(); |
| 90 | if (!pRootDict) |
| 91 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 92 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 93 | CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictFor("AcroForm"); |
thestig | 907a522 | 2016-06-21 14:38:27 -0700 | [diff] [blame] | 94 | if (!pAcroFormDict) |
| 95 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 97 | CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictFor("DR"); |
thestig | 907a522 | 2016-06-21 14:38:27 -0700 | [diff] [blame] | 98 | if (!pDRDict) |
| 99 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 100 | |
thestig | 907a522 | 2016-06-21 14:38:27 -0700 | [diff] [blame] | 101 | return FindResFontSameCharset(pDRDict, sFontAlias, nCharset); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 104 | CPDF_Document* CBA_FontMap::GetDocument() { |
| 105 | return m_pDocument; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 108 | CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict, |
| 109 | CFX_ByteString& sFontAlias, |
| 110 | int32_t nCharset) { |
| 111 | if (!pResDict) |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 112 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 113 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 114 | CPDF_Dictionary* pFonts = pResDict->GetDictFor("Font"); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 115 | if (!pFonts) |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 116 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 117 | |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 118 | CPDF_Document* pDocument = GetDocument(); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 119 | CPDF_Font* pFind = nullptr; |
Oliver Chang | 3f1c71f | 2016-01-11 08:45:31 -0800 | [diff] [blame] | 120 | for (const auto& it : *pFonts) { |
| 121 | const CFX_ByteString& csKey = it.first; |
| 122 | CPDF_Object* pObj = it.second; |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 123 | if (!pObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 124 | continue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 125 | |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 126 | CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
| 127 | if (!pElement) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 128 | continue; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 129 | if (pElement->GetStringFor("Type") != "Font") |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 130 | continue; |
| 131 | |
| 132 | CPDF_Font* pFont = pDocument->LoadFont(pElement); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 133 | if (!pFont) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 134 | continue; |
| 135 | const CFX_SubstFont* pSubst = pFont->GetSubstFont(); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 136 | if (!pSubst) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 137 | continue; |
| 138 | if (pSubst->m_Charset == nCharset) { |
| 139 | sFontAlias = csKey; |
| 140 | pFind = pFont; |
| 141 | } |
| 142 | } |
| 143 | return pFind; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 146 | void CBA_FontMap::AddedFont(CPDF_Font* pFont, |
| 147 | const CFX_ByteString& sFontAlias) { |
| 148 | AddFontToAnnotDict(pFont, sFontAlias); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 151 | void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, |
| 152 | const CFX_ByteString& sAlias) { |
| 153 | if (!pFont) |
| 154 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 155 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 156 | CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictFor("AP"); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 157 | if (!pAPDict) { |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 158 | pAPDict = new CPDF_Dictionary; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 159 | m_pAnnotDict->SetFor("AP", pAPDict); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 160 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 161 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 162 | // to avoid checkbox and radiobutton |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 163 | CPDF_Object* pObject = pAPDict->GetObjectFor(m_sAPType); |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 164 | if (ToDictionary(pObject)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 166 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 167 | CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 168 | if (!pStream) { |
tsepez | e6db16e | 2016-09-19 10:45:09 -0700 | [diff] [blame] | 169 | pStream = new CPDF_Stream; |
tsepez | bb577af | 2016-09-21 19:10:19 -0700 | [diff] [blame^] | 170 | pAPDict->SetReferenceFor(m_sAPType, m_pDocument, |
| 171 | m_pDocument->AddIndirectObject(pStream)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 172 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 173 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 174 | CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 175 | if (!pStreamDict) { |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 176 | pStreamDict = new CPDF_Dictionary; |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 177 | pStream->InitStream(nullptr, 0, pStreamDict); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | if (pStreamDict) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 181 | CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 182 | if (!pStreamResList) { |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 183 | pStreamResList = new CPDF_Dictionary(); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 184 | pStreamDict->SetFor("Resources", pStreamResList); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 185 | } |
tsepez | bb577af | 2016-09-21 19:10:19 -0700 | [diff] [blame^] | 186 | CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); |
| 187 | if (!pStreamResFontList) { |
| 188 | pStreamResFontList = new CPDF_Dictionary; |
| 189 | pStreamResList->SetReferenceFor( |
| 190 | "Font", m_pDocument, |
| 191 | m_pDocument->AddIndirectObject(pStreamResFontList)); |
| 192 | } |
| 193 | if (!pStreamResFontList->KeyExist(sAlias)) { |
| 194 | pStreamResFontList->SetReferenceFor(sAlias, m_pDocument, |
| 195 | pFont->GetFontDict()->GetObjNum()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 196 | } |
| 197 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 200 | CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 201 | CPDF_Dictionary* pAcroFormDict = nullptr; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 202 | const bool bWidget = (m_pAnnotDict->GetStringFor("Subtype") == "Widget"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 203 | if (bWidget) { |
| 204 | if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 205 | pAcroFormDict = pRootDict->GetDictFor("AcroForm"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | CFX_ByteString sDA; |
Wei Li | d4e8f12 | 2016-03-21 11:20:44 -0700 | [diff] [blame] | 209 | CPDF_Object* pObj = FPDF_GetFieldAttr(m_pAnnotDict, "DA"); |
| 210 | if (pObj) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 211 | sDA = pObj->GetString(); |
| 212 | |
| 213 | if (bWidget) { |
| 214 | if (sDA.IsEmpty()) { |
| 215 | pObj = FPDF_GetFieldAttr(pAcroFormDict, "DA"); |
| 216 | sDA = pObj ? pObj->GetString() : CFX_ByteString(); |
| 217 | } |
| 218 | } |
npm | 860a2d0 | 2016-09-12 15:02:28 -0700 | [diff] [blame] | 219 | if (sDA.IsEmpty()) |
| 220 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 221 | |
npm | 860a2d0 | 2016-09-12 15:02:28 -0700 | [diff] [blame] | 222 | CPDF_SimpleParser syntax(sDA.AsStringC()); |
| 223 | syntax.FindTagParamFromStart("Tf", 2); |
| 224 | CFX_ByteString sFontName(syntax.GetWord()); |
| 225 | sAlias = PDF_NameDecode(sFontName).Mid(1); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 226 | CPDF_Dictionary* pFontDict = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 227 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 228 | if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictFor("AP")) { |
| 229 | if (CPDF_Dictionary* pNormalDict = pAPDict->GetDictFor("N")) { |
npm | 860a2d0 | 2016-09-12 15:02:28 -0700 | [diff] [blame] | 230 | if (CPDF_Dictionary* pNormalResDict = |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 231 | pNormalDict->GetDictFor("Resources")) { |
| 232 | if (CPDF_Dictionary* pResFontDict = pNormalResDict->GetDictFor("Font")) |
| 233 | pFontDict = pResFontDict->GetDictFor(sAlias); |
npm | 860a2d0 | 2016-09-12 15:02:28 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 237 | |
npm | 860a2d0 | 2016-09-12 15:02:28 -0700 | [diff] [blame] | 238 | if (bWidget && !pFontDict && pAcroFormDict) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 239 | if (CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictFor("DR")) { |
| 240 | if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictFor("Font")) |
| 241 | pFontDict = pDRFontDict->GetDictFor(sAlias); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
| 245 | return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 248 | void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { |
| 249 | m_sAPType = sAPType; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 250 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 251 | Reset(); |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 252 | Initialize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 253 | } |