Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: fpdfsdk/src/fpdfview.cpp

Issue 1477583002: Inflict PDF_ENABLE_XFA ifdefs on XFA fpdfsdk/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
Lei Zhang 2015/11/25 00:34:30 #endif here, and another #if PDF_ENABLE_XFA for CF
Tom Sepez 2015/11/25 21:45:30 Yup, manual cleanup to follow. diff is too good a
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;
59 } 74 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 const FPDF_LIBRARY_CONFIG* cfg) { 228 const FPDF_LIBRARY_CONFIG* cfg) {
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::Get()->SetCodecModule(g_pCodecModule); 235 CPDF_ModuleMgr::Get()->SetCodecModule(g_pCodecModule);
218 CPDF_ModuleMgr::Get()->InitPageModule(); 236 CPDF_ModuleMgr::Get()->InitPageModule();
219 CPDF_ModuleMgr::Get()->InitRenderModule(); 237 CPDF_ModuleMgr::Get()->InitRenderModule();
238 #ifndef PDF_ENABLE_XFA
239 CPDF_ModuleMgr* pModuleMgr = CPDF_ModuleMgr::Get();
240 if (pModuleMgr) {
Lei Zhang 2015/11/25 00:34:30 Always true, given the lines above.
Tom Sepez 2015/11/25 21:45:30 Done.
241 pModuleMgr->LoadEmbeddedGB1CMaps();
242 pModuleMgr->LoadEmbeddedJapan1CMaps();
243 pModuleMgr->LoadEmbeddedCNS1CMaps();
244 pModuleMgr->LoadEmbeddedKorea1CMaps();
245 }
246 #else
220 CPDFXFA_App::GetInstance()->Initialize(); 247 CPDFXFA_App::GetInstance()->Initialize();
248 #endif
221 if (cfg && cfg->version >= 2) 249 if (cfg && cfg->version >= 2)
222 IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate); 250 IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate);
223 } 251 }
224 252
225 DLLEXPORT void STDCALL FPDF_DestroyLibrary() { 253 DLLEXPORT void STDCALL FPDF_DestroyLibrary() {
254 #ifdef PDF_ENABLE_XFA
226 CPDFXFA_App::ReleaseInstance(); 255 CPDFXFA_App::ReleaseInstance();
256 #endif
227 CPDF_ModuleMgr::Destroy(); 257 CPDF_ModuleMgr::Destroy();
228 CFX_GEModule::Destroy(); 258 CFX_GEModule::Destroy();
229 259
230 delete g_pCodecModule; 260 delete g_pCodecModule;
231 g_pCodecModule = nullptr; 261 g_pCodecModule = nullptr;
232 } 262 }
233 263
234 #ifndef _WIN32 264 #ifndef _WIN32
235 int g_LastError; 265 int g_LastError;
236 void SetLastError(int err) { 266 void SetLastError(int err) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 307
278 CPDF_Parser* pParser = new CPDF_Parser; 308 CPDF_Parser* pParser = new CPDF_Parser;
279 pParser->SetPassword(password); 309 pParser->SetPassword(password);
280 310
281 FX_DWORD err_code = pParser->StartParse(pFileAccess); 311 FX_DWORD err_code = pParser->StartParse(pFileAccess);
282 if (err_code) { 312 if (err_code) {
283 delete pParser; 313 delete pParser;
284 ProcessParseError(err_code); 314 ProcessParseError(err_code);
285 return NULL; 315 return NULL;
286 } 316 }
317 #ifndef PDF_ENABLE_XFA
318 return pParser->GetDocument();
319 #else
287 CPDF_Document* pPDFDoc = pParser->GetDocument(); 320 CPDF_Document* pPDFDoc = pParser->GetDocument();
288 if (!pPDFDoc) 321 if (!pPDFDoc)
289 return NULL; 322 return NULL;
290 323
291 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); 324 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
292 return new CPDFXFA_Document(pPDFDoc, pProvider); 325 return new CPDFXFA_Document(pPDFDoc, pProvider);
293 } 326 }
294 327
295 DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, 328 DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document,
296 int* docType) { 329 int* docType) {
(...skipping 22 matching lines...) Expand all
319 if (bDynamicXFA) 352 if (bDynamicXFA)
320 *docType = DOCTYPE_DYNIMIC_XFA; 353 *docType = DOCTYPE_DYNIMIC_XFA;
321 else 354 else
322 *docType = DOCTYPE_STATIC_XFA; 355 *docType = DOCTYPE_STATIC_XFA;
323 356
324 return TRUE; 357 return TRUE;
325 } 358 }
326 359
327 DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) { 360 DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) {
328 return document && (static_cast<CPDFXFA_Document*>(document))->LoadXFADoc(); 361 return document && (static_cast<CPDFXFA_Document*>(document))->LoadXFADoc();
362 #endif
329 } 363 }
330 364
331 class CMemFile final : public IFX_FileRead { 365 class CMemFile final : public IFX_FileRead {
332 public: 366 public:
333 CMemFile(uint8_t* pBuf, FX_FILESIZE size) : m_pBuf(pBuf), m_size(size) {} 367 CMemFile(uint8_t* pBuf, FX_FILESIZE size) : m_pBuf(pBuf), m_size(size) {}
334 368
335 void Release() override { delete this; } 369 void Release() override { delete this; }
336 FX_FILESIZE GetSize() override { return m_size; } 370 FX_FILESIZE GetSize() override { return m_size; }
337 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { 371 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
338 if (offset < 0) { 372 if (offset < 0) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 441
408 *fileVersion = pParser->GetFileVersion(); 442 *fileVersion = pParser->GetFileVersion();
409 return TRUE; 443 return TRUE;
410 } 444 }
411 445
412 // jabdelmalek: changed return type from FX_DWORD to build on Linux (and match 446 // jabdelmalek: changed return type from FX_DWORD to build on Linux (and match
413 // header). 447 // header).
414 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) { 448 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) {
415 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 449 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
416 if (!pDoc) 450 if (!pDoc)
451 #ifndef PDF_ENABLE_XFA
452 return 0;
Lei Zhang 2015/11/25 00:34:30 This is a weird discrepancy.
Tom Sepez 2015/11/25 21:45:30 Sure is. It looks like its been this way since be
453 #else
417 return (FX_DWORD)-1; 454 return (FX_DWORD)-1;
455 #endif
418 456
419 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); 457 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict();
420 return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1; 458 return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1;
421 } 459 }
422 460
423 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { 461 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) {
424 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 462 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
425 if (!pDoc) 463 if (!pDoc)
426 return -1; 464 return -1;
427 465
428 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); 466 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict();
429 return pDict ? pDict->GetInteger("R") : -1; 467 return pDict ? pDict->GetInteger("R") : -1;
430 } 468 }
431 469
432 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) { 470 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) {
433 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); 471 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document);
434 return pDoc ? pDoc->GetPageCount() : 0; 472 return pDoc ? pDoc->GetPageCount() : 0;
435 } 473 }
436 474
437 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, 475 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document,
438 int page_index) { 476 int page_index) {
439 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); 477 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document);
440 if (!pDoc) 478 if (!pDoc)
441 return nullptr; 479 return nullptr;
480 #ifndef PDF_ENABLE_XFA
481
Lei Zhang 2015/11/25 00:34:30 blank
Tom Sepez 2015/11/25 21:45:30 Done.
482 #endif
442 if (page_index < 0 || page_index >= pDoc->GetPageCount()) 483 if (page_index < 0 || page_index >= pDoc->GetPageCount())
443 return nullptr; 484 return nullptr;
444 485
486 #ifndef PDF_ENABLE_XFA
487 CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
488 if (pDict == NULL)
489 return NULL;
490 CPDF_Page* pPage = new CPDF_Page;
491 pPage->Load(pDoc, pDict);
492 pPage->ParseContent();
493 return pPage;
494 #else
445 return pDoc->GetPage(page_index); 495 return pDoc->GetPage(page_index);
496 #endif
446 } 497 }
447 498
448 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { 499 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) {
449 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); 500 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
450 return pPage ? pPage->GetPageWidth() : 0.0; 501 return pPage ? pPage->GetPageWidth() : 0.0;
451 } 502 }
452 503
453 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { 504 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) {
454 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); 505 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
455 return pPage ? pPage->GetPageHeight() : 0.0; 506 return pPage ? pPage->GetPageHeight() : 0.0;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, 711 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
661 rotate, flags, TRUE, NULL); 712 rotate, flags, TRUE, NULL);
662 713
663 delete pContext; 714 delete pContext;
664 pPage->RemovePrivateData((void*)1); 715 pPage->RemovePrivateData((void*)1);
665 } 716 }
666 717
667 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) { 718 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) {
668 if (!page) 719 if (!page)
669 return; 720 return;
721 #ifndef PDF_ENABLE_XFA
722 CPDFSDK_PageView* pPageView =
723 (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((void*)page);
724 if (pPageView && pPageView->IsLocked()) {
725 pPageView->TakeOverPage();
726 return;
727 }
728 delete (CPDF_Page*)page;
729 #else
670 730
671 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; 731 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
672 pPage->Release(); 732 pPage->Release();
733 #endif
673 } 734 }
674 735
675 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { 736 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) {
737 #ifndef PDF_ENABLE_XFA
738 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
739 if (!pDoc)
740 return;
741
742 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
743 if (!pParser) {
744 delete pDoc;
745 return;
746 }
747 delete pParser;
748 #else
676 delete CPDFDocumentFromFPDFDocument(document); 749 delete CPDFDocumentFromFPDFDocument(document);
750 #endif
677 } 751 }
678 752
679 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() { 753 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() {
680 return GetLastError(); 754 return GetLastError();
681 } 755 }
682 756
683 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, 757 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page,
684 int start_x, 758 int start_x,
685 int start_y, 759 int start_y,
686 int size_x, 760 int size_x,
687 int size_y, 761 int size_y,
688 int rotate, 762 int rotate,
689 int device_x, 763 int device_x,
690 int device_y, 764 int device_y,
691 double* page_x, 765 double* page_x,
692 double* page_y) { 766 double* page_y) {
693 if (page == NULL || page_x == NULL || page_y == NULL) 767 if (page == NULL || page_x == NULL || page_y == NULL)
694 return; 768 return;
695 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); 769 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
770 #ifndef PDF_ENABLE_XFA
771
772 CPDF_Matrix page2device;
773 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y,
774 rotate);
775 CPDF_Matrix device2page;
776 device2page.SetReverse(page2device);
777
778 FX_FLOAT page_x_f, page_y_f;
779 device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x_f,
780 page_y_f);
781
782 *page_x = (page_x_f);
783 *page_y = (page_y_f);
784 #else
696 pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x, 785 pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x,
697 device_y, page_x, page_y); 786 device_y, page_x, page_y);
787 #endif
698 } 788 }
699 789
700 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, 790 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page,
701 int start_x, 791 int start_x,
702 int start_y, 792 int start_y,
703 int size_x, 793 int size_x,
704 int size_y, 794 int size_y,
705 int rotate, 795 int rotate,
706 double page_x, 796 double page_x,
707 double page_y, 797 double page_y,
708 int* device_x, 798 int* device_x,
709 int* device_y) { 799 int* device_y) {
710 if (!device_x || !device_y) 800 if (!device_x || !device_y)
711 return; 801 return;
712 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); 802 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
713 if (!pPage) 803 if (!pPage)
714 return; 804 return;
805 #ifndef PDF_ENABLE_XFA
806 CPDF_Matrix page2device;
807 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y,
808 rotate);
809
810 FX_FLOAT device_x_f, device_y_f;
811 page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f,
812 device_y_f);
813
814 *device_x = FXSYS_round(device_x_f);
815 *device_y = FXSYS_round(device_y_f);
816 #else
715 pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y, 817 pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y,
716 device_x, device_y); 818 device_x, device_y);
819 #endif
717 } 820 }
718 821
719 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, 822 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width,
720 int height, 823 int height,
721 int alpha) { 824 int alpha) {
722 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); 825 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap);
723 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) { 826 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) {
724 return NULL; 827 return NULL;
725 } 828 }
726 return pBitmap.release(); 829 return pBitmap.release();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 if (flags & FPDF_LCD_TEXT) 924 if (flags & FPDF_LCD_TEXT)
822 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; 925 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE;
823 else 926 else
824 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; 927 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE;
825 if (flags & FPDF_NO_NATIVETEXT) 928 if (flags & FPDF_NO_NATIVETEXT)
826 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT; 929 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT;
827 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE) 930 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE)
828 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE; 931 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE;
829 if (flags & FPDF_RENDER_FORCEHALFTONE) 932 if (flags & FPDF_RENDER_FORCEHALFTONE)
830 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE; 933 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE;
934 #ifndef PDF_ENABLE_XFA
935 if (flags & FPDF_RENDER_NO_SMOOTHTEXT)
936 pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH;
937 if (flags & FPDF_RENDER_NO_SMOOTHIMAGE)
938 pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH;
939 if (flags & FPDF_RENDER_NO_SMOOTHPATH)
940 pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH;
941 #endif
831 // Grayscale output 942 // Grayscale output
832 if (flags & FPDF_GRAYSCALE) { 943 if (flags & FPDF_GRAYSCALE) {
833 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; 944 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY;
834 pContext->m_pOptions->m_ForeColor = 0; 945 pContext->m_pOptions->m_ForeColor = 0;
835 pContext->m_pOptions->m_BackColor = 0xffffff; 946 pContext->m_pOptions->m_BackColor = 0xffffff;
836 } 947 }
837 const CPDF_OCContext::UsageType usage = 948 const CPDF_OCContext::UsageType usage =
838 (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View; 949 (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View;
839 pContext->m_pOptions->m_AddFlags = flags >> 8; 950 pContext->m_pOptions->m_AddFlags = flags >> 8;
840 pContext->m_pOptions->m_pOCContext = 951 pContext->m_pOptions->m_pOCContext =
(...skipping 29 matching lines...) Expand all
870 } 981 }
871 982
872 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, 983 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
873 int page_index, 984 int page_index,
874 double* width, 985 double* width,
875 double* height) { 986 double* height) {
876 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); 987 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document);
877 if (!pDoc) 988 if (!pDoc)
878 return FALSE; 989 return FALSE;
879 990
991 #ifndef PDF_ENABLE_XFA
992 CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
Lei Zhang 2015/11/25 00:34:30 More readable to combine all the XFA path into one
Tom Sepez 2015/11/25 21:45:30 Manual task for later. diff is too smart here.
993 if (!pDict)
994 #else
880 int count = pDoc->GetPageCount(); 995 int count = pDoc->GetPageCount();
881 if (page_index < 0 || page_index >= count) 996 if (page_index < 0 || page_index >= count)
997 #endif
882 return FALSE; 998 return FALSE;
883 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
884 CPDFXFA_Page* pPage = pDoc->GetPage(page_index); 1006 CPDFXFA_Page* pPage = pDoc->GetPage(page_index);
885 if (!pPage) 1007 if (!pPage)
886 return FALSE; 1008 return FALSE;
887 1009
888 *width = pPage->GetPageWidth(); 1010 *width = pPage->GetPageWidth();
889 *height = pPage->GetPageHeight(); 1011 *height = pPage->GetPageHeight();
1012 #endif
890 1013
891 return TRUE; 1014 return TRUE;
892 } 1015 }
893 1016
894 DLLEXPORT FPDF_BOOL STDCALL 1017 DLLEXPORT FPDF_BOOL STDCALL
895 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) { 1018 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) {
896 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 1019 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
897 if (!pDoc) 1020 if (!pDoc)
898 return TRUE; 1021 return TRUE;
899 CPDF_ViewerPreferences viewRef(pDoc); 1022 CPDF_ViewerPreferences viewRef(pDoc);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 return nullptr; 1079 return nullptr;
957 1080
958 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 1081 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
959 if (!pDoc) 1082 if (!pDoc)
960 return nullptr; 1083 return nullptr;
961 1084
962 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); 1085 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
963 return name_tree.LookupNamedDest(pDoc, name); 1086 return name_tree.LookupNamedDest(pDoc, name);
964 } 1087 }
965 1088
1089 #ifdef PDF_ENABLE_XFA
966 FPDF_RESULT FPDF_BStr_Init(FPDF_BSTR* str) { 1090 FPDF_RESULT FPDF_BStr_Init(FPDF_BSTR* str) {
967 if (!str) 1091 if (!str)
968 return -1; 1092 return -1;
969 1093
970 FXSYS_memset(str, 0, sizeof(FPDF_BSTR)); 1094 FXSYS_memset(str, 0, sizeof(FPDF_BSTR));
971 return 0; 1095 return 0;
972 } 1096 }
973 1097
974 FPDF_RESULT FPDF_BStr_Set(FPDF_BSTR* str, FPDF_LPCSTR bstr, int length) { 1098 FPDF_RESULT FPDF_BStr_Set(FPDF_BSTR* str, FPDF_LPCSTR bstr, int length) {
975 if (!str) 1099 if (!str)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 return -1; 1132 return -1;
1009 1133
1010 if (str->str) { 1134 if (str->str) {
1011 FX_Free(str->str); 1135 FX_Free(str->str);
1012 str->str = NULL; 1136 str->str = NULL;
1013 } 1137 }
1014 str->len = 0; 1138 str->len = 0;
1015 return 0; 1139 return 0;
1016 } 1140 }
1017 1141
1142 #endif
1018 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, 1143 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
1019 int index, 1144 int index,
1020 void* buffer, 1145 void* buffer,
1021 long* buflen) { 1146 long* buflen) {
1022 if (!buffer) 1147 if (!buffer)
1023 *buflen = 0; 1148 *buflen = 0;
1024 1149
1025 if (index < 0) 1150 if (index < 0)
1026 return nullptr; 1151 return nullptr;
1027 1152
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 if (!buffer) { 1198 if (!buffer) {
1074 *buflen = len; 1199 *buflen = len;
1075 } else if (*buflen >= len) { 1200 } else if (*buflen >= len) {
1076 memcpy(buffer, utf16Name.c_str(), len); 1201 memcpy(buffer, utf16Name.c_str(), len);
1077 *buflen = len; 1202 *buflen = len;
1078 } else { 1203 } else {
1079 *buflen = -1; 1204 *buflen = -1;
1080 } 1205 }
1081 return (FPDF_DEST)pDestObj; 1206 return (FPDF_DEST)pDestObj;
1082 } 1207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698