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

Side by Side Diff: samples/pdfium_test.cc

Issue 343303004: Explicitly use binary mode when opening files in the pdfium_test sample. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 6 years, 6 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 | « AUTHORS ('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>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 13
14 #include "../fpdfsdk/include/fpdf_dataavail.h" 14 #include "../fpdfsdk/include/fpdf_dataavail.h"
15 #include "../fpdfsdk/include/fpdf_ext.h" 15 #include "../fpdfsdk/include/fpdf_ext.h"
16 #include "../fpdfsdk/include/fpdfformfill.h" 16 #include "../fpdfsdk/include/fpdfformfill.h"
17 #include "../fpdfsdk/include/fpdftext.h" 17 #include "../fpdfsdk/include/fpdftext.h"
18 #include "../fpdfsdk/include/fpdfview.h" 18 #include "../fpdfsdk/include/fpdfview.h"
19 #include "v8/include/v8.h" 19 #include "v8/include/v8.h"
20 20
21 #ifdef _WIN32 21 #ifdef _WIN32
22 #define snprintf _snprintf 22 #define snprintf _snprintf
23 /* in Windows, rb for open and read binary file */
24 #define FOPEN_READ "rb"
25 #else
26 #define FOPEN_READ "r"
27 #endif 23 #endif
28 24
29 static void WritePpm(const char* pdf_name, int num, 25 static void WritePpm(const char* pdf_name, int num,
30 const char* buffer, int stride, int width, int height) { 26 const char* buffer, int stride, int width, int height) {
31 if (stride < 0 || width < 0 || height < 0) 27 if (stride < 0 || width < 0 || height < 0)
32 return; 28 return;
33 if (height > 0 && width > INT_MAX / height) 29 if (height > 0 && width > INT_MAX / height)
34 return; 30 return;
35 int out_len = width * height; 31 int out_len = width * height;
36 if (out_len > INT_MAX / 3) 32 if (out_len > INT_MAX / 3)
37 return; 33 return;
38 out_len *= 3; 34 out_len *= 3;
39 35
40 char filename[256]; 36 char filename[256];
41 snprintf(filename, sizeof(filename), "%s.%d.ppm", pdf_name, num); 37 snprintf(filename, sizeof(filename), "%s.%d.ppm", pdf_name, num);
42 FILE* fp = fopen(filename, "w"); 38 FILE* fp = fopen(filename, "wb");
43 if (!fp) 39 if (!fp)
44 return; 40 return;
45 fprintf(fp, "P6\n# PDF test render\n%d %d\n255\n", width, height); 41 fprintf(fp, "P6\n# PDF test render\n%d %d\n255\n", width, height);
46 // Source data is B, G, R, unused. 42 // Source data is B, G, R, unused.
47 // Dest data is R, G, B. 43 // Dest data is R, G, B.
48 char* result = new char[out_len]; 44 char* result = new char[out_len];
49 if (result) { 45 if (result) {
50 for (int h = 0; h < height; ++h) { 46 for (int h = 0; h < height; ++h) {
51 const char* src_line = buffer + (stride * h); 47 const char* src_line = buffer + (stride * h);
52 char* dest_line = result + (width * h * 3); 48 char* dest_line = result + (width * h * 3);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 UNSUPPORT_INFO unsuppored_info; 272 UNSUPPORT_INFO unsuppored_info;
277 memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); 273 memset(&unsuppored_info, '\0', sizeof(unsuppored_info));
278 unsuppored_info.version = 1; 274 unsuppored_info.version = 1;
279 unsuppored_info.FSDK_UnSupport_Handler = Unsupported_Handler; 275 unsuppored_info.FSDK_UnSupport_Handler = Unsupported_Handler;
280 276
281 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); 277 FSDK_SetUnSpObjProcessHandler(&unsuppored_info);
282 278
283 while (!files.empty()) { 279 while (!files.empty()) {
284 const char* filename = files.front(); 280 const char* filename = files.front();
285 files.pop_front(); 281 files.pop_front();
286 FILE* file = fopen(filename, FOPEN_READ); 282 FILE* file = fopen(filename, "rb");
287 if (!file) { 283 if (!file) {
288 fprintf(stderr, "Failed to open: %s\n", filename); 284 fprintf(stderr, "Failed to open: %s\n", filename);
289 continue; 285 continue;
290 } 286 }
291 (void) fseek(file, 0, SEEK_END); 287 (void) fseek(file, 0, SEEK_END);
292 size_t len = ftell(file); 288 size_t len = ftell(file);
293 (void) fseek(file, 0, SEEK_SET); 289 (void) fseek(file, 0, SEEK_SET);
294 char* pBuf = (char*) malloc(len); 290 char* pBuf = (char*) malloc(len);
295 size_t ret = fread(pBuf, 1, len, file); 291 size_t ret = fread(pBuf, 1, len, file);
296 (void) fclose(file); 292 (void) fclose(file);
297 if (ret != len) { 293 if (ret != len) {
298 fprintf(stderr, "Failed to read: %s\n", filename); 294 fprintf(stderr, "Failed to read: %s\n", filename);
299 } else { 295 } else {
300 RenderPdf(filename, pBuf, len, write_images); 296 RenderPdf(filename, pBuf, len, write_images);
301 } 297 }
302 free(pBuf); 298 free(pBuf);
303 } 299 }
304 300
305 FPDF_DestroyLibrary(); 301 FPDF_DestroyLibrary();
306 302
307 return 0; 303 return 0;
308 } 304 }
309 305
OLDNEW
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698