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

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

Issue 1399273003: fpdfsdk/ differences with XFA (for didactic purposes only). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Regenerate after taking juns patch 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
« no previous file with comments | « fpdfsdk/src/fpdftext.cpp ('k') | fpdfsdk/src/fpdfview_c_api_test.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
10 #include "../include/fpdfxfa/fpdfxfa_app.h"
11 #include "../include/fpdfxfa/fpdfxfa_doc.h"
12 #include "../include/fpdfxfa/fpdfxfa_page.h"
13 #include "../include/fpdfxfa/fpdfxfa_util.h"
14 #include "core/include/fpdfapi/fpdf_module.h"
15 #endif
9 #include "core/include/fxcodec/fx_codec.h" 16 #include "core/include/fxcodec/fx_codec.h"
10 #include "core/include/fxcrt/fx_safe_types.h" 17 #include "core/include/fxcrt/fx_safe_types.h"
11 #include "fpdfsdk/include/fsdk_define.h" 18 #include "fpdfsdk/include/fsdk_define.h"
12 #include "fpdfsdk/include/fsdk_mgr.h" 19 #include "fpdfsdk/include/fsdk_mgr.h"
13 #include "fpdfsdk/include/fsdk_rendercontext.h" 20 #include "fpdfsdk/include/fsdk_rendercontext.h"
14 #include "fpdfsdk/include/javascript/IJavaScript.h" 21 #include "fpdfsdk/include/javascript/IJavaScript.h"
15 #include "public/fpdf_ext.h" 22 #include "public/fpdf_ext.h"
23 #ifdef PDF_ENABLE_XFA
24 #include "public/fpdf_formfill.h"
25 #endif
16 #include "public/fpdf_progressive.h" 26 #include "public/fpdf_progressive.h"
17 #include "third_party/base/nonstd_unique_ptr.h" 27 #include "third_party/base/nonstd_unique_ptr.h"
18 #include "third_party/base/numerics/safe_conversions_impl.h" 28 #include "third_party/base/numerics/safe_conversions_impl.h"
19 29
20 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { 30 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) {
21 return static_cast<UnderlyingDocumentType*>(doc); 31 return static_cast<UnderlyingDocumentType*>(doc);
22 } 32 }
23 33
24 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { 34 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) {
25 return static_cast<FPDF_DOCUMENT>(doc); 35 return static_cast<FPDF_DOCUMENT>(doc);
26 } 36 }
27 37
28 UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) { 38 UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) {
29 return static_cast<UnderlyingPageType*>(page); 39 return static_cast<UnderlyingPageType*>(page);
30 } 40 }
31 41
32 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { 42 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) {
43 #ifndef PDF_ENABLE_XFA
33 return UnderlyingFromFPDFDocument(doc); 44 return UnderlyingFromFPDFDocument(doc);
45 #else
46 return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr;
47 #endif
34 } 48 }
35 49
36 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { 50 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) {
51 #ifndef PDF_ENABLE_XFA
37 return FPDFDocumentFromUnderlying(doc); 52 return FPDFDocumentFromUnderlying(doc);
53 #else
54 return doc ? FPDFDocumentFromUnderlying(
55 new CPDFXFA_Document(doc, CPDFXFA_App::GetInstance()))
56 : nullptr;
57 #endif
38 } 58 }
39 59
40 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { 60 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) {
61 #ifndef PDF_ENABLE_XFA
41 return UnderlyingFromFPDFPage(page); 62 return UnderlyingFromFPDFPage(page);
63 #else
64 return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr;
65 }
66
67 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) {
68 m_pFS = pFS;
69 m_nCurPos = 0;
70 }
71
72 IFX_FileStream* CFPDF_FileStream::Retain() {
73 return this;
74 }
75
76 void CFPDF_FileStream::Release() {
77 if (m_pFS && m_pFS->Release)
78 m_pFS->Release(m_pFS->clientData);
79 delete this;
80 }
81
82 FX_FILESIZE CFPDF_FileStream::GetSize() {
83 if (m_pFS && m_pFS->GetSize)
84 return (FX_FILESIZE)m_pFS->GetSize(m_pFS->clientData);
85 return 0;
86 }
87
88 FX_BOOL CFPDF_FileStream::IsEOF() {
89 return m_nCurPos >= GetSize();
90 }
91
92 FX_BOOL CFPDF_FileStream::ReadBlock(void* buffer,
93 FX_FILESIZE offset,
94 size_t size) {
95 if (!buffer || !size || !m_pFS->ReadBlock)
96 return FALSE;
97
98 if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer,
99 (FPDF_DWORD)size) == 0) {
100 m_nCurPos = offset + size;
101 return TRUE;
102 }
103 return FALSE;
104 }
105
106 size_t CFPDF_FileStream::ReadBlock(void* buffer, size_t size) {
107 if (!buffer || !size || !m_pFS->ReadBlock)
108 return 0;
109
110 FX_FILESIZE nSize = GetSize();
111 if (m_nCurPos >= nSize)
112 return 0;
113 FX_FILESIZE dwAvail = nSize - m_nCurPos;
114 if (dwAvail < (FX_FILESIZE)size)
115 size = (size_t)dwAvail;
116 if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)m_nCurPos, buffer,
117 (FPDF_DWORD)size) == 0) {
118 m_nCurPos += size;
119 return size;
120 }
121
122 return 0;
123 }
124
125 FX_BOOL CFPDF_FileStream::WriteBlock(const void* buffer,
126 FX_FILESIZE offset,
127 size_t size) {
128 if (!m_pFS || !m_pFS->WriteBlock)
129 return FALSE;
130
131 if (m_pFS->WriteBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer,
132 (FPDF_DWORD)size) == 0) {
133 m_nCurPos = offset + size;
134 return TRUE;
135 }
136 return FALSE;
137 }
138
139 FX_BOOL CFPDF_FileStream::Flush() {
140 if (!m_pFS || !m_pFS->Flush)
141 return TRUE;
142
143 return m_pFS->Flush(m_pFS->clientData) == 0;
144 #endif
42 } 145 }
43 146
44 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { 147 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) {
45 m_FileAccess = *pFileAccess; 148 m_FileAccess = *pFileAccess;
149 #ifdef PDF_ENABLE_XFA
150 m_BufferOffset = (FX_DWORD)-1;
151 }
152
153 FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, uint8_t& ch) {
154 if (pos >= m_FileAccess.m_FileLen)
155 return FALSE;
156 if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset ||
157 pos >= m_BufferOffset + 512) {
158 // Need to read from file access
159 m_BufferOffset = pos;
160 int size = 512;
161 if (pos + 512 > m_FileAccess.m_FileLen)
162 size = m_FileAccess.m_FileLen - pos;
163 if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffset, m_Buffer,
164 size))
165 return FALSE;
166 }
167 ch = m_Buffer[pos - m_BufferOffset];
168 return TRUE;
169 }
170
171 FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos,
172 uint8_t* pBuf,
173 FX_DWORD size) {
174 if (pos + size > m_FileAccess.m_FileLen)
175 return FALSE;
176 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size);
177 #endif
46 } 178 }
47 179
48 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, 180 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer,
49 FX_FILESIZE offset, 181 FX_FILESIZE offset,
50 size_t size) { 182 size_t size) {
51 if (offset < 0) { 183 if (offset < 0) {
52 return FALSE; 184 return FALSE;
53 } 185 }
54 FX_SAFE_FILESIZE newPos = 186 FX_SAFE_FILESIZE newPos =
55 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
97 g_pCodecModule = new CCodec_ModuleMgr(); 229 g_pCodecModule = new CCodec_ModuleMgr();
98 230
99 CFX_GEModule::Create(cfg ? cfg->m_pUserFontPaths : nullptr); 231 CFX_GEModule::Create(cfg ? cfg->m_pUserFontPaths : nullptr);
100 CFX_GEModule::Get()->SetCodecModule(g_pCodecModule); 232 CFX_GEModule::Get()->SetCodecModule(g_pCodecModule);
101 233
102 CPDF_ModuleMgr::Create(); 234 CPDF_ModuleMgr::Create();
103 CPDF_ModuleMgr* pModuleMgr = CPDF_ModuleMgr::Get(); 235 CPDF_ModuleMgr* pModuleMgr = CPDF_ModuleMgr::Get();
104 pModuleMgr->SetCodecModule(g_pCodecModule); 236 pModuleMgr->SetCodecModule(g_pCodecModule);
105 pModuleMgr->InitPageModule(); 237 pModuleMgr->InitPageModule();
106 pModuleMgr->InitRenderModule(); 238 pModuleMgr->InitRenderModule();
239 #ifndef PDF_ENABLE_XFA
107 pModuleMgr->LoadEmbeddedGB1CMaps(); 240 pModuleMgr->LoadEmbeddedGB1CMaps();
108 pModuleMgr->LoadEmbeddedJapan1CMaps(); 241 pModuleMgr->LoadEmbeddedJapan1CMaps();
109 pModuleMgr->LoadEmbeddedCNS1CMaps(); 242 pModuleMgr->LoadEmbeddedCNS1CMaps();
110 pModuleMgr->LoadEmbeddedKorea1CMaps(); 243 pModuleMgr->LoadEmbeddedKorea1CMaps();
244 #else
245 CPDFXFA_App::GetInstance()->Initialize();
246 #endif
111 if (cfg && cfg->version >= 2) 247 if (cfg && cfg->version >= 2)
112 IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate); 248 IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate);
113 } 249 }
114 250
115 DLLEXPORT void STDCALL FPDF_DestroyLibrary() { 251 DLLEXPORT void STDCALL FPDF_DestroyLibrary() {
252 #ifdef PDF_ENABLE_XFA
253 CPDFXFA_App::ReleaseInstance();
254 #endif
116 CPDF_ModuleMgr::Destroy(); 255 CPDF_ModuleMgr::Destroy();
117 CFX_GEModule::Destroy(); 256 CFX_GEModule::Destroy();
118 257
119 delete g_pCodecModule; 258 delete g_pCodecModule;
120 g_pCodecModule = nullptr; 259 g_pCodecModule = nullptr;
121 } 260 }
122 261
123 #ifndef _WIN32 262 #ifndef _WIN32
124 int g_LastError; 263 int g_LastError;
125 void SetLastError(int err) { 264 void SetLastError(int err) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 305
167 CPDF_Parser* pParser = new CPDF_Parser; 306 CPDF_Parser* pParser = new CPDF_Parser;
168 pParser->SetPassword(password); 307 pParser->SetPassword(password);
169 308
170 FX_DWORD err_code = pParser->StartParse(pFileAccess); 309 FX_DWORD err_code = pParser->StartParse(pFileAccess);
171 if (err_code) { 310 if (err_code) {
172 delete pParser; 311 delete pParser;
173 ProcessParseError(err_code); 312 ProcessParseError(err_code);
174 return NULL; 313 return NULL;
175 } 314 }
315 #ifndef PDF_ENABLE_XFA
176 return pParser->GetDocument(); 316 return pParser->GetDocument();
317 #else
318 CPDF_Document* pPDFDoc = pParser->GetDocument();
319 if (!pPDFDoc)
320 return NULL;
321
322 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
323 return new CPDFXFA_Document(pPDFDoc, pProvider);
324 }
325
326 DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document,
327 int* docType) {
328 if (!document)
329 return FALSE;
330
331 CPDF_Document* pdfDoc =
332 (static_cast<CPDFXFA_Document*>(document))->GetPDFDoc();
333 if (!pdfDoc)
334 return FALSE;
335
336 CPDF_Dictionary* pRoot = pdfDoc->GetRoot();
337 if (!pRoot)
338 return FALSE;
339
340 CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm");
341 if (!pAcroForm)
342 return FALSE;
343
344 CPDF_Object* pXFA = pAcroForm->GetElement("XFA");
345 if (!pXFA)
346 return FALSE;
347
348 FX_BOOL bDynamicXFA = pRoot->GetBoolean("NeedsRendering", FALSE);
349
350 if (bDynamicXFA)
351 *docType = DOCTYPE_DYNAMIC_XFA;
352 else
353 *docType = DOCTYPE_STATIC_XFA;
354
355 return TRUE;
356 }
357
358 DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) {
359 return document && (static_cast<CPDFXFA_Document*>(document))->LoadXFADoc();
360 #endif
177 } 361 }
178 362
179 class CMemFile final : public IFX_FileRead { 363 class CMemFile final : public IFX_FileRead {
180 public: 364 public:
181 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) {}
182 366
183 void Release() override { delete this; } 367 void Release() override { delete this; }
184 FX_FILESIZE GetSize() override { return m_size; } 368 FX_FILESIZE GetSize() override { return m_size; }
185 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 {
186 if (offset < 0) { 370 if (offset < 0) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 439
256 *fileVersion = pParser->GetFileVersion(); 440 *fileVersion = pParser->GetFileVersion();
257 return TRUE; 441 return TRUE;
258 } 442 }
259 443
260 // 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
261 // header). 445 // header).
262 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) { 446 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) {
263 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 447 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
264 if (!pDoc) 448 if (!pDoc)
449 #ifndef PDF_ENABLE_XFA
265 return 0; 450 return 0;
451 #else
452 return (FX_DWORD)-1;
453 #endif
266 454
267 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); 455 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict();
268 return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1; 456 return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1;
269 } 457 }
270 458
271 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { 459 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) {
272 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 460 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
273 if (!pDoc) 461 if (!pDoc)
274 return -1; 462 return -1;
275 463
276 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); 464 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict();
277 return pDict ? pDict->GetInteger("R") : -1; 465 return pDict ? pDict->GetInteger("R") : -1;
278 } 466 }
279 467
280 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) { 468 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) {
281 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); 469 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document);
282 return pDoc ? pDoc->GetPageCount() : 0; 470 return pDoc ? pDoc->GetPageCount() : 0;
283 } 471 }
284 472
285 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, 473 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document,
286 int page_index) { 474 int page_index) {
287 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); 475 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document);
288 if (!pDoc) 476 if (!pDoc)
289 return nullptr; 477 return nullptr;
290 478
291 if (page_index < 0 || page_index >= pDoc->GetPageCount()) 479 if (page_index < 0 || page_index >= pDoc->GetPageCount())
292 return nullptr; 480 return nullptr;
293 481
482 #ifndef PDF_ENABLE_XFA
294 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); 483 CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
295 if (pDict == NULL) 484 if (pDict == NULL)
296 return NULL; 485 return NULL;
297 CPDF_Page* pPage = new CPDF_Page; 486 CPDF_Page* pPage = new CPDF_Page;
298 pPage->Load(pDoc, pDict); 487 pPage->Load(pDoc, pDict);
299 pPage->ParseContent(); 488 pPage->ParseContent();
300 return pPage; 489 return pPage;
490 #else
491 return pDoc->GetPage(page_index);
492 #endif
301 } 493 }
302 494
303 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { 495 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) {
304 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); 496 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
305 return pPage ? pPage->GetPageWidth() : 0.0; 497 return pPage ? pPage->GetPageWidth() : 0.0;
306 } 498 }
307 499
308 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { 500 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) {
309 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); 501 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
310 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
515 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,
516 rotate, flags, TRUE, NULL); 708 rotate, flags, TRUE, NULL);
517 709
518 delete pContext; 710 delete pContext;
519 pPage->RemovePrivateData((void*)1); 711 pPage->RemovePrivateData((void*)1);
520 } 712 }
521 713
522 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) { 714 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) {
523 if (!page) 715 if (!page)
524 return; 716 return;
717 #ifndef PDF_ENABLE_XFA
525 CPDFSDK_PageView* pPageView = 718 CPDFSDK_PageView* pPageView =
526 (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((void*)page); 719 (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((void*)page);
527 if (pPageView && pPageView->IsLocked()) { 720 if (pPageView && pPageView->IsLocked()) {
528 pPageView->TakeOverPage(); 721 pPageView->TakeOverPage();
529 return; 722 return;
530 } 723 }
531 delete (CPDF_Page*)page; 724 delete (CPDF_Page*)page;
725 #else
726
727 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
728 pPage->Release();
729 #endif
532 } 730 }
533 731
534 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { 732 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) {
733 #ifndef PDF_ENABLE_XFA
535 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 734 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
536 if (!pDoc) 735 if (!pDoc)
537 return; 736 return;
538 737
539 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); 738 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
540 if (!pParser) { 739 if (!pParser) {
541 delete pDoc; 740 delete pDoc;
542 return; 741 return;
543 } 742 }
544 delete pParser; 743 delete pParser;
744 #else
745 delete CPDFDocumentFromFPDFDocument(document);
746 #endif
545 } 747 }
546 748
547 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() { 749 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() {
548 return GetLastError(); 750 return GetLastError();
549 } 751 }
550 752
551 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, 753 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page,
552 int start_x, 754 int start_x,
553 int start_y, 755 int start_y,
554 int size_x, 756 int size_x,
555 int size_y, 757 int size_y,
556 int rotate, 758 int rotate,
557 int device_x, 759 int device_x,
558 int device_y, 760 int device_y,
559 double* page_x, 761 double* page_x,
560 double* page_y) { 762 double* page_y) {
561 if (page == NULL || page_x == NULL || page_y == NULL) 763 if (page == NULL || page_x == NULL || page_y == NULL)
562 return; 764 return;
563 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); 765 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
766 #ifndef PDF_ENABLE_XFA
564 767
565 CPDF_Matrix page2device; 768 CPDF_Matrix page2device;
566 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, 769 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y,
567 rotate); 770 rotate);
568 CPDF_Matrix device2page; 771 CPDF_Matrix device2page;
569 device2page.SetReverse(page2device); 772 device2page.SetReverse(page2device);
570 773
571 FX_FLOAT page_x_f, page_y_f; 774 FX_FLOAT page_x_f, page_y_f;
572 device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x_f, 775 device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x_f,
573 page_y_f); 776 page_y_f);
574 777
575 *page_x = (page_x_f); 778 *page_x = (page_x_f);
576 *page_y = (page_y_f); 779 *page_y = (page_y_f);
780 #else
781 pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x,
782 device_y, page_x, page_y);
783 #endif
577 } 784 }
578 785
579 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, 786 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page,
580 int start_x, 787 int start_x,
581 int start_y, 788 int start_y,
582 int size_x, 789 int size_x,
583 int size_y, 790 int size_y,
584 int rotate, 791 int rotate,
585 double page_x, 792 double page_x,
586 double page_y, 793 double page_y,
587 int* device_x, 794 int* device_x,
588 int* device_y) { 795 int* device_y) {
589 if (!device_x || !device_y) 796 if (!device_x || !device_y)
590 return; 797 return;
591 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); 798 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
592 if (!pPage) 799 if (!pPage)
593 return; 800 return;
801 #ifndef PDF_ENABLE_XFA
594 CPDF_Matrix page2device; 802 CPDF_Matrix page2device;
595 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, 803 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y,
596 rotate); 804 rotate);
597 805
598 FX_FLOAT device_x_f, device_y_f; 806 FX_FLOAT device_x_f, device_y_f;
599 page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f, 807 page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f,
600 device_y_f); 808 device_y_f);
601 809
602 *device_x = FXSYS_round(device_x_f); 810 *device_x = FXSYS_round(device_x_f);
603 *device_y = FXSYS_round(device_y_f); 811 *device_y = FXSYS_round(device_y_f);
812 #else
813 pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y,
814 device_x, device_y);
815 #endif
604 } 816 }
605 817
606 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, 818 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width,
607 int height, 819 int height,
608 int alpha) { 820 int alpha) {
609 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); 821 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap);
610 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) { 822 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) {
611 return NULL; 823 return NULL;
612 } 824 }
613 return pBitmap.release(); 825 return pBitmap.release();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 if (flags & FPDF_LCD_TEXT) 920 if (flags & FPDF_LCD_TEXT)
709 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; 921 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE;
710 else 922 else
711 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; 923 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE;
712 if (flags & FPDF_NO_NATIVETEXT) 924 if (flags & FPDF_NO_NATIVETEXT)
713 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT; 925 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT;
714 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE) 926 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE)
715 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE; 927 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE;
716 if (flags & FPDF_RENDER_FORCEHALFTONE) 928 if (flags & FPDF_RENDER_FORCEHALFTONE)
717 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE; 929 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE;
930 #ifndef PDF_ENABLE_XFA
718 if (flags & FPDF_RENDER_NO_SMOOTHTEXT) 931 if (flags & FPDF_RENDER_NO_SMOOTHTEXT)
719 pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH; 932 pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH;
720 if (flags & FPDF_RENDER_NO_SMOOTHIMAGE) 933 if (flags & FPDF_RENDER_NO_SMOOTHIMAGE)
721 pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH; 934 pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH;
722 if (flags & FPDF_RENDER_NO_SMOOTHPATH) 935 if (flags & FPDF_RENDER_NO_SMOOTHPATH)
723 pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH; 936 pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH;
937 #endif
724 // Grayscale output 938 // Grayscale output
725 if (flags & FPDF_GRAYSCALE) { 939 if (flags & FPDF_GRAYSCALE) {
726 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; 940 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY;
727 pContext->m_pOptions->m_ForeColor = 0; 941 pContext->m_pOptions->m_ForeColor = 0;
728 pContext->m_pOptions->m_BackColor = 0xffffff; 942 pContext->m_pOptions->m_BackColor = 0xffffff;
729 } 943 }
730 const CPDF_OCContext::UsageType usage = 944 const CPDF_OCContext::UsageType usage =
731 (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View; 945 (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View;
732 pContext->m_pOptions->m_AddFlags = flags >> 8; 946 pContext->m_pOptions->m_AddFlags = flags >> 8;
733 pContext->m_pOptions->m_pOCContext = 947 pContext->m_pOptions->m_pOCContext =
(...skipping 29 matching lines...) Expand all
763 } 977 }
764 978
765 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, 979 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
766 int page_index, 980 int page_index,
767 double* width, 981 double* width,
768 double* height) { 982 double* height) {
769 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); 983 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document);
770 if (!pDoc) 984 if (!pDoc)
771 return FALSE; 985 return FALSE;
772 986
987 #ifndef PDF_ENABLE_XFA
773 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); 988 CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
774 if (!pDict) 989 if (!pDict)
990 #else
991 int count = pDoc->GetPageCount();
992 if (page_index < 0 || page_index >= count)
775 return FALSE; 993 return FALSE;
776 994
995 CPDFXFA_Page* pPage = pDoc->GetPage(page_index);
996 if (!pPage)
997 #endif
998 return FALSE;
999
1000 #ifndef PDF_ENABLE_XFA
777 CPDF_Page page; 1001 CPDF_Page page;
778 page.Load(pDoc, pDict); 1002 page.Load(pDoc, pDict);
779 *width = page.GetPageWidth(); 1003 *width = page.GetPageWidth();
780 *height = page.GetPageHeight(); 1004 *height = page.GetPageHeight();
1005 #else
1006 *width = pPage->GetPageWidth();
1007 *height = pPage->GetPageHeight();
1008 #endif
781 1009
782 return TRUE; 1010 return TRUE;
783 } 1011 }
784 1012
785 DLLEXPORT FPDF_BOOL STDCALL 1013 DLLEXPORT FPDF_BOOL STDCALL
786 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) { 1014 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) {
787 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 1015 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
788 if (!pDoc) 1016 if (!pDoc)
789 return TRUE; 1017 return TRUE;
790 CPDF_ViewerPreferences viewRef(pDoc); 1018 CPDF_ViewerPreferences viewRef(pDoc);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 return nullptr; 1075 return nullptr;
848 1076
849 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); 1077 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
850 if (!pDoc) 1078 if (!pDoc)
851 return nullptr; 1079 return nullptr;
852 1080
853 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); 1081 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
854 return name_tree.LookupNamedDest(pDoc, name); 1082 return name_tree.LookupNamedDest(pDoc, name);
855 } 1083 }
856 1084
1085 #ifdef PDF_ENABLE_XFA
1086 FPDF_RESULT FPDF_BStr_Init(FPDF_BSTR* str) {
1087 if (!str)
1088 return -1;
1089
1090 FXSYS_memset(str, 0, sizeof(FPDF_BSTR));
1091 return 0;
1092 }
1093
1094 FPDF_RESULT FPDF_BStr_Set(FPDF_BSTR* str, FPDF_LPCSTR bstr, int length) {
1095 if (!str)
1096 return -1;
1097 if (!bstr || !length)
1098 return -1;
1099 if (length == -1)
1100 length = FXSYS_strlen(bstr);
1101
1102 if (length == 0) {
1103 if (str->str) {
1104 FX_Free(str->str);
1105 str->str = NULL;
1106 }
1107 str->len = 0;
1108 return 0;
1109 }
1110
1111 if (str->str && str->len < length)
1112 str->str = FX_Realloc(char, str->str, length + 1);
1113 else if (!str->str)
1114 str->str = FX_Alloc(char, length + 1);
1115
1116 str->str[length] = 0;
1117 if (str->str == NULL)
1118 return -1;
1119
1120 FXSYS_memcpy(str->str, bstr, length);
1121 str->len = length;
1122
1123 return 0;
1124 }
1125
1126 FPDF_RESULT FPDF_BStr_Clear(FPDF_BSTR* str) {
1127 if (!str)
1128 return -1;
1129
1130 if (str->str) {
1131 FX_Free(str->str);
1132 str->str = NULL;
1133 }
1134 str->len = 0;
1135 return 0;
1136 }
1137
1138 #endif
857 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, 1139 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
858 int index, 1140 int index,
859 void* buffer, 1141 void* buffer,
860 long* buflen) { 1142 long* buflen) {
861 if (!buffer) 1143 if (!buffer)
862 *buflen = 0; 1144 *buflen = 0;
863 1145
864 if (index < 0) 1146 if (index < 0)
865 return nullptr; 1147 return nullptr;
866 1148
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 if (!buffer) { 1194 if (!buffer) {
913 *buflen = len; 1195 *buflen = len;
914 } else if (*buflen >= len) { 1196 } else if (*buflen >= len) {
915 memcpy(buffer, utf16Name.c_str(), len); 1197 memcpy(buffer, utf16Name.c_str(), len);
916 *buflen = len; 1198 *buflen = len;
917 } else { 1199 } else {
918 *buflen = -1; 1200 *buflen = -1;
919 } 1201 }
920 return (FPDF_DEST)pDestObj; 1202 return (FPDF_DEST)pDestObj;
921 } 1203 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdftext.cpp ('k') | fpdfsdk/src/fpdfview_c_api_test.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698