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 "../include/fsdk_define.h" | 7 #include "../include/fsdk_define.h" |
8 #include "../include/fpdfview.h" | 8 #include "../include/fpdfview.h" |
9 #include "../include/fsdk_rendercontext.h" | 9 #include "../include/fsdk_rendercontext.h" |
10 #include "../include/fpdf_progressive.h" | 10 #include "../include/fpdf_progressive.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 | 265 |
266 DLLEXPORT void STDCALL FPDF_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enabl e) | 266 DLLEXPORT void STDCALL FPDF_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enabl e) |
267 { | 267 { |
268 return FSDK_SetSandBoxPolicy(policy, enable); | 268 return FSDK_SetSandBoxPolicy(policy, enable); |
269 } | 269 } |
270 | 270 |
271 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BY TESTRING password) | 271 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BY TESTRING password) |
272 { | 272 { |
273 CPDF_Parser* pParser = FX_NEW CPDF_Parser; | 273 CPDF_Parser* pParser = FX_NEW CPDF_Parser; |
274 pParser->SetPassword(password); | 274 pParser->SetPassword(password); |
275 » try { | 275 |
276 » » FX_DWORD err_code = pParser->StartParse((FX_LPCSTR)file_path); | 276 » FX_DWORD err_code = pParser->StartParse((FX_LPCSTR)file_path); |
277 » » if (err_code) { | 277 if (err_code) { |
Nico
2014/08/13 17:59:31
nit: use tabs for indent for the if and its body t
Bo Xu
2014/08/13 18:03:00
Done.
| |
278 » » » delete pParser; | 278 delete pParser; |
279 » » » ProcessParseError(err_code); | 279 ProcessParseError(err_code); |
280 » » » return NULL; | 280 return NULL; |
281 » » } | 281 } |
282 » } | |
283 » catch (...) { | |
284 » » delete pParser; | |
285 » » SetLastError(FPDF_ERR_UNKNOWN); | |
286 » » return NULL; | |
287 » } | |
288 return pParser->GetDocument(); | 282 return pParser->GetDocument(); |
289 } | 283 } |
290 | 284 |
291 extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code); | 285 extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code); |
292 | 286 |
293 class CMemFile FX_FINAL: public IFX_FileRead, public CFX_Object | 287 class CMemFile FX_FINAL: public IFX_FileRead, public CFX_Object |
294 { | 288 { |
295 public: | 289 public: |
296 CMemFile(FX_BYTE* pBuf, FX_FILESIZE size):m_pBuf(pBuf),m_size(size) {} | 290 CMemFile(FX_BYTE* pBuf, FX_FILESIZE size):m_pBuf(pBuf),m_size(size) {} |
297 | 291 |
(...skipping 13 matching lines...) Expand all Loading... | |
311 return TRUE; | 305 return TRUE; |
312 } | 306 } |
313 private: | 307 private: |
314 FX_BYTE* m_pBuf; | 308 FX_BYTE* m_pBuf; |
315 FX_FILESIZE m_size; | 309 FX_FILESIZE m_size; |
316 }; | 310 }; |
317 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int s ize, FPDF_BYTESTRING password) | 311 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int s ize, FPDF_BYTESTRING password) |
318 { | 312 { |
319 CPDF_Parser* pParser = FX_NEW CPDF_Parser; | 313 CPDF_Parser* pParser = FX_NEW CPDF_Parser; |
320 pParser->SetPassword(password); | 314 pParser->SetPassword(password); |
321 » try { | 315 » CMemFile* pMemFile = FX_NEW CMemFile((FX_BYTE*)data_buf, size); |
322 » » CMemFile* pMemFile = FX_NEW CMemFile((FX_BYTE*)data_buf, size); | 316 » FX_DWORD err_code = pParser->StartParse(pMemFile); |
323 » » FX_DWORD err_code = pParser->StartParse(pMemFile); | 317 » if (err_code) { |
324 » » if (err_code) { | |
325 » » » delete pParser; | |
326 » » » ProcessParseError(err_code); | |
327 » » » return NULL; | |
328 » » } | |
329 » » CPDF_Document * pDoc = NULL; | |
330 » » pDoc = pParser?pParser->GetDocument():NULL; | |
331 » » CheckUnSupportError(pDoc, err_code); | |
332 » } | |
333 » catch (...) { | |
334 delete pParser; | 318 delete pParser; |
335 » » SetLastError(FPDF_ERR_UNKNOWN); | 319 » » ProcessParseError(err_code); |
336 return NULL; | 320 return NULL; |
337 } | 321 } |
322 CPDF_Document * pDoc = NULL; | |
323 pDoc = pParser?pParser->GetDocument():NULL; | |
324 CheckUnSupportError(pDoc, err_code); | |
338 return pParser->GetDocument(); | 325 return pParser->GetDocument(); |
339 } | 326 } |
340 | 327 |
341 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAc cess, FPDF_BYTESTRING password) | 328 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAc cess, FPDF_BYTESTRING password) |
342 { | 329 { |
343 CPDF_Parser* pParser = FX_NEW CPDF_Parser; | 330 CPDF_Parser* pParser = FX_NEW CPDF_Parser; |
344 pParser->SetPassword(password); | 331 pParser->SetPassword(password); |
345 CPDF_CustomAccess* pFile = FX_NEW CPDF_CustomAccess(pFileAccess); | 332 CPDF_CustomAccess* pFile = FX_NEW CPDF_CustomAccess(pFileAccess); |
346 » try { | 333 » FX_DWORD err_code = pParser->StartParse(pFile); |
347 » » FX_DWORD err_code = pParser->StartParse(pFile); | 334 » if (err_code) { |
348 » » if (err_code) { | |
349 » » » delete pParser; | |
350 » » » ProcessParseError(err_code); | |
351 » » » return NULL; | |
352 » » } | |
353 » » CPDF_Document * pDoc = NULL; | |
354 » » pDoc = pParser?pParser->GetDocument():NULL; | |
355 » » CheckUnSupportError(pDoc, err_code); | |
356 » } | |
357 » catch (...) { | |
358 delete pParser; | 335 delete pParser; |
359 » » SetLastError(FPDF_ERR_UNKNOWN); | 336 » » ProcessParseError(err_code); |
360 return NULL; | 337 return NULL; |
361 } | 338 } |
339 CPDF_Document * pDoc = NULL; | |
340 pDoc = pParser?pParser->GetDocument():NULL; | |
341 CheckUnSupportError(pDoc, err_code); | |
362 return pParser->GetDocument(); | 342 return pParser->GetDocument(); |
363 } | 343 } |
364 | 344 |
365 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, int* fileVers ion) | 345 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, int* fileVers ion) |
366 { | 346 { |
367 if(!doc||!fileVersion) return FALSE; | 347 if(!doc||!fileVersion) return FALSE; |
368 *fileVersion = 0; | 348 *fileVersion = 0; |
369 CPDF_Document* pDoc = (CPDF_Document*)doc; | 349 CPDF_Document* pDoc = (CPDF_Document*)doc; |
370 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); | 350 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); |
371 if(!pParser) | 351 if(!pParser) |
(...skipping 24 matching lines...) Expand all Loading... | |
396 { | 376 { |
397 if (document == NULL) return NULL; | 377 if (document == NULL) return NULL; |
398 if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) return NULL; | 378 if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) return NULL; |
399 // CPDF_Parser* pParser = (CPDF_Parser*)document; | 379 // CPDF_Parser* pParser = (CPDF_Parser*)document; |
400 CPDF_Document* pDoc = (CPDF_Document*)document; | 380 CPDF_Document* pDoc = (CPDF_Document*)document; |
401 if (pDoc == NULL) return NULL; | 381 if (pDoc == NULL) return NULL; |
402 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); | 382 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); |
403 if (pDict == NULL) return NULL; | 383 if (pDict == NULL) return NULL; |
404 CPDF_Page* pPage = FX_NEW CPDF_Page; | 384 CPDF_Page* pPage = FX_NEW CPDF_Page; |
405 pPage->Load(pDoc, pDict); | 385 pPage->Load(pDoc, pDict); |
406 » try { | 386 » pPage->ParseContent(); |
407 » » pPage->ParseContent(); | |
408 » } | |
409 » catch (...) { | |
410 » » delete pPage; | |
411 » » return NULL; | |
412 » } | |
413 | 387 |
414 // CheckUnSupportError(pDoc, 0); | 388 // CheckUnSupportError(pDoc, 0); |
415 | 389 |
416 return pPage; | 390 return pPage; |
417 } | 391 } |
418 | 392 |
419 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) | 393 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) |
420 { | 394 { |
421 if (!page) | 395 if (!page) |
422 return 0.0; | 396 return 0.0; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 #ifdef _SKIA_SUPPORT_ | 440 #ifdef _SKIA_SUPPORT_ |
467 pContext->m_pDevice = FX_NEW CFX_SkiaDevice; | 441 pContext->m_pDevice = FX_NEW CFX_SkiaDevice; |
468 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pB itmap); | 442 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pB itmap); |
469 #else | 443 #else |
470 pContext->m_pDevice = FX_NEW CFX_FxgeDevice; | 444 pContext->m_pDevice = FX_NEW CFX_FxgeDevice; |
471 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pB itmap); | 445 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pB itmap); |
472 #endif | 446 #endif |
473 } | 447 } |
474 else | 448 else |
475 pContext->m_pDevice = FX_NEW CFX_WindowsDevice(dc); | 449 pContext->m_pDevice = FX_NEW CFX_WindowsDevice(dc); |
476 » if (flags & FPDF_NO_CATCH) | 450 |
477 » » Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y , rotate, flags,TRUE,NULL); | 451 » Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate , flags,TRUE,NULL); |
478 » else { | 452 |
479 » » try { | |
480 » » » Func_RenderPage(pContext, page, start_x, start_y, size_x , size_y, rotate, flags,TRUE,NULL); | |
481 » » } catch (...) { | |
482 » » } | |
483 » } | |
484 if (bBackgroundAlphaNeeded) | 453 if (bBackgroundAlphaNeeded) |
485 { | 454 { |
486 if (pBitmap) | 455 if (pBitmap) |
487 { | 456 { |
488 CFX_WindowsDevice WinDC(dc); | 457 CFX_WindowsDevice WinDC(dc); |
489 | 458 |
490 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINT ER) | 459 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINT ER) |
491 { | 460 { |
492 CFX_DIBitmap* pDst = FX_NEW CFX_DIBitmap; | 461 CFX_DIBitmap* pDst = FX_NEW CFX_DIBitmap; |
493 pDst->Create(pBitmap->GetWidth(), pBitmap->GetHe ight(),FXDIB_Rgb32); | 462 pDst->Create(pBitmap->GetWidth(), pBitmap->GetHe ight(),FXDIB_Rgb32); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 pContext->m_pBitmap = FX_NEW CFX_DIBitmap; | 521 pContext->m_pBitmap = FX_NEW CFX_DIBitmap; |
553 pContext->m_pBitmap->Create(width, height, FXDIB_Rgb, (FX_LPBYTE)pBuffer ); | 522 pContext->m_pBitmap->Create(width, height, FXDIB_Rgb, (FX_LPBYTE)pBuffer ); |
554 pContext->m_pDevice = FX_NEW CPDF_FxgeDevice; | 523 pContext->m_pDevice = FX_NEW CPDF_FxgeDevice; |
555 ((CPDF_FxgeDevice*)pContext->m_pDevice)->Attach(pContext->m_pBitmap); | 524 ((CPDF_FxgeDevice*)pContext->m_pDevice)->Attach(pContext->m_pBitmap); |
556 | 525 |
557 #ifdef DEBUG_TRACE | 526 #ifdef DEBUG_TRACE |
558 CPDF_ModuleMgr::Get()->ReportError(999, "Ready for PDF rendering"); | 527 CPDF_ModuleMgr::Get()->ReportError(999, "Ready for PDF rendering"); |
559 #endif | 528 #endif |
560 | 529 |
561 // output to bitmap device | 530 // output to bitmap device |
562 » if (flags & FPDF_NO_CATCH) | 531 » Func_RenderPage(pContext, page, start_x - rect.left, start_y - rect.top, size_x, size_y, rotate, flags); |
563 » » Func_RenderPage(pContext, page, start_x - rect.left, start_y - r ect.top, size_x, size_y, rotate, flags); | |
564 » else { | |
565 » » try { | |
566 » » » Func_RenderPage(pContext, page, start_x - rect.left, sta rt_y - rect.top, size_x, size_y, rotate, flags); | |
567 » » } catch (...) { | |
568 » » } | |
569 » } | |
570 | 532 |
571 #ifdef DEBUG_TRACE | 533 #ifdef DEBUG_TRACE |
572 CPDF_ModuleMgr::Get()->ReportError(999, "Finished PDF rendering"); | 534 CPDF_ModuleMgr::Get()->ReportError(999, "Finished PDF rendering"); |
573 #endif | 535 #endif |
574 | 536 |
575 // Now output to real device | 537 // Now output to real device |
576 HDC hMemDC = CreateCompatibleDC(dc); | 538 HDC hMemDC = CreateCompatibleDC(dc); |
577 if (hMemDC == NULL) { | 539 if (hMemDC == NULL) { |
578 #if defined(DEBUG) || defined(_DEBUG) | 540 #if defined(DEBUG) || defined(_DEBUG) |
579 char str[128]; | 541 char str[128]; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 else | 589 else |
628 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi tmap); | 590 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi tmap); |
629 #else | 591 #else |
630 pContext->m_pDevice = FX_NEW CFX_FxgeDevice; | 592 pContext->m_pDevice = FX_NEW CFX_FxgeDevice; |
631 | 593 |
632 if (flags & FPDF_REVERSE_BYTE_ORDER) | 594 if (flags & FPDF_REVERSE_BYTE_ORDER) |
633 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi tmap,0,TRUE); | 595 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi tmap,0,TRUE); |
634 else | 596 else |
635 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi tmap); | 597 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi tmap); |
636 #endif | 598 #endif |
637 » if (flags & FPDF_NO_CATCH) | 599 |
638 » » Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y , rotate, flags,TRUE,NULL); | 600 » Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate , flags,TRUE,NULL); |
639 » else { | |
640 » » try { | |
641 » » » Func_RenderPage(pContext, page, start_x, start_y, size_x , size_y, rotate, flags,TRUE,NULL); | |
642 » » } catch (...) { | |
643 » » } | |
644 » } | |
645 | 601 |
646 delete pContext; | 602 delete pContext; |
647 pPage->RemovePrivateData((void*)1); | 603 pPage->RemovePrivateData((void*)1); |
648 } | 604 } |
649 | 605 |
650 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) | 606 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) |
651 { | 607 { |
652 if (!page) return; | 608 if (!page) return; |
653 delete (CPDF_Page*)page; | 609 delete (CPDF_Page*)page; |
654 | 610 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
908 { | 864 { |
909 if (document == NULL) | 865 if (document == NULL) |
910 return NULL; | 866 return NULL; |
911 if (name == NULL || name[0] == 0) | 867 if (name == NULL || name[0] == 0) |
912 return NULL; | 868 return NULL; |
913 | 869 |
914 CPDF_Document* pDoc = (CPDF_Document*)document; | 870 CPDF_Document* pDoc = (CPDF_Document*)document; |
915 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); | 871 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); |
916 return name_tree.LookupNamedDest(pDoc, name); | 872 return name_tree.LookupNamedDest(pDoc, name); |
917 } | 873 } |
OLD | NEW |