OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium 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 #include <limits.h> | 5 #include <limits.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <wchar.h> | 9 #include <wchar.h> |
10 | 10 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 // If a PS_NULL pen is used, the dimensions of the rectangle are 1 pixel less. | 255 // If a PS_NULL pen is used, the dimensions of the rectangle are 1 pixel less. |
256 Rectangle(dc, 0, 0, width + 1, height + 1); | 256 Rectangle(dc, 0, 0, width + 1, height + 1); |
257 | 257 |
258 FPDF_RenderPage(dc, page, 0, 0, width, height, 0, | 258 FPDF_RenderPage(dc, page, 0, 0, width, height, 0, |
259 FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); | 259 FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); |
260 | 260 |
261 DeleteEnhMetaFile(CloseEnhMetaFile(dc)); | 261 DeleteEnhMetaFile(CloseEnhMetaFile(dc)); |
262 } | 262 } |
263 #endif | 263 #endif |
264 | 264 |
265 int Form_Alert(IPDF_JSPLATFORM*, FPDF_WIDESTRING msg, FPDF_WIDESTRING, | 265 int ExampleAppAlert(IPDF_JSPLATFORM*, FPDF_WIDESTRING msg, FPDF_WIDESTRING, |
266 int, int) { | 266 int, int) { |
267 // Deal with differences between UTF16LE and wchar_t on this platform. | 267 // Deal with differences between UTF16LE and wchar_t on this platform. |
268 size_t characters = 0; | 268 size_t characters = 0; |
269 while (msg[characters]) { | 269 while (msg[characters]) { |
270 ++characters; | 270 ++characters; |
271 } | 271 } |
272 wchar_t* platform_string = | 272 wchar_t* platform_string = |
273 (wchar_t*)malloc((characters + 1) * sizeof(wchar_t)); | 273 (wchar_t*)malloc((characters + 1) * sizeof(wchar_t)); |
274 for (size_t i = 0; i < characters + 1; ++i) { | 274 for (size_t i = 0; i < characters + 1; ++i) { |
275 unsigned char* ptr = (unsigned char*)&msg[i]; | 275 unsigned char* ptr = (unsigned char*)&msg[i]; |
276 platform_string[i] = ptr[0] + 256 * ptr[1]; | 276 platform_string[i] = ptr[0] + 256 * ptr[1]; |
277 } | 277 } |
278 printf("Alert: %ls\n", platform_string); | 278 printf("Alert: %ls\n", platform_string); |
279 free(platform_string); | 279 free(platform_string); |
280 return 0; | 280 return 0; |
281 } | 281 } |
282 | 282 |
283 void Unsupported_Handler(UNSUPPORT_INFO*, int type) { | 283 void ExampleDocGotoPage(IPDF_JSPLATFORM*, int pageNumber) { |
| 284 printf("Goto Page: %d\n", pageNumber); |
| 285 } |
| 286 |
| 287 void ExampleUnsupportedHandler(UNSUPPORT_INFO*, int type) { |
284 std::string feature = "Unknown"; | 288 std::string feature = "Unknown"; |
285 switch (type) { | 289 switch (type) { |
286 case FPDF_UNSP_DOC_XFAFORM: | 290 case FPDF_UNSP_DOC_XFAFORM: |
287 feature = "XFA"; | 291 feature = "XFA"; |
288 break; | 292 break; |
289 case FPDF_UNSP_DOC_PORTABLECOLLECTION: | 293 case FPDF_UNSP_DOC_PORTABLECOLLECTION: |
290 feature = "Portfolios_Packages"; | 294 feature = "Portfolios_Packages"; |
291 break; | 295 break; |
292 case FPDF_UNSP_DOC_ATTACHMENT: | 296 case FPDF_UNSP_DOC_ATTACHMENT: |
293 case FPDF_UNSP_ANNOT_ATTACHMENT: | 297 case FPDF_UNSP_ANNOT_ATTACHMENT: |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { | 422 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { |
419 } | 423 } |
420 | 424 |
421 void RenderPdf(const std::string& name, const char* pBuf, size_t len, | 425 void RenderPdf(const std::string& name, const char* pBuf, size_t len, |
422 const Options& options) { | 426 const Options& options) { |
423 fprintf(stderr, "Rendering PDF file %s.\n", name.c_str()); | 427 fprintf(stderr, "Rendering PDF file %s.\n", name.c_str()); |
424 | 428 |
425 IPDF_JSPLATFORM platform_callbacks; | 429 IPDF_JSPLATFORM platform_callbacks; |
426 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); | 430 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); |
427 platform_callbacks.version = 1; | 431 platform_callbacks.version = 1; |
428 platform_callbacks.app_alert = Form_Alert; | 432 platform_callbacks.app_alert = ExampleAppAlert; |
| 433 platform_callbacks.Doc_gotoPage = ExampleDocGotoPage; |
429 | 434 |
430 FPDF_FORMFILLINFO form_callbacks; | 435 FPDF_FORMFILLINFO form_callbacks; |
431 memset(&form_callbacks, '\0', sizeof(form_callbacks)); | 436 memset(&form_callbacks, '\0', sizeof(form_callbacks)); |
432 form_callbacks.version = 2; | 437 form_callbacks.version = 2; |
433 form_callbacks.m_pJsPlatform = &platform_callbacks; | 438 form_callbacks.m_pJsPlatform = &platform_callbacks; |
434 | 439 |
435 TestLoader loader(pBuf, len); | 440 TestLoader loader(pBuf, len); |
436 | 441 |
437 FPDF_FILEACCESS file_access; | 442 FPDF_FILEACCESS file_access; |
438 memset(&file_access, '\0', sizeof(file_access)); | 443 memset(&file_access, '\0', sizeof(file_access)); |
(...skipping 22 matching lines...) Expand all Loading... |
461 } else { | 466 } else { |
462 fprintf(stderr, "Linearized path...\n"); | 467 fprintf(stderr, "Linearized path...\n"); |
463 doc = FPDFAvail_GetDocument(pdf_avail, NULL); | 468 doc = FPDFAvail_GetDocument(pdf_avail, NULL); |
464 } | 469 } |
465 | 470 |
466 (void) FPDF_GetDocPermissions(doc); | 471 (void) FPDF_GetDocPermissions(doc); |
467 (void) FPDFAvail_IsFormAvail(pdf_avail, &hints); | 472 (void) FPDFAvail_IsFormAvail(pdf_avail, &hints); |
468 | 473 |
469 FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnvironment(doc, &form_callbacks); | 474 FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnvironment(doc, &form_callbacks); |
470 if (!FPDF_LoadXFA(doc)) { | 475 if (!FPDF_LoadXFA(doc)) { |
471 printf("LoadXFA unsuccessful, continuing anyway.\n"); | 476 fprintf(stderr, "LoadXFA unsuccessful, continuing anyway.\n"); |
472 } | 477 } |
473 FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD); | 478 FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD); |
474 FPDF_SetFormFieldHighlightAlpha(form, 100); | 479 FPDF_SetFormFieldHighlightAlpha(form, 100); |
475 | 480 |
476 int first_page = FPDFAvail_GetFirstPageNum(doc); | 481 int first_page = FPDFAvail_GetFirstPageNum(doc); |
477 (void) FPDFAvail_IsPageAvail(pdf_avail, first_page, &hints); | 482 (void) FPDFAvail_IsPageAvail(pdf_avail, first_page, &hints); |
478 | 483 |
479 int page_count = FPDF_GetPageCount(doc); | 484 int page_count = FPDF_GetPageCount(doc); |
480 for (int i = 0; i < page_count; ++i) { | 485 for (int i = 0; i < page_count; ++i) { |
481 (void) FPDFAvail_IsPageAvail(pdf_avail, i, &hints); | 486 (void) FPDFAvail_IsPageAvail(pdf_avail, i, &hints); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 } | 593 } |
589 v8::V8::SetNativesDataBlob(&natives); | 594 v8::V8::SetNativesDataBlob(&natives); |
590 v8::V8::SetSnapshotDataBlob(&snapshot); | 595 v8::V8::SetSnapshotDataBlob(&snapshot); |
591 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 596 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
592 | 597 |
593 FPDF_InitLibrary(); | 598 FPDF_InitLibrary(); |
594 | 599 |
595 UNSUPPORT_INFO unsuppored_info; | 600 UNSUPPORT_INFO unsuppored_info; |
596 memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); | 601 memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); |
597 unsuppored_info.version = 1; | 602 unsuppored_info.version = 1; |
598 unsuppored_info.FSDK_UnSupport_Handler = Unsupported_Handler; | 603 unsuppored_info.FSDK_UnSupport_Handler = ExampleUnsupportedHandler; |
599 | 604 |
600 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); | 605 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); |
601 | 606 |
602 while (!files.empty()) { | 607 while (!files.empty()) { |
603 std::string filename = files.front(); | 608 std::string filename = files.front(); |
604 files.pop_front(); | 609 files.pop_front(); |
605 size_t file_length = 0; | 610 size_t file_length = 0; |
606 char* file_contents = GetFileContents(filename.c_str(), &file_length); | 611 char* file_contents = GetFileContents(filename.c_str(), &file_length); |
607 if (!file_contents) | 612 if (!file_contents) |
608 continue; | 613 continue; |
609 RenderPdf(filename, file_contents, file_length, options); | 614 RenderPdf(filename, file_contents, file_length, options); |
610 free(file_contents); | 615 free(file_contents); |
611 } | 616 } |
612 | 617 |
613 FPDF_DestroyLibrary(); | 618 FPDF_DestroyLibrary(); |
614 v8::V8::ShutdownPlatform(); | 619 v8::V8::ShutdownPlatform(); |
615 delete platform; | 620 delete platform; |
616 | 621 |
617 return 0; | 622 return 0; |
618 } | 623 } |
OLD | NEW |