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