| 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 "public/fpdfview.h" | 7 #include "public/fpdfview.h" |
| 8 | 8 |
| 9 #ifdef PDF_ENABLE_XFA |
| 9 #include "../include/fpdfxfa/fpdfxfa_app.h" | 10 #include "../include/fpdfxfa/fpdfxfa_app.h" |
| 10 #include "../include/fpdfxfa/fpdfxfa_doc.h" | 11 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 11 #include "../include/fpdfxfa/fpdfxfa_page.h" | 12 #include "../include/fpdfxfa/fpdfxfa_page.h" |
| 12 #include "../include/fpdfxfa/fpdfxfa_util.h" | 13 #include "../include/fpdfxfa/fpdfxfa_util.h" |
| 13 #include "core/include/fpdfapi/fpdf_module.h" | 14 #include "core/include/fpdfapi/fpdf_module.h" |
| 15 #endif |
| 14 #include "core/include/fxcodec/fx_codec.h" | 16 #include "core/include/fxcodec/fx_codec.h" |
| 15 #include "core/include/fxcrt/fx_safe_types.h" | 17 #include "core/include/fxcrt/fx_safe_types.h" |
| 16 #include "fpdfsdk/include/fsdk_define.h" | 18 #include "fpdfsdk/include/fsdk_define.h" |
| 17 #include "fpdfsdk/include/fsdk_mgr.h" | 19 #include "fpdfsdk/include/fsdk_mgr.h" |
| 18 #include "fpdfsdk/include/fsdk_rendercontext.h" | 20 #include "fpdfsdk/include/fsdk_rendercontext.h" |
| 19 #include "fpdfsdk/include/javascript/IJavaScript.h" | 21 #include "fpdfsdk/include/javascript/IJavaScript.h" |
| 20 #include "public/fpdf_ext.h" | 22 #include "public/fpdf_ext.h" |
| 23 #ifdef PDF_ENABLE_XFA |
| 21 #include "public/fpdf_formfill.h" | 24 #include "public/fpdf_formfill.h" |
| 25 #endif |
| 22 #include "public/fpdf_progressive.h" | 26 #include "public/fpdf_progressive.h" |
| 23 #include "third_party/base/nonstd_unique_ptr.h" | 27 #include "third_party/base/nonstd_unique_ptr.h" |
| 24 #include "third_party/base/numerics/safe_conversions_impl.h" | 28 #include "third_party/base/numerics/safe_conversions_impl.h" |
| 25 | 29 |
| 26 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { | 30 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { |
| 27 return static_cast<UnderlyingDocumentType*>(doc); | 31 return static_cast<UnderlyingDocumentType*>(doc); |
| 28 } | 32 } |
| 29 | 33 |
| 30 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { | 34 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { |
| 31 return static_cast<FPDF_DOCUMENT>(doc); | 35 return static_cast<FPDF_DOCUMENT>(doc); |
| 32 } | 36 } |
| 33 | 37 |
| 34 UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) { | 38 UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) { |
| 35 return static_cast<UnderlyingPageType*>(page); | 39 return static_cast<UnderlyingPageType*>(page); |
| 36 } | 40 } |
| 37 | 41 |
| 38 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { | 42 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { |
| 43 #ifndef PDF_ENABLE_XFA |
| 44 return UnderlyingFromFPDFDocument(doc); |
| 45 #else |
| 39 return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr; | 46 return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr; |
| 47 #endif |
| 40 } | 48 } |
| 41 | 49 |
| 42 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { | 50 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { |
| 51 #ifndef PDF_ENABLE_XFA |
| 52 return FPDFDocumentFromUnderlying(doc); |
| 53 #else |
| 43 return doc ? FPDFDocumentFromUnderlying( | 54 return doc ? FPDFDocumentFromUnderlying( |
| 44 new CPDFXFA_Document(doc, CPDFXFA_App::GetInstance())) | 55 new CPDFXFA_Document(doc, CPDFXFA_App::GetInstance())) |
| 45 : nullptr; | 56 : nullptr; |
| 57 #endif |
| 46 } | 58 } |
| 47 | 59 |
| 48 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { | 60 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { |
| 61 #ifndef PDF_ENABLE_XFA |
| 62 return UnderlyingFromFPDFPage(page); |
| 63 #else |
| 49 return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; | 64 return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; |
| 50 } | 65 } |
| 51 | 66 |
| 52 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { | 67 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { |
| 53 m_pFS = pFS; | 68 m_pFS = pFS; |
| 54 m_nCurPos = 0; | 69 m_nCurPos = 0; |
| 55 } | 70 } |
| 56 | 71 |
| 57 IFX_FileStream* CFPDF_FileStream::Retain() { | 72 IFX_FileStream* CFPDF_FileStream::Retain() { |
| 58 return this; | 73 return this; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 return TRUE; | 134 return TRUE; |
| 120 } | 135 } |
| 121 return FALSE; | 136 return FALSE; |
| 122 } | 137 } |
| 123 | 138 |
| 124 FX_BOOL CFPDF_FileStream::Flush() { | 139 FX_BOOL CFPDF_FileStream::Flush() { |
| 125 if (!m_pFS || !m_pFS->Flush) | 140 if (!m_pFS || !m_pFS->Flush) |
| 126 return TRUE; | 141 return TRUE; |
| 127 | 142 |
| 128 return m_pFS->Flush(m_pFS->clientData) == 0; | 143 return m_pFS->Flush(m_pFS->clientData) == 0; |
| 144 #endif |
| 129 } | 145 } |
| 130 | 146 |
| 131 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { | 147 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { |
| 132 m_FileAccess = *pFileAccess; | 148 m_FileAccess = *pFileAccess; |
| 149 #ifdef PDF_ENABLE_XFA |
| 133 m_BufferOffset = (FX_DWORD)-1; | 150 m_BufferOffset = (FX_DWORD)-1; |
| 134 } | 151 } |
| 135 | 152 |
| 136 FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, uint8_t& ch) { | 153 FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, uint8_t& ch) { |
| 137 if (pos >= m_FileAccess.m_FileLen) | 154 if (pos >= m_FileAccess.m_FileLen) |
| 138 return FALSE; | 155 return FALSE; |
| 139 if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || | 156 if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || |
| 140 pos >= m_BufferOffset + 512) { | 157 pos >= m_BufferOffset + 512) { |
| 141 // Need to read from file access | 158 // Need to read from file access |
| 142 m_BufferOffset = pos; | 159 m_BufferOffset = pos; |
| 143 int size = 512; | 160 int size = 512; |
| 144 if (pos + 512 > m_FileAccess.m_FileLen) | 161 if (pos + 512 > m_FileAccess.m_FileLen) |
| 145 size = m_FileAccess.m_FileLen - pos; | 162 size = m_FileAccess.m_FileLen - pos; |
| 146 if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffset, m_Buffer, | 163 if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffset, m_Buffer, |
| 147 size)) | 164 size)) |
| 148 return FALSE; | 165 return FALSE; |
| 149 } | 166 } |
| 150 ch = m_Buffer[pos - m_BufferOffset]; | 167 ch = m_Buffer[pos - m_BufferOffset]; |
| 151 return TRUE; | 168 return TRUE; |
| 152 } | 169 } |
| 153 | 170 |
| 154 FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos, | 171 FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos, |
| 155 uint8_t* pBuf, | 172 uint8_t* pBuf, |
| 156 FX_DWORD size) { | 173 FX_DWORD size) { |
| 157 if (pos + size > m_FileAccess.m_FileLen) | 174 if (pos + size > m_FileAccess.m_FileLen) |
| 158 return FALSE; | 175 return FALSE; |
| 159 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size); | 176 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size); |
| 177 #endif |
| 160 } | 178 } |
| 161 | 179 |
| 162 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, | 180 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, |
| 163 FX_FILESIZE offset, | 181 FX_FILESIZE offset, |
| 164 size_t size) { | 182 size_t size) { |
| 165 if (offset < 0) { | 183 if (offset < 0) { |
| 166 return FALSE; | 184 return FALSE; |
| 167 } | 185 } |
| 168 FX_SAFE_FILESIZE newPos = | 186 FX_SAFE_FILESIZE newPos = |
| 169 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); | 187 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 g_pCodecModule = new CCodec_ModuleMgr(); | 229 g_pCodecModule = new CCodec_ModuleMgr(); |
| 212 | 230 |
| 213 CFX_GEModule::Create(cfg ? cfg->m_pUserFontPaths : nullptr); | 231 CFX_GEModule::Create(cfg ? cfg->m_pUserFontPaths : nullptr); |
| 214 CFX_GEModule::Get()->SetCodecModule(g_pCodecModule); | 232 CFX_GEModule::Get()->SetCodecModule(g_pCodecModule); |
| 215 | 233 |
| 216 CPDF_ModuleMgr::Create(); | 234 CPDF_ModuleMgr::Create(); |
| 217 CPDF_ModuleMgr* pModuleMgr = CPDF_ModuleMgr::Get(); | 235 CPDF_ModuleMgr* pModuleMgr = CPDF_ModuleMgr::Get(); |
| 218 pModuleMgr->SetCodecModule(g_pCodecModule); | 236 pModuleMgr->SetCodecModule(g_pCodecModule); |
| 219 pModuleMgr->InitPageModule(); | 237 pModuleMgr->InitPageModule(); |
| 220 pModuleMgr->InitRenderModule(); | 238 pModuleMgr->InitRenderModule(); |
| 239 #ifndef PDF_ENABLE_XFA |
| 240 pModuleMgr->LoadEmbeddedGB1CMaps(); |
| 241 pModuleMgr->LoadEmbeddedJapan1CMaps(); |
| 242 pModuleMgr->LoadEmbeddedCNS1CMaps(); |
| 243 pModuleMgr->LoadEmbeddedKorea1CMaps(); |
| 244 #else |
| 221 CPDFXFA_App::GetInstance()->Initialize(); | 245 CPDFXFA_App::GetInstance()->Initialize(); |
| 246 #endif |
| 222 if (cfg && cfg->version >= 2) | 247 if (cfg && cfg->version >= 2) |
| 223 IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate); | 248 IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate); |
| 224 } | 249 } |
| 225 | 250 |
| 226 DLLEXPORT void STDCALL FPDF_DestroyLibrary() { | 251 DLLEXPORT void STDCALL FPDF_DestroyLibrary() { |
| 252 #ifdef PDF_ENABLE_XFA |
| 227 CPDFXFA_App::ReleaseInstance(); | 253 CPDFXFA_App::ReleaseInstance(); |
| 254 #endif |
| 228 CPDF_ModuleMgr::Destroy(); | 255 CPDF_ModuleMgr::Destroy(); |
| 229 CFX_GEModule::Destroy(); | 256 CFX_GEModule::Destroy(); |
| 230 | 257 |
| 231 delete g_pCodecModule; | 258 delete g_pCodecModule; |
| 232 g_pCodecModule = nullptr; | 259 g_pCodecModule = nullptr; |
| 233 } | 260 } |
| 234 | 261 |
| 235 #ifndef _WIN32 | 262 #ifndef _WIN32 |
| 236 int g_LastError; | 263 int g_LastError; |
| 237 void SetLastError(int err) { | 264 void SetLastError(int err) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 305 |
| 279 CPDF_Parser* pParser = new CPDF_Parser; | 306 CPDF_Parser* pParser = new CPDF_Parser; |
| 280 pParser->SetPassword(password); | 307 pParser->SetPassword(password); |
| 281 | 308 |
| 282 FX_DWORD err_code = pParser->StartParse(pFileAccess); | 309 FX_DWORD err_code = pParser->StartParse(pFileAccess); |
| 283 if (err_code) { | 310 if (err_code) { |
| 284 delete pParser; | 311 delete pParser; |
| 285 ProcessParseError(err_code); | 312 ProcessParseError(err_code); |
| 286 return NULL; | 313 return NULL; |
| 287 } | 314 } |
| 315 #ifndef PDF_ENABLE_XFA |
| 316 return pParser->GetDocument(); |
| 317 #else |
| 288 CPDF_Document* pPDFDoc = pParser->GetDocument(); | 318 CPDF_Document* pPDFDoc = pParser->GetDocument(); |
| 289 if (!pPDFDoc) | 319 if (!pPDFDoc) |
| 290 return NULL; | 320 return NULL; |
| 291 | 321 |
| 292 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); | 322 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
| 293 return new CPDFXFA_Document(pPDFDoc, pProvider); | 323 return new CPDFXFA_Document(pPDFDoc, pProvider); |
| 294 } | 324 } |
| 295 | 325 |
| 296 DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, | 326 DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, |
| 297 int* docType) { | 327 int* docType) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 320 if (bDynamicXFA) | 350 if (bDynamicXFA) |
| 321 *docType = DOCTYPE_DYNAMIC_XFA; | 351 *docType = DOCTYPE_DYNAMIC_XFA; |
| 322 else | 352 else |
| 323 *docType = DOCTYPE_STATIC_XFA; | 353 *docType = DOCTYPE_STATIC_XFA; |
| 324 | 354 |
| 325 return TRUE; | 355 return TRUE; |
| 326 } | 356 } |
| 327 | 357 |
| 328 DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) { | 358 DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) { |
| 329 return document && (static_cast<CPDFXFA_Document*>(document))->LoadXFADoc(); | 359 return document && (static_cast<CPDFXFA_Document*>(document))->LoadXFADoc(); |
| 360 #endif |
| 330 } | 361 } |
| 331 | 362 |
| 332 class CMemFile final : public IFX_FileRead { | 363 class CMemFile final : public IFX_FileRead { |
| 333 public: | 364 public: |
| 334 CMemFile(uint8_t* pBuf, FX_FILESIZE size) : m_pBuf(pBuf), m_size(size) {} | 365 CMemFile(uint8_t* pBuf, FX_FILESIZE size) : m_pBuf(pBuf), m_size(size) {} |
| 335 | 366 |
| 336 void Release() override { delete this; } | 367 void Release() override { delete this; } |
| 337 FX_FILESIZE GetSize() override { return m_size; } | 368 FX_FILESIZE GetSize() override { return m_size; } |
| 338 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { | 369 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { |
| 339 if (offset < 0) { | 370 if (offset < 0) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 | 439 |
| 409 *fileVersion = pParser->GetFileVersion(); | 440 *fileVersion = pParser->GetFileVersion(); |
| 410 return TRUE; | 441 return TRUE; |
| 411 } | 442 } |
| 412 | 443 |
| 413 // jabdelmalek: changed return type from FX_DWORD to build on Linux (and match | 444 // jabdelmalek: changed return type from FX_DWORD to build on Linux (and match |
| 414 // header). | 445 // header). |
| 415 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) { | 446 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) { |
| 416 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 447 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 417 if (!pDoc) | 448 if (!pDoc) |
| 449 #ifndef PDF_ENABLE_XFA |
| 450 return 0; |
| 451 #else |
| 418 return (FX_DWORD)-1; | 452 return (FX_DWORD)-1; |
| 453 #endif |
| 419 | 454 |
| 420 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); | 455 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); |
| 421 return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1; | 456 return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1; |
| 422 } | 457 } |
| 423 | 458 |
| 424 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { | 459 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { |
| 425 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 460 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 426 if (!pDoc) | 461 if (!pDoc) |
| 427 return -1; | 462 return -1; |
| 428 | 463 |
| 429 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); | 464 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); |
| 430 return pDict ? pDict->GetInteger("R") : -1; | 465 return pDict ? pDict->GetInteger("R") : -1; |
| 431 } | 466 } |
| 432 | 467 |
| 433 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) { | 468 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) { |
| 434 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); | 469 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); |
| 435 return pDoc ? pDoc->GetPageCount() : 0; | 470 return pDoc ? pDoc->GetPageCount() : 0; |
| 436 } | 471 } |
| 437 | 472 |
| 438 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, | 473 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, |
| 439 int page_index) { | 474 int page_index) { |
| 440 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); | 475 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); |
| 441 if (!pDoc) | 476 if (!pDoc) |
| 442 return nullptr; | 477 return nullptr; |
| 443 | 478 |
| 444 if (page_index < 0 || page_index >= pDoc->GetPageCount()) | 479 if (page_index < 0 || page_index >= pDoc->GetPageCount()) |
| 445 return nullptr; | 480 return nullptr; |
| 446 | 481 |
| 482 #ifndef PDF_ENABLE_XFA |
| 483 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); |
| 484 if (pDict == NULL) |
| 485 return NULL; |
| 486 CPDF_Page* pPage = new CPDF_Page; |
| 487 pPage->Load(pDoc, pDict); |
| 488 pPage->ParseContent(); |
| 489 return pPage; |
| 490 #else |
| 447 return pDoc->GetPage(page_index); | 491 return pDoc->GetPage(page_index); |
| 492 #endif |
| 448 } | 493 } |
| 449 | 494 |
| 450 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { | 495 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { |
| 451 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 496 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 452 return pPage ? pPage->GetPageWidth() : 0.0; | 497 return pPage ? pPage->GetPageWidth() : 0.0; |
| 453 } | 498 } |
| 454 | 499 |
| 455 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { | 500 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { |
| 456 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 501 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 457 return pPage ? pPage->GetPageHeight() : 0.0; | 502 return pPage ? pPage->GetPageHeight() : 0.0; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, | 707 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
| 663 rotate, flags, TRUE, NULL); | 708 rotate, flags, TRUE, NULL); |
| 664 | 709 |
| 665 delete pContext; | 710 delete pContext; |
| 666 pPage->RemovePrivateData((void*)1); | 711 pPage->RemovePrivateData((void*)1); |
| 667 } | 712 } |
| 668 | 713 |
| 669 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) { | 714 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) { |
| 670 if (!page) | 715 if (!page) |
| 671 return; | 716 return; |
| 717 #ifndef PDF_ENABLE_XFA |
| 718 CPDFSDK_PageView* pPageView = |
| 719 (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((void*)page); |
| 720 if (pPageView && pPageView->IsLocked()) { |
| 721 pPageView->TakeOverPage(); |
| 722 return; |
| 723 } |
| 724 delete (CPDF_Page*)page; |
| 725 #else |
| 672 | 726 |
| 673 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; | 727 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; |
| 674 pPage->Release(); | 728 pPage->Release(); |
| 729 #endif |
| 675 } | 730 } |
| 676 | 731 |
| 677 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { | 732 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { |
| 733 #ifndef PDF_ENABLE_XFA |
| 734 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 735 if (!pDoc) |
| 736 return; |
| 737 |
| 738 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); |
| 739 if (!pParser) { |
| 740 delete pDoc; |
| 741 return; |
| 742 } |
| 743 delete pParser; |
| 744 #else |
| 678 delete CPDFDocumentFromFPDFDocument(document); | 745 delete CPDFDocumentFromFPDFDocument(document); |
| 746 #endif |
| 679 } | 747 } |
| 680 | 748 |
| 681 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() { | 749 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() { |
| 682 return GetLastError(); | 750 return GetLastError(); |
| 683 } | 751 } |
| 684 | 752 |
| 685 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, | 753 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, |
| 686 int start_x, | 754 int start_x, |
| 687 int start_y, | 755 int start_y, |
| 688 int size_x, | 756 int size_x, |
| 689 int size_y, | 757 int size_y, |
| 690 int rotate, | 758 int rotate, |
| 691 int device_x, | 759 int device_x, |
| 692 int device_y, | 760 int device_y, |
| 693 double* page_x, | 761 double* page_x, |
| 694 double* page_y) { | 762 double* page_y) { |
| 695 if (page == NULL || page_x == NULL || page_y == NULL) | 763 if (page == NULL || page_x == NULL || page_y == NULL) |
| 696 return; | 764 return; |
| 697 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 765 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 766 #ifndef PDF_ENABLE_XFA |
| 767 |
| 768 CPDF_Matrix page2device; |
| 769 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, |
| 770 rotate); |
| 771 CPDF_Matrix device2page; |
| 772 device2page.SetReverse(page2device); |
| 773 |
| 774 FX_FLOAT page_x_f, page_y_f; |
| 775 device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x_f, |
| 776 page_y_f); |
| 777 |
| 778 *page_x = (page_x_f); |
| 779 *page_y = (page_y_f); |
| 780 #else |
| 698 pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x, | 781 pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x, |
| 699 device_y, page_x, page_y); | 782 device_y, page_x, page_y); |
| 783 #endif |
| 700 } | 784 } |
| 701 | 785 |
| 702 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, | 786 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, |
| 703 int start_x, | 787 int start_x, |
| 704 int start_y, | 788 int start_y, |
| 705 int size_x, | 789 int size_x, |
| 706 int size_y, | 790 int size_y, |
| 707 int rotate, | 791 int rotate, |
| 708 double page_x, | 792 double page_x, |
| 709 double page_y, | 793 double page_y, |
| 710 int* device_x, | 794 int* device_x, |
| 711 int* device_y) { | 795 int* device_y) { |
| 712 if (!device_x || !device_y) | 796 if (!device_x || !device_y) |
| 713 return; | 797 return; |
| 714 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 798 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 715 if (!pPage) | 799 if (!pPage) |
| 716 return; | 800 return; |
| 801 #ifndef PDF_ENABLE_XFA |
| 802 CPDF_Matrix page2device; |
| 803 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, |
| 804 rotate); |
| 805 |
| 806 FX_FLOAT device_x_f, device_y_f; |
| 807 page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f, |
| 808 device_y_f); |
| 809 |
| 810 *device_x = FXSYS_round(device_x_f); |
| 811 *device_y = FXSYS_round(device_y_f); |
| 812 #else |
| 717 pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y, | 813 pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y, |
| 718 device_x, device_y); | 814 device_x, device_y); |
| 815 #endif |
| 719 } | 816 } |
| 720 | 817 |
| 721 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, | 818 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, |
| 722 int height, | 819 int height, |
| 723 int alpha) { | 820 int alpha) { |
| 724 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); | 821 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); |
| 725 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) { | 822 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) { |
| 726 return NULL; | 823 return NULL; |
| 727 } | 824 } |
| 728 return pBitmap.release(); | 825 return pBitmap.release(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 if (flags & FPDF_LCD_TEXT) | 920 if (flags & FPDF_LCD_TEXT) |
| 824 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; | 921 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; |
| 825 else | 922 else |
| 826 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; | 923 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; |
| 827 if (flags & FPDF_NO_NATIVETEXT) | 924 if (flags & FPDF_NO_NATIVETEXT) |
| 828 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT; | 925 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT; |
| 829 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE) | 926 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE) |
| 830 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE; | 927 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE; |
| 831 if (flags & FPDF_RENDER_FORCEHALFTONE) | 928 if (flags & FPDF_RENDER_FORCEHALFTONE) |
| 832 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE; | 929 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE; |
| 930 #ifndef PDF_ENABLE_XFA |
| 931 if (flags & FPDF_RENDER_NO_SMOOTHTEXT) |
| 932 pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH; |
| 933 if (flags & FPDF_RENDER_NO_SMOOTHIMAGE) |
| 934 pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH; |
| 935 if (flags & FPDF_RENDER_NO_SMOOTHPATH) |
| 936 pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH; |
| 937 #endif |
| 833 // Grayscale output | 938 // Grayscale output |
| 834 if (flags & FPDF_GRAYSCALE) { | 939 if (flags & FPDF_GRAYSCALE) { |
| 835 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; | 940 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; |
| 836 pContext->m_pOptions->m_ForeColor = 0; | 941 pContext->m_pOptions->m_ForeColor = 0; |
| 837 pContext->m_pOptions->m_BackColor = 0xffffff; | 942 pContext->m_pOptions->m_BackColor = 0xffffff; |
| 838 } | 943 } |
| 839 const CPDF_OCContext::UsageType usage = | 944 const CPDF_OCContext::UsageType usage = |
| 840 (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View; | 945 (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View; |
| 841 pContext->m_pOptions->m_AddFlags = flags >> 8; | 946 pContext->m_pOptions->m_AddFlags = flags >> 8; |
| 842 pContext->m_pOptions->m_pOCContext = | 947 pContext->m_pOptions->m_pOCContext = |
| (...skipping 29 matching lines...) Expand all Loading... |
| 872 } | 977 } |
| 873 | 978 |
| 874 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, | 979 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, |
| 875 int page_index, | 980 int page_index, |
| 876 double* width, | 981 double* width, |
| 877 double* height) { | 982 double* height) { |
| 878 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); | 983 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); |
| 879 if (!pDoc) | 984 if (!pDoc) |
| 880 return FALSE; | 985 return FALSE; |
| 881 | 986 |
| 987 #ifndef PDF_ENABLE_XFA |
| 988 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); |
| 989 if (!pDict) |
| 990 #else |
| 882 int count = pDoc->GetPageCount(); | 991 int count = pDoc->GetPageCount(); |
| 883 if (page_index < 0 || page_index >= count) | 992 if (page_index < 0 || page_index >= count) |
| 884 return FALSE; | 993 return FALSE; |
| 885 | 994 |
| 886 CPDFXFA_Page* pPage = pDoc->GetPage(page_index); | 995 CPDFXFA_Page* pPage = pDoc->GetPage(page_index); |
| 887 if (!pPage) | 996 if (!pPage) |
| 997 #endif |
| 888 return FALSE; | 998 return FALSE; |
| 889 | 999 |
| 1000 #ifndef PDF_ENABLE_XFA |
| 1001 CPDF_Page page; |
| 1002 page.Load(pDoc, pDict); |
| 1003 *width = page.GetPageWidth(); |
| 1004 *height = page.GetPageHeight(); |
| 1005 #else |
| 890 *width = pPage->GetPageWidth(); | 1006 *width = pPage->GetPageWidth(); |
| 891 *height = pPage->GetPageHeight(); | 1007 *height = pPage->GetPageHeight(); |
| 1008 #endif |
| 892 | 1009 |
| 893 return TRUE; | 1010 return TRUE; |
| 894 } | 1011 } |
| 895 | 1012 |
| 896 DLLEXPORT FPDF_BOOL STDCALL | 1013 DLLEXPORT FPDF_BOOL STDCALL |
| 897 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) { | 1014 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) { |
| 898 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 1015 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 899 if (!pDoc) | 1016 if (!pDoc) |
| 900 return TRUE; | 1017 return TRUE; |
| 901 CPDF_ViewerPreferences viewRef(pDoc); | 1018 CPDF_ViewerPreferences viewRef(pDoc); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 return nullptr; | 1075 return nullptr; |
| 959 | 1076 |
| 960 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 1077 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 961 if (!pDoc) | 1078 if (!pDoc) |
| 962 return nullptr; | 1079 return nullptr; |
| 963 | 1080 |
| 964 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); | 1081 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); |
| 965 return name_tree.LookupNamedDest(pDoc, name); | 1082 return name_tree.LookupNamedDest(pDoc, name); |
| 966 } | 1083 } |
| 967 | 1084 |
| 1085 #ifdef PDF_ENABLE_XFA |
| 968 FPDF_RESULT FPDF_BStr_Init(FPDF_BSTR* str) { | 1086 FPDF_RESULT FPDF_BStr_Init(FPDF_BSTR* str) { |
| 969 if (!str) | 1087 if (!str) |
| 970 return -1; | 1088 return -1; |
| 971 | 1089 |
| 972 FXSYS_memset(str, 0, sizeof(FPDF_BSTR)); | 1090 FXSYS_memset(str, 0, sizeof(FPDF_BSTR)); |
| 973 return 0; | 1091 return 0; |
| 974 } | 1092 } |
| 975 | 1093 |
| 976 FPDF_RESULT FPDF_BStr_Set(FPDF_BSTR* str, FPDF_LPCSTR bstr, int length) { | 1094 FPDF_RESULT FPDF_BStr_Set(FPDF_BSTR* str, FPDF_LPCSTR bstr, int length) { |
| 977 if (!str) | 1095 if (!str) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 return -1; | 1128 return -1; |
| 1011 | 1129 |
| 1012 if (str->str) { | 1130 if (str->str) { |
| 1013 FX_Free(str->str); | 1131 FX_Free(str->str); |
| 1014 str->str = NULL; | 1132 str->str = NULL; |
| 1015 } | 1133 } |
| 1016 str->len = 0; | 1134 str->len = 0; |
| 1017 return 0; | 1135 return 0; |
| 1018 } | 1136 } |
| 1019 | 1137 |
| 1138 #endif |
| 1020 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, | 1139 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, |
| 1021 int index, | 1140 int index, |
| 1022 void* buffer, | 1141 void* buffer, |
| 1023 long* buflen) { | 1142 long* buflen) { |
| 1024 if (!buffer) | 1143 if (!buffer) |
| 1025 *buflen = 0; | 1144 *buflen = 0; |
| 1026 | 1145 |
| 1027 if (index < 0) | 1146 if (index < 0) |
| 1028 return nullptr; | 1147 return nullptr; |
| 1029 | 1148 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 if (!buffer) { | 1194 if (!buffer) { |
| 1076 *buflen = len; | 1195 *buflen = len; |
| 1077 } else if (*buflen >= len) { | 1196 } else if (*buflen >= len) { |
| 1078 memcpy(buffer, utf16Name.c_str(), len); | 1197 memcpy(buffer, utf16Name.c_str(), len); |
| 1079 *buflen = len; | 1198 *buflen = len; |
| 1080 } else { | 1199 } else { |
| 1081 *buflen = -1; | 1200 *buflen = -1; |
| 1082 } | 1201 } |
| 1083 return (FPDF_DEST)pDestObj; | 1202 return (FPDF_DEST)pDestObj; |
| 1084 } | 1203 } |
| OLD | NEW |