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

Side by Side Diff: samples/pdfium_test.cc

Issue 477873003: Fix a hang issue due to inconsistent page number in the test file (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 4 months 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 | « core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 (void) FPDFAvail_IsPageAvail(pdf_avail, first_page, &hints); 297 (void) FPDFAvail_IsPageAvail(pdf_avail, first_page, &hints);
298 298
299 int page_count = FPDF_GetPageCount(doc); 299 int page_count = FPDF_GetPageCount(doc);
300 for (int i = 0; i < page_count; ++i) { 300 for (int i = 0; i < page_count; ++i) {
301 (void) FPDFAvail_IsPageAvail(pdf_avail, i, &hints); 301 (void) FPDFAvail_IsPageAvail(pdf_avail, i, &hints);
302 } 302 }
303 303
304 FORM_DoDocumentJSAction(form); 304 FORM_DoDocumentJSAction(form);
305 FORM_DoDocumentOpenAction(form); 305 FORM_DoDocumentOpenAction(form);
306 306
307 size_t rendered_pages = 0;
308 size_t bad_pages = 0;
307 for (int i = 0; i < page_count; ++i) { 309 for (int i = 0; i < page_count; ++i) {
308 FPDF_PAGE page = FPDF_LoadPage(doc, i); 310 FPDF_PAGE page = FPDF_LoadPage(doc, i);
311 if (!page) {
312 bad_pages ++;
313 continue;
314 }
309 FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); 315 FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page);
310 FORM_OnAfterLoadPage(page, form); 316 FORM_OnAfterLoadPage(page, form);
311 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN); 317 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN);
312 318
313 int width = static_cast<int>(FPDF_GetPageWidth(page)); 319 int width = static_cast<int>(FPDF_GetPageWidth(page));
314 int height = static_cast<int>(FPDF_GetPageHeight(page)); 320 int height = static_cast<int>(FPDF_GetPageHeight(page));
315 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0); 321 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0);
316 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); 322 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF);
317 323
318 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); 324 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0);
325 rendered_pages ++;
326
319 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); 327 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0);
320 int stride = FPDFBitmap_GetStride(bitmap); 328 int stride = FPDFBitmap_GetStride(bitmap);
321 const char* buffer = 329 const char* buffer =
322 reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap)); 330 reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap));
323 331
324 switch (format) { 332 switch (format) {
325 #ifdef _WIN32 333 #ifdef _WIN32
326 case OUTPUT_BMP: 334 case OUTPUT_BMP:
327 WriteBmp(name, i, buffer, stride, width, height); 335 WriteBmp(name, i, buffer, stride, width, height);
328 break; 336 break;
(...skipping 15 matching lines...) Expand all
344 FORM_OnBeforeClosePage(page, form); 352 FORM_OnBeforeClosePage(page, form);
345 FPDFText_ClosePage(text_page); 353 FPDFText_ClosePage(text_page);
346 FPDF_ClosePage(page); 354 FPDF_ClosePage(page);
347 } 355 }
348 356
349 FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC); 357 FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC);
350 FPDFDOC_ExitFormFillEnviroument(form); 358 FPDFDOC_ExitFormFillEnviroument(form);
351 FPDF_CloseDocument(doc); 359 FPDF_CloseDocument(doc);
352 FPDFAvail_Destroy(pdf_avail); 360 FPDFAvail_Destroy(pdf_avail);
353 361
354 printf("Loaded, parsed and rendered %d pages.\n", page_count); 362 printf("Loaded, parsed and rendered %d pages.\n", rendered_pages);
363 printf("Skipped %d bad pages.\n", bad_pages);
355 } 364 }
356 365
357 int main(int argc, const char* argv[]) { 366 int main(int argc, const char* argv[]) {
358 v8::V8::InitializeICU(); 367 v8::V8::InitializeICU();
359 OutputFormat format = OUTPUT_NONE; 368 OutputFormat format = OUTPUT_NONE;
360 std::list<const char*> files; 369 std::list<const char*> files;
361 if (!ParseCommandLine(argc, argv, &format, &files)) { 370 if (!ParseCommandLine(argc, argv, &format, &files)) {
362 printf("Usage: pdfium_test [OPTION] [FILE]...\n"); 371 printf("Usage: pdfium_test [OPTION] [FILE]...\n");
363 printf("--ppm write page images <pdf-name>.<page-number>.ppm\n"); 372 printf("--ppm write page images <pdf-name>.<page-number>.ppm\n");
364 #ifdef _WIN32 373 #ifdef _WIN32
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 } else { 405 } else {
397 RenderPdf(filename, pBuf, len, format); 406 RenderPdf(filename, pBuf, len, format);
398 } 407 }
399 free(pBuf); 408 free(pBuf);
400 } 409 }
401 410
402 FPDF_DestroyLibrary(); 411 FPDF_DestroyLibrary();
403 412
404 return 0; 413 return 0;
405 } 414 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698