Chromium Code Reviews| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 } | 192 } |
| 193 | 193 |
| 194 void WriteEmf(FPDF_PAGE page, const char* pdf_name, int num) { | 194 void WriteEmf(FPDF_PAGE page, const char* pdf_name, int num) { |
| 195 int width = static_cast<int>(FPDF_GetPageWidth(page)); | 195 int width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 196 int height = static_cast<int>(FPDF_GetPageHeight(page)); | 196 int height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 197 | 197 |
| 198 char filename[256]; | 198 char filename[256]; |
| 199 snprintf(filename, sizeof(filename), "%s.%d.emf", pdf_name, num); | 199 snprintf(filename, sizeof(filename), "%s.%d.emf", pdf_name, num); |
| 200 | 200 |
| 201 HDC dc = CreateEnhMetaFileA(NULL, filename, NULL, NULL); | 201 HDC dc = CreateEnhMetaFileA(NULL, filename, NULL, NULL); |
| 202 | 202 |
| 203 HRGN rgn = CreateRectRgn(0, 0, width, height); | 203 HRGN rgn = CreateRectRgn(0, 0, width, height); |
| 204 SelectClipRgn(dc, rgn); | 204 SelectClipRgn(dc, rgn); |
| 205 DeleteObject(rgn); | 205 DeleteObject(rgn); |
| 206 | 206 |
| 207 SelectObject(dc, GetStockObject(NULL_PEN)); | 207 SelectObject(dc, GetStockObject(NULL_PEN)); |
| 208 SelectObject(dc, GetStockObject(WHITE_BRUSH)); | 208 SelectObject(dc, GetStockObject(WHITE_BRUSH)); |
| 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, FPDF_WIDESTRING, int, int) { | 219 int Form_Alert(IPDF_JSPLATFORM*, FPDF_WIDESTRING msg, FPDF_WIDESTRING, |
| 220 printf("Form_Alert called.\n"); | 220 int, int) { |
| 221 // Deal with differences between UTF16LE and wchar_t on this platform. | |
| 222 size_t characters = 0; | |
| 223 while (msg[characters]) { | |
| 224 ++characters; | |
| 225 } | |
| 226 wchar_t* platform_string = | |
| 227 (wchar_t*)malloc((characters + 1) * sizeof(wchar_t)); | |
|
Lei Zhang
2015/02/06 22:53:07
avoid C style casting?
| |
| 228 for (size_t i = 0; i < characters + 1; ++i) { | |
| 229 unsigned char* ptr = (unsigned char*)&msg[i]; | |
| 230 platform_string[i] = ptr[0] + 256 * ptr[1]; | |
| 231 } | |
| 232 printf("Alert: %ls\n", platform_string); | |
| 233 free(platform_string); | |
| 221 return 0; | 234 return 0; |
| 222 } | 235 } |
| 223 | 236 |
| 224 void Unsupported_Handler(UNSUPPORT_INFO*, int type) { | 237 void Unsupported_Handler(UNSUPPORT_INFO*, int type) { |
| 225 std::string feature = "Unknown"; | 238 std::string feature = "Unknown"; |
| 226 switch (type) { | 239 switch (type) { |
| 227 case FPDF_UNSP_DOC_XFAFORM: | 240 case FPDF_UNSP_DOC_XFAFORM: |
| 228 feature = "XFA"; | 241 feature = "XFA"; |
| 229 break; | 242 break; |
| 230 case FPDF_UNSP_DOC_PORTABLECOLLECTION: | 243 case FPDF_UNSP_DOC_PORTABLECOLLECTION: |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 | 361 |
| 349 bool Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { | 362 bool Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { |
| 350 return true; | 363 return true; |
| 351 } | 364 } |
| 352 | 365 |
| 353 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { | 366 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { |
| 354 } | 367 } |
| 355 | 368 |
| 356 void RenderPdf(const std::string& name, const char* pBuf, size_t len, | 369 void RenderPdf(const std::string& name, const char* pBuf, size_t len, |
| 357 const Options& options) { | 370 const Options& options) { |
| 358 printf("Rendering PDF file %s.\n", name.c_str()); | 371 fprintf(stderr, "Rendering PDF file %s.\n", name.c_str()); |
| 359 | 372 |
| 360 IPDF_JSPLATFORM platform_callbacks; | 373 IPDF_JSPLATFORM platform_callbacks; |
| 361 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); | 374 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); |
| 362 platform_callbacks.version = 1; | 375 platform_callbacks.version = 1; |
| 363 platform_callbacks.app_alert = Form_Alert; | 376 platform_callbacks.app_alert = Form_Alert; |
| 364 | 377 |
| 365 FPDF_FORMFILLINFO form_callbacks; | 378 FPDF_FORMFILLINFO form_callbacks; |
| 366 memset(&form_callbacks, '\0', sizeof(form_callbacks)); | 379 memset(&form_callbacks, '\0', sizeof(form_callbacks)); |
| 367 form_callbacks.version = 1; | 380 form_callbacks.version = 1; |
| 368 form_callbacks.m_pJsPlatform = &platform_callbacks; | 381 form_callbacks.m_pJsPlatform = &platform_callbacks; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 384 memset(&hints, '\0', sizeof(hints)); | 397 memset(&hints, '\0', sizeof(hints)); |
| 385 hints.version = 1; | 398 hints.version = 1; |
| 386 hints.AddSegment = Add_Segment; | 399 hints.AddSegment = Add_Segment; |
| 387 | 400 |
| 388 FPDF_DOCUMENT doc; | 401 FPDF_DOCUMENT doc; |
| 389 FPDF_AVAIL pdf_avail = FPDFAvail_Create(&file_avail, &file_access); | 402 FPDF_AVAIL pdf_avail = FPDFAvail_Create(&file_avail, &file_access); |
| 390 | 403 |
| 391 (void) FPDFAvail_IsDocAvail(pdf_avail, &hints); | 404 (void) FPDFAvail_IsDocAvail(pdf_avail, &hints); |
| 392 | 405 |
| 393 if (!FPDFAvail_IsLinearized(pdf_avail)) { | 406 if (!FPDFAvail_IsLinearized(pdf_avail)) { |
| 394 printf("Non-linearized path...\n"); | 407 fprintf(stderr, "Non-linearized path...\n"); |
| 395 doc = FPDF_LoadCustomDocument(&file_access, NULL); | 408 doc = FPDF_LoadCustomDocument(&file_access, NULL); |
| 396 } else { | 409 } else { |
| 397 printf("Linearized path...\n"); | 410 fprintf(stderr, "Linearized path...\n"); |
| 398 doc = FPDFAvail_GetDocument(pdf_avail, NULL); | 411 doc = FPDFAvail_GetDocument(pdf_avail, NULL); |
| 399 } | 412 } |
| 400 | 413 |
| 401 (void) FPDF_GetDocPermissions(doc); | 414 (void) FPDF_GetDocPermissions(doc); |
| 402 (void) FPDFAvail_IsFormAvail(pdf_avail, &hints); | 415 (void) FPDFAvail_IsFormAvail(pdf_avail, &hints); |
| 403 | 416 |
| 404 FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnvironment(doc, &form_callbacks); | 417 FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnvironment(doc, &form_callbacks); |
| 405 FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD); | 418 FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD); |
| 406 FPDF_SetFormFieldHighlightAlpha(form, 100); | 419 FPDF_SetFormFieldHighlightAlpha(form, 100); |
| 407 | 420 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 FORM_OnBeforeClosePage(page, form); | 483 FORM_OnBeforeClosePage(page, form); |
| 471 FPDFText_ClosePage(text_page); | 484 FPDFText_ClosePage(text_page); |
| 472 FPDF_ClosePage(page); | 485 FPDF_ClosePage(page); |
| 473 } | 486 } |
| 474 | 487 |
| 475 FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC); | 488 FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC); |
| 476 FPDFDOC_ExitFormFillEnvironment(form); | 489 FPDFDOC_ExitFormFillEnvironment(form); |
| 477 FPDF_CloseDocument(doc); | 490 FPDF_CloseDocument(doc); |
| 478 FPDFAvail_Destroy(pdf_avail); | 491 FPDFAvail_Destroy(pdf_avail); |
| 479 | 492 |
| 480 printf("Loaded, parsed and rendered %" PRIuS " pages.\n", rendered_pages); | 493 fprintf(stderr, "Rendered %" PRIuS " pages.\n", rendered_pages); |
| 481 printf("Skipped %" PRIuS " bad pages.\n", bad_pages); | 494 fprintf(stderr, "Skipped %" PRIuS " bad pages.\n", bad_pages); |
| 482 } | 495 } |
| 483 | 496 |
| 497 static const char usage_string[] = | |
| 498 "Usage: pdfium_test [OPTION] [FILE]...\n" | |
| 499 " --bin-dir=<path> - override path to v8 external data\n" | |
| 500 " --scale=<number> - scale output size by number (e.g. 0.5)\n" | |
| 501 #ifdef _WIN32 | |
| 502 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" | |
| 503 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" | |
| 504 #endif | |
| 505 " --ppm - write page images <pdf-name>.<page-number>.ppm\n"; | |
| 506 | |
| 484 int main(int argc, const char* argv[]) { | 507 int main(int argc, const char* argv[]) { |
| 485 std::vector<std::string> args(argv, argv + argc); | 508 std::vector<std::string> args(argv, argv + argc); |
| 486 Options options; | 509 Options options; |
| 487 std::list<std::string> files; | 510 std::list<std::string> files; |
| 488 if (!ParseCommandLine(args, &options, &files)) { | 511 if (!ParseCommandLine(args, &options, &files)) { |
| 489 printf("Usage: pdfium_test [OPTION] [FILE]...\n"); | 512 fprintf(stderr, "%s", usage_string); |
| 490 printf("--bin-dir=<path> - override path to v8 external data\n"); | |
| 491 printf("--scale=<number> - scale output size by number (e.g. 0.5)\n"); | |
| 492 printf("--ppm - write page images <pdf-name>.<page-number>.ppm\n"); | |
| 493 #ifdef _WIN32 | |
| 494 printf("--bmp - write page images <pdf-name>.<page-number>.bmp\n"); | |
| 495 printf("--emf - write page meta files <pdf-name>.<page-number>.emf\n"); | |
| 496 #endif | |
| 497 return 1; | 513 return 1; |
| 498 } | 514 } |
| 499 | 515 |
| 500 v8::V8::InitializeICU(); | 516 v8::V8::InitializeICU(); |
| 501 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); | 517 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); |
| 502 v8::V8::InitializePlatform(platform); | 518 v8::V8::InitializePlatform(platform); |
| 503 v8::V8::Initialize(); | 519 v8::V8::Initialize(); |
| 504 | 520 |
| 505 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 521 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 506 v8::StartupData natives; | 522 v8::StartupData natives; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 532 RenderPdf(filename, file_contents, file_length, options); | 548 RenderPdf(filename, file_contents, file_length, options); |
| 533 free(file_contents); | 549 free(file_contents); |
| 534 } | 550 } |
| 535 | 551 |
| 536 FPDF_DestroyLibrary(); | 552 FPDF_DestroyLibrary(); |
| 537 v8::V8::ShutdownPlatform(); | 553 v8::V8::ShutdownPlatform(); |
| 538 delete platform; | 554 delete platform; |
| 539 | 555 |
| 540 return 0; | 556 return 0; |
| 541 } | 557 } |
| OLD | NEW |