| 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 | 9 |
| 10 #include <list> | 10 #include <list> |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // If a PS_NULL pen is used, the dimensions of the rectangle are 1 pixel less. | 209 // If a PS_NULL pen is used, the dimensions of the rectangle are 1 pixel less. |
| 210 Rectangle(dc, 0, 0, width + 1, height + 1); | 210 Rectangle(dc, 0, 0, width + 1, height + 1); |
| 211 | 211 |
| 212 FPDF_RenderPage(dc, page, 0, 0, width, height, 0, | 212 FPDF_RenderPage(dc, page, 0, 0, width, height, 0, |
| 213 FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); | 213 FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); |
| 214 | 214 |
| 215 DeleteEnhMetaFile(CloseEnhMetaFile(dc)); | 215 DeleteEnhMetaFile(CloseEnhMetaFile(dc)); |
| 216 } | 216 } |
| 217 #endif | 217 #endif |
| 218 | 218 |
| 219 int Form_Alert(IPDF_JSPLATFORM*, FPDF_WIDESTRING msg, FPDF_WIDESTRING, | 219 int ExampleAppAlert(IPDF_JSPLATFORM*, FPDF_WIDESTRING msg, FPDF_WIDESTRING, |
| 220 int, int) { | 220 int, int) { |
| 221 // Deal with differences between UTF16LE and wchar_t on this platform. | 221 // Deal with differences between UTF16LE and wchar_t on this platform. |
| 222 size_t characters = 0; | 222 size_t characters = 0; |
| 223 while (msg[characters]) { | 223 while (msg[characters]) { |
| 224 ++characters; | 224 ++characters; |
| 225 } | 225 } |
| 226 wchar_t* platform_string = | 226 wchar_t* platform_string = |
| 227 (wchar_t*)malloc((characters + 1) * sizeof(wchar_t)); | 227 (wchar_t*)malloc((characters + 1) * sizeof(wchar_t)); |
| 228 for (size_t i = 0; i < characters + 1; ++i) { | 228 for (size_t i = 0; i < characters + 1; ++i) { |
| 229 unsigned char* ptr = (unsigned char*)&msg[i]; | 229 unsigned char* ptr = (unsigned char*)&msg[i]; |
| 230 platform_string[i] = ptr[0] + 256 * ptr[1]; | 230 platform_string[i] = ptr[0] + 256 * ptr[1]; |
| 231 } | 231 } |
| 232 printf("Alert: %ls\n", platform_string); | 232 printf("Alert: %ls\n", platform_string); |
| 233 free(platform_string); | 233 free(platform_string); |
| 234 return 0; | 234 return 0; |
| 235 } | 235 } |
| 236 | 236 |
| 237 void Unsupported_Handler(UNSUPPORT_INFO*, int type) { | 237 void ExampleDocGotoPage(IPDF_JSPLATFORM*, int pageNumber) { |
| 238 printf("Goto Page: %d\n", pageNumber); |
| 239 } |
| 240 |
| 241 void ExampleUnsupportedHandler(UNSUPPORT_INFO*, int type) { |
| 238 std::string feature = "Unknown"; | 242 std::string feature = "Unknown"; |
| 239 switch (type) { | 243 switch (type) { |
| 240 case FPDF_UNSP_DOC_XFAFORM: | 244 case FPDF_UNSP_DOC_XFAFORM: |
| 241 feature = "XFA"; | 245 feature = "XFA"; |
| 242 break; | 246 break; |
| 243 case FPDF_UNSP_DOC_PORTABLECOLLECTION: | 247 case FPDF_UNSP_DOC_PORTABLECOLLECTION: |
| 244 feature = "Portfolios_Packages"; | 248 feature = "Portfolios_Packages"; |
| 245 break; | 249 break; |
| 246 case FPDF_UNSP_DOC_ATTACHMENT: | 250 case FPDF_UNSP_DOC_ATTACHMENT: |
| 247 case FPDF_UNSP_ANNOT_ATTACHMENT: | 251 case FPDF_UNSP_ANNOT_ATTACHMENT: |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { | 370 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { |
| 367 } | 371 } |
| 368 | 372 |
| 369 void RenderPdf(const std::string& name, const char* pBuf, size_t len, | 373 void RenderPdf(const std::string& name, const char* pBuf, size_t len, |
| 370 const Options& options) { | 374 const Options& options) { |
| 371 fprintf(stderr, "Rendering PDF file %s.\n", name.c_str()); | 375 fprintf(stderr, "Rendering PDF file %s.\n", name.c_str()); |
| 372 | 376 |
| 373 IPDF_JSPLATFORM platform_callbacks; | 377 IPDF_JSPLATFORM platform_callbacks; |
| 374 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); | 378 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); |
| 375 platform_callbacks.version = 1; | 379 platform_callbacks.version = 1; |
| 376 platform_callbacks.app_alert = Form_Alert; | 380 platform_callbacks.app_alert = ExampleAppAlert; |
| 381 platform_callbacks.Doc_gotoPage = ExampleDocGotoPage; |
| 377 | 382 |
| 378 FPDF_FORMFILLINFO form_callbacks; | 383 FPDF_FORMFILLINFO form_callbacks; |
| 379 memset(&form_callbacks, '\0', sizeof(form_callbacks)); | 384 memset(&form_callbacks, '\0', sizeof(form_callbacks)); |
| 380 form_callbacks.version = 1; | 385 form_callbacks.version = 1; |
| 381 form_callbacks.m_pJsPlatform = &platform_callbacks; | 386 form_callbacks.m_pJsPlatform = &platform_callbacks; |
| 382 | 387 |
| 383 TestLoader loader(pBuf, len); | 388 TestLoader loader(pBuf, len); |
| 384 | 389 |
| 385 FPDF_FILEACCESS file_access; | 390 FPDF_FILEACCESS file_access; |
| 386 memset(&file_access, '\0', sizeof(file_access)); | 391 memset(&file_access, '\0', sizeof(file_access)); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 } | 532 } |
| 528 v8::V8::SetNativesDataBlob(&natives); | 533 v8::V8::SetNativesDataBlob(&natives); |
| 529 v8::V8::SetSnapshotDataBlob(&snapshot); | 534 v8::V8::SetSnapshotDataBlob(&snapshot); |
| 530 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 535 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 531 | 536 |
| 532 FPDF_InitLibrary(); | 537 FPDF_InitLibrary(); |
| 533 | 538 |
| 534 UNSUPPORT_INFO unsuppored_info; | 539 UNSUPPORT_INFO unsuppored_info; |
| 535 memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); | 540 memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); |
| 536 unsuppored_info.version = 1; | 541 unsuppored_info.version = 1; |
| 537 unsuppored_info.FSDK_UnSupport_Handler = Unsupported_Handler; | 542 unsuppored_info.FSDK_UnSupport_Handler = ExampleUnsupportedHandler; |
| 538 | 543 |
| 539 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); | 544 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); |
| 540 | 545 |
| 541 while (!files.empty()) { | 546 while (!files.empty()) { |
| 542 std::string filename = files.front(); | 547 std::string filename = files.front(); |
| 543 files.pop_front(); | 548 files.pop_front(); |
| 544 size_t file_length = 0; | 549 size_t file_length = 0; |
| 545 char* file_contents = GetFileContents(filename.c_str(), &file_length); | 550 char* file_contents = GetFileContents(filename.c_str(), &file_length); |
| 546 if (!file_contents) | 551 if (!file_contents) |
| 547 continue; | 552 continue; |
| 548 RenderPdf(filename, file_contents, file_length, options); | 553 RenderPdf(filename, file_contents, file_length, options); |
| 549 free(file_contents); | 554 free(file_contents); |
| 550 } | 555 } |
| 551 | 556 |
| 552 FPDF_DestroyLibrary(); | 557 FPDF_DestroyLibrary(); |
| 553 v8::V8::ShutdownPlatform(); | 558 v8::V8::ShutdownPlatform(); |
| 554 delete platform; | 559 delete platform; |
| 555 | 560 |
| 556 return 0; | 561 return 0; |
| 557 } | 562 } |
| OLD | NEW |