Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 1 | // Copyright 2018 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. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | 00d47a6 | 2018-03-28 18:39:04 +0000 | [diff] [blame] | 7 | #include "fpdfsdk/cpdfsdk_helpers.h" |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 8 | |
Lei Zhang | 2617056 | 2018-04-17 17:01:52 +0000 | [diff] [blame] | 9 | #include "constants/stream_dict_common.h" |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 10 | #include "core/fpdfapi/cpdf_modulemgr.h" |
Tom Sepez | a1d3442 | 2018-04-24 20:54:41 +0000 | [diff] [blame] | 11 | #include "core/fpdfapi/page/cpdf_page.h" |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 12 | #include "core/fpdfapi/parser/cpdf_array.h" |
Lei Zhang | 8153561 | 2018-10-09 21:15:17 +0000 | [diff] [blame] | 13 | #include "core/fpdfapi/parser/cpdf_dictionary.h" |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 14 | #include "core/fpdfapi/parser/cpdf_document.h" |
Artem Strygin | eababa1 | 2018-06-06 12:31:18 +0000 | [diff] [blame] | 15 | #include "core/fpdfapi/parser/cpdf_stream_acc.h" |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 16 | #include "core/fpdfdoc/cpdf_annot.h" |
Lei Zhang | c345065 | 2018-10-11 16:54:42 +0000 | [diff] [blame^] | 17 | #include "core/fpdfdoc/cpdf_interactiveform.h" |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 18 | #include "core/fpdfdoc/cpdf_metadata.h" |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 19 | #include "public/fpdf_ext.h" |
| 20 | |
Tom Sepez | a1d3442 | 2018-04-24 20:54:41 +0000 | [diff] [blame] | 21 | #ifdef PDF_ENABLE_XFA |
| 22 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
| 23 | #endif |
| 24 | |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 25 | namespace { |
| 26 | |
Ralf Sippl | 1638179 | 2018-04-12 21:20:26 +0000 | [diff] [blame] | 27 | constexpr char kQuadPoints[] = "QuadPoints"; |
| 28 | |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 29 | bool RaiseUnSupportError(int nError) { |
| 30 | CFSDK_UnsupportInfo_Adapter* pAdapter = |
| 31 | CPDF_ModuleMgr::Get()->GetUnsupportInfoAdapter(); |
| 32 | if (!pAdapter) |
| 33 | return false; |
| 34 | |
| 35 | UNSUPPORT_INFO* info = static_cast<UNSUPPORT_INFO*>(pAdapter->GetUnspInfo()); |
| 36 | if (info && info->FSDK_UnSupport_Handler) |
| 37 | info->FSDK_UnSupport_Handler(info, nError); |
| 38 | return true; |
| 39 | } |
| 40 | |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 41 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 5586545 | 2018-08-27 20:18:04 +0000 | [diff] [blame] | 42 | class FPDF_FileHandlerContext final : public IFX_SeekableStream { |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 43 | public: |
| 44 | template <typename T, typename... Args> |
| 45 | friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); |
| 46 | |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 47 | // IFX_SeekableStream: |
| 48 | FX_FILESIZE GetSize() override; |
| 49 | bool IsEOF() override; |
| 50 | FX_FILESIZE GetPosition() override; |
| 51 | bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; |
| 52 | size_t ReadBlock(void* buffer, size_t size) override; |
| 53 | bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override; |
| 54 | bool Flush() override; |
| 55 | |
| 56 | void SetPosition(FX_FILESIZE pos) { m_nCurPos = pos; } |
| 57 | |
Tom Sepez | cb79825 | 2018-09-17 18:25:32 +0000 | [diff] [blame] | 58 | private: |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 59 | explicit FPDF_FileHandlerContext(FPDF_FILEHANDLER* pFS); |
Lei Zhang | 86688de | 2018-05-22 22:06:49 +0000 | [diff] [blame] | 60 | ~FPDF_FileHandlerContext() override; |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 61 | |
| 62 | FPDF_FILEHANDLER* m_pFS; |
| 63 | FX_FILESIZE m_nCurPos; |
| 64 | }; |
| 65 | |
| 66 | FPDF_FileHandlerContext::FPDF_FileHandlerContext(FPDF_FILEHANDLER* pFS) { |
| 67 | m_pFS = pFS; |
| 68 | m_nCurPos = 0; |
| 69 | } |
| 70 | |
| 71 | FPDF_FileHandlerContext::~FPDF_FileHandlerContext() { |
| 72 | if (m_pFS && m_pFS->Release) |
| 73 | m_pFS->Release(m_pFS->clientData); |
| 74 | } |
| 75 | |
| 76 | FX_FILESIZE FPDF_FileHandlerContext::GetSize() { |
| 77 | if (m_pFS && m_pFS->GetSize) |
| 78 | return (FX_FILESIZE)m_pFS->GetSize(m_pFS->clientData); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | bool FPDF_FileHandlerContext::IsEOF() { |
| 83 | return m_nCurPos >= GetSize(); |
| 84 | } |
| 85 | |
| 86 | FX_FILESIZE FPDF_FileHandlerContext::GetPosition() { |
| 87 | return m_nCurPos; |
| 88 | } |
| 89 | |
| 90 | bool FPDF_FileHandlerContext::ReadBlock(void* buffer, |
| 91 | FX_FILESIZE offset, |
| 92 | size_t size) { |
| 93 | if (!buffer || !size || !m_pFS->ReadBlock) |
| 94 | return false; |
| 95 | |
| 96 | if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer, |
| 97 | (FPDF_DWORD)size) == 0) { |
| 98 | m_nCurPos = offset + size; |
| 99 | return true; |
| 100 | } |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | size_t FPDF_FileHandlerContext::ReadBlock(void* buffer, size_t size) { |
| 105 | if (!buffer || !size || !m_pFS->ReadBlock) |
| 106 | return 0; |
| 107 | |
| 108 | FX_FILESIZE nSize = GetSize(); |
| 109 | if (m_nCurPos >= nSize) |
| 110 | return 0; |
| 111 | FX_FILESIZE dwAvail = nSize - m_nCurPos; |
| 112 | if (dwAvail < (FX_FILESIZE)size) |
| 113 | size = static_cast<size_t>(dwAvail); |
| 114 | if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)m_nCurPos, buffer, |
| 115 | (FPDF_DWORD)size) == 0) { |
| 116 | m_nCurPos += size; |
| 117 | return size; |
| 118 | } |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | bool FPDF_FileHandlerContext::WriteBlock(const void* buffer, |
| 124 | FX_FILESIZE offset, |
| 125 | size_t size) { |
| 126 | if (!m_pFS || !m_pFS->WriteBlock) |
| 127 | return false; |
| 128 | |
| 129 | if (m_pFS->WriteBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer, |
| 130 | (FPDF_DWORD)size) == 0) { |
| 131 | m_nCurPos = offset + size; |
| 132 | return true; |
| 133 | } |
| 134 | return false; |
| 135 | } |
| 136 | |
| 137 | bool FPDF_FileHandlerContext::Flush() { |
| 138 | if (!m_pFS || !m_pFS->Flush) |
| 139 | return true; |
| 140 | |
| 141 | return m_pFS->Flush(m_pFS->clientData) == 0; |
| 142 | } |
| 143 | #endif // PDF_ENABLE_XFA |
| 144 | |
| 145 | } // namespace |
| 146 | |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 147 | IPDF_Page* IPDFPageFromFPDFPage(FPDF_PAGE page) { |
| 148 | return reinterpret_cast<IPDF_Page*>(page); |
Tom Sepez | 3f3c39d | 2018-05-01 17:46:34 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 151 | FPDF_PAGE FPDFPageFromIPDFPage(IPDF_Page* page) { |
Tom Sepez | 3f3c39d | 2018-05-01 17:46:34 +0000 | [diff] [blame] | 152 | return reinterpret_cast<FPDF_PAGE>(page); |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame] | 156 | return reinterpret_cast<CPDF_Document*>(doc); |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame] | 160 | return reinterpret_cast<FPDF_DOCUMENT>(doc); |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 164 | return page ? IPDFPageFromFPDFPage(page)->AsPDFPage() : nullptr; |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 167 | ByteString CFXByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string) { |
| 168 | return WideString::FromUTF16LE(wide_string, |
| 169 | WideString::WStringLength(wide_string)) |
| 170 | .UTF8Encode(); |
| 171 | } |
| 172 | |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 173 | void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot) { |
| 174 | CPDF_Annot::Subtype nAnnotSubtype = pPDFAnnot->GetSubtype(); |
| 175 | if (nAnnotSubtype == CPDF_Annot::Subtype::THREED) { |
| 176 | RaiseUnSupportError(FPDF_UNSP_ANNOT_3DANNOT); |
| 177 | } else if (nAnnotSubtype == CPDF_Annot::Subtype::SCREEN) { |
| 178 | const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict(); |
| 179 | ByteString cbString; |
| 180 | if (pAnnotDict->KeyExist("IT")) |
| 181 | cbString = pAnnotDict->GetStringFor("IT"); |
| 182 | if (cbString.Compare("Img") != 0) |
| 183 | RaiseUnSupportError(FPDF_UNSP_ANNOT_SCREEN_MEDIA); |
| 184 | } else if (nAnnotSubtype == CPDF_Annot::Subtype::MOVIE) { |
| 185 | RaiseUnSupportError(FPDF_UNSP_ANNOT_MOVIE); |
| 186 | } else if (nAnnotSubtype == CPDF_Annot::Subtype::SOUND) { |
| 187 | RaiseUnSupportError(FPDF_UNSP_ANNOT_SOUND); |
| 188 | } else if (nAnnotSubtype == CPDF_Annot::Subtype::RICHMEDIA) { |
| 189 | RaiseUnSupportError(FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA); |
| 190 | } else if (nAnnotSubtype == CPDF_Annot::Subtype::FILEATTACHMENT) { |
| 191 | RaiseUnSupportError(FPDF_UNSP_ANNOT_ATTACHMENT); |
| 192 | } else if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET) { |
| 193 | const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict(); |
| 194 | ByteString cbString; |
| 195 | if (pAnnotDict->KeyExist("FT")) |
| 196 | cbString = pAnnotDict->GetStringFor("FT"); |
| 197 | if (cbString.Compare("Sig") == 0) |
| 198 | RaiseUnSupportError(FPDF_UNSP_ANNOT_SIG); |
| 199 | } |
| 200 | } |
| 201 | |
Tom Sepez | 8128485 | 2018-06-12 19:26:15 +0000 | [diff] [blame] | 202 | void ReportUnsupportedFeatures(CPDF_Document* pDoc) { |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 203 | const CPDF_Dictionary* pRootDict = pDoc->GetRoot(); |
| 204 | if (pRootDict) { |
Tom Sepez | ca027339 | 2018-05-25 23:37:50 +0000 | [diff] [blame] | 205 | // Portfolios and Packages |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 206 | if (pRootDict->KeyExist("Collection")) { |
| 207 | RaiseUnSupportError(FPDF_UNSP_DOC_PORTABLECOLLECTION); |
| 208 | return; |
| 209 | } |
| 210 | if (pRootDict->KeyExist("Names")) { |
Lei Zhang | 5cee3f2 | 2018-05-25 21:48:49 +0000 | [diff] [blame] | 211 | const CPDF_Dictionary* pNameDict = pRootDict->GetDictFor("Names"); |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 212 | if (pNameDict && pNameDict->KeyExist("EmbeddedFiles")) { |
| 213 | RaiseUnSupportError(FPDF_UNSP_DOC_ATTACHMENT); |
| 214 | return; |
| 215 | } |
| 216 | if (pNameDict && pNameDict->KeyExist("JavaScript")) { |
Lei Zhang | 5cee3f2 | 2018-05-25 21:48:49 +0000 | [diff] [blame] | 217 | const CPDF_Dictionary* pJSDict = pNameDict->GetDictFor("JavaScript"); |
| 218 | const CPDF_Array* pArray = |
| 219 | pJSDict ? pJSDict->GetArrayFor("Names") : nullptr; |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 220 | if (pArray) { |
| 221 | for (size_t i = 0; i < pArray->GetCount(); i++) { |
| 222 | ByteString cbStr = pArray->GetStringAt(i); |
| 223 | if (cbStr.Compare("com.adobe.acrobat.SharedReview.Register") == 0) { |
| 224 | RaiseUnSupportError(FPDF_UNSP_DOC_SHAREDREVIEW); |
| 225 | return; |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | } |
Tom Sepez | 8128485 | 2018-06-12 19:26:15 +0000 | [diff] [blame] | 231 | |
Tom Sepez | ca027339 | 2018-05-25 23:37:50 +0000 | [diff] [blame] | 232 | // SharedForm |
| 233 | const CPDF_Stream* pStream = pRootDict->GetStreamFor("Metadata"); |
dan sinclair | e04b66c | 2018-04-13 16:43:05 +0000 | [diff] [blame] | 234 | if (pStream) { |
| 235 | CPDF_Metadata metaData(pStream); |
| 236 | for (const auto& err : metaData.CheckForSharedForm()) |
| 237 | RaiseUnSupportError(static_cast<int>(err)); |
| 238 | } |
| 239 | } |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 240 | |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 241 | // XFA Forms |
Tom Sepez | a3843c9 | 2018-06-12 19:21:46 +0000 | [diff] [blame] | 242 | if (!pDoc->GetExtension() && CPDF_InterForm(pDoc).HasXFAForm()) |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 243 | RaiseUnSupportError(FPDF_UNSP_DOC_XFAFORM); |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | #ifndef _WIN32 |
| 247 | int g_LastError; |
| 248 | void SetLastError(int err) { |
| 249 | g_LastError = err; |
| 250 | } |
| 251 | |
| 252 | int GetLastError() { |
| 253 | return g_LastError; |
| 254 | } |
| 255 | #endif // _WIN32 |
| 256 | |
| 257 | void ProcessParseError(CPDF_Parser::Error err) { |
| 258 | uint32_t err_code = FPDF_ERR_SUCCESS; |
| 259 | // Translate FPDFAPI error code to FPDFVIEW error code |
| 260 | switch (err) { |
| 261 | case CPDF_Parser::SUCCESS: |
| 262 | err_code = FPDF_ERR_SUCCESS; |
| 263 | break; |
| 264 | case CPDF_Parser::FILE_ERROR: |
| 265 | err_code = FPDF_ERR_FILE; |
| 266 | break; |
| 267 | case CPDF_Parser::FORMAT_ERROR: |
| 268 | err_code = FPDF_ERR_FORMAT; |
| 269 | break; |
| 270 | case CPDF_Parser::PASSWORD_ERROR: |
| 271 | err_code = FPDF_ERR_PASSWORD; |
| 272 | break; |
| 273 | case CPDF_Parser::HANDLER_ERROR: |
| 274 | err_code = FPDF_ERR_SECURITY; |
| 275 | break; |
| 276 | } |
| 277 | SetLastError(err_code); |
| 278 | } |
| 279 | |
| 280 | // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS |
| 281 | static uint32_t foxit_sandbox_policy = 0xFFFFFFFF; |
| 282 | |
| 283 | void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) { |
| 284 | switch (policy) { |
| 285 | case FPDF_POLICY_MACHINETIME_ACCESS: { |
| 286 | if (enable) |
| 287 | foxit_sandbox_policy |= 0x01; |
| 288 | else |
| 289 | foxit_sandbox_policy &= 0xFFFFFFFE; |
| 290 | } break; |
| 291 | default: |
| 292 | break; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy) { |
| 297 | switch (policy) { |
| 298 | case FPDF_POLICY_MACHINETIME_ACCESS: |
| 299 | return !!(foxit_sandbox_policy & 0x01); |
| 300 | default: |
| 301 | return false; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | unsigned long DecodeStreamMaybeCopyAndReturnLength(const CPDF_Stream* stream, |
| 306 | void* buffer, |
| 307 | unsigned long buflen) { |
| 308 | ASSERT(stream); |
Artem Strygin | eababa1 | 2018-06-06 12:31:18 +0000 | [diff] [blame] | 309 | auto stream_acc = pdfium::MakeRetain<CPDF_StreamAcc>(stream); |
| 310 | stream_acc->LoadAllDataFiltered(); |
| 311 | const auto stream_data_size = stream_acc->GetSize(); |
| 312 | if (!buffer || buflen < stream_data_size) |
| 313 | return stream_data_size; |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 314 | |
Artem Strygin | eababa1 | 2018-06-06 12:31:18 +0000 | [diff] [blame] | 315 | memcpy(buffer, stream_acc->GetData(), stream_data_size); |
| 316 | return stream_data_size; |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | unsigned long Utf16EncodeMaybeCopyAndReturnLength(const WideString& text, |
| 320 | void* buffer, |
| 321 | unsigned long buflen) { |
| 322 | ByteString encoded_text = text.UTF16LE_Encode(); |
| 323 | unsigned long len = encoded_text.GetLength(); |
| 324 | if (buffer && len <= buflen) |
| 325 | memcpy(buffer, encoded_text.c_str(), len); |
| 326 | return len; |
| 327 | } |
| 328 | |
| 329 | void FSRECTFFromCFXFloatRect(const CFX_FloatRect& rect, FS_RECTF* out_rect) { |
| 330 | out_rect->left = rect.left; |
| 331 | out_rect->top = rect.top; |
| 332 | out_rect->right = rect.right; |
| 333 | out_rect->bottom = rect.bottom; |
| 334 | } |
| 335 | |
| 336 | CFX_FloatRect CFXFloatRectFromFSRECTF(const FS_RECTF& rect) { |
| 337 | return CFX_FloatRect(rect.left, rect.bottom, rect.right, rect.top); |
| 338 | } |
| 339 | |
Lei Zhang | 5cee3f2 | 2018-05-25 21:48:49 +0000 | [diff] [blame] | 340 | const CPDF_Array* GetQuadPointsArrayFromDictionary( |
| 341 | const CPDF_Dictionary* dict) { |
| 342 | return dict ? dict->GetArrayFor("QuadPoints") : nullptr; |
| 343 | } |
| 344 | |
| 345 | CPDF_Array* GetQuadPointsArrayFromDictionary(CPDF_Dictionary* dict) { |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 346 | return dict ? dict->GetArrayFor("QuadPoints") : nullptr; |
| 347 | } |
| 348 | |
Ralf Sippl | 1638179 | 2018-04-12 21:20:26 +0000 | [diff] [blame] | 349 | CPDF_Array* AddQuadPointsArrayToDictionary(CPDF_Dictionary* dict) { |
| 350 | if (!dict) |
| 351 | return nullptr; |
| 352 | return dict->SetNewFor<CPDF_Array>(kQuadPoints); |
| 353 | } |
| 354 | |
| 355 | bool IsValidQuadPointsIndex(const CPDF_Array* array, size_t index) { |
| 356 | return array && index < array->GetCount() / 8; |
| 357 | } |
| 358 | |
| 359 | bool GetQuadPointsAtIndex(const CPDF_Array* array, |
| 360 | size_t quad_index, |
| 361 | FS_QUADPOINTSF* quad_points) { |
| 362 | ASSERT(quad_points); |
| 363 | ASSERT(array); |
| 364 | |
| 365 | if (!IsValidQuadPointsIndex(array, quad_index)) |
| 366 | return false; |
| 367 | |
| 368 | quad_index *= 8; |
| 369 | quad_points->x1 = array->GetNumberAt(quad_index); |
| 370 | quad_points->y1 = array->GetNumberAt(quad_index + 1); |
| 371 | quad_points->x2 = array->GetNumberAt(quad_index + 2); |
| 372 | quad_points->y2 = array->GetNumberAt(quad_index + 3); |
| 373 | quad_points->x3 = array->GetNumberAt(quad_index + 4); |
| 374 | quad_points->y3 = array->GetNumberAt(quad_index + 5); |
| 375 | quad_points->x4 = array->GetNumberAt(quad_index + 6); |
| 376 | quad_points->y4 = array->GetNumberAt(quad_index + 7); |
| 377 | return true; |
| 378 | } |
| 379 | |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 380 | bool GetQuadPointsFromDictionary(CPDF_Dictionary* dict, |
| 381 | size_t quad_index, |
| 382 | FS_QUADPOINTSF* quad_points) { |
| 383 | ASSERT(quad_points); |
| 384 | |
| 385 | const CPDF_Array* pArray = GetQuadPointsArrayFromDictionary(dict); |
| 386 | if (!pArray || quad_index >= pArray->GetCount() / 8) |
| 387 | return false; |
| 388 | |
| 389 | quad_index *= 8; |
| 390 | quad_points->x1 = pArray->GetNumberAt(quad_index); |
| 391 | quad_points->y1 = pArray->GetNumberAt(quad_index + 1); |
| 392 | quad_points->x2 = pArray->GetNumberAt(quad_index + 2); |
| 393 | quad_points->y2 = pArray->GetNumberAt(quad_index + 3); |
| 394 | quad_points->x3 = pArray->GetNumberAt(quad_index + 4); |
| 395 | quad_points->y3 = pArray->GetNumberAt(quad_index + 5); |
| 396 | quad_points->x4 = pArray->GetNumberAt(quad_index + 6); |
| 397 | quad_points->y4 = pArray->GetNumberAt(quad_index + 7); |
| 398 | return true; |
| 399 | } |
| 400 | |
| 401 | #ifdef PDF_ENABLE_XFA |
| 402 | RetainPtr<IFX_SeekableStream> MakeSeekableStream( |
| 403 | FPDF_FILEHANDLER* pFilehandler) { |
| 404 | return pdfium::MakeRetain<FPDF_FileHandlerContext>(pFilehandler); |
| 405 | } |
| 406 | #endif // PDF_ENABLE_XFA |