You need to sign in before continuing.

Commit cb769c62e55599e9f980001830bc61d9fcaa64a9

Authored by Jay Berkenbilt
1 parent 716381f6

WHITESPACE ONLY -- expand tabs in source code

This comment expands all tabs using an 8-character tab-width. You
should ignore this commit when using git blame or use git blame -w.

In the early days, I used to use tabs where possible for indentation,
since emacs did this automatically. In recent years, I have switched
to only using spaces, which means qpdf source code has been a mixture
of spaces and tabs. I have avoided cleaning this up because of not
wanting gratuitous whitespaces change to cloud the output of git
blame, but I changed my mind after discussing with users who view qpdf
source code in editors/IDEs that have other tab widths by default and
in light of the fact that I am planning to start applying automatic
code formatting soon.
Showing 157 changed files with 8717 additions and 8717 deletions

Too many changes.

To preserve performance only 100 of 157 files are displayed.

examples/pdf-attach-file.cc
@@ -150,7 +150,7 @@ int main(int argc, char* argv[]) @@ -150,7 +150,7 @@ int main(int argc, char* argv[])
150 // For libtool's sake.... 150 // For libtool's sake....
151 if (strncmp(whoami, "lt-", 3) == 0) 151 if (strncmp(whoami, "lt-", 3) == 0)
152 { 152 {
153 - whoami += 3; 153 + whoami += 3;
154 } 154 }
155 155
156 char const* infilename = 0; 156 char const* infilename = 0;
@@ -216,9 +216,9 @@ int main(int argc, char* argv[]) @@ -216,9 +216,9 @@ int main(int argc, char* argv[])
216 } 216 }
217 catch (std::exception &e) 217 catch (std::exception &e)
218 { 218 {
219 - std::cerr << whoami << " exception: "  
220 - << e.what() << std::endl;  
221 - exit(2); 219 + std::cerr << whoami << " exception: "
  220 + << e.what() << std::endl;
  221 + exit(2);
222 } 222 }
223 223
224 return 0; 224 return 0;
examples/pdf-bookmarks.cc
@@ -20,16 +20,16 @@ static std::map&lt;QPDFObjGen, int&gt; page_map; @@ -20,16 +20,16 @@ static std::map&lt;QPDFObjGen, int&gt; page_map;
20 void usage() 20 void usage()
21 { 21 {
22 std::cerr << "Usage: " << whoami << " [options] file.pdf [password]" 22 std::cerr << "Usage: " << whoami << " [options] file.pdf [password]"
23 - << std::endl  
24 - << "Options:" << std::endl  
25 - << " --numbers give bookmarks outline-style numbers"  
26 - << std::endl  
27 - << " --lines draw lines to show bookmark hierarchy"  
28 - << std::endl  
29 - << " --show-open indicate whether a bookmark is initially open"  
30 - << std::endl  
31 - << " --show-targets show target if possible"  
32 - << std::endl; 23 + << std::endl
  24 + << "Options:" << std::endl
  25 + << " --numbers give bookmarks outline-style numbers"
  26 + << std::endl
  27 + << " --lines draw lines to show bookmark hierarchy"
  28 + << std::endl
  29 + << " --show-open indicate whether a bookmark is initially open"
  30 + << std::endl
  31 + << " --show-targets show target if possible"
  32 + << std::endl;
33 exit(2); 33 exit(2);
34 } 34 }
35 35
@@ -37,14 +37,14 @@ void print_lines(std::vector&lt;int&gt;&amp; numbers) @@ -37,14 +37,14 @@ void print_lines(std::vector&lt;int&gt;&amp; numbers)
37 { 37 {
38 for (unsigned int i = 0; i < numbers.size() - 1; ++i) 38 for (unsigned int i = 0; i < numbers.size() - 1; ++i)
39 { 39 {
40 - if (numbers.at(i))  
41 - {  
42 - std::cout << "| ";  
43 - }  
44 - else  
45 - {  
46 - std::cout << " ";  
47 - } 40 + if (numbers.at(i))
  41 + {
  42 + std::cout << "| ";
  43 + }
  44 + else
  45 + {
  46 + std::cout << " ";
  47 + }
48 } 48 }
49 } 49 }
50 50
@@ -54,10 +54,10 @@ void generate_page_map(QPDF&amp; qpdf) @@ -54,10 +54,10 @@ void generate_page_map(QPDF&amp; qpdf)
54 std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); 54 std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
55 int n = 0; 55 int n = 0;
56 for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); 56 for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
57 - iter != pages.end(); ++iter) 57 + iter != pages.end(); ++iter)
58 { 58 {
59 - QPDFObjectHandle oh = (*iter).getObjectHandle();  
60 - page_map[oh.getObjGen()] = ++n; 59 + QPDFObjectHandle oh = (*iter).getObjectHandle();
  60 + page_map[oh.getObjGen()] = ++n;
61 } 61 }
62 } 62 }
63 63
@@ -163,50 +163,50 @@ int main(int argc, char* argv[]) @@ -163,50 +163,50 @@ int main(int argc, char* argv[])
163 // For libtool's sake.... 163 // For libtool's sake....
164 if (strncmp(whoami, "lt-", 3) == 0) 164 if (strncmp(whoami, "lt-", 3) == 0)
165 { 165 {
166 - whoami += 3; 166 + whoami += 3;
167 } 167 }
168 168
169 if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) 169 if ((argc == 2) && (strcmp(argv[1], "--version") == 0))
170 { 170 {
171 - std::cout << whoami << " version 1.5" << std::endl;  
172 - exit(0); 171 + std::cout << whoami << " version 1.5" << std::endl;
  172 + exit(0);
173 } 173 }
174 174
175 int arg; 175 int arg;
176 for (arg = 1; arg < argc; ++arg) 176 for (arg = 1; arg < argc; ++arg)
177 { 177 {
178 - if (argv[arg][0] == '-')  
179 - {  
180 - if (strcmp(argv[arg], "--numbers") == 0)  
181 - {  
182 - style = st_numbers;  
183 - }  
184 - else if (strcmp(argv[arg], "--lines") == 0)  
185 - {  
186 - style = st_lines;  
187 - }  
188 - else if (strcmp(argv[arg], "--show-open") == 0)  
189 - {  
190 - show_open = true;  
191 - }  
192 - else if (strcmp(argv[arg], "--show-targets") == 0)  
193 - {  
194 - show_targets = true;  
195 - }  
196 - else  
197 - {  
198 - usage();  
199 - }  
200 - }  
201 - else  
202 - {  
203 - break;  
204 - } 178 + if (argv[arg][0] == '-')
  179 + {
  180 + if (strcmp(argv[arg], "--numbers") == 0)
  181 + {
  182 + style = st_numbers;
  183 + }
  184 + else if (strcmp(argv[arg], "--lines") == 0)
  185 + {
  186 + style = st_lines;
  187 + }
  188 + else if (strcmp(argv[arg], "--show-open") == 0)
  189 + {
  190 + show_open = true;
  191 + }
  192 + else if (strcmp(argv[arg], "--show-targets") == 0)
  193 + {
  194 + show_targets = true;
  195 + }
  196 + else
  197 + {
  198 + usage();
  199 + }
  200 + }
  201 + else
  202 + {
  203 + break;
  204 + }
205 } 205 }
206 206
207 if (arg >= argc) 207 if (arg >= argc)
208 { 208 {
209 - usage(); 209 + usage();
210 } 210 }
211 211
212 char const* filename = argv[arg++]; 212 char const* filename = argv[arg++];
@@ -214,38 +214,38 @@ int main(int argc, char* argv[]) @@ -214,38 +214,38 @@ int main(int argc, char* argv[])
214 214
215 if (arg < argc) 215 if (arg < argc)
216 { 216 {
217 - password = argv[arg++]; 217 + password = argv[arg++];
218 } 218 }
219 if (arg != argc) 219 if (arg != argc)
220 { 220 {
221 - usage(); 221 + usage();
222 } 222 }
223 223
224 try 224 try
225 { 225 {
226 - QPDF qpdf;  
227 - qpdf.processFile(filename, password); 226 + QPDF qpdf;
  227 + qpdf.processFile(filename, password);
228 228
229 QPDFOutlineDocumentHelper odh(qpdf); 229 QPDFOutlineDocumentHelper odh(qpdf);
230 - if (odh.hasOutlines())  
231 - {  
232 - std::vector<int> numbers;  
233 - if (show_targets)  
234 - {  
235 - generate_page_map(qpdf);  
236 - }  
237 - extract_bookmarks(odh.getTopLevelOutlines(), numbers);  
238 - }  
239 - else  
240 - {  
241 - std::cout << filename << " has no bookmarks" << std::endl;  
242 - } 230 + if (odh.hasOutlines())
  231 + {
  232 + std::vector<int> numbers;
  233 + if (show_targets)
  234 + {
  235 + generate_page_map(qpdf);
  236 + }
  237 + extract_bookmarks(odh.getTopLevelOutlines(), numbers);
  238 + }
  239 + else
  240 + {
  241 + std::cout << filename << " has no bookmarks" << std::endl;
  242 + }
243 } 243 }
244 catch (std::exception &e) 244 catch (std::exception &e)
245 { 245 {
246 - std::cerr << whoami << " processing file " << filename << ": "  
247 - << e.what() << std::endl;  
248 - exit(2); 246 + std::cerr << whoami << " processing file " << filename << ": "
  247 + << e.what() << std::endl;
  248 + exit(2);
249 } 249 }
250 250
251 return 0; 251 return 0;
examples/pdf-c-objects.c
@@ -58,20 +58,20 @@ int main(int argc, char* argv[]) @@ -58,20 +58,20 @@ int main(int argc, char* argv[])
58 58
59 if ((p = strrchr(argv[0], '/')) != NULL) 59 if ((p = strrchr(argv[0], '/')) != NULL)
60 { 60 {
61 - whoami = p + 1; 61 + whoami = p + 1;
62 } 62 }
63 else if ((p = strrchr(argv[0], '\\')) != NULL) 63 else if ((p = strrchr(argv[0], '\\')) != NULL)
64 { 64 {
65 - whoami = p + 1; 65 + whoami = p + 1;
66 } 66 }
67 else 67 else
68 { 68 {
69 - whoami = argv[0]; 69 + whoami = argv[0];
70 } 70 }
71 71
72 if (argc != 4) 72 if (argc != 4)
73 { 73 {
74 - usage(); 74 + usage();
75 } 75 }
76 76
77 infile = argv[1]; 77 infile = argv[1];
@@ -80,34 +80,34 @@ int main(int argc, char* argv[]) @@ -80,34 +80,34 @@ int main(int argc, char* argv[])
80 80
81 if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) && 81 if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) &&
82 modify_file(qpdf) && 82 modify_file(qpdf) &&
83 - ((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0)) 83 + ((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0))
84 { 84 {
85 /* Use static ID for testing only. For production, a 85 /* Use static ID for testing only. For production, a
86 * non-static ID is used. See also 86 * non-static ID is used. See also
87 * qpdf_set_deterministic_ID. */ 87 * qpdf_set_deterministic_ID. */
88 - qpdf_set_static_ID(qpdf, QPDF_TRUE); /* for testing only */  
89 - qpdf_write(qpdf); 88 + qpdf_set_static_ID(qpdf, QPDF_TRUE); /* for testing only */
  89 + qpdf_write(qpdf);
90 } 90 }
91 while (qpdf_more_warnings(qpdf)) 91 while (qpdf_more_warnings(qpdf))
92 { 92 {
93 - warnings = 1;  
94 - printf("warning: %s\n",  
95 - qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf))); 93 + warnings = 1;
  94 + printf("warning: %s\n",
  95 + qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf)));
96 } 96 }
97 if (qpdf_has_error(qpdf)) 97 if (qpdf_has_error(qpdf))
98 { 98 {
99 - errors = 1;  
100 - printf("error: %s\n",  
101 - qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf))); 99 + errors = 1;
  100 + printf("error: %s\n",
  101 + qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf)));
102 } 102 }
103 qpdf_cleanup(&qpdf); 103 qpdf_cleanup(&qpdf);
104 if (errors) 104 if (errors)
105 { 105 {
106 - return 2; 106 + return 2;
107 } 107 }
108 else if (warnings) 108 else if (warnings)
109 { 109 {
110 - return 3; 110 + return 3;
111 } 111 }
112 112
113 return 0; 113 return 0;
examples/pdf-count-strings.cc
@@ -20,7 +20,7 @@ static char const* whoami = 0; @@ -20,7 +20,7 @@ static char const* whoami = 0;
20 void usage() 20 void usage()
21 { 21 {
22 std::cerr << "Usage: " << whoami << " infile" << std::endl 22 std::cerr << "Usage: " << whoami << " infile" << std::endl
23 - << "Applies token filters to infile" 23 + << "Applies token filters to infile"
24 << std::endl; 24 << std::endl;
25 exit(2); 25 exit(2);
26 } 26 }
@@ -78,19 +78,19 @@ int main(int argc, char* argv[]) @@ -78,19 +78,19 @@ int main(int argc, char* argv[])
78 // For libtool's sake.... 78 // For libtool's sake....
79 if (strncmp(whoami, "lt-", 3) == 0) 79 if (strncmp(whoami, "lt-", 3) == 0)
80 { 80 {
81 - whoami += 3; 81 + whoami += 3;
82 } 82 }
83 83
84 if (argc != 2) 84 if (argc != 2)
85 { 85 {
86 - usage(); 86 + usage();
87 } 87 }
88 char const* infilename = argv[1]; 88 char const* infilename = argv[1];
89 89
90 try 90 try
91 { 91 {
92 - QPDF pdf;  
93 - pdf.processFile(infilename); 92 + QPDF pdf;
  93 + pdf.processFile(infilename);
94 std::vector<QPDFPageObjectHelper> pages = 94 std::vector<QPDFPageObjectHelper> pages =
95 QPDFPageDocumentHelper(pdf).getAllPages(); 95 QPDFPageDocumentHelper(pdf).getAllPages();
96 int pageno = 0; 96 int pageno = 0;
@@ -123,8 +123,8 @@ int main(int argc, char* argv[]) @@ -123,8 +123,8 @@ int main(int argc, char* argv[])
123 } 123 }
124 catch (std::exception& e) 124 catch (std::exception& e)
125 { 125 {
126 - std::cerr << whoami << ": " << e.what() << std::endl;  
127 - exit(2); 126 + std::cerr << whoami << ": " << e.what() << std::endl;
  127 + exit(2);
128 } 128 }
129 129
130 return 0; 130 return 0;
examples/pdf-create.cc
@@ -31,7 +31,7 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider @@ -31,7 +31,7 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider
31 std::string const& filter); 31 std::string const& filter);
32 virtual ~ImageProvider(); 32 virtual ~ImageProvider();
33 virtual void provideStreamData(int objid, int generation, 33 virtual void provideStreamData(int objid, int generation,
34 - Pipeline* pipeline); 34 + Pipeline* pipeline);
35 size_t getWidth() const; 35 size_t getWidth() const;
36 size_t getHeight() const; 36 size_t getHeight() const;
37 37
@@ -142,7 +142,7 @@ ImageProvider::provideStreamData(int objid, int generation, @@ -142,7 +142,7 @@ ImageProvider::provideStreamData(int objid, int generation,
142 void usage() 142 void usage()
143 { 143 {
144 std::cerr << "Usage: " << whoami << " filename" << std::endl 144 std::cerr << "Usage: " << whoami << " filename" << std::endl
145 - << "Creates a simple PDF and writes it to filename" << std::endl; 145 + << "Creates a simple PDF and writes it to filename" << std::endl;
146 exit(2); 146 exit(2);
147 } 147 }
148 148
@@ -424,22 +424,22 @@ int main(int argc, char* argv[]) @@ -424,22 +424,22 @@ int main(int argc, char* argv[])
424 // For libtool's sake.... 424 // For libtool's sake....
425 if (strncmp(whoami, "lt-", 3) == 0) 425 if (strncmp(whoami, "lt-", 3) == 0)
426 { 426 {
427 - whoami += 3; 427 + whoami += 3;
428 } 428 }
429 if (argc != 2) 429 if (argc != 2)
430 { 430 {
431 - usage(); 431 + usage();
432 } 432 }
433 char const* filename = argv[1]; 433 char const* filename = argv[1];
434 434
435 try 435 try
436 { 436 {
437 - create_pdf(filename); 437 + create_pdf(filename);
438 } 438 }
439 catch (std::exception& e) 439 catch (std::exception& e)
440 { 440 {
441 - std::cerr << e.what() << std::endl;  
442 - exit(2); 441 + std::cerr << e.what() << std::endl;
  442 + exit(2);
443 } 443 }
444 444
445 return 0; 445 return 0;
examples/pdf-custom-filter.cc
@@ -207,7 +207,7 @@ class StreamReplacer: public QPDFObjectHandle::StreamDataProvider @@ -207,7 +207,7 @@ class StreamReplacer: public QPDFObjectHandle::StreamDataProvider
207 StreamReplacer(QPDF* pdf); 207 StreamReplacer(QPDF* pdf);
208 virtual ~StreamReplacer() = default; 208 virtual ~StreamReplacer() = default;
209 virtual void provideStreamData(int objid, int generation, 209 virtual void provideStreamData(int objid, int generation,
210 - Pipeline* pipeline) override; 210 + Pipeline* pipeline) override;
211 211
212 void registerStream( 212 void registerStream(
213 QPDFObjectHandle stream, 213 QPDFObjectHandle stream,
@@ -473,7 +473,7 @@ int main(int argc, char* argv[]) @@ -473,7 +473,7 @@ int main(int argc, char* argv[])
473 // For libtool's sake.... 473 // For libtool's sake....
474 if (strncmp(whoami, "lt-", 3) == 0) 474 if (strncmp(whoami, "lt-", 3) == 0)
475 { 475 {
476 - whoami += 3; 476 + whoami += 3;
477 } 477 }
478 478
479 char const* infilename = 0; 479 char const* infilename = 0;
@@ -517,7 +517,7 @@ int main(int argc, char* argv[]) @@ -517,7 +517,7 @@ int main(int argc, char* argv[])
517 catch (std::exception &e) 517 catch (std::exception &e)
518 { 518 {
519 std::cerr << whoami << ": exception: " << e.what() << std::endl; 519 std::cerr << whoami << ": exception: " << e.what() << std::endl;
520 - exit(2); 520 + exit(2);
521 } 521 }
522 522
523 return 0; 523 return 0;
examples/pdf-double-page-size.cc
@@ -13,9 +13,9 @@ static char const* whoami = 0; @@ -13,9 +13,9 @@ static char const* whoami = 0;
13 void usage() 13 void usage()
14 { 14 {
15 std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" 15 std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]"
16 - << std::endl  
17 - << "Double size of all pages in infile.pdf;"  
18 - << " write output to outfile.pdf" << std::endl; 16 + << std::endl
  17 + << "Double size of all pages in infile.pdf;"
  18 + << " write output to outfile.pdf" << std::endl;
19 exit(2); 19 exit(2);
20 } 20 }
21 21
@@ -26,18 +26,18 @@ static void doubleBoxSize(QPDFObjectHandle&amp; page, char const* box_name) @@ -26,18 +26,18 @@ static void doubleBoxSize(QPDFObjectHandle&amp; page, char const* box_name)
26 QPDFObjectHandle box = page.getKey(box_name); 26 QPDFObjectHandle box = page.getKey(box_name);
27 if (box.isNull()) 27 if (box.isNull())
28 { 28 {
29 - return; 29 + return;
30 } 30 }
31 if (! (box.isArray() && (box.getArrayNItems() == 4))) 31 if (! (box.isArray() && (box.getArrayNItems() == 4)))
32 { 32 {
33 - throw std::runtime_error(std::string("box ") + box_name +  
34 - " is not an array of four elements"); 33 + throw std::runtime_error(std::string("box ") + box_name +
  34 + " is not an array of four elements");
35 } 35 }
36 std::vector<QPDFObjectHandle> doubled; 36 std::vector<QPDFObjectHandle> doubled;
37 for (int i = 0; i < 4; ++i) 37 for (int i = 0; i < 4; ++i)
38 { 38 {
39 - doubled.push_back(  
40 - QPDFObjectHandle::newReal( 39 + doubled.push_back(
  40 + QPDFObjectHandle::newReal(
41 box.getArrayItem(i).getNumericValue() * 2.0, 2)); 41 box.getArrayItem(i).getNumericValue() * 2.0, 2));
42 } 42 }
43 page.replaceKey(box_name, QPDFObjectHandle::newArray(doubled)); 43 page.replaceKey(box_name, QPDFObjectHandle::newArray(doubled));
@@ -50,7 +50,7 @@ int main(int argc, char* argv[]) @@ -50,7 +50,7 @@ int main(int argc, char* argv[])
50 // For libtool's sake.... 50 // For libtool's sake....
51 if (strncmp(whoami, "lt-", 3) == 0) 51 if (strncmp(whoami, "lt-", 3) == 0)
52 { 52 {
53 - whoami += 3; 53 + whoami += 3;
54 } 54 }
55 55
56 // For test suite 56 // For test suite
@@ -64,7 +64,7 @@ int main(int argc, char* argv[]) @@ -64,7 +64,7 @@ int main(int argc, char* argv[])
64 64
65 if (! ((argc == 3) || (argc == 4))) 65 if (! ((argc == 3) || (argc == 4)))
66 { 66 {
67 - usage(); 67 + usage();
68 } 68 }
69 69
70 char const* infilename = argv[1]; 70 char const* infilename = argv[1];
@@ -76,48 +76,48 @@ int main(int argc, char* argv[]) @@ -76,48 +76,48 @@ int main(int argc, char* argv[])
76 76
77 try 77 try
78 { 78 {
79 - QPDF qpdf;  
80 - qpdf.processFile(infilename, password); 79 + QPDF qpdf;
  80 + qpdf.processFile(infilename, password);
81 81
82 - std::vector<QPDFPageObjectHelper> pages = 82 + std::vector<QPDFPageObjectHelper> pages =
83 QPDFPageDocumentHelper(qpdf).getAllPages(); 83 QPDFPageDocumentHelper(qpdf).getAllPages();
84 - for (std::vector<QPDFPageObjectHelper>::iterator iter = 84 + for (std::vector<QPDFPageObjectHelper>::iterator iter =
85 pages.begin(); 85 pages.begin();
86 - iter != pages.end(); ++iter)  
87 - { 86 + iter != pages.end(); ++iter)
  87 + {
88 QPDFPageObjectHelper& ph(*iter); 88 QPDFPageObjectHelper& ph(*iter);
89 - QPDFObjectHandle page = ph.getObjectHandle(); 89 + QPDFObjectHandle page = ph.getObjectHandle();
90 90
91 - // Prepend the buffer to the page's contents  
92 - ph.addPageContents( 91 + // Prepend the buffer to the page's contents
  92 + ph.addPageContents(
93 QPDFObjectHandle::newStream(&qpdf, content), true); 93 QPDFObjectHandle::newStream(&qpdf, content), true);
94 94
95 - // Double the size of each of the content boxes  
96 - doubleBoxSize(page, "/MediaBox");  
97 - doubleBoxSize(page, "/CropBox");  
98 - doubleBoxSize(page, "/BleedBox");  
99 - doubleBoxSize(page, "/TrimBox");  
100 - doubleBoxSize(page, "/ArtBox");  
101 - } 95 + // Double the size of each of the content boxes
  96 + doubleBoxSize(page, "/MediaBox");
  97 + doubleBoxSize(page, "/CropBox");
  98 + doubleBoxSize(page, "/BleedBox");
  99 + doubleBoxSize(page, "/TrimBox");
  100 + doubleBoxSize(page, "/ArtBox");
  101 + }
102 102
103 - // Write out a new file  
104 - QPDFWriter w(qpdf, outfilename);  
105 - if (static_id)  
106 - {  
107 - // For the test suite, uncompress streams and use static  
108 - // IDs.  
109 - w.setStaticID(true); // for testing only  
110 - w.setStreamDataMode(qpdf_s_uncompress);  
111 - }  
112 - w.write();  
113 - std::cout << whoami << ": new file written to " << outfilename  
114 - << std::endl; 103 + // Write out a new file
  104 + QPDFWriter w(qpdf, outfilename);
  105 + if (static_id)
  106 + {
  107 + // For the test suite, uncompress streams and use static
  108 + // IDs.
  109 + w.setStaticID(true); // for testing only
  110 + w.setStreamDataMode(qpdf_s_uncompress);
  111 + }
  112 + w.write();
  113 + std::cout << whoami << ": new file written to " << outfilename
  114 + << std::endl;
115 } 115 }
116 catch (std::exception &e) 116 catch (std::exception &e)
117 { 117 {
118 - std::cerr << whoami << " processing file " << infilename << ": "  
119 - << e.what() << std::endl;  
120 - exit(2); 118 + std::cerr << whoami << " processing file " << infilename << ": "
  119 + << e.what() << std::endl;
  120 + exit(2);
121 } 121 }
122 122
123 return 0; 123 return 0;
examples/pdf-filter-tokens.cc
@@ -23,7 +23,7 @@ static char const* whoami = 0; @@ -23,7 +23,7 @@ static char const* whoami = 0;
23 void usage() 23 void usage()
24 { 24 {
25 std::cerr << "Usage: " << whoami << " infile outfile" << std::endl 25 std::cerr << "Usage: " << whoami << " infile outfile" << std::endl
26 - << "Applies token filters to infile and writes outfile" 26 + << "Applies token filters to infile and writes outfile"
27 << std::endl; 27 << std::endl;
28 exit(2); 28 exit(2);
29 } 29 }
@@ -195,20 +195,20 @@ int main(int argc, char* argv[]) @@ -195,20 +195,20 @@ int main(int argc, char* argv[])
195 // For libtool's sake.... 195 // For libtool's sake....
196 if (strncmp(whoami, "lt-", 3) == 0) 196 if (strncmp(whoami, "lt-", 3) == 0)
197 { 197 {
198 - whoami += 3; 198 + whoami += 3;
199 } 199 }
200 200
201 if (argc != 3) 201 if (argc != 3)
202 { 202 {
203 - usage(); 203 + usage();
204 } 204 }
205 char const* infilename = argv[1]; 205 char const* infilename = argv[1];
206 char const* outfilename = argv[2]; 206 char const* outfilename = argv[2];
207 207
208 try 208 try
209 { 209 {
210 - QPDF pdf;  
211 - pdf.processFile(infilename); 210 + QPDF pdf;
  211 + pdf.processFile(infilename);
212 std::vector<QPDFPageObjectHelper> pages = 212 std::vector<QPDFPageObjectHelper> pages =
213 QPDFPageDocumentHelper(pdf).getAllPages(); 213 QPDFPageDocumentHelper(pdf).getAllPages();
214 for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin(); 214 for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
@@ -233,8 +233,8 @@ int main(int argc, char* argv[]) @@ -233,8 +233,8 @@ int main(int argc, char* argv[])
233 } 233 }
234 catch (std::exception& e) 234 catch (std::exception& e)
235 { 235 {
236 - std::cerr << whoami << ": " << e.what() << std::endl;  
237 - exit(2); 236 + std::cerr << whoami << ": " << e.what() << std::endl;
  237 + exit(2);
238 } 238 }
239 239
240 return 0; 240 return 0;
examples/pdf-invert-images.cc
@@ -14,9 +14,9 @@ static char const* whoami = 0; @@ -14,9 +14,9 @@ static char const* whoami = 0;
14 void usage() 14 void usage()
15 { 15 {
16 std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" 16 std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]"
17 - << std::endl  
18 - << "Invert some images in infile.pdf;"  
19 - << " write output to outfile.pdf" << std::endl; 17 + << std::endl
  18 + << "Invert some images in infile.pdf;"
  19 + << " write output to outfile.pdf" << std::endl;
20 exit(2); 20 exit(2);
21 } 21 }
22 22
@@ -36,7 +36,7 @@ class ImageInverter: public QPDFObjectHandle::StreamDataProvider @@ -36,7 +36,7 @@ class ImageInverter: public QPDFObjectHandle::StreamDataProvider
36 { 36 {
37 } 37 }
38 virtual void provideStreamData(int objid, int generation, 38 virtual void provideStreamData(int objid, int generation,
39 - Pipeline* pipeline) override; 39 + Pipeline* pipeline) override;
40 40
41 void registerImage( 41 void registerImage(
42 QPDFObjectHandle image, 42 QPDFObjectHandle image,
@@ -80,13 +80,13 @@ ImageInverter::registerImage( @@ -80,13 +80,13 @@ ImageInverter::registerImage(
80 // with it explicitly here. We could explicitly use /DCTDecode and 80 // with it explicitly here. We could explicitly use /DCTDecode and
81 // write through a DCT filter if we wanted. 81 // write through a DCT filter if we wanted.
82 image.replaceStreamData(self, 82 image.replaceStreamData(self,
83 - QPDFObjectHandle::newNull(),  
84 - QPDFObjectHandle::newNull()); 83 + QPDFObjectHandle::newNull(),
  84 + QPDFObjectHandle::newNull());
85 } 85 }
86 86
87 void 87 void
88 ImageInverter::provideStreamData(int objid, int generation, 88 ImageInverter::provideStreamData(int objid, int generation,
89 - Pipeline* pipeline) 89 + Pipeline* pipeline)
90 { 90 {
91 // Use the object and generation number supplied to look up the 91 // Use the object and generation number supplied to look up the
92 // image data. Then invert the image data and write the inverted 92 // image data. Then invert the image data and write the inverted
@@ -99,8 +99,8 @@ ImageInverter::provideStreamData(int objid, int generation, @@ -99,8 +99,8 @@ ImageInverter::provideStreamData(int objid, int generation,
99 unsigned char ch; 99 unsigned char ch;
100 for (size_t i = 0; i < size; ++i) 100 for (size_t i = 0; i < size; ++i)
101 { 101 {
102 - ch = QIntC::to_uchar(0xff - buf[i]);  
103 - pipeline->write(&ch, 1); 102 + ch = QIntC::to_uchar(0xff - buf[i]);
  103 + pipeline->write(&ch, 1);
104 } 104 }
105 pipeline->finish(); 105 pipeline->finish();
106 } 106 }
@@ -112,7 +112,7 @@ int main(int argc, char* argv[]) @@ -112,7 +112,7 @@ int main(int argc, char* argv[])
112 // For libtool's sake.... 112 // For libtool's sake....
113 if (strncmp(whoami, "lt-", 3) == 0) 113 if (strncmp(whoami, "lt-", 3) == 0)
114 { 114 {
115 - whoami += 3; 115 + whoami += 3;
116 } 116 }
117 117
118 // For test suite 118 // For test suite
@@ -126,7 +126,7 @@ int main(int argc, char* argv[]) @@ -126,7 +126,7 @@ int main(int argc, char* argv[])
126 126
127 if (! ((argc == 3) || (argc == 4))) 127 if (! ((argc == 3) || (argc == 4)))
128 { 128 {
129 - usage(); 129 + usage();
130 } 130 }
131 131
132 char const* infilename = argv[1]; 132 char const* infilename = argv[1];
@@ -135,64 +135,64 @@ int main(int argc, char* argv[]) @@ -135,64 +135,64 @@ int main(int argc, char* argv[])
135 135
136 try 136 try
137 { 137 {
138 - QPDF qpdf;  
139 - qpdf.processFile(infilename, password); 138 + QPDF qpdf;
  139 + qpdf.processFile(infilename, password);
140 140
141 - ImageInverter* inv = new ImageInverter;  
142 - auto p = PointerHolder<QPDFObjectHandle::StreamDataProvider>(inv); 141 + ImageInverter* inv = new ImageInverter;
  142 + auto p = PointerHolder<QPDFObjectHandle::StreamDataProvider>(inv);
143 143
144 - // For each page...  
145 - std::vector<QPDFPageObjectHelper> pages = 144 + // For each page...
  145 + std::vector<QPDFPageObjectHelper> pages =
146 QPDFPageDocumentHelper(qpdf).getAllPages(); 146 QPDFPageDocumentHelper(qpdf).getAllPages();
147 - for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();  
148 - iter != pages.end(); ++iter)  
149 - {  
150 - QPDFPageObjectHelper& page(*iter);  
151 - // Get all images on the page.  
152 - std::map<std::string, QPDFObjectHandle> images =  
153 - page.getImages();  
154 - for (auto& iter2: images)  
155 - {  
156 - QPDFObjectHandle& image = iter2.second;  
157 - QPDFObjectHandle image_dict = image.getDict();  
158 - QPDFObjectHandle color_space =  
159 - image_dict.getKey("/ColorSpace");  
160 - QPDFObjectHandle bits_per_component =  
161 - image_dict.getKey("/BitsPerComponent");  
162 -  
163 - // For our example, we can only work with images 8-bit  
164 - // grayscale images that we can fully decode. Use  
165 - // pipeStreamData with a null pipeline to determine  
166 - // whether the image is filterable. Directly inspect  
167 - // keys to determine the image type.  
168 - if (image.pipeStreamData(0, qpdf_ef_compress, 147 + for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
  148 + iter != pages.end(); ++iter)
  149 + {
  150 + QPDFPageObjectHelper& page(*iter);
  151 + // Get all images on the page.
  152 + std::map<std::string, QPDFObjectHandle> images =
  153 + page.getImages();
  154 + for (auto& iter2: images)
  155 + {
  156 + QPDFObjectHandle& image = iter2.second;
  157 + QPDFObjectHandle image_dict = image.getDict();
  158 + QPDFObjectHandle color_space =
  159 + image_dict.getKey("/ColorSpace");
  160 + QPDFObjectHandle bits_per_component =
  161 + image_dict.getKey("/BitsPerComponent");
  162 +
  163 + // For our example, we can only work with images 8-bit
  164 + // grayscale images that we can fully decode. Use
  165 + // pipeStreamData with a null pipeline to determine
  166 + // whether the image is filterable. Directly inspect
  167 + // keys to determine the image type.
  168 + if (image.pipeStreamData(0, qpdf_ef_compress,
169 qpdf_dl_all) && 169 qpdf_dl_all) &&
170 color_space.isNameAndEquals("/DeviceGray") && 170 color_space.isNameAndEquals("/DeviceGray") &&
171 - bits_per_component.isInteger() &&  
172 - (bits_per_component.getIntValue() == 8))  
173 - { 171 + bits_per_component.isInteger() &&
  172 + (bits_per_component.getIntValue() == 8))
  173 + {
174 inv->registerImage(image, p); 174 inv->registerImage(image, p);
175 } 175 }
176 - }  
177 - }  
178 -  
179 - // Write out a new file  
180 - QPDFWriter w(qpdf, outfilename);  
181 - if (static_id)  
182 - {  
183 - // For the test suite, uncompress streams and use static  
184 - // IDs.  
185 - w.setStaticID(true); // for testing only  
186 - }  
187 - w.write();  
188 - std::cout << whoami << ": new file written to " << outfilename  
189 - << std::endl; 176 + }
  177 + }
  178 +
  179 + // Write out a new file
  180 + QPDFWriter w(qpdf, outfilename);
  181 + if (static_id)
  182 + {
  183 + // For the test suite, uncompress streams and use static
  184 + // IDs.
  185 + w.setStaticID(true); // for testing only
  186 + }
  187 + w.write();
  188 + std::cout << whoami << ": new file written to " << outfilename
  189 + << std::endl;
190 } 190 }
191 catch (std::exception &e) 191 catch (std::exception &e)
192 { 192 {
193 - std::cerr << whoami << " processing file " << infilename << ": "  
194 - << e.what() << std::endl;  
195 - exit(2); 193 + std::cerr << whoami << " processing file " << infilename << ": "
  194 + << e.what() << std::endl;
  195 + exit(2);
196 } 196 }
197 197
198 return 0; 198 return 0;
examples/pdf-linearize.c
@@ -32,20 +32,20 @@ int main(int argc, char* argv[]) @@ -32,20 +32,20 @@ int main(int argc, char* argv[])
32 32
33 if ((p = strrchr(argv[0], '/')) != NULL) 33 if ((p = strrchr(argv[0], '/')) != NULL)
34 { 34 {
35 - whoami = p + 1; 35 + whoami = p + 1;
36 } 36 }
37 else if ((p = strrchr(argv[0], '\\')) != NULL) 37 else if ((p = strrchr(argv[0], '\\')) != NULL)
38 { 38 {
39 - whoami = p + 1; 39 + whoami = p + 1;
40 } 40 }
41 else 41 else
42 { 42 {
43 - whoami = argv[0]; 43 + whoami = argv[0];
44 } 44 }
45 45
46 if (argc != 4) 46 if (argc != 4)
47 { 47 {
48 - usage(); 48 + usage();
49 } 49 }
50 50
51 infile = argv[1]; 51 infile = argv[1];
@@ -53,36 +53,36 @@ int main(int argc, char* argv[]) @@ -53,36 +53,36 @@ int main(int argc, char* argv[])
53 outfile = argv[3]; 53 outfile = argv[3];
54 54
55 if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) && 55 if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) &&
56 - ((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0)) 56 + ((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0))
57 { 57 {
58 /* Use static ID for testing only. For production, a 58 /* Use static ID for testing only. For production, a
59 * non-static ID is used. See also 59 * non-static ID is used. See also
60 * qpdf_set_deterministic_ID. */ 60 * qpdf_set_deterministic_ID. */
61 - qpdf_set_static_ID(qpdf, QPDF_TRUE); /* for testing only */  
62 - qpdf_set_linearization(qpdf, QPDF_TRUE); 61 + qpdf_set_static_ID(qpdf, QPDF_TRUE); /* for testing only */
  62 + qpdf_set_linearization(qpdf, QPDF_TRUE);
63 qpdf_register_progress_reporter(qpdf, write_progress, infile); 63 qpdf_register_progress_reporter(qpdf, write_progress, infile);
64 - qpdf_write(qpdf); 64 + qpdf_write(qpdf);
65 } 65 }
66 while (qpdf_more_warnings(qpdf)) 66 while (qpdf_more_warnings(qpdf))
67 { 67 {
68 - warnings = 1;  
69 - printf("warning: %s\n",  
70 - qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf))); 68 + warnings = 1;
  69 + printf("warning: %s\n",
  70 + qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf)));
71 } 71 }
72 if (qpdf_has_error(qpdf)) 72 if (qpdf_has_error(qpdf))
73 { 73 {
74 - errors = 1;  
75 - printf("error: %s\n",  
76 - qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf))); 74 + errors = 1;
  75 + printf("error: %s\n",
  76 + qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf)));
77 } 77 }
78 qpdf_cleanup(&qpdf); 78 qpdf_cleanup(&qpdf);
79 if (errors) 79 if (errors)
80 { 80 {
81 - return 2; 81 + return 2;
82 } 82 }
83 else if (warnings) 83 else if (warnings)
84 { 84 {
85 - return 3; 85 + return 3;
86 } 86 }
87 87
88 return 0; 88 return 0;
examples/pdf-mod-info.cc
@@ -16,39 +16,39 @@ static char const* whoami = 0; @@ -16,39 +16,39 @@ static char const* whoami = 0;
16 void usage() 16 void usage()
17 { 17 {
18 std::cerr 18 std::cerr
19 - << "Usage: " << whoami  
20 - << " --in in_file [--out out_file] [--key key [--val val]?]+\n"  
21 - << "Modifies/Adds/Removes PDF /Info entries in the in_file\n"  
22 - << "and stores the result in out_file\n"  
23 - << "Special mode: " << whoami << " --dump file\n"  
24 - << "dumps all /Info entries to stdout\n"; 19 + << "Usage: " << whoami
  20 + << " --in in_file [--out out_file] [--key key [--val val]?]+\n"
  21 + << "Modifies/Adds/Removes PDF /Info entries in the in_file\n"
  22 + << "and stores the result in out_file\n"
  23 + << "Special mode: " << whoami << " --dump file\n"
  24 + << "dumps all /Info entries to stdout\n";
25 exit(2); 25 exit(2);
26 } 26 }
27 27
28 void dumpInfoDict(QPDF& pdf, 28 void dumpInfoDict(QPDF& pdf,
29 - std::ostream& os = std::cout,  
30 - std::string const& sep = ":\t") 29 + std::ostream& os = std::cout,
  30 + std::string const& sep = ":\t")
31 { 31 {
32 QPDFObjectHandle trailer = pdf.getTrailer(); 32 QPDFObjectHandle trailer = pdf.getTrailer();
33 if (trailer.hasKey("/Info")) 33 if (trailer.hasKey("/Info"))
34 { 34 {
35 - for (auto& it: trailer.getKey("/Info").ditems())  
36 - {  
37 - std::string val;  
38 - if (it.second.isString())  
39 - {  
40 - val = it.second.getStringValue();  
41 - }  
42 - else if (it.second.isName())  
43 - {  
44 - val = it.second.getName();  
45 - }  
46 - else // according to PDF Spec 1.5, shouldn't happen  
47 - {  
48 - val = it.second.unparseResolved();  
49 - }  
50 - os << it.first.substr(1) << sep << val << std::endl; // skip '/'  
51 - } 35 + for (auto& it: trailer.getKey("/Info").ditems())
  36 + {
  37 + std::string val;
  38 + if (it.second.isString())
  39 + {
  40 + val = it.second.getStringValue();
  41 + }
  42 + else if (it.second.isName())
  43 + {
  44 + val = it.second.getName();
  45 + }
  46 + else // according to PDF Spec 1.5, shouldn't happen
  47 + {
  48 + val = it.second.unparseResolved();
  49 + }
  50 + os << it.first.substr(1) << sep << val << std::endl; // skip '/'
  51 + }
52 } 52 }
53 } 53 }
54 54
@@ -56,14 +56,14 @@ void pdfDumpInfoDict(char const* fname) @@ -56,14 +56,14 @@ void pdfDumpInfoDict(char const* fname)
56 { 56 {
57 try 57 try
58 { 58 {
59 - QPDF pdf;  
60 - pdf.processFile(fname);  
61 - dumpInfoDict(pdf); 59 + QPDF pdf;
  60 + pdf.processFile(fname);
  61 + dumpInfoDict(pdf);
62 } 62 }
63 catch (std::exception& e) 63 catch (std::exception& e)
64 { 64 {
65 - std::cerr << e.what() << std::endl;  
66 - exit(2); 65 + std::cerr << e.what() << std::endl;
  66 + exit(2);
67 } 67 }
68 } 68 }
69 69
@@ -78,19 +78,19 @@ int main(int argc, char* argv[]) @@ -78,19 +78,19 @@ int main(int argc, char* argv[])
78 // For libtool's sake.... 78 // For libtool's sake....
79 if (strncmp(whoami, "lt-", 3) == 0) 79 if (strncmp(whoami, "lt-", 3) == 0)
80 { 80 {
81 - whoami += 3; 81 + whoami += 3;
82 } 82 }
83 83
84 if ((argc == 2) && (! strcmp(argv[1], "--version")) ) 84 if ((argc == 2) && (! strcmp(argv[1], "--version")) )
85 { 85 {
86 - std::cout << whoami << " version " << version << std::endl;  
87 - exit(0); 86 + std::cout << whoami << " version " << version << std::endl;
  87 + exit(0);
88 } 88 }
89 if ((argc == 3) && (! strcmp(argv[1], "--dump"))) 89 if ((argc == 3) && (! strcmp(argv[1], "--dump")))
90 { 90 {
91 - QTC::TC("examples", "pdf-mod-info --dump");  
92 - pdfDumpInfoDict(argv[2]);  
93 - exit(0); 91 + QTC::TC("examples", "pdf-mod-info --dump");
  92 + pdfDumpInfoDict(argv[2]);
  93 + exit(0);
94 } 94 }
95 95
96 char* fl_in = 0; 96 char* fl_in = 0;
@@ -99,59 +99,59 @@ int main(int argc, char* argv[]) @@ -99,59 +99,59 @@ int main(int argc, char* argv[])
99 99
100 for (int i = 1; i < argc; ++i) 100 for (int i = 1; i < argc; ++i)
101 { 101 {
102 - if ((! strcmp(argv[i], "--in")) && (++i < argc))  
103 - {  
104 - fl_in = argv[i];  
105 - }  
106 - else if ((! strcmp(argv[i], "--out")) && (++i < argc))  
107 - {  
108 - fl_out = argv[i];  
109 - }  
110 - else if (! strcmp(argv[i], "--static-id")) // don't document  
111 - {  
112 - static_id = true; // this should be used in test suites only  
113 - }  
114 - else if ((! strcmp(argv[i], "--key")) && (++i < argc))  
115 - {  
116 - QTC::TC("examples", "pdf-mod-info -key");  
117 - cur_key = argv[i];  
118 - if (! ((cur_key.length() > 0) && (cur_key.at(0) == '/')))  
119 - {  
120 - cur_key = "/" + cur_key;  
121 - }  
122 - Keys[cur_key] = "";  
123 - }  
124 - else if ((! strcmp(argv[i], "--val")) && (++i < argc))  
125 - {  
126 - if (cur_key.empty())  
127 - {  
128 - QTC::TC("examples", "pdf-mod-info usage wrong val");  
129 - usage();  
130 - }  
131 - QTC::TC("examples", "pdf-mod-info -val");  
132 - Keys[cur_key] = argv[i];  
133 - cur_key.clear();  
134 - }  
135 - else  
136 - {  
137 - QTC::TC("examples", "pdf-mod-info usage junk");  
138 - usage();  
139 - } 102 + if ((! strcmp(argv[i], "--in")) && (++i < argc))
  103 + {
  104 + fl_in = argv[i];
  105 + }
  106 + else if ((! strcmp(argv[i], "--out")) && (++i < argc))
  107 + {
  108 + fl_out = argv[i];
  109 + }
  110 + else if (! strcmp(argv[i], "--static-id")) // don't document
  111 + {
  112 + static_id = true; // this should be used in test suites only
  113 + }
  114 + else if ((! strcmp(argv[i], "--key")) && (++i < argc))
  115 + {
  116 + QTC::TC("examples", "pdf-mod-info -key");
  117 + cur_key = argv[i];
  118 + if (! ((cur_key.length() > 0) && (cur_key.at(0) == '/')))
  119 + {
  120 + cur_key = "/" + cur_key;
  121 + }
  122 + Keys[cur_key] = "";
  123 + }
  124 + else if ((! strcmp(argv[i], "--val")) && (++i < argc))
  125 + {
  126 + if (cur_key.empty())
  127 + {
  128 + QTC::TC("examples", "pdf-mod-info usage wrong val");
  129 + usage();
  130 + }
  131 + QTC::TC("examples", "pdf-mod-info -val");
  132 + Keys[cur_key] = argv[i];
  133 + cur_key.clear();
  134 + }
  135 + else
  136 + {
  137 + QTC::TC("examples", "pdf-mod-info usage junk");
  138 + usage();
  139 + }
140 } 140 }
141 if (! fl_in) 141 if (! fl_in)
142 { 142 {
143 - QTC::TC("examples", "pdf-mod-info no in file");  
144 - usage(); 143 + QTC::TC("examples", "pdf-mod-info no in file");
  144 + usage();
145 } 145 }
146 if (! fl_out) 146 if (! fl_out)
147 { 147 {
148 - QTC::TC("examples", "pdf-mod-info in-place");  
149 - fl_out = fl_in; 148 + QTC::TC("examples", "pdf-mod-info in-place");
  149 + fl_out = fl_in;
150 } 150 }
151 if (Keys.size() == 0) 151 if (Keys.size() == 0)
152 { 152 {
153 - QTC::TC("examples", "pdf-mod-info no keys");  
154 - usage(); 153 + QTC::TC("examples", "pdf-mod-info no keys");
  154 + usage();
155 } 155 }
156 156
157 std::string fl_tmp = fl_out; 157 std::string fl_tmp = fl_out;
@@ -159,62 +159,62 @@ int main(int argc, char* argv[]) @@ -159,62 +159,62 @@ int main(int argc, char* argv[])
159 159
160 try 160 try
161 { 161 {
162 - QPDF file;  
163 - file.processFile(fl_in);  
164 -  
165 - QPDFObjectHandle filetrailer = file.getTrailer();  
166 - QPDFObjectHandle fileinfo;  
167 -  
168 - for (std::map<std::string, std::string>::const_iterator it =  
169 - Keys.begin(); Keys.end() != it; ++it)  
170 - {  
171 - if (! fileinfo.isInitialized())  
172 - {  
173 - if (filetrailer.hasKey("/Info"))  
174 - {  
175 - QTC::TC("examples", "pdf-mod-info has info");  
176 - fileinfo = filetrailer.getKey("/Info");  
177 - }  
178 - else  
179 - {  
180 - QTC::TC("examples", "pdf-mod-info file no info");  
181 - fileinfo = QPDFObjectHandle::newDictionary();  
182 - filetrailer.replaceKey("/Info", fileinfo);  
183 - }  
184 - }  
185 - if (it->second == "")  
186 - {  
187 - fileinfo.removeKey(it->first);  
188 - }  
189 - else  
190 - {  
191 - QPDFObjectHandle elt = fileinfo.newString(it->second);  
192 - elt.makeDirect();  
193 - fileinfo.replaceKey(it->first, elt);  
194 - }  
195 - }  
196 - QPDFWriter w(file, fl_tmp.c_str());  
197 - w.setStreamDataMode(qpdf_s_preserve);  
198 - w.setLinearization(true);  
199 - w.setStaticID(static_id); // for testing only  
200 - w.write(); 162 + QPDF file;
  163 + file.processFile(fl_in);
  164 +
  165 + QPDFObjectHandle filetrailer = file.getTrailer();
  166 + QPDFObjectHandle fileinfo;
  167 +
  168 + for (std::map<std::string, std::string>::const_iterator it =
  169 + Keys.begin(); Keys.end() != it; ++it)
  170 + {
  171 + if (! fileinfo.isInitialized())
  172 + {
  173 + if (filetrailer.hasKey("/Info"))
  174 + {
  175 + QTC::TC("examples", "pdf-mod-info has info");
  176 + fileinfo = filetrailer.getKey("/Info");
  177 + }
  178 + else
  179 + {
  180 + QTC::TC("examples", "pdf-mod-info file no info");
  181 + fileinfo = QPDFObjectHandle::newDictionary();
  182 + filetrailer.replaceKey("/Info", fileinfo);
  183 + }
  184 + }
  185 + if (it->second == "")
  186 + {
  187 + fileinfo.removeKey(it->first);
  188 + }
  189 + else
  190 + {
  191 + QPDFObjectHandle elt = fileinfo.newString(it->second);
  192 + elt.makeDirect();
  193 + fileinfo.replaceKey(it->first, elt);
  194 + }
  195 + }
  196 + QPDFWriter w(file, fl_tmp.c_str());
  197 + w.setStreamDataMode(qpdf_s_preserve);
  198 + w.setLinearization(true);
  199 + w.setStaticID(static_id); // for testing only
  200 + w.write();
201 } 201 }
202 catch (std::exception& e) 202 catch (std::exception& e)
203 { 203 {
204 - std::cerr << e.what() << std::endl;  
205 - exit(2); 204 + std::cerr << e.what() << std::endl;
  205 + exit(2);
206 } 206 }
207 207
208 try 208 try
209 { 209 {
210 - (void) remove(fl_out);  
211 - QUtil::os_wrapper("rename " + fl_tmp + " " + std::string(fl_out),  
212 - rename(fl_tmp.c_str(), fl_out)); 210 + (void) remove(fl_out);
  211 + QUtil::os_wrapper("rename " + fl_tmp + " " + std::string(fl_out),
  212 + rename(fl_tmp.c_str(), fl_out));
213 } 213 }
214 catch (std::exception& e) 214 catch (std::exception& e)
215 { 215 {
216 - std::cerr << e.what() << std::endl;  
217 - exit(2); 216 + std::cerr << e.what() << std::endl;
  217 + exit(2);
218 } 218 }
219 219
220 return 0; 220 return 0;
examples/pdf-name-number-tree.cc
@@ -11,9 +11,9 @@ static char const* whoami = 0; @@ -11,9 +11,9 @@ static char const* whoami = 0;
11 void usage() 11 void usage()
12 { 12 {
13 std::cerr << "Usage: " << whoami << " outfile.pdf" 13 std::cerr << "Usage: " << whoami << " outfile.pdf"
14 - << std::endl  
15 - << "Create some name/number trees and write to a file"  
16 - << std::endl; 14 + << std::endl
  15 + << "Create some name/number trees and write to a file"
  16 + << std::endl;
17 exit(2); 17 exit(2);
18 } 18 }
19 19
@@ -24,12 +24,12 @@ int main(int argc, char* argv[]) @@ -24,12 +24,12 @@ int main(int argc, char* argv[])
24 // For libtool's sake.... 24 // For libtool's sake....
25 if (strncmp(whoami, "lt-", 3) == 0) 25 if (strncmp(whoami, "lt-", 3) == 0)
26 { 26 {
27 - whoami += 3; 27 + whoami += 3;
28 } 28 }
29 29
30 if (argc != 2) 30 if (argc != 2)
31 { 31 {
32 - usage(); 32 + usage();
33 } 33 }
34 34
35 char const* outfilename = argv[1]; 35 char const* outfilename = argv[1];
examples/pdf-npages.cc
@@ -10,7 +10,7 @@ static char const* whoami = 0; @@ -10,7 +10,7 @@ static char const* whoami = 0;
10 void usage() 10 void usage()
11 { 11 {
12 std::cerr << "Usage: " << whoami << " filename" << std::endl 12 std::cerr << "Usage: " << whoami << " filename" << std::endl
13 - << "Prints the number of pages in filename" << std::endl; 13 + << "Prints the number of pages in filename" << std::endl;
14 exit(2); 14 exit(2);
15 } 15 }
16 16
@@ -21,34 +21,34 @@ int main(int argc, char* argv[]) @@ -21,34 +21,34 @@ int main(int argc, char* argv[])
21 // For libtool's sake.... 21 // For libtool's sake....
22 if (strncmp(whoami, "lt-", 3) == 0) 22 if (strncmp(whoami, "lt-", 3) == 0)
23 { 23 {
24 - whoami += 3; 24 + whoami += 3;
25 } 25 }
26 26
27 if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) 27 if ((argc == 2) && (strcmp(argv[1], "--version") == 0))
28 { 28 {
29 - std::cout << whoami << " version 1.3" << std::endl;  
30 - exit(0); 29 + std::cout << whoami << " version 1.3" << std::endl;
  30 + exit(0);
31 } 31 }
32 32
33 if (argc != 2) 33 if (argc != 2)
34 { 34 {
35 - usage(); 35 + usage();
36 } 36 }
37 char const* filename = argv[1]; 37 char const* filename = argv[1];
38 38
39 try 39 try
40 { 40 {
41 - QPDF pdf;  
42 - pdf.processFile(filename);  
43 - QPDFObjectHandle root = pdf.getRoot();  
44 - QPDFObjectHandle pages = root.getKey("/Pages");  
45 - QPDFObjectHandle count = pages.getKey("/Count");  
46 - std::cout << count.getIntValue() << std::endl; 41 + QPDF pdf;
  42 + pdf.processFile(filename);
  43 + QPDFObjectHandle root = pdf.getRoot();
  44 + QPDFObjectHandle pages = root.getKey("/Pages");
  45 + QPDFObjectHandle count = pages.getKey("/Count");
  46 + std::cout << count.getIntValue() << std::endl;
47 } 47 }
48 catch (std::exception& e) 48 catch (std::exception& e)
49 { 49 {
50 - std::cerr << whoami << ": " << e.what() << std::endl;  
51 - exit(2); 50 + std::cerr << whoami << ": " << e.what() << std::endl;
  51 + exit(2);
52 } 52 }
53 53
54 return 0; 54 return 0;
examples/pdf-overlay-page.cc
@@ -17,10 +17,10 @@ static char const* whoami = 0; @@ -17,10 +17,10 @@ static char const* whoami = 0;
17 void usage() 17 void usage()
18 { 18 {
19 std::cerr << "Usage: " << whoami << " infile pagefile outfile" 19 std::cerr << "Usage: " << whoami << " infile pagefile outfile"
20 - << std::endl  
21 - << "Stamp page 1 of pagefile on every page of infile," 20 + << std::endl
  21 + << "Stamp page 1 of pagefile on every page of infile,"
22 << " writing to outfile" 22 << " writing to outfile"
23 - << std::endl; 23 + << std::endl;
24 exit(2); 24 exit(2);
25 } 25 }
26 26
@@ -91,7 +91,7 @@ int main(int argc, char* argv[]) @@ -91,7 +91,7 @@ int main(int argc, char* argv[])
91 // For libtool's sake.... 91 // For libtool's sake....
92 if (strncmp(whoami, "lt-", 3) == 0) 92 if (strncmp(whoami, "lt-", 3) == 0)
93 { 93 {
94 - whoami += 3; 94 + whoami += 3;
95 } 95 }
96 96
97 if (argc != 4) 97 if (argc != 4)
@@ -108,8 +108,8 @@ int main(int argc, char* argv[]) @@ -108,8 +108,8 @@ int main(int argc, char* argv[])
108 } 108 }
109 catch (std::exception &e) 109 catch (std::exception &e)
110 { 110 {
111 - std::cerr << whoami << ": " << e.what() << std::endl;  
112 - exit(2); 111 + std::cerr << whoami << ": " << e.what() << std::endl;
  112 + exit(2);
113 } 113 }
114 return 0; 114 return 0;
115 } 115 }
examples/pdf-parse-content.cc
@@ -13,7 +13,7 @@ static char const* whoami = 0; @@ -13,7 +13,7 @@ static char const* whoami = 0;
13 void usage() 13 void usage()
14 { 14 {
15 std::cerr << "Usage: " << whoami << " filename page-number" << std::endl 15 std::cerr << "Usage: " << whoami << " filename page-number" << std::endl
16 - << "Prints a dump of the objects in the content streams" 16 + << "Prints a dump of the objects in the content streams"
17 << " of the given page." << std::endl 17 << " of the given page." << std::endl
18 << "Pages are numbered from 1." << std::endl; 18 << "Pages are numbered from 1." << std::endl;
19 exit(2); 19 exit(2);
@@ -66,20 +66,20 @@ int main(int argc, char* argv[]) @@ -66,20 +66,20 @@ int main(int argc, char* argv[])
66 // For libtool's sake.... 66 // For libtool's sake....
67 if (strncmp(whoami, "lt-", 3) == 0) 67 if (strncmp(whoami, "lt-", 3) == 0)
68 { 68 {
69 - whoami += 3; 69 + whoami += 3;
70 } 70 }
71 71
72 if (argc != 3) 72 if (argc != 3)
73 { 73 {
74 - usage(); 74 + usage();
75 } 75 }
76 char const* filename = argv[1]; 76 char const* filename = argv[1];
77 int pageno = QUtil::string_to_int(argv[2]); 77 int pageno = QUtil::string_to_int(argv[2]);
78 78
79 try 79 try
80 { 80 {
81 - QPDF pdf;  
82 - pdf.processFile(filename); 81 + QPDF pdf;
  82 + pdf.processFile(filename);
83 std::vector<QPDFPageObjectHelper> pages = 83 std::vector<QPDFPageObjectHelper> pages =
84 QPDFPageDocumentHelper(pdf).getAllPages(); 84 QPDFPageDocumentHelper(pdf).getAllPages();
85 if ((pageno < 1) || (QIntC::to_size(pageno) > pages.size())) 85 if ((pageno < 1) || (QIntC::to_size(pageno) > pages.size()))
@@ -93,8 +93,8 @@ int main(int argc, char* argv[]) @@ -93,8 +93,8 @@ int main(int argc, char* argv[])
93 } 93 }
94 catch (std::exception& e) 94 catch (std::exception& e)
95 { 95 {
96 - std::cerr << whoami << ": " << e.what() << std::endl;  
97 - exit(2); 96 + std::cerr << whoami << ": " << e.what() << std::endl;
  97 + exit(2);
98 } 98 }
99 99
100 return 0; 100 return 0;
examples/pdf-set-form-values.cc
@@ -13,8 +13,8 @@ static char const* whoami = 0; @@ -13,8 +13,8 @@ static char const* whoami = 0;
13 void usage() 13 void usage()
14 { 14 {
15 std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf value" 15 std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf value"
16 - << std::endl  
17 - << "Set the value of all text fields to a specified value" 16 + << std::endl
  17 + << "Set the value of all text fields to a specified value"
18 << std::endl; 18 << std::endl;
19 exit(2); 19 exit(2);
20 } 20 }
@@ -27,7 +27,7 @@ int main(int argc, char* argv[]) @@ -27,7 +27,7 @@ int main(int argc, char* argv[])
27 // For libtool's sake.... 27 // For libtool's sake....
28 if (strncmp(whoami, "lt-", 3) == 0) 28 if (strncmp(whoami, "lt-", 3) == 0)
29 { 29 {
30 - whoami += 3; 30 + whoami += 3;
31 } 31 }
32 32
33 if (argc != 4) 33 if (argc != 4)
@@ -47,8 +47,8 @@ int main(int argc, char* argv[]) @@ -47,8 +47,8 @@ int main(int argc, char* argv[])
47 47
48 try 48 try
49 { 49 {
50 - QPDF qpdf;  
51 - qpdf.processFile(infilename); 50 + QPDF qpdf;
  51 + qpdf.processFile(infilename);
52 52
53 // We will iterate through form fields by starting at the page 53 // We will iterate through form fields by starting at the page
54 // level and looking at each field for each page. We could 54 // level and looking at each field for each page. We could
@@ -94,16 +94,16 @@ int main(int argc, char* argv[]) @@ -94,16 +94,16 @@ int main(int argc, char* argv[])
94 } 94 }
95 } 95 }
96 96
97 - // Write out a new file  
98 - QPDFWriter w(qpdf, outfilename); 97 + // Write out a new file
  98 + QPDFWriter w(qpdf, outfilename);
99 w.setStaticID(true); // for testing only 99 w.setStaticID(true); // for testing only
100 - w.write(); 100 + w.write();
101 } 101 }
102 catch (std::exception &e) 102 catch (std::exception &e)
103 { 103 {
104 - std::cerr << whoami << " processing file " << infilename << ": "  
105 - << e.what() << std::endl;  
106 - exit(2); 104 + std::cerr << whoami << " processing file " << infilename << ": "
  105 + << e.what() << std::endl;
  106 + exit(2);
107 } 107 }
108 108
109 return 0; 109 return 0;
examples/pdf-split-pages.cc
@@ -38,13 +38,13 @@ static void process(char const* whoami, @@ -38,13 +38,13 @@ static void process(char const* whoami,
38 outpdf.emptyPDF(); 38 outpdf.emptyPDF();
39 QPDFPageDocumentHelper(outpdf).addPage(page, false); 39 QPDFPageDocumentHelper(outpdf).addPage(page, false);
40 QPDFWriter outpdfw(outpdf, outfile.c_str()); 40 QPDFWriter outpdfw(outpdf, outfile.c_str());
41 - if (static_id)  
42 - {  
43 - // For the test suite, uncompress streams and use static  
44 - // IDs.  
45 - outpdfw.setStaticID(true); // for testing only  
46 - outpdfw.setStreamDataMode(qpdf_s_uncompress);  
47 - } 41 + if (static_id)
  42 + {
  43 + // For the test suite, uncompress streams and use static
  44 + // IDs.
  45 + outpdfw.setStaticID(true); // for testing only
  46 + outpdfw.setStreamDataMode(qpdf_s_uncompress);
  47 + }
48 outpdfw.write(); 48 outpdfw.write();
49 } 49 }
50 } 50 }
@@ -62,7 +62,7 @@ int main(int argc, char* argv[]) @@ -62,7 +62,7 @@ int main(int argc, char* argv[])
62 // For libtool's sake.... 62 // For libtool's sake....
63 if (strncmp(whoami, "lt-", 3) == 0) 63 if (strncmp(whoami, "lt-", 3) == 0)
64 { 64 {
65 - whoami += 3; 65 + whoami += 3;
66 } 66 }
67 // For test suite 67 // For test suite
68 if ((argc > 1) && (strcmp(argv[1], " --static-id") == 0)) 68 if ((argc > 1) && (strcmp(argv[1], " --static-id") == 0))
examples/qpdf-job.cc
@@ -30,7 +30,7 @@ int main(int argc, char* argv[]) @@ -30,7 +30,7 @@ int main(int argc, char* argv[])
30 // For libtool's sake.... 30 // For libtool's sake....
31 if (strncmp(whoami, "lt-", 3) == 0) 31 if (strncmp(whoami, "lt-", 3) == 0)
32 { 32 {
33 - whoami += 3; 33 + whoami += 3;
34 } 34 }
35 35
36 if (argc != 1) 36 if (argc != 1)
examples/qpdfjob-c.c
@@ -26,20 +26,20 @@ int main(int argc, char* argv[]) @@ -26,20 +26,20 @@ int main(int argc, char* argv[])
26 26
27 if ((p = strrchr(argv[0], '/')) != NULL) 27 if ((p = strrchr(argv[0], '/')) != NULL)
28 { 28 {
29 - whoami = p + 1; 29 + whoami = p + 1;
30 } 30 }
31 else if ((p = strrchr(argv[0], '\\')) != NULL) 31 else if ((p = strrchr(argv[0], '\\')) != NULL)
32 { 32 {
33 - whoami = p + 1; 33 + whoami = p + 1;
34 } 34 }
35 else 35 else
36 { 36 {
37 - whoami = argv[0]; 37 + whoami = argv[0];
38 } 38 }
39 39
40 if (argc != 3) 40 if (argc != 3)
41 { 41 {
42 - usage(); 42 + usage();
43 } 43 }
44 44
45 infile = argv[1]; 45 infile = argv[1];
examples/qtest/bookmarks.test
@@ -15,38 +15,38 @@ foreach my $show (&quot;&quot;, &quot; --show-open&quot;) @@ -15,38 +15,38 @@ foreach my $show (&quot;&quot;, &quot; --show-open&quot;)
15 { 15 {
16 my $xshow = $show ? $show : "x"; 16 my $xshow = $show ? $show : "x";
17 my $xstyle = $style ? $style : "x"; 17 my $xstyle = $style ? $style : "x";
18 - my $out = "test.$xshow.$xstyle.out";  
19 - $out =~ s/ //g;  
20 - $td->runtest("show:$show, style:$style",  
21 - {$td->COMMAND => "pdf-bookmarks $show $style 1.pdf"},  
22 - {$td->FILE => $out, $td->EXIT_STATUS => 0},  
23 - $td->NORMALIZE_NEWLINES); 18 + my $out = "test.$xshow.$xstyle.out";
  19 + $out =~ s/ //g;
  20 + $td->runtest("show:$show, style:$style",
  21 + {$td->COMMAND => "pdf-bookmarks $show $style 1.pdf"},
  22 + {$td->FILE => $out, $td->EXIT_STATUS => 0},
  23 + $td->NORMALIZE_NEWLINES);
24 } 24 }
25 } 25 }
26 $td->runtest("no bookmarks", 26 $td->runtest("no bookmarks",
27 - {$td->COMMAND => "pdf-bookmarks 2.pdf"},  
28 - {$td->STRING => "2.pdf has no bookmarks\n",  
29 - $td->EXIT_STATUS => 0},  
30 - $td->NORMALIZE_NEWLINES); 27 + {$td->COMMAND => "pdf-bookmarks 2.pdf"},
  28 + {$td->STRING => "2.pdf has no bookmarks\n",
  29 + $td->EXIT_STATUS => 0},
  30 + $td->NORMALIZE_NEWLINES);
31 31
32 $td->runtest("bad", 32 $td->runtest("bad",
33 - {$td->COMMAND => "pdf-bookmarks 3.pdf"},  
34 - {$td->REGEXP => "pdf-bookmarks processing file 3.pdf: " .  
35 - ".*unable to find trailer.*",  
36 - $td->EXIT_STATUS => 2},  
37 - $td->NORMALIZE_NEWLINES); 33 + {$td->COMMAND => "pdf-bookmarks 3.pdf"},
  34 + {$td->REGEXP => "pdf-bookmarks processing file 3.pdf: " .
  35 + ".*unable to find trailer.*",
  36 + $td->EXIT_STATUS => 2},
  37 + $td->NORMALIZE_NEWLINES);
38 38
39 $td->runtest("encrypted, targets", 39 $td->runtest("encrypted, targets",
40 - {$td->COMMAND => "pdf-bookmarks --show-targets 4.pdf user"},  
41 - {$td->FILE => "encrypted.out",  
42 - $td->EXIT_STATUS => 0},  
43 - $td->NORMALIZE_NEWLINES); 40 + {$td->COMMAND => "pdf-bookmarks --show-targets 4.pdf user"},
  41 + {$td->FILE => "encrypted.out",
  42 + $td->EXIT_STATUS => 0},
  43 + $td->NORMALIZE_NEWLINES);
44 44
45 $td->runtest("bookmarks deleted", 45 $td->runtest("bookmarks deleted",
46 - {$td->COMMAND => "pdf-bookmarks 5.pdf user"},  
47 - {$td->STRING => "5.pdf has no bookmarks\n",  
48 - $td->EXIT_STATUS => 0},  
49 - $td->NORMALIZE_NEWLINES); 46 + {$td->COMMAND => "pdf-bookmarks 5.pdf user"},
  47 + {$td->STRING => "5.pdf has no bookmarks\n",
  48 + $td->EXIT_STATUS => 0},
  49 + $td->NORMALIZE_NEWLINES);
50 50
51 $td->runtest("non-trivial pdf doc to unicode", 51 $td->runtest("non-trivial pdf doc to unicode",
52 {$td->COMMAND => "pdf-bookmarks issue-179.pdf"}, 52 {$td->COMMAND => "pdf-bookmarks issue-179.pdf"},
examples/qtest/count-strings.test
@@ -10,8 +10,8 @@ require TestDriver; @@ -10,8 +10,8 @@ require TestDriver;
10 my $td = new TestDriver('pdf-count-strings'); 10 my $td = new TestDriver('pdf-count-strings');
11 11
12 $td->runtest("filter tokens", 12 $td->runtest("filter tokens",
13 - {$td->COMMAND => "pdf-count-strings in.pdf"},  
14 - {$td->FILE => "out", $td->EXIT_STATUS => 0}, 13 + {$td->COMMAND => "pdf-count-strings in.pdf"},
  14 + {$td->FILE => "out", $td->EXIT_STATUS => 0},
15 $td->NORMALIZE_NEWLINES); 15 $td->NORMALIZE_NEWLINES);
16 16
17 $td->report(1); 17 $td->report(1);
examples/qtest/create.test
@@ -12,8 +12,8 @@ cleanup(); @@ -12,8 +12,8 @@ cleanup();
12 my $td = new TestDriver('create'); 12 my $td = new TestDriver('create');
13 13
14 $td->runtest("create a simple PDF", 14 $td->runtest("create a simple PDF",
15 - {$td->COMMAND => "pdf-create a.pdf"},  
16 - {$td->FILE => "create.out", $td->EXIT_STATUS => 0}, 15 + {$td->COMMAND => "pdf-create a.pdf"},
  16 + {$td->FILE => "create.out", $td->EXIT_STATUS => 0},
17 $td->NORMALIZE_NEWLINES); 17 $td->NORMALIZE_NEWLINES);
18 18
19 cleanup(); 19 cleanup();
examples/qtest/double-page-size.test
@@ -12,16 +12,16 @@ my $td = new TestDriver(&#39;double-page-size&#39;); @@ -12,16 +12,16 @@ my $td = new TestDriver(&#39;double-page-size&#39;);
12 cleanup(); 12 cleanup();
13 13
14 $td->runtest("double page size", 14 $td->runtest("double page size",
15 - {$td->COMMAND => ['pdf-double-page-size', ' --static-id', 15 + {$td->COMMAND => ['pdf-double-page-size', ' --static-id',
16 'in.pdf', 'a.pdf']}, 16 'in.pdf', 'a.pdf']},
17 - {$td->STRING =>  
18 - "pdf-double-page-size: new file written to a.pdf\n",  
19 - $td->EXIT_STATUS => 0},  
20 - $td->NORMALIZE_NEWLINES); 17 + {$td->STRING =>
  18 + "pdf-double-page-size: new file written to a.pdf\n",
  19 + $td->EXIT_STATUS => 0},
  20 + $td->NORMALIZE_NEWLINES);
21 21
22 $td->runtest("check output", 22 $td->runtest("check output",
23 - {$td->FILE => "a.pdf"},  
24 - {$td->FILE => "out.pdf"}); 23 + {$td->FILE => "a.pdf"},
  24 + {$td->FILE => "out.pdf"});
25 25
26 cleanup(); 26 cleanup();
27 27
examples/qtest/filter-tokens.test
@@ -12,12 +12,12 @@ my $td = new TestDriver(&#39;pdf-filter-tokens&#39;); @@ -12,12 +12,12 @@ my $td = new TestDriver(&#39;pdf-filter-tokens&#39;);
12 cleanup(); 12 cleanup();
13 13
14 $td->runtest("filter tokens", 14 $td->runtest("filter tokens",
15 - {$td->COMMAND => "pdf-filter-tokens in.pdf a.pdf"},  
16 - {$td->STRING => "", $td->EXIT_STATUS => 0}); 15 + {$td->COMMAND => "pdf-filter-tokens in.pdf a.pdf"},
  16 + {$td->STRING => "", $td->EXIT_STATUS => 0});
17 17
18 $td->runtest("check output", 18 $td->runtest("check output",
19 - {$td->FILE => "a.pdf"},  
20 - {$td->FILE => "out.pdf"}); 19 + {$td->FILE => "a.pdf"},
  20 + {$td->FILE => "out.pdf"});
21 21
22 cleanup(); 22 cleanup();
23 23
examples/qtest/invert-images.test
@@ -12,16 +12,16 @@ my $td = new TestDriver(&#39;invert-images&#39;); @@ -12,16 +12,16 @@ my $td = new TestDriver(&#39;invert-images&#39;);
12 cleanup(); 12 cleanup();
13 13
14 $td->runtest("invert images", 14 $td->runtest("invert images",
15 - {$td->COMMAND => ['pdf-invert-images', ' --static-id', 15 + {$td->COMMAND => ['pdf-invert-images', ' --static-id',
16 'in.pdf', 'a.pdf']}, 16 'in.pdf', 'a.pdf']},
17 - {$td->STRING =>  
18 - "pdf-invert-images: new file written to a.pdf\n",  
19 - $td->EXIT_STATUS => 0},  
20 - $td->NORMALIZE_NEWLINES); 17 + {$td->STRING =>
  18 + "pdf-invert-images: new file written to a.pdf\n",
  19 + $td->EXIT_STATUS => 0},
  20 + $td->NORMALIZE_NEWLINES);
21 21
22 $td->runtest("check output", 22 $td->runtest("check output",
23 - {$td->FILE => "a.pdf"},  
24 - {$td->FILE => "out.pdf"}); 23 + {$td->FILE => "a.pdf"},
  24 + {$td->FILE => "out.pdf"});
25 25
26 cleanup(); 26 cleanup();
27 27
examples/qtest/linearize.test
@@ -14,14 +14,14 @@ my $td = new TestDriver(&#39;linearize&#39;); @@ -14,14 +14,14 @@ my $td = new TestDriver(&#39;linearize&#39;);
14 my $qpdf = $ENV{'QPDF_BIN'} or die; 14 my $qpdf = $ENV{'QPDF_BIN'} or die;
15 15
16 $td->runtest("linearize", 16 $td->runtest("linearize",
17 - {$td->COMMAND => "pdf-linearize input.pdf '' a.pdf"},  
18 - {$td->REGEXP => '(?s).*input\.pdf progress: \d+\%.*', 17 + {$td->COMMAND => "pdf-linearize input.pdf '' a.pdf"},
  18 + {$td->REGEXP => '(?s).*input\.pdf progress: \d+\%.*',
19 $td->EXIT_STATUS => 0}); 19 $td->EXIT_STATUS => 0});
20 20
21 $td->runtest("check", 21 $td->runtest("check",
22 - {$td->COMMAND => "$qpdf --check a.pdf"},  
23 - {$td->FILE => "check.out", $td->EXIT_STATUS => 0},  
24 - $td->NORMALIZE_NEWLINES); 22 + {$td->COMMAND => "$qpdf --check a.pdf"},
  23 + {$td->FILE => "check.out", $td->EXIT_STATUS => 0},
  24 + $td->NORMALIZE_NEWLINES);
25 25
26 cleanup(); 26 cleanup();
27 27
examples/qtest/mod-info.test
@@ -16,65 +16,65 @@ my $qpdf = $ENV{&#39;QPDF_BIN&#39;} or die; @@ -16,65 +16,65 @@ my $qpdf = $ENV{&#39;QPDF_BIN&#39;} or die;
16 cleanup(); 16 cleanup();
17 17
18 $td->runtest("usage #1", 18 $td->runtest("usage #1",
19 - {$td->COMMAND => "$prg --in target.pdf"},  
20 - {$td->FILE => "usage.out",  
21 - $td->EXIT_STATUS => 2},  
22 - $td->NORMALIZE_NEWLINES); 19 + {$td->COMMAND => "$prg --in target.pdf"},
  20 + {$td->FILE => "usage.out",
  21 + $td->EXIT_STATUS => 2},
  22 + $td->NORMALIZE_NEWLINES);
23 23
24 $td->runtest("usage #2", 24 $td->runtest("usage #2",
25 - {$td->COMMAND => "$prg --key abc --val def"},  
26 - {$td->FILE => "usage.out",  
27 - $td->EXIT_STATUS => 2},  
28 - $td->NORMALIZE_NEWLINES); 25 + {$td->COMMAND => "$prg --key abc --val def"},
  26 + {$td->FILE => "usage.out",
  27 + $td->EXIT_STATUS => 2},
  28 + $td->NORMALIZE_NEWLINES);
29 29
30 $td->runtest("usage #3", 30 $td->runtest("usage #3",
31 - {$td->COMMAND => "$prg --key abc --val def abc"},  
32 - {$td->FILE => "usage.out",  
33 - $td->EXIT_STATUS => 2},  
34 - $td->NORMALIZE_NEWLINES); 31 + {$td->COMMAND => "$prg --key abc --val def abc"},
  32 + {$td->FILE => "usage.out",
  33 + $td->EXIT_STATUS => 2},
  34 + $td->NORMALIZE_NEWLINES);
35 35
36 $td->runtest("usage #4", 36 $td->runtest("usage #4",
37 - {$td->COMMAND => "$prg --in source1.pdf --key date --val 01/01/01 --val 12/12/12"},  
38 - {$td->FILE => "usage.out",  
39 - $td->EXIT_STATUS => 2},  
40 - $td->NORMALIZE_NEWLINES); 37 + {$td->COMMAND => "$prg --in source1.pdf --key date --val 01/01/01 --val 12/12/12"},
  38 + {$td->FILE => "usage.out",
  39 + $td->EXIT_STATUS => 2},
  40 + $td->NORMALIZE_NEWLINES);
41 41
42 $td->runtest("dump #1", 42 $td->runtest("dump #1",
43 - {$td->COMMAND => "$prg --dump files/source1.pdf"},  
44 - {$td->FILE => "dump.out",  
45 - $td->EXIT_STATUS => 0},  
46 - $td->NORMALIZE_NEWLINES); 43 + {$td->COMMAND => "$prg --dump files/source1.pdf"},
  44 + {$td->FILE => "dump.out",
  45 + $td->EXIT_STATUS => 0},
  46 + $td->NORMALIZE_NEWLINES);
47 47
48 $td->runtest("dump #2", 48 $td->runtest("dump #2",
49 - {$td->COMMAND => "$prg --dump files/no-info.pdf"},  
50 - {$td->STRING => "",  
51 - $td->EXIT_STATUS => 0},  
52 - $td->NORMALIZE_NEWLINES); 49 + {$td->COMMAND => "$prg --dump files/no-info.pdf"},
  50 + {$td->STRING => "",
  51 + $td->EXIT_STATUS => 0},
  52 + $td->NORMALIZE_NEWLINES);
53 53
54 $td->runtest("dump #3", 54 $td->runtest("dump #3",
55 - {$td->COMMAND => "$prg --dump files/empty-info.pdf"},  
56 - {$td->STRING => "",  
57 - $td->EXIT_STATUS => 0}); 55 + {$td->COMMAND => "$prg --dump files/empty-info.pdf"},
  56 + {$td->STRING => "",
  57 + $td->EXIT_STATUS => 0});
58 58
59 run_and_cmp("modify Subject", 59 run_and_cmp("modify Subject",
60 - "$prg --in files/source1.pdf --out out.pdf --key Subject " .  
61 - "--val \"Export Business\"",  
62 - "", "out.pdf", "files/1.qdf"); 60 + "$prg --in files/source1.pdf --out out.pdf --key Subject " .
  61 + "--val \"Export Business\"",
  62 + "", "out.pdf", "files/1.qdf");
63 63
64 run_and_cmp("add Subject, remove Producer, modify CreationDate", 64 run_and_cmp("add Subject, remove Producer, modify CreationDate",
65 - "$prg --in files/source2.pdf --out out.pdf --key Subject " .  
66 - "--val \"Tammlin\" --key Producer --key CreationDate --val 12/12",  
67 - "", "out.pdf", "files/2.qdf"); 65 + "$prg --in files/source2.pdf --out out.pdf --key Subject " .
  66 + "--val \"Tammlin\" --key Producer --key CreationDate --val 12/12",
  67 + "", "out.pdf", "files/2.qdf");
68 68
69 run_and_cmp("add Subject (empty-info file)", 69 run_and_cmp("add Subject (empty-info file)",
70 - "$prg --in files/empty-info.pdf --out out.pdf --key Subject " .  
71 - "--val Tammlin",  
72 - "", "out.pdf", "files/3.qdf"); 70 + "$prg --in files/empty-info.pdf --out out.pdf --key Subject " .
  71 + "--val Tammlin",
  72 + "", "out.pdf", "files/3.qdf");
73 73
74 copy("files/no-info.pdf", "no-info.pdf") or die "can't copy no-info: $!"; 74 copy("files/no-info.pdf", "no-info.pdf") or die "can't copy no-info: $!";
75 run_and_cmp("in-place Producer added (no-info file)", 75 run_and_cmp("in-place Producer added (no-info file)",
76 - "$prg --in no-info.pdf --key Producer --val \"Obivan Kinobi\"",  
77 - "", "no-info.pdf", "files/4.qdf"); 76 + "$prg --in no-info.pdf --key Producer --val \"Obivan Kinobi\"",
  77 + "", "no-info.pdf", "files/4.qdf");
78 78
79 cleanup(); 79 cleanup();
80 80
@@ -89,12 +89,12 @@ sub run_and_cmp @@ -89,12 +89,12 @@ sub run_and_cmp
89 { 89 {
90 my ($dsc, $cmd, $out, $fout, $fexp) = @_; 90 my ($dsc, $cmd, $out, $fout, $fexp) = @_;
91 $td->runtest($dsc, 91 $td->runtest($dsc,
92 - {$td->COMMAND => "$cmd --static-id"},  
93 - {$td->STRING => $out,  
94 - $td->EXIT_STATUS => 0}); 92 + {$td->COMMAND => "$cmd --static-id"},
  93 + {$td->STRING => $out,
  94 + $td->EXIT_STATUS => 0});
95 $td->runtest("$dsc output", 95 $td->runtest("$dsc output",
96 - {$td->COMMAND => "$qpdf --static-id" .  
97 - " --no-original-object-ids -qdf $fout -"},  
98 - {$td->FILE => $fexp,  
99 - $td->EXIT_STATUS => 0}); 96 + {$td->COMMAND => "$qpdf --static-id" .
  97 + " --no-original-object-ids -qdf $fout -"},
  98 + {$td->FILE => $fexp,
  99 + $td->EXIT_STATUS => 0});
100 } 100 }
examples/qtest/name-number-tree.test
@@ -12,13 +12,13 @@ my $td = new TestDriver(&#39;name-number-tree&#39;); @@ -12,13 +12,13 @@ my $td = new TestDriver(&#39;name-number-tree&#39;);
12 cleanup(); 12 cleanup();
13 13
14 $td->runtest("name/number tree", 14 $td->runtest("name/number tree",
15 - {$td->COMMAND => 'pdf-name-number-tree a.pdf'},  
16 - {$td->FILE => 'nn.out', $td->EXIT_STATUS => 0},  
17 - $td->NORMALIZE_NEWLINES); 15 + {$td->COMMAND => 'pdf-name-number-tree a.pdf'},
  16 + {$td->FILE => 'nn.out', $td->EXIT_STATUS => 0},
  17 + $td->NORMALIZE_NEWLINES);
18 18
19 $td->runtest("check output", 19 $td->runtest("check output",
20 - {$td->FILE => "a.pdf"},  
21 - {$td->FILE => "out.pdf"}); 20 + {$td->FILE => "a.pdf"},
  21 + {$td->FILE => "out.pdf"});
22 22
23 cleanup(); 23 cleanup();
24 24
examples/qtest/npages.test
@@ -10,14 +10,14 @@ require TestDriver; @@ -10,14 +10,14 @@ require TestDriver;
10 my $td = new TestDriver('pdf-npages'); 10 my $td = new TestDriver('pdf-npages');
11 11
12 $td->runtest("normal", 12 $td->runtest("normal",
13 - {$td->COMMAND => "pdf-npages minimal.pdf"},  
14 - {$td->STRING => "1\n", $td->EXIT_STATUS => 0},  
15 - $td->NORMALIZE_NEWLINES); 13 + {$td->COMMAND => "pdf-npages minimal.pdf"},
  14 + {$td->STRING => "1\n", $td->EXIT_STATUS => 0},
  15 + $td->NORMALIZE_NEWLINES);
16 16
17 $td->runtest("error", 17 $td->runtest("error",
18 - {$td->COMMAND => "pdf-npages bad"},  
19 - {$td->REGEXP => "pdf-npages: bad: unable to find trailer.*",  
20 - $td->EXIT_STATUS => 2},  
21 - $td->NORMALIZE_NEWLINES); 18 + {$td->COMMAND => "pdf-npages bad"},
  19 + {$td->REGEXP => "pdf-npages: bad: unable to find trailer.*",
  20 + $td->EXIT_STATUS => 2},
  21 + $td->NORMALIZE_NEWLINES);
22 22
23 $td->report(2); 23 $td->report(2);
examples/qtest/overlay-page.test
@@ -12,18 +12,18 @@ my $td = new TestDriver(&#39;overlay-page&#39;); @@ -12,18 +12,18 @@ my $td = new TestDriver(&#39;overlay-page&#39;);
12 cleanup(); 12 cleanup();
13 13
14 $td->runtest("overlay-page", 14 $td->runtest("overlay-page",
15 - {$td->COMMAND => "pdf-overlay-page in.pdf stamp.pdf a.pdf"},  
16 - {$td->STRING => "", $td->EXIT_STATUS => 0}); 15 + {$td->COMMAND => "pdf-overlay-page in.pdf stamp.pdf a.pdf"},
  16 + {$td->STRING => "", $td->EXIT_STATUS => 0});
17 $td->runtest("compare files", 17 $td->runtest("compare files",
18 - {$td->FILE => "a.pdf"},  
19 - {$td->FILE => "out.pdf"}); 18 + {$td->FILE => "a.pdf"},
  19 + {$td->FILE => "out.pdf"});
20 20
21 $td->runtest("overlay-page with fields/ annotations", 21 $td->runtest("overlay-page with fields/ annotations",
22 - {$td->COMMAND => "pdf-overlay-page in.pdf annotations.pdf a.pdf"},  
23 - {$td->STRING => "", $td->EXIT_STATUS => 0}); 22 + {$td->COMMAND => "pdf-overlay-page in.pdf annotations.pdf a.pdf"},
  23 + {$td->STRING => "", $td->EXIT_STATUS => 0});
24 $td->runtest("compare files", 24 $td->runtest("compare files",
25 - {$td->FILE => "a.pdf"},  
26 - {$td->FILE => "annotations-out.pdf"}); 25 + {$td->FILE => "a.pdf"},
  26 + {$td->FILE => "annotations-out.pdf"});
27 27
28 cleanup(); 28 cleanup();
29 29
examples/qtest/parse-content.test
@@ -10,8 +10,8 @@ require TestDriver; @@ -10,8 +10,8 @@ require TestDriver;
10 my $td = new TestDriver('pdf-parse-content'); 10 my $td = new TestDriver('pdf-parse-content');
11 11
12 $td->runtest("parse content", 12 $td->runtest("parse content",
13 - {$td->COMMAND => "pdf-parse-content input.pdf 1"},  
14 - {$td->FILE => "content.out", $td->EXIT_STATUS => 0},  
15 - $td->NORMALIZE_NEWLINES); 13 + {$td->COMMAND => "pdf-parse-content input.pdf 1"},
  14 + {$td->FILE => "content.out", $td->EXIT_STATUS => 0},
  15 + $td->NORMALIZE_NEWLINES);
16 16
17 $td->report(1); 17 $td->report(1);
examples/qtest/pdf-split-pages.test
@@ -12,16 +12,16 @@ my $td = new TestDriver(&#39;pdf-split-pages&#39;); @@ -12,16 +12,16 @@ my $td = new TestDriver(&#39;pdf-split-pages&#39;);
12 cleanup(); 12 cleanup();
13 13
14 $td->runtest("split", 14 $td->runtest("split",
15 - {$td->COMMAND => "pdf-split-pages ' --static-id' in.pdf out"},  
16 - {$td->STRING => "", $td->EXIT_STATUS => 0}); 15 + {$td->COMMAND => "pdf-split-pages ' --static-id' in.pdf out"},
  16 + {$td->STRING => "", $td->EXIT_STATUS => 0});
17 17
18 $td->runtest("check page 1", 18 $td->runtest("check page 1",
19 - {$td->FILE => "out1.pdf"},  
20 - {$td->FILE => "exp1.pdf"}); 19 + {$td->FILE => "out1.pdf"},
  20 + {$td->FILE => "exp1.pdf"});
21 21
22 $td->runtest("check page 2", 22 $td->runtest("check page 2",
23 - {$td->FILE => "out2.pdf"},  
24 - {$td->FILE => "exp2.pdf"}); 23 + {$td->FILE => "out2.pdf"},
  24 + {$td->FILE => "exp2.pdf"});
25 25
26 cleanup(); 26 cleanup();
27 27
examples/qtest/qpdf-job.test
@@ -12,8 +12,8 @@ cleanup(); @@ -12,8 +12,8 @@ cleanup();
12 my $td = new TestDriver('qpdf-job'); 12 my $td = new TestDriver('qpdf-job');
13 13
14 $td->runtest("qpdf-job", 14 $td->runtest("qpdf-job",
15 - {$td->COMMAND => "qpdf-job"},  
16 - {$td->FILE => "out", $td->EXIT_STATUS => 0}, 15 + {$td->COMMAND => "qpdf-job"},
  16 + {$td->FILE => "out", $td->EXIT_STATUS => 0},
17 $td->NORMALIZE_NEWLINES); 17 $td->NORMALIZE_NEWLINES);
18 for (my $i = 1; $i <= 3; ++$i) 18 for (my $i = 1; $i <= 3; ++$i)
19 { 19 {
examples/qtest/qpdfjob-c.test
@@ -12,12 +12,12 @@ cleanup(); @@ -12,12 +12,12 @@ cleanup();
12 my $td = new TestDriver('qpdfjob-c'); 12 my $td = new TestDriver('qpdfjob-c');
13 13
14 $td->runtest("qpdfjob-c", 14 $td->runtest("qpdfjob-c",
15 - {$td->COMMAND => "qpdfjob-c in.pdf a.pdf"},  
16 - {$td->STRING => "", $td->EXIT_STATUS => 0}, 15 + {$td->COMMAND => "qpdfjob-c in.pdf a.pdf"},
  16 + {$td->STRING => "", $td->EXIT_STATUS => 0},
17 $td->NORMALIZE_NEWLINES); 17 $td->NORMALIZE_NEWLINES);
18 $td->runtest("check output", 18 $td->runtest("check output",
19 - {$td->FILE => "a.pdf"},  
20 - {$td->FILE => "out.pdf"}); 19 + {$td->FILE => "a.pdf"},
  20 + {$td->FILE => "out.pdf"});
21 21
22 cleanup(); 22 cleanup();
23 23
examples/qtest/set-form-values.test
@@ -12,11 +12,11 @@ my $td = new TestDriver(&#39;pdf-set-form-values&#39;); @@ -12,11 +12,11 @@ my $td = new TestDriver(&#39;pdf-set-form-values&#39;);
12 cleanup(); 12 cleanup();
13 13
14 $td->runtest("set form values", 14 $td->runtest("set form values",
15 - {$td->COMMAND => "pdf-set-form-values form-in.pdf a.pdf soup"},  
16 - {$td->STRING => "", $td->EXIT_STATUS => 0}); 15 + {$td->COMMAND => "pdf-set-form-values form-in.pdf a.pdf soup"},
  16 + {$td->STRING => "", $td->EXIT_STATUS => 0});
17 $td->runtest("compare files", 17 $td->runtest("compare files",
18 - {$td->FILE => "a.pdf"},  
19 - {$td->FILE => "form-out.pdf"}); 18 + {$td->FILE => "a.pdf"},
  19 + {$td->FILE => "form-out.pdf"});
20 20
21 cleanup(); 21 cleanup();
22 22
fuzz/qpdf_fuzzer.cc
@@ -107,7 +107,7 @@ FuzzHelper::testWrite() @@ -107,7 +107,7 @@ FuzzHelper::testWrite()
107 w->setStaticID(true); 107 w->setStaticID(true);
108 w->setObjectStreamMode(qpdf_o_disable); 108 w->setObjectStreamMode(qpdf_o_disable);
109 w->setR3EncryptionParameters( 109 w->setR3EncryptionParameters(
110 - "u", "o", true, true, true, true, true, true, qpdf_r3p_full); 110 + "u", "o", true, true, true, true, true, true, qpdf_r3p_full);
111 doWrite(w); 111 doWrite(w);
112 112
113 q = getQpdf(); 113 q = getQpdf();
include/qpdf/Constants.h
@@ -32,11 +32,11 @@ @@ -32,11 +32,11 @@
32 enum qpdf_error_code_e 32 enum qpdf_error_code_e
33 { 33 {
34 qpdf_e_success = 0, 34 qpdf_e_success = 0,
35 - qpdf_e_internal, /* logic/programming error -- indicates bug */  
36 - qpdf_e_system, /* I/O error, memory error, etc. */  
37 - qpdf_e_unsupported, /* PDF feature not (yet) supported by qpdf */  
38 - qpdf_e_password, /* incorrect password for encrypted file */  
39 - qpdf_e_damaged_pdf, /* syntax errors or other damage in PDF */ 35 + qpdf_e_internal, /* logic/programming error -- indicates bug */
  36 + qpdf_e_system, /* I/O error, memory error, etc. */
  37 + qpdf_e_unsupported, /* PDF feature not (yet) supported by qpdf */
  38 + qpdf_e_password, /* incorrect password for encrypted file */
  39 + qpdf_e_damaged_pdf, /* syntax errors or other damage in PDF */
40 qpdf_e_pages, /* erroneous or unsupported pages structure */ 40 qpdf_e_pages, /* erroneous or unsupported pages structure */
41 qpdf_e_object, /* type/bounds errors accessing objects */ 41 qpdf_e_object, /* type/bounds errors accessing objects */
42 }; 42 };
@@ -77,15 +77,15 @@ enum qpdf_object_type_e { @@ -77,15 +77,15 @@ enum qpdf_object_type_e {
77 77
78 enum qpdf_object_stream_e 78 enum qpdf_object_stream_e
79 { 79 {
80 - qpdf_o_disable = 0, /* disable object streams */  
81 - qpdf_o_preserve, /* preserve object streams */  
82 - qpdf_o_generate /* generate object streams */ 80 + qpdf_o_disable = 0, /* disable object streams */
  81 + qpdf_o_preserve, /* preserve object streams */
  82 + qpdf_o_generate /* generate object streams */
83 }; 83 };
84 enum qpdf_stream_data_e 84 enum qpdf_stream_data_e
85 { 85 {
86 - qpdf_s_uncompress = 0, /* uncompress stream data */  
87 - qpdf_s_preserve, /* preserve stream data compression */  
88 - qpdf_s_compress /* compress stream data */ 86 + qpdf_s_uncompress = 0, /* uncompress stream data */
  87 + qpdf_s_preserve, /* preserve stream data compression */
  88 + qpdf_s_compress /* compress stream data */
89 }; 89 };
90 90
91 /* Stream data flags */ 91 /* Stream data flags */
@@ -109,22 +109,22 @@ enum qpdf_stream_decode_level_e @@ -109,22 +109,22 @@ enum qpdf_stream_decode_level_e
109 109
110 enum qpdf_r3_print_e 110 enum qpdf_r3_print_e
111 { 111 {
112 - qpdf_r3p_full = 0, /* allow all printing */  
113 - qpdf_r3p_low, /* allow only low-resolution printing */  
114 - qpdf_r3p_none /* allow no printing */ 112 + qpdf_r3p_full = 0, /* allow all printing */
  113 + qpdf_r3p_low, /* allow only low-resolution printing */
  114 + qpdf_r3p_none /* allow no printing */
115 }; 115 };
116 116
117 /* qpdf_r3_modify_e doesn't allow the full flexibility of the spec. It 117 /* qpdf_r3_modify_e doesn't allow the full flexibility of the spec. It
118 * corresponds to options in Acrobat 5's menus. The new interface in 118 * corresponds to options in Acrobat 5's menus. The new interface in
119 * QPDFWriter offers more granularity and no longer uses this type. 119 * QPDFWriter offers more granularity and no longer uses this type.
120 */ 120 */
121 -enum qpdf_r3_modify_e /* Allowed changes: */ 121 +enum qpdf_r3_modify_e /* Allowed changes: */
122 { 122 {
123 - qpdf_r3m_all = 0, /* All editing */ 123 + qpdf_r3m_all = 0, /* All editing */
124 qpdf_r3m_annotate, /* Comments, fill forms, signing, assembly */ 124 qpdf_r3m_annotate, /* Comments, fill forms, signing, assembly */
125 - qpdf_r3m_form, /* Fill forms, signing, assembly */  
126 - qpdf_r3m_assembly, /* Only document assembly */  
127 - qpdf_r3m_none /* No modifications */ 125 + qpdf_r3m_form, /* Fill forms, signing, assembly */
  126 + qpdf_r3m_assembly, /* Only document assembly */
  127 + qpdf_r3m_none /* No modifications */
128 }; 128 };
129 129
130 /* Form field flags from the PDF spec */ 130 /* Form field flags from the PDF spec */
include/qpdf/Pl_Flate.hh
@@ -36,7 +36,7 @@ class Pl_Flate: public Pipeline @@ -36,7 +36,7 @@ class Pl_Flate: public Pipeline
36 36
37 QPDF_DLL 37 QPDF_DLL
38 Pl_Flate(char const* identifier, Pipeline* next, 38 Pl_Flate(char const* identifier, Pipeline* next,
39 - action_e action, unsigned int out_bufsize = def_bufsize); 39 + action_e action, unsigned int out_bufsize = def_bufsize);
40 QPDF_DLL 40 QPDF_DLL
41 virtual ~Pl_Flate(); 41 virtual ~Pl_Flate();
42 42
include/qpdf/QPDF.hh
@@ -95,8 +95,8 @@ class QPDF @@ -95,8 +95,8 @@ class QPDF
95 // error message in place of the file name. 95 // error message in place of the file name.
96 QPDF_DLL 96 QPDF_DLL
97 void processMemoryFile(char const* description, 97 void processMemoryFile(char const* description,
98 - char const* buf, size_t length,  
99 - char const* password = 0); 98 + char const* buf, size_t length,
  99 + char const* password = 0);
100 100
101 // Parse a PDF file loaded from a custom InputSource. If you have 101 // Parse a PDF file loaded from a custom InputSource. If you have
102 // your own method of retrieving a PDF file, you can subclass 102 // your own method of retrieving a PDF file, you can subclass
@@ -308,7 +308,7 @@ class QPDF @@ -308,7 +308,7 @@ class QPDF
308 void swapObjects(QPDFObjGen const& og1, QPDFObjGen const& og2); 308 void swapObjects(QPDFObjGen const& og1, QPDFObjGen const& og2);
309 QPDF_DLL 309 QPDF_DLL
310 void swapObjects(int objid1, int generation1, 310 void swapObjects(int objid1, int generation1,
311 - int objid2, int generation2); 311 + int objid2, int generation2);
312 312
313 // Replace a reserved object. This is a wrapper around 313 // Replace a reserved object. This is a wrapper around
314 // replaceObject but it guarantees that the underlying object is a 314 // replaceObject but it guarantees that the underlying object is a
@@ -373,37 +373,37 @@ class QPDF @@ -373,37 +373,37 @@ class QPDF
373 { 373 {
374 public: 374 public:
375 375
376 - // This class holds data read from the encryption dictionary.  
377 - EncryptionData(int V, int R, int Length_bytes, int P,  
378 - std::string const& O, std::string const& U, 376 + // This class holds data read from the encryption dictionary.
  377 + EncryptionData(int V, int R, int Length_bytes, int P,
  378 + std::string const& O, std::string const& U,
379 std::string const& OE, std::string const& UE, 379 std::string const& OE, std::string const& UE,
380 std::string const& Perms, 380 std::string const& Perms,
381 - std::string const& id1, bool encrypt_metadata) :  
382 - V(V),  
383 - R(R),  
384 - Length_bytes(Length_bytes),  
385 - P(P),  
386 - O(O),  
387 - U(U), 381 + std::string const& id1, bool encrypt_metadata) :
  382 + V(V),
  383 + R(R),
  384 + Length_bytes(Length_bytes),
  385 + P(P),
  386 + O(O),
  387 + U(U),
388 OE(OE), 388 OE(OE),
389 UE(UE), 389 UE(UE),
390 Perms(Perms), 390 Perms(Perms),
391 - id1(id1),  
392 - encrypt_metadata(encrypt_metadata)  
393 - {  
394 - }  
395 -  
396 - int getV() const;  
397 - int getR() const;  
398 - int getLengthBytes() const;  
399 - int getP() const;  
400 - std::string const& getO() const;  
401 - std::string const& getU() const;  
402 - std::string const& getOE() const;  
403 - std::string const& getUE() const;  
404 - std::string const& getPerms() const;  
405 - std::string const& getId1() const;  
406 - bool getEncryptMetadata() const; 391 + id1(id1),
  392 + encrypt_metadata(encrypt_metadata)
  393 + {
  394 + }
  395 +
  396 + int getV() const;
  397 + int getR() const;
  398 + int getLengthBytes() const;
  399 + int getP() const;
  400 + std::string const& getO() const;
  401 + std::string const& getU() const;
  402 + std::string const& getOE() const;
  403 + std::string const& getUE() const;
  404 + std::string const& getPerms() const;
  405 + std::string const& getId1() const;
  406 + bool getEncryptMetadata() const;
407 407
408 void setO(std::string const&); 408 void setO(std::string const&);
409 void setU(std::string const&); 409 void setU(std::string const&);
@@ -417,17 +417,17 @@ class QPDF @@ -417,17 +417,17 @@ class QPDF
417 EncryptionData(EncryptionData const&) = delete; 417 EncryptionData(EncryptionData const&) = delete;
418 EncryptionData& operator=(EncryptionData const&) = delete; 418 EncryptionData& operator=(EncryptionData const&) = delete;
419 419
420 - int V;  
421 - int R;  
422 - int Length_bytes;  
423 - int P;  
424 - std::string O;  
425 - std::string U; 420 + int V;
  421 + int R;
  422 + int Length_bytes;
  423 + int P;
  424 + std::string O;
  425 + std::string U;
426 std::string OE; 426 std::string OE;
427 std::string UE; 427 std::string UE;
428 std::string Perms; 428 std::string Perms;
429 - std::string id1;  
430 - bool encrypt_metadata; 429 + std::string id1;
  430 + bool encrypt_metadata;
431 }; 431 };
432 432
433 QPDF_DLL 433 QPDF_DLL
@@ -475,25 +475,25 @@ class QPDF @@ -475,25 +475,25 @@ class QPDF
475 static void trim_user_password(std::string& user_password); 475 static void trim_user_password(std::string& user_password);
476 QPDF_DLL 476 QPDF_DLL
477 static std::string compute_data_key( 477 static std::string compute_data_key(
478 - std::string const& encryption_key, int objid, int generation,  
479 - bool use_aes, int encryption_V, int encryption_R); 478 + std::string const& encryption_key, int objid, int generation,
  479 + bool use_aes, int encryption_V, int encryption_R);
480 QPDF_DLL 480 QPDF_DLL
481 static std::string compute_encryption_key( 481 static std::string compute_encryption_key(
482 - std::string const& password, EncryptionData const& data); 482 + std::string const& password, EncryptionData const& data);
483 483
484 QPDF_DLL 484 QPDF_DLL
485 static void compute_encryption_O_U( 485 static void compute_encryption_O_U(
486 - char const* user_password, char const* owner_password,  
487 - int V, int R, int key_len, int P, bool encrypt_metadata,  
488 - std::string const& id1,  
489 - std::string& O, std::string& U); 486 + char const* user_password, char const* owner_password,
  487 + int V, int R, int key_len, int P, bool encrypt_metadata,
  488 + std::string const& id1,
  489 + std::string& O, std::string& U);
490 QPDF_DLL 490 QPDF_DLL
491 static void compute_encryption_parameters_V5( 491 static void compute_encryption_parameters_V5(
492 - char const* user_password, char const* owner_password,  
493 - int V, int R, int key_len, int P, bool encrypt_metadata,  
494 - std::string const& id1, 492 + char const* user_password, char const* owner_password,
  493 + int V, int R, int key_len, int P, bool encrypt_metadata,
  494 + std::string const& id1,
495 std::string& encryption_key, 495 std::string& encryption_key,
496 - std::string& O, std::string& U, 496 + std::string& O, std::string& U,
497 std::string& OE, std::string& UE, std::string& Perms); 497 std::string& OE, std::string& UE, std::string& Perms);
498 // Return the full user password as stored in the PDF file. For 498 // Return the full user password as stored in the PDF file. For
499 // files encrypted with 40-bit or 128-bit keys, the user password 499 // files encrypted with 40-bit or 128-bit keys, the user password
@@ -583,7 +583,7 @@ class QPDF @@ -583,7 +583,7 @@ class QPDF
583 // objects for stream dictionary keys it will be regenerating. 583 // objects for stream dictionary keys it will be regenerating.
584 QPDF_DLL 584 QPDF_DLL
585 void optimize(std::map<int, int> const& object_stream_data, 585 void optimize(std::map<int, int> const& object_stream_data,
586 - bool allow_changes = true); 586 + bool allow_changes = true);
587 // ABI: make function optional and merge overloaded versions 587 // ABI: make function optional and merge overloaded versions
588 QPDF_DLL 588 QPDF_DLL
589 void optimize( 589 void optimize(
@@ -698,13 +698,13 @@ class QPDF @@ -698,13 +698,13 @@ class QPDF
698 // it can resolve indirect references. 698 // it can resolve indirect references.
699 class Resolver 699 class Resolver
700 { 700 {
701 - friend class QPDFObjectHandle; 701 + friend class QPDFObjectHandle;
702 private: 702 private:
703 - static PointerHolder<QPDFObject> resolve(  
704 - QPDF* qpdf, int objid, int generation)  
705 - {  
706 - return qpdf->resolve(objid, generation);  
707 - } 703 + static PointerHolder<QPDFObject> resolve(
  704 + QPDF* qpdf, int objid, int generation)
  705 + {
  706 + return qpdf->resolve(objid, generation);
  707 + }
708 static bool objectChanged( 708 static bool objectChanged(
709 QPDF* qpdf, QPDFObjGen const& og, PointerHolder<QPDFObject>& oph) 709 QPDF* qpdf, QPDFObjGen const& og, PointerHolder<QPDFObject>& oph)
710 { 710 {
@@ -717,14 +717,14 @@ class QPDF @@ -717,14 +717,14 @@ class QPDF
717 // copy stream data. 717 // copy stream data.
718 class StreamCopier 718 class StreamCopier
719 { 719 {
720 - friend class QPDFObjectHandle; 720 + friend class QPDFObjectHandle;
721 private: 721 private:
722 - static void copyStreamData(QPDF* qpdf, 722 + static void copyStreamData(QPDF* qpdf,
723 QPDFObjectHandle const& dest, 723 QPDFObjectHandle const& dest,
724 QPDFObjectHandle const& src) 724 QPDFObjectHandle const& src)
725 - {  
726 - qpdf->copyStreamData(dest, src);  
727 - } 725 + {
  726 + qpdf->copyStreamData(dest, src);
  727 + }
728 }; 728 };
729 friend class Resolver; 729 friend class Resolver;
730 730
@@ -732,7 +732,7 @@ class QPDF @@ -732,7 +732,7 @@ class QPDF
732 // resolution 732 // resolution
733 class ParseGuard 733 class ParseGuard
734 { 734 {
735 - friend class QPDFObjectHandle; 735 + friend class QPDFObjectHandle;
736 private: 736 private:
737 ParseGuard(QPDF* qpdf) : 737 ParseGuard(QPDF* qpdf) :
738 qpdf(qpdf) 738 qpdf(qpdf)
@@ -756,19 +756,19 @@ class QPDF @@ -756,19 +756,19 @@ class QPDF
756 // Pipe class is restricted to QPDF_Stream 756 // Pipe class is restricted to QPDF_Stream
757 class Pipe 757 class Pipe
758 { 758 {
759 - friend class QPDF_Stream; 759 + friend class QPDF_Stream;
760 private: 760 private:
761 - static bool pipeStreamData(QPDF* qpdf, int objid, int generation,  
762 - qpdf_offset_t offset, size_t length,  
763 - QPDFObjectHandle dict,  
764 - Pipeline* pipeline, 761 + static bool pipeStreamData(QPDF* qpdf, int objid, int generation,
  762 + qpdf_offset_t offset, size_t length,
  763 + QPDFObjectHandle dict,
  764 + Pipeline* pipeline,
765 bool suppress_warnings, 765 bool suppress_warnings,
766 bool will_retry) 766 bool will_retry)
767 - {  
768 - return qpdf->pipeStreamData(  
769 - objid, generation, offset, length, dict, pipeline, 767 + {
  768 + return qpdf->pipeStreamData(
  769 + objid, generation, offset, length, dict, pipeline,
770 suppress_warnings, will_retry); 770 suppress_warnings, will_retry);
771 - } 771 + }
772 }; 772 };
773 friend class Pipe; 773 friend class Pipe;
774 774
@@ -778,23 +778,23 @@ class QPDF @@ -778,23 +778,23 @@ class QPDF
778 class ObjCache 778 class ObjCache
779 { 779 {
780 public: 780 public:
781 - ObjCache() :  
782 - end_before_space(0),  
783 - end_after_space(0)  
784 - {  
785 - }  
786 - ObjCache(PointerHolder<QPDFObject> object,  
787 - qpdf_offset_t end_before_space,  
788 - qpdf_offset_t end_after_space) :  
789 - object(object),  
790 - end_before_space(end_before_space),  
791 - end_after_space(end_after_space)  
792 - {  
793 - }  
794 -  
795 - PointerHolder<QPDFObject> object;  
796 - qpdf_offset_t end_before_space;  
797 - qpdf_offset_t end_after_space; 781 + ObjCache() :
  782 + end_before_space(0),
  783 + end_after_space(0)
  784 + {
  785 + }
  786 + ObjCache(PointerHolder<QPDFObject> object,
  787 + qpdf_offset_t end_before_space,
  788 + qpdf_offset_t end_after_space) :
  789 + object(object),
  790 + end_before_space(end_before_space),
  791 + end_after_space(end_after_space)
  792 + {
  793 + }
  794 +
  795 + PointerHolder<QPDFObject> object;
  796 + qpdf_offset_t end_before_space;
  797 + qpdf_offset_t end_after_space;
798 }; 798 };
799 799
800 class ObjCopier 800 class ObjCopier
@@ -861,7 +861,7 @@ class QPDF @@ -861,7 +861,7 @@ class QPDF
861 virtual ~CopiedStreamDataProvider() 861 virtual ~CopiedStreamDataProvider()
862 { 862 {
863 } 863 }
864 - virtual bool provideStreamData( 864 + virtual bool provideStreamData(
865 int objid, int generation, Pipeline* pipeline, 865 int objid, int generation, Pipeline* pipeline,
866 bool suppress_warnings, bool will_retry) override; 866 bool suppress_warnings, bool will_retry) override;
867 void registerForeignStream(QPDFObjGen const& local_og, 867 void registerForeignStream(QPDFObjGen const& local_og,
@@ -926,23 +926,23 @@ class QPDF @@ -926,23 +926,23 @@ class QPDF
926 qpdf_offset_t processXRefStream( 926 qpdf_offset_t processXRefStream(
927 qpdf_offset_t offset, QPDFObjectHandle& xref_stream); 927 qpdf_offset_t offset, QPDFObjectHandle& xref_stream);
928 void insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, 928 void insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2,
929 - bool overwrite = false); 929 + bool overwrite = false);
930 void setLastObjectDescription(std::string const& description, 930 void setLastObjectDescription(std::string const& description,
931 - int objid, int generation); 931 + int objid, int generation);
932 QPDFObjectHandle readObject( 932 QPDFObjectHandle readObject(
933 - PointerHolder<InputSource>, std::string const& description,  
934 - int objid, int generation, bool in_object_stream); 933 + PointerHolder<InputSource>, std::string const& description,
  934 + int objid, int generation, bool in_object_stream);
935 size_t recoverStreamLength( 935 size_t recoverStreamLength(
936 - PointerHolder<InputSource> input, int objid, int generation,  
937 - qpdf_offset_t stream_offset); 936 + PointerHolder<InputSource> input, int objid, int generation,
  937 + qpdf_offset_t stream_offset);
938 QPDFTokenizer::Token readToken(PointerHolder<InputSource>, 938 QPDFTokenizer::Token readToken(PointerHolder<InputSource>,
939 size_t max_len = 0); 939 size_t max_len = 0);
940 940
941 QPDFObjectHandle readObjectAtOffset( 941 QPDFObjectHandle readObjectAtOffset(
942 - bool attempt_recovery,  
943 - qpdf_offset_t offset, std::string const& description,  
944 - int exp_objid, int exp_generation,  
945 - int& act_objid, int& act_generation); 942 + bool attempt_recovery,
  943 + qpdf_offset_t offset, std::string const& description,
  944 + int exp_objid, int exp_generation,
  945 + int& act_objid, int& act_generation);
946 bool objectChanged(QPDFObjGen const& og, PointerHolder<QPDFObject>& oph); 946 bool objectChanged(QPDFObjGen const& og, PointerHolder<QPDFObject>& oph);
947 PointerHolder<QPDFObject> resolve(int objid, int generation); 947 PointerHolder<QPDFObject> resolve(int objid, int generation);
948 void resolveObjectsInStream(int obj_stream_number); 948 void resolveObjectsInStream(int obj_stream_number);
@@ -950,9 +950,9 @@ class QPDF @@ -950,9 +950,9 @@ class QPDF
950 950
951 // Calls finish() on the pipeline when done but does not delete it 951 // Calls finish() on the pipeline when done but does not delete it
952 bool pipeStreamData(int objid, int generation, 952 bool pipeStreamData(int objid, int generation,
953 - qpdf_offset_t offset, size_t length,  
954 - QPDFObjectHandle dict,  
955 - Pipeline* pipeline, 953 + qpdf_offset_t offset, size_t length,
  954 + QPDFObjectHandle dict,
  955 + Pipeline* pipeline,
956 bool suppress_warnings, 956 bool suppress_warnings,
957 bool will_retry); 957 bool will_retry);
958 bool pipeForeignStreamData( 958 bool pipeForeignStreamData(
@@ -973,18 +973,18 @@ class QPDF @@ -973,18 +973,18 @@ class QPDF
973 // Get lists of all objects in order according to the part of a 973 // Get lists of all objects in order according to the part of a
974 // linearized file that they belong to. 974 // linearized file that they belong to.
975 void getLinearizedParts( 975 void getLinearizedParts(
976 - std::map<int, int> const& object_stream_data,  
977 - std::vector<QPDFObjectHandle>& part4,  
978 - std::vector<QPDFObjectHandle>& part6,  
979 - std::vector<QPDFObjectHandle>& part7,  
980 - std::vector<QPDFObjectHandle>& part8,  
981 - std::vector<QPDFObjectHandle>& part9); 976 + std::map<int, int> const& object_stream_data,
  977 + std::vector<QPDFObjectHandle>& part4,
  978 + std::vector<QPDFObjectHandle>& part6,
  979 + std::vector<QPDFObjectHandle>& part7,
  980 + std::vector<QPDFObjectHandle>& part8,
  981 + std::vector<QPDFObjectHandle>& part9);
982 982
983 void generateHintStream(std::map<int, QPDFXRefEntry> const& xref, 983 void generateHintStream(std::map<int, QPDFXRefEntry> const& xref,
984 - std::map<int, qpdf_offset_t> const& lengths,  
985 - std::map<int, int> const& obj_renumber,  
986 - PointerHolder<Buffer>& hint_stream,  
987 - int& S, int& O); 984 + std::map<int, qpdf_offset_t> const& lengths,
  985 + std::map<int, int> const& obj_renumber,
  986 + PointerHolder<Buffer>& hint_stream,
  987 + int& S, int& O);
988 988
989 // Map object to object stream that contains it 989 // Map object to object stream that contains it
990 void getObjectStreamData(std::map<int, int>&); 990 void getObjectStreamData(std::map<int, int>&);
@@ -1020,12 +1020,12 @@ class QPDF @@ -1020,12 +1020,12 @@ class QPDF
1020 std::string const& password, EncryptionData const& data, 1020 std::string const& password, EncryptionData const& data,
1021 bool& perms_valid); 1021 bool& perms_valid);
1022 static void decryptStream( 1022 static void decryptStream(
1023 - PointerHolder<EncryptionParameters> encp, 1023 + PointerHolder<EncryptionParameters> encp,
1024 PointerHolder<InputSource> file, 1024 PointerHolder<InputSource> file,
1025 QPDF& qpdf_for_warning, Pipeline*& pipeline, 1025 QPDF& qpdf_for_warning, Pipeline*& pipeline,
1026 int objid, int generation, 1026 int objid, int generation,
1027 - QPDFObjectHandle& stream_dict,  
1028 - std::vector<std::shared_ptr<Pipeline>>& heap); 1027 + QPDFObjectHandle& stream_dict,
  1028 + std::vector<std::shared_ptr<Pipeline>>& heap);
1029 1029
1030 // Methods to support object copying 1030 // Methods to support object copying
1031 void reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, 1031 void reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier,
@@ -1051,118 +1051,118 @@ class QPDF @@ -1051,118 +1051,118 @@ class QPDF
1051 // PDF 1.4: Table F.4 1051 // PDF 1.4: Table F.4
1052 struct HPageOffsetEntry 1052 struct HPageOffsetEntry
1053 { 1053 {
1054 - HPageOffsetEntry() :  
1055 - delta_nobjects(0),  
1056 - delta_page_length(0),  
1057 - nshared_objects(0),  
1058 - delta_content_offset(0),  
1059 - delta_content_length(0)  
1060 - {  
1061 - }  
1062 -  
1063 - int delta_nobjects; // 1  
1064 - qpdf_offset_t delta_page_length; // 2  
1065 - int nshared_objects; // 3  
1066 - // vectors' sizes = nshared_objects  
1067 - std::vector<int> shared_identifiers; // 4  
1068 - std::vector<int> shared_numerators; // 5  
1069 - qpdf_offset_t delta_content_offset; // 6 1054 + HPageOffsetEntry() :
  1055 + delta_nobjects(0),
  1056 + delta_page_length(0),
  1057 + nshared_objects(0),
  1058 + delta_content_offset(0),
  1059 + delta_content_length(0)
  1060 + {
  1061 + }
  1062 +
  1063 + int delta_nobjects; // 1
  1064 + qpdf_offset_t delta_page_length; // 2
  1065 + int nshared_objects; // 3
  1066 + // vectors' sizes = nshared_objects
  1067 + std::vector<int> shared_identifiers; // 4
  1068 + std::vector<int> shared_numerators; // 5
  1069 + qpdf_offset_t delta_content_offset; // 6
1070 qpdf_offset_t delta_content_length; // 7 1070 qpdf_offset_t delta_content_length; // 7
1071 }; 1071 };
1072 1072
1073 // PDF 1.4: Table F.3 1073 // PDF 1.4: Table F.3
1074 struct HPageOffset 1074 struct HPageOffset
1075 { 1075 {
1076 - HPageOffset() :  
1077 - min_nobjects(0),  
1078 - first_page_offset(0),  
1079 - nbits_delta_nobjects(0),  
1080 - min_page_length(0),  
1081 - nbits_delta_page_length(0),  
1082 - min_content_offset(0),  
1083 - nbits_delta_content_offset(0),  
1084 - min_content_length(0),  
1085 - nbits_delta_content_length(0),  
1086 - nbits_nshared_objects(0),  
1087 - nbits_shared_identifier(0),  
1088 - nbits_shared_numerator(0),  
1089 - shared_denominator(0)  
1090 - {  
1091 - }  
1092 -  
1093 - int min_nobjects; // 1  
1094 - qpdf_offset_t first_page_offset; // 2  
1095 - int nbits_delta_nobjects; // 3  
1096 - int min_page_length; // 4  
1097 - int nbits_delta_page_length; // 5  
1098 - int min_content_offset; // 6  
1099 - int nbits_delta_content_offset; // 7  
1100 - int min_content_length; // 8  
1101 - int nbits_delta_content_length; // 9  
1102 - int nbits_nshared_objects; // 10  
1103 - int nbits_shared_identifier; // 11  
1104 - int nbits_shared_numerator; // 12  
1105 - int shared_denominator; // 13  
1106 - // vector size is npages  
1107 - std::vector<HPageOffsetEntry> entries; 1076 + HPageOffset() :
  1077 + min_nobjects(0),
  1078 + first_page_offset(0),
  1079 + nbits_delta_nobjects(0),
  1080 + min_page_length(0),
  1081 + nbits_delta_page_length(0),
  1082 + min_content_offset(0),
  1083 + nbits_delta_content_offset(0),
  1084 + min_content_length(0),
  1085 + nbits_delta_content_length(0),
  1086 + nbits_nshared_objects(0),
  1087 + nbits_shared_identifier(0),
  1088 + nbits_shared_numerator(0),
  1089 + shared_denominator(0)
  1090 + {
  1091 + }
  1092 +
  1093 + int min_nobjects; // 1
  1094 + qpdf_offset_t first_page_offset; // 2
  1095 + int nbits_delta_nobjects; // 3
  1096 + int min_page_length; // 4
  1097 + int nbits_delta_page_length; // 5
  1098 + int min_content_offset; // 6
  1099 + int nbits_delta_content_offset; // 7
  1100 + int min_content_length; // 8
  1101 + int nbits_delta_content_length; // 9
  1102 + int nbits_nshared_objects; // 10
  1103 + int nbits_shared_identifier; // 11
  1104 + int nbits_shared_numerator; // 12
  1105 + int shared_denominator; // 13
  1106 + // vector size is npages
  1107 + std::vector<HPageOffsetEntry> entries;
1108 }; 1108 };
1109 1109
1110 // PDF 1.4: Table F.6 1110 // PDF 1.4: Table F.6
1111 struct HSharedObjectEntry 1111 struct HSharedObjectEntry
1112 { 1112 {
1113 - HSharedObjectEntry() :  
1114 - delta_group_length(0),  
1115 - signature_present(0),  
1116 - nobjects_minus_one(0)  
1117 - {  
1118 - }  
1119 -  
1120 - // Item 3 is a 128-bit signature (unsupported by Acrobat)  
1121 - int delta_group_length; // 1  
1122 - int signature_present; // 2 -- always 0  
1123 - int nobjects_minus_one; // 4 -- always 0 1113 + HSharedObjectEntry() :
  1114 + delta_group_length(0),
  1115 + signature_present(0),
  1116 + nobjects_minus_one(0)
  1117 + {
  1118 + }
  1119 +
  1120 + // Item 3 is a 128-bit signature (unsupported by Acrobat)
  1121 + int delta_group_length; // 1
  1122 + int signature_present; // 2 -- always 0
  1123 + int nobjects_minus_one; // 4 -- always 0
1124 }; 1124 };
1125 1125
1126 // PDF 1.4: Table F.5 1126 // PDF 1.4: Table F.5
1127 struct HSharedObject 1127 struct HSharedObject
1128 { 1128 {
1129 - HSharedObject() :  
1130 - first_shared_obj(0),  
1131 - first_shared_offset(0),  
1132 - nshared_first_page(0),  
1133 - nshared_total(0),  
1134 - nbits_nobjects(0),  
1135 - min_group_length(0),  
1136 - nbits_delta_group_length(0)  
1137 - {  
1138 - }  
1139 -  
1140 - int first_shared_obj; // 1  
1141 - qpdf_offset_t first_shared_offset; // 2  
1142 - int nshared_first_page; // 3  
1143 - int nshared_total; // 4  
1144 - int nbits_nobjects; // 5  
1145 - int min_group_length; // 6  
1146 - int nbits_delta_group_length; // 7  
1147 - // vector size is nshared_total  
1148 - std::vector<HSharedObjectEntry> entries; 1129 + HSharedObject() :
  1130 + first_shared_obj(0),
  1131 + first_shared_offset(0),
  1132 + nshared_first_page(0),
  1133 + nshared_total(0),
  1134 + nbits_nobjects(0),
  1135 + min_group_length(0),
  1136 + nbits_delta_group_length(0)
  1137 + {
  1138 + }
  1139 +
  1140 + int first_shared_obj; // 1
  1141 + qpdf_offset_t first_shared_offset; // 2
  1142 + int nshared_first_page; // 3
  1143 + int nshared_total; // 4
  1144 + int nbits_nobjects; // 5
  1145 + int min_group_length; // 6
  1146 + int nbits_delta_group_length; // 7
  1147 + // vector size is nshared_total
  1148 + std::vector<HSharedObjectEntry> entries;
1149 }; 1149 };
1150 1150
1151 // PDF 1.4: Table F.9 1151 // PDF 1.4: Table F.9
1152 struct HGeneric 1152 struct HGeneric
1153 { 1153 {
1154 - HGeneric() :  
1155 - first_object(0),  
1156 - first_object_offset(0),  
1157 - nobjects(0),  
1158 - group_length(0)  
1159 - {  
1160 - }  
1161 -  
1162 - int first_object; // 1  
1163 - qpdf_offset_t first_object_offset; // 2  
1164 - int nobjects; // 3  
1165 - int group_length; // 4 1154 + HGeneric() :
  1155 + first_object(0),
  1156 + first_object_offset(0),
  1157 + nobjects(0),
  1158 + group_length(0)
  1159 + {
  1160 + }
  1161 +
  1162 + int first_object; // 1
  1163 + qpdf_offset_t first_object_offset; // 2
  1164 + int nobjects; // 3
  1165 + int group_length; // 4
1166 }; 1166 };
1167 1167
1168 // Other linearization data structures 1168 // Other linearization data structures
@@ -1170,26 +1170,26 @@ class QPDF @@ -1170,26 +1170,26 @@ class QPDF
1170 // Initialized from Linearization Parameter dictionary 1170 // Initialized from Linearization Parameter dictionary
1171 struct LinParameters 1171 struct LinParameters
1172 { 1172 {
1173 - LinParameters() :  
1174 - file_size(0),  
1175 - first_page_object(0),  
1176 - first_page_end(0),  
1177 - npages(0),  
1178 - xref_zero_offset(0),  
1179 - first_page(0),  
1180 - H_offset(0),  
1181 - H_length(0)  
1182 - {  
1183 - }  
1184 -  
1185 - qpdf_offset_t file_size; // /L  
1186 - int first_page_object; // /O  
1187 - qpdf_offset_t first_page_end; // /E  
1188 - int npages; // /N  
1189 - qpdf_offset_t xref_zero_offset; // /T  
1190 - int first_page; // /P  
1191 - qpdf_offset_t H_offset; // offset of primary hint stream  
1192 - qpdf_offset_t H_length; // length of primary hint stream 1173 + LinParameters() :
  1174 + file_size(0),
  1175 + first_page_object(0),
  1176 + first_page_end(0),
  1177 + npages(0),
  1178 + xref_zero_offset(0),
  1179 + first_page(0),
  1180 + H_offset(0),
  1181 + H_length(0)
  1182 + {
  1183 + }
  1184 +
  1185 + qpdf_offset_t file_size; // /L
  1186 + int first_page_object; // /O
  1187 + qpdf_offset_t first_page_end; // /E
  1188 + int npages; // /N
  1189 + qpdf_offset_t xref_zero_offset; // /T
  1190 + int first_page; // /P
  1191 + qpdf_offset_t H_offset; // offset of primary hint stream
  1192 + qpdf_offset_t H_length; // length of primary hint stream
1193 }; 1193 };
1194 1194
1195 // Computed hint table value data structures. These tables 1195 // Computed hint table value data structures. These tables
@@ -1209,49 +1209,49 @@ class QPDF @@ -1209,49 +1209,49 @@ class QPDF
1209 1209
1210 struct CHPageOffsetEntry 1210 struct CHPageOffsetEntry
1211 { 1211 {
1212 - CHPageOffsetEntry() :  
1213 - nobjects(0),  
1214 - nshared_objects(0)  
1215 - {  
1216 - }  
1217 -  
1218 - int nobjects;  
1219 - int nshared_objects;  
1220 - // vectors' sizes = nshared_objects  
1221 - std::vector<int> shared_identifiers; 1212 + CHPageOffsetEntry() :
  1213 + nobjects(0),
  1214 + nshared_objects(0)
  1215 + {
  1216 + }
  1217 +
  1218 + int nobjects;
  1219 + int nshared_objects;
  1220 + // vectors' sizes = nshared_objects
  1221 + std::vector<int> shared_identifiers;
1222 }; 1222 };
1223 1223
1224 struct CHPageOffset 1224 struct CHPageOffset
1225 { 1225 {
1226 - // vector size is npages  
1227 - std::vector<CHPageOffsetEntry> entries; 1226 + // vector size is npages
  1227 + std::vector<CHPageOffsetEntry> entries;
1228 }; 1228 };
1229 1229
1230 struct CHSharedObjectEntry 1230 struct CHSharedObjectEntry
1231 { 1231 {
1232 - CHSharedObjectEntry(int object) :  
1233 - object(object)  
1234 - {  
1235 - } 1232 + CHSharedObjectEntry(int object) :
  1233 + object(object)
  1234 + {
  1235 + }
1236 1236
1237 - int object; 1237 + int object;
1238 }; 1238 };
1239 1239
1240 // PDF 1.4: Table F.5 1240 // PDF 1.4: Table F.5
1241 struct CHSharedObject 1241 struct CHSharedObject
1242 { 1242 {
1243 - CHSharedObject() :  
1244 - first_shared_obj(0),  
1245 - nshared_first_page(0),  
1246 - nshared_total(0)  
1247 - {  
1248 - }  
1249 -  
1250 - int first_shared_obj;  
1251 - int nshared_first_page;  
1252 - int nshared_total;  
1253 - // vector size is nshared_total  
1254 - std::vector<CHSharedObjectEntry> entries; 1243 + CHSharedObject() :
  1244 + first_shared_obj(0),
  1245 + nshared_first_page(0),
  1246 + nshared_total(0)
  1247 + {
  1248 + }
  1249 +
  1250 + int first_shared_obj;
  1251 + int nshared_first_page;
  1252 + int nshared_total;
  1253 + // vector size is nshared_total
  1254 + std::vector<CHSharedObjectEntry> entries;
1255 }; 1255 };
1256 1256
1257 // No need for CHGeneric -- HGeneric is fine as is. 1257 // No need for CHGeneric -- HGeneric is fine as is.
@@ -1263,33 +1263,33 @@ class QPDF @@ -1263,33 +1263,33 @@ class QPDF
1263 class ObjUser 1263 class ObjUser
1264 { 1264 {
1265 public: 1265 public:
1266 - enum user_e  
1267 - {  
1268 - ou_bad,  
1269 - ou_page,  
1270 - ou_thumb,  
1271 - ou_trailer_key,  
1272 - ou_root_key,  
1273 - ou_root  
1274 - }; 1266 + enum user_e
  1267 + {
  1268 + ou_bad,
  1269 + ou_page,
  1270 + ou_thumb,
  1271 + ou_trailer_key,
  1272 + ou_root_key,
  1273 + ou_root
  1274 + };
1275 1275
1276 - // type is set to ou_bad  
1277 - ObjUser(); 1276 + // type is set to ou_bad
  1277 + ObjUser();
1278 1278
1279 - // type must be ou_root  
1280 - ObjUser(user_e type); 1279 + // type must be ou_root
  1280 + ObjUser(user_e type);
1281 1281
1282 - // type must be one of ou_page or ou_thumb  
1283 - ObjUser(user_e type, int pageno); 1282 + // type must be one of ou_page or ou_thumb
  1283 + ObjUser(user_e type, int pageno);
1284 1284
1285 - // type must be one of ou_trailer_key or ou_root_key  
1286 - ObjUser(user_e type, std::string const& key); 1285 + // type must be one of ou_trailer_key or ou_root_key
  1286 + ObjUser(user_e type, std::string const& key);
1287 1287
1288 - bool operator<(ObjUser const&) const; 1288 + bool operator<(ObjUser const&) const;
1289 1289
1290 - user_e ou_type;  
1291 - int pageno; // if ou_page;  
1292 - std::string key; // if ou_trailer_key or ou_root_key 1290 + user_e ou_type;
  1291 + int pageno; // if ou_page;
  1292 + std::string key; // if ou_trailer_key or ou_root_key
1293 }; 1293 };
1294 1294
1295 class PatternFinder: public InputSource::Finder 1295 class PatternFinder: public InputSource::Finder
@@ -1331,17 +1331,17 @@ class QPDF @@ -1331,17 +1331,17 @@ class QPDF
1331 qpdf_offset_t maxEnd(ObjUser const& ou); 1331 qpdf_offset_t maxEnd(ObjUser const& ou);
1332 qpdf_offset_t getLinearizationOffset(QPDFObjGen const&); 1332 qpdf_offset_t getLinearizationOffset(QPDFObjGen const&);
1333 QPDFObjectHandle getUncompressedObject( 1333 QPDFObjectHandle getUncompressedObject(
1334 - QPDFObjectHandle&, std::map<int, int> const& object_stream_data); 1334 + QPDFObjectHandle&, std::map<int, int> const& object_stream_data);
1335 int lengthNextN(int first_object, int n, 1335 int lengthNextN(int first_object, int n,
1336 - std::list<std::string>& errors); 1336 + std::list<std::string>& errors);
1337 void checkHPageOffset(std::list<std::string>& errors, 1337 void checkHPageOffset(std::list<std::string>& errors,
1338 - std::list<std::string>& warnings,  
1339 - std::vector<QPDFObjectHandle> const& pages,  
1340 - std::map<int, int>& idx_to_obj); 1338 + std::list<std::string>& warnings,
  1339 + std::vector<QPDFObjectHandle> const& pages,
  1340 + std::map<int, int>& idx_to_obj);
1341 void checkHSharedObject(std::list<std::string>& warnings, 1341 void checkHSharedObject(std::list<std::string>& warnings,
1342 - std::list<std::string>& errors,  
1343 - std::vector<QPDFObjectHandle> const& pages,  
1344 - std::map<int, int>& idx_to_obj); 1342 + std::list<std::string>& errors,
  1343 + std::vector<QPDFObjectHandle> const& pages,
  1344 + std::map<int, int>& idx_to_obj);
1345 void checkHOutlines(std::list<std::string>& warnings); 1345 void checkHOutlines(std::list<std::string>& warnings);
1346 void dumpHPageOffset(); 1346 void dumpHPageOffset();
1347 void dumpHSharedObject(); 1347 void dumpHSharedObject();
@@ -1349,27 +1349,27 @@ class QPDF @@ -1349,27 +1349,27 @@ class QPDF
1349 qpdf_offset_t adjusted_offset(qpdf_offset_t offset); 1349 qpdf_offset_t adjusted_offset(qpdf_offset_t offset);
1350 QPDFObjectHandle objGenToIndirect(QPDFObjGen const&); 1350 QPDFObjectHandle objGenToIndirect(QPDFObjGen const&);
1351 void calculateLinearizationData( 1351 void calculateLinearizationData(
1352 - std::map<int, int> const& object_stream_data); 1352 + std::map<int, int> const& object_stream_data);
1353 void pushOutlinesToPart( 1353 void pushOutlinesToPart(
1354 - std::vector<QPDFObjectHandle>& part,  
1355 - std::set<QPDFObjGen>& lc_outlines,  
1356 - std::map<int, int> const& object_stream_data); 1354 + std::vector<QPDFObjectHandle>& part,
  1355 + std::set<QPDFObjGen>& lc_outlines,
  1356 + std::map<int, int> const& object_stream_data);
1357 int outputLengthNextN( 1357 int outputLengthNextN(
1358 - int in_object, int n,  
1359 - std::map<int, qpdf_offset_t> const& lengths,  
1360 - std::map<int, int> const& obj_renumber); 1358 + int in_object, int n,
  1359 + std::map<int, qpdf_offset_t> const& lengths,
  1360 + std::map<int, int> const& obj_renumber);
1361 void calculateHPageOffset( 1361 void calculateHPageOffset(
1362 - std::map<int, QPDFXRefEntry> const& xref,  
1363 - std::map<int, qpdf_offset_t> const& lengths,  
1364 - std::map<int, int> const& obj_renumber); 1362 + std::map<int, QPDFXRefEntry> const& xref,
  1363 + std::map<int, qpdf_offset_t> const& lengths,
  1364 + std::map<int, int> const& obj_renumber);
1365 void calculateHSharedObject( 1365 void calculateHSharedObject(
1366 - std::map<int, QPDFXRefEntry> const& xref,  
1367 - std::map<int, qpdf_offset_t> const& lengths,  
1368 - std::map<int, int> const& obj_renumber); 1366 + std::map<int, QPDFXRefEntry> const& xref,
  1367 + std::map<int, qpdf_offset_t> const& lengths,
  1368 + std::map<int, int> const& obj_renumber);
1369 void calculateHOutline( 1369 void calculateHOutline(
1370 - std::map<int, QPDFXRefEntry> const& xref,  
1371 - std::map<int, qpdf_offset_t> const& lengths,  
1372 - std::map<int, int> const& obj_renumber); 1370 + std::map<int, QPDFXRefEntry> const& xref,
  1371 + std::map<int, qpdf_offset_t> const& lengths,
  1372 + std::map<int, int> const& obj_renumber);
1373 void writeHPageOffset(BitWriter&); 1373 void writeHPageOffset(BitWriter&);
1374 void writeHSharedObject(BitWriter&); 1374 void writeHSharedObject(BitWriter&);
1375 void writeHGeneric(BitWriter&, HGeneric&); 1375 void writeHGeneric(BitWriter&, HGeneric&);
@@ -1380,10 +1380,10 @@ class QPDF @@ -1380,10 +1380,10 @@ class QPDF
1380 void pushInheritedAttributesToPage(bool allow_changes, 1380 void pushInheritedAttributesToPage(bool allow_changes,
1381 bool warn_skipped_keys); 1381 bool warn_skipped_keys);
1382 void pushInheritedAttributesToPageInternal( 1382 void pushInheritedAttributesToPageInternal(
1383 - QPDFObjectHandle,  
1384 - std::map<std::string, std::vector<QPDFObjectHandle> >&,  
1385 - std::vector<QPDFObjectHandle>& all_pages,  
1386 - bool allow_changes, bool warn_skipped_keys, 1383 + QPDFObjectHandle,
  1384 + std::map<std::string, std::vector<QPDFObjectHandle> >&,
  1385 + std::vector<QPDFObjectHandle>& all_pages,
  1386 + bool allow_changes, bool warn_skipped_keys,
1387 std::set<QPDFObjGen>& visited); 1387 std::set<QPDFObjGen>& visited);
1388 void updateObjectMaps( 1388 void updateObjectMaps(
1389 ObjUser const& ou, QPDFObjectHandle oh, 1389 ObjUser const& ou, QPDFObjectHandle oh,
include/qpdf/QPDFExc.hh
@@ -34,10 +34,10 @@ class QPDF_DLL_CLASS QPDFExc: public std::runtime_error @@ -34,10 +34,10 @@ class QPDF_DLL_CLASS QPDFExc: public std::runtime_error
34 public: 34 public:
35 QPDF_DLL 35 QPDF_DLL
36 QPDFExc(qpdf_error_code_e error_code, 36 QPDFExc(qpdf_error_code_e error_code,
37 - std::string const& filename,  
38 - std::string const& object,  
39 - qpdf_offset_t offset,  
40 - std::string const& message); 37 + std::string const& filename,
  38 + std::string const& object,
  39 + qpdf_offset_t offset,
  40 + std::string const& message);
41 QPDF_DLL 41 QPDF_DLL
42 virtual ~QPDFExc() noexcept 42 virtual ~QPDFExc() noexcept
43 { 43 {
@@ -66,9 +66,9 @@ class QPDF_DLL_CLASS QPDFExc: public std::runtime_error @@ -66,9 +66,9 @@ class QPDF_DLL_CLASS QPDFExc: public std::runtime_error
66 66
67 private: 67 private:
68 static std::string createWhat(std::string const& filename, 68 static std::string createWhat(std::string const& filename,
69 - std::string const& object,  
70 - qpdf_offset_t offset,  
71 - std::string const& message); 69 + std::string const& object,
  70 + qpdf_offset_t offset,
  71 + std::string const& message);
72 72
73 // This class does not use the Members pattern to avoid needless 73 // This class does not use the Members pattern to avoid needless
74 // memory allocations during exception handling. 74 // memory allocations during exception handling.
include/qpdf/QPDFObject.hh
@@ -76,16 +76,16 @@ class QPDF_DLL_CLASS QPDFObject @@ -76,16 +76,16 @@ class QPDF_DLL_CLASS QPDFObject
76 // Accessor to give specific access to non-public methods 76 // Accessor to give specific access to non-public methods
77 class ObjAccessor 77 class ObjAccessor
78 { 78 {
79 - friend class QPDF;  
80 - friend class QPDFObjectHandle; 79 + friend class QPDF;
  80 + friend class QPDFObjectHandle;
81 private: 81 private:
82 - static void releaseResolved(QPDFObject* o)  
83 - {  
84 - if (o)  
85 - {  
86 - o->releaseResolved();  
87 - }  
88 - } 82 + static void releaseResolved(QPDFObject* o)
  83 + {
  84 + if (o)
  85 + {
  86 + o->releaseResolved();
  87 + }
  88 + }
89 }; 89 };
90 friend class ObjAccessor; 90 friend class ObjAccessor;
91 91
include/qpdf/QPDFObjectHandle.hh
@@ -63,27 +63,27 @@ class QPDFObjectHandle @@ -63,27 +63,27 @@ class QPDFObjectHandle
63 QPDF_DLL 63 QPDF_DLL
64 StreamDataProvider(bool supports_retry = false); 64 StreamDataProvider(bool supports_retry = false);
65 65
66 - QPDF_DLL  
67 - virtual ~StreamDataProvider()  
68 - {  
69 - }  
70 - // The implementation of this function must write stream data  
71 - // to the given pipeline. The stream data must conform to  
72 - // whatever filters are explicitly associated with the stream.  
73 - // QPDFWriter may, in some cases, add compression, but if it  
74 - // does, it will update the filters as needed. Every call to  
75 - // provideStreamData for a given stream must write the same  
76 - // data. Note that, when writing linearized files, qpdf will  
77 - // call your provideStreamData twice, and if it generates  
78 - // different output, you risk generating invalid output or  
79 - // having qpdf throw an exception. The object ID and  
80 - // generation passed to this method are those that belong to  
81 - // the stream on behalf of which the provider is called. They  
82 - // may be ignored or used by the implementation for indexing  
83 - // or other purposes. This information is made available just  
84 - // to make it more convenient to use a single  
85 - // StreamDataProvider object to provide data for multiple  
86 - // streams. 66 + QPDF_DLL
  67 + virtual ~StreamDataProvider()
  68 + {
  69 + }
  70 + // The implementation of this function must write stream data
  71 + // to the given pipeline. The stream data must conform to
  72 + // whatever filters are explicitly associated with the stream.
  73 + // QPDFWriter may, in some cases, add compression, but if it
  74 + // does, it will update the filters as needed. Every call to
  75 + // provideStreamData for a given stream must write the same
  76 + // data. Note that, when writing linearized files, qpdf will
  77 + // call your provideStreamData twice, and if it generates
  78 + // different output, you risk generating invalid output or
  79 + // having qpdf throw an exception. The object ID and
  80 + // generation passed to this method are those that belong to
  81 + // the stream on behalf of which the provider is called. They
  82 + // may be ignored or used by the implementation for indexing
  83 + // or other purposes. This information is made available just
  84 + // to make it more convenient to use a single
  85 + // StreamDataProvider object to provide data for multiple
  86 + // streams.
87 87
88 // A few things to keep in mind: 88 // A few things to keep in mind:
89 // 89 //
@@ -117,14 +117,14 @@ class QPDFObjectHandle @@ -117,14 +117,14 @@ class QPDFObjectHandle
117 // version of the method, which should also return a boolean 117 // version of the method, which should also return a boolean
118 // indicating whether it ran without errors. 118 // indicating whether it ran without errors.
119 QPDF_DLL 119 QPDF_DLL
120 - virtual void provideStreamData(int objid, int generation,  
121 - Pipeline* pipeline); 120 + virtual void provideStreamData(int objid, int generation,
  121 + Pipeline* pipeline);
122 QPDF_DLL 122 QPDF_DLL
123 - virtual bool provideStreamData( 123 + virtual bool provideStreamData(
124 int objid, int generation, Pipeline* pipeline, 124 int objid, int generation, Pipeline* pipeline,
125 bool suppress_warnings, bool will_retry); 125 bool suppress_warnings, bool will_retry);
126 QPDF_DLL 126 QPDF_DLL
127 - bool supportsRetry(); 127 + bool supportsRetry();
128 128
129 private: 129 private:
130 bool supports_retry; 130 bool supports_retry;
@@ -563,7 +563,7 @@ class QPDFObjectHandle @@ -563,7 +563,7 @@ class QPDFObjectHandle
563 static QPDFObjectHandle newArray(); 563 static QPDFObjectHandle newArray();
564 QPDF_DLL 564 QPDF_DLL
565 static QPDFObjectHandle newArray( 565 static QPDFObjectHandle newArray(
566 - std::vector<QPDFObjectHandle> const& items); 566 + std::vector<QPDFObjectHandle> const& items);
567 QPDF_DLL 567 QPDF_DLL
568 static QPDFObjectHandle newArray(Rectangle const&); 568 static QPDFObjectHandle newArray(Rectangle const&);
569 QPDF_DLL 569 QPDF_DLL
@@ -574,7 +574,7 @@ class QPDFObjectHandle @@ -574,7 +574,7 @@ class QPDFObjectHandle
574 static QPDFObjectHandle newDictionary(); 574 static QPDFObjectHandle newDictionary();
575 QPDF_DLL 575 QPDF_DLL
576 static QPDFObjectHandle newDictionary( 576 static QPDFObjectHandle newDictionary(
577 - std::map<std::string, QPDFObjectHandle> const& items); 577 + std::map<std::string, QPDFObjectHandle> const& items);
578 578
579 // Create an array from a rectangle. Equivalent to the rectangle 579 // Create an array from a rectangle. Equivalent to the rectangle
580 // form of newArray. 580 // form of newArray.
@@ -1159,7 +1159,7 @@ class QPDFObjectHandle @@ -1159,7 +1159,7 @@ class QPDFObjectHandle
1159 // Return value is whether filtering was attempted. 1159 // Return value is whether filtering was attempted.
1160 QPDF_DLL 1160 QPDF_DLL
1161 bool pipeStreamData(Pipeline*, bool filter, 1161 bool pipeStreamData(Pipeline*, bool filter,
1162 - bool normalize, bool compress); 1162 + bool normalize, bool compress);
1163 1163
1164 // Replace a stream's dictionary. The new dictionary must be 1164 // Replace a stream's dictionary. The new dictionary must be
1165 // consistent with the stream's data. This is most appropriately 1165 // consistent with the stream's data. This is most appropriately
@@ -1179,8 +1179,8 @@ class QPDFObjectHandle @@ -1179,8 +1179,8 @@ class QPDFObjectHandle
1179 // decryption filters have been applied, is as presented. 1179 // decryption filters have been applied, is as presented.
1180 QPDF_DLL 1180 QPDF_DLL
1181 void replaceStreamData(PointerHolder<Buffer> data, 1181 void replaceStreamData(PointerHolder<Buffer> data,
1182 - QPDFObjectHandle const& filter,  
1183 - QPDFObjectHandle const& decode_parms); 1182 + QPDFObjectHandle const& filter,
  1183 + QPDFObjectHandle const& decode_parms);
1184 1184
1185 // Replace the stream's stream data with the given string. 1185 // Replace the stream's stream data with the given string.
1186 // This method will create a copy of the data rather than using 1186 // This method will create a copy of the data rather than using
@@ -1188,8 +1188,8 @@ class QPDFObjectHandle @@ -1188,8 +1188,8 @@ class QPDFObjectHandle
1188 // of replaceStreamData. 1188 // of replaceStreamData.
1189 QPDF_DLL 1189 QPDF_DLL
1190 void replaceStreamData(std::string const& data, 1190 void replaceStreamData(std::string const& data,
1191 - QPDFObjectHandle const& filter,  
1192 - QPDFObjectHandle const& decode_parms); 1191 + QPDFObjectHandle const& filter,
  1192 + QPDFObjectHandle const& decode_parms);
1193 1193
1194 // As above, replace this stream's stream data. Instead of 1194 // As above, replace this stream's stream data. Instead of
1195 // directly providing a buffer with the stream data, call the 1195 // directly providing a buffer with the stream data, call the
@@ -1218,8 +1218,8 @@ class QPDFObjectHandle @@ -1218,8 +1218,8 @@ class QPDFObjectHandle
1218 // compute the length in advance. 1218 // compute the length in advance.
1219 QPDF_DLL 1219 QPDF_DLL
1220 void replaceStreamData(PointerHolder<StreamDataProvider> provider, 1220 void replaceStreamData(PointerHolder<StreamDataProvider> provider,
1221 - QPDFObjectHandle const& filter,  
1222 - QPDFObjectHandle const& decode_parms); 1221 + QPDFObjectHandle const& filter,
  1222 + QPDFObjectHandle const& decode_parms);
1223 1223
1224 // Starting in qpdf 10.2, you can use C++-11 function objects 1224 // Starting in qpdf 10.2, you can use C++-11 function objects
1225 // instead of StreamDataProvider. 1225 // instead of StreamDataProvider.
@@ -1229,8 +1229,8 @@ class QPDFObjectHandle @@ -1229,8 +1229,8 @@ class QPDFObjectHandle
1229 // pass QUtil::file_provider(filename) as provider. 1229 // pass QUtil::file_provider(filename) as provider.
1230 QPDF_DLL 1230 QPDF_DLL
1231 void replaceStreamData(std::function<void(Pipeline*)> provider, 1231 void replaceStreamData(std::function<void(Pipeline*)> provider,
1232 - QPDFObjectHandle const& filter,  
1233 - QPDFObjectHandle const& decode_parms); 1232 + QPDFObjectHandle const& filter,
  1233 + QPDFObjectHandle const& decode_parms);
1234 // The provider should write the stream data to the pipeline, 1234 // The provider should write the stream data to the pipeline,
1235 // returning true if it succeeded without errors. 1235 // returning true if it succeeded without errors.
1236 QPDF_DLL 1236 QPDF_DLL
@@ -1317,21 +1317,21 @@ class QPDFObjectHandle @@ -1317,21 +1317,21 @@ class QPDFObjectHandle
1317 // making it a friend of the whole QPDFObjectHandle class. 1317 // making it a friend of the whole QPDFObjectHandle class.
1318 class Factory 1318 class Factory
1319 { 1319 {
1320 - friend class QPDF; 1320 + friend class QPDF;
1321 private: 1321 private:
1322 - static QPDFObjectHandle newIndirect(QPDF* qpdf,  
1323 - int objid, int generation)  
1324 - {  
1325 - return QPDFObjectHandle::newIndirect(qpdf, objid, generation);  
1326 - }  
1327 - // object must be dictionary object  
1328 - static QPDFObjectHandle newStream(  
1329 - QPDF* qpdf, int objid, int generation,  
1330 - QPDFObjectHandle stream_dict, qpdf_offset_t offset, size_t length)  
1331 - {  
1332 - return QPDFObjectHandle::newStream(  
1333 - qpdf, objid, generation, stream_dict, offset, length);  
1334 - } 1322 + static QPDFObjectHandle newIndirect(QPDF* qpdf,
  1323 + int objid, int generation)
  1324 + {
  1325 + return QPDFObjectHandle::newIndirect(qpdf, objid, generation);
  1326 + }
  1327 + // object must be dictionary object
  1328 + static QPDFObjectHandle newStream(
  1329 + QPDF* qpdf, int objid, int generation,
  1330 + QPDFObjectHandle stream_dict, qpdf_offset_t offset, size_t length)
  1331 + {
  1332 + return QPDFObjectHandle::newStream(
  1333 + qpdf, objid, generation, stream_dict, offset, length);
  1334 + }
1335 }; 1335 };
1336 friend class Factory; 1336 friend class Factory;
1337 1337
@@ -1339,13 +1339,13 @@ class QPDFObjectHandle @@ -1339,13 +1339,13 @@ class QPDFObjectHandle
1339 // call this. 1339 // call this.
1340 class ObjAccessor 1340 class ObjAccessor
1341 { 1341 {
1342 - friend class QPDF; 1342 + friend class QPDF;
1343 private: 1343 private:
1344 - static PointerHolder<QPDFObject> getObject(QPDFObjectHandle& o)  
1345 - {  
1346 - o.dereference();  
1347 - return o.obj;  
1348 - } 1344 + static PointerHolder<QPDFObject> getObject(QPDFObjectHandle& o)
  1345 + {
  1346 + o.dereference();
  1347 + return o.obj;
  1348 + }
1349 }; 1349 };
1350 friend class ObjAccessor; 1350 friend class ObjAccessor;
1351 1351
@@ -1353,14 +1353,14 @@ class QPDFObjectHandle @@ -1353,14 +1353,14 @@ class QPDFObjectHandle
1353 // releaseResolved(). 1353 // releaseResolved().
1354 class ReleaseResolver 1354 class ReleaseResolver
1355 { 1355 {
1356 - friend class QPDF_Dictionary; 1356 + friend class QPDF_Dictionary;
1357 friend class QPDF_Stream; 1357 friend class QPDF_Stream;
1358 friend class SparseOHArray; 1358 friend class SparseOHArray;
1359 private: 1359 private:
1360 - static void releaseResolved(QPDFObjectHandle& o)  
1361 - {  
1362 - o.releaseResolved();  
1363 - } 1360 + static void releaseResolved(QPDFObjectHandle& o)
  1361 + {
  1362 + o.releaseResolved();
  1363 + }
1364 }; 1364 };
1365 friend class ReleaseResolver; 1365 friend class ReleaseResolver;
1366 1366
@@ -1440,8 +1440,8 @@ class QPDFObjectHandle @@ -1440,8 +1440,8 @@ class QPDFObjectHandle
1440 // Private object factory methods 1440 // Private object factory methods
1441 static QPDFObjectHandle newIndirect(QPDF*, int objid, int generation); 1441 static QPDFObjectHandle newIndirect(QPDF*, int objid, int generation);
1442 static QPDFObjectHandle newStream( 1442 static QPDFObjectHandle newStream(
1443 - QPDF* qpdf, int objid, int generation,  
1444 - QPDFObjectHandle stream_dict, qpdf_offset_t offset, size_t length); 1443 + QPDF* qpdf, int objid, int generation,
  1444 + QPDFObjectHandle stream_dict, qpdf_offset_t offset, size_t length);
1445 1445
1446 void typeWarning(char const* expected_type, 1446 void typeWarning(char const* expected_type,
1447 std::string const& warning); 1447 std::string const& warning);
@@ -1481,7 +1481,7 @@ class QPDFObjectHandle @@ -1481,7 +1481,7 @@ class QPDFObjectHandle
1481 // a substantial performance penalty since QPDFObjectHandle 1481 // a substantial performance penalty since QPDFObjectHandle
1482 // objects are copied around so frequently. 1482 // objects are copied around so frequently.
1483 QPDF* qpdf; 1483 QPDF* qpdf;
1484 - int objid; // 0 for direct object 1484 + int objid; // 0 for direct object
1485 int generation; 1485 int generation;
1486 PointerHolder<QPDFObject> obj; 1486 PointerHolder<QPDFObject> obj;
1487 bool reserved; 1487 bool reserved;
include/qpdf/QPDFSystemError.hh
@@ -49,7 +49,7 @@ class QPDF_DLL_CLASS QPDFSystemError: public std::runtime_error @@ -49,7 +49,7 @@ class QPDF_DLL_CLASS QPDFSystemError: public std::runtime_error
49 49
50 private: 50 private:
51 static std::string createWhat(std::string const& description, 51 static std::string createWhat(std::string const& description,
52 - int system_errno); 52 + int system_errno);
53 53
54 // This class does not use the Members pattern to avoid needless 54 // This class does not use the Members pattern to avoid needless
55 // memory allocations during exception handling. 55 // memory allocations during exception handling.
include/qpdf/QPDFTokenizer.hh
@@ -40,20 +40,20 @@ class QPDFTokenizer @@ -40,20 +40,20 @@ class QPDFTokenizer
40 // version 8. 40 // version 8.
41 enum token_type_e 41 enum token_type_e
42 { 42 {
43 - tt_bad,  
44 - tt_array_close,  
45 - tt_array_open,  
46 - tt_brace_close,  
47 - tt_brace_open,  
48 - tt_dict_close,  
49 - tt_dict_open,  
50 - tt_integer,  
51 - tt_name,  
52 - tt_real,  
53 - tt_string,  
54 - tt_null,  
55 - tt_bool,  
56 - tt_word, 43 + tt_bad,
  44 + tt_array_close,
  45 + tt_array_open,
  46 + tt_brace_close,
  47 + tt_brace_open,
  48 + tt_dict_close,
  49 + tt_dict_open,
  50 + tt_integer,
  51 + tt_name,
  52 + tt_real,
  53 + tt_string,
  54 + tt_null,
  55 + tt_bool,
  56 + tt_word,
57 tt_eof, 57 tt_eof,
58 tt_space, 58 tt_space,
59 tt_comment, 59 tt_comment,
@@ -63,46 +63,46 @@ class QPDFTokenizer @@ -63,46 +63,46 @@ class QPDFTokenizer
63 class Token 63 class Token
64 { 64 {
65 public: 65 public:
66 - Token() : type(tt_bad) {} 66 + Token() : type(tt_bad) {}
67 QPDF_DLL 67 QPDF_DLL
68 - Token(token_type_e type, std::string const& value);  
69 - Token(token_type_e type, std::string const& value,  
70 - std::string raw_value, std::string error_message) :  
71 - type(type),  
72 - value(value),  
73 - raw_value(raw_value),  
74 - error_message(error_message)  
75 - {  
76 - }  
77 - token_type_e getType() const  
78 - {  
79 - return this->type;  
80 - }  
81 - std::string const& getValue() const  
82 - {  
83 - return this->value;  
84 - }  
85 - std::string const& getRawValue() const  
86 - {  
87 - return this->raw_value;  
88 - }  
89 - std::string const& getErrorMessage() const  
90 - {  
91 - return this->error_message;  
92 - }  
93 - bool operator==(Token const& rhs) const  
94 - {  
95 - // Ignore fields other than type and value  
96 - return ((this->type != tt_bad) &&  
97 - (this->type == rhs.type) &&  
98 - (this->value == rhs.value));  
99 - } 68 + Token(token_type_e type, std::string const& value);
  69 + Token(token_type_e type, std::string const& value,
  70 + std::string raw_value, std::string error_message) :
  71 + type(type),
  72 + value(value),
  73 + raw_value(raw_value),
  74 + error_message(error_message)
  75 + {
  76 + }
  77 + token_type_e getType() const
  78 + {
  79 + return this->type;
  80 + }
  81 + std::string const& getValue() const
  82 + {
  83 + return this->value;
  84 + }
  85 + std::string const& getRawValue() const
  86 + {
  87 + return this->raw_value;
  88 + }
  89 + std::string const& getErrorMessage() const
  90 + {
  91 + return this->error_message;
  92 + }
  93 + bool operator==(Token const& rhs) const
  94 + {
  95 + // Ignore fields other than type and value
  96 + return ((this->type != tt_bad) &&
  97 + (this->type == rhs.type) &&
  98 + (this->value == rhs.value));
  99 + }
100 100
101 private: 101 private:
102 - token_type_e type;  
103 - std::string value;  
104 - std::string raw_value;  
105 - std::string error_message; 102 + token_type_e type;
  103 + std::string value;
  104 + std::string raw_value;
  105 + std::string error_message;
106 }; 106 };
107 107
108 QPDF_DLL 108 QPDF_DLL
include/qpdf/QPDFWriter.hh
@@ -370,73 +370,73 @@ class QPDFWriter @@ -370,73 +370,73 @@ class QPDFWriter
370 // it unless you have to. 370 // it unless you have to.
371 QPDF_DLL 371 QPDF_DLL
372 void setR2EncryptionParameters( 372 void setR2EncryptionParameters(
373 - char const* user_password, char const* owner_password,  
374 - bool allow_print, bool allow_modify,  
375 - bool allow_extract, bool allow_annotate); 373 + char const* user_password, char const* owner_password,
  374 + bool allow_print, bool allow_modify,
  375 + bool allow_extract, bool allow_annotate);
376 // R3 uses RC4, which is a weak cryptographic algorithm. Don't use 376 // R3 uses RC4, which is a weak cryptographic algorithm. Don't use
377 // it unless you have to. 377 // it unless you have to.
378 QPDF_DLL 378 QPDF_DLL
379 void setR3EncryptionParameters( 379 void setR3EncryptionParameters(
380 - char const* user_password, char const* owner_password,  
381 - bool allow_accessibility, bool allow_extract, 380 + char const* user_password, char const* owner_password,
  381 + bool allow_accessibility, bool allow_extract,
382 bool allow_assemble, bool allow_annotate_and_form, 382 bool allow_assemble, bool allow_annotate_and_form,
383 bool allow_form_filling, bool allow_modify_other, 383 bool allow_form_filling, bool allow_modify_other,
384 - qpdf_r3_print_e print); 384 + qpdf_r3_print_e print);
385 // R4 uses RC4, which is a weak cryptographic algorithm, when 385 // R4 uses RC4, which is a weak cryptographic algorithm, when
386 // use_aes=false. Don't use it unless you have to. 386 // use_aes=false. Don't use it unless you have to.
387 QPDF_DLL 387 QPDF_DLL
388 void setR4EncryptionParameters( 388 void setR4EncryptionParameters(
389 - char const* user_password, char const* owner_password,  
390 - bool allow_accessibility, bool allow_extract, 389 + char const* user_password, char const* owner_password,
  390 + bool allow_accessibility, bool allow_extract,
391 bool allow_assemble, bool allow_annotate_and_form, 391 bool allow_assemble, bool allow_annotate_and_form,
392 bool allow_form_filling, bool allow_modify_other, 392 bool allow_form_filling, bool allow_modify_other,
393 - qpdf_r3_print_e print, bool encrypt_metadata, bool use_aes); 393 + qpdf_r3_print_e print, bool encrypt_metadata, bool use_aes);
394 // R5 is deprecated. Do not use it for production use. Writing 394 // R5 is deprecated. Do not use it for production use. Writing
395 // R5 is supported by qpdf primarily to generate test files for 395 // R5 is supported by qpdf primarily to generate test files for
396 // applications that may need to test R5 support. 396 // applications that may need to test R5 support.
397 QPDF_DLL 397 QPDF_DLL
398 void setR5EncryptionParameters( 398 void setR5EncryptionParameters(
399 - char const* user_password, char const* owner_password,  
400 - bool allow_accessibility, bool allow_extract, 399 + char const* user_password, char const* owner_password,
  400 + bool allow_accessibility, bool allow_extract,
401 bool allow_assemble, bool allow_annotate_and_form, 401 bool allow_assemble, bool allow_annotate_and_form,
402 bool allow_form_filling, bool allow_modify_other, 402 bool allow_form_filling, bool allow_modify_other,
403 - qpdf_r3_print_e print, bool encrypt_metadata); 403 + qpdf_r3_print_e print, bool encrypt_metadata);
404 QPDF_DLL 404 QPDF_DLL
405 void setR6EncryptionParameters( 405 void setR6EncryptionParameters(
406 - char const* user_password, char const* owner_password,  
407 - bool allow_accessibility, bool allow_extract, 406 + char const* user_password, char const* owner_password,
  407 + bool allow_accessibility, bool allow_extract,
408 bool allow_assemble, bool allow_annotate_and_form, 408 bool allow_assemble, bool allow_annotate_and_form,
409 bool allow_form_filling, bool allow_modify_other, 409 bool allow_form_filling, bool allow_modify_other,
410 - qpdf_r3_print_e print, bool encrypt_metadata_aes); 410 + qpdf_r3_print_e print, bool encrypt_metadata_aes);
411 411
412 // Pre qpdf 8.4.0 API 412 // Pre qpdf 8.4.0 API
413 [[deprecated("see newer API above")]] 413 [[deprecated("see newer API above")]]
414 QPDF_DLL 414 QPDF_DLL
415 void setR3EncryptionParameters( 415 void setR3EncryptionParameters(
416 - char const* user_password, char const* owner_password,  
417 - bool allow_accessibility, bool allow_extract,  
418 - qpdf_r3_print_e print, qpdf_r3_modify_e modify); 416 + char const* user_password, char const* owner_password,
  417 + bool allow_accessibility, bool allow_extract,
  418 + qpdf_r3_print_e print, qpdf_r3_modify_e modify);
419 [[deprecated("see newer API above")]] 419 [[deprecated("see newer API above")]]
420 QPDF_DLL 420 QPDF_DLL
421 void setR4EncryptionParameters( 421 void setR4EncryptionParameters(
422 - char const* user_password, char const* owner_password,  
423 - bool allow_accessibility, bool allow_extract,  
424 - qpdf_r3_print_e print, qpdf_r3_modify_e modify,  
425 - bool encrypt_metadata, bool use_aes); 422 + char const* user_password, char const* owner_password,
  423 + bool allow_accessibility, bool allow_extract,
  424 + qpdf_r3_print_e print, qpdf_r3_modify_e modify,
  425 + bool encrypt_metadata, bool use_aes);
426 [[deprecated("see newer API above")]] 426 [[deprecated("see newer API above")]]
427 QPDF_DLL 427 QPDF_DLL
428 void setR5EncryptionParameters( 428 void setR5EncryptionParameters(
429 - char const* user_password, char const* owner_password,  
430 - bool allow_accessibility, bool allow_extract,  
431 - qpdf_r3_print_e print, qpdf_r3_modify_e modify,  
432 - bool encrypt_metadata); 429 + char const* user_password, char const* owner_password,
  430 + bool allow_accessibility, bool allow_extract,
  431 + qpdf_r3_print_e print, qpdf_r3_modify_e modify,
  432 + bool encrypt_metadata);
433 [[deprecated("see newer API above")]] 433 [[deprecated("see newer API above")]]
434 QPDF_DLL 434 QPDF_DLL
435 void setR6EncryptionParameters( 435 void setR6EncryptionParameters(
436 - char const* user_password, char const* owner_password,  
437 - bool allow_accessibility, bool allow_extract,  
438 - qpdf_r3_print_e print, qpdf_r3_modify_e modify,  
439 - bool encrypt_metadata_aes); 436 + char const* user_password, char const* owner_password,
  437 + bool allow_accessibility, bool allow_extract,
  438 + qpdf_r3_print_e print, qpdf_r3_modify_e modify,
  439 + bool encrypt_metadata_aes);
440 440
441 // Create linearized output. Disables qdf mode, content 441 // Create linearized output. Disables qdf mode, content
442 // normalization, and stream prefiltering. 442 // normalization, and stream prefiltering.
@@ -494,8 +494,8 @@ class QPDFWriter @@ -494,8 +494,8 @@ class QPDFWriter
494 494
495 private: 495 private:
496 // flags used by unparseObject 496 // flags used by unparseObject
497 - static int const f_stream = 1 << 0;  
498 - static int const f_filtered = 1 << 1; 497 + static int const f_stream = 1 << 0;
  498 + static int const f_filtered = 1 << 1;
499 static int const f_in_ostream = 1 << 2; 499 static int const f_in_ostream = 1 << 2;
500 static int const f_hex_string = 1 << 3; 500 static int const f_hex_string = 1 << 3;
501 static int const f_no_encryption = 1 << 4; 501 static int const f_no_encryption = 1 << 4;
@@ -544,14 +544,14 @@ class QPDFWriter @@ -544,14 +544,14 @@ class QPDFWriter
544 void writeObjectStream(QPDFObjectHandle object); 544 void writeObjectStream(QPDFObjectHandle object);
545 void writeObject(QPDFObjectHandle object, int object_stream_index = -1); 545 void writeObject(QPDFObjectHandle object, int object_stream_index = -1);
546 void writeTrailer(trailer_e which, int size, 546 void writeTrailer(trailer_e which, int size,
547 - bool xref_stream, qpdf_offset_t prev, 547 + bool xref_stream, qpdf_offset_t prev,
548 int linearization_pass); 548 int linearization_pass);
549 bool willFilterStream(QPDFObjectHandle stream, 549 bool willFilterStream(QPDFObjectHandle stream,
550 bool& compress_stream, bool& is_metadata, 550 bool& compress_stream, bool& is_metadata,
551 PointerHolder<Buffer>* stream_data); 551 PointerHolder<Buffer>* stream_data);
552 void unparseObject(QPDFObjectHandle object, int level, int flags, 552 void unparseObject(QPDFObjectHandle object, int level, int flags,
553 - // for stream dictionaries  
554 - size_t stream_length = 0, bool compress = false); 553 + // for stream dictionaries
  554 + size_t stream_length = 0, bool compress = false);
555 void unparseChild(QPDFObjectHandle child, int level, int flags); 555 void unparseChild(QPDFObjectHandle child, int level, int flags);
556 void initializeSpecialStreams(); 556 void initializeSpecialStreams();
557 void preserveObjectStreams(); 557 void preserveObjectStreams();
@@ -559,24 +559,24 @@ class QPDFWriter @@ -559,24 +559,24 @@ class QPDFWriter
559 std::string getOriginalID1(); 559 std::string getOriginalID1();
560 void generateID(); 560 void generateID();
561 void interpretR3EncryptionParameters( 561 void interpretR3EncryptionParameters(
562 - std::set<int>& bits_to_clear,  
563 - char const* user_password, char const* owner_password,  
564 - bool allow_accessibility, bool allow_extract, 562 + std::set<int>& bits_to_clear,
  563 + char const* user_password, char const* owner_password,
  564 + bool allow_accessibility, bool allow_extract,
565 bool allow_assemble, bool allow_annotate_and_form, 565 bool allow_assemble, bool allow_annotate_and_form,
566 bool allow_form_filling, bool allow_modify_other, 566 bool allow_form_filling, bool allow_modify_other,
567 - qpdf_r3_print_e print, qpdf_r3_modify_e modify); 567 + qpdf_r3_print_e print, qpdf_r3_modify_e modify);
568 void disableIncompatibleEncryption(int major, int minor, 568 void disableIncompatibleEncryption(int major, int minor,
569 int extension_level); 569 int extension_level);
570 void parseVersion(std::string const& version, int& major, int& minor) const; 570 void parseVersion(std::string const& version, int& major, int& minor) const;
571 int compareVersions(int major1, int minor1, int major2, int minor2) const; 571 int compareVersions(int major1, int minor1, int major2, int minor2) const;
572 void setEncryptionParameters( 572 void setEncryptionParameters(
573 - char const* user_password, char const* owner_password,  
574 - int V, int R, int key_len, std::set<int>& bits_to_clear); 573 + char const* user_password, char const* owner_password,
  574 + int V, int R, int key_len, std::set<int>& bits_to_clear);
575 void setEncryptionParametersInternal( 575 void setEncryptionParametersInternal(
576 - int V, int R, int key_len, int P,  
577 - std::string const& O, std::string const& U,  
578 - std::string const& OE, std::string const& UE, std::string const& Perms,  
579 - std::string const& id1, std::string const& user_password, 576 + int V, int R, int key_len, int P,
  577 + std::string const& O, std::string const& U,
  578 + std::string const& OE, std::string const& UE, std::string const& Perms,
  579 + std::string const& id1, std::string const& user_password,
580 std::string const& encryption_key); 580 std::string const& encryption_key);
581 void setDataKey(int objid); 581 void setDataKey(int objid);
582 int openObject(int objid = 0); 582 int openObject(int objid = 0);
@@ -679,8 +679,8 @@ class QPDFWriter @@ -679,8 +679,8 @@ class QPDFWriter
679 int encryption_V; 679 int encryption_V;
680 int encryption_R; 680 int encryption_R;
681 681
682 - std::string id1; // for /ID key of  
683 - std::string id2; // trailer dictionary 682 + std::string id1; // for /ID key of
  683 + std::string id2; // trailer dictionary
684 std::string final_pdf_version; 684 std::string final_pdf_version;
685 int final_extension_level; 685 int final_extension_level;
686 std::string min_pdf_version; 686 std::string min_pdf_version;
include/qpdf/QPDFXRefEntry.hh
@@ -46,7 +46,7 @@ class QPDFXRefEntry @@ -46,7 +46,7 @@ class QPDFXRefEntry
46 QPDF_DLL 46 QPDF_DLL
47 int getObjStreamNumber() const; // only for type 2 47 int getObjStreamNumber() const; // only for type 2
48 QPDF_DLL 48 QPDF_DLL
49 - int getObjStreamIndex() const; // only for type 2 49 + int getObjStreamIndex() const; // only for type 2
50 50
51 private: 51 private:
52 // This class does not use the Members pattern to avoid a memory 52 // This class does not use the Members pattern to avoid a memory
include/qpdf/qpdf-c.h
@@ -274,7 +274,7 @@ extern &quot;C&quot; { @@ -274,7 +274,7 @@ extern &quot;C&quot; {
274 */ 274 */
275 QPDF_DLL 275 QPDF_DLL
276 QPDF_ERROR_CODE qpdf_read(qpdf_data qpdf, char const* filename, 276 QPDF_ERROR_CODE qpdf_read(qpdf_data qpdf, char const* filename,
277 - char const* password); 277 + char const* password);
278 278
279 /* Calling qpdf_read_memory causes processMemoryFile to be called 279 /* Calling qpdf_read_memory causes processMemoryFile to be called
280 * in the C++ API. Otherwise, it behaves in the same way as 280 * in the C++ API. Otherwise, it behaves in the same way as
@@ -284,10 +284,10 @@ extern &quot;C&quot; { @@ -284,10 +284,10 @@ extern &quot;C&quot; {
284 */ 284 */
285 QPDF_DLL 285 QPDF_DLL
286 QPDF_ERROR_CODE qpdf_read_memory(qpdf_data qpdf, 286 QPDF_ERROR_CODE qpdf_read_memory(qpdf_data qpdf,
287 - char const* description,  
288 - char const* buffer,  
289 - unsigned long long size,  
290 - char const* password); 287 + char const* description,
  288 + char const* buffer,
  289 + unsigned long long size,
  290 + char const* password);
291 291
292 /* Calling qpdf_empty_pdf initializes this qpdf object with an 292 /* Calling qpdf_empty_pdf initializes this qpdf object with an
293 * empty PDF, making it possible to create a PDF from scratch 293 * empty PDF, making it possible to create a PDF from scratch
@@ -410,11 +410,11 @@ extern &quot;C&quot; { @@ -410,11 +410,11 @@ extern &quot;C&quot; {
410 410
411 QPDF_DLL 411 QPDF_DLL
412 void qpdf_set_object_stream_mode(qpdf_data qpdf, 412 void qpdf_set_object_stream_mode(qpdf_data qpdf,
413 - enum qpdf_object_stream_e mode); 413 + enum qpdf_object_stream_e mode);
414 414
415 QPDF_DLL 415 QPDF_DLL
416 void qpdf_set_stream_data_mode(qpdf_data qpdf, 416 void qpdf_set_stream_data_mode(qpdf_data qpdf,
417 - enum qpdf_stream_data_e mode); 417 + enum qpdf_stream_data_e mode);
418 418
419 QPDF_DLL 419 QPDF_DLL
420 void qpdf_set_compress_streams(qpdf_data qpdf, QPDF_BOOL value); 420 void qpdf_set_compress_streams(qpdf_data qpdf, QPDF_BOOL value);
@@ -454,77 +454,77 @@ extern &quot;C&quot; { @@ -454,77 +454,77 @@ extern &quot;C&quot; {
454 454
455 QPDF_DLL 455 QPDF_DLL
456 void qpdf_set_suppress_original_object_IDs( 456 void qpdf_set_suppress_original_object_IDs(
457 - qpdf_data qpdf, QPDF_BOOL value); 457 + qpdf_data qpdf, QPDF_BOOL value);
458 458
459 QPDF_DLL 459 QPDF_DLL
460 void qpdf_set_preserve_encryption(qpdf_data qpdf, QPDF_BOOL value); 460 void qpdf_set_preserve_encryption(qpdf_data qpdf, QPDF_BOOL value);
461 461
462 QPDF_DLL 462 QPDF_DLL
463 void qpdf_set_r2_encryption_parameters( 463 void qpdf_set_r2_encryption_parameters(
464 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
465 - QPDF_BOOL allow_print, QPDF_BOOL allow_modify,  
466 - QPDF_BOOL allow_extract, QPDF_BOOL allow_annotate); 464 + qpdf_data qpdf, char const* user_password, char const* owner_password,
  465 + QPDF_BOOL allow_print, QPDF_BOOL allow_modify,
  466 + QPDF_BOOL allow_extract, QPDF_BOOL allow_annotate);
467 467
468 QPDF_DLL 468 QPDF_DLL
469 void qpdf_set_r3_encryption_parameters2( 469 void qpdf_set_r3_encryption_parameters2(
470 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
471 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract, 470 + qpdf_data qpdf, char const* user_password, char const* owner_password,
  471 + QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
472 QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form, 472 QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
473 QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other, 473 QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
474 - enum qpdf_r3_print_e print); 474 + enum qpdf_r3_print_e print);
475 475
476 QPDF_DLL 476 QPDF_DLL
477 void qpdf_set_r4_encryption_parameters2( 477 void qpdf_set_r4_encryption_parameters2(
478 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
479 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract, 478 + qpdf_data qpdf, char const* user_password, char const* owner_password,
  479 + QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
480 QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form, 480 QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
481 QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other, 481 QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
482 - enum qpdf_r3_print_e print, 482 + enum qpdf_r3_print_e print,
483 QPDF_BOOL encrypt_metadata, QPDF_BOOL use_aes); 483 QPDF_BOOL encrypt_metadata, QPDF_BOOL use_aes);
484 484
485 QPDF_DLL 485 QPDF_DLL
486 void qpdf_set_r5_encryption_parameters2( 486 void qpdf_set_r5_encryption_parameters2(
487 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
488 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract, 487 + qpdf_data qpdf, char const* user_password, char const* owner_password,
  488 + QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
489 QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form, 489 QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
490 QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other, 490 QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
491 - enum qpdf_r3_print_e print, QPDF_BOOL encrypt_metadata); 491 + enum qpdf_r3_print_e print, QPDF_BOOL encrypt_metadata);
492 492
493 QPDF_DLL 493 QPDF_DLL
494 void qpdf_set_r6_encryption_parameters2( 494 void qpdf_set_r6_encryption_parameters2(
495 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
496 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract, 495 + qpdf_data qpdf, char const* user_password, char const* owner_password,
  496 + QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
497 QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form, 497 QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
498 QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other, 498 QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
499 - enum qpdf_r3_print_e print, QPDF_BOOL encrypt_metadata); 499 + enum qpdf_r3_print_e print, QPDF_BOOL encrypt_metadata);
500 500
501 /* Pre 8.4.0 encryption API */ 501 /* Pre 8.4.0 encryption API */
502 QPDF_DLL 502 QPDF_DLL
503 void qpdf_set_r3_encryption_parameters( 503 void qpdf_set_r3_encryption_parameters(
504 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
505 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,  
506 - enum qpdf_r3_print_e print, enum qpdf_r3_modify_e modify); 504 + qpdf_data qpdf, char const* user_password, char const* owner_password,
  505 + QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
  506 + enum qpdf_r3_print_e print, enum qpdf_r3_modify_e modify);
507 507
508 QPDF_DLL 508 QPDF_DLL
509 void qpdf_set_r4_encryption_parameters( 509 void qpdf_set_r4_encryption_parameters(
510 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
511 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,  
512 - enum qpdf_r3_print_e print, enum qpdf_r3_modify_e modify,  
513 - QPDF_BOOL encrypt_metadata, QPDF_BOOL use_aes); 510 + qpdf_data qpdf, char const* user_password, char const* owner_password,
  511 + QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
  512 + enum qpdf_r3_print_e print, enum qpdf_r3_modify_e modify,
  513 + QPDF_BOOL encrypt_metadata, QPDF_BOOL use_aes);
514 514
515 QPDF_DLL 515 QPDF_DLL
516 void qpdf_set_r5_encryption_parameters( 516 void qpdf_set_r5_encryption_parameters(
517 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
518 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,  
519 - enum qpdf_r3_print_e print, enum qpdf_r3_modify_e modify,  
520 - QPDF_BOOL encrypt_metadata); 517 + qpdf_data qpdf, char const* user_password, char const* owner_password,
  518 + QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
  519 + enum qpdf_r3_print_e print, enum qpdf_r3_modify_e modify,
  520 + QPDF_BOOL encrypt_metadata);
521 521
522 QPDF_DLL 522 QPDF_DLL
523 void qpdf_set_r6_encryption_parameters( 523 void qpdf_set_r6_encryption_parameters(
524 - qpdf_data qpdf, char const* user_password, char const* owner_password,  
525 - QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,  
526 - enum qpdf_r3_print_e print, enum qpdf_r3_modify_e modify,  
527 - QPDF_BOOL encrypt_metadata); 524 + qpdf_data qpdf, char const* user_password, char const* owner_password,
  525 + QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
  526 + enum qpdf_r3_print_e print, enum qpdf_r3_modify_e modify,
  527 + QPDF_BOOL encrypt_metadata);
528 528
529 QPDF_DLL 529 QPDF_DLL
530 void qpdf_set_linearization(qpdf_data qpdf, QPDF_BOOL value); 530 void qpdf_set_linearization(qpdf_data qpdf, QPDF_BOOL value);
libqpdf/AES_PDF_native.cc
@@ -26,12 +26,12 @@ AES_PDF_native::AES_PDF_native(bool encrypt, unsigned char const* key, @@ -26,12 +26,12 @@ AES_PDF_native::AES_PDF_native(bool encrypt, unsigned char const* key,
26 std::memset(this->rk.get(), 0, rk_bytes); 26 std::memset(this->rk.get(), 0, rk_bytes);
27 if (encrypt) 27 if (encrypt)
28 { 28 {
29 - this->nrounds = rijndaelSetupEncrypt( 29 + this->nrounds = rijndaelSetupEncrypt(
30 this->rk.get(), this->key.get(), keybits); 30 this->rk.get(), this->key.get(), keybits);
31 } 31 }
32 else 32 else
33 { 33 {
34 - this->nrounds = rijndaelSetupDecrypt( 34 + this->nrounds = rijndaelSetupDecrypt(
35 this->rk.get(), this->key.get(), keybits); 35 this->rk.get(), this->key.get(), keybits);
36 } 36 }
37 } 37 }
@@ -45,33 +45,33 @@ AES_PDF_native::update(unsigned char* in_data, unsigned char* out_data) @@ -45,33 +45,33 @@ AES_PDF_native::update(unsigned char* in_data, unsigned char* out_data)
45 { 45 {
46 if (this->encrypt) 46 if (this->encrypt)
47 { 47 {
48 - if (this->cbc_mode)  
49 - {  
50 - for (size_t i = 0; i < QPDFCryptoImpl::rijndael_buf_size; ++i)  
51 - {  
52 - in_data[i] ^= this->cbc_block[i];  
53 - }  
54 - }  
55 - rijndaelEncrypt(this->rk.get(), 48 + if (this->cbc_mode)
  49 + {
  50 + for (size_t i = 0; i < QPDFCryptoImpl::rijndael_buf_size; ++i)
  51 + {
  52 + in_data[i] ^= this->cbc_block[i];
  53 + }
  54 + }
  55 + rijndaelEncrypt(this->rk.get(),
56 this->nrounds, in_data, out_data); 56 this->nrounds, in_data, out_data);
57 - if (this->cbc_mode)  
58 - {  
59 - memcpy(this->cbc_block, out_data, 57 + if (this->cbc_mode)
  58 + {
  59 + memcpy(this->cbc_block, out_data,
60 QPDFCryptoImpl::rijndael_buf_size); 60 QPDFCryptoImpl::rijndael_buf_size);
61 - } 61 + }
62 } 62 }
63 else 63 else
64 { 64 {
65 - rijndaelDecrypt(this->rk.get(), 65 + rijndaelDecrypt(this->rk.get(),
66 this->nrounds, in_data, out_data); 66 this->nrounds, in_data, out_data);
67 - if (this->cbc_mode)  
68 - {  
69 - for (size_t i = 0; i < QPDFCryptoImpl::rijndael_buf_size; ++i)  
70 - {  
71 - out_data[i] ^= this->cbc_block[i];  
72 - }  
73 - memcpy(this->cbc_block, in_data, 67 + if (this->cbc_mode)
  68 + {
  69 + for (size_t i = 0; i < QPDFCryptoImpl::rijndael_buf_size; ++i)
  70 + {
  71 + out_data[i] ^= this->cbc_block[i];
  72 + }
  73 + memcpy(this->cbc_block, in_data,
74 QPDFCryptoImpl::rijndael_buf_size); 74 QPDFCryptoImpl::rijndael_buf_size);
75 - } 75 + }
76 } 76 }
77 } 77 }
libqpdf/BitStream.cc
@@ -20,7 +20,7 @@ BitStream::reset() @@ -20,7 +20,7 @@ BitStream::reset()
20 bit_offset = 7; 20 bit_offset = 7;
21 if (QIntC::to_uint(nbytes) > static_cast<unsigned int>(-1) / 8) 21 if (QIntC::to_uint(nbytes) > static_cast<unsigned int>(-1) / 8)
22 { 22 {
23 - throw std::runtime_error("array too large for bitstream"); 23 + throw std::runtime_error("array too large for bitstream");
24 } 24 }
25 bits_available = 8 * nbytes; 25 bits_available = 8 * nbytes;
26 } 26 }
@@ -29,7 +29,7 @@ unsigned long long @@ -29,7 +29,7 @@ unsigned long long
29 BitStream::getBits(size_t nbits) 29 BitStream::getBits(size_t nbits)
30 { 30 {
31 return read_bits(this->p, this->bit_offset, 31 return read_bits(this->p, this->bit_offset,
32 - this->bits_available, nbits); 32 + this->bits_available, nbits);
33 } 33 }
34 34
35 long long 35 long long
@@ -63,14 +63,14 @@ BitStream::skipToNextByte() @@ -63,14 +63,14 @@ BitStream::skipToNextByte()
63 { 63 {
64 if (bit_offset != 7) 64 if (bit_offset != 7)
65 { 65 {
66 - size_t bits_to_skip = bit_offset + 1;  
67 - if (bits_available < bits_to_skip)  
68 - {  
69 - throw std::logic_error(  
70 - "INTERNAL ERROR: overflow skipping to next byte in bitstream");  
71 - }  
72 - bit_offset = 7;  
73 - ++p;  
74 - bits_available -= bits_to_skip; 66 + size_t bits_to_skip = bit_offset + 1;
  67 + if (bits_available < bits_to_skip)
  68 + {
  69 + throw std::logic_error(
  70 + "INTERNAL ERROR: overflow skipping to next byte in bitstream");
  71 + }
  72 + bit_offset = 7;
  73 + ++p;
  74 + bits_available -= bits_to_skip;
75 } 75 }
76 } 76 }
libqpdf/BitWriter.cc
@@ -43,7 +43,7 @@ BitWriter::flush() @@ -43,7 +43,7 @@ BitWriter::flush()
43 { 43 {
44 if (bit_offset < 7) 44 if (bit_offset < 7)
45 { 45 {
46 - size_t bits_to_write = bit_offset + 1;  
47 - write_bits(this->ch, this->bit_offset, 0, bits_to_write, this->pl); 46 + size_t bits_to_write = bit_offset + 1;
  47 + write_bits(this->ch, this->bit_offset, 0, bits_to_write, this->pl);
48 } 48 }
49 } 49 }
libqpdf/Buffer.cc
@@ -9,11 +9,11 @@ Buffer::Members::Members(size_t size, unsigned char* buf, bool own_memory) : @@ -9,11 +9,11 @@ Buffer::Members::Members(size_t size, unsigned char* buf, bool own_memory) :
9 { 9 {
10 if (own_memory) 10 if (own_memory)
11 { 11 {
12 - this->buf = (size ? new unsigned char[size] : 0); 12 + this->buf = (size ? new unsigned char[size] : 0);
13 } 13 }
14 else 14 else
15 { 15 {
16 - this->buf = buf; 16 + this->buf = buf;
17 } 17 }
18 } 18 }
19 19
@@ -21,7 +21,7 @@ Buffer::Members::~Members() @@ -21,7 +21,7 @@ Buffer::Members::~Members()
21 { 21 {
22 if (this->own_memory) 22 if (this->own_memory)
23 { 23 {
24 - delete [] this->buf; 24 + delete [] this->buf;
25 } 25 }
26 } 26 }
27 27
@@ -58,10 +58,10 @@ Buffer::copy(Buffer const&amp; rhs) @@ -58,10 +58,10 @@ Buffer::copy(Buffer const&amp; rhs)
58 if (this != &rhs) 58 if (this != &rhs)
59 { 59 {
60 this->m = PointerHolder<Members>(new Members(rhs.m->size, 0, true)); 60 this->m = PointerHolder<Members>(new Members(rhs.m->size, 0, true));
61 - if (this->m->size)  
62 - {  
63 - memcpy(this->m->buf, rhs.m->buf, this->m->size);  
64 - } 61 + if (this->m->size)
  62 + {
  63 + memcpy(this->m->buf, rhs.m->buf, this->m->size);
  64 + }
65 } 65 }
66 } 66 }
67 67
libqpdf/BufferInputSource.cc
@@ -42,7 +42,7 @@ BufferInputSource::~BufferInputSource() @@ -42,7 +42,7 @@ BufferInputSource::~BufferInputSource()
42 { 42 {
43 if (this->m->own_memory) 43 if (this->m->own_memory)
44 { 44 {
45 - delete this->m->buf; 45 + delete this->m->buf;
46 } 46 }
47 } 47 }
48 48
@@ -56,9 +56,9 @@ BufferInputSource::findAndSkipNextEOL() @@ -56,9 +56,9 @@ BufferInputSource::findAndSkipNextEOL()
56 qpdf_offset_t end_pos = this->m->max_offset; 56 qpdf_offset_t end_pos = this->m->max_offset;
57 if (this->m->cur_offset >= end_pos) 57 if (this->m->cur_offset >= end_pos)
58 { 58 {
59 - this->last_offset = end_pos; 59 + this->last_offset = end_pos;
60 this->m->cur_offset = end_pos; 60 this->m->cur_offset = end_pos;
61 - return end_pos; 61 + return end_pos;
62 } 62 }
63 63
64 qpdf_offset_t result = 0; 64 qpdf_offset_t result = 0;
@@ -108,23 +108,23 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence) @@ -108,23 +108,23 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence)
108 switch (whence) 108 switch (whence)
109 { 109 {
110 case SEEK_SET: 110 case SEEK_SET:
111 - this->m->cur_offset = offset;  
112 - break; 111 + this->m->cur_offset = offset;
  112 + break;
113 113
114 case SEEK_END: 114 case SEEK_END:
115 QIntC::range_check(this->m->max_offset, offset); 115 QIntC::range_check(this->m->max_offset, offset);
116 - this->m->cur_offset = this->m->max_offset + offset;  
117 - break; 116 + this->m->cur_offset = this->m->max_offset + offset;
  117 + break;
118 118
119 case SEEK_CUR: 119 case SEEK_CUR:
120 QIntC::range_check(this->m->cur_offset, offset); 120 QIntC::range_check(this->m->cur_offset, offset);
121 - this->m->cur_offset += offset;  
122 - break; 121 + this->m->cur_offset += offset;
  122 + break;
123 123
124 default: 124 default:
125 - throw std::logic_error(  
126 - "INTERNAL ERROR: invalid argument to BufferInputSource::seek");  
127 - break; 125 + throw std::logic_error(
  126 + "INTERNAL ERROR: invalid argument to BufferInputSource::seek");
  127 + break;
128 } 128 }
129 129
130 if (this->m->cur_offset < 0) 130 if (this->m->cur_offset < 0)
@@ -150,8 +150,8 @@ BufferInputSource::read(char* buffer, size_t length) @@ -150,8 +150,8 @@ BufferInputSource::read(char* buffer, size_t length)
150 qpdf_offset_t end_pos = this->m->max_offset; 150 qpdf_offset_t end_pos = this->m->max_offset;
151 if (this->m->cur_offset >= end_pos) 151 if (this->m->cur_offset >= end_pos)
152 { 152 {
153 - this->last_offset = end_pos;  
154 - return 0; 153 + this->last_offset = end_pos;
  154 + return 0;
155 } 155 }
156 156
157 this->last_offset = this->m->cur_offset; 157 this->last_offset = this->m->cur_offset;
@@ -167,6 +167,6 @@ BufferInputSource::unreadCh(char ch) @@ -167,6 +167,6 @@ BufferInputSource::unreadCh(char ch)
167 { 167 {
168 if (this->m->cur_offset > 0) 168 if (this->m->cur_offset > 0)
169 { 169 {
170 - --this->m->cur_offset; 170 + --this->m->cur_offset;
171 } 171 }
172 } 172 }
libqpdf/ContentNormalizer.cc
@@ -61,16 +61,16 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const&amp; token) @@ -61,16 +61,16 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const&amp; token)
61 // quoting of unprintable characters, etc. 61 // quoting of unprintable characters, etc.
62 writeToken(QPDFTokenizer::Token( 62 writeToken(QPDFTokenizer::Token(
63 QPDFTokenizer::tt_string, token.getValue())); 63 QPDFTokenizer::tt_string, token.getValue()));
64 - break; 64 + break;
65 65
66 case QPDFTokenizer::tt_name: 66 case QPDFTokenizer::tt_name:
67 writeToken(QPDFTokenizer::Token( 67 writeToken(QPDFTokenizer::Token(
68 QPDFTokenizer::tt_name, token.getValue())); 68 QPDFTokenizer::tt_name, token.getValue()));
69 - break; 69 + break;
70 70
71 default: 71 default:
72 writeToken(token); 72 writeToken(token);
73 - break; 73 + break;
74 } 74 }
75 75
76 value = token.getRawValue(); 76 value = token.getRawValue();
libqpdf/FileInputSource.cc
@@ -15,7 +15,7 @@ FileInputSource::Members::~Members() @@ -15,7 +15,7 @@ FileInputSource::Members::~Members()
15 { 15 {
16 if (this->file && this->close_file) 16 if (this->file && this->close_file)
17 { 17 {
18 - fclose(this->file); 18 + fclose(this->file);
19 } 19 }
20 } 20 }
21 21
@@ -108,9 +108,9 @@ FileInputSource::seek(qpdf_offset_t offset, int whence) @@ -108,9 +108,9 @@ FileInputSource::seek(qpdf_offset_t offset, int whence)
108 { 108 {
109 QUtil::os_wrapper(std::string("seek to ") + 109 QUtil::os_wrapper(std::string("seek to ") +
110 this->m->filename + ", offset " + 110 this->m->filename + ", offset " +
111 - QUtil::int_to_string(offset) + " (" +  
112 - QUtil::int_to_string(whence) + ")",  
113 - QUtil::seek(this->m->file, offset, whence)); 111 + QUtil::int_to_string(offset) + " (" +
  112 + QUtil::int_to_string(whence) + ")",
  113 + QUtil::seek(this->m->file, offset, whence));
114 } 114 }
115 115
116 void 116 void
@@ -147,5 +147,5 @@ void @@ -147,5 +147,5 @@ void
147 FileInputSource::unreadCh(char ch) 147 FileInputSource::unreadCh(char ch)
148 { 148 {
149 QUtil::os_wrapper(this->m->filename + ": unread character", 149 QUtil::os_wrapper(this->m->filename + ": unread character",
150 - ungetc(static_cast<unsigned char>(ch), this->m->file)); 150 + ungetc(static_cast<unsigned char>(ch), this->m->file));
151 } 151 }
libqpdf/InsecureRandomDataProvider.cc
@@ -27,9 +27,9 @@ InsecureRandomDataProvider::random() @@ -27,9 +27,9 @@ InsecureRandomDataProvider::random()
27 { 27 {
28 if (! this->seeded_random) 28 if (! this->seeded_random)
29 { 29 {
30 - // Seed the random number generator with something simple, but  
31 - // just to be interesting, don't use the unmodified current  
32 - // time. It would be better if this were a more secure seed. 30 + // Seed the random number generator with something simple, but
  31 + // just to be interesting, don't use the unmodified current
  32 + // time. It would be better if this were a more secure seed.
33 unsigned int seed = static_cast<unsigned int>( 33 unsigned int seed = static_cast<unsigned int>(
34 QUtil::get_current_time() ^ 0xcccc); 34 QUtil::get_current_time() ^ 0xcccc);
35 #ifdef HAVE_RANDOM 35 #ifdef HAVE_RANDOM
@@ -37,7 +37,7 @@ InsecureRandomDataProvider::random() @@ -37,7 +37,7 @@ InsecureRandomDataProvider::random()
37 #else 37 #else
38 srand(seed); 38 srand(seed);
39 #endif 39 #endif
40 - this->seeded_random = true; 40 + this->seeded_random = true;
41 } 41 }
42 42
43 # ifdef HAVE_RANDOM 43 # ifdef HAVE_RANDOM
libqpdf/MD5.cc
@@ -66,28 +66,28 @@ void MD5::encodeFile(char const *filename, qpdf_offset_t up_to_offset) @@ -66,28 +66,28 @@ void MD5::encodeFile(char const *filename, qpdf_offset_t up_to_offset)
66 } 66 }
67 do 67 do
68 { 68 {
69 - if ((up_to_offset >= 0) && ((so_far + to_try) > up_to_size))  
70 - {  
71 - to_try = up_to_size - so_far;  
72 - }  
73 - len = fread(buffer, 1, to_try, file);  
74 - if (len > 0)  
75 - {  
76 - encodeDataIncrementally(buffer, len);  
77 - so_far += len;  
78 - if ((up_to_offset >= 0) && (so_far >= up_to_size))  
79 - {  
80 - break;  
81 - }  
82 - } 69 + if ((up_to_offset >= 0) && ((so_far + to_try) > up_to_size))
  70 + {
  71 + to_try = up_to_size - so_far;
  72 + }
  73 + len = fread(buffer, 1, to_try, file);
  74 + if (len > 0)
  75 + {
  76 + encodeDataIncrementally(buffer, len);
  77 + so_far += len;
  78 + if ((up_to_offset >= 0) && (so_far >= up_to_size))
  79 + {
  80 + break;
  81 + }
  82 + }
83 } while (len > 0); 83 } while (len > 0);
84 if (ferror(file)) 84 if (ferror(file))
85 { 85 {
86 - // Assume, perhaps incorrectly, that errno was set by the  
87 - // underlying call to read....  
88 - (void) fclose(file);  
89 - QUtil::throw_system_error(  
90 - std::string("MD5: read error on ") + filename); 86 + // Assume, perhaps incorrectly, that errno was set by the
  87 + // underlying call to read....
  88 + (void) fclose(file);
  89 + QUtil::throw_system_error(
  90 + std::string("MD5: read error on ") + filename);
91 } 91 }
92 (void) fclose(file); 92 (void) fclose(file);
93 93
@@ -108,7 +108,7 @@ void MD5::print() @@ -108,7 +108,7 @@ void MD5::print()
108 unsigned int i; 108 unsigned int i;
109 for (i = 0; i < 16; ++i) 109 for (i = 0; i < 16; ++i)
110 { 110 {
111 - printf("%02x", digest_val[i]); 111 + printf("%02x", digest_val[i]);
112 } 112 }
113 printf("\n"); 113 printf("\n");
114 } 114 }
@@ -140,7 +140,7 @@ MD5::getFileChecksum(char const* filename, qpdf_offset_t up_to_offset) @@ -140,7 +140,7 @@ MD5::getFileChecksum(char const* filename, qpdf_offset_t up_to_offset)
140 140
141 bool 141 bool
142 MD5::checkDataChecksum(char const* const checksum, 142 MD5::checkDataChecksum(char const* const checksum,
143 - char const* buf, size_t len) 143 + char const* buf, size_t len)
144 { 144 {
145 std::string actual_checksum = getDataChecksum(buf, len); 145 std::string actual_checksum = getDataChecksum(buf, len);
146 return (checksum == actual_checksum); 146 return (checksum == actual_checksum);
@@ -148,17 +148,17 @@ MD5::checkDataChecksum(char const* const checksum, @@ -148,17 +148,17 @@ MD5::checkDataChecksum(char const* const checksum,
148 148
149 bool 149 bool
150 MD5::checkFileChecksum(char const* const checksum, 150 MD5::checkFileChecksum(char const* const checksum,
151 - char const* filename, qpdf_offset_t up_to_offset) 151 + char const* filename, qpdf_offset_t up_to_offset)
152 { 152 {
153 bool result = false; 153 bool result = false;
154 try 154 try
155 { 155 {
156 - std::string actual_checksum = getFileChecksum(filename, up_to_offset);  
157 - result = (checksum == actual_checksum); 156 + std::string actual_checksum = getFileChecksum(filename, up_to_offset);
  157 + result = (checksum == actual_checksum);
158 } 158 }
159 catch (std::runtime_error const&) 159 catch (std::runtime_error const&)
160 { 160 {
161 - // Ignore -- return false 161 + // Ignore -- return false
162 } 162 }
163 return result; 163 return result;
164 } 164 }
libqpdf/MD5_native.cc
@@ -117,7 +117,7 @@ void MD5_native::init() @@ -117,7 +117,7 @@ void MD5_native::init()
117 // context. 117 // context.
118 118
119 void MD5_native::update(unsigned char *input, 119 void MD5_native::update(unsigned char *input,
120 - size_t inputLen) 120 + size_t inputLen)
121 { 121 {
122 unsigned int i, index, partLen; 122 unsigned int i, index, partLen;
123 123
@@ -127,7 +127,7 @@ void MD5_native::update(unsigned char *input, @@ -127,7 +127,7 @@ void MD5_native::update(unsigned char *input,
127 // Update number of bits 127 // Update number of bits
128 if ((count[0] += (static_cast<uint32_t>(inputLen) << 3)) < 128 if ((count[0] += (static_cast<uint32_t>(inputLen) << 3)) <
129 (static_cast<uint32_t>(inputLen) << 3)) 129 (static_cast<uint32_t>(inputLen) << 3))
130 - count[1]++; 130 + count[1]++;
131 count[1] += (static_cast<uint32_t>(inputLen) >> 29); 131 count[1] += (static_cast<uint32_t>(inputLen) >> 29);
132 132
133 partLen = 64 - index; 133 partLen = 64 - index;
@@ -135,16 +135,16 @@ void MD5_native::update(unsigned char *input, @@ -135,16 +135,16 @@ void MD5_native::update(unsigned char *input,
135 // Transform as many times as possible. 135 // Transform as many times as possible.
136 136
137 if (inputLen >= partLen) { 137 if (inputLen >= partLen) {
138 - memcpy(&buffer[index], input, partLen);  
139 - transform(state, buffer); 138 + memcpy(&buffer[index], input, partLen);
  139 + transform(state, buffer);
140 140
141 - for (i = partLen; i + 63 < inputLen; i += 64)  
142 - transform(state, &input[i]); 141 + for (i = partLen; i + 63 < inputLen; i += 64)
  142 + transform(state, &input[i]);
143 143
144 - index = 0; 144 + index = 0;
145 } 145 }
146 else 146 else
147 - i = 0; 147 + i = 0;
148 148
149 // Buffer remaining input 149 // Buffer remaining input
150 memcpy(&buffer[index], &input[i], inputLen-i); 150 memcpy(&buffer[index], &input[i], inputLen-i);
@@ -156,7 +156,7 @@ void MD5_native::finalize() @@ -156,7 +156,7 @@ void MD5_native::finalize()
156 { 156 {
157 if (finalized) 157 if (finalized)
158 { 158 {
159 - return; 159 + return;
160 } 160 }
161 161
162 unsigned char bits[8]; 162 unsigned char bits[8];
@@ -286,10 +286,10 @@ void MD5_native::encode(unsigned char *output, uint32_t *input, size_t len) @@ -286,10 +286,10 @@ void MD5_native::encode(unsigned char *output, uint32_t *input, size_t len)
286 unsigned int i, j; 286 unsigned int i, j;
287 287
288 for (i = 0, j = 0; j < len; i++, j += 4) { 288 for (i = 0, j = 0; j < len; i++, j += 4) {
289 - output[j] = static_cast<unsigned char>(input[i] & 0xff);  
290 - output[j+1] = static_cast<unsigned char>((input[i] >> 8) & 0xff);  
291 - output[j+2] = static_cast<unsigned char>((input[i] >> 16) & 0xff);  
292 - output[j+3] = static_cast<unsigned char>((input[i] >> 24) & 0xff); 289 + output[j] = static_cast<unsigned char>(input[i] & 0xff);
  290 + output[j+1] = static_cast<unsigned char>((input[i] >> 8) & 0xff);
  291 + output[j+2] = static_cast<unsigned char>((input[i] >> 16) & 0xff);
  292 + output[j+3] = static_cast<unsigned char>((input[i] >> 24) & 0xff);
293 } 293 }
294 } 294 }
295 295
@@ -300,9 +300,9 @@ void MD5_native::decode(uint32_t *output, unsigned char *input, size_t len) @@ -300,9 +300,9 @@ void MD5_native::decode(uint32_t *output, unsigned char *input, size_t len)
300 unsigned int i, j; 300 unsigned int i, j;
301 301
302 for (i = 0, j = 0; j < len; i++, j += 4) 302 for (i = 0, j = 0; j < len; i++, j += 4)
303 - output[i] = 303 + output[i] =
304 static_cast<uint32_t>(input[j]) | 304 static_cast<uint32_t>(input[j]) |
305 (static_cast<uint32_t>(input[j+1]) << 8) | 305 (static_cast<uint32_t>(input[j+1]) << 8) |
306 - (static_cast<uint32_t>(input[j+2]) << 16) | 306 + (static_cast<uint32_t>(input[j+2]) << 16) |
307 (static_cast<uint32_t>(input[j+3]) << 24); 307 (static_cast<uint32_t>(input[j+3]) << 24);
308 } 308 }
libqpdf/Pipeline.cc
@@ -17,9 +17,9 @@ Pipeline::getNext(bool allow_null) @@ -17,9 +17,9 @@ Pipeline::getNext(bool allow_null)
17 { 17 {
18 if ((this->next == 0) && (! allow_null)) 18 if ((this->next == 0) && (! allow_null))
19 { 19 {
20 - throw std::logic_error(  
21 - this->identifier +  
22 - ": Pipeline::getNext() called on pipeline with no next"); 20 + throw std::logic_error(
  21 + this->identifier +
  22 + ": Pipeline::getNext() called on pipeline with no next");
23 } 23 }
24 return this->next; 24 return this->next;
25 } 25 }
libqpdf/Pl_AES_PDF.cc
@@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
12 bool Pl_AES_PDF::use_static_iv = false; 12 bool Pl_AES_PDF::use_static_iv = false;
13 13
14 Pl_AES_PDF::Pl_AES_PDF(char const* identifier, Pipeline* next, 14 Pl_AES_PDF::Pl_AES_PDF(char const* identifier, Pipeline* next,
15 - bool encrypt, unsigned char const* key, 15 + bool encrypt, unsigned char const* key,
16 size_t key_bytes) : 16 size_t key_bytes) :
17 Pipeline(identifier, next), 17 Pipeline(identifier, next),
18 crypto(QPDFCryptoProvider::getImpl()), 18 crypto(QPDFCryptoProvider::getImpl()),
@@ -81,17 +81,17 @@ Pl_AES_PDF::write(unsigned char* data, size_t len) @@ -81,17 +81,17 @@ Pl_AES_PDF::write(unsigned char* data, size_t len)
81 81
82 while (bytes_left > 0) 82 while (bytes_left > 0)
83 { 83 {
84 - if (this->offset == this->buf_size)  
85 - {  
86 - flush(false);  
87 - }  
88 -  
89 - size_t available = this->buf_size - this->offset;  
90 - size_t bytes = (bytes_left < available ? bytes_left : available);  
91 - bytes_left -= bytes;  
92 - std::memcpy(this->inbuf + this->offset, p, bytes);  
93 - this->offset += bytes;  
94 - p += bytes; 84 + if (this->offset == this->buf_size)
  85 + {
  86 + flush(false);
  87 + }
  88 +
  89 + size_t available = this->buf_size - this->offset;
  90 + size_t bytes = (bytes_left < available ? bytes_left : available);
  91 + bytes_left -= bytes;
  92 + std::memcpy(this->inbuf + this->offset, p, bytes);
  93 + this->offset += bytes;
  94 + p += bytes;
95 } 95 }
96 } 96 }
97 97
@@ -100,10 +100,10 @@ Pl_AES_PDF::finish() @@ -100,10 +100,10 @@ Pl_AES_PDF::finish()
100 { 100 {
101 if (this->encrypt) 101 if (this->encrypt)
102 { 102 {
103 - if (this->offset == this->buf_size)  
104 - {  
105 - flush(false);  
106 - } 103 + if (this->offset == this->buf_size)
  104 + {
  105 + flush(false);
  106 + }
107 if (! this->disable_padding) 107 if (! this->disable_padding)
108 { 108 {
109 // Pad as described in section 3.5.1 of version 1.7 of the PDF 109 // Pad as described in section 3.5.1 of version 1.7 of the PDF
@@ -118,19 +118,19 @@ Pl_AES_PDF::finish() @@ -118,19 +118,19 @@ Pl_AES_PDF::finish()
118 } 118 }
119 else 119 else
120 { 120 {
121 - if (this->offset != this->buf_size)  
122 - {  
123 - // This is never supposed to happen as the output is  
124 - // always supposed to be padded. However, we have  
125 - // encountered files for which the output is not a  
126 - // multiple of the block size. In this case, pad with  
127 - // zeroes and hope for the best.  
128 - assert(this->buf_size > this->offset);  
129 - std::memset(this->inbuf + this->offset, 0,  
130 - this->buf_size - this->offset);  
131 - this->offset = this->buf_size;  
132 - }  
133 - flush(! this->disable_padding); 121 + if (this->offset != this->buf_size)
  122 + {
  123 + // This is never supposed to happen as the output is
  124 + // always supposed to be padded. However, we have
  125 + // encountered files for which the output is not a
  126 + // multiple of the block size. In this case, pad with
  127 + // zeroes and hope for the best.
  128 + assert(this->buf_size > this->offset);
  129 + std::memset(this->inbuf + this->offset, 0,
  130 + this->buf_size - this->offset);
  131 + this->offset = this->buf_size;
  132 + }
  133 + flush(! this->disable_padding);
134 } 134 }
135 this->crypto->rijndael_finalize(); 135 this->crypto->rijndael_finalize();
136 getNext()->finish(); 136 getNext()->finish();
@@ -141,10 +141,10 @@ Pl_AES_PDF::initializeVector() @@ -141,10 +141,10 @@ Pl_AES_PDF::initializeVector()
141 { 141 {
142 if (use_zero_iv) 142 if (use_zero_iv)
143 { 143 {
144 - for (unsigned int i = 0; i < this->buf_size; ++i)  
145 - {  
146 - this->cbc_block[i] = 0;  
147 - } 144 + for (unsigned int i = 0; i < this->buf_size; ++i)
  145 + {
  146 + this->cbc_block[i] = 0;
  147 + }
148 } 148 }
149 else if (use_specified_iv) 149 else if (use_specified_iv)
150 { 150 {
@@ -152,10 +152,10 @@ Pl_AES_PDF::initializeVector() @@ -152,10 +152,10 @@ Pl_AES_PDF::initializeVector()
152 } 152 }
153 else if (use_static_iv) 153 else if (use_static_iv)
154 { 154 {
155 - for (unsigned int i = 0; i < this->buf_size; ++i)  
156 - {  
157 - this->cbc_block[i] = static_cast<unsigned char>(14U * (1U + i));  
158 - } 155 + for (unsigned int i = 0; i < this->buf_size; ++i)
  156 + {
  157 + this->cbc_block[i] = static_cast<unsigned char>(14U * (1U + i));
  158 + }
159 } 159 }
160 else 160 else
161 { 161 {
@@ -170,35 +170,35 @@ Pl_AES_PDF::flush(bool strip_padding) @@ -170,35 +170,35 @@ Pl_AES_PDF::flush(bool strip_padding)
170 170
171 if (first) 171 if (first)
172 { 172 {
173 - first = false; 173 + first = false;
174 bool return_after_init = false; 174 bool return_after_init = false;
175 - if (this->cbc_mode)  
176 - {  
177 - if (encrypt)  
178 - {  
179 - // Set cbc_block to the initialization vector, and if  
180 - // not zero, write it to the output stream.  
181 - initializeVector(); 175 + if (this->cbc_mode)
  176 + {
  177 + if (encrypt)
  178 + {
  179 + // Set cbc_block to the initialization vector, and if
  180 + // not zero, write it to the output stream.
  181 + initializeVector();
182 if (! (this->use_zero_iv || this->use_specified_iv)) 182 if (! (this->use_zero_iv || this->use_specified_iv))
183 { 183 {
184 getNext()->write(this->cbc_block, this->buf_size); 184 getNext()->write(this->cbc_block, this->buf_size);
185 } 185 }
186 - }  
187 - else if (this->use_zero_iv || this->use_specified_iv) 186 + }
  187 + else if (this->use_zero_iv || this->use_specified_iv)
188 { 188 {
189 // Initialize vector with zeroes; zero vector was not 189 // Initialize vector with zeroes; zero vector was not
190 // written to the beginning of the input file. 190 // written to the beginning of the input file.
191 initializeVector(); 191 initializeVector();
192 } 192 }
193 else 193 else
194 - {  
195 - // Take the first block of input as the initialization  
196 - // vector. There's nothing to write at this time.  
197 - memcpy(this->cbc_block, this->inbuf, this->buf_size);  
198 - this->offset = 0; 194 + {
  195 + // Take the first block of input as the initialization
  196 + // vector. There's nothing to write at this time.
  197 + memcpy(this->cbc_block, this->inbuf, this->buf_size);
  198 + this->offset = 0;
199 return_after_init = true; 199 return_after_init = true;
200 - }  
201 - } 200 + }
  201 + }
202 this->crypto->rijndael_init( 202 this->crypto->rijndael_init(
203 encrypt, this->key.get(), key_bytes, 203 encrypt, this->key.get(), key_bytes,
204 this->cbc_mode, this->cbc_block); 204 this->cbc_mode, this->cbc_block);
@@ -212,23 +212,23 @@ Pl_AES_PDF::flush(bool strip_padding) @@ -212,23 +212,23 @@ Pl_AES_PDF::flush(bool strip_padding)
212 unsigned int bytes = this->buf_size; 212 unsigned int bytes = this->buf_size;
213 if (strip_padding) 213 if (strip_padding)
214 { 214 {
215 - unsigned char last = this->outbuf[this->buf_size - 1];  
216 - if (last <= this->buf_size)  
217 - {  
218 - bool strip = true;  
219 - for (unsigned int i = 1; i <= last; ++i)  
220 - {  
221 - if (this->outbuf[this->buf_size - i] != last)  
222 - {  
223 - strip = false;  
224 - break;  
225 - }  
226 - }  
227 - if (strip)  
228 - {  
229 - bytes -= last;  
230 - }  
231 - } 215 + unsigned char last = this->outbuf[this->buf_size - 1];
  216 + if (last <= this->buf_size)
  217 + {
  218 + bool strip = true;
  219 + for (unsigned int i = 1; i <= last; ++i)
  220 + {
  221 + if (this->outbuf[this->buf_size - i] != last)
  222 + {
  223 + strip = false;
  224 + break;
  225 + }
  226 + }
  227 + if (strip)
  228 + {
  229 + bytes -= last;
  230 + }
  231 + }
232 } 232 }
233 this->offset = 0; 233 this->offset = 0;
234 getNext()->write(this->outbuf, bytes); 234 getNext()->write(this->outbuf, bytes);
libqpdf/Pl_ASCII85Decoder.cc
@@ -21,77 +21,77 @@ Pl_ASCII85Decoder::write(unsigned char* buf, size_t len) @@ -21,77 +21,77 @@ Pl_ASCII85Decoder::write(unsigned char* buf, size_t len)
21 { 21 {
22 if (eod > 1) 22 if (eod > 1)
23 { 23 {
24 - return; 24 + return;
25 } 25 }
26 for (size_t i = 0; i < len; ++i) 26 for (size_t i = 0; i < len; ++i)
27 { 27 {
28 - if (eod > 1)  
29 - {  
30 - break;  
31 - }  
32 - else if (eod == 1)  
33 - {  
34 - if (buf[i] == '>')  
35 - {  
36 - flush();  
37 - eod = 2;  
38 - }  
39 - else  
40 - {  
41 - throw std::runtime_error(  
42 - "broken end-of-data sequence in base 85 data");  
43 - }  
44 - }  
45 - else  
46 - {  
47 - switch (buf[i])  
48 - {  
49 - case ' ':  
50 - case '\f':  
51 - case '\v':  
52 - case '\t':  
53 - case '\r':  
54 - case '\n':  
55 - QTC::TC("libtests", "Pl_ASCII85Decoder ignore space");  
56 - // ignore whitespace  
57 - break; 28 + if (eod > 1)
  29 + {
  30 + break;
  31 + }
  32 + else if (eod == 1)
  33 + {
  34 + if (buf[i] == '>')
  35 + {
  36 + flush();
  37 + eod = 2;
  38 + }
  39 + else
  40 + {
  41 + throw std::runtime_error(
  42 + "broken end-of-data sequence in base 85 data");
  43 + }
  44 + }
  45 + else
  46 + {
  47 + switch (buf[i])
  48 + {
  49 + case ' ':
  50 + case '\f':
  51 + case '\v':
  52 + case '\t':
  53 + case '\r':
  54 + case '\n':
  55 + QTC::TC("libtests", "Pl_ASCII85Decoder ignore space");
  56 + // ignore whitespace
  57 + break;
58 58
59 - case '~':  
60 - eod = 1;  
61 - break; 59 + case '~':
  60 + eod = 1;
  61 + break;
62 62
63 - case 'z':  
64 - if (pos != 0)  
65 - {  
66 - throw std::runtime_error(  
67 - "unexpected z during base 85 decode");  
68 - }  
69 - else  
70 - {  
71 - QTC::TC("libtests", "Pl_ASCII85Decoder read z"); 63 + case 'z':
  64 + if (pos != 0)
  65 + {
  66 + throw std::runtime_error(
  67 + "unexpected z during base 85 decode");
  68 + }
  69 + else
  70 + {
  71 + QTC::TC("libtests", "Pl_ASCII85Decoder read z");
72 unsigned char zeroes[4]; 72 unsigned char zeroes[4];
73 memset(zeroes, '\0', 4); 73 memset(zeroes, '\0', 4);
74 - getNext()->write(zeroes, 4);  
75 - }  
76 - break; 74 + getNext()->write(zeroes, 4);
  75 + }
  76 + break;
77 77
78 - default:  
79 - if ((buf[i] < 33) || (buf[i] > 117))  
80 - {  
81 - throw std::runtime_error(  
82 - "character out of range during base 85 decode");  
83 - }  
84 - else  
85 - {  
86 - this->inbuf[this->pos++] = buf[i];  
87 - if (pos == 5)  
88 - {  
89 - flush();  
90 - }  
91 - }  
92 - break;  
93 - }  
94 - } 78 + default:
  79 + if ((buf[i] < 33) || (buf[i] > 117))
  80 + {
  81 + throw std::runtime_error(
  82 + "character out of range during base 85 decode");
  83 + }
  84 + else
  85 + {
  86 + this->inbuf[this->pos++] = buf[i];
  87 + if (pos == 5)
  88 + {
  89 + flush();
  90 + }
  91 + }
  92 + break;
  93 + }
  94 + }
95 } 95 }
96 } 96 }
97 97
@@ -100,26 +100,26 @@ Pl_ASCII85Decoder::flush() @@ -100,26 +100,26 @@ Pl_ASCII85Decoder::flush()
100 { 100 {
101 if (this->pos == 0) 101 if (this->pos == 0)
102 { 102 {
103 - QTC::TC("libtests", "Pl_ASCII85Decoder no-op flush");  
104 - return; 103 + QTC::TC("libtests", "Pl_ASCII85Decoder no-op flush");
  104 + return;
105 } 105 }
106 unsigned long lval = 0; 106 unsigned long lval = 0;
107 for (int i = 0; i < 5; ++i) 107 for (int i = 0; i < 5; ++i)
108 { 108 {
109 - lval *= 85;  
110 - lval += (this->inbuf[i] - 33U); 109 + lval *= 85;
  110 + lval += (this->inbuf[i] - 33U);
111 } 111 }
112 112
113 unsigned char outbuf[4]; 113 unsigned char outbuf[4];
114 memset(outbuf, 0, 4); 114 memset(outbuf, 0, 4);
115 for (int i = 3; i >= 0; --i) 115 for (int i = 3; i >= 0; --i)
116 { 116 {
117 - outbuf[i] = lval & 0xff;  
118 - lval >>= 8; 117 + outbuf[i] = lval & 0xff;
  118 + lval >>= 8;
119 } 119 }
120 120
121 QTC::TC("libtests", "Pl_ASCII85Decoder partial flush", 121 QTC::TC("libtests", "Pl_ASCII85Decoder partial flush",
122 - (this->pos == 5) ? 0 : 1); 122 + (this->pos == 5) ? 0 : 1);
123 // Reset before calling getNext()->write in case that throws an 123 // Reset before calling getNext()->write in case that throws an
124 // exception. 124 // exception.
125 auto t = this->pos - 1; 125 auto t = this->pos - 1;
libqpdf/Pl_ASCIIHexDecoder.cc
@@ -24,53 +24,53 @@ Pl_ASCIIHexDecoder::write(unsigned char* buf, size_t len) @@ -24,53 +24,53 @@ Pl_ASCIIHexDecoder::write(unsigned char* buf, size_t len)
24 { 24 {
25 if (this->eod) 25 if (this->eod)
26 { 26 {
27 - return; 27 + return;
28 } 28 }
29 for (size_t i = 0; i < len; ++i) 29 for (size_t i = 0; i < len; ++i)
30 { 30 {
31 - char ch = static_cast<char>(toupper(buf[i]));  
32 - switch (ch)  
33 - {  
34 - case ' ':  
35 - case '\f':  
36 - case '\v':  
37 - case '\t':  
38 - case '\r':  
39 - case '\n':  
40 - QTC::TC("libtests", "Pl_ASCIIHexDecoder ignore space");  
41 - // ignore whitespace  
42 - break; 31 + char ch = static_cast<char>(toupper(buf[i]));
  32 + switch (ch)
  33 + {
  34 + case ' ':
  35 + case '\f':
  36 + case '\v':
  37 + case '\t':
  38 + case '\r':
  39 + case '\n':
  40 + QTC::TC("libtests", "Pl_ASCIIHexDecoder ignore space");
  41 + // ignore whitespace
  42 + break;
43 43
44 - case '>':  
45 - this->eod = true;  
46 - flush();  
47 - break; 44 + case '>':
  45 + this->eod = true;
  46 + flush();
  47 + break;
48 48
49 - default:  
50 - if (((ch >= '0') && (ch <= '9')) ||  
51 - ((ch >= 'A') && (ch <= 'F')))  
52 - {  
53 - this->inbuf[this->pos++] = ch;  
54 - if (this->pos == 2)  
55 - {  
56 - flush();  
57 - }  
58 - }  
59 - else  
60 - {  
61 - char t[2];  
62 - t[0] = ch;  
63 - t[1] = 0;  
64 - throw std::runtime_error(  
65 - std::string("character out of range"  
66 - " during base Hex decode: ") + t);  
67 - }  
68 - break;  
69 - }  
70 - if (this->eod)  
71 - {  
72 - break;  
73 - } 49 + default:
  50 + if (((ch >= '0') && (ch <= '9')) ||
  51 + ((ch >= 'A') && (ch <= 'F')))
  52 + {
  53 + this->inbuf[this->pos++] = ch;
  54 + if (this->pos == 2)
  55 + {
  56 + flush();
  57 + }
  58 + }
  59 + else
  60 + {
  61 + char t[2];
  62 + t[0] = ch;
  63 + t[1] = 0;
  64 + throw std::runtime_error(
  65 + std::string("character out of range"
  66 + " during base Hex decode: ") + t);
  67 + }
  68 + break;
  69 + }
  70 + if (this->eod)
  71 + {
  72 + break;
  73 + }
74 } 74 }
75 } 75 }
76 76
@@ -79,25 +79,25 @@ Pl_ASCIIHexDecoder::flush() @@ -79,25 +79,25 @@ Pl_ASCIIHexDecoder::flush()
79 { 79 {
80 if (this->pos == 0) 80 if (this->pos == 0)
81 { 81 {
82 - QTC::TC("libtests", "Pl_ASCIIHexDecoder no-op flush");  
83 - return; 82 + QTC::TC("libtests", "Pl_ASCIIHexDecoder no-op flush");
  83 + return;
84 } 84 }
85 int b[2]; 85 int b[2];
86 for (int i = 0; i < 2; ++i) 86 for (int i = 0; i < 2; ++i)
87 { 87 {
88 - if (this->inbuf[i] >= 'A')  
89 - {  
90 - b[i] = this->inbuf[i] - 'A' + 10;  
91 - }  
92 - else  
93 - {  
94 - b[i] = this->inbuf[i] - '0';  
95 - } 88 + if (this->inbuf[i] >= 'A')
  89 + {
  90 + b[i] = this->inbuf[i] - 'A' + 10;
  91 + }
  92 + else
  93 + {
  94 + b[i] = this->inbuf[i] - '0';
  95 + }
96 } 96 }
97 unsigned char ch = static_cast<unsigned char>((b[0] << 4) + b[1]); 97 unsigned char ch = static_cast<unsigned char>((b[0] << 4) + b[1]);
98 98
99 QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush", 99 QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush",
100 - (this->pos == 2) ? 0 : 1); 100 + (this->pos == 2) ? 0 : 1);
101 // Reset before calling getNext()->write in case that throws an 101 // Reset before calling getNext()->write in case that throws an
102 // exception. 102 // exception.
103 this->pos = 0; 103 this->pos = 0;
libqpdf/Pl_Buffer.cc
@@ -51,7 +51,7 @@ Pl_Buffer::write(unsigned char* buf, size_t len) @@ -51,7 +51,7 @@ Pl_Buffer::write(unsigned char* buf, size_t len)
51 51
52 if (getNext(true)) 52 if (getNext(true))
53 { 53 {
54 - getNext()->write(buf, len); 54 + getNext()->write(buf, len);
55 } 55 }
56 } 56 }
57 57
@@ -61,7 +61,7 @@ Pl_Buffer::finish() @@ -61,7 +61,7 @@ Pl_Buffer::finish()
61 this->m->ready = true; 61 this->m->ready = true;
62 if (getNext(true)) 62 if (getNext(true))
63 { 63 {
64 - getNext()->finish(); 64 + getNext()->finish();
65 } 65 }
66 } 66 }
67 67
@@ -70,7 +70,7 @@ Pl_Buffer::getBuffer() @@ -70,7 +70,7 @@ Pl_Buffer::getBuffer()
70 { 70 {
71 if (! this->m->ready) 71 if (! this->m->ready)
72 { 72 {
73 - throw std::logic_error("Pl_Buffer::getBuffer() called when not ready"); 73 + throw std::logic_error("Pl_Buffer::getBuffer() called when not ready");
74 } 74 }
75 75
76 Buffer* b = new Buffer(this->m->total_size); 76 Buffer* b = new Buffer(this->m->total_size);
@@ -94,7 +94,7 @@ Pl_Buffer::getMallocBuffer(unsigned char **buf, size_t* len) @@ -94,7 +94,7 @@ Pl_Buffer::getMallocBuffer(unsigned char **buf, size_t* len)
94 { 94 {
95 if (! this->m->ready) 95 if (! this->m->ready)
96 { 96 {
97 - throw std::logic_error( 97 + throw std::logic_error(
98 "Pl_Buffer::getMallocBuffer() called when not ready"); 98 "Pl_Buffer::getMallocBuffer() called when not ready");
99 } 99 }
100 100
libqpdf/Pl_Count.cc
@@ -27,9 +27,9 @@ Pl_Count::write(unsigned char* buf, size_t len) @@ -27,9 +27,9 @@ Pl_Count::write(unsigned char* buf, size_t len)
27 { 27 {
28 if (len) 28 if (len)
29 { 29 {
30 - this->m->count += QIntC::to_offset(len);  
31 - this->m->last_char = buf[len - 1];  
32 - getNext()->write(buf, len); 30 + this->m->count += QIntC::to_offset(len);
  31 + this->m->last_char = buf[len - 1];
  32 + getNext()->write(buf, len);
33 } 33 }
34 } 34 }
35 35
libqpdf/Pl_Flate.cc
@@ -61,7 +61,7 @@ Pl_Flate::Members::~Members() @@ -61,7 +61,7 @@ Pl_Flate::Members::~Members()
61 } 61 }
62 62
63 Pl_Flate::Pl_Flate(char const* identifier, Pipeline* next, 63 Pl_Flate::Pl_Flate(char const* identifier, Pipeline* next,
64 - action_e action, unsigned int out_bufsize_int) : 64 + action_e action, unsigned int out_bufsize_int) :
65 Pipeline(identifier, next), 65 Pipeline(identifier, next),
66 m(new Members(QIntC::to_size(out_bufsize_int), action)) 66 m(new Members(QIntC::to_size(out_bufsize_int), action))
67 { 67 {
@@ -91,9 +91,9 @@ Pl_Flate::write(unsigned char* data, size_t len) @@ -91,9 +91,9 @@ Pl_Flate::write(unsigned char* data, size_t len)
91 { 91 {
92 if (this->m->outbuf.get() == 0) 92 if (this->m->outbuf.get() == 0)
93 { 93 {
94 - throw std::logic_error(  
95 - this->identifier +  
96 - ": Pl_Flate: write() called after finish() called"); 94 + throw std::logic_error(
  95 + this->identifier +
  96 + ": Pl_Flate: write() called after finish() called");
97 } 97 }
98 98
99 // Write in chunks in case len is too big to fit in an int. 99 // Write in chunks in case len is too big to fit in an int.
@@ -103,10 +103,10 @@ Pl_Flate::write(unsigned char* data, size_t len) @@ -103,10 +103,10 @@ Pl_Flate::write(unsigned char* data, size_t len)
103 unsigned char* buf = data; 103 unsigned char* buf = data;
104 while (bytes_left > 0) 104 while (bytes_left > 0)
105 { 105 {
106 - size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); 106 + size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left);
107 handleData(buf, bytes, 107 handleData(buf, bytes,
108 (this->m->action == a_inflate ? Z_SYNC_FLUSH : Z_NO_FLUSH)); 108 (this->m->action == a_inflate ? Z_SYNC_FLUSH : Z_NO_FLUSH));
109 - bytes_left -= bytes; 109 + bytes_left -= bytes;
110 buf += bytes; 110 buf += bytes;
111 } 111 }
112 } 112 }
@@ -126,7 +126,7 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush) @@ -126,7 +126,7 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush)
126 126
127 if (! this->m->initialized) 127 if (! this->m->initialized)
128 { 128 {
129 - int err = Z_OK; 129 + int err = Z_OK;
130 130
131 // deflateInit and inflateInit are macros that use old-style 131 // deflateInit and inflateInit are macros that use old-style
132 // casts. 132 // casts.
@@ -135,21 +135,21 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush) @@ -135,21 +135,21 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush)
135 # pragma GCC diagnostic push 135 # pragma GCC diagnostic push
136 # pragma GCC diagnostic ignored "-Wold-style-cast" 136 # pragma GCC diagnostic ignored "-Wold-style-cast"
137 #endif 137 #endif
138 - if (this->m->action == a_deflate)  
139 - {  
140 - err = deflateInit(&zstream, compression_level);  
141 - }  
142 - else  
143 - {  
144 - err = inflateInit(&zstream);  
145 - } 138 + if (this->m->action == a_deflate)
  139 + {
  140 + err = deflateInit(&zstream, compression_level);
  141 + }
  142 + else
  143 + {
  144 + err = inflateInit(&zstream);
  145 + }
146 #if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \ 146 #if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \
147 defined(__clang__)) 147 defined(__clang__))
148 # pragma GCC diagnostic pop 148 # pragma GCC diagnostic pop
149 #endif 149 #endif
150 150
151 - checkError("Init", err);  
152 - this->m->initialized = true; 151 + checkError("Init", err);
  152 + this->m->initialized = true;
153 } 153 }
154 154
155 int err = Z_OK; 155 int err = Z_OK;
@@ -157,14 +157,14 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush) @@ -157,14 +157,14 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush)
157 bool done = false; 157 bool done = false;
158 while (! done) 158 while (! done)
159 { 159 {
160 - if (this->m->action == a_deflate)  
161 - {  
162 - err = deflate(&zstream, flush);  
163 - }  
164 - else  
165 - {  
166 - err = inflate(&zstream, flush);  
167 - } 160 + if (this->m->action == a_deflate)
  161 + {
  162 + err = deflate(&zstream, flush);
  163 + }
  164 + else
  165 + {
  166 + err = inflate(&zstream, flush);
  167 + }
168 if ((this->m->action == a_inflate) && (err != Z_OK) && zstream.msg && 168 if ((this->m->action == a_inflate) && (err != Z_OK) && zstream.msg &&
169 (strcmp(zstream.msg, "incorrect data check") == 0)) 169 (strcmp(zstream.msg, "incorrect data check") == 0))
170 { 170 {
@@ -173,52 +173,52 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush) @@ -173,52 +173,52 @@ Pl_Flate::handleData(unsigned char* data, size_t len, int flush)
173 // broken zlib streams without losing data. 173 // broken zlib streams without losing data.
174 err = Z_STREAM_END; 174 err = Z_STREAM_END;
175 } 175 }
176 - switch (err)  
177 - {  
178 - case Z_BUF_ERROR:  
179 - // Probably shouldn't be able to happen, but possible as a  
180 - // boundary condition: if the last call to inflate exactly  
181 - // filled the output buffer, it's possible that the next  
182 - // call to inflate could have nothing to do. There are PDF  
183 - // files in the wild that have this error (including at  
184 - // least one in qpdf's test suite). In some cases, we want  
185 - // to know about this, because it indicates incorrect  
186 - // compression, so call a callback if provided. 176 + switch (err)
  177 + {
  178 + case Z_BUF_ERROR:
  179 + // Probably shouldn't be able to happen, but possible as a
  180 + // boundary condition: if the last call to inflate exactly
  181 + // filled the output buffer, it's possible that the next
  182 + // call to inflate could have nothing to do. There are PDF
  183 + // files in the wild that have this error (including at
  184 + // least one in qpdf's test suite). In some cases, we want
  185 + // to know about this, because it indicates incorrect
  186 + // compression, so call a callback if provided.
187 this->warn( 187 this->warn(
188 "input stream is complete but output may still be valid", 188 "input stream is complete but output may still be valid",
189 err); 189 err);
190 - done = true;  
191 - break;  
192 -  
193 - case Z_STREAM_END:  
194 - done = true;  
195 - // fall through  
196 -  
197 - case Z_OK:  
198 - {  
199 - if ((zstream.avail_in == 0) &&  
200 - (zstream.avail_out > 0))  
201 - {  
202 - // There is nothing left to read, and there was  
203 - // sufficient buffer space to write everything we  
204 - // needed, so we're done for now.  
205 - done = true;  
206 - }  
207 - uLong ready = 190 + done = true;
  191 + break;
  192 +
  193 + case Z_STREAM_END:
  194 + done = true;
  195 + // fall through
  196 +
  197 + case Z_OK:
  198 + {
  199 + if ((zstream.avail_in == 0) &&
  200 + (zstream.avail_out > 0))
  201 + {
  202 + // There is nothing left to read, and there was
  203 + // sufficient buffer space to write everything we
  204 + // needed, so we're done for now.
  205 + done = true;
  206 + }
  207 + uLong ready =
208 QIntC::to_ulong(this->m->out_bufsize - zstream.avail_out); 208 QIntC::to_ulong(this->m->out_bufsize - zstream.avail_out);
209 - if (ready > 0)  
210 - {  
211 - this->getNext()->write(this->m->outbuf.get(), ready);  
212 - zstream.next_out = this->m->outbuf.get();  
213 - zstream.avail_out = QIntC::to_uint(this->m->out_bufsize);  
214 - }  
215 - }  
216 - break;  
217 -  
218 - default:  
219 - this->checkError("data", err);  
220 - break;  
221 - } 209 + if (ready > 0)
  210 + {
  211 + this->getNext()->write(this->m->outbuf.get(), ready);
  212 + zstream.next_out = this->m->outbuf.get();
  213 + zstream.avail_out = QIntC::to_uint(this->m->out_bufsize);
  214 + }
  215 + }
  216 + break;
  217 +
  218 + default:
  219 + this->checkError("data", err);
  220 + break;
  221 + }
222 } 222 }
223 } 223 }
224 224
@@ -278,50 +278,50 @@ Pl_Flate::checkError(char const* prefix, int error_code) @@ -278,50 +278,50 @@ Pl_Flate::checkError(char const* prefix, int error_code)
278 z_stream& zstream = *(static_cast<z_stream*>(this->m->zdata)); 278 z_stream& zstream = *(static_cast<z_stream*>(this->m->zdata));
279 if (error_code != Z_OK) 279 if (error_code != Z_OK)
280 { 280 {
281 - char const* action_str = 281 + char const* action_str =
282 (this->m->action == a_deflate ? "deflate" : "inflate"); 282 (this->m->action == a_deflate ? "deflate" : "inflate");
283 - std::string msg =  
284 - this->identifier + ": " + action_str + ": " + prefix + ": ";  
285 -  
286 - if (zstream.msg)  
287 - {  
288 - msg += zstream.msg;  
289 - }  
290 - else  
291 - {  
292 - switch (error_code)  
293 - {  
294 - case Z_ERRNO:  
295 - msg += "zlib system error";  
296 - break;  
297 -  
298 - case Z_STREAM_ERROR:  
299 - msg += "zlib stream error";  
300 - break;  
301 -  
302 - case Z_DATA_ERROR:  
303 - msg += "zlib data error";  
304 - break;  
305 -  
306 - case Z_MEM_ERROR:  
307 - msg += "zlib memory error";  
308 - break;  
309 -  
310 - case Z_BUF_ERROR:  
311 - msg += "zlib buffer error";  
312 - break;  
313 -  
314 - case Z_VERSION_ERROR:  
315 - msg += "zlib version error";  
316 - break;  
317 -  
318 - default:  
319 - msg += std::string("zlib unknown error (") +  
320 - QUtil::int_to_string(error_code) + ")";  
321 - break;  
322 - }  
323 - }  
324 -  
325 - throw std::runtime_error(msg); 283 + std::string msg =
  284 + this->identifier + ": " + action_str + ": " + prefix + ": ";
  285 +
  286 + if (zstream.msg)
  287 + {
  288 + msg += zstream.msg;
  289 + }
  290 + else
  291 + {
  292 + switch (error_code)
  293 + {
  294 + case Z_ERRNO:
  295 + msg += "zlib system error";
  296 + break;
  297 +
  298 + case Z_STREAM_ERROR:
  299 + msg += "zlib stream error";
  300 + break;
  301 +
  302 + case Z_DATA_ERROR:
  303 + msg += "zlib data error";
  304 + break;
  305 +
  306 + case Z_MEM_ERROR:
  307 + msg += "zlib memory error";
  308 + break;
  309 +
  310 + case Z_BUF_ERROR:
  311 + msg += "zlib buffer error";
  312 + break;
  313 +
  314 + case Z_VERSION_ERROR:
  315 + msg += "zlib version error";
  316 + break;
  317 +
  318 + default:
  319 + msg += std::string("zlib unknown error (") +
  320 + QUtil::int_to_string(error_code) + ")";
  321 + break;
  322 + }
  323 + }
  324 +
  325 + throw std::runtime_error(msg);
326 } 326 }
327 } 327 }
libqpdf/Pl_LZWDecoder.cc
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 #include <assert.h> 8 #include <assert.h>
9 9
10 Pl_LZWDecoder::Pl_LZWDecoder(char const* identifier, Pipeline* next, 10 Pl_LZWDecoder::Pl_LZWDecoder(char const* identifier, Pipeline* next,
11 - bool early_code_change) : 11 + bool early_code_change) :
12 Pipeline(identifier, next), 12 Pipeline(identifier, next),
13 code_size(9), 13 code_size(9),
14 next(0), 14 next(0),
@@ -31,16 +31,16 @@ Pl_LZWDecoder::write(unsigned char* bytes, size_t len) @@ -31,16 +31,16 @@ Pl_LZWDecoder::write(unsigned char* bytes, size_t len)
31 { 31 {
32 for (size_t i = 0; i < len; ++i) 32 for (size_t i = 0; i < len; ++i)
33 { 33 {
34 - this->buf[next++] = bytes[i];  
35 - if (this->next == 3)  
36 - {  
37 - this->next = 0;  
38 - }  
39 - this->bits_available += 8;  
40 - if (this->bits_available >= this->code_size)  
41 - {  
42 - sendNextCode();  
43 - } 34 + this->buf[next++] = bytes[i];
  35 + if (this->next == 3)
  36 + {
  37 + this->next = 0;
  38 + }
  39 + this->bits_available += 8;
  40 + if (this->bits_available >= this->code_size)
  41 + {
  42 + sendNextCode();
  43 + }
44 } 44 }
45 } 45 }
46 46
@@ -62,8 +62,8 @@ Pl_LZWDecoder::sendNextCode() @@ -62,8 +62,8 @@ Pl_LZWDecoder::sendNextCode()
62 unsigned int bits_from_low = 0; 62 unsigned int bits_from_low = 0;
63 if (bits_from_med > 8) 63 if (bits_from_med > 8)
64 { 64 {
65 - bits_from_low = bits_from_med - 8;  
66 - bits_from_med = 8; 65 + bits_from_low = bits_from_med - 8;
  66 + bits_from_med = 8;
67 } 67 }
68 unsigned int high_mask = (1U << bits_from_high) - 1U; 68 unsigned int high_mask = (1U << bits_from_high) - 1U;
69 unsigned int med_mask = 0xff - ((1U << (8 - bits_from_med)) - 1U); 69 unsigned int med_mask = 0xff - ((1U << (8 - bits_from_med)) - 1U);
@@ -73,21 +73,21 @@ Pl_LZWDecoder::sendNextCode() @@ -73,21 +73,21 @@ Pl_LZWDecoder::sendNextCode()
73 code += ((this->buf[med] & med_mask) >> (8 - bits_from_med)); 73 code += ((this->buf[med] & med_mask) >> (8 - bits_from_med));
74 if (bits_from_low) 74 if (bits_from_low)
75 { 75 {
76 - code <<= bits_from_low;  
77 - code += ((this->buf[low] & low_mask) >> (8 - bits_from_low));  
78 - this->byte_pos = low;  
79 - this->bit_pos = bits_from_low; 76 + code <<= bits_from_low;
  77 + code += ((this->buf[low] & low_mask) >> (8 - bits_from_low));
  78 + this->byte_pos = low;
  79 + this->bit_pos = bits_from_low;
80 } 80 }
81 else 81 else
82 { 82 {
83 - this->byte_pos = med;  
84 - this->bit_pos = bits_from_med; 83 + this->byte_pos = med;
  84 + this->bit_pos = bits_from_med;
85 } 85 }
86 if (this->bit_pos == 8) 86 if (this->bit_pos == 8)
87 { 87 {
88 - this->bit_pos = 0;  
89 - ++this->byte_pos;  
90 - this->byte_pos %= 3; 88 + this->bit_pos = 0;
  89 + ++this->byte_pos;
  90 + this->byte_pos %= 3;
91 } 91 }
92 this->bits_available -= this->code_size; 92 this->bits_available -= this->code_size;
93 93
@@ -100,18 +100,18 @@ Pl_LZWDecoder::getFirstChar(unsigned int code) @@ -100,18 +100,18 @@ Pl_LZWDecoder::getFirstChar(unsigned int code)
100 unsigned char result = '\0'; 100 unsigned char result = '\0';
101 if (code < 256) 101 if (code < 256)
102 { 102 {
103 - result = static_cast<unsigned char>(code); 103 + result = static_cast<unsigned char>(code);
104 } 104 }
105 else if (code > 257) 105 else if (code > 257)
106 { 106 {
107 - unsigned int idx = code - 258;  
108 - if (idx >= table.size()) 107 + unsigned int idx = code - 258;
  108 + if (idx >= table.size())
109 { 109 {
110 throw std::runtime_error( 110 throw std::runtime_error(
111 "Pl_LZWDecoder::getFirstChar: table overflow"); 111 "Pl_LZWDecoder::getFirstChar: table overflow");
112 } 112 }
113 - Buffer& b = table.at(idx);  
114 - result = b.getBuffer()[0]; 113 + Buffer& b = table.at(idx);
  114 + result = b.getBuffer()[0];
115 } 115 }
116 else 116 else
117 { 117 {
@@ -131,21 +131,21 @@ Pl_LZWDecoder::addToTable(unsigned char next) @@ -131,21 +131,21 @@ Pl_LZWDecoder::addToTable(unsigned char next)
131 131
132 if (this->last_code < 256) 132 if (this->last_code < 256)
133 { 133 {
134 - tmp[0] = static_cast<unsigned char>(this->last_code);  
135 - last_data = tmp;  
136 - last_size = 1; 134 + tmp[0] = static_cast<unsigned char>(this->last_code);
  135 + last_data = tmp;
  136 + last_size = 1;
137 } 137 }
138 else if (this->last_code > 257) 138 else if (this->last_code > 257)
139 { 139 {
140 - unsigned int idx = this->last_code - 258;  
141 - if (idx >= table.size()) 140 + unsigned int idx = this->last_code - 258;
  141 + if (idx >= table.size())
142 { 142 {
143 throw std::runtime_error( 143 throw std::runtime_error(
144 "Pl_LZWDecoder::addToTable: table overflow"); 144 "Pl_LZWDecoder::addToTable: table overflow");
145 } 145 }
146 - Buffer& b = table.at(idx);  
147 - last_data = b.getBuffer();  
148 - last_size = QIntC::to_uint(b.getSize()); 146 + Buffer& b = table.at(idx);
  147 + last_data = b.getBuffer();
  148 + last_size = QIntC::to_uint(b.getSize());
149 } 149 }
150 else 150 else
151 { 151 {
@@ -166,88 +166,88 @@ Pl_LZWDecoder::handleCode(unsigned int code) @@ -166,88 +166,88 @@ Pl_LZWDecoder::handleCode(unsigned int code)
166 { 166 {
167 if (this->eod) 167 if (this->eod)
168 { 168 {
169 - return; 169 + return;
170 } 170 }
171 171
172 if (code == 256) 172 if (code == 256)
173 { 173 {
174 - if (! this->table.empty())  
175 - {  
176 - QTC::TC("libtests", "Pl_LZWDecoder intermediate reset");  
177 - }  
178 - this->table.clear();  
179 - this->code_size = 9; 174 + if (! this->table.empty())
  175 + {
  176 + QTC::TC("libtests", "Pl_LZWDecoder intermediate reset");
  177 + }
  178 + this->table.clear();
  179 + this->code_size = 9;
180 } 180 }
181 else if (code == 257) 181 else if (code == 257)
182 { 182 {
183 - this->eod = true; 183 + this->eod = true;
184 } 184 }
185 else 185 else
186 { 186 {
187 - if (this->last_code != 256)  
188 - {  
189 - // Add to the table from last time. New table entry would  
190 - // be what we read last plus the first character of what  
191 - // we're reading now.  
192 - unsigned char next = '\0';  
193 - unsigned int table_size = QIntC::to_uint(table.size());  
194 - if (code < 256)  
195 - {  
196 - // just read < 256; last time's next was code  
197 - next = static_cast<unsigned char>(code);  
198 - }  
199 - else if (code > 257)  
200 - {  
201 - size_t idx = code - 258;  
202 - if (idx > table_size)  
203 - {  
204 - throw std::runtime_error("LZWDecoder: bad code received");  
205 - }  
206 - else if (idx == table_size)  
207 - {  
208 - // The encoder would have just created this entry,  
209 - // so the first character of this entry would have  
210 - // been the same as the first character of the  
211 - // last entry.  
212 - QTC::TC("libtests", "Pl_LZWDecoder last was table size");  
213 - next = getFirstChar(this->last_code);  
214 - }  
215 - else  
216 - {  
217 - next = getFirstChar(code);  
218 - }  
219 - }  
220 - unsigned int new_idx = 258 + table_size;  
221 - if (new_idx == 4096)  
222 - {  
223 - throw std::runtime_error("LZWDecoder: table full");  
224 - }  
225 - addToTable(next);  
226 - unsigned int change_idx = new_idx + code_change_delta;  
227 - if ((change_idx == 511) ||  
228 - (change_idx == 1023) ||  
229 - (change_idx == 2047))  
230 - {  
231 - ++this->code_size;  
232 - }  
233 - }  
234 -  
235 - if (code < 256)  
236 - {  
237 - unsigned char ch = static_cast<unsigned char>(code);  
238 - getNext()->write(&ch, 1);  
239 - }  
240 - else  
241 - { 187 + if (this->last_code != 256)
  188 + {
  189 + // Add to the table from last time. New table entry would
  190 + // be what we read last plus the first character of what
  191 + // we're reading now.
  192 + unsigned char next = '\0';
  193 + unsigned int table_size = QIntC::to_uint(table.size());
  194 + if (code < 256)
  195 + {
  196 + // just read < 256; last time's next was code
  197 + next = static_cast<unsigned char>(code);
  198 + }
  199 + else if (code > 257)
  200 + {
  201 + size_t idx = code - 258;
  202 + if (idx > table_size)
  203 + {
  204 + throw std::runtime_error("LZWDecoder: bad code received");
  205 + }
  206 + else if (idx == table_size)
  207 + {
  208 + // The encoder would have just created this entry,
  209 + // so the first character of this entry would have
  210 + // been the same as the first character of the
  211 + // last entry.
  212 + QTC::TC("libtests", "Pl_LZWDecoder last was table size");
  213 + next = getFirstChar(this->last_code);
  214 + }
  215 + else
  216 + {
  217 + next = getFirstChar(code);
  218 + }
  219 + }
  220 + unsigned int new_idx = 258 + table_size;
  221 + if (new_idx == 4096)
  222 + {
  223 + throw std::runtime_error("LZWDecoder: table full");
  224 + }
  225 + addToTable(next);
  226 + unsigned int change_idx = new_idx + code_change_delta;
  227 + if ((change_idx == 511) ||
  228 + (change_idx == 1023) ||
  229 + (change_idx == 2047))
  230 + {
  231 + ++this->code_size;
  232 + }
  233 + }
  234 +
  235 + if (code < 256)
  236 + {
  237 + unsigned char ch = static_cast<unsigned char>(code);
  238 + getNext()->write(&ch, 1);
  239 + }
  240 + else
  241 + {
242 unsigned int idx = code - 258; 242 unsigned int idx = code - 258;
243 if (idx >= table.size()) 243 if (idx >= table.size())
244 { 244 {
245 throw std::runtime_error( 245 throw std::runtime_error(
246 "Pl_LZWDecoder::handleCode: table overflow"); 246 "Pl_LZWDecoder::handleCode: table overflow");
247 } 247 }
248 - Buffer& b = table.at(idx);  
249 - getNext()->write(b.getBuffer(), b.getSize());  
250 - } 248 + Buffer& b = table.at(idx);
  249 + getNext()->write(b.getBuffer(), b.getSize());
  250 + }
251 } 251 }
252 252
253 this->last_code = code; 253 this->last_code = code;
libqpdf/Pl_MD5.cc
@@ -70,8 +70,8 @@ Pl_MD5::getHexDigest() @@ -70,8 +70,8 @@ Pl_MD5::getHexDigest()
70 { 70 {
71 if (! this->enabled) 71 if (! this->enabled)
72 { 72 {
73 - throw std::logic_error(  
74 - "digest requested for a disabled MD5 Pipeline"); 73 + throw std::logic_error(
  74 + "digest requested for a disabled MD5 Pipeline");
75 } 75 }
76 this->in_progress = false; 76 this->in_progress = false;
77 return this->md5.unparse(); 77 return this->md5.unparse();
libqpdf/Pl_PNGFilter.cc
@@ -13,7 +13,7 @@ static int abs_diff(int a, int b) @@ -13,7 +13,7 @@ static int abs_diff(int a, int b)
13 } 13 }
14 14
15 Pl_PNGFilter::Pl_PNGFilter(char const* identifier, Pipeline* next, 15 Pl_PNGFilter::Pl_PNGFilter(char const* identifier, Pipeline* next,
16 - action_e action, unsigned int columns, 16 + action_e action, unsigned int columns,
17 unsigned int samples_per_pixel, 17 unsigned int samples_per_pixel,
18 unsigned int bits_per_sample) : 18 unsigned int bits_per_sample) :
19 Pipeline(identifier, next), 19 Pipeline(identifier, next),
@@ -74,24 +74,24 @@ Pl_PNGFilter::write(unsigned char* data, size_t len) @@ -74,24 +74,24 @@ Pl_PNGFilter::write(unsigned char* data, size_t len)
74 size_t offset = 0; 74 size_t offset = 0;
75 while (len >= left) 75 while (len >= left)
76 { 76 {
77 - // finish off current row  
78 - memcpy(this->cur_row + this->pos, data + offset, left);  
79 - offset += left;  
80 - len -= left; 77 + // finish off current row
  78 + memcpy(this->cur_row + this->pos, data + offset, left);
  79 + offset += left;
  80 + len -= left;
81 81
82 - processRow(); 82 + processRow();
83 83
84 - // Swap rows  
85 - unsigned char* t = this->prev_row;  
86 - this->prev_row = this->cur_row;  
87 - this->cur_row = t ? t : this->buf2.get();  
88 - memset(this->cur_row, 0, this->bytes_per_row + 1);  
89 - left = this->incoming;  
90 - this->pos = 0; 84 + // Swap rows
  85 + unsigned char* t = this->prev_row;
  86 + this->prev_row = this->cur_row;
  87 + this->cur_row = t ? t : this->buf2.get();
  88 + memset(this->cur_row, 0, this->bytes_per_row + 1);
  89 + left = this->incoming;
  90 + this->pos = 0;
91 } 91 }
92 if (len) 92 if (len)
93 { 93 {
94 - memcpy(this->cur_row + this->pos, data + offset, len); 94 + memcpy(this->cur_row + this->pos, data + offset, len);
95 } 95 }
96 this->pos += len; 96 this->pos += len;
97 } 97 }
@@ -101,11 +101,11 @@ Pl_PNGFilter::processRow() @@ -101,11 +101,11 @@ Pl_PNGFilter::processRow()
101 { 101 {
102 if (this->action == a_encode) 102 if (this->action == a_encode)
103 { 103 {
104 - encodeRow(); 104 + encodeRow();
105 } 105 }
106 else 106 else
107 { 107 {
108 - decodeRow(); 108 + decodeRow();
109 } 109 }
110 } 110 }
111 111
@@ -250,16 +250,16 @@ Pl_PNGFilter::encodeRow() @@ -250,16 +250,16 @@ Pl_PNGFilter::encodeRow()
250 getNext()->write(&ch, 1); 250 getNext()->write(&ch, 1);
251 if (this->prev_row) 251 if (this->prev_row)
252 { 252 {
253 - for (unsigned int i = 0; i < this->bytes_per_row; ++i)  
254 - {  
255 - ch = static_cast<unsigned char>( 253 + for (unsigned int i = 0; i < this->bytes_per_row; ++i)
  254 + {
  255 + ch = static_cast<unsigned char>(
256 this->cur_row[i] - this->prev_row[i]); 256 this->cur_row[i] - this->prev_row[i]);
257 - getNext()->write(&ch, 1);  
258 - } 257 + getNext()->write(&ch, 1);
  258 + }
259 } 259 }
260 else 260 else
261 { 261 {
262 - getNext()->write(this->cur_row, this->bytes_per_row); 262 + getNext()->write(this->cur_row, this->bytes_per_row);
263 } 263 }
264 } 264 }
265 265
@@ -268,8 +268,8 @@ Pl_PNGFilter::finish() @@ -268,8 +268,8 @@ Pl_PNGFilter::finish()
268 { 268 {
269 if (this->pos) 269 if (this->pos)
270 { 270 {
271 - // write partial row  
272 - processRow(); 271 + // write partial row
  272 + processRow();
273 } 273 }
274 this->prev_row = 0; 274 this->prev_row = 0;
275 this->cur_row = buf1.get(); 275 this->cur_row = buf1.get();
libqpdf/Pl_QPDFTokenizer.cc
@@ -52,7 +52,7 @@ Pl_QPDFTokenizer::finish() @@ -52,7 +52,7 @@ Pl_QPDFTokenizer::finish()
52 QPDFTokenizer::Token token = this->m->tokenizer.readToken( 52 QPDFTokenizer::Token token = this->m->tokenizer.readToken(
53 input, "offset " + QUtil::int_to_string(input->tell()), 53 input, "offset " + QUtil::int_to_string(input->tell()),
54 true); 54 true);
55 - this->m->filter->handleToken(token); 55 + this->m->filter->handleToken(token);
56 if (token.getType() == QPDFTokenizer::tt_eof) 56 if (token.getType() == QPDFTokenizer::tt_eof)
57 { 57 {
58 break; 58 break;
libqpdf/Pl_RC4.cc
@@ -3,8 +3,8 @@ @@ -3,8 +3,8 @@
3 #include <qpdf/QUtil.hh> 3 #include <qpdf/QUtil.hh>
4 4
5 Pl_RC4::Pl_RC4(char const* identifier, Pipeline* next, 5 Pl_RC4::Pl_RC4(char const* identifier, Pipeline* next,
6 - unsigned char const* key_data, int key_len,  
7 - size_t out_bufsize) : 6 + unsigned char const* key_data, int key_len,
  7 + size_t out_bufsize) :
8 Pipeline(identifier, next), 8 Pipeline(identifier, next),
9 out_bufsize(out_bufsize), 9 out_bufsize(out_bufsize),
10 rc4(key_data, key_len) 10 rc4(key_data, key_len)
@@ -21,9 +21,9 @@ Pl_RC4::write(unsigned char* data, size_t len) @@ -21,9 +21,9 @@ Pl_RC4::write(unsigned char* data, size_t len)
21 { 21 {
22 if (this->outbuf.get() == 0) 22 if (this->outbuf.get() == 0)
23 { 23 {
24 - throw std::logic_error(  
25 - this->identifier +  
26 - ": Pl_RC4: write() called after finish() called"); 24 + throw std::logic_error(
  25 + this->identifier +
  26 + ": Pl_RC4: write() called after finish() called");
27 } 27 }
28 28
29 size_t bytes_left = len; 29 size_t bytes_left = len;
@@ -31,13 +31,13 @@ Pl_RC4::write(unsigned char* data, size_t len) @@ -31,13 +31,13 @@ Pl_RC4::write(unsigned char* data, size_t len)
31 31
32 while (bytes_left > 0) 32 while (bytes_left > 0)
33 { 33 {
34 - size_t bytes = 34 + size_t bytes =
35 (bytes_left < this->out_bufsize ? bytes_left : out_bufsize); 35 (bytes_left < this->out_bufsize ? bytes_left : out_bufsize);
36 - bytes_left -= bytes; 36 + bytes_left -= bytes;
37 // lgtm[cpp/weak-cryptographic-algorithm] 37 // lgtm[cpp/weak-cryptographic-algorithm]
38 - rc4.process(p, bytes, outbuf.get());  
39 - p += bytes;  
40 - getNext()->write(outbuf.get(), bytes); 38 + rc4.process(p, bytes, outbuf.get());
  39 + p += bytes;
  40 + getNext()->write(outbuf.get(), bytes);
41 } 41 }
42 } 42 }
43 43
libqpdf/Pl_SHA2.cc
@@ -25,7 +25,7 @@ Pl_SHA2::write(unsigned char* buf, size_t len) @@ -25,7 +25,7 @@ Pl_SHA2::write(unsigned char* buf, size_t len)
25 { 25 {
26 if (! this->in_progress) 26 if (! this->in_progress)
27 { 27 {
28 - this->in_progress = true; 28 + this->in_progress = true;
29 } 29 }
30 30
31 // Write in chunks in case len is too big to fit in an int. 31 // Write in chunks in case len is too big to fit in an int.
@@ -35,9 +35,9 @@ Pl_SHA2::write(unsigned char* buf, size_t len) @@ -35,9 +35,9 @@ Pl_SHA2::write(unsigned char* buf, size_t len)
35 unsigned char* data = buf; 35 unsigned char* data = buf;
36 while (bytes_left > 0) 36 while (bytes_left > 0)
37 { 37 {
38 - size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); 38 + size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left);
39 this->crypto->SHA2_update(data, bytes); 39 this->crypto->SHA2_update(data, bytes);
40 - bytes_left -= bytes; 40 + bytes_left -= bytes;
41 data += bytes; 41 data += bytes;
42 } 42 }
43 43
@@ -63,8 +63,8 @@ Pl_SHA2::resetBits(int bits) @@ -63,8 +63,8 @@ Pl_SHA2::resetBits(int bits)
63 { 63 {
64 if (this->in_progress) 64 if (this->in_progress)
65 { 65 {
66 - throw std::logic_error(  
67 - "bit reset requested for in-progress SHA2 Pipeline"); 66 + throw std::logic_error(
  67 + "bit reset requested for in-progress SHA2 Pipeline");
68 } 68 }
69 this->crypto = QPDFCryptoProvider::getImpl(); 69 this->crypto = QPDFCryptoProvider::getImpl();
70 this->crypto->SHA2_init(bits); 70 this->crypto->SHA2_init(bits);
@@ -75,8 +75,8 @@ Pl_SHA2::getRawDigest() @@ -75,8 +75,8 @@ Pl_SHA2::getRawDigest()
75 { 75 {
76 if (this->in_progress) 76 if (this->in_progress)
77 { 77 {
78 - throw std::logic_error(  
79 - "digest requested for in-progress SHA2 Pipeline"); 78 + throw std::logic_error(
  79 + "digest requested for in-progress SHA2 Pipeline");
80 } 80 }
81 return this->crypto->SHA2_digest(); 81 return this->crypto->SHA2_digest();
82 } 82 }
@@ -86,8 +86,8 @@ Pl_SHA2::getHexDigest() @@ -86,8 +86,8 @@ Pl_SHA2::getHexDigest()
86 { 86 {
87 if (this->in_progress) 87 if (this->in_progress)
88 { 88 {
89 - throw std::logic_error(  
90 - "digest requested for in-progress SHA2 Pipeline"); 89 + throw std::logic_error(
  90 + "digest requested for in-progress SHA2 Pipeline");
91 } 91 }
92 return QUtil::hex_encode(getRawDigest()); 92 return QUtil::hex_encode(getRawDigest());
93 } 93 }
libqpdf/Pl_StdioFile.cc
@@ -31,17 +31,17 @@ Pl_StdioFile::write(unsigned char* buf, size_t len) @@ -31,17 +31,17 @@ Pl_StdioFile::write(unsigned char* buf, size_t len)
31 size_t so_far = 0; 31 size_t so_far = 0;
32 while (len > 0) 32 while (len > 0)
33 { 33 {
34 - so_far = fwrite(buf, 1, len, this->m->file);  
35 - if (so_far == 0)  
36 - {  
37 - QUtil::throw_system_error(  
38 - this->identifier + ": Pl_StdioFile::write");  
39 - }  
40 - else  
41 - {  
42 - buf += so_far;  
43 - len -= so_far;  
44 - } 34 + so_far = fwrite(buf, 1, len, this->m->file);
  35 + if (so_far == 0)
  36 + {
  37 + QUtil::throw_system_error(
  38 + this->identifier + ": Pl_StdioFile::write");
  39 + }
  40 + else
  41 + {
  42 + buf += so_far;
  43 + len -= so_far;
  44 + }
45 } 45 }
46 } 46 }
47 47
@@ -51,8 +51,8 @@ Pl_StdioFile::finish() @@ -51,8 +51,8 @@ Pl_StdioFile::finish()
51 if ((fflush(this->m->file) == -1) && 51 if ((fflush(this->m->file) == -1) &&
52 (errno == EBADF)) 52 (errno == EBADF))
53 { 53 {
54 - throw std::logic_error(  
55 - this->identifier +  
56 - ": Pl_StdioFile::finish: stream already closed"); 54 + throw std::logic_error(
  55 + this->identifier +
  56 + ": Pl_StdioFile::finish: stream already closed");
57 } 57 }
58 } 58 }
libqpdf/Pl_TIFFPredictor.cc
@@ -56,21 +56,21 @@ Pl_TIFFPredictor::write(unsigned char* data, size_t len) @@ -56,21 +56,21 @@ Pl_TIFFPredictor::write(unsigned char* data, size_t len)
56 size_t offset = 0; 56 size_t offset = 0;
57 while (len >= left) 57 while (len >= left)
58 { 58 {
59 - // finish off current row  
60 - memcpy(this->cur_row.get() + this->pos, data + offset, left);  
61 - offset += left;  
62 - len -= left; 59 + // finish off current row
  60 + memcpy(this->cur_row.get() + this->pos, data + offset, left);
  61 + offset += left;
  62 + len -= left;
63 63
64 - processRow(); 64 + processRow();
65 65
66 - // Prepare for next row  
67 - memset(this->cur_row.get(), 0, this->bytes_per_row);  
68 - left = this->bytes_per_row;  
69 - this->pos = 0; 66 + // Prepare for next row
  67 + memset(this->cur_row.get(), 0, this->bytes_per_row);
  68 + left = this->bytes_per_row;
  69 + this->pos = 0;
70 } 70 }
71 if (len) 71 if (len)
72 { 72 {
73 - memcpy(this->cur_row.get() + this->pos, data + offset, len); 73 + memcpy(this->cur_row.get() + this->pos, data + offset, len);
74 } 74 }
75 this->pos += len; 75 this->pos += len;
76 } 76 }
@@ -116,8 +116,8 @@ Pl_TIFFPredictor::finish() @@ -116,8 +116,8 @@ Pl_TIFFPredictor::finish()
116 { 116 {
117 if (this->pos) 117 if (this->pos)
118 { 118 {
119 - // write partial row  
120 - processRow(); 119 + // write partial row
  120 + processRow();
121 } 121 }
122 this->pos = 0; 122 this->pos = 0;
123 memset(this->cur_row.get(), 0, this->bytes_per_row); 123 memset(this->cur_row.get(), 0, this->bytes_per_row);
libqpdf/QPDF.cc
@@ -257,10 +257,10 @@ QPDF::~QPDF() @@ -257,10 +257,10 @@ QPDF::~QPDF()
257 this->m->xref_table.clear(); 257 this->m->xref_table.clear();
258 for (std::map<QPDFObjGen, ObjCache>::iterator iter = 258 for (std::map<QPDFObjGen, ObjCache>::iterator iter =
259 this->m->obj_cache.begin(); 259 this->m->obj_cache.begin();
260 - iter != this->m->obj_cache.end(); ++iter) 260 + iter != this->m->obj_cache.end(); ++iter)
261 { 261 {
262 - QPDFObject::ObjAccessor::releaseResolved(  
263 - (*iter).second.object.get()); 262 + QPDFObject::ObjAccessor::releaseResolved(
  263 + (*iter).second.object.get());
264 } 264 }
265 } 265 }
266 266
@@ -283,11 +283,11 @@ QPDF::processFile(char const* description, FILE* filep, @@ -283,11 +283,11 @@ QPDF::processFile(char const* description, FILE* filep,
283 283
284 void 284 void
285 QPDF::processMemoryFile(char const* description, 285 QPDF::processMemoryFile(char const* description,
286 - char const* buf, size_t length,  
287 - char const* password) 286 + char const* buf, size_t length,
  287 + char const* password)
288 { 288 {
289 processInputSource( 289 processInputSource(
290 - PointerHolder<InputSource>( 290 + PointerHolder<InputSource>(
291 new BufferInputSource( 291 new BufferInputSource(
292 description, 292 description,
293 new Buffer(QUtil::unsigned_char_pointer(buf), length), 293 new Buffer(QUtil::unsigned_char_pointer(buf), length),
@@ -455,15 +455,15 @@ QPDF::parse(char const* password) @@ -455,15 +455,15 @@ QPDF::parse(char const* password)
455 { 455 {
456 if (password) 456 if (password)
457 { 457 {
458 - this->m->encp->provided_password = password; 458 + this->m->encp->provided_password = password;
459 } 459 }
460 460
461 // Find the header anywhere in the first 1024 bytes of the file. 461 // Find the header anywhere in the first 1024 bytes of the file.
462 PatternFinder hf(*this, &QPDF::findHeader); 462 PatternFinder hf(*this, &QPDF::findHeader);
463 if (! this->m->file->findFirst("%PDF-", 0, 1024, hf)) 463 if (! this->m->file->findFirst("%PDF-", 0, 1024, hf))
464 { 464 {
465 - QTC::TC("qpdf", "QPDF not a pdf file");  
466 - warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), 465 + QTC::TC("qpdf", "QPDF not a pdf file");
  466 + warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
467 "", 0, "can't find PDF header")); 467 "", 0, "can't find PDF header"));
468 // QPDFWriter writes files that usually require at least 468 // QPDFWriter writes files that usually require at least
469 // version 1.2 for /FlateDecode 469 // version 1.2 for /FlateDecode
@@ -486,12 +486,12 @@ QPDF::parse(char const* password) @@ -486,12 +486,12 @@ QPDF::parse(char const* password)
486 486
487 try 487 try
488 { 488 {
489 - if (xref_offset == 0)  
490 - {  
491 - QTC::TC("qpdf", "QPDF can't find startxref");  
492 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), "", 0,  
493 - "can't find startxref");  
494 - } 489 + if (xref_offset == 0)
  490 + {
  491 + QTC::TC("qpdf", "QPDF can't find startxref");
  492 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), "", 0,
  493 + "can't find startxref");
  494 + }
495 try 495 try
496 { 496 {
497 read_xref(xref_offset); 497 read_xref(xref_offset);
@@ -502,22 +502,22 @@ QPDF::parse(char const* password) @@ -502,22 +502,22 @@ QPDF::parse(char const* password)
502 } 502 }
503 catch (std::exception& e) 503 catch (std::exception& e)
504 { 504 {
505 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), "", 0,  
506 - std::string("error reading xref: ") + e.what()); 505 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), "", 0,
  506 + std::string("error reading xref: ") + e.what());
507 507
508 } 508 }
509 } 509 }
510 catch (QPDFExc& e) 510 catch (QPDFExc& e)
511 { 511 {
512 - if (this->m->attempt_recovery)  
513 - {  
514 - reconstruct_xref(e);  
515 - QTC::TC("qpdf", "QPDF reconstructed xref table");  
516 - }  
517 - else  
518 - {  
519 - throw e;  
520 - } 512 + if (this->m->attempt_recovery)
  513 + {
  514 + reconstruct_xref(e);
  515 + QTC::TC("qpdf", "QPDF reconstructed xref table");
  516 + }
  517 + else
  518 + {
  519 + throw e;
  520 + }
521 } 521 }
522 522
523 initializeEncryption(); 523 initializeEncryption();
@@ -544,7 +544,7 @@ QPDF::warn(QPDFExc const&amp; e) @@ -544,7 +544,7 @@ QPDF::warn(QPDFExc const&amp; e)
544 this->m->warnings.push_back(e); 544 this->m->warnings.push_back(e);
545 if (! this->m->suppress_warnings) 545 if (! this->m->suppress_warnings)
546 { 546 {
547 - *this->m->err_stream 547 + *this->m->err_stream
548 << "WARNING: " 548 << "WARNING: "
549 << this->m->warnings.back().what() << std::endl; 549 << this->m->warnings.back().what() << std::endl;
550 } 550 }
@@ -555,7 +555,7 @@ QPDF::setTrailer(QPDFObjectHandle obj) @@ -555,7 +555,7 @@ QPDF::setTrailer(QPDFObjectHandle obj)
555 { 555 {
556 if (this->m->trailer.isInitialized()) 556 if (this->m->trailer.isInitialized())
557 { 557 {
558 - return; 558 + return;
559 } 559 }
560 this->m->trailer = obj; 560 this->m->trailer = obj;
561 } 561 }
@@ -574,26 +574,26 @@ QPDF::reconstruct_xref(QPDFExc&amp; e) @@ -574,26 +574,26 @@ QPDF::reconstruct_xref(QPDFExc&amp; e)
574 this->m->reconstructed_xref = true; 574 this->m->reconstructed_xref = true;
575 575
576 warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), "", 0, 576 warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), "", 0,
577 - "file is damaged")); 577 + "file is damaged"));
578 warn(e); 578 warn(e);
579 warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), "", 0, 579 warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), "", 0,
580 - "Attempting to reconstruct cross-reference table")); 580 + "Attempting to reconstruct cross-reference table"));
581 581
582 // Delete all references to type 1 (uncompressed) objects 582 // Delete all references to type 1 (uncompressed) objects
583 std::set<QPDFObjGen> to_delete; 583 std::set<QPDFObjGen> to_delete;
584 for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter = 584 for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter =
585 - this->m->xref_table.begin();  
586 - iter != this->m->xref_table.end(); ++iter) 585 + this->m->xref_table.begin();
  586 + iter != this->m->xref_table.end(); ++iter)
587 { 587 {
588 - if (((*iter).second).getType() == 1)  
589 - {  
590 - to_delete.insert((*iter).first);  
591 - } 588 + if (((*iter).second).getType() == 1)
  589 + {
  590 + to_delete.insert((*iter).first);
  591 + }
592 } 592 }
593 for (std::set<QPDFObjGen>::iterator iter = to_delete.begin(); 593 for (std::set<QPDFObjGen>::iterator iter = to_delete.begin();
594 - iter != to_delete.end(); ++iter) 594 + iter != to_delete.end(); ++iter)
595 { 595 {
596 - this->m->xref_table.erase(*iter); 596 + this->m->xref_table.erase(*iter);
597 } 597 }
598 598
599 this->m->file->seek(0, SEEK_END); 599 this->m->file->seek(0, SEEK_END);
@@ -615,7 +615,7 @@ QPDF::reconstruct_xref(QPDFExc&amp; e) @@ -615,7 +615,7 @@ QPDF::reconstruct_xref(QPDFExc&amp; e)
615 // don't process yet -- wait until we get to the line 615 // don't process yet -- wait until we get to the line
616 // containing this token 616 // containing this token
617 } 617 }
618 - else if (t1.getType() == QPDFTokenizer::tt_integer) 618 + else if (t1.getType() == QPDFTokenizer::tt_integer)
619 { 619 {
620 QPDFTokenizer::Token t2 = 620 QPDFTokenizer::Token t2 =
621 readToken(this->m->file, MAX_LEN); 621 readToken(this->m->file, MAX_LEN);
@@ -643,22 +643,22 @@ QPDF::reconstruct_xref(QPDFExc&amp; e) @@ -643,22 +643,22 @@ QPDF::reconstruct_xref(QPDFExc&amp; e)
643 { 643 {
644 setTrailer(t); 644 setTrailer(t);
645 } 645 }
646 - } 646 + }
647 this->m->file->seek(next_line_start, SEEK_SET); 647 this->m->file->seek(next_line_start, SEEK_SET);
648 line_start = next_line_start; 648 line_start = next_line_start;
649 } 649 }
650 650
651 if (! this->m->trailer.isInitialized()) 651 if (! this->m->trailer.isInitialized())
652 { 652 {
653 - // We could check the last encountered object to see if it was  
654 - // an xref stream. If so, we could try to get the trailer  
655 - // from there. This may make it possible to recover files  
656 - // with bad startxref pointers even when they have object  
657 - // streams. 653 + // We could check the last encountered object to see if it was
  654 + // an xref stream. If so, we could try to get the trailer
  655 + // from there. This may make it possible to recover files
  656 + // with bad startxref pointers even when they have object
  657 + // streams.
658 658
659 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), "", 0,  
660 - "unable to find trailer "  
661 - "dictionary while recovering damaged file"); 659 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), "", 0,
  660 + "unable to find trailer "
  661 + "dictionary while recovering damaged file");
662 } 662 }
663 663
664 // We could iterate through the objects looking for streams and 664 // We could iterate through the objects looking for streams and
@@ -680,7 +680,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset) @@ -680,7 +680,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset)
680 visited.insert(xref_offset); 680 visited.insert(xref_offset);
681 char buf[7]; 681 char buf[7];
682 memset(buf, 0, sizeof(buf)); 682 memset(buf, 0, sizeof(buf));
683 - this->m->file->seek(xref_offset, SEEK_SET); 683 + this->m->file->seek(xref_offset, SEEK_SET);
684 // Some files miss the mark a little with startxref. We could 684 // Some files miss the mark a little with startxref. We could
685 // do a better job of searching in the neighborhood for 685 // do a better job of searching in the neighborhood for
686 // something that looks like either an xref table or stream, 686 // something that looks like either an xref table or stream,
@@ -712,13 +712,13 @@ QPDF::read_xref(qpdf_offset_t xref_offset) @@ -712,13 +712,13 @@ QPDF::read_xref(qpdf_offset_t xref_offset)
712 } 712 }
713 } 713 }
714 714
715 - this->m->file->read(buf, sizeof(buf) - 1); 715 + this->m->file->read(buf, sizeof(buf) - 1);
716 // The PDF spec says xref must be followed by a line 716 // The PDF spec says xref must be followed by a line
717 // terminator, but files exist in the wild where it is 717 // terminator, but files exist in the wild where it is
718 // terminated by arbitrary whitespace. 718 // terminated by arbitrary whitespace.
719 if ((strncmp(buf, "xref", 4) == 0) && 719 if ((strncmp(buf, "xref", 4) == 0) &&
720 QUtil::is_space(buf[4])) 720 QUtil::is_space(buf[4]))
721 - { 721 + {
722 if (skipped_space) 722 if (skipped_space)
723 { 723 {
724 QTC::TC("qpdf", "QPDF xref skipped space"); 724 QTC::TC("qpdf", "QPDF xref skipped space");
@@ -738,11 +738,11 @@ QPDF::read_xref(qpdf_offset_t xref_offset) @@ -738,11 +738,11 @@ QPDF::read_xref(qpdf_offset_t xref_offset)
738 ++skip; 738 ++skip;
739 } 739 }
740 xref_offset = read_xrefTable(xref_offset + skip); 740 xref_offset = read_xrefTable(xref_offset + skip);
741 - }  
742 - else  
743 - {  
744 - xref_offset = read_xrefStream(xref_offset);  
745 - } 741 + }
  742 + else
  743 + {
  744 + xref_offset = read_xrefStream(xref_offset);
  745 + }
746 if (visited.count(xref_offset) != 0) 746 if (visited.count(xref_offset) != 0)
747 { 747 {
748 QTC::TC("qpdf", "QPDF xref loop"); 748 QTC::TC("qpdf", "QPDF xref loop");
@@ -760,20 +760,20 @@ QPDF::read_xref(qpdf_offset_t xref_offset) @@ -760,20 +760,20 @@ QPDF::read_xref(qpdf_offset_t xref_offset)
760 int max_obj = 0; 760 int max_obj = 0;
761 if (! this->m->xref_table.empty()) 761 if (! this->m->xref_table.empty())
762 { 762 {
763 - max_obj = (*(this->m->xref_table.rbegin())).first.getObj(); 763 + max_obj = (*(this->m->xref_table.rbegin())).first.getObj();
764 } 764 }
765 if (! this->m->deleted_objects.empty()) 765 if (! this->m->deleted_objects.empty())
766 { 766 {
767 - max_obj = std::max(max_obj, *(this->m->deleted_objects.rbegin())); 767 + max_obj = std::max(max_obj, *(this->m->deleted_objects.rbegin()));
768 } 768 }
769 if ((size < 1) || (size - 1 != max_obj)) 769 if ((size < 1) || (size - 1 != max_obj))
770 { 770 {
771 - QTC::TC("qpdf", "QPDF xref size mismatch");  
772 - warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), "", 0,  
773 - std::string("reported number of objects (") +  
774 - QUtil::int_to_string(size) +  
775 - ") is not one plus the highest object number (" +  
776 - QUtil::int_to_string(max_obj) + ")")); 771 + QTC::TC("qpdf", "QPDF xref size mismatch");
  772 + warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), "", 0,
  773 + std::string("reported number of objects (") +
  774 + QUtil::int_to_string(size) +
  775 + ") is not one plus the highest object number (" +
  776 + QUtil::int_to_string(max_obj) + ")"));
777 } 777 }
778 778
779 // We no longer need the deleted_objects table, so go ahead and 779 // We no longer need the deleted_objects table, so go ahead and
@@ -946,143 +946,143 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) @@ -946,143 +946,143 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset)
946 char linebuf[51]; 946 char linebuf[51];
947 memset(linebuf, 0, sizeof(linebuf)); 947 memset(linebuf, 0, sizeof(linebuf));
948 this->m->file->read(linebuf, sizeof(linebuf) - 1); 948 this->m->file->read(linebuf, sizeof(linebuf) - 1);
949 - std::string line = linebuf; 949 + std::string line = linebuf;
950 int obj = 0; 950 int obj = 0;
951 int num = 0; 951 int num = 0;
952 int bytes = 0; 952 int bytes = 0;
953 if (! parse_xrefFirst(line, obj, num, bytes)) 953 if (! parse_xrefFirst(line, obj, num, bytes))
954 - {  
955 - QTC::TC("qpdf", "QPDF invalid xref");  
956 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
957 - "xref table", this->m->file->getLastOffset(),  
958 - "xref syntax invalid");  
959 - } 954 + {
  955 + QTC::TC("qpdf", "QPDF invalid xref");
  956 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  957 + "xref table", this->m->file->getLastOffset(),
  958 + "xref syntax invalid");
  959 + }
960 this->m->file->seek(this->m->file->getLastOffset() + bytes, SEEK_SET); 960 this->m->file->seek(this->m->file->getLastOffset() + bytes, SEEK_SET);
961 - for (qpdf_offset_t i = obj; i - num < obj; ++i)  
962 - {  
963 - if (i == 0)  
964 - {  
965 - // This is needed by checkLinearization()  
966 - this->m->first_xref_item_offset = this->m->file->tell();  
967 - }  
968 - std::string xref_entry = this->m->file->readLine(30); 961 + for (qpdf_offset_t i = obj; i - num < obj; ++i)
  962 + {
  963 + if (i == 0)
  964 + {
  965 + // This is needed by checkLinearization()
  966 + this->m->first_xref_item_offset = this->m->file->tell();
  967 + }
  968 + std::string xref_entry = this->m->file->readLine(30);
969 // For xref_table, these will always be small enough to be ints 969 // For xref_table, these will always be small enough to be ints
970 - qpdf_offset_t f1 = 0;  
971 - int f2 = 0;  
972 - char type = '\0'; 970 + qpdf_offset_t f1 = 0;
  971 + int f2 = 0;
  972 + char type = '\0';
973 if (! parse_xrefEntry(xref_entry, f1, f2, type)) 973 if (! parse_xrefEntry(xref_entry, f1, f2, type))
974 - {  
975 - QTC::TC("qpdf", "QPDF invalid xref entry");  
976 - throw QPDFExc(  
977 - qpdf_e_damaged_pdf, this->m->file->getName(),  
978 - "xref table", this->m->file->getLastOffset(),  
979 - "invalid xref entry (obj=" +  
980 - QUtil::int_to_string(i) + ")");  
981 - }  
982 - if (type == 'f')  
983 - {  
984 - // Save deleted items until after we've checked the  
985 - // XRefStm, if any.  
986 - deleted_items.push_back(QPDFObjGen(toI(i), f2));  
987 - }  
988 - else  
989 - {  
990 - insertXrefEntry(toI(i), 1, f1, f2);  
991 - }  
992 - }  
993 - qpdf_offset_t pos = this->m->file->tell();  
994 - QPDFTokenizer::Token t = readToken(this->m->file);  
995 - if (t == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "trailer"))  
996 - {  
997 - done = true;  
998 - }  
999 - else  
1000 - {  
1001 - this->m->file->seek(pos, SEEK_SET);  
1002 - } 974 + {
  975 + QTC::TC("qpdf", "QPDF invalid xref entry");
  976 + throw QPDFExc(
  977 + qpdf_e_damaged_pdf, this->m->file->getName(),
  978 + "xref table", this->m->file->getLastOffset(),
  979 + "invalid xref entry (obj=" +
  980 + QUtil::int_to_string(i) + ")");
  981 + }
  982 + if (type == 'f')
  983 + {
  984 + // Save deleted items until after we've checked the
  985 + // XRefStm, if any.
  986 + deleted_items.push_back(QPDFObjGen(toI(i), f2));
  987 + }
  988 + else
  989 + {
  990 + insertXrefEntry(toI(i), 1, f1, f2);
  991 + }
  992 + }
  993 + qpdf_offset_t pos = this->m->file->tell();
  994 + QPDFTokenizer::Token t = readToken(this->m->file);
  995 + if (t == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "trailer"))
  996 + {
  997 + done = true;
  998 + }
  999 + else
  1000 + {
  1001 + this->m->file->seek(pos, SEEK_SET);
  1002 + }
1003 } 1003 }
1004 1004
1005 // Set offset to previous xref table if any 1005 // Set offset to previous xref table if any
1006 QPDFObjectHandle cur_trailer = 1006 QPDFObjectHandle cur_trailer =
1007 - readObject(this->m->file, "trailer", 0, 0, false); 1007 + readObject(this->m->file, "trailer", 0, 0, false);
1008 if (! cur_trailer.isDictionary()) 1008 if (! cur_trailer.isDictionary())
1009 { 1009 {
1010 - QTC::TC("qpdf", "QPDF missing trailer");  
1011 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
1012 - "", this->m->file->getLastOffset(),  
1013 - "expected trailer dictionary"); 1010 + QTC::TC("qpdf", "QPDF missing trailer");
  1011 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  1012 + "", this->m->file->getLastOffset(),
  1013 + "expected trailer dictionary");
1014 } 1014 }
1015 1015
1016 if (! this->m->trailer.isInitialized()) 1016 if (! this->m->trailer.isInitialized())
1017 { 1017 {
1018 - setTrailer(cur_trailer);  
1019 -  
1020 - if (! this->m->trailer.hasKey("/Size"))  
1021 - {  
1022 - QTC::TC("qpdf", "QPDF trailer lacks size");  
1023 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
1024 - "trailer", this->m->file->getLastOffset(),  
1025 - "trailer dictionary lacks /Size key");  
1026 - }  
1027 - if (! this->m->trailer.getKey("/Size").isInteger())  
1028 - {  
1029 - QTC::TC("qpdf", "QPDF trailer size not integer");  
1030 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
1031 - "trailer", this->m->file->getLastOffset(),  
1032 - "/Size key in trailer dictionary is not "  
1033 - "an integer");  
1034 - } 1018 + setTrailer(cur_trailer);
  1019 +
  1020 + if (! this->m->trailer.hasKey("/Size"))
  1021 + {
  1022 + QTC::TC("qpdf", "QPDF trailer lacks size");
  1023 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  1024 + "trailer", this->m->file->getLastOffset(),
  1025 + "trailer dictionary lacks /Size key");
  1026 + }
  1027 + if (! this->m->trailer.getKey("/Size").isInteger())
  1028 + {
  1029 + QTC::TC("qpdf", "QPDF trailer size not integer");
  1030 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  1031 + "trailer", this->m->file->getLastOffset(),
  1032 + "/Size key in trailer dictionary is not "
  1033 + "an integer");
  1034 + }
1035 } 1035 }
1036 1036
1037 if (cur_trailer.hasKey("/XRefStm")) 1037 if (cur_trailer.hasKey("/XRefStm"))
1038 { 1038 {
1039 - if (this->m->ignore_xref_streams)  
1040 - {  
1041 - QTC::TC("qpdf", "QPDF ignoring XRefStm in trailer");  
1042 - }  
1043 - else  
1044 - {  
1045 - if (cur_trailer.getKey("/XRefStm").isInteger())  
1046 - {  
1047 - // Read the xref stream but disregard any return value  
1048 - // -- we'll use our trailer's /Prev key instead of the  
1049 - // xref stream's.  
1050 - (void) read_xrefStream(  
1051 - cur_trailer.getKey("/XRefStm").getIntValue());  
1052 - }  
1053 - else  
1054 - {  
1055 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
1056 - "xref stream", xref_offset,  
1057 - "invalid /XRefStm");  
1058 - }  
1059 - } 1039 + if (this->m->ignore_xref_streams)
  1040 + {
  1041 + QTC::TC("qpdf", "QPDF ignoring XRefStm in trailer");
  1042 + }
  1043 + else
  1044 + {
  1045 + if (cur_trailer.getKey("/XRefStm").isInteger())
  1046 + {
  1047 + // Read the xref stream but disregard any return value
  1048 + // -- we'll use our trailer's /Prev key instead of the
  1049 + // xref stream's.
  1050 + (void) read_xrefStream(
  1051 + cur_trailer.getKey("/XRefStm").getIntValue());
  1052 + }
  1053 + else
  1054 + {
  1055 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  1056 + "xref stream", xref_offset,
  1057 + "invalid /XRefStm");
  1058 + }
  1059 + }
1060 } 1060 }
1061 1061
1062 // Handle any deleted items now that we've read the /XRefStm. 1062 // Handle any deleted items now that we've read the /XRefStm.
1063 for (std::vector<QPDFObjGen>::iterator iter = deleted_items.begin(); 1063 for (std::vector<QPDFObjGen>::iterator iter = deleted_items.begin();
1064 - iter != deleted_items.end(); ++iter) 1064 + iter != deleted_items.end(); ++iter)
1065 { 1065 {
1066 - QPDFObjGen& og = *iter;  
1067 - insertXrefEntry(og.getObj(), 0, 0, og.getGen()); 1066 + QPDFObjGen& og = *iter;
  1067 + insertXrefEntry(og.getObj(), 0, 0, og.getGen());
1068 } 1068 }
1069 1069
1070 if (cur_trailer.hasKey("/Prev")) 1070 if (cur_trailer.hasKey("/Prev"))
1071 { 1071 {
1072 - if (! cur_trailer.getKey("/Prev").isInteger())  
1073 - {  
1074 - QTC::TC("qpdf", "QPDF trailer prev not integer");  
1075 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
1076 - "trailer", this->m->file->getLastOffset(),  
1077 - "/Prev key in trailer dictionary is not "  
1078 - "an integer");  
1079 - }  
1080 - QTC::TC("qpdf", "QPDF prev key in trailer dictionary");  
1081 - xref_offset = cur_trailer.getKey("/Prev").getIntValue(); 1072 + if (! cur_trailer.getKey("/Prev").isInteger())
  1073 + {
  1074 + QTC::TC("qpdf", "QPDF trailer prev not integer");
  1075 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  1076 + "trailer", this->m->file->getLastOffset(),
  1077 + "/Prev key in trailer dictionary is not "
  1078 + "an integer");
  1079 + }
  1080 + QTC::TC("qpdf", "QPDF prev key in trailer dictionary");
  1081 + xref_offset = cur_trailer.getKey("/Prev").getIntValue();
1082 } 1082 }
1083 else 1083 else
1084 { 1084 {
1085 - xref_offset = 0; 1085 + xref_offset = 0;
1086 } 1086 }
1087 1087
1088 return xref_offset; 1088 return xref_offset;
@@ -1094,31 +1094,31 @@ QPDF::read_xrefStream(qpdf_offset_t xref_offset) @@ -1094,31 +1094,31 @@ QPDF::read_xrefStream(qpdf_offset_t xref_offset)
1094 bool found = false; 1094 bool found = false;
1095 if (! this->m->ignore_xref_streams) 1095 if (! this->m->ignore_xref_streams)
1096 { 1096 {
1097 - int xobj;  
1098 - int xgen;  
1099 - QPDFObjectHandle xref_obj;  
1100 - try  
1101 - {  
1102 - xref_obj = readObjectAtOffset(  
1103 - false, xref_offset, "xref stream", -1, 0, xobj, xgen);  
1104 - }  
1105 - catch (QPDFExc&)  
1106 - {  
1107 - // ignore -- report error below  
1108 - } 1097 + int xobj;
  1098 + int xgen;
  1099 + QPDFObjectHandle xref_obj;
  1100 + try
  1101 + {
  1102 + xref_obj = readObjectAtOffset(
  1103 + false, xref_offset, "xref stream", -1, 0, xobj, xgen);
  1104 + }
  1105 + catch (QPDFExc&)
  1106 + {
  1107 + // ignore -- report error below
  1108 + }
1109 if (xref_obj.isStreamOfType("/XRef")) 1109 if (xref_obj.isStreamOfType("/XRef"))
1110 - {  
1111 - QTC::TC("qpdf", "QPDF found xref stream");  
1112 - found = true;  
1113 - xref_offset = processXRefStream(xref_offset, xref_obj);  
1114 - } 1110 + {
  1111 + QTC::TC("qpdf", "QPDF found xref stream");
  1112 + found = true;
  1113 + xref_offset = processXRefStream(xref_offset, xref_obj);
  1114 + }
1115 } 1115 }
1116 1116
1117 if (! found) 1117 if (! found)
1118 { 1118 {
1119 - QTC::TC("qpdf", "QPDF can't find xref");  
1120 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
1121 - "", xref_offset, "xref not found"); 1119 + QTC::TC("qpdf", "QPDF can't find xref");
  1120 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  1121 + "", xref_offset, "xref not found");
1122 } 1122 }
1123 1123
1124 return xref_offset; 1124 return xref_offset;
@@ -1131,17 +1131,17 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj) @@ -1131,17 +1131,17 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj)
1131 QPDFObjectHandle W_obj = dict.getKey("/W"); 1131 QPDFObjectHandle W_obj = dict.getKey("/W");
1132 QPDFObjectHandle Index_obj = dict.getKey("/Index"); 1132 QPDFObjectHandle Index_obj = dict.getKey("/Index");
1133 if (! (W_obj.isArray() && 1133 if (! (W_obj.isArray() &&
1134 - (W_obj.getArrayNItems() >= 3) &&  
1135 - W_obj.getArrayItem(0).isInteger() &&  
1136 - W_obj.getArrayItem(1).isInteger() &&  
1137 - W_obj.getArrayItem(2).isInteger() &&  
1138 - dict.getKey("/Size").isInteger() &&  
1139 - (Index_obj.isArray() || Index_obj.isNull()))) 1134 + (W_obj.getArrayNItems() >= 3) &&
  1135 + W_obj.getArrayItem(0).isInteger() &&
  1136 + W_obj.getArrayItem(1).isInteger() &&
  1137 + W_obj.getArrayItem(2).isInteger() &&
  1138 + dict.getKey("/Size").isInteger() &&
  1139 + (Index_obj.isArray() || Index_obj.isNull())))
1140 { 1140 {
1141 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
1142 - "xref stream", xref_offset,  
1143 - "Cross-reference stream does not have"  
1144 - " proper /W and /Index keys"); 1141 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  1142 + "xref stream", xref_offset,
  1143 + "Cross-reference stream does not have"
  1144 + " proper /W and /Index keys");
1145 } 1145 }
1146 1146
1147 int W[3]; 1147 int W[3];
@@ -1149,7 +1149,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj) @@ -1149,7 +1149,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj)
1149 int max_bytes = sizeof(qpdf_offset_t); 1149 int max_bytes = sizeof(qpdf_offset_t);
1150 for (int i = 0; i < 3; ++i) 1150 for (int i = 0; i < 3; ++i)
1151 { 1151 {
1152 - W[i] = W_obj.getArrayItem(i).getIntValueAsInt(); 1152 + W[i] = W_obj.getArrayItem(i).getIntValueAsInt();
1153 if (W[i] > max_bytes) 1153 if (W[i] > max_bytes)
1154 { 1154 {
1155 throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), 1155 throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
@@ -1157,7 +1157,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj) @@ -1157,7 +1157,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj)
1157 "Cross-reference stream's /W contains" 1157 "Cross-reference stream's /W contains"
1158 " impossibly large values"); 1158 " impossibly large values");
1159 } 1159 }
1160 - entry_size += toS(W[i]); 1160 + entry_size += toS(W[i]);
1161 } 1161 }
1162 if (entry_size == 0) 1162 if (entry_size == 0)
1163 { 1163 {
@@ -1172,38 +1172,38 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj) @@ -1172,38 +1172,38 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj)
1172 std::vector<long long> indx; 1172 std::vector<long long> indx;
1173 if (Index_obj.isArray()) 1173 if (Index_obj.isArray())
1174 { 1174 {
1175 - int n_index = Index_obj.getArrayNItems();  
1176 - if ((n_index % 2) || (n_index < 2))  
1177 - {  
1178 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
1179 - "xref stream", xref_offset,  
1180 - "Cross-reference stream's /Index has an"  
1181 - " invalid number of values");  
1182 - }  
1183 - for (int i = 0; i < n_index; ++i)  
1184 - {  
1185 - if (Index_obj.getArrayItem(i).isInteger())  
1186 - {  
1187 - indx.push_back(Index_obj.getArrayItem(i).getIntValue());  
1188 - }  
1189 - else  
1190 - {  
1191 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
1192 - "xref stream", xref_offset,  
1193 - "Cross-reference stream's /Index's item " +  
1194 - QUtil::int_to_string(i) +  
1195 - " is not an integer");  
1196 - }  
1197 - }  
1198 - QTC::TC("qpdf", "QPDF xref /Index is array",  
1199 - n_index == 2 ? 0 : 1); 1175 + int n_index = Index_obj.getArrayNItems();
  1176 + if ((n_index % 2) || (n_index < 2))
  1177 + {
  1178 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  1179 + "xref stream", xref_offset,
  1180 + "Cross-reference stream's /Index has an"
  1181 + " invalid number of values");
  1182 + }
  1183 + for (int i = 0; i < n_index; ++i)
  1184 + {
  1185 + if (Index_obj.getArrayItem(i).isInteger())
  1186 + {
  1187 + indx.push_back(Index_obj.getArrayItem(i).getIntValue());
  1188 + }
  1189 + else
  1190 + {
  1191 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  1192 + "xref stream", xref_offset,
  1193 + "Cross-reference stream's /Index's item " +
  1194 + QUtil::int_to_string(i) +
  1195 + " is not an integer");
  1196 + }
  1197 + }
  1198 + QTC::TC("qpdf", "QPDF xref /Index is array",
  1199 + n_index == 2 ? 0 : 1);
1200 } 1200 }
1201 else 1201 else
1202 { 1202 {
1203 - QTC::TC("qpdf", "QPDF xref /Index is null");  
1204 - long long size = dict.getKey("/Size").getIntValue();  
1205 - indx.push_back(0);  
1206 - indx.push_back(size); 1203 + QTC::TC("qpdf", "QPDF xref /Index is null");
  1204 + long long size = dict.getKey("/Size").getIntValue();
  1205 + indx.push_back(0);
  1206 + indx.push_back(size);
1207 } 1207 }
1208 1208
1209 size_t num_entries = 0; 1209 size_t num_entries = 0;
@@ -1219,7 +1219,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj) @@ -1219,7 +1219,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj)
1219 QUtil::uint_to_string(max_num_entries) + " " + 1219 QUtil::uint_to_string(max_num_entries) + " " +
1220 QUtil::uint_to_string(num_entries)); 1220 QUtil::uint_to_string(num_entries));
1221 } 1221 }
1222 - num_entries += toS(indx.at(i)); 1222 + num_entries += toS(indx.at(i));
1223 } 1223 }
1224 1224
1225 // entry_size and num_entries have both been validated to ensure 1225 // entry_size and num_entries have both been validated to ensure
@@ -1231,19 +1231,19 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj) @@ -1231,19 +1231,19 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj)
1231 1231
1232 if (expected_size != actual_size) 1232 if (expected_size != actual_size)
1233 { 1233 {
1234 - QPDFExc x(qpdf_e_damaged_pdf, this->m->file->getName(),  
1235 - "xref stream", xref_offset,  
1236 - "Cross-reference stream data has the wrong size;"  
1237 - " expected = " + QUtil::uint_to_string(expected_size) +  
1238 - "; actual = " + QUtil::uint_to_string(actual_size));  
1239 - if (expected_size > actual_size)  
1240 - {  
1241 - throw x;  
1242 - }  
1243 - else  
1244 - {  
1245 - warn(x);  
1246 - } 1234 + QPDFExc x(qpdf_e_damaged_pdf, this->m->file->getName(),
  1235 + "xref stream", xref_offset,
  1236 + "Cross-reference stream data has the wrong size;"
  1237 + " expected = " + QUtil::uint_to_string(expected_size) +
  1238 + "; actual = " + QUtil::uint_to_string(actual_size));
  1239 + if (expected_size > actual_size)
  1240 + {
  1241 + throw x;
  1242 + }
  1243 + else
  1244 + {
  1245 + warn(x);
  1246 + }
1247 } 1247 }
1248 1248
1249 size_t cur_chunk = 0; 1249 size_t cur_chunk = 0;
@@ -1257,30 +1257,30 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj) @@ -1257,30 +1257,30 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj)
1257 unsigned char const* data = bp->getBuffer(); 1257 unsigned char const* data = bp->getBuffer();
1258 for (size_t i = 0; i < num_entries; ++i) 1258 for (size_t i = 0; i < num_entries; ++i)
1259 { 1259 {
1260 - // Read this entry  
1261 - unsigned char const* entry = data + (entry_size * i);  
1262 - qpdf_offset_t fields[3];  
1263 - unsigned char const* p = entry;  
1264 - for (int j = 0; j < 3; ++j)  
1265 - {  
1266 - fields[j] = 0;  
1267 - if ((j == 0) && (W[0] == 0))  
1268 - {  
1269 - QTC::TC("qpdf", "QPDF default for xref stream field 0");  
1270 - fields[0] = 1;  
1271 - }  
1272 - for (int k = 0; k < W[j]; ++k)  
1273 - {  
1274 - fields[j] <<= 8;  
1275 - fields[j] += toI(*p++);  
1276 - }  
1277 - }  
1278 -  
1279 - // Get the object and generation number. The object number is  
1280 - // based on /Index. The generation number is 0 unless this is  
1281 - // an uncompressed object record, in which case the generation  
1282 - // number appears as the third field.  
1283 - int obj = toI(indx.at(cur_chunk)); 1260 + // Read this entry
  1261 + unsigned char const* entry = data + (entry_size * i);
  1262 + qpdf_offset_t fields[3];
  1263 + unsigned char const* p = entry;
  1264 + for (int j = 0; j < 3; ++j)
  1265 + {
  1266 + fields[j] = 0;
  1267 + if ((j == 0) && (W[0] == 0))
  1268 + {
  1269 + QTC::TC("qpdf", "QPDF default for xref stream field 0");
  1270 + fields[0] = 1;
  1271 + }
  1272 + for (int k = 0; k < W[j]; ++k)
  1273 + {
  1274 + fields[j] <<= 8;
  1275 + fields[j] += toI(*p++);
  1276 + }
  1277 + }
  1278 +
  1279 + // Get the object and generation number. The object number is
  1280 + // based on /Index. The generation number is 0 unless this is
  1281 + // an uncompressed object record, in which case the generation
  1282 + // number appears as the third field.
  1283 + int obj = toI(indx.at(cur_chunk));
1284 if ((obj < 0) || 1284 if ((obj < 0) ||
1285 ((std::numeric_limits<int>::max() - obj) < chunk_count)) 1285 ((std::numeric_limits<int>::max() - obj) < chunk_count))
1286 { 1286 {
@@ -1292,29 +1292,29 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj) @@ -1292,29 +1292,29 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj)
1292 throw std::range_error(msg.str()); 1292 throw std::range_error(msg.str());
1293 } 1293 }
1294 obj += chunk_count; 1294 obj += chunk_count;
1295 - ++chunk_count;  
1296 - if (chunk_count >= indx.at(cur_chunk + 1))  
1297 - {  
1298 - cur_chunk += 2;  
1299 - chunk_count = 0;  
1300 - }  
1301 -  
1302 - if (saw_first_compressed_object)  
1303 - {  
1304 - if (fields[0] != 2)  
1305 - {  
1306 - this->m->uncompressed_after_compressed = true;  
1307 - }  
1308 - }  
1309 - else if (fields[0] == 2)  
1310 - {  
1311 - saw_first_compressed_object = true;  
1312 - }  
1313 - if (obj == 0)  
1314 - {  
1315 - // This is needed by checkLinearization()  
1316 - this->m->first_xref_item_offset = xref_offset;  
1317 - } 1295 + ++chunk_count;
  1296 + if (chunk_count >= indx.at(cur_chunk + 1))
  1297 + {
  1298 + cur_chunk += 2;
  1299 + chunk_count = 0;
  1300 + }
  1301 +
  1302 + if (saw_first_compressed_object)
  1303 + {
  1304 + if (fields[0] != 2)
  1305 + {
  1306 + this->m->uncompressed_after_compressed = true;
  1307 + }
  1308 + }
  1309 + else if (fields[0] == 2)
  1310 + {
  1311 + saw_first_compressed_object = true;
  1312 + }
  1313 + if (obj == 0)
  1314 + {
  1315 + // This is needed by checkLinearization()
  1316 + this->m->first_xref_item_offset = xref_offset;
  1317 + }
1318 if (fields[0] == 0) 1318 if (fields[0] == 0)
1319 { 1319 {
1320 // Ignore fields[2], which we don't care about in this 1320 // Ignore fields[2], which we don't care about in this
@@ -1323,30 +1323,30 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj) @@ -1323,30 +1323,30 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle&amp; xref_obj)
1323 // objects. 1323 // objects.
1324 fields[2] = 0; 1324 fields[2] = 0;
1325 } 1325 }
1326 - insertXrefEntry(obj, toI(fields[0]), 1326 + insertXrefEntry(obj, toI(fields[0]),
1327 fields[1], toI(fields[2])); 1327 fields[1], toI(fields[2]));
1328 } 1328 }
1329 1329
1330 if (! this->m->trailer.isInitialized()) 1330 if (! this->m->trailer.isInitialized())
1331 { 1331 {
1332 - setTrailer(dict); 1332 + setTrailer(dict);
1333 } 1333 }
1334 1334
1335 if (dict.hasKey("/Prev")) 1335 if (dict.hasKey("/Prev"))
1336 { 1336 {
1337 - if (! dict.getKey("/Prev").isInteger())  
1338 - {  
1339 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
1340 - "xref stream", this->m->file->getLastOffset(),  
1341 - "/Prev key in xref stream dictionary is not "  
1342 - "an integer");  
1343 - }  
1344 - QTC::TC("qpdf", "QPDF prev key in xref stream dictionary");  
1345 - xref_offset = dict.getKey("/Prev").getIntValue(); 1337 + if (! dict.getKey("/Prev").isInteger())
  1338 + {
  1339 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  1340 + "xref stream", this->m->file->getLastOffset(),
  1341 + "/Prev key in xref stream dictionary is not "
  1342 + "an integer");
  1343 + }
  1344 + QTC::TC("qpdf", "QPDF prev key in xref stream dictionary");
  1345 + xref_offset = dict.getKey("/Prev").getIntValue();
1346 } 1346 }
1347 else 1347 else
1348 { 1348 {
1349 - xref_offset = 0; 1349 + xref_offset = 0;
1350 } 1350 }
1351 1351
1352 return xref_offset; 1352 return xref_offset;
@@ -1367,50 +1367,50 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite) @@ -1367,50 +1367,50 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite)
1367 // the table, it means that a later xref table has registered this 1367 // the table, it means that a later xref table has registered this
1368 // object. Disregard this one. 1368 // object. Disregard this one.
1369 { // private scope 1369 { // private scope
1370 - int gen = (f0 == 2 ? 0 : f2);  
1371 - QPDFObjGen og(obj, gen);  
1372 - if (this->m->xref_table.count(og))  
1373 - {  
1374 - if (overwrite)  
1375 - {  
1376 - QTC::TC("qpdf", "QPDF xref overwrite object");  
1377 - this->m->xref_table.erase(og);  
1378 - }  
1379 - else  
1380 - {  
1381 - QTC::TC("qpdf", "QPDF xref reused object");  
1382 - return;  
1383 - }  
1384 - }  
1385 - if (this->m->deleted_objects.count(obj))  
1386 - {  
1387 - QTC::TC("qpdf", "QPDF xref deleted object");  
1388 - return;  
1389 - } 1370 + int gen = (f0 == 2 ? 0 : f2);
  1371 + QPDFObjGen og(obj, gen);
  1372 + if (this->m->xref_table.count(og))
  1373 + {
  1374 + if (overwrite)
  1375 + {
  1376 + QTC::TC("qpdf", "QPDF xref overwrite object");
  1377 + this->m->xref_table.erase(og);
  1378 + }
  1379 + else
  1380 + {
  1381 + QTC::TC("qpdf", "QPDF xref reused object");
  1382 + return;
  1383 + }
  1384 + }
  1385 + if (this->m->deleted_objects.count(obj))
  1386 + {
  1387 + QTC::TC("qpdf", "QPDF xref deleted object");
  1388 + return;
  1389 + }
1390 } 1390 }
1391 1391
1392 switch (f0) 1392 switch (f0)
1393 { 1393 {
1394 case 0: 1394 case 0:
1395 - this->m->deleted_objects.insert(obj);  
1396 - break; 1395 + this->m->deleted_objects.insert(obj);
  1396 + break;
1397 1397
1398 case 1: 1398 case 1:
1399 - // f2 is generation  
1400 - QTC::TC("qpdf", "QPDF xref gen > 0", ((f2 > 0) ? 1 : 0));  
1401 - this->m->xref_table[QPDFObjGen(obj, f2)] = QPDFXRefEntry(f0, f1, f2);  
1402 - break; 1399 + // f2 is generation
  1400 + QTC::TC("qpdf", "QPDF xref gen > 0", ((f2 > 0) ? 1 : 0));
  1401 + this->m->xref_table[QPDFObjGen(obj, f2)] = QPDFXRefEntry(f0, f1, f2);
  1402 + break;
1403 1403
1404 case 2: 1404 case 2:
1405 - this->m->xref_table[QPDFObjGen(obj, 0)] = QPDFXRefEntry(f0, f1, f2);  
1406 - break; 1405 + this->m->xref_table[QPDFObjGen(obj, 0)] = QPDFXRefEntry(f0, f1, f2);
  1406 + break;
1407 1407
1408 default: 1408 default:
1409 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
1410 - "xref stream", this->m->file->getLastOffset(),  
1411 - "unknown xref stream entry type " +  
1412 - QUtil::int_to_string(f0));  
1413 - break; 1409 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  1410 + "xref stream", this->m->file->getLastOffset(),
  1411 + "unknown xref stream entry type " +
  1412 + QUtil::int_to_string(f0));
  1413 + break;
1414 } 1414 }
1415 } 1415 }
1416 1416
@@ -1418,32 +1418,32 @@ void @@ -1418,32 +1418,32 @@ void
1418 QPDF::showXRefTable() 1418 QPDF::showXRefTable()
1419 { 1419 {
1420 for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter = 1420 for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter =
1421 - this->m->xref_table.begin();  
1422 - iter != this->m->xref_table.end(); ++iter)  
1423 - {  
1424 - QPDFObjGen const& og = (*iter).first;  
1425 - QPDFXRefEntry const& entry = (*iter).second;  
1426 - *this->m->out_stream << og.getObj() << "/" << og.getGen() << ": ";  
1427 - switch (entry.getType())  
1428 - {  
1429 - case 1:  
1430 - *this->m->out_stream 1421 + this->m->xref_table.begin();
  1422 + iter != this->m->xref_table.end(); ++iter)
  1423 + {
  1424 + QPDFObjGen const& og = (*iter).first;
  1425 + QPDFXRefEntry const& entry = (*iter).second;
  1426 + *this->m->out_stream << og.getObj() << "/" << og.getGen() << ": ";
  1427 + switch (entry.getType())
  1428 + {
  1429 + case 1:
  1430 + *this->m->out_stream
1431 << "uncompressed; offset = " << entry.getOffset(); 1431 << "uncompressed; offset = " << entry.getOffset();
1432 - break; 1432 + break;
1433 1433
1434 - case 2:  
1435 - *this->m->out_stream 1434 + case 2:
  1435 + *this->m->out_stream
1436 << "compressed; stream = " 1436 << "compressed; stream = "
1437 << entry.getObjStreamNumber() 1437 << entry.getObjStreamNumber()
1438 << ", index = " << entry.getObjStreamIndex(); 1438 << ", index = " << entry.getObjStreamIndex();
1439 - break; 1439 + break;
1440 1440
1441 - default:  
1442 - throw std::logic_error("unknown cross-reference table type while"  
1443 - " showing xref_table");  
1444 - break;  
1445 - }  
1446 - *this->m->out_stream << std::endl; 1441 + default:
  1442 + throw std::logic_error("unknown cross-reference table type while"
  1443 + " showing xref_table");
  1444 + break;
  1445 + }
  1446 + *this->m->out_stream << std::endl;
1447 } 1447 }
1448 } 1448 }
1449 1449
@@ -1460,16 +1460,16 @@ QPDF::fixDanglingReferences(bool force) @@ -1460,16 +1460,16 @@ QPDF::fixDanglingReferences(bool force)
1460 // we've previously resolved and those that we have created. 1460 // we've previously resolved and those that we have created.
1461 std::set<QPDFObjGen> to_process; 1461 std::set<QPDFObjGen> to_process;
1462 for (std::map<QPDFObjGen, ObjCache>::iterator iter = 1462 for (std::map<QPDFObjGen, ObjCache>::iterator iter =
1463 - this->m->obj_cache.begin();  
1464 - iter != this->m->obj_cache.end(); ++iter) 1463 + this->m->obj_cache.begin();
  1464 + iter != this->m->obj_cache.end(); ++iter)
1465 { 1465 {
1466 - to_process.insert((*iter).first); 1466 + to_process.insert((*iter).first);
1467 } 1467 }
1468 for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter = 1468 for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter =
1469 - this->m->xref_table.begin();  
1470 - iter != this->m->xref_table.end(); ++iter) 1469 + this->m->xref_table.begin();
  1470 + iter != this->m->xref_table.end(); ++iter)
1471 { 1471 {
1472 - to_process.insert((*iter).first); 1472 + to_process.insert((*iter).first);
1473 } 1473 }
1474 1474
1475 // For each non-scalar item to process, put it in the queue. 1475 // For each non-scalar item to process, put it in the queue.
@@ -1551,7 +1551,7 @@ QPDF::getObjectCount() @@ -1551,7 +1551,7 @@ QPDF::getObjectCount()
1551 QPDFObjGen og(0, 0); 1551 QPDFObjGen og(0, 0);
1552 if (! this->m->obj_cache.empty()) 1552 if (! this->m->obj_cache.empty())
1553 { 1553 {
1554 - og = (*(this->m->obj_cache.rbegin())).first; 1554 + og = (*(this->m->obj_cache.rbegin())).first;
1555 } 1555 }
1556 return toS(og.getObj()); 1556 return toS(og.getObj());
1557 } 1557 }
@@ -1564,11 +1564,11 @@ QPDF::getAllObjects() @@ -1564,11 +1564,11 @@ QPDF::getAllObjects()
1564 fixDanglingReferences(true); 1564 fixDanglingReferences(true);
1565 std::vector<QPDFObjectHandle> result; 1565 std::vector<QPDFObjectHandle> result;
1566 for (std::map<QPDFObjGen, ObjCache>::iterator iter = 1566 for (std::map<QPDFObjGen, ObjCache>::iterator iter =
1567 - this->m->obj_cache.begin();  
1568 - iter != this->m->obj_cache.end(); ++iter) 1567 + this->m->obj_cache.begin();
  1568 + iter != this->m->obj_cache.end(); ++iter)
1569 { 1569 {
1570 1570
1571 - QPDFObjGen const& og = (*iter).first; 1571 + QPDFObjGen const& og = (*iter).first;
1572 result.push_back(QPDFObjectHandle::Factory::newIndirect( 1572 result.push_back(QPDFObjectHandle::Factory::newIndirect(
1573 this, og.getObj(), og.getGen())); 1573 this, og.getObj(), og.getGen()));
1574 } 1574 }
@@ -1577,29 +1577,29 @@ QPDF::getAllObjects() @@ -1577,29 +1577,29 @@ QPDF::getAllObjects()
1577 1577
1578 void 1578 void
1579 QPDF::setLastObjectDescription(std::string const& description, 1579 QPDF::setLastObjectDescription(std::string const& description,
1580 - int objid, int generation) 1580 + int objid, int generation)
1581 { 1581 {
1582 this->m->last_object_description.clear(); 1582 this->m->last_object_description.clear();
1583 if (! description.empty()) 1583 if (! description.empty())
1584 { 1584 {
1585 - this->m->last_object_description += description;  
1586 - if (objid > 0)  
1587 - {  
1588 - this->m->last_object_description += ": ";  
1589 - } 1585 + this->m->last_object_description += description;
  1586 + if (objid > 0)
  1587 + {
  1588 + this->m->last_object_description += ": ";
  1589 + }
1590 } 1590 }
1591 if (objid > 0) 1591 if (objid > 0)
1592 { 1592 {
1593 - this->m->last_object_description += "object " +  
1594 - QUtil::int_to_string(objid) + " " +  
1595 - QUtil::int_to_string(generation); 1593 + this->m->last_object_description += "object " +
  1594 + QUtil::int_to_string(objid) + " " +
  1595 + QUtil::int_to_string(generation);
1596 } 1596 }
1597 } 1597 }
1598 1598
1599 QPDFObjectHandle 1599 QPDFObjectHandle
1600 QPDF::readObject(PointerHolder<InputSource> input, 1600 QPDF::readObject(PointerHolder<InputSource> input,
1601 - std::string const& description,  
1602 - int objid, int generation, bool in_object_stream) 1601 + std::string const& description,
  1602 + int objid, int generation, bool in_object_stream)
1603 { 1603 {
1604 setLastObjectDescription(description, objid, generation); 1604 setLastObjectDescription(description, objid, generation);
1605 qpdf_offset_t offset = input->tell(); 1605 qpdf_offset_t offset = input->tell();
@@ -1801,14 +1801,14 @@ QPDF::findEndstream() @@ -1801,14 +1801,14 @@ QPDF::findEndstream()
1801 1801
1802 size_t 1802 size_t
1803 QPDF::recoverStreamLength(PointerHolder<InputSource> input, 1803 QPDF::recoverStreamLength(PointerHolder<InputSource> input,
1804 - int objid, int generation, 1804 + int objid, int generation,
1805 qpdf_offset_t stream_offset) 1805 qpdf_offset_t stream_offset)
1806 { 1806 {
1807 // Try to reconstruct stream length by looking for 1807 // Try to reconstruct stream length by looking for
1808 // endstream or endobj 1808 // endstream or endobj
1809 warn(QPDFExc(qpdf_e_damaged_pdf, input->getName(), 1809 warn(QPDFExc(qpdf_e_damaged_pdf, input->getName(),
1810 - this->m->last_object_description, stream_offset,  
1811 - "attempting to recover stream length")); 1810 + this->m->last_object_description, stream_offset,
  1811 + "attempting to recover stream length"));
1812 1812
1813 PatternFinder ef(*this, &QPDF::findEndstream); 1813 PatternFinder ef(*this, &QPDF::findEndstream);
1814 size_t length = 0; 1814 size_t length = 0;
@@ -1825,40 +1825,40 @@ QPDF::recoverStreamLength(PointerHolder&lt;InputSource&gt; input, @@ -1825,40 +1825,40 @@ QPDF::recoverStreamLength(PointerHolder&lt;InputSource&gt; input,
1825 1825
1826 if (length) 1826 if (length)
1827 { 1827 {
1828 - qpdf_offset_t this_obj_offset = 0;  
1829 - QPDFObjGen this_obj(0, 0);  
1830 -  
1831 - // Make sure this is inside this object  
1832 - for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter =  
1833 - this->m->xref_table.begin();  
1834 - iter != this->m->xref_table.end(); ++iter)  
1835 - {  
1836 - QPDFObjGen const& og = (*iter).first;  
1837 - QPDFXRefEntry const& entry = (*iter).second;  
1838 - if (entry.getType() == 1)  
1839 - {  
1840 - qpdf_offset_t obj_offset = entry.getOffset();  
1841 - if ((obj_offset > stream_offset) &&  
1842 - ((this_obj_offset == 0) ||  
1843 - (this_obj_offset > obj_offset)))  
1844 - {  
1845 - this_obj_offset = obj_offset;  
1846 - this_obj = og;  
1847 - }  
1848 - }  
1849 - }  
1850 - if (this_obj_offset &&  
1851 - (this_obj.getObj() == objid) &&  
1852 - (this_obj.getGen() == generation))  
1853 - {  
1854 - // Well, we found endstream\nendobj within the space  
1855 - // allowed for this object, so we're probably in good  
1856 - // shape.  
1857 - }  
1858 - else  
1859 - {  
1860 - QTC::TC("qpdf", "QPDF found wrong endstream in recovery");  
1861 - } 1828 + qpdf_offset_t this_obj_offset = 0;
  1829 + QPDFObjGen this_obj(0, 0);
  1830 +
  1831 + // Make sure this is inside this object
  1832 + for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter =
  1833 + this->m->xref_table.begin();
  1834 + iter != this->m->xref_table.end(); ++iter)
  1835 + {
  1836 + QPDFObjGen const& og = (*iter).first;
  1837 + QPDFXRefEntry const& entry = (*iter).second;
  1838 + if (entry.getType() == 1)
  1839 + {
  1840 + qpdf_offset_t obj_offset = entry.getOffset();
  1841 + if ((obj_offset > stream_offset) &&
  1842 + ((this_obj_offset == 0) ||
  1843 + (this_obj_offset > obj_offset)))
  1844 + {
  1845 + this_obj_offset = obj_offset;
  1846 + this_obj = og;
  1847 + }
  1848 + }
  1849 + }
  1850 + if (this_obj_offset &&
  1851 + (this_obj.getObj() == objid) &&
  1852 + (this_obj.getGen() == generation))
  1853 + {
  1854 + // Well, we found endstream\nendobj within the space
  1855 + // allowed for this object, so we're probably in good
  1856 + // shape.
  1857 + }
  1858 + else
  1859 + {
  1860 + QTC::TC("qpdf", "QPDF found wrong endstream in recovery");
  1861 + }
1862 } 1862 }
1863 1863
1864 if (length == 0) 1864 if (length == 0)
@@ -1889,9 +1889,9 @@ QPDF::readToken(PointerHolder&lt;InputSource&gt; input, size_t max_len) @@ -1889,9 +1889,9 @@ QPDF::readToken(PointerHolder&lt;InputSource&gt; input, size_t max_len)
1889 1889
1890 QPDFObjectHandle 1890 QPDFObjectHandle
1891 QPDF::readObjectAtOffset(bool try_recovery, 1891 QPDF::readObjectAtOffset(bool try_recovery,
1892 - qpdf_offset_t offset, std::string const& description,  
1893 - int exp_objid, int exp_generation,  
1894 - int& objid, int& generation) 1892 + qpdf_offset_t offset, std::string const& description,
  1893 + int exp_objid, int exp_generation,
  1894 + int& objid, int& generation)
1895 { 1895 {
1896 if (! this->m->attempt_recovery) 1896 if (! this->m->attempt_recovery)
1897 { 1897 {
@@ -1907,9 +1907,9 @@ QPDF::readObjectAtOffset(bool try_recovery, @@ -1907,9 +1907,9 @@ QPDF::readObjectAtOffset(bool try_recovery,
1907 if (offset == 0) 1907 if (offset == 0)
1908 { 1908 {
1909 QTC::TC("qpdf", "QPDF bogus 0 offset", 0); 1909 QTC::TC("qpdf", "QPDF bogus 0 offset", 0);
1910 - warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
1911 - this->m->last_object_description, 0,  
1912 - "object has offset 0")); 1910 + warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  1911 + this->m->last_object_description, 0,
  1912 + "object has offset 0"));
1913 return QPDFObjectHandle::newNull(); 1913 return QPDFObjectHandle::newNull();
1914 } 1914 }
1915 1915
@@ -1929,15 +1929,15 @@ QPDF::readObjectAtOffset(bool try_recovery, @@ -1929,15 +1929,15 @@ QPDF::readObjectAtOffset(bool try_recovery,
1929 1929
1930 try 1930 try
1931 { 1931 {
1932 - if (! (objidok && genok && objok))  
1933 - {  
1934 - QTC::TC("qpdf", "QPDF expected n n obj");  
1935 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
1936 - this->m->last_object_description, offset,  
1937 - "expected n n obj");  
1938 - }  
1939 - objid = QUtil::string_to_int(tobjid.getValue().c_str());  
1940 - generation = QUtil::string_to_int(tgen.getValue().c_str()); 1932 + if (! (objidok && genok && objok))
  1933 + {
  1934 + QTC::TC("qpdf", "QPDF expected n n obj");
  1935 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  1936 + this->m->last_object_description, offset,
  1937 + "expected n n obj");
  1938 + }
  1939 + objid = QUtil::string_to_int(tobjid.getValue().c_str());
  1940 + generation = QUtil::string_to_int(tgen.getValue().c_str());
1941 1941
1942 if (objid == 0) 1942 if (objid == 0)
1943 { 1943 {
@@ -1947,11 +1947,11 @@ QPDF::readObjectAtOffset(bool try_recovery, @@ -1947,11 +1947,11 @@ QPDF::readObjectAtOffset(bool try_recovery,
1947 "object with ID 0"); 1947 "object with ID 0");
1948 } 1948 }
1949 1949
1950 - if ((exp_objid >= 0) &&  
1951 - (! ((objid == exp_objid) && (generation == exp_generation))))  
1952 - {  
1953 - QTC::TC("qpdf", "QPDF err wrong objid/generation");  
1954 - QPDFExc e(qpdf_e_damaged_pdf, this->m->file->getName(), 1950 + if ((exp_objid >= 0) &&
  1951 + (! ((objid == exp_objid) && (generation == exp_generation))))
  1952 + {
  1953 + QTC::TC("qpdf", "QPDF err wrong objid/generation");
  1954 + QPDFExc e(qpdf_e_damaged_pdf, this->m->file->getName(),
1955 this->m->last_object_description, offset, 1955 this->m->last_object_description, offset,
1956 std::string("expected ") + 1956 std::string("expected ") +
1957 QUtil::int_to_string(exp_objid) + " " + 1957 QUtil::int_to_string(exp_objid) + " " +
@@ -1967,100 +1967,100 @@ QPDF::readObjectAtOffset(bool try_recovery, @@ -1967,100 +1967,100 @@ QPDF::readObjectAtOffset(bool try_recovery,
1967 // doesn't match. 1967 // doesn't match.
1968 warn(e); 1968 warn(e);
1969 } 1969 }
1970 - } 1970 + }
1971 } 1971 }
1972 catch (QPDFExc& e) 1972 catch (QPDFExc& e)
1973 { 1973 {
1974 - if ((exp_objid >= 0) && try_recovery)  
1975 - {  
1976 - // Try again after reconstructing xref table  
1977 - reconstruct_xref(e);  
1978 - QPDFObjGen og(exp_objid, exp_generation);  
1979 - if (this->m->xref_table.count(og) &&  
1980 - (this->m->xref_table[og].getType() == 1))  
1981 - {  
1982 - qpdf_offset_t new_offset = this->m->xref_table[og].getOffset();  
1983 - QPDFObjectHandle result = readObjectAtOffset(  
1984 - false, new_offset, description,  
1985 - exp_objid, exp_generation, objid, generation);  
1986 - QTC::TC("qpdf", "QPDF recovered in readObjectAtOffset");  
1987 - return result;  
1988 - }  
1989 - else  
1990 - {  
1991 - QTC::TC("qpdf", "QPDF object gone after xref reconstruction");  
1992 - warn(QPDFExc(  
1993 - qpdf_e_damaged_pdf, this->m->file->getName(),  
1994 - "", 0,  
1995 - std::string(  
1996 - "object " +  
1997 - QUtil::int_to_string(exp_objid) +  
1998 - " " +  
1999 - QUtil::int_to_string(exp_generation) +  
2000 - " not found in file after regenerating"  
2001 - " cross reference table")));  
2002 - return QPDFObjectHandle::newNull();  
2003 - }  
2004 - }  
2005 - else  
2006 - {  
2007 - throw e;  
2008 - } 1974 + if ((exp_objid >= 0) && try_recovery)
  1975 + {
  1976 + // Try again after reconstructing xref table
  1977 + reconstruct_xref(e);
  1978 + QPDFObjGen og(exp_objid, exp_generation);
  1979 + if (this->m->xref_table.count(og) &&
  1980 + (this->m->xref_table[og].getType() == 1))
  1981 + {
  1982 + qpdf_offset_t new_offset = this->m->xref_table[og].getOffset();
  1983 + QPDFObjectHandle result = readObjectAtOffset(
  1984 + false, new_offset, description,
  1985 + exp_objid, exp_generation, objid, generation);
  1986 + QTC::TC("qpdf", "QPDF recovered in readObjectAtOffset");
  1987 + return result;
  1988 + }
  1989 + else
  1990 + {
  1991 + QTC::TC("qpdf", "QPDF object gone after xref reconstruction");
  1992 + warn(QPDFExc(
  1993 + qpdf_e_damaged_pdf, this->m->file->getName(),
  1994 + "", 0,
  1995 + std::string(
  1996 + "object " +
  1997 + QUtil::int_to_string(exp_objid) +
  1998 + " " +
  1999 + QUtil::int_to_string(exp_generation) +
  2000 + " not found in file after regenerating"
  2001 + " cross reference table")));
  2002 + return QPDFObjectHandle::newNull();
  2003 + }
  2004 + }
  2005 + else
  2006 + {
  2007 + throw e;
  2008 + }
2009 } 2009 }
2010 2010
2011 QPDFObjectHandle oh = readObject( 2011 QPDFObjectHandle oh = readObject(
2012 - this->m->file, description, objid, generation, false); 2012 + this->m->file, description, objid, generation, false);
2013 2013
2014 if (! (readToken(this->m->file) == 2014 if (! (readToken(this->m->file) ==
2015 - QPDFTokenizer::Token(QPDFTokenizer::tt_word, "endobj"))) 2015 + QPDFTokenizer::Token(QPDFTokenizer::tt_word, "endobj")))
2016 { 2016 {
2017 - QTC::TC("qpdf", "QPDF err expected endobj");  
2018 - warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
2019 - this->m->last_object_description, 2017 + QTC::TC("qpdf", "QPDF err expected endobj");
  2018 + warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  2019 + this->m->last_object_description,
2020 this->m->file->getLastOffset(), 2020 this->m->file->getLastOffset(),
2021 - "expected endobj")); 2021 + "expected endobj"));
2022 } 2022 }
2023 2023
2024 QPDFObjGen og(objid, generation); 2024 QPDFObjGen og(objid, generation);
2025 if (! this->m->obj_cache.count(og)) 2025 if (! this->m->obj_cache.count(og))
2026 { 2026 {
2027 - // Store the object in the cache here so it gets cached  
2028 - // whether we first know the offset or whether we first know  
2029 - // the object ID and generation (in which we case we would get  
2030 - // here through resolve).  
2031 -  
2032 - // Determine the end offset of this object before and after  
2033 - // white space. We use these numbers to validate  
2034 - // linearization hint tables. Offsets and lengths of objects  
2035 - // may imply the end of an object to be anywhere between these  
2036 - // values.  
2037 - qpdf_offset_t end_before_space = this->m->file->tell();  
2038 -  
2039 - // skip over spaces  
2040 - while (true)  
2041 - {  
2042 - char ch;  
2043 - if (this->m->file->read(&ch, 1))  
2044 - {  
2045 - if (! isspace(static_cast<unsigned char>(ch)))  
2046 - {  
2047 - this->m->file->seek(-1, SEEK_CUR);  
2048 - break;  
2049 - }  
2050 - }  
2051 - else  
2052 - {  
2053 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
2054 - this->m->last_object_description, 2027 + // Store the object in the cache here so it gets cached
  2028 + // whether we first know the offset or whether we first know
  2029 + // the object ID and generation (in which we case we would get
  2030 + // here through resolve).
  2031 +
  2032 + // Determine the end offset of this object before and after
  2033 + // white space. We use these numbers to validate
  2034 + // linearization hint tables. Offsets and lengths of objects
  2035 + // may imply the end of an object to be anywhere between these
  2036 + // values.
  2037 + qpdf_offset_t end_before_space = this->m->file->tell();
  2038 +
  2039 + // skip over spaces
  2040 + while (true)
  2041 + {
  2042 + char ch;
  2043 + if (this->m->file->read(&ch, 1))
  2044 + {
  2045 + if (! isspace(static_cast<unsigned char>(ch)))
  2046 + {
  2047 + this->m->file->seek(-1, SEEK_CUR);
  2048 + break;
  2049 + }
  2050 + }
  2051 + else
  2052 + {
  2053 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  2054 + this->m->last_object_description,
2055 this->m->file->tell(), 2055 this->m->file->tell(),
2056 - "EOF after endobj");  
2057 - }  
2058 - }  
2059 - qpdf_offset_t end_after_space = this->m->file->tell(); 2056 + "EOF after endobj");
  2057 + }
  2058 + }
  2059 + qpdf_offset_t end_after_space = this->m->file->tell();
2060 2060
2061 - this->m->obj_cache[og] =  
2062 - ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh),  
2063 - end_before_space, end_after_space); 2061 + this->m->obj_cache[og] =
  2062 + ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh),
  2063 + end_before_space, end_after_space);
2064 } 2064 }
2065 2065
2066 return oh; 2066 return oh;
@@ -2102,19 +2102,19 @@ QPDF::resolve(int objid, int generation) @@ -2102,19 +2102,19 @@ QPDF::resolve(int objid, int generation)
2102 // This can happen if an object references itself directly or 2102 // This can happen if an object references itself directly or
2103 // indirectly in some key that has to be resolved during 2103 // indirectly in some key that has to be resolved during
2104 // object parsing, such as stream length. 2104 // object parsing, such as stream length.
2105 - QTC::TC("qpdf", "QPDF recursion loop in resolve");  
2106 - warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
2107 - "", this->m->file->getLastOffset(),  
2108 - "loop detected resolving object " +  
2109 - QUtil::int_to_string(objid) + " " +  
2110 - QUtil::int_to_string(generation))); 2105 + QTC::TC("qpdf", "QPDF recursion loop in resolve");
  2106 + warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  2107 + "", this->m->file->getLastOffset(),
  2108 + "loop detected resolving object " +
  2109 + QUtil::int_to_string(objid) + " " +
  2110 + QUtil::int_to_string(generation)));
2111 return PointerHolder<QPDFObject>(new QPDF_Null); 2111 return PointerHolder<QPDFObject>(new QPDF_Null);
2112 } 2112 }
2113 ResolveRecorder rr(this, og); 2113 ResolveRecorder rr(this, og);
2114 2114
2115 if ((! this->m->obj_cache.count(og)) && this->m->xref_table.count(og)) 2115 if ((! this->m->obj_cache.count(og)) && this->m->xref_table.count(og))
2116 { 2116 {
2117 - QPDFXRefEntry const& entry = this->m->xref_table[og]; 2117 + QPDFXRefEntry const& entry = this->m->xref_table[og];
2118 try 2118 try
2119 { 2119 {
2120 switch (entry.getType()) 2120 switch (entry.getType())
@@ -2189,12 +2189,12 @@ QPDF::resolveObjectsInStream(int obj_stream_number) @@ -2189,12 +2189,12 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
2189 QPDFObjectHandle obj_stream = getObjectByID(obj_stream_number, 0); 2189 QPDFObjectHandle obj_stream = getObjectByID(obj_stream_number, 0);
2190 if (! obj_stream.isStream()) 2190 if (! obj_stream.isStream())
2191 { 2191 {
2192 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
2193 - this->m->last_object_description,  
2194 - this->m->file->getLastOffset(),  
2195 - "supposed object stream " +  
2196 - QUtil::int_to_string(obj_stream_number) +  
2197 - " is not a stream"); 2192 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  2193 + this->m->last_object_description,
  2194 + this->m->file->getLastOffset(),
  2195 + "supposed object stream " +
  2196 + QUtil::int_to_string(obj_stream_number) +
  2197 + " is not a stream");
2198 } 2198 }
2199 2199
2200 // For linearization data in the object, use the data from the 2200 // For linearization data in the object, use the data from the
@@ -2208,8 +2208,8 @@ QPDF::resolveObjectsInStream(int obj_stream_number) @@ -2208,8 +2208,8 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
2208 QPDFObjectHandle dict = obj_stream.getDict(); 2208 QPDFObjectHandle dict = obj_stream.getDict();
2209 if (! dict.isDictionaryOfType("/ObjStm")) 2209 if (! dict.isDictionaryOfType("/ObjStm"))
2210 { 2210 {
2211 - QTC::TC("qpdf", "QPDF ERR object stream with wrong type");  
2212 - warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), 2211 + QTC::TC("qpdf", "QPDF ERR object stream with wrong type");
  2212 + warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
2213 this->m->last_object_description, 2213 this->m->last_object_description,
2214 this->m->file->getLastOffset(), 2214 this->m->file->getLastOffset(),
2215 "supposed object stream " + 2215 "supposed object stream " +
@@ -2218,14 +2218,14 @@ QPDF::resolveObjectsInStream(int obj_stream_number) @@ -2218,14 +2218,14 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
2218 } 2218 }
2219 2219
2220 if (! (dict.getKey("/N").isInteger() && 2220 if (! (dict.getKey("/N").isInteger() &&
2221 - dict.getKey("/First").isInteger())) 2221 + dict.getKey("/First").isInteger()))
2222 { 2222 {
2223 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
2224 - this->m->last_object_description,  
2225 - this->m->file->getLastOffset(),  
2226 - "object stream " +  
2227 - QUtil::int_to_string(obj_stream_number) +  
2228 - " has incorrect keys"); 2223 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  2224 + this->m->last_object_description,
  2225 + this->m->file->getLastOffset(),
  2226 + "object stream " +
  2227 + QUtil::int_to_string(obj_stream_number) +
  2228 + " has incorrect keys");
2229 } 2229 }
2230 2230
2231 int n = dict.getKey("/N").getIntValueAsInt(); 2231 int n = dict.getKey("/N").getIntValueAsInt();
@@ -2242,20 +2242,20 @@ QPDF::resolveObjectsInStream(int obj_stream_number) @@ -2242,20 +2242,20 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
2242 2242
2243 for (int i = 0; i < n; ++i) 2243 for (int i = 0; i < n; ++i)
2244 { 2244 {
2245 - QPDFTokenizer::Token tnum = readToken(input);  
2246 - QPDFTokenizer::Token toffset = readToken(input);  
2247 - if (! ((tnum.getType() == QPDFTokenizer::tt_integer) &&  
2248 - (toffset.getType() == QPDFTokenizer::tt_integer)))  
2249 - {  
2250 - throw QPDFExc(qpdf_e_damaged_pdf, input->getName(),  
2251 - this->m->last_object_description, 2245 + QPDFTokenizer::Token tnum = readToken(input);
  2246 + QPDFTokenizer::Token toffset = readToken(input);
  2247 + if (! ((tnum.getType() == QPDFTokenizer::tt_integer) &&
  2248 + (toffset.getType() == QPDFTokenizer::tt_integer)))
  2249 + {
  2250 + throw QPDFExc(qpdf_e_damaged_pdf, input->getName(),
  2251 + this->m->last_object_description,
2252 input->getLastOffset(), 2252 input->getLastOffset(),
2253 - "expected integer in object stream header");  
2254 - } 2253 + "expected integer in object stream header");
  2254 + }
2255 2255
2256 - int num = QUtil::string_to_int(tnum.getValue().c_str());  
2257 - long long offset = QUtil::string_to_int(toffset.getValue().c_str());  
2258 - offsets[num] = QIntC::to_int(offset + first); 2256 + int num = QUtil::string_to_int(tnum.getValue().c_str());
  2257 + long long offset = QUtil::string_to_int(toffset.getValue().c_str());
  2258 + offsets[num] = QIntC::to_int(offset + first);
2259 } 2259 }
2260 2260
2261 // To avoid having to read the object stream multiple times, store 2261 // To avoid having to read the object stream multiple times, store
@@ -2264,10 +2264,10 @@ QPDF::resolveObjectsInStream(int obj_stream_number) @@ -2264,10 +2264,10 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
2264 // objects appended to the file, so it is necessary to recheck the 2264 // objects appended to the file, so it is necessary to recheck the
2265 // xref table and only cache what would actually be resolved here. 2265 // xref table and only cache what would actually be resolved here.
2266 for (std::map<int, int>::iterator iter = offsets.begin(); 2266 for (std::map<int, int>::iterator iter = offsets.begin();
2267 - iter != offsets.end(); ++iter) 2267 + iter != offsets.end(); ++iter)
2268 { 2268 {
2269 - int obj = (*iter).first;  
2270 - QPDFObjGen og(obj, 0); 2269 + int obj = (*iter).first;
  2270 + QPDFObjGen og(obj, 0);
2271 QPDFXRefEntry const& entry = this->m->xref_table[og]; 2271 QPDFXRefEntry const& entry = this->m->xref_table[og];
2272 if ((entry.getType() == 2) && 2272 if ((entry.getType() == 2) &&
2273 (entry.getObjStreamNumber() == obj_stream_number)) 2273 (entry.getObjStreamNumber() == obj_stream_number))
@@ -2297,7 +2297,7 @@ QPDF::makeIndirectObject(QPDFObjectHandle oh) @@ -2297,7 +2297,7 @@ QPDF::makeIndirectObject(QPDFObjectHandle oh)
2297 } 2297 }
2298 QPDFObjGen next(max_objid + 1, 0); 2298 QPDFObjGen next(max_objid + 1, 0);
2299 this->m->obj_cache[next] = 2299 this->m->obj_cache[next] =
2300 - ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1); 2300 + ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1);
2301 return QPDFObjectHandle::Factory::newIndirect( 2301 return QPDFObjectHandle::Factory::newIndirect(
2302 this, next.getObj(), next.getGen()); 2302 this, next.getObj(), next.getGen());
2303 } 2303 }
@@ -2325,9 +2325,9 @@ QPDF::replaceObject(int objid, int generation, QPDFObjectHandle oh) @@ -2325,9 +2325,9 @@ QPDF::replaceObject(int objid, int generation, QPDFObjectHandle oh)
2325 { 2325 {
2326 if (oh.isIndirect()) 2326 if (oh.isIndirect())
2327 { 2327 {
2328 - QTC::TC("qpdf", "QPDF replaceObject called with indirect object");  
2329 - throw std::logic_error(  
2330 - "QPDF::replaceObject called with indirect object handle"); 2328 + QTC::TC("qpdf", "QPDF replaceObject called with indirect object");
  2329 + throw std::logic_error(
  2330 + "QPDF::replaceObject called with indirect object handle");
2331 } 2331 }
2332 2332
2333 // Force new object to appear in the cache 2333 // Force new object to appear in the cache
@@ -2337,7 +2337,7 @@ QPDF::replaceObject(int objid, int generation, QPDFObjectHandle oh) @@ -2337,7 +2337,7 @@ QPDF::replaceObject(int objid, int generation, QPDFObjectHandle oh)
2337 QPDFObjGen og(objid, generation); 2337 QPDFObjGen og(objid, generation);
2338 this->m->ever_replaced_objects = true; 2338 this->m->ever_replaced_objects = true;
2339 this->m->obj_cache[og] = 2339 this->m->obj_cache[og] =
2340 - ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1); 2340 + ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1);
2341 } 2341 }
2342 2342
2343 void 2343 void
@@ -2399,8 +2399,8 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign) @@ -2399,8 +2399,8 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign)
2399 if (! foreign.isIndirect()) 2399 if (! foreign.isIndirect())
2400 { 2400 {
2401 QTC::TC("qpdf", "QPDF copyForeign direct"); 2401 QTC::TC("qpdf", "QPDF copyForeign direct");
2402 - throw std::logic_error(  
2403 - "QPDF::copyForeign called with direct object handle"); 2402 + throw std::logic_error(
  2403 + "QPDF::copyForeign called with direct object handle");
2404 } 2404 }
2405 QPDF* other = foreign.getOwningQPDF(); 2405 QPDF* other = foreign.getOwningQPDF();
2406 if (other == this) 2406 if (other == this)
@@ -2509,21 +2509,21 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier&amp; obj_copier, @@ -2509,21 +2509,21 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier&amp; obj_copier,
2509 if (foreign.isArray()) 2509 if (foreign.isArray())
2510 { 2510 {
2511 QTC::TC("qpdf", "QPDF reserve array"); 2511 QTC::TC("qpdf", "QPDF reserve array");
2512 - int n = foreign.getArrayNItems();  
2513 - for (int i = 0; i < n; ++i)  
2514 - { 2512 + int n = foreign.getArrayNItems();
  2513 + for (int i = 0; i < n; ++i)
  2514 + {
2515 reserveObjects(foreign.getArrayItem(i), obj_copier, false); 2515 reserveObjects(foreign.getArrayItem(i), obj_copier, false);
2516 - } 2516 + }
2517 } 2517 }
2518 else if (foreign.isDictionary()) 2518 else if (foreign.isDictionary())
2519 { 2519 {
2520 QTC::TC("qpdf", "QPDF reserve dictionary"); 2520 QTC::TC("qpdf", "QPDF reserve dictionary");
2521 - std::set<std::string> keys = foreign.getKeys();  
2522 - for (std::set<std::string>::iterator iter = keys.begin();  
2523 - iter != keys.end(); ++iter)  
2524 - { 2521 + std::set<std::string> keys = foreign.getKeys();
  2522 + for (std::set<std::string>::iterator iter = keys.begin();
  2523 + iter != keys.end(); ++iter)
  2524 + {
2525 reserveObjects(foreign.getKey(*iter), obj_copier, false); 2525 reserveObjects(foreign.getKey(*iter), obj_copier, false);
2526 - } 2526 + }
2527 } 2527 }
2528 else if (foreign.isStream()) 2528 else if (foreign.isStream())
2529 { 2529 {
@@ -2565,27 +2565,27 @@ QPDF::replaceForeignIndirectObjects( @@ -2565,27 +2565,27 @@ QPDF::replaceForeignIndirectObjects(
2565 { 2565 {
2566 QTC::TC("qpdf", "QPDF replace array"); 2566 QTC::TC("qpdf", "QPDF replace array");
2567 result = QPDFObjectHandle::newArray(); 2567 result = QPDFObjectHandle::newArray();
2568 - int n = foreign.getArrayNItems();  
2569 - for (int i = 0; i < n; ++i)  
2570 - { 2568 + int n = foreign.getArrayNItems();
  2569 + for (int i = 0; i < n; ++i)
  2570 + {
2571 result.appendItem( 2571 result.appendItem(
2572 replaceForeignIndirectObjects( 2572 replaceForeignIndirectObjects(
2573 foreign.getArrayItem(i), obj_copier, false)); 2573 foreign.getArrayItem(i), obj_copier, false));
2574 - } 2574 + }
2575 } 2575 }
2576 else if (foreign.isDictionary()) 2576 else if (foreign.isDictionary())
2577 { 2577 {
2578 QTC::TC("qpdf", "QPDF replace dictionary"); 2578 QTC::TC("qpdf", "QPDF replace dictionary");
2579 result = QPDFObjectHandle::newDictionary(); 2579 result = QPDFObjectHandle::newDictionary();
2580 - std::set<std::string> keys = foreign.getKeys();  
2581 - for (std::set<std::string>::iterator iter = keys.begin();  
2582 - iter != keys.end(); ++iter)  
2583 - { 2580 + std::set<std::string> keys = foreign.getKeys();
  2581 + for (std::set<std::string>::iterator iter = keys.begin();
  2582 + iter != keys.end(); ++iter)
  2583 + {
2584 result.replaceKey( 2584 result.replaceKey(
2585 *iter, 2585 *iter,
2586 replaceForeignIndirectObjects( 2586 replaceForeignIndirectObjects(
2587 foreign.getKey(*iter), obj_copier, false)); 2587 foreign.getKey(*iter), obj_copier, false));
2588 - } 2588 + }
2589 } 2589 }
2590 else if (foreign.isStream()) 2590 else if (foreign.isStream())
2591 { 2591 {
@@ -2806,15 +2806,15 @@ void @@ -2806,15 +2806,15 @@ void
2806 QPDF::getObjectStreamData(std::map<int, int>& omap) 2806 QPDF::getObjectStreamData(std::map<int, int>& omap)
2807 { 2807 {
2808 for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter = 2808 for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter =
2809 - this->m->xref_table.begin();  
2810 - iter != this->m->xref_table.end(); ++iter) 2809 + this->m->xref_table.begin();
  2810 + iter != this->m->xref_table.end(); ++iter)
2811 { 2811 {
2812 - QPDFObjGen const& og = (*iter).first;  
2813 - QPDFXRefEntry const& entry = (*iter).second;  
2814 - if (entry.getType() == 2)  
2815 - {  
2816 - omap[og.getObj()] = entry.getObjStreamNumber();  
2817 - } 2812 + QPDFObjGen const& og = (*iter).first;
  2813 + QPDFXRefEntry const& entry = (*iter).second;
  2814 + if (entry.getType() == 2)
  2815 + {
  2816 + omap[og.getObj()] = entry.getObjStreamNumber();
  2817 + }
2818 } 2818 }
2819 } 2819 }
2820 2820
@@ -2841,69 +2841,69 @@ QPDF::getCompressibleObjGens() @@ -2841,69 +2841,69 @@ QPDF::getCompressibleObjGens()
2841 std::vector<QPDFObjGen> result; 2841 std::vector<QPDFObjGen> result;
2842 while (! queue.empty()) 2842 while (! queue.empty())
2843 { 2843 {
2844 - QPDFObjectHandle obj = queue.front();  
2845 - queue.pop_front();  
2846 - if (obj.isIndirect())  
2847 - {  
2848 - QPDFObjGen og = obj.getObjGen();  
2849 - if (visited.count(og))  
2850 - {  
2851 - QTC::TC("qpdf", "QPDF loop detected traversing objects");  
2852 - continue;  
2853 - }  
2854 - if (og == encryption_dict_og)  
2855 - {  
2856 - QTC::TC("qpdf", "QPDF exclude encryption dictionary");  
2857 - } 2844 + QPDFObjectHandle obj = queue.front();
  2845 + queue.pop_front();
  2846 + if (obj.isIndirect())
  2847 + {
  2848 + QPDFObjGen og = obj.getObjGen();
  2849 + if (visited.count(og))
  2850 + {
  2851 + QTC::TC("qpdf", "QPDF loop detected traversing objects");
  2852 + continue;
  2853 + }
  2854 + if (og == encryption_dict_og)
  2855 + {
  2856 + QTC::TC("qpdf", "QPDF exclude encryption dictionary");
  2857 + }
2858 else if (! (obj.isStream() || 2858 else if (! (obj.isStream() ||
2859 (obj.isDictionaryOfType("/Sig") && 2859 (obj.isDictionaryOfType("/Sig") &&
2860 obj.hasKey("/ByteRange") && 2860 obj.hasKey("/ByteRange") &&
2861 obj.hasKey("/Contents")))) 2861 obj.hasKey("/Contents"))))
2862 - {  
2863 - result.push_back(og);  
2864 - }  
2865 - visited.insert(og);  
2866 - }  
2867 - if (obj.isStream())  
2868 - {  
2869 - QPDFObjectHandle dict = obj.getDict();  
2870 - std::set<std::string> keys = dict.getKeys();  
2871 - for (std::set<std::string>::reverse_iterator iter = keys.rbegin();  
2872 - iter != keys.rend(); ++iter)  
2873 - {  
2874 - std::string const& key = *iter;  
2875 - QPDFObjectHandle value = dict.getKey(key);  
2876 - if (key == "/Length")  
2877 - {  
2878 - // omit stream lengths  
2879 - if (value.isIndirect())  
2880 - {  
2881 - QTC::TC("qpdf", "QPDF exclude indirect length");  
2882 - }  
2883 - }  
2884 - else  
2885 - {  
2886 - queue.push_front(value);  
2887 - }  
2888 - }  
2889 - }  
2890 - else if (obj.isDictionary())  
2891 - {  
2892 - std::set<std::string> keys = obj.getKeys();  
2893 - for (std::set<std::string>::reverse_iterator iter = keys.rbegin();  
2894 - iter != keys.rend(); ++iter)  
2895 - {  
2896 - queue.push_front(obj.getKey(*iter));  
2897 - }  
2898 - }  
2899 - else if (obj.isArray())  
2900 - {  
2901 - int n = obj.getArrayNItems();  
2902 - for (int i = 1; i <= n; ++i)  
2903 - {  
2904 - queue.push_front(obj.getArrayItem(n - i));  
2905 - }  
2906 - } 2862 + {
  2863 + result.push_back(og);
  2864 + }
  2865 + visited.insert(og);
  2866 + }
  2867 + if (obj.isStream())
  2868 + {
  2869 + QPDFObjectHandle dict = obj.getDict();
  2870 + std::set<std::string> keys = dict.getKeys();
  2871 + for (std::set<std::string>::reverse_iterator iter = keys.rbegin();
  2872 + iter != keys.rend(); ++iter)
  2873 + {
  2874 + std::string const& key = *iter;
  2875 + QPDFObjectHandle value = dict.getKey(key);
  2876 + if (key == "/Length")
  2877 + {
  2878 + // omit stream lengths
  2879 + if (value.isIndirect())
  2880 + {
  2881 + QTC::TC("qpdf", "QPDF exclude indirect length");
  2882 + }
  2883 + }
  2884 + else
  2885 + {
  2886 + queue.push_front(value);
  2887 + }
  2888 + }
  2889 + }
  2890 + else if (obj.isDictionary())
  2891 + {
  2892 + std::set<std::string> keys = obj.getKeys();
  2893 + for (std::set<std::string>::reverse_iterator iter = keys.rbegin();
  2894 + iter != keys.rend(); ++iter)
  2895 + {
  2896 + queue.push_front(obj.getKey(*iter));
  2897 + }
  2898 + }
  2899 + else if (obj.isArray())
  2900 + {
  2901 + int n = obj.getArrayNItems();
  2902 + for (int i = 1; i <= n; ++i)
  2903 + {
  2904 + queue.push_front(obj.getArrayItem(n - i));
  2905 + }
  2906 + }
2907 } 2907 }
2908 2908
2909 return result; 2909 return result;
@@ -2914,16 +2914,16 @@ QPDF::pipeStreamData(PointerHolder&lt;EncryptionParameters&gt; encp, @@ -2914,16 +2914,16 @@ QPDF::pipeStreamData(PointerHolder&lt;EncryptionParameters&gt; encp,
2914 PointerHolder<InputSource> file, 2914 PointerHolder<InputSource> file,
2915 QPDF& qpdf_for_warning, 2915 QPDF& qpdf_for_warning,
2916 int objid, int generation, 2916 int objid, int generation,
2917 - qpdf_offset_t offset, size_t length,  
2918 - QPDFObjectHandle stream_dict,  
2919 - Pipeline* pipeline, 2917 + qpdf_offset_t offset, size_t length,
  2918 + QPDFObjectHandle stream_dict,
  2919 + Pipeline* pipeline,
2920 bool suppress_warnings, 2920 bool suppress_warnings,
2921 bool will_retry) 2921 bool will_retry)
2922 { 2922 {
2923 std::vector<std::shared_ptr<Pipeline>> to_delete; 2923 std::vector<std::shared_ptr<Pipeline>> to_delete;
2924 if (encp->encrypted) 2924 if (encp->encrypted)
2925 { 2925 {
2926 - decryptStream(encp, file, qpdf_for_warning, 2926 + decryptStream(encp, file, qpdf_for_warning,
2927 pipeline, objid, generation, 2927 pipeline, objid, generation,
2928 stream_dict, to_delete); 2928 stream_dict, to_delete);
2929 } 2929 }
@@ -2931,23 +2931,23 @@ QPDF::pipeStreamData(PointerHolder&lt;EncryptionParameters&gt; encp, @@ -2931,23 +2931,23 @@ QPDF::pipeStreamData(PointerHolder&lt;EncryptionParameters&gt; encp,
2931 bool success = false; 2931 bool success = false;
2932 try 2932 try
2933 { 2933 {
2934 - file->seek(offset, SEEK_SET);  
2935 - char buf[10240];  
2936 - while (length > 0)  
2937 - {  
2938 - size_t to_read = (sizeof(buf) < length ? sizeof(buf) : length);  
2939 - size_t len = file->read(buf, to_read);  
2940 - if (len == 0)  
2941 - {  
2942 - throw QPDFExc(qpdf_e_damaged_pdf,  
2943 - file->getName(),  
2944 - "",  
2945 - file->getLastOffset(),  
2946 - "unexpected EOF reading stream data");  
2947 - }  
2948 - length -= len;  
2949 - pipeline->write(QUtil::unsigned_char_pointer(buf), len);  
2950 - } 2934 + file->seek(offset, SEEK_SET);
  2935 + char buf[10240];
  2936 + while (length > 0)
  2937 + {
  2938 + size_t to_read = (sizeof(buf) < length ? sizeof(buf) : length);
  2939 + size_t len = file->read(buf, to_read);
  2940 + if (len == 0)
  2941 + {
  2942 + throw QPDFExc(qpdf_e_damaged_pdf,
  2943 + file->getName(),
  2944 + "",
  2945 + file->getLastOffset(),
  2946 + "unexpected EOF reading stream data");
  2947 + }
  2948 + length -= len;
  2949 + pipeline->write(QUtil::unsigned_char_pointer(buf), len);
  2950 + }
2951 pipeline->finish(); 2951 pipeline->finish();
2952 success = true; 2952 success = true;
2953 } 2953 }
@@ -2995,9 +2995,9 @@ QPDF::pipeStreamData(PointerHolder&lt;EncryptionParameters&gt; encp, @@ -2995,9 +2995,9 @@ QPDF::pipeStreamData(PointerHolder&lt;EncryptionParameters&gt; encp,
2995 2995
2996 bool 2996 bool
2997 QPDF::pipeStreamData(int objid, int generation, 2997 QPDF::pipeStreamData(int objid, int generation,
2998 - qpdf_offset_t offset, size_t length,  
2999 - QPDFObjectHandle stream_dict,  
3000 - Pipeline* pipeline, 2998 + qpdf_offset_t offset, size_t length,
  2999 + QPDFObjectHandle stream_dict,
  3000 + Pipeline* pipeline,
3001 bool suppress_warnings, 3001 bool suppress_warnings,
3002 bool will_retry) 3002 bool will_retry)
3003 { 3003 {
libqpdf/QPDFArgParser.cc
@@ -25,7 +25,7 @@ QPDFArgParser::Members::Members( @@ -25,7 +25,7 @@ QPDFArgParser::Members::Members(
25 // Remove prefix added by libtool for consistency during testing. 25 // Remove prefix added by libtool for consistency during testing.
26 if (strncmp(p, "lt-", 3) == 0) 26 if (strncmp(p, "lt-", 3) == 0)
27 { 27 {
28 - p += 3; 28 + p += 3;
29 } 29 }
30 whoami = p; 30 whoami = p;
31 } 31 }
libqpdf/QPDFCrypto_gnutls.cc
@@ -20,11 +20,11 @@ QPDFCrypto_gnutls::~QPDFCrypto_gnutls() @@ -20,11 +20,11 @@ QPDFCrypto_gnutls::~QPDFCrypto_gnutls()
20 { 20 {
21 if (this->hash_ctx) 21 if (this->hash_ctx)
22 { 22 {
23 - gnutls_hash_deinit(this->hash_ctx, digest); 23 + gnutls_hash_deinit(this->hash_ctx, digest);
24 } 24 }
25 if (cipher_ctx) 25 if (cipher_ctx)
26 { 26 {
27 - gnutls_cipher_deinit(this->cipher_ctx); 27 + gnutls_cipher_deinit(this->cipher_ctx);
28 } 28 }
29 this->aes_key_data = nullptr; 29 this->aes_key_data = nullptr;
30 this->aes_key_len = 0; 30 this->aes_key_len = 0;
@@ -36,8 +36,8 @@ QPDFCrypto_gnutls::provideRandomData(unsigned char* data, size_t len) @@ -36,8 +36,8 @@ QPDFCrypto_gnutls::provideRandomData(unsigned char* data, size_t len)
36 int code = gnutls_rnd (GNUTLS_RND_KEY, data, len); 36 int code = gnutls_rnd (GNUTLS_RND_KEY, data, len);
37 if (code < 0) 37 if (code < 0)
38 { 38 {
39 - throw std::runtime_error(  
40 - std::string("gnutls: random number generation error: ") + 39 + throw std::runtime_error(
  40 + std::string("gnutls: random number generation error: ") +
41 std::string(gnutls_strerror(code))); 41 std::string(gnutls_strerror(code)));
42 } 42 }
43 } 43 }
@@ -50,8 +50,8 @@ QPDFCrypto_gnutls::MD5_init() @@ -50,8 +50,8 @@ QPDFCrypto_gnutls::MD5_init()
50 if (code < 0) 50 if (code < 0)
51 { 51 {
52 this->hash_ctx = nullptr; 52 this->hash_ctx = nullptr;
53 - throw std::runtime_error(  
54 - std::string("gnutls: MD5 error: ") + 53 + throw std::runtime_error(
  54 + std::string("gnutls: MD5 error: ") +
55 std::string(gnutls_strerror(code))); 55 std::string(gnutls_strerror(code)));
56 } 56 }
57 } 57 }
@@ -84,7 +84,7 @@ QPDFCrypto_gnutls::RC4_init(unsigned char const* key_data, int key_len) @@ -84,7 +84,7 @@ QPDFCrypto_gnutls::RC4_init(unsigned char const* key_data, int key_len)
84 RC4_finalize(); 84 RC4_finalize();
85 if (key_len == -1) 85 if (key_len == -1)
86 { 86 {
87 - key_len = QIntC::to_int( 87 + key_len = QIntC::to_int(
88 strlen(reinterpret_cast<char const*>(key_data))); 88 strlen(reinterpret_cast<char const*>(key_data)));
89 } 89 }
90 gnutls_datum_t key; 90 gnutls_datum_t key;
@@ -96,8 +96,8 @@ QPDFCrypto_gnutls::RC4_init(unsigned char const* key_data, int key_len) @@ -96,8 +96,8 @@ QPDFCrypto_gnutls::RC4_init(unsigned char const* key_data, int key_len)
96 if (code < 0) 96 if (code < 0)
97 { 97 {
98 this->cipher_ctx = nullptr; 98 this->cipher_ctx = nullptr;
99 - throw std::runtime_error(  
100 - std::string("gnutls: RC4 error: ") + 99 + throw std::runtime_error(
  100 + std::string("gnutls: RC4 error: ") +
101 std::string(gnutls_strerror(code))); 101 std::string(gnutls_strerror(code)));
102 } 102 }
103 } 103 }
@@ -118,8 +118,8 @@ QPDFCrypto_gnutls::RC4_finalize() @@ -118,8 +118,8 @@ QPDFCrypto_gnutls::RC4_finalize()
118 { 118 {
119 if (this->cipher_ctx) 119 if (this->cipher_ctx)
120 { 120 {
121 - gnutls_cipher_deinit(this->cipher_ctx);  
122 - this->cipher_ctx = nullptr; 121 + gnutls_cipher_deinit(this->cipher_ctx);
  122 + this->cipher_ctx = nullptr;
123 } 123 }
124 } 124 }
125 125
@@ -148,8 +148,8 @@ QPDFCrypto_gnutls::SHA2_init(int bits) @@ -148,8 +148,8 @@ QPDFCrypto_gnutls::SHA2_init(int bits)
148 if (code < 0) 148 if (code < 0)
149 { 149 {
150 this->hash_ctx = nullptr; 150 this->hash_ctx = nullptr;
151 - throw std::runtime_error(  
152 - std::string("gnutls: SHA") + QUtil::int_to_string(bits) + 151 + throw std::runtime_error(
  152 + std::string("gnutls: SHA") + QUtil::int_to_string(bits) +
153 " error: " + std::string(gnutls_strerror(code))); 153 " error: " + std::string(gnutls_strerror(code)));
154 } 154 }
155 } 155 }
@@ -278,8 +278,8 @@ QPDFCrypto_gnutls::rijndael_finalize() @@ -278,8 +278,8 @@ QPDFCrypto_gnutls::rijndael_finalize()
278 { 278 {
279 if (this->cipher_ctx) 279 if (this->cipher_ctx)
280 { 280 {
281 - gnutls_cipher_deinit(this->cipher_ctx);  
282 - this->cipher_ctx = nullptr; 281 + gnutls_cipher_deinit(this->cipher_ctx);
  282 + this->cipher_ctx = nullptr;
283 } 283 }
284 } 284 }
285 285
libqpdf/QPDFExc.cc
@@ -3,10 +3,10 @@ @@ -3,10 +3,10 @@
3 #include <qpdf/QUtil.hh> 3 #include <qpdf/QUtil.hh>
4 4
5 QPDFExc::QPDFExc(qpdf_error_code_e error_code, 5 QPDFExc::QPDFExc(qpdf_error_code_e error_code,
6 - std::string const& filename,  
7 - std::string const& object,  
8 - qpdf_offset_t offset,  
9 - std::string const& message) : 6 + std::string const& filename,
  7 + std::string const& object,
  8 + qpdf_offset_t offset,
  9 + std::string const& message) :
10 std::runtime_error(createWhat(filename, object, offset, message)), 10 std::runtime_error(createWhat(filename, object, offset, message)),
11 error_code(error_code), 11 error_code(error_code),
12 filename(filename), 12 filename(filename),
@@ -18,14 +18,14 @@ QPDFExc::QPDFExc(qpdf_error_code_e error_code, @@ -18,14 +18,14 @@ QPDFExc::QPDFExc(qpdf_error_code_e error_code,
18 18
19 std::string 19 std::string
20 QPDFExc::createWhat(std::string const& filename, 20 QPDFExc::createWhat(std::string const& filename,
21 - std::string const& object,  
22 - qpdf_offset_t offset,  
23 - std::string const& message) 21 + std::string const& object,
  22 + qpdf_offset_t offset,
  23 + std::string const& message)
24 { 24 {
25 std::string result; 25 std::string result;
26 if (! filename.empty()) 26 if (! filename.empty())
27 { 27 {
28 - result += filename; 28 + result += filename;
29 } 29 }
30 if (! (object.empty() && offset == 0)) 30 if (! (object.empty() && offset == 0))
31 { 31 {
@@ -33,18 +33,18 @@ QPDFExc::createWhat(std::string const&amp; filename, @@ -33,18 +33,18 @@ QPDFExc::createWhat(std::string const&amp; filename,
33 { 33 {
34 result += " ("; 34 result += " (";
35 } 35 }
36 - if (! object.empty())  
37 - {  
38 - result += object;  
39 - if (offset > 0)  
40 - {  
41 - result += ", ";  
42 - }  
43 - }  
44 - if (offset > 0)  
45 - {  
46 - result += "offset " + QUtil::int_to_string(offset);  
47 - } 36 + if (! object.empty())
  37 + {
  38 + result += object;
  39 + if (offset > 0)
  40 + {
  41 + result += ", ";
  42 + }
  43 + }
  44 + if (offset > 0)
  45 + {
  46 + result += "offset " + QUtil::int_to_string(offset);
  47 + }
48 if (! filename.empty()) 48 if (! filename.empty())
49 { 49 {
50 result += ")"; 50 result += ")";
@@ -52,7 +52,7 @@ QPDFExc::createWhat(std::string const&amp; filename, @@ -52,7 +52,7 @@ QPDFExc::createWhat(std::string const&amp; filename,
52 } 52 }
53 if (! result.empty()) 53 if (! result.empty())
54 { 54 {
55 - result += ": "; 55 + result += ": ";
56 } 56 }
57 result += message; 57 result += message;
58 return result; 58 return result;
libqpdf/QPDFObjGen.cc
@@ -18,7 +18,7 @@ bool @@ -18,7 +18,7 @@ bool
18 QPDFObjGen::operator<(QPDFObjGen const& rhs) const 18 QPDFObjGen::operator<(QPDFObjGen const& rhs) const
19 { 19 {
20 return ((this->obj < rhs.obj) || 20 return ((this->obj < rhs.obj) ||
21 - ((this->obj == rhs.obj) && (this->gen < rhs.gen))); 21 + ((this->obj == rhs.obj) && (this->gen < rhs.gen)));
22 } 22 }
23 23
24 bool 24 bool
libqpdf/QPDFObjectHandle.cc
@@ -117,7 +117,7 @@ QPDFObjectHandle::TokenFilter::write(char const* data, size_t len) @@ -117,7 +117,7 @@ QPDFObjectHandle::TokenFilter::write(char const* data, size_t len)
117 } 117 }
118 if (len) 118 if (len)
119 { 119 {
120 - this->pipeline->write(QUtil::unsigned_char_pointer(data), len); 120 + this->pipeline->write(QUtil::unsigned_char_pointer(data), len);
121 } 121 }
122 } 122 }
123 123
@@ -241,14 +241,14 @@ QPDFObjectHandle::releaseResolved() @@ -241,14 +241,14 @@ QPDFObjectHandle::releaseResolved()
241 // destruction. See comments in QPDF::~QPDF(). 241 // destruction. See comments in QPDF::~QPDF().
242 if (isIndirect()) 242 if (isIndirect())
243 { 243 {
244 - if (this->obj.get())  
245 - {  
246 - this->obj = 0;  
247 - } 244 + if (this->obj.get())
  245 + {
  246 + this->obj = 0;
  247 + }
248 } 248 }
249 else 249 else
250 { 250 {
251 - QPDFObject::ObjAccessor::releaseResolved(this->obj.get()); 251 + QPDFObject::ObjAccessor::releaseResolved(this->obj.get());
252 } 252 }
253 } 253 }
254 254
@@ -304,11 +304,11 @@ class QPDFObjectTypeAccessor @@ -304,11 +304,11 @@ class QPDFObjectTypeAccessor
304 public: 304 public:
305 static bool check(QPDFObject* o) 305 static bool check(QPDFObject* o)
306 { 306 {
307 - return (o && dynamic_cast<T*>(o)); 307 + return (o && dynamic_cast<T*>(o));
308 } 308 }
309 static bool check(QPDFObject const* o) 309 static bool check(QPDFObject const* o)
310 { 310 {
311 - return (o && dynamic_cast<T const*>(o)); 311 + return (o && dynamic_cast<T const*>(o));
312 } 312 }
313 }; 313 };
314 314
@@ -377,11 +377,11 @@ QPDFObjectHandle::getNumericValue() @@ -377,11 +377,11 @@ QPDFObjectHandle::getNumericValue()
377 double result = 0.0; 377 double result = 0.0;
378 if (isInteger()) 378 if (isInteger())
379 { 379 {
380 - result = static_cast<double>(getIntValue()); 380 + result = static_cast<double>(getIntValue());
381 } 381 }
382 else if (isReal()) 382 else if (isReal())
383 { 383 {
384 - result = atof(getRealValue().c_str()); 384 + result = atof(getRealValue().c_str());
385 } 385 }
386 else 386 else
387 { 387 {
@@ -1443,7 +1443,7 @@ QPDFObjectHandle::getOwningQPDF() @@ -1443,7 +1443,7 @@ QPDFObjectHandle::getOwningQPDF()
1443 1443
1444 void 1444 void
1445 QPDFObjectHandle::replaceKey(std::string const& key, 1445 QPDFObjectHandle::replaceKey(std::string const& key,
1446 - QPDFObjectHandle value) 1446 + QPDFObjectHandle value)
1447 { 1447 {
1448 if (isDictionary()) 1448 if (isDictionary())
1449 { 1449 {
@@ -1474,7 +1474,7 @@ QPDFObjectHandle::removeKey(std::string const&amp; key) @@ -1474,7 +1474,7 @@ QPDFObjectHandle::removeKey(std::string const&amp; key)
1474 1474
1475 void 1475 void
1476 QPDFObjectHandle::replaceOrRemoveKey(std::string const& key, 1476 QPDFObjectHandle::replaceOrRemoveKey(std::string const& key,
1477 - QPDFObjectHandle value) 1477 + QPDFObjectHandle value)
1478 { 1478 {
1479 if (isDictionary()) 1479 if (isDictionary())
1480 { 1480 {
@@ -1548,7 +1548,7 @@ QPDFObjectHandle::pipeStreamData(Pipeline* p, bool* filtering_attempted, @@ -1548,7 +1548,7 @@ QPDFObjectHandle::pipeStreamData(Pipeline* p, bool* filtering_attempted,
1548 { 1548 {
1549 assertStream(); 1549 assertStream();
1550 return dynamic_cast<QPDF_Stream*>(obj.get())->pipeStreamData( 1550 return dynamic_cast<QPDF_Stream*>(obj.get())->pipeStreamData(
1551 - p, filtering_attempted, encode_flags, decode_level, 1551 + p, filtering_attempted, encode_flags, decode_level,
1552 suppress_warnings, will_retry); 1552 suppress_warnings, will_retry);
1553 } 1553 }
1554 1554
@@ -1561,14 +1561,14 @@ QPDFObjectHandle::pipeStreamData(Pipeline* p, @@ -1561,14 +1561,14 @@ QPDFObjectHandle::pipeStreamData(Pipeline* p,
1561 assertStream(); 1561 assertStream();
1562 bool filtering_attempted; 1562 bool filtering_attempted;
1563 dynamic_cast<QPDF_Stream*>(obj.get())->pipeStreamData( 1563 dynamic_cast<QPDF_Stream*>(obj.get())->pipeStreamData(
1564 - p, &filtering_attempted, encode_flags, decode_level, 1564 + p, &filtering_attempted, encode_flags, decode_level,
1565 suppress_warnings, will_retry); 1565 suppress_warnings, will_retry);
1566 return filtering_attempted; 1566 return filtering_attempted;
1567 } 1567 }
1568 1568
1569 bool 1569 bool
1570 QPDFObjectHandle::pipeStreamData(Pipeline* p, bool filter, 1570 QPDFObjectHandle::pipeStreamData(Pipeline* p, bool filter,
1571 - bool normalize, bool compress) 1571 + bool normalize, bool compress)
1572 { 1572 {
1573 int encode_flags = 0; 1573 int encode_flags = 0;
1574 qpdf_stream_decode_level_e decode_level = qpdf_dl_none; 1574 qpdf_stream_decode_level_e decode_level = qpdf_dl_none;
@@ -1589,35 +1589,35 @@ QPDFObjectHandle::pipeStreamData(Pipeline* p, bool filter, @@ -1589,35 +1589,35 @@ QPDFObjectHandle::pipeStreamData(Pipeline* p, bool filter,
1589 1589
1590 void 1590 void
1591 QPDFObjectHandle::replaceStreamData(PointerHolder<Buffer> data, 1591 QPDFObjectHandle::replaceStreamData(PointerHolder<Buffer> data,
1592 - QPDFObjectHandle const& filter,  
1593 - QPDFObjectHandle const& decode_parms) 1592 + QPDFObjectHandle const& filter,
  1593 + QPDFObjectHandle const& decode_parms)
1594 { 1594 {
1595 assertStream(); 1595 assertStream();
1596 dynamic_cast<QPDF_Stream*>(obj.get())->replaceStreamData( 1596 dynamic_cast<QPDF_Stream*>(obj.get())->replaceStreamData(
1597 - data, filter, decode_parms); 1597 + data, filter, decode_parms);
1598 } 1598 }
1599 1599
1600 void 1600 void
1601 QPDFObjectHandle::replaceStreamData(std::string const& data, 1601 QPDFObjectHandle::replaceStreamData(std::string const& data,
1602 - QPDFObjectHandle const& filter,  
1603 - QPDFObjectHandle const& decode_parms) 1602 + QPDFObjectHandle const& filter,
  1603 + QPDFObjectHandle const& decode_parms)
1604 { 1604 {
1605 assertStream(); 1605 assertStream();
1606 auto b = make_pointer_holder<Buffer>(data.length()); 1606 auto b = make_pointer_holder<Buffer>(data.length());
1607 unsigned char* bp = b->getBuffer(); 1607 unsigned char* bp = b->getBuffer();
1608 memcpy(bp, data.c_str(), data.length()); 1608 memcpy(bp, data.c_str(), data.length());
1609 dynamic_cast<QPDF_Stream*>(obj.get())->replaceStreamData( 1609 dynamic_cast<QPDF_Stream*>(obj.get())->replaceStreamData(
1610 - b, filter, decode_parms); 1610 + b, filter, decode_parms);
1611 } 1611 }
1612 1612
1613 void 1613 void
1614 QPDFObjectHandle::replaceStreamData(PointerHolder<StreamDataProvider> provider, 1614 QPDFObjectHandle::replaceStreamData(PointerHolder<StreamDataProvider> provider,
1615 - QPDFObjectHandle const& filter,  
1616 - QPDFObjectHandle const& decode_parms) 1615 + QPDFObjectHandle const& filter,
  1616 + QPDFObjectHandle const& decode_parms)
1617 { 1617 {
1618 assertStream(); 1618 assertStream();
1619 dynamic_cast<QPDF_Stream*>(obj.get())->replaceStreamData( 1619 dynamic_cast<QPDF_Stream*>(obj.get())->replaceStreamData(
1620 - provider, filter, decode_parms); 1620 + provider, filter, decode_parms);
1621 } 1621 }
1622 1622
1623 class FunctionProvider: public QPDFObjectHandle::StreamDataProvider 1623 class FunctionProvider: public QPDFObjectHandle::StreamDataProvider
@@ -1662,7 +1662,7 @@ QPDFObjectHandle::replaceStreamData(std::function&lt;void(Pipeline*)&gt; provider, @@ -1662,7 +1662,7 @@ QPDFObjectHandle::replaceStreamData(std::function&lt;void(Pipeline*)&gt; provider,
1662 auto sdp = PointerHolder<StreamDataProvider>( 1662 auto sdp = PointerHolder<StreamDataProvider>(
1663 new FunctionProvider(provider)); 1663 new FunctionProvider(provider));
1664 dynamic_cast<QPDF_Stream*>(obj.get())->replaceStreamData( 1664 dynamic_cast<QPDF_Stream*>(obj.get())->replaceStreamData(
1665 - sdp, filter, decode_parms); 1665 + sdp, filter, decode_parms);
1666 } 1666 }
1667 1667
1668 void 1668 void
@@ -1675,7 +1675,7 @@ QPDFObjectHandle::replaceStreamData( @@ -1675,7 +1675,7 @@ QPDFObjectHandle::replaceStreamData(
1675 auto sdp = PointerHolder<StreamDataProvider>( 1675 auto sdp = PointerHolder<StreamDataProvider>(
1676 new FunctionProvider(provider)); 1676 new FunctionProvider(provider));
1677 dynamic_cast<QPDF_Stream*>(obj.get())->replaceStreamData( 1677 dynamic_cast<QPDF_Stream*>(obj.get())->replaceStreamData(
1678 - sdp, filter, decode_parms); 1678 + sdp, filter, decode_parms);
1679 } 1679 }
1680 1680
1681 QPDFObjGen 1681 QPDFObjGen
@@ -1710,28 +1710,28 @@ QPDFObjectHandle::arrayOrStreamToStreamArray( @@ -1710,28 +1710,28 @@ QPDFObjectHandle::arrayOrStreamToStreamArray(
1710 std::vector<QPDFObjectHandle> result; 1710 std::vector<QPDFObjectHandle> result;
1711 if (isArray()) 1711 if (isArray())
1712 { 1712 {
1713 - int n_items = getArrayNItems();  
1714 - for (int i = 0; i < n_items; ++i)  
1715 - {  
1716 - QPDFObjectHandle item = getArrayItem(i);  
1717 - if (item.isStream()) 1713 + int n_items = getArrayNItems();
  1714 + for (int i = 0; i < n_items; ++i)
  1715 + {
  1716 + QPDFObjectHandle item = getArrayItem(i);
  1717 + if (item.isStream())
1718 { 1718 {
1719 result.push_back(item); 1719 result.push_back(item);
1720 } 1720 }
1721 else 1721 else
1722 - { 1722 + {
1723 QTC::TC("qpdf", "QPDFObjectHandle non-stream in stream array"); 1723 QTC::TC("qpdf", "QPDFObjectHandle non-stream in stream array");
1724 warn(item.getOwningQPDF(), 1724 warn(item.getOwningQPDF(),
1725 QPDFExc(qpdf_e_damaged_pdf, description, 1725 QPDFExc(qpdf_e_damaged_pdf, description,
1726 "item index " + QUtil::int_to_string(i) + 1726 "item index " + QUtil::int_to_string(i) +
1727 " (from 0)", 0, 1727 " (from 0)", 0,
1728 "ignoring non-stream in an array of streams")); 1728 "ignoring non-stream in an array of streams"));
1729 - }  
1730 - } 1729 + }
  1730 + }
1731 } 1731 }
1732 else if (isStream()) 1732 else if (isStream())
1733 { 1733 {
1734 - result.push_back(*this); 1734 + result.push_back(*this);
1735 } 1735 }
1736 else if (! isNull()) 1736 else if (! isNull())
1737 { 1737 {
@@ -1784,18 +1784,18 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first) @@ -1784,18 +1784,18 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first)
1784 std::vector<QPDFObjectHandle> content_streams; 1784 std::vector<QPDFObjectHandle> content_streams;
1785 if (first) 1785 if (first)
1786 { 1786 {
1787 - QTC::TC("qpdf", "QPDFObjectHandle prepend page contents");  
1788 - content_streams.push_back(new_contents); 1787 + QTC::TC("qpdf", "QPDFObjectHandle prepend page contents");
  1788 + content_streams.push_back(new_contents);
1789 } 1789 }
1790 for (std::vector<QPDFObjectHandle>::iterator iter = orig_contents.begin(); 1790 for (std::vector<QPDFObjectHandle>::iterator iter = orig_contents.begin();
1791 - iter != orig_contents.end(); ++iter) 1791 + iter != orig_contents.end(); ++iter)
1792 { 1792 {
1793 - QTC::TC("qpdf", "QPDFObjectHandle append page contents");  
1794 - content_streams.push_back(*iter); 1793 + QTC::TC("qpdf", "QPDFObjectHandle append page contents");
  1794 + content_streams.push_back(*iter);
1795 } 1795 }
1796 if (! first) 1796 if (! first)
1797 { 1797 {
1798 - content_streams.push_back(new_contents); 1798 + content_streams.push_back(new_contents);
1799 } 1799 }
1800 1800
1801 QPDFObjectHandle contents = QPDFObjectHandle::newArray(content_streams); 1801 QPDFObjectHandle contents = QPDFObjectHandle::newArray(content_streams);
@@ -1899,12 +1899,12 @@ QPDFObjectHandle::unparse() @@ -1899,12 +1899,12 @@ QPDFObjectHandle::unparse()
1899 std::string result; 1899 std::string result;
1900 if (this->isIndirect()) 1900 if (this->isIndirect())
1901 { 1901 {
1902 - result = QUtil::int_to_string(this->objid) + " " +  
1903 - QUtil::int_to_string(this->generation) + " R"; 1902 + result = QUtil::int_to_string(this->objid) + " " +
  1903 + QUtil::int_to_string(this->generation) + " R";
1904 } 1904 }
1905 else 1905 else
1906 { 1906 {
1907 - result = unparseResolved(); 1907 + result = unparseResolved();
1908 } 1908 }
1909 return result; 1909 return result;
1910 } 1910 }
@@ -2253,10 +2253,10 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input, @@ -2253,10 +2253,10 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input,
2253 std::string& contents_string = contents_string_stack.back(); 2253 std::string& contents_string = contents_string_stack.back();
2254 qpdf_offset_t& contents_offset = contents_offset_stack.back(); 2254 qpdf_offset_t& contents_offset = contents_offset_stack.back();
2255 2255
2256 - object = QPDFObjectHandle();  
2257 - set_offset = false; 2256 + object = QPDFObjectHandle();
  2257 + set_offset = false;
2258 2258
2259 - QPDFTokenizer::Token token = 2259 + QPDFTokenizer::Token token =
2260 tokenizer.readToken(input, object_description, true); 2260 tokenizer.readToken(input, object_description, true);
2261 std::string const& token_error_message = token.getErrorMessage(); 2261 std::string const& token_error_message = token.getErrorMessage();
2262 if (! token_error_message.empty()) 2262 if (! token_error_message.empty())
@@ -2269,8 +2269,8 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input, @@ -2269,8 +2269,8 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input,
2269 token_error_message)); 2269 token_error_message));
2270 } 2270 }
2271 2271
2272 - switch (token.getType())  
2273 - { 2272 + switch (token.getType())
  2273 + {
2274 case QPDFTokenizer::tt_eof: 2274 case QPDFTokenizer::tt_eof:
2275 if (! content_stream) 2275 if (! content_stream)
2276 { 2276 {
@@ -2286,14 +2286,14 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input, @@ -2286,14 +2286,14 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input,
2286 break; 2286 break;
2287 2287
2288 case QPDFTokenizer::tt_bad: 2288 case QPDFTokenizer::tt_bad:
2289 - QTC::TC("qpdf", "QPDFObjectHandle bad token in parse"); 2289 + QTC::TC("qpdf", "QPDFObjectHandle bad token in parse");
2290 bad = true; 2290 bad = true;
2291 object = newNull(); 2291 object = newNull();
2292 - break; 2292 + break;
2293 2293
2294 - case QPDFTokenizer::tt_brace_open:  
2295 - case QPDFTokenizer::tt_brace_close:  
2296 - QTC::TC("qpdf", "QPDFObjectHandle bad brace"); 2294 + case QPDFTokenizer::tt_brace_open:
  2295 + case QPDFTokenizer::tt_brace_close:
  2296 + QTC::TC("qpdf", "QPDFObjectHandle bad brace");
2297 warn(context, 2297 warn(context,
2298 QPDFExc(qpdf_e_damaged_pdf, input->getName(), 2298 QPDFExc(qpdf_e_damaged_pdf, input->getName(),
2299 object_description, 2299 object_description,
@@ -2301,16 +2301,16 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input, @@ -2301,16 +2301,16 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input,
2301 "treating unexpected brace token as null")); 2301 "treating unexpected brace token as null"));
2302 bad = true; 2302 bad = true;
2303 object = newNull(); 2303 object = newNull();
2304 - break; 2304 + break;
2305 2305
2306 - case QPDFTokenizer::tt_array_close:  
2307 - if (state == st_array)  
2308 - { 2306 + case QPDFTokenizer::tt_array_close:
  2307 + if (state == st_array)
  2308 + {
2309 state = st_stop; 2309 state = st_stop;
2310 - }  
2311 - else  
2312 - {  
2313 - QTC::TC("qpdf", "QPDFObjectHandle bad array close"); 2310 + }
  2311 + else
  2312 + {
  2313 + QTC::TC("qpdf", "QPDFObjectHandle bad array close");
2314 warn(context, 2314 warn(context,
2315 QPDFExc(qpdf_e_damaged_pdf, input->getName(), 2315 QPDFExc(qpdf_e_damaged_pdf, input->getName(),
2316 object_description, 2316 object_description,
@@ -2318,17 +2318,17 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input, @@ -2318,17 +2318,17 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input,
2318 "treating unexpected array close token as null")); 2318 "treating unexpected array close token as null"));
2319 bad = true; 2319 bad = true;
2320 object = newNull(); 2320 object = newNull();
2321 - }  
2322 - break; 2321 + }
  2322 + break;
2323 2323
2324 - case QPDFTokenizer::tt_dict_close:  
2325 - if (state == st_dictionary)  
2326 - { 2324 + case QPDFTokenizer::tt_dict_close:
  2325 + if (state == st_dictionary)
  2326 + {
2327 state = st_stop; 2327 state = st_stop;
2328 - }  
2329 - else  
2330 - {  
2331 - QTC::TC("qpdf", "QPDFObjectHandle bad dictionary close"); 2328 + }
  2329 + else
  2330 + {
  2331 + QTC::TC("qpdf", "QPDFObjectHandle bad dictionary close");
2332 warn(context, 2332 warn(context,
2333 QPDFExc(qpdf_e_damaged_pdf, input->getName(), 2333 QPDFExc(qpdf_e_damaged_pdf, input->getName(),
2334 object_description, 2334 object_description,
@@ -2336,14 +2336,14 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input, @@ -2336,14 +2336,14 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input,
2336 "unexpected dictionary close token")); 2336 "unexpected dictionary close token"));
2337 bad = true; 2337 bad = true;
2338 object = newNull(); 2338 object = newNull();
2339 - }  
2340 - break; 2339 + }
  2340 + break;
2341 2341
2342 - case QPDFTokenizer::tt_array_open:  
2343 - case QPDFTokenizer::tt_dict_open: 2342 + case QPDFTokenizer::tt_array_open:
  2343 + case QPDFTokenizer::tt_dict_open:
2344 if (olist_stack.size() > 500) 2344 if (olist_stack.size() > 500)
2345 { 2345 {
2346 - QTC::TC("qpdf", "QPDFObjectHandle too deep"); 2346 + QTC::TC("qpdf", "QPDFObjectHandle too deep");
2347 warn(context, 2347 warn(context,
2348 QPDFExc(qpdf_e_damaged_pdf, input->getName(), 2348 QPDFExc(qpdf_e_damaged_pdf, input->getName(),
2349 object_description, 2349 object_description,
@@ -2365,54 +2365,54 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input, @@ -2365,54 +2365,54 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input,
2365 contents_string_stack.push_back(""); 2365 contents_string_stack.push_back("");
2366 contents_offset_stack.push_back(-1); 2366 contents_offset_stack.push_back(-1);
2367 } 2367 }
2368 - break;  
2369 -  
2370 - case QPDFTokenizer::tt_bool:  
2371 - object = newBool((token.getValue() == "true"));  
2372 - break;  
2373 -  
2374 - case QPDFTokenizer::tt_null:  
2375 - object = newNull();  
2376 - break;  
2377 -  
2378 - case QPDFTokenizer::tt_integer:  
2379 - object = newInteger(QUtil::string_to_ll(token.getValue().c_str()));  
2380 - break;  
2381 -  
2382 - case QPDFTokenizer::tt_real:  
2383 - object = newReal(token.getValue());  
2384 - break;  
2385 -  
2386 - case QPDFTokenizer::tt_name:  
2387 - {  
2388 - std::string name = token.getValue();  
2389 - object = newName(name);  
2390 -  
2391 - if (name == "/Contents")  
2392 - {  
2393 - b_contents = true;  
2394 - }  
2395 - else  
2396 - {  
2397 - b_contents = false;  
2398 - }  
2399 - }  
2400 - break;  
2401 -  
2402 - case QPDFTokenizer::tt_word:  
2403 - {  
2404 - std::string const& value = token.getValue(); 2368 + break;
  2369 +
  2370 + case QPDFTokenizer::tt_bool:
  2371 + object = newBool((token.getValue() == "true"));
  2372 + break;
  2373 +
  2374 + case QPDFTokenizer::tt_null:
  2375 + object = newNull();
  2376 + break;
  2377 +
  2378 + case QPDFTokenizer::tt_integer:
  2379 + object = newInteger(QUtil::string_to_ll(token.getValue().c_str()));
  2380 + break;
  2381 +
  2382 + case QPDFTokenizer::tt_real:
  2383 + object = newReal(token.getValue());
  2384 + break;
  2385 +
  2386 + case QPDFTokenizer::tt_name:
  2387 + {
  2388 + std::string name = token.getValue();
  2389 + object = newName(name);
  2390 +
  2391 + if (name == "/Contents")
  2392 + {
  2393 + b_contents = true;
  2394 + }
  2395 + else
  2396 + {
  2397 + b_contents = false;
  2398 + }
  2399 + }
  2400 + break;
  2401 +
  2402 + case QPDFTokenizer::tt_word:
  2403 + {
  2404 + std::string const& value = token.getValue();
2405 if (content_stream) 2405 if (content_stream)
2406 { 2406 {
2407 object = QPDFObjectHandle::newOperator(value); 2407 object = QPDFObjectHandle::newOperator(value);
2408 } 2408 }
2409 - else if ((value == "R") && (state != st_top) && 2409 + else if ((value == "R") && (state != st_top) &&
2410 (olist.size() >= 2) && 2410 (olist.size() >= 2) &&
2411 (! olist.at(olist.size() - 1).isIndirect()) && 2411 (! olist.at(olist.size() - 1).isIndirect()) &&
2412 (olist.at(olist.size() - 1).isInteger()) && 2412 (olist.at(olist.size() - 1).isInteger()) &&
2413 (! olist.at(olist.size() - 2).isIndirect()) && 2413 (! olist.at(olist.size() - 2).isIndirect()) &&
2414 (olist.at(olist.size() - 2).isInteger())) 2414 (olist.at(olist.size() - 2).isInteger()))
2415 - { 2415 + {
2416 if (context == 0) 2416 if (context == 0)
2417 { 2417 {
2418 QTC::TC("qpdf", "QPDFObjectHandle indirect without context"); 2418 QTC::TC("qpdf", "QPDFObjectHandle indirect without context");
@@ -2420,25 +2420,25 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input, @@ -2420,25 +2420,25 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input,
2420 "QPDFObjectHandle::parse called without context" 2420 "QPDFObjectHandle::parse called without context"
2421 " on an object with indirect references"); 2421 " on an object with indirect references");
2422 } 2422 }
2423 - // Try to resolve indirect objects  
2424 - object = newIndirect(  
2425 - context,  
2426 - olist.at(olist.size() - 2).getIntValueAsInt(),  
2427 - olist.at(olist.size() - 1).getIntValueAsInt());  
2428 - olist.remove_last();  
2429 - olist.remove_last();  
2430 - }  
2431 - else if ((value == "endobj") && (state == st_top))  
2432 - {  
2433 - // We just saw endobj without having read  
2434 - // anything. Treat this as a null and do not move  
2435 - // the input source's offset.  
2436 - object = newNull();  
2437 - input->seek(input->getLastOffset(), SEEK_SET); 2423 + // Try to resolve indirect objects
  2424 + object = newIndirect(
  2425 + context,
  2426 + olist.at(olist.size() - 2).getIntValueAsInt(),
  2427 + olist.at(olist.size() - 1).getIntValueAsInt());
  2428 + olist.remove_last();
  2429 + olist.remove_last();
  2430 + }
  2431 + else if ((value == "endobj") && (state == st_top))
  2432 + {
  2433 + // We just saw endobj without having read
  2434 + // anything. Treat this as a null and do not move
  2435 + // the input source's offset.
  2436 + object = newNull();
  2437 + input->seek(input->getLastOffset(), SEEK_SET);
2438 empty = true; 2438 empty = true;
2439 - }  
2440 - else  
2441 - { 2439 + }
  2440 + else
  2441 + {
2442 QTC::TC("qpdf", "QPDFObjectHandle treat word as string"); 2442 QTC::TC("qpdf", "QPDFObjectHandle treat word as string");
2443 warn(context, 2443 warn(context,
2444 QPDFExc(qpdf_e_damaged_pdf, input->getName(), 2444 QPDFExc(qpdf_e_damaged_pdf, input->getName(),
@@ -2448,13 +2448,13 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input, @@ -2448,13 +2448,13 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input,
2448 " treating as string")); 2448 " treating as string"));
2449 bad = true; 2449 bad = true;
2450 object = newString(value); 2450 object = newString(value);
2451 - }  
2452 - }  
2453 - break; 2451 + }
  2452 + }
  2453 + break;
2454 2454
2455 - case QPDFTokenizer::tt_string:  
2456 - {  
2457 - std::string val = token.getValue(); 2455 + case QPDFTokenizer::tt_string:
  2456 + {
  2457 + std::string val = token.getValue();
2458 if (decrypter) 2458 if (decrypter)
2459 { 2459 {
2460 if (b_contents) 2460 if (b_contents)
@@ -2465,12 +2465,12 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input, @@ -2465,12 +2465,12 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input,
2465 } 2465 }
2466 decrypter->decryptString(val); 2466 decrypter->decryptString(val);
2467 } 2467 }
2468 - object = QPDFObjectHandle::newString(val);  
2469 - } 2468 + object = QPDFObjectHandle::newString(val);
  2469 + }
2470 2470
2471 - break; 2471 + break;
2472 2472
2473 - default: 2473 + default:
2474 warn(context, 2474 warn(context,
2475 QPDFExc(qpdf_e_damaged_pdf, input->getName(), 2475 QPDFExc(qpdf_e_damaged_pdf, input->getName(),
2476 object_description, 2476 object_description,
@@ -2479,8 +2479,8 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input, @@ -2479,8 +2479,8 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input,
2479 "reading object")); 2479 "reading object"));
2480 bad = true; 2480 bad = true;
2481 object = newNull(); 2481 object = newNull();
2482 - break;  
2483 - } 2482 + break;
  2483 + }
2484 2484
2485 if ((! object.isInitialized()) && 2485 if ((! object.isInitialized()) &&
2486 (! ((state == st_start) || 2486 (! ((state == st_start) ||
@@ -2656,17 +2656,17 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input, @@ -2656,17 +2656,17 @@ QPDFObjectHandle::parseInternal(PointerHolder&lt;InputSource&gt; input,
2656 } 2656 }
2657 dict[key] = val; 2657 dict[key] = val;
2658 } 2658 }
2659 - if (!contents_string.empty() &&  
2660 - dict.count("/Type") && 2659 + if (!contents_string.empty() &&
  2660 + dict.count("/Type") &&
2661 dict["/Type"].isNameAndEquals("/Sig") && 2661 dict["/Type"].isNameAndEquals("/Sig") &&
2662 - dict.count("/ByteRange") &&  
2663 - dict.count("/Contents") &&  
2664 - dict["/Contents"].isString())  
2665 - {  
2666 - dict["/Contents"]  
2667 - = QPDFObjectHandle::newString(contents_string);  
2668 - dict["/Contents"].setParsedOffset(contents_offset);  
2669 - } 2662 + dict.count("/ByteRange") &&
  2663 + dict.count("/Contents") &&
  2664 + dict["/Contents"].isString())
  2665 + {
  2666 + dict["/Contents"]
  2667 + = QPDFObjectHandle::newString(contents_string);
  2668 + dict["/Contents"].setParsedOffset(contents_offset);
  2669 + }
2670 object = newDictionary(dict); 2670 object = newDictionary(dict);
2671 setObjectDescriptionFromInput( 2671 setObjectDescriptionFromInput(
2672 object, context, object_description, input, offset); 2672 object, context, object_description, input, offset);
@@ -2889,12 +2889,12 @@ QPDFObjectHandle::newDictionary( @@ -2889,12 +2889,12 @@ QPDFObjectHandle::newDictionary(
2889 2889
2890 QPDFObjectHandle 2890 QPDFObjectHandle
2891 QPDFObjectHandle::newStream(QPDF* qpdf, int objid, int generation, 2891 QPDFObjectHandle::newStream(QPDF* qpdf, int objid, int generation,
2892 - QPDFObjectHandle stream_dict,  
2893 - qpdf_offset_t offset, size_t length) 2892 + QPDFObjectHandle stream_dict,
  2893 + qpdf_offset_t offset, size_t length)
2894 { 2894 {
2895 QPDFObjectHandle result = QPDFObjectHandle(new QPDF_Stream( 2895 QPDFObjectHandle result = QPDFObjectHandle(new QPDF_Stream(
2896 - qpdf, objid, generation,  
2897 - stream_dict, offset, length)); 2896 + qpdf, objid, generation,
  2897 + stream_dict, offset, length));
2898 if (offset) 2898 if (offset)
2899 { 2899 {
2900 result.setParsedOffset(offset); 2900 result.setParsedOffset(offset);
@@ -2913,8 +2913,8 @@ QPDFObjectHandle::newStream(QPDF* qpdf) @@ -2913,8 +2913,8 @@ QPDFObjectHandle::newStream(QPDF* qpdf)
2913 QTC::TC("qpdf", "QPDFObjectHandle newStream"); 2913 QTC::TC("qpdf", "QPDFObjectHandle newStream");
2914 QPDFObjectHandle stream_dict = newDictionary(); 2914 QPDFObjectHandle stream_dict = newDictionary();
2915 QPDFObjectHandle result = qpdf->makeIndirectObject( 2915 QPDFObjectHandle result = qpdf->makeIndirectObject(
2916 - QPDFObjectHandle(  
2917 - new QPDF_Stream(qpdf, 0, 0, stream_dict, 0, 0))); 2916 + QPDFObjectHandle(
  2917 + new QPDF_Stream(qpdf, 0, 0, stream_dict, 0, 0)));
2918 result.dereference(); 2918 result.dereference();
2919 QPDF_Stream* stream = 2919 QPDF_Stream* stream =
2920 dynamic_cast<QPDF_Stream*>(result.obj.get()); 2920 dynamic_cast<QPDF_Stream*>(result.obj.get());
@@ -2946,7 +2946,7 @@ QPDFObjectHandle::newReserved(QPDF* qpdf) @@ -2946,7 +2946,7 @@ QPDFObjectHandle::newReserved(QPDF* qpdf)
2946 // Reserve a spot for this object by assigning it an object 2946 // Reserve a spot for this object by assigning it an object
2947 // number, but then return an unresolved handle to the object. 2947 // number, but then return an unresolved handle to the object.
2948 QPDFObjectHandle reserved = qpdf->makeIndirectObject( 2948 QPDFObjectHandle reserved = qpdf->makeIndirectObject(
2949 - QPDFObjectHandle(new QPDF_Reserved())); 2949 + QPDFObjectHandle(new QPDF_Reserved()));
2950 QPDFObjectHandle result = 2950 QPDFObjectHandle result =
2951 newIndirect(qpdf, reserved.objid, reserved.generation); 2951 newIndirect(qpdf, reserved.objid, reserved.generation);
2952 result.reserved = true; 2952 result.reserved = true;
@@ -3003,14 +3003,14 @@ QPDFObjectHandle::shallowCopyInternal(QPDFObjectHandle&amp; new_obj, @@ -3003,14 +3003,14 @@ QPDFObjectHandle::shallowCopyInternal(QPDFObjectHandle&amp; new_obj,
3003 3003
3004 if (isStream()) 3004 if (isStream())
3005 { 3005 {
3006 - QTC::TC("qpdf", "QPDFObjectHandle ERR shallow copy stream");  
3007 - throw std::runtime_error(  
3008 - "attempt to make a shallow copy of a stream"); 3006 + QTC::TC("qpdf", "QPDFObjectHandle ERR shallow copy stream");
  3007 + throw std::runtime_error(
  3008 + "attempt to make a shallow copy of a stream");
3009 } 3009 }
3010 3010
3011 if (isArray()) 3011 if (isArray())
3012 { 3012 {
3013 - QTC::TC("qpdf", "QPDFObjectHandle shallow copy array"); 3013 + QTC::TC("qpdf", "QPDFObjectHandle shallow copy array");
3014 // No newArray for shallow copying the sparse array 3014 // No newArray for shallow copying the sparse array
3015 QPDF_Array* arr = dynamic_cast<QPDF_Array*>(obj.get()); 3015 QPDF_Array* arr = dynamic_cast<QPDF_Array*>(obj.get());
3016 new_obj = QPDFObjectHandle( 3016 new_obj = QPDFObjectHandle(
@@ -3018,12 +3018,12 @@ QPDFObjectHandle::shallowCopyInternal(QPDFObjectHandle&amp; new_obj, @@ -3018,12 +3018,12 @@ QPDFObjectHandle::shallowCopyInternal(QPDFObjectHandle&amp; new_obj,
3018 } 3018 }
3019 else if (isDictionary()) 3019 else if (isDictionary())
3020 { 3020 {
3021 - QTC::TC("qpdf", "QPDFObjectHandle shallow copy dictionary"); 3021 + QTC::TC("qpdf", "QPDFObjectHandle shallow copy dictionary");
3022 new_obj = newDictionary(getDictAsMap()); 3022 new_obj = newDictionary(getDictAsMap());
3023 } 3023 }
3024 else 3024 else
3025 { 3025 {
3026 - QTC::TC("qpdf", "QPDFObjectHandle shallow copy scalar"); 3026 + QTC::TC("qpdf", "QPDFObjectHandle shallow copy scalar");
3027 new_obj = *this; 3027 new_obj = *this;
3028 } 3028 }
3029 3029
@@ -3040,27 +3040,27 @@ QPDFObjectHandle::copyObject(std::set&lt;QPDFObjGen&gt;&amp; visited, @@ -3040,27 +3040,27 @@ QPDFObjectHandle::copyObject(std::set&lt;QPDFObjGen&gt;&amp; visited,
3040 3040
3041 if (isStream()) 3041 if (isStream())
3042 { 3042 {
3043 - QTC::TC("qpdf", "QPDFObjectHandle copy stream", 3043 + QTC::TC("qpdf", "QPDFObjectHandle copy stream",
3044 stop_at_streams ? 0 : 1); 3044 stop_at_streams ? 0 : 1);
3045 if (stop_at_streams) 3045 if (stop_at_streams)
3046 { 3046 {
3047 return; 3047 return;
3048 } 3048 }
3049 - throw std::runtime_error(  
3050 - "attempt to make a stream into a direct object"); 3049 + throw std::runtime_error(
  3050 + "attempt to make a stream into a direct object");
3051 } 3051 }
3052 3052
3053 QPDFObjGen cur_og(this->objid, this->generation); 3053 QPDFObjGen cur_og(this->objid, this->generation);
3054 if (cur_og.getObj() != 0) 3054 if (cur_og.getObj() != 0)
3055 { 3055 {
3056 - if (visited.count(cur_og))  
3057 - {  
3058 - QTC::TC("qpdf", "QPDFObjectHandle makeDirect loop");  
3059 - throw std::runtime_error(  
3060 - "loop detected while converting object from "  
3061 - "indirect to direct");  
3062 - }  
3063 - visited.insert(cur_og); 3056 + if (visited.count(cur_og))
  3057 + {
  3058 + QTC::TC("qpdf", "QPDFObjectHandle makeDirect loop");
  3059 + throw std::runtime_error(
  3060 + "loop detected while converting object from "
  3061 + "indirect to direct");
  3062 + }
  3063 + visited.insert(cur_og);
3064 } 3064 }
3065 3065
3066 if (isReserved()) 3066 if (isReserved())
@@ -3079,42 +3079,42 @@ QPDFObjectHandle::copyObject(std::set&lt;QPDFObjGen&gt;&amp; visited, @@ -3079,42 +3079,42 @@ QPDFObjectHandle::copyObject(std::set&lt;QPDFObjGen&gt;&amp; visited,
3079 3079
3080 if (isBool()) 3080 if (isBool())
3081 { 3081 {
3082 - QTC::TC("qpdf", "QPDFObjectHandle clone bool");  
3083 - new_obj = PointerHolder<QPDFObject>(new QPDF_Bool(getBoolValue())); 3082 + QTC::TC("qpdf", "QPDFObjectHandle clone bool");
  3083 + new_obj = PointerHolder<QPDFObject>(new QPDF_Bool(getBoolValue()));
3084 } 3084 }
3085 else if (isNull()) 3085 else if (isNull())
3086 { 3086 {
3087 - QTC::TC("qpdf", "QPDFObjectHandle clone null");  
3088 - new_obj = PointerHolder<QPDFObject>(new QPDF_Null()); 3087 + QTC::TC("qpdf", "QPDFObjectHandle clone null");
  3088 + new_obj = PointerHolder<QPDFObject>(new QPDF_Null());
3089 } 3089 }
3090 else if (isInteger()) 3090 else if (isInteger())
3091 { 3091 {
3092 - QTC::TC("qpdf", "QPDFObjectHandle clone integer");  
3093 - new_obj = PointerHolder<QPDFObject>(new QPDF_Integer(getIntValue())); 3092 + QTC::TC("qpdf", "QPDFObjectHandle clone integer");
  3093 + new_obj = PointerHolder<QPDFObject>(new QPDF_Integer(getIntValue()));
3094 } 3094 }
3095 else if (isReal()) 3095 else if (isReal())
3096 { 3096 {
3097 - QTC::TC("qpdf", "QPDFObjectHandle clone real");  
3098 - new_obj = PointerHolder<QPDFObject>(new QPDF_Real(getRealValue())); 3097 + QTC::TC("qpdf", "QPDFObjectHandle clone real");
  3098 + new_obj = PointerHolder<QPDFObject>(new QPDF_Real(getRealValue()));
3099 } 3099 }
3100 else if (isName()) 3100 else if (isName())
3101 { 3101 {
3102 - QTC::TC("qpdf", "QPDFObjectHandle clone name");  
3103 - new_obj = PointerHolder<QPDFObject>(new QPDF_Name(getName())); 3102 + QTC::TC("qpdf", "QPDFObjectHandle clone name");
  3103 + new_obj = PointerHolder<QPDFObject>(new QPDF_Name(getName()));
3104 } 3104 }
3105 else if (isString()) 3105 else if (isString())
3106 { 3106 {
3107 - QTC::TC("qpdf", "QPDFObjectHandle clone string");  
3108 - new_obj = PointerHolder<QPDFObject>(new QPDF_String(getStringValue())); 3107 + QTC::TC("qpdf", "QPDFObjectHandle clone string");
  3108 + new_obj = PointerHolder<QPDFObject>(new QPDF_String(getStringValue()));
3109 } 3109 }
3110 else if (isArray()) 3110 else if (isArray())
3111 { 3111 {
3112 - QTC::TC("qpdf", "QPDFObjectHandle clone array");  
3113 - std::vector<QPDFObjectHandle> items;  
3114 - int n = getArrayNItems();  
3115 - for (int i = 0; i < n; ++i)  
3116 - {  
3117 - items.push_back(getArrayItem(i)); 3112 + QTC::TC("qpdf", "QPDFObjectHandle clone array");
  3113 + std::vector<QPDFObjectHandle> items;
  3114 + int n = getArrayNItems();
  3115 + for (int i = 0; i < n; ++i)
  3116 + {
  3117 + items.push_back(getArrayItem(i));
3118 if ((! first_level_only) && 3118 if ((! first_level_only) &&
3119 (cross_indirect || (! items.back().isIndirect()))) 3119 (cross_indirect || (! items.back().isIndirect())))
3120 { 3120 {
@@ -3122,18 +3122,18 @@ QPDFObjectHandle::copyObject(std::set&lt;QPDFObjGen&gt;&amp; visited, @@ -3122,18 +3122,18 @@ QPDFObjectHandle::copyObject(std::set&lt;QPDFObjGen&gt;&amp; visited,
3122 visited, cross_indirect, 3122 visited, cross_indirect,
3123 first_level_only, stop_at_streams); 3123 first_level_only, stop_at_streams);
3124 } 3124 }
3125 - }  
3126 - new_obj = PointerHolder<QPDFObject>(new QPDF_Array(items)); 3125 + }
  3126 + new_obj = PointerHolder<QPDFObject>(new QPDF_Array(items));
3127 } 3127 }
3128 else if (isDictionary()) 3128 else if (isDictionary())
3129 { 3129 {
3130 - QTC::TC("qpdf", "QPDFObjectHandle clone dictionary");  
3131 - std::set<std::string> keys = getKeys();  
3132 - std::map<std::string, QPDFObjectHandle> items;  
3133 - for (std::set<std::string>::iterator iter = keys.begin();  
3134 - iter != keys.end(); ++iter)  
3135 - {  
3136 - items[*iter] = getKey(*iter); 3130 + QTC::TC("qpdf", "QPDFObjectHandle clone dictionary");
  3131 + std::set<std::string> keys = getKeys();
  3132 + std::map<std::string, QPDFObjectHandle> items;
  3133 + for (std::set<std::string>::iterator iter = keys.begin();
  3134 + iter != keys.end(); ++iter)
  3135 + {
  3136 + items[*iter] = getKey(*iter);
3137 if ((! first_level_only) && 3137 if ((! first_level_only) &&
3138 (cross_indirect || (! items[*iter].isIndirect()))) 3138 (cross_indirect || (! items[*iter].isIndirect())))
3139 { 3139 {
@@ -3141,20 +3141,20 @@ QPDFObjectHandle::copyObject(std::set&lt;QPDFObjGen&gt;&amp; visited, @@ -3141,20 +3141,20 @@ QPDFObjectHandle::copyObject(std::set&lt;QPDFObjGen&gt;&amp; visited,
3141 visited, cross_indirect, 3141 visited, cross_indirect,
3142 first_level_only, stop_at_streams); 3142 first_level_only, stop_at_streams);
3143 } 3143 }
3144 - }  
3145 - new_obj = PointerHolder<QPDFObject>(new QPDF_Dictionary(items)); 3144 + }
  3145 + new_obj = PointerHolder<QPDFObject>(new QPDF_Dictionary(items));
3146 } 3146 }
3147 else 3147 else
3148 { 3148 {
3149 - throw std::logic_error("QPDFObjectHandle::makeDirectInternal: "  
3150 - "unknown object type"); 3149 + throw std::logic_error("QPDFObjectHandle::makeDirectInternal: "
  3150 + "unknown object type");
3151 } 3151 }
3152 3152
3153 this->obj = new_obj; 3153 this->obj = new_obj;
3154 3154
3155 if (cur_og.getObj()) 3155 if (cur_og.getObj())
3156 { 3156 {
3157 - visited.erase(cur_og); 3157 + visited.erase(cur_og);
3158 } 3158 }
3159 } 3159 }
3160 3160
@@ -3198,8 +3198,8 @@ QPDFObjectHandle::assertInitialized() const @@ -3198,8 +3198,8 @@ QPDFObjectHandle::assertInitialized() const
3198 { 3198 {
3199 if (! this->initialized) 3199 if (! this->initialized)
3200 { 3200 {
3201 - throw std::logic_error("operation attempted on uninitialized "  
3202 - "QPDFObjectHandle"); 3201 + throw std::logic_error("operation attempted on uninitialized "
  3202 + "QPDFObjectHandle");
3203 } 3203 }
3204 } 3204 }
3205 3205
@@ -3257,7 +3257,7 @@ QPDFObjectHandle::assertType(char const* type_name, bool istype) @@ -3257,7 +3257,7 @@ QPDFObjectHandle::assertType(char const* type_name, bool istype)
3257 { 3257 {
3258 if (! istype) 3258 if (! istype)
3259 { 3259 {
3260 - throw std::runtime_error(std::string("operation for ") + type_name + 3260 + throw std::runtime_error(std::string("operation for ") + type_name +
3261 " attempted on object of type " + 3261 " attempted on object of type " +
3262 getTypeName()); 3262 getTypeName());
3263 } 3263 }
@@ -3340,7 +3340,7 @@ QPDFObjectHandle::assertIndirect() @@ -3340,7 +3340,7 @@ QPDFObjectHandle::assertIndirect()
3340 { 3340 {
3341 if (! isIndirect()) 3341 if (! isIndirect())
3342 { 3342 {
3343 - throw std::logic_error( 3343 + throw std::logic_error(
3344 "operation for indirect object attempted on direct object"); 3344 "operation for indirect object attempted on direct object");
3345 } 3345 }
3346 } 3346 }
@@ -3437,7 +3437,7 @@ QPDFObjectHandle::assertPageObject() @@ -3437,7 +3437,7 @@ QPDFObjectHandle::assertPageObject()
3437 { 3437 {
3438 if (! isPageObject()) 3438 if (! isPageObject())
3439 { 3439 {
3440 - throw std::runtime_error("page operation called on non-Page object"); 3440 + throw std::runtime_error("page operation called on non-Page object");
3441 } 3441 }
3442 } 3442 }
3443 3443
@@ -3458,13 +3458,13 @@ QPDFObjectHandle::dereference() @@ -3458,13 +3458,13 @@ QPDFObjectHandle::dereference()
3458 if (this->obj.get() == 0) 3458 if (this->obj.get() == 0)
3459 { 3459 {
3460 PointerHolder<QPDFObject> obj = QPDF::Resolver::resolve( 3460 PointerHolder<QPDFObject> obj = QPDF::Resolver::resolve(
3461 - this->qpdf, this->objid, this->generation);  
3462 - if (obj.get() == 0)  
3463 - { 3461 + this->qpdf, this->objid, this->generation);
  3462 + if (obj.get() == 0)
  3463 + {
3464 // QPDF::resolve never returns an uninitialized object, but 3464 // QPDF::resolve never returns an uninitialized object, but
3465 // check just in case. 3465 // check just in case.
3466 - this->obj = PointerHolder<QPDFObject>(new QPDF_Null());  
3467 - } 3466 + this->obj = PointerHolder<QPDFObject>(new QPDF_Null());
  3467 + }
3468 else if (dynamic_cast<QPDF_Reserved*>(obj.get())) 3468 else if (dynamic_cast<QPDF_Reserved*>(obj.get()))
3469 { 3469 {
3470 // Do not resolve 3470 // Do not resolve
libqpdf/QPDFPageObjectHelper.cc
@@ -430,7 +430,7 @@ QPDFPageObjectHelper::forEachXObject( @@ -430,7 +430,7 @@ QPDFPageObjectHelper::forEachXObject(
430 queue.push_back(QPDFPageObjectHelper(obj)); 430 queue.push_back(QPDFPageObjectHelper(obj));
431 } 431 }
432 } 432 }
433 - } 433 + }
434 } 434 }
435 } 435 }
436 436
libqpdf/QPDFTokenizer.cc
@@ -240,9 +240,9 @@ QPDFTokenizer::presentCharacter(char ch) @@ -240,9 +240,9 @@ QPDFTokenizer::presentCharacter(char ch)
240 { 240 {
241 if (this->m->state == st_token_ready) 241 if (this->m->state == st_token_ready)
242 { 242 {
243 - throw std::logic_error(  
244 - "INTERNAL ERROR: QPDF tokenizer presented character "  
245 - "while token is waiting"); 243 + throw std::logic_error(
  244 + "INTERNAL ERROR: QPDF tokenizer presented character "
  245 + "while token is waiting");
246 } 246 }
247 247
248 char orig_ch = ch; 248 char orig_ch = ch;
@@ -254,87 +254,87 @@ QPDFTokenizer::presentCharacter(char ch) @@ -254,87 +254,87 @@ QPDFTokenizer::presentCharacter(char ch)
254 bool handled = true; 254 bool handled = true;
255 if (this->m->state == st_top) 255 if (this->m->state == st_top)
256 { 256 {
257 - // Note: we specifically do not use ctype here. It is  
258 - // locale-dependent.  
259 - if (isSpace(ch))  
260 - { 257 + // Note: we specifically do not use ctype here. It is
  258 + // locale-dependent.
  259 + if (isSpace(ch))
  260 + {
261 if (this->m->include_ignorable) 261 if (this->m->include_ignorable)
262 { 262 {
263 this->m->state = st_in_space; 263 this->m->state = st_in_space;
264 this->m->val += ch; 264 this->m->val += ch;
265 } 265 }
266 - }  
267 - else if (ch == '%')  
268 - {  
269 - this->m->state = st_in_comment; 266 + }
  267 + else if (ch == '%')
  268 + {
  269 + this->m->state = st_in_comment;
270 if (this->m->include_ignorable) 270 if (this->m->include_ignorable)
271 { 271 {
272 this->m->val += ch; 272 this->m->val += ch;
273 } 273 }
274 - }  
275 - else if (ch == '(')  
276 - {  
277 - this->m->string_depth = 1;  
278 - this->m->string_ignoring_newline = false;  
279 - memset(this->m->bs_num_register, '\0', 274 + }
  275 + else if (ch == '(')
  276 + {
  277 + this->m->string_depth = 1;
  278 + this->m->string_ignoring_newline = false;
  279 + memset(this->m->bs_num_register, '\0',
280 sizeof(this->m->bs_num_register)); 280 sizeof(this->m->bs_num_register));
281 - this->m->last_char_was_bs = false;  
282 - this->m->last_char_was_cr = false;  
283 - this->m->state = st_in_string;  
284 - }  
285 - else if (ch == '<')  
286 - {  
287 - this->m->state = st_lt;  
288 - }  
289 - else if (ch == '>')  
290 - {  
291 - this->m->state = st_gt;  
292 - }  
293 - else  
294 - {  
295 - this->m->val += ch;  
296 - if (ch == ')')  
297 - {  
298 - this->m->type = tt_bad;  
299 - QTC::TC("qpdf", "QPDFTokenizer bad )");  
300 - this->m->error_message = "unexpected )";  
301 - this->m->state = st_token_ready;  
302 - }  
303 - else if (ch == '[')  
304 - {  
305 - this->m->type = tt_array_open;  
306 - this->m->state = st_token_ready;  
307 - }  
308 - else if (ch == ']')  
309 - {  
310 - this->m->type = tt_array_close;  
311 - this->m->state = st_token_ready;  
312 - }  
313 - else if (ch == '{')  
314 - {  
315 - this->m->type = tt_brace_open;  
316 - this->m->state = st_token_ready;  
317 - }  
318 - else if (ch == '}')  
319 - {  
320 - this->m->type = tt_brace_close;  
321 - this->m->state = st_token_ready;  
322 - }  
323 - else  
324 - {  
325 - this->m->state = st_literal;  
326 - }  
327 - } 281 + this->m->last_char_was_bs = false;
  282 + this->m->last_char_was_cr = false;
  283 + this->m->state = st_in_string;
  284 + }
  285 + else if (ch == '<')
  286 + {
  287 + this->m->state = st_lt;
  288 + }
  289 + else if (ch == '>')
  290 + {
  291 + this->m->state = st_gt;
  292 + }
  293 + else
  294 + {
  295 + this->m->val += ch;
  296 + if (ch == ')')
  297 + {
  298 + this->m->type = tt_bad;
  299 + QTC::TC("qpdf", "QPDFTokenizer bad )");
  300 + this->m->error_message = "unexpected )";
  301 + this->m->state = st_token_ready;
  302 + }
  303 + else if (ch == '[')
  304 + {
  305 + this->m->type = tt_array_open;
  306 + this->m->state = st_token_ready;
  307 + }
  308 + else if (ch == ']')
  309 + {
  310 + this->m->type = tt_array_close;
  311 + this->m->state = st_token_ready;
  312 + }
  313 + else if (ch == '{')
  314 + {
  315 + this->m->type = tt_brace_open;
  316 + this->m->state = st_token_ready;
  317 + }
  318 + else if (ch == '}')
  319 + {
  320 + this->m->type = tt_brace_close;
  321 + this->m->state = st_token_ready;
  322 + }
  323 + else
  324 + {
  325 + this->m->state = st_literal;
  326 + }
  327 + }
328 } 328 }
329 else if (this->m->state == st_in_space) 329 else if (this->m->state == st_in_space)
330 { 330 {
331 // We only enter this state if include_ignorable is true. 331 // We only enter this state if include_ignorable is true.
332 if (! isSpace(ch)) 332 if (! isSpace(ch))
333 { 333 {
334 - this->m->type = tt_space;  
335 - this->m->unread_char = true;  
336 - this->m->char_to_unread = ch;  
337 - this->m->state = st_token_ready; 334 + this->m->type = tt_space;
  335 + this->m->unread_char = true;
  336 + this->m->char_to_unread = ch;
  337 + this->m->state = st_token_ready;
338 } 338 }
339 else 339 else
340 { 340 {
@@ -343,7 +343,7 @@ QPDFTokenizer::presentCharacter(char ch) @@ -343,7 +343,7 @@ QPDFTokenizer::presentCharacter(char ch)
343 } 343 }
344 else if (this->m->state == st_in_comment) 344 else if (this->m->state == st_in_comment)
345 { 345 {
346 - if ((ch == '\r') || (ch == '\n')) 346 + if ((ch == '\r') || (ch == '\n'))
347 { 347 {
348 if (this->m->include_ignorable) 348 if (this->m->include_ignorable)
349 { 349 {
@@ -364,124 +364,124 @@ QPDFTokenizer::presentCharacter(char ch) @@ -364,124 +364,124 @@ QPDFTokenizer::presentCharacter(char ch)
364 } 364 }
365 else if (this->m->state == st_lt) 365 else if (this->m->state == st_lt)
366 { 366 {
367 - if (ch == '<')  
368 - {  
369 - this->m->val = "<<";  
370 - this->m->type = tt_dict_open;  
371 - this->m->state = st_token_ready;  
372 - }  
373 - else  
374 - {  
375 - handled = false;  
376 - this->m->state = st_in_hexstring;  
377 - } 367 + if (ch == '<')
  368 + {
  369 + this->m->val = "<<";
  370 + this->m->type = tt_dict_open;
  371 + this->m->state = st_token_ready;
  372 + }
  373 + else
  374 + {
  375 + handled = false;
  376 + this->m->state = st_in_hexstring;
  377 + }
378 } 378 }
379 else if (this->m->state == st_gt) 379 else if (this->m->state == st_gt)
380 { 380 {
381 - if (ch == '>')  
382 - {  
383 - this->m->val = ">>";  
384 - this->m->type = tt_dict_close;  
385 - this->m->state = st_token_ready;  
386 - }  
387 - else  
388 - {  
389 - this->m->val = ">";  
390 - this->m->type = tt_bad;  
391 - QTC::TC("qpdf", "QPDFTokenizer bad >");  
392 - this->m->error_message = "unexpected >";  
393 - this->m->unread_char = true;  
394 - this->m->char_to_unread = ch;  
395 - this->m->state = st_token_ready;  
396 - } 381 + if (ch == '>')
  382 + {
  383 + this->m->val = ">>";
  384 + this->m->type = tt_dict_close;
  385 + this->m->state = st_token_ready;
  386 + }
  387 + else
  388 + {
  389 + this->m->val = ">";
  390 + this->m->type = tt_bad;
  391 + QTC::TC("qpdf", "QPDFTokenizer bad >");
  392 + this->m->error_message = "unexpected >";
  393 + this->m->unread_char = true;
  394 + this->m->char_to_unread = ch;
  395 + this->m->state = st_token_ready;
  396 + }
397 } 397 }
398 else if (this->m->state == st_in_string) 398 else if (this->m->state == st_in_string)
399 { 399 {
400 - if (this->m->string_ignoring_newline && (ch != '\n'))  
401 - {  
402 - this->m->string_ignoring_newline = false;  
403 - }  
404 -  
405 - size_t bs_num_count = strlen(this->m->bs_num_register);  
406 - bool ch_is_octal = ((ch >= '0') && (ch <= '7'));  
407 - if ((bs_num_count == 3) || ((bs_num_count > 0) && (! ch_is_octal)))  
408 - {  
409 - // We've accumulated \ddd. PDF Spec says to ignore  
410 - // high-order overflow.  
411 - this->m->val += static_cast<char>( 400 + if (this->m->string_ignoring_newline && (ch != '\n'))
  401 + {
  402 + this->m->string_ignoring_newline = false;
  403 + }
  404 +
  405 + size_t bs_num_count = strlen(this->m->bs_num_register);
  406 + bool ch_is_octal = ((ch >= '0') && (ch <= '7'));
  407 + if ((bs_num_count == 3) || ((bs_num_count > 0) && (! ch_is_octal)))
  408 + {
  409 + // We've accumulated \ddd. PDF Spec says to ignore
  410 + // high-order overflow.
  411 + this->m->val += static_cast<char>(
412 strtol(this->m->bs_num_register, 0, 8)); 412 strtol(this->m->bs_num_register, 0, 8));
413 - memset(this->m->bs_num_register, ' memset(this->m->bs_num_register, '\0',', 413 + memset(this->m->bs_num_register, ' memset(this->m->bs_num_register, '\0',',
414 sizeof(this->m->bs_num_register)); 414 sizeof(this->m->bs_num_register));
415 - bs_num_count = 0;  
416 - } 415 + bs_num_count = 0;
  416 + }
417 417
418 - if (this->m->string_ignoring_newline && (ch == '\n'))  
419 - {  
420 - // ignore 418 + if (this->m->string_ignoring_newline && (ch == '\n'))
  419 + {
  420 + // ignore
421 this->m->string_ignoring_newline = false; 421 this->m->string_ignoring_newline = false;
422 - }  
423 - else if (ch_is_octal && 422 + }
  423 + else if (ch_is_octal &&
424 (this->m->last_char_was_bs || (bs_num_count > 0))) 424 (this->m->last_char_was_bs || (bs_num_count > 0)))
425 - {  
426 - this->m->bs_num_register[bs_num_count++] = ch;  
427 - }  
428 - else if (this->m->last_char_was_bs)  
429 - {  
430 - switch (ch)  
431 - {  
432 - case 'n':  
433 - this->m->val += '\n';  
434 - break;  
435 -  
436 - case 'r':  
437 - this->m->val += '\r';  
438 - break;  
439 -  
440 - case 't':  
441 - this->m->val += '\t';  
442 - break;  
443 -  
444 - case 'b':  
445 - this->m->val += '\b';  
446 - break;  
447 -  
448 - case 'f':  
449 - this->m->val += '\f';  
450 - break;  
451 -  
452 - case '\n': 425 + {
  426 + this->m->bs_num_register[bs_num_count++] = ch;
  427 + }
  428 + else if (this->m->last_char_was_bs)
  429 + {
  430 + switch (ch)
  431 + {
  432 + case 'n':
  433 + this->m->val += '\n';
453 break; 434 break;
454 435
455 - case '\r':  
456 - this->m->string_ignoring_newline = true;  
457 - break;  
458 -  
459 - default:  
460 - // PDF spec says backslash is ignored before anything else  
461 - this->m->val += ch;  
462 - break;  
463 - }  
464 - }  
465 - else if (ch == '\\')  
466 - {  
467 - // last_char_was_bs is set/cleared below as appropriate  
468 - if (bs_num_count)  
469 - {  
470 - throw std::logic_error(  
471 - "INTERNAL ERROR: QPDFTokenizer: bs_num_count != 0 "  
472 - "when ch == '\\'");  
473 - }  
474 - }  
475 - else if (ch == '(')  
476 - {  
477 - this->m->val += ch;  
478 - ++this->m->string_depth;  
479 - }  
480 - else if ((ch == ')') && (--this->m->string_depth == 0))  
481 - {  
482 - this->m->type = tt_string;  
483 - this->m->state = st_token_ready;  
484 - } 436 + case 'r':
  437 + this->m->val += '\r';
  438 + break;
  439 +
  440 + case 't':
  441 + this->m->val += '\t';
  442 + break;
  443 +
  444 + case 'b':
  445 + this->m->val += '\b';
  446 + break;
  447 +
  448 + case 'f':
  449 + this->m->val += '\f';
  450 + break;
  451 +
  452 + case '\n':
  453 + break;
  454 +
  455 + case '\r':
  456 + this->m->string_ignoring_newline = true;
  457 + break;
  458 +
  459 + default:
  460 + // PDF spec says backslash is ignored before anything else
  461 + this->m->val += ch;
  462 + break;
  463 + }
  464 + }
  465 + else if (ch == '\\')
  466 + {
  467 + // last_char_was_bs is set/cleared below as appropriate
  468 + if (bs_num_count)
  469 + {
  470 + throw std::logic_error(
  471 + "INTERNAL ERROR: QPDFTokenizer: bs_num_count != 0 "
  472 + "when ch == '\\'");
  473 + }
  474 + }
  475 + else if (ch == '(')
  476 + {
  477 + this->m->val += ch;
  478 + ++this->m->string_depth;
  479 + }
  480 + else if ((ch == ')') && (--this->m->string_depth == 0))
  481 + {
  482 + this->m->type = tt_string;
  483 + this->m->state = st_token_ready;
  484 + }
485 else if (ch == '\r') 485 else if (ch == '\r')
486 { 486 {
487 // CR by itself is converted to LF 487 // CR by itself is converted to LF
@@ -495,37 +495,37 @@ QPDFTokenizer::presentCharacter(char ch) @@ -495,37 +495,37 @@ QPDFTokenizer::presentCharacter(char ch)
495 this->m->val += ch; 495 this->m->val += ch;
496 } 496 }
497 } 497 }
498 - else  
499 - {  
500 - this->m->val += ch;  
501 - } 498 + else
  499 + {
  500 + this->m->val += ch;
  501 + }
502 502
503 this->m->last_char_was_cr = 503 this->m->last_char_was_cr =
504 ((! this->m->string_ignoring_newline) && (ch == '\r')); 504 ((! this->m->string_ignoring_newline) && (ch == '\r'));
505 - this->m->last_char_was_bs = 505 + this->m->last_char_was_bs =
506 ((! this->m->last_char_was_bs) && (ch == '\\')); 506 ((! this->m->last_char_was_bs) && (ch == '\\'));
507 } 507 }
508 else if (this->m->state == st_literal) 508 else if (this->m->state == st_literal)
509 { 509 {
510 - if (isDelimiter(ch))  
511 - {  
512 - // A C-locale whitespace character or delimiter terminates  
513 - // token. It is important to unread the whitespace  
514 - // character even though it is ignored since it may be the  
515 - // newline after a stream keyword. Removing it here could  
516 - // make the stream-reading code break on some files,  
517 - // though not on any files in the test suite as of this  
518 - // writing.  
519 -  
520 - this->m->type = tt_word;  
521 - this->m->unread_char = true;  
522 - this->m->char_to_unread = ch;  
523 - this->m->state = st_token_ready;  
524 - }  
525 - else  
526 - {  
527 - this->m->val += ch;  
528 - } 510 + if (isDelimiter(ch))
  511 + {
  512 + // A C-locale whitespace character or delimiter terminates
  513 + // token. It is important to unread the whitespace
  514 + // character even though it is ignored since it may be the
  515 + // newline after a stream keyword. Removing it here could
  516 + // make the stream-reading code break on some files,
  517 + // though not on any files in the test suite as of this
  518 + // writing.
  519 +
  520 + this->m->type = tt_word;
  521 + this->m->unread_char = true;
  522 + this->m->char_to_unread = ch;
  523 + this->m->state = st_token_ready;
  524 + }
  525 + else
  526 + {
  527 + this->m->val += ch;
  528 + }
529 } 529 }
530 else if (this->m->state == st_inline_image) 530 else if (this->m->state == st_inline_image)
531 { 531 {
@@ -541,58 +541,58 @@ QPDFTokenizer::presentCharacter(char ch) @@ -541,58 +541,58 @@ QPDFTokenizer::presentCharacter(char ch)
541 } 541 }
542 else 542 else
543 { 543 {
544 - handled = false; 544 + handled = false;
545 } 545 }
546 546
547 if (handled) 547 if (handled)
548 { 548 {
549 - // okay 549 + // okay
550 } 550 }
551 else if (this->m->state == st_in_hexstring) 551 else if (this->m->state == st_in_hexstring)
552 { 552 {
553 - if (ch == '>')  
554 - {  
555 - this->m->type = tt_string;  
556 - this->m->state = st_token_ready;  
557 - if (this->m->val.length() % 2)  
558 - {  
559 - // PDF spec says odd hexstrings have implicit  
560 - // trailing 0.  
561 - this->m->val += '0';  
562 - }  
563 - char num[3];  
564 - num[2] = '\0';  
565 - std::string nval;  
566 - for (unsigned int i = 0; i < this->m->val.length(); i += 2)  
567 - {  
568 - num[0] = this->m->val.at(i);  
569 - num[1] = this->m->val.at(i+1);  
570 - char nch = static_cast<char>(strtol(num, 0, 16));  
571 - nval += nch;  
572 - }  
573 - this->m->val = nval;  
574 - }  
575 - else if (QUtil::is_hex_digit(ch))  
576 - {  
577 - this->m->val += ch;  
578 - }  
579 - else if (isSpace(ch))  
580 - {  
581 - // ignore  
582 - }  
583 - else  
584 - {  
585 - this->m->type = tt_bad;  
586 - QTC::TC("qpdf", "QPDFTokenizer bad hexstring character");  
587 - this->m->error_message = std::string("invalid character (") +  
588 - ch + ") in hexstring";  
589 - this->m->state = st_token_ready;  
590 - } 553 + if (ch == '>')
  554 + {
  555 + this->m->type = tt_string;
  556 + this->m->state = st_token_ready;
  557 + if (this->m->val.length() % 2)
  558 + {
  559 + // PDF spec says odd hexstrings have implicit
  560 + // trailing 0.
  561 + this->m->val += '0';
  562 + }
  563 + char num[3];
  564 + num[2] = '\0';
  565 + std::string nval;
  566 + for (unsigned int i = 0; i < this->m->val.length(); i += 2)
  567 + {
  568 + num[0] = this->m->val.at(i);
  569 + num[1] = this->m->val.at(i+1);
  570 + char nch = static_cast<char>(strtol(num, 0, 16));
  571 + nval += nch;
  572 + }
  573 + this->m->val = nval;
  574 + }
  575 + else if (QUtil::is_hex_digit(ch))
  576 + {
  577 + this->m->val += ch;
  578 + }
  579 + else if (isSpace(ch))
  580 + {
  581 + // ignore
  582 + }
  583 + else
  584 + {
  585 + this->m->type = tt_bad;
  586 + QTC::TC("qpdf", "QPDFTokenizer bad hexstring character");
  587 + this->m->error_message = std::string("invalid character (") +
  588 + ch + ") in hexstring";
  589 + this->m->state = st_token_ready;
  590 + }
591 } 591 }
592 else 592 else
593 { 593 {
594 - throw std::logic_error(  
595 - "INTERNAL ERROR: invalid state while reading token"); 594 + throw std::logic_error(
  595 + "INTERNAL ERROR: invalid state while reading token");
596 } 596 }
597 597
598 if ((this->m->state == st_token_ready) && (this->m->type == tt_word)) 598 if ((this->m->state == st_token_ready) && (this->m->type == tt_word))
@@ -603,7 +603,7 @@ QPDFTokenizer::presentCharacter(char ch) @@ -603,7 +603,7 @@ QPDFTokenizer::presentCharacter(char ch)
603 if (! (betweenTokens() || 603 if (! (betweenTokens() ||
604 ((this->m->state == st_token_ready) && this->m->unread_char))) 604 ((this->m->state == st_token_ready) && this->m->unread_char)))
605 { 605 {
606 - this->m->raw_val += orig_ch; 606 + this->m->raw_val += orig_ch;
607 } 607 }
608 } 608 }
609 609
@@ -782,9 +782,9 @@ QPDFTokenizer::getToken(Token&amp; token, bool&amp; unread_char, char&amp; ch) @@ -782,9 +782,9 @@ QPDFTokenizer::getToken(Token&amp; token, bool&amp; unread_char, char&amp; ch)
782 { 782 {
783 this->m->val = this->m->raw_val; 783 this->m->val = this->m->raw_val;
784 } 784 }
785 - token = Token(this->m->type, this->m->val, 785 + token = Token(this->m->type, this->m->val,
786 this->m->raw_val, this->m->error_message); 786 this->m->raw_val, this->m->error_message);
787 - this->m->reset(); 787 + this->m->reset();
788 } 788 }
789 return ready; 789 return ready;
790 } 790 }
@@ -811,9 +811,9 @@ QPDFTokenizer::readToken(PointerHolder&lt;InputSource&gt; input, @@ -811,9 +811,9 @@ QPDFTokenizer::readToken(PointerHolder&lt;InputSource&gt; input,
811 bool presented_eof = false; 811 bool presented_eof = false;
812 while (! getToken(token, unread_char, char_to_unread)) 812 while (! getToken(token, unread_char, char_to_unread))
813 { 813 {
814 - char ch;  
815 - if (input->read(&ch, 1) == 0)  
816 - { 814 + char ch;
  815 + if (input->read(&ch, 1) == 0)
  816 + {
817 if (! presented_eof) 817 if (! presented_eof)
818 { 818 {
819 presentEOF(); 819 presentEOF();
@@ -833,14 +833,14 @@ QPDFTokenizer::readToken(PointerHolder&lt;InputSource&gt; input, @@ -833,14 +833,14 @@ QPDFTokenizer::readToken(PointerHolder&lt;InputSource&gt; input,
833 throw std::logic_error( 833 throw std::logic_error(
834 "getToken returned false after presenting EOF"); 834 "getToken returned false after presenting EOF");
835 } 835 }
836 - }  
837 - else  
838 - {  
839 - presentCharacter(ch);  
840 - if (betweenTokens() && (input->getLastOffset() == offset))  
841 - {  
842 - ++offset;  
843 - } 836 + }
  837 + else
  838 + {
  839 + presentCharacter(ch);
  840 + if (betweenTokens() && (input->getLastOffset() == offset))
  841 + {
  842 + ++offset;
  843 + }
844 if (max_len && (this->m->raw_val.length() >= max_len) && 844 if (max_len && (this->m->raw_val.length() >= max_len) &&
845 (this->m->state != st_token_ready)) 845 (this->m->state != st_token_ready))
846 { 846 {
@@ -851,12 +851,12 @@ QPDFTokenizer::readToken(PointerHolder&lt;InputSource&gt; input, @@ -851,12 +851,12 @@ QPDFTokenizer::readToken(PointerHolder&lt;InputSource&gt; input,
851 this->m->error_message = 851 this->m->error_message =
852 "exceeded allowable length while reading token"; 852 "exceeded allowable length while reading token";
853 } 853 }
854 - } 854 + }
855 } 855 }
856 856
857 if (unread_char) 857 if (unread_char)
858 { 858 {
859 - input->unreadCh(char_to_unread); 859 + input->unreadCh(char_to_unread);
860 } 860 }
861 861
862 if (token.getType() != tt_eof) 862 if (token.getType() != tt_eof)
libqpdf/QPDFWriter.cc
@@ -78,7 +78,7 @@ QPDFWriter::Members::~Members() @@ -78,7 +78,7 @@ QPDFWriter::Members::~Members()
78 { 78 {
79 if (file && close_file) 79 if (file && close_file)
80 { 80 {
81 - fclose(file); 81 + fclose(file);
82 } 82 }
83 delete output_buffer; 83 delete output_buffer;
84 } 84 }
@@ -113,16 +113,16 @@ QPDFWriter::setOutputFilename(char const* filename) @@ -113,16 +113,16 @@ QPDFWriter::setOutputFilename(char const* filename)
113 bool close_file = false; 113 bool close_file = false;
114 if (filename == 0) 114 if (filename == 0)
115 { 115 {
116 - description = "standard output";  
117 - QTC::TC("qpdf", "QPDFWriter write to stdout");  
118 - f = stdout;  
119 - QUtil::binary_stdout(); 116 + description = "standard output";
  117 + QTC::TC("qpdf", "QPDFWriter write to stdout");
  118 + f = stdout;
  119 + QUtil::binary_stdout();
120 } 120 }
121 else 121 else
122 { 122 {
123 - QTC::TC("qpdf", "QPDFWriter write to file");  
124 - f = QUtil::safe_fopen(filename, "wb+");  
125 - close_file = true; 123 + QTC::TC("qpdf", "QPDFWriter write to file");
  124 + f = QUtil::safe_fopen(filename, "wb+");
  125 + close_file = true;
126 } 126 }
127 setOutputFile(description, f, close_file); 127 setOutputFile(description, f, close_file);
128 } 128 }
@@ -256,26 +256,26 @@ QPDFWriter::setMinimumPDFVersion(std::string const&amp; version, @@ -256,26 +256,26 @@ QPDFWriter::setMinimumPDFVersion(std::string const&amp; version,
256 bool set_extension_level = false; 256 bool set_extension_level = false;
257 if (this->m->min_pdf_version.empty()) 257 if (this->m->min_pdf_version.empty())
258 { 258 {
259 - set_version = true; 259 + set_version = true;
260 set_extension_level = true; 260 set_extension_level = true;
261 } 261 }
262 else 262 else
263 { 263 {
264 - int old_major = 0;  
265 - int old_minor = 0;  
266 - int min_major = 0;  
267 - int min_minor = 0;  
268 - parseVersion(version, old_major, old_minor);  
269 - parseVersion(this->m->min_pdf_version, min_major, min_minor); 264 + int old_major = 0;
  265 + int old_minor = 0;
  266 + int min_major = 0;
  267 + int min_minor = 0;
  268 + parseVersion(version, old_major, old_minor);
  269 + parseVersion(this->m->min_pdf_version, min_major, min_minor);
270 int compare = compareVersions( 270 int compare = compareVersions(
271 old_major, old_minor, min_major, min_minor); 271 old_major, old_minor, min_major, min_minor);
272 - if (compare > 0)  
273 - {  
274 - QTC::TC("qpdf", "QPDFWriter increasing minimum version", 272 + if (compare > 0)
  273 + {
  274 + QTC::TC("qpdf", "QPDFWriter increasing minimum version",
275 extension_level == 0 ? 0 : 1); 275 extension_level == 0 ? 0 : 1);
276 - set_version = true; 276 + set_version = true;
277 set_extension_level = true; 277 set_extension_level = true;
278 - } 278 + }
279 else if (compare == 0) 279 else if (compare == 0)
280 { 280 {
281 if (extension_level > this->m->min_extension_level) 281 if (extension_level > this->m->min_extension_level)
@@ -283,12 +283,12 @@ QPDFWriter::setMinimumPDFVersion(std::string const&amp; version, @@ -283,12 +283,12 @@ QPDFWriter::setMinimumPDFVersion(std::string const&amp; version,
283 QTC::TC("qpdf", "QPDFWriter increasing extension level"); 283 QTC::TC("qpdf", "QPDFWriter increasing extension level");
284 set_extension_level = true; 284 set_extension_level = true;
285 } 285 }
286 - } 286 + }
287 } 287 }
288 288
289 if (set_version) 289 if (set_version)
290 { 290 {
291 - this->m->min_pdf_version = version; 291 + this->m->min_pdf_version = version;
292 } 292 }
293 if (set_extension_level) 293 if (set_extension_level)
294 { 294 {
@@ -337,7 +337,7 @@ QPDFWriter::setStaticAesIV(bool val) @@ -337,7 +337,7 @@ QPDFWriter::setStaticAesIV(bool val)
337 { 337 {
338 if (val) 338 if (val)
339 { 339 {
340 - Pl_AES_PDF::useStaticIV(); 340 + Pl_AES_PDF::useStaticIV();
341 } 341 }
342 } 342 }
343 343
@@ -388,19 +388,19 @@ QPDFWriter::setR2EncryptionParameters( @@ -388,19 +388,19 @@ QPDFWriter::setR2EncryptionParameters(
388 std::set<int> clear; 388 std::set<int> clear;
389 if (! allow_print) 389 if (! allow_print)
390 { 390 {
391 - clear.insert(3); 391 + clear.insert(3);
392 } 392 }
393 if (! allow_modify) 393 if (! allow_modify)
394 { 394 {
395 - clear.insert(4); 395 + clear.insert(4);
396 } 396 }
397 if (! allow_extract) 397 if (! allow_extract)
398 { 398 {
399 - clear.insert(5); 399 + clear.insert(5);
400 } 400 }
401 if (! allow_annotate) 401 if (! allow_annotate)
402 { 402 {
403 - clear.insert(6); 403 + clear.insert(6);
404 } 404 }
405 405
406 setEncryptionParameters(user_password, owner_password, 1, 2, 5, clear); 406 setEncryptionParameters(user_password, owner_password, 1, 2, 5, clear);
@@ -414,8 +414,8 @@ QPDFWriter::setR3EncryptionParameters( @@ -414,8 +414,8 @@ QPDFWriter::setR3EncryptionParameters(
414 { 414 {
415 std::set<int> clear; 415 std::set<int> clear;
416 interpretR3EncryptionParameters( 416 interpretR3EncryptionParameters(
417 - clear, user_password, owner_password,  
418 - allow_accessibility, allow_extract, 417 + clear, user_password, owner_password,
  418 + allow_accessibility, allow_extract,
419 true, true, true, true, print, modify); 419 true, true, true, true, print, modify);
420 setEncryptionParameters(user_password, owner_password, 2, 3, 16, clear); 420 setEncryptionParameters(user_password, owner_password, 2, 3, 16, clear);
421 } 421 }
@@ -430,8 +430,8 @@ QPDFWriter::setR3EncryptionParameters( @@ -430,8 +430,8 @@ QPDFWriter::setR3EncryptionParameters(
430 { 430 {
431 std::set<int> clear; 431 std::set<int> clear;
432 interpretR3EncryptionParameters( 432 interpretR3EncryptionParameters(
433 - clear, user_password, owner_password,  
434 - allow_accessibility, allow_extract, 433 + clear, user_password, owner_password,
  434 + allow_accessibility, allow_extract,
435 allow_assemble, allow_annotate_and_form, 435 allow_assemble, allow_annotate_and_form,
436 allow_form_filling, allow_modify_other, 436 allow_form_filling, allow_modify_other,
437 print, qpdf_r3m_all); 437 print, qpdf_r3m_all);
@@ -447,8 +447,8 @@ QPDFWriter::setR4EncryptionParameters( @@ -447,8 +447,8 @@ QPDFWriter::setR4EncryptionParameters(
447 { 447 {
448 std::set<int> clear; 448 std::set<int> clear;
449 interpretR3EncryptionParameters( 449 interpretR3EncryptionParameters(
450 - clear, user_password, owner_password,  
451 - allow_accessibility, allow_extract, 450 + clear, user_password, owner_password,
  451 + allow_accessibility, allow_extract,
452 true, true, true, true, print, modify); 452 true, true, true, true, print, modify);
453 this->m->encrypt_use_aes = use_aes; 453 this->m->encrypt_use_aes = use_aes;
454 this->m->encrypt_metadata = encrypt_metadata; 454 this->m->encrypt_metadata = encrypt_metadata;
@@ -466,8 +466,8 @@ QPDFWriter::setR4EncryptionParameters( @@ -466,8 +466,8 @@ QPDFWriter::setR4EncryptionParameters(
466 { 466 {
467 std::set<int> clear; 467 std::set<int> clear;
468 interpretR3EncryptionParameters( 468 interpretR3EncryptionParameters(
469 - clear, user_password, owner_password,  
470 - allow_accessibility, allow_extract, 469 + clear, user_password, owner_password,
  470 + allow_accessibility, allow_extract,
471 allow_assemble, allow_annotate_and_form, 471 allow_assemble, allow_annotate_and_form,
472 allow_form_filling, allow_modify_other, 472 allow_form_filling, allow_modify_other,
473 print, qpdf_r3m_all); 473 print, qpdf_r3m_all);
@@ -485,8 +485,8 @@ QPDFWriter::setR5EncryptionParameters( @@ -485,8 +485,8 @@ QPDFWriter::setR5EncryptionParameters(
485 { 485 {
486 std::set<int> clear; 486 std::set<int> clear;
487 interpretR3EncryptionParameters( 487 interpretR3EncryptionParameters(
488 - clear, user_password, owner_password,  
489 - allow_accessibility, allow_extract, 488 + clear, user_password, owner_password,
  489 + allow_accessibility, allow_extract,
490 true, true, true, true, print, modify); 490 true, true, true, true, print, modify);
491 this->m->encrypt_use_aes = true; 491 this->m->encrypt_use_aes = true;
492 this->m->encrypt_metadata = encrypt_metadata; 492 this->m->encrypt_metadata = encrypt_metadata;
@@ -504,8 +504,8 @@ QPDFWriter::setR5EncryptionParameters( @@ -504,8 +504,8 @@ QPDFWriter::setR5EncryptionParameters(
504 { 504 {
505 std::set<int> clear; 505 std::set<int> clear;
506 interpretR3EncryptionParameters( 506 interpretR3EncryptionParameters(
507 - clear, user_password, owner_password,  
508 - allow_accessibility, allow_extract, 507 + clear, user_password, owner_password,
  508 + allow_accessibility, allow_extract,
509 allow_assemble, allow_annotate_and_form, 509 allow_assemble, allow_annotate_and_form,
510 allow_form_filling, allow_modify_other, 510 allow_form_filling, allow_modify_other,
511 print, qpdf_r3m_all); 511 print, qpdf_r3m_all);
@@ -523,8 +523,8 @@ QPDFWriter::setR6EncryptionParameters( @@ -523,8 +523,8 @@ QPDFWriter::setR6EncryptionParameters(
523 { 523 {
524 std::set<int> clear; 524 std::set<int> clear;
525 interpretR3EncryptionParameters( 525 interpretR3EncryptionParameters(
526 - clear, user_password, owner_password,  
527 - allow_accessibility, allow_extract, 526 + clear, user_password, owner_password,
  527 + allow_accessibility, allow_extract,
528 true, true, true, true, print, modify); 528 true, true, true, true, print, modify);
529 this->m->encrypt_use_aes = true; 529 this->m->encrypt_use_aes = true;
530 this->m->encrypt_metadata = encrypt_metadata; 530 this->m->encrypt_metadata = encrypt_metadata;
@@ -542,8 +542,8 @@ QPDFWriter::setR6EncryptionParameters( @@ -542,8 +542,8 @@ QPDFWriter::setR6EncryptionParameters(
542 { 542 {
543 std::set<int> clear; 543 std::set<int> clear;
544 interpretR3EncryptionParameters( 544 interpretR3EncryptionParameters(
545 - clear, user_password, owner_password,  
546 - allow_accessibility, allow_extract, 545 + clear, user_password, owner_password,
  546 + allow_accessibility, allow_extract,
547 allow_assemble, allow_annotate_and_form, 547 allow_assemble, allow_annotate_and_form,
548 allow_form_filling, allow_modify_other, 548 allow_form_filling, allow_modify_other,
549 print, qpdf_r3m_all); 549 print, qpdf_r3m_all);
@@ -594,11 +594,11 @@ QPDFWriter::interpretR3EncryptionParameters( @@ -594,11 +594,11 @@ QPDFWriter::interpretR3EncryptionParameters(
594 if (! allow_accessibility) 594 if (! allow_accessibility)
595 { 595 {
596 // setEncryptionParameters sets this if R > 3 596 // setEncryptionParameters sets this if R > 3
597 - clear.insert(10); 597 + clear.insert(10);
598 } 598 }
599 if (! allow_extract) 599 if (! allow_extract)
600 { 600 {
601 - clear.insert(5); 601 + clear.insert(5);
602 } 602 }
603 603
604 // Note: these switch statements all "fall through" (no break 604 // Note: these switch statements all "fall through" (no break
@@ -606,15 +606,15 @@ QPDFWriter::interpretR3EncryptionParameters( @@ -606,15 +606,15 @@ QPDFWriter::interpretR3EncryptionParameters(
606 switch (print) 606 switch (print)
607 { 607 {
608 case qpdf_r3p_none: 608 case qpdf_r3p_none:
609 - clear.insert(3); // any printing 609 + clear.insert(3); // any printing
610 610
611 case qpdf_r3p_low: 611 case qpdf_r3p_low:
612 - clear.insert(12); // high resolution printing 612 + clear.insert(12); // high resolution printing
613 613
614 case qpdf_r3p_full: 614 case qpdf_r3p_full:
615 - break; 615 + break;
616 616
617 - // no default so gcc warns for missing cases 617 + // no default so gcc warns for missing cases
618 } 618 }
619 619
620 // Modify options. The qpdf_r3_modify_e options control groups of 620 // Modify options. The qpdf_r3_modify_e options control groups of
@@ -627,21 +627,21 @@ QPDFWriter::interpretR3EncryptionParameters( @@ -627,21 +627,21 @@ QPDFWriter::interpretR3EncryptionParameters(
627 switch (modify) 627 switch (modify)
628 { 628 {
629 case qpdf_r3m_none: 629 case qpdf_r3m_none:
630 - clear.insert(11); // document assembly 630 + clear.insert(11); // document assembly
631 631
632 case qpdf_r3m_assembly: 632 case qpdf_r3m_assembly:
633 - clear.insert(9); // filling in form fields 633 + clear.insert(9); // filling in form fields
634 634
635 case qpdf_r3m_form: 635 case qpdf_r3m_form:
636 - clear.insert(6); // modify annotations, fill in form fields 636 + clear.insert(6); // modify annotations, fill in form fields
637 637
638 case qpdf_r3m_annotate: 638 case qpdf_r3m_annotate:
639 - clear.insert(4); // other modifications 639 + clear.insert(4); // other modifications
640 640
641 case qpdf_r3m_all: 641 case qpdf_r3m_all:
642 - break; 642 + break;
643 643
644 - // no default so gcc warns for missing cases 644 + // no default so gcc warns for missing cases
645 } 645 }
646 // END NOT EXERCISED IN TEST SUITE 646 // END NOT EXERCISED IN TEST SUITE
647 647
@@ -686,9 +686,9 @@ QPDFWriter::setEncryptionParameters( @@ -686,9 +686,9 @@ QPDFWriter::setEncryptionParameters(
686 int P = 0; 686 int P = 0;
687 // Create the complement of P, then invert. 687 // Create the complement of P, then invert.
688 for (std::set<int>::iterator iter = bits_to_clear.begin(); 688 for (std::set<int>::iterator iter = bits_to_clear.begin();
689 - iter != bits_to_clear.end(); ++iter) 689 + iter != bits_to_clear.end(); ++iter)
690 { 690 {
691 - P |= (1 << ((*iter) - 1)); 691 + P |= (1 << ((*iter) - 1));
692 } 692 }
693 P = ~P; 693 P = ~P;
694 694
@@ -713,7 +713,7 @@ QPDFWriter::setEncryptionParameters( @@ -713,7 +713,7 @@ QPDFWriter::setEncryptionParameters(
713 encryption_key, O, U, OE, UE, Perms); 713 encryption_key, O, U, OE, UE, Perms);
714 } 714 }
715 setEncryptionParametersInternal( 715 setEncryptionParametersInternal(
716 - V, R, key_len, P, O, U, OE, UE, Perms, 716 + V, R, key_len, P, O, U, OE, UE, Perms,
717 this->m->id1, user_password, encryption_key); 717 this->m->id1, user_password, encryption_key);
718 } 718 }
719 719
@@ -727,19 +727,19 @@ QPDFWriter::copyEncryptionParameters(QPDF&amp; qpdf) @@ -727,19 +727,19 @@ QPDFWriter::copyEncryptionParameters(QPDF&amp; qpdf)
727 generateID(); 727 generateID();
728 this->m->id1 = 728 this->m->id1 =
729 trailer.getKey("/ID").getArrayItem(0).getStringValue(); 729 trailer.getKey("/ID").getArrayItem(0).getStringValue();
730 - QPDFObjectHandle encrypt = trailer.getKey("/Encrypt");  
731 - int V = encrypt.getKey("/V").getIntValueAsInt();  
732 - int key_len = 5;  
733 - if (V > 1)  
734 - {  
735 - key_len = encrypt.getKey("/Length").getIntValueAsInt() / 8;  
736 - }  
737 - if (encrypt.hasKey("/EncryptMetadata") &&  
738 - encrypt.getKey("/EncryptMetadata").isBool())  
739 - {  
740 - this->m->encrypt_metadata =  
741 - encrypt.getKey("/EncryptMetadata").getBoolValue();  
742 - } 730 + QPDFObjectHandle encrypt = trailer.getKey("/Encrypt");
  731 + int V = encrypt.getKey("/V").getIntValueAsInt();
  732 + int key_len = 5;
  733 + if (V > 1)
  734 + {
  735 + key_len = encrypt.getKey("/Length").getIntValueAsInt() / 8;
  736 + }
  737 + if (encrypt.hasKey("/EncryptMetadata") &&
  738 + encrypt.getKey("/EncryptMetadata").isBool())
  739 + {
  740 + this->m->encrypt_metadata =
  741 + encrypt.getKey("/EncryptMetadata").getBoolValue();
  742 + }
743 if (V >= 4) 743 if (V >= 4)
744 { 744 {
745 // When copying encryption parameters, use AES even if the 745 // When copying encryption parameters, use AES even if the
@@ -750,8 +750,8 @@ QPDFWriter::copyEncryptionParameters(QPDF&amp; qpdf) @@ -750,8 +750,8 @@ QPDFWriter::copyEncryptionParameters(QPDF&amp; qpdf)
750 // different values. 750 // different values.
751 this->m->encrypt_use_aes = true; 751 this->m->encrypt_use_aes = true;
752 } 752 }
753 - QTC::TC("qpdf", "QPDFWriter copy encrypt metadata",  
754 - this->m->encrypt_metadata ? 0 : 1); 753 + QTC::TC("qpdf", "QPDFWriter copy encrypt metadata",
  754 + this->m->encrypt_metadata ? 0 : 1);
755 QTC::TC("qpdf", "QPDFWriter copy use_aes", 755 QTC::TC("qpdf", "QPDFWriter copy use_aes",
756 this->m->encrypt_use_aes ? 0 : 1); 756 this->m->encrypt_use_aes ? 0 : 1);
757 std::string OE; 757 std::string OE;
@@ -761,24 +761,24 @@ QPDFWriter::copyEncryptionParameters(QPDF&amp; qpdf) @@ -761,24 +761,24 @@ QPDFWriter::copyEncryptionParameters(QPDF&amp; qpdf)
761 if (V >= 5) 761 if (V >= 5)
762 { 762 {
763 QTC::TC("qpdf", "QPDFWriter copy V5"); 763 QTC::TC("qpdf", "QPDFWriter copy V5");
764 - OE = encrypt.getKey("/OE").getStringValue(); 764 + OE = encrypt.getKey("/OE").getStringValue();
765 UE = encrypt.getKey("/UE").getStringValue(); 765 UE = encrypt.getKey("/UE").getStringValue();
766 - Perms = encrypt.getKey("/Perms").getStringValue(); 766 + Perms = encrypt.getKey("/Perms").getStringValue();
767 encryption_key = qpdf.getEncryptionKey(); 767 encryption_key = qpdf.getEncryptionKey();
768 } 768 }
769 769
770 - setEncryptionParametersInternal(  
771 - V,  
772 - encrypt.getKey("/R").getIntValueAsInt(),  
773 - key_len,  
774 - static_cast<int>(encrypt.getKey("/P").getIntValue()),  
775 - encrypt.getKey("/O").getStringValue(),  
776 - encrypt.getKey("/U").getStringValue(), 770 + setEncryptionParametersInternal(
  771 + V,
  772 + encrypt.getKey("/R").getIntValueAsInt(),
  773 + key_len,
  774 + static_cast<int>(encrypt.getKey("/P").getIntValue()),
  775 + encrypt.getKey("/O").getStringValue(),
  776 + encrypt.getKey("/U").getStringValue(),
777 OE, 777 OE,
778 UE, 778 UE,
779 Perms, 779 Perms,
780 - this->m->id1, // this->m->id1 == the other file's id1  
781 - qpdf.getPaddedUserPassword(), 780 + this->m->id1, // this->m->id1 == the other file's id1
  781 + qpdf.getPaddedUserPassword(),
782 encryption_key); 782 encryption_key);
783 } 783 }
784 } 784 }
@@ -789,41 +789,41 @@ QPDFWriter::disableIncompatibleEncryption(int major, int minor, @@ -789,41 +789,41 @@ QPDFWriter::disableIncompatibleEncryption(int major, int minor,
789 { 789 {
790 if (! this->m->encrypted) 790 if (! this->m->encrypted)
791 { 791 {
792 - return; 792 + return;
793 } 793 }
794 794
795 bool disable = false; 795 bool disable = false;
796 if (compareVersions(major, minor, 1, 3) < 0) 796 if (compareVersions(major, minor, 1, 3) < 0)
797 { 797 {
798 - disable = true; 798 + disable = true;
799 } 799 }
800 else 800 else
801 { 801 {
802 - int V = QUtil::string_to_int( 802 + int V = QUtil::string_to_int(
803 this->m->encryption_dictionary["/V"].c_str()); 803 this->m->encryption_dictionary["/V"].c_str());
804 - int R = QUtil::string_to_int( 804 + int R = QUtil::string_to_int(
805 this->m->encryption_dictionary["/R"].c_str()); 805 this->m->encryption_dictionary["/R"].c_str());
806 - if (compareVersions(major, minor, 1, 4) < 0)  
807 - {  
808 - if ((V > 1) || (R > 2))  
809 - {  
810 - disable = true;  
811 - }  
812 - }  
813 - else if (compareVersions(major, minor, 1, 5) < 0)  
814 - {  
815 - if ((V > 2) || (R > 3))  
816 - {  
817 - disable = true;  
818 - }  
819 - }  
820 - else if (compareVersions(major, minor, 1, 6) < 0)  
821 - {  
822 - if (this->m->encrypt_use_aes)  
823 - {  
824 - disable = true;  
825 - }  
826 - } 806 + if (compareVersions(major, minor, 1, 4) < 0)
  807 + {
  808 + if ((V > 1) || (R > 2))
  809 + {
  810 + disable = true;
  811 + }
  812 + }
  813 + else if (compareVersions(major, minor, 1, 5) < 0)
  814 + {
  815 + if ((V > 2) || (R > 3))
  816 + {
  817 + disable = true;
  818 + }
  819 + }
  820 + else if (compareVersions(major, minor, 1, 6) < 0)
  821 + {
  822 + if (this->m->encrypt_use_aes)
  823 + {
  824 + disable = true;
  825 + }
  826 + }
827 else if ((compareVersions(major, minor, 1, 7) < 0) || 827 else if ((compareVersions(major, minor, 1, 7) < 0) ||
828 ((compareVersions(major, minor, 1, 7) == 0) && 828 ((compareVersions(major, minor, 1, 7) == 0) &&
829 extension_level < 3)) 829 extension_level < 3))
@@ -836,24 +836,24 @@ QPDFWriter::disableIncompatibleEncryption(int major, int minor, @@ -836,24 +836,24 @@ QPDFWriter::disableIncompatibleEncryption(int major, int minor,
836 } 836 }
837 if (disable) 837 if (disable)
838 { 838 {
839 - QTC::TC("qpdf", "QPDFWriter forced version disabled encryption");  
840 - this->m->encrypted = false; 839 + QTC::TC("qpdf", "QPDFWriter forced version disabled encryption");
  840 + this->m->encrypted = false;
841 } 841 }
842 } 842 }
843 843
844 void 844 void
845 QPDFWriter::parseVersion(std::string const& version, 845 QPDFWriter::parseVersion(std::string const& version,
846 - int& major, int& minor) const 846 + int& major, int& minor) const
847 { 847 {
848 major = QUtil::string_to_int(version.c_str()); 848 major = QUtil::string_to_int(version.c_str());
849 minor = 0; 849 minor = 0;
850 size_t p = version.find('.'); 850 size_t p = version.find('.');
851 if ((p != std::string::npos) && (version.length() > p)) 851 if ((p != std::string::npos) && (version.length() > p))
852 { 852 {
853 - minor = QUtil::string_to_int(version.substr(p + 1).c_str()); 853 + minor = QUtil::string_to_int(version.substr(p + 1).c_str());
854 } 854 }
855 std::string tmp = QUtil::int_to_string(major) + "." + 855 std::string tmp = QUtil::int_to_string(major) + "." +
856 - QUtil::int_to_string(minor); 856 + QUtil::int_to_string(minor);
857 if (tmp != version) 857 if (tmp != version)
858 { 858 {
859 // The version number in the input is probably invalid. This 859 // The version number in the input is probably invalid. This
@@ -866,27 +866,27 @@ QPDFWriter::parseVersion(std::string const&amp; version, @@ -866,27 +866,27 @@ QPDFWriter::parseVersion(std::string const&amp; version,
866 866
867 int 867 int
868 QPDFWriter::compareVersions(int major1, int minor1, 868 QPDFWriter::compareVersions(int major1, int minor1,
869 - int major2, int minor2) const 869 + int major2, int minor2) const
870 { 870 {
871 if (major1 < major2) 871 if (major1 < major2)
872 { 872 {
873 - return -1; 873 + return -1;
874 } 874 }
875 else if (major1 > major2) 875 else if (major1 > major2)
876 { 876 {
877 - return 1; 877 + return 1;
878 } 878 }
879 else if (minor1 < minor2) 879 else if (minor1 < minor2)
880 { 880 {
881 - return -1; 881 + return -1;
882 } 882 }
883 else if (minor1 > minor2) 883 else if (minor1 > minor2)
884 { 884 {
885 - return 1; 885 + return 1;
886 } 886 }
887 else 887 else
888 { 888 {
889 - return 0; 889 + return 0;
890 } 890 }
891 } 891 }
892 892
@@ -938,29 +938,29 @@ QPDFWriter::setEncryptionParametersInternal( @@ -938,29 +938,29 @@ QPDFWriter::setEncryptionParametersInternal(
938 938
939 if ((R >= 4) && (! this->m->encrypt_metadata)) 939 if ((R >= 4) && (! this->m->encrypt_metadata))
940 { 940 {
941 - this->m->encryption_dictionary["/EncryptMetadata"] = "false"; 941 + this->m->encryption_dictionary["/EncryptMetadata"] = "false";
942 } 942 }
943 if ((V == 4) || (V == 5)) 943 if ((V == 4) || (V == 5))
944 { 944 {
945 - // The spec says the value for the crypt filter key can be  
946 - // anything, and xpdf seems to agree. However, Adobe Reader  
947 - // won't open our files unless we use /StdCF.  
948 - this->m->encryption_dictionary["/StmF"] = "/StdCF";  
949 - this->m->encryption_dictionary["/StrF"] = "/StdCF";  
950 - std::string method = (this->m->encrypt_use_aes 945 + // The spec says the value for the crypt filter key can be
  946 + // anything, and xpdf seems to agree. However, Adobe Reader
  947 + // won't open our files unless we use /StdCF.
  948 + this->m->encryption_dictionary["/StmF"] = "/StdCF";
  949 + this->m->encryption_dictionary["/StrF"] = "/StdCF";
  950 + std::string method = (this->m->encrypt_use_aes
951 ? ((V < 5) ? "/AESV2" : "/AESV3") 951 ? ((V < 5) ? "/AESV2" : "/AESV3")
952 : "/V2"); 952 : "/V2");
953 // The PDF spec says the /Length key is optional, but the PDF 953 // The PDF spec says the /Length key is optional, but the PDF
954 // previewer on some versions of MacOS won't open encrypted 954 // previewer on some versions of MacOS won't open encrypted
955 // files without it. 955 // files without it.
956 - this->m->encryption_dictionary["/CF"] =  
957 - "<< /StdCF << /AuthEvent /DocOpen /CFM " + method + 956 + this->m->encryption_dictionary["/CF"] =
  957 + "<< /StdCF << /AuthEvent /DocOpen /CFM " + method +
958 " /Length " + std::string((V < 5) ? "16" : "32") + " >> >>"; 958 " /Length " + std::string((V < 5) ? "16" : "32") + " >> >>";
959 } 959 }
960 960
961 this->m->encrypted = true; 961 this->m->encrypted = true;
962 QPDF::EncryptionData encryption_data( 962 QPDF::EncryptionData encryption_data(
963 - V, R, key_len, P, O, U, OE, UE, Perms, id1, this->m->encrypt_metadata); 963 + V, R, key_len, P, O, U, OE, UE, Perms, id1, this->m->encrypt_metadata);
964 if (V < 5) 964 if (V < 5)
965 { 965 {
966 this->m->encryption_key = QPDF::compute_encryption_key( 966 this->m->encryption_key = QPDF::compute_encryption_key(
@@ -976,7 +976,7 @@ void @@ -976,7 +976,7 @@ void
976 QPDFWriter::setDataKey(int objid) 976 QPDFWriter::setDataKey(int objid)
977 { 977 {
978 this->m->cur_data_key = QPDF::compute_data_key( 978 this->m->cur_data_key = QPDF::compute_data_key(
979 - this->m->encryption_key, objid, 0, 979 + this->m->encryption_key, objid, 0,
980 this->m->encrypt_use_aes, this->m->encryption_V, this->m->encryption_R); 980 this->m->encrypt_use_aes, this->m->encryption_V, this->m->encryption_R);
981 } 981 }
982 982
@@ -986,8 +986,8 @@ QPDFWriter::bytesNeeded(long long n) @@ -986,8 +986,8 @@ QPDFWriter::bytesNeeded(long long n)
986 unsigned int bytes = 0; 986 unsigned int bytes = 0;
987 while (n) 987 while (n)
988 { 988 {
989 - ++bytes;  
990 - n >>= 8; 989 + ++bytes;
  990 + n >>= 8;
991 } 991 }
992 return bytes; 992 return bytes;
993 } 993 }
@@ -1003,8 +1003,8 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes) @@ -1003,8 +1003,8 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes)
1003 unsigned char data[sizeof(unsigned long long)]; 1003 unsigned char data[sizeof(unsigned long long)];
1004 for (unsigned int i = 0; i < bytes; ++i) 1004 for (unsigned int i = 0; i < bytes; ++i)
1005 { 1005 {
1006 - data[bytes - i - 1] = static_cast<unsigned char>(val & 0xff);  
1007 - val >>= 8; 1006 + data[bytes - i - 1] = static_cast<unsigned char>(val & 0xff);
  1007 + val >>= 8;
1008 } 1008 }
1009 this->m->pipeline->write(data, bytes); 1009 this->m->pipeline->write(data, bytes);
1010 } 1010 }
@@ -1026,7 +1026,7 @@ QPDFWriter::writeStringQDF(std::string const&amp; str) @@ -1026,7 +1026,7 @@ QPDFWriter::writeStringQDF(std::string const&amp; str)
1026 { 1026 {
1027 if (this->m->qdf_mode) 1027 if (this->m->qdf_mode)
1028 { 1028 {
1029 - writeString(str); 1029 + writeString(str);
1030 } 1030 }
1031 } 1031 }
1032 1032
@@ -1035,7 +1035,7 @@ QPDFWriter::writeStringNoQDF(std::string const&amp; str) @@ -1035,7 +1035,7 @@ QPDFWriter::writeStringNoQDF(std::string const&amp; str)
1035 { 1035 {
1036 if (! this->m->qdf_mode) 1036 if (! this->m->qdf_mode)
1037 { 1037 {
1038 - writeString(str); 1038 + writeString(str);
1039 } 1039 }
1040 } 1040 }
1041 1041
@@ -1044,7 +1044,7 @@ QPDFWriter::writePad(int nspaces) @@ -1044,7 +1044,7 @@ QPDFWriter::writePad(int nspaces)
1044 { 1044 {
1045 for (int i = 0; i < nspaces; ++i) 1045 for (int i = 0; i < nspaces; ++i)
1046 { 1046 {
1047 - writeString(" "); 1047 + writeString(" ");
1048 } 1048 }
1049 } 1049 }
1050 1050
@@ -1087,7 +1087,7 @@ QPDFWriter::PipelinePopper::~PipelinePopper() @@ -1087,7 +1087,7 @@ QPDFWriter::PipelinePopper::~PipelinePopper()
1087 assert(qw->m->pipeline_stack.size() >= 2); 1087 assert(qw->m->pipeline_stack.size() >= 2);
1088 qw->m->pipeline->finish(); 1088 qw->m->pipeline->finish();
1089 assert(dynamic_cast<Pl_Count*>(qw->m->pipeline_stack.back()) == 1089 assert(dynamic_cast<Pl_Count*>(qw->m->pipeline_stack.back()) ==
1090 - qw->m->pipeline); 1090 + qw->m->pipeline);
1091 // It might be possible for this assertion to fail if 1091 // It might be possible for this assertion to fail if
1092 // writeLinearized exits by exception when deterministic ID, but I 1092 // writeLinearized exits by exception when deterministic ID, but I
1093 // don't think so. As of this writing, this is the only case in 1093 // don't think so. As of this writing, this is the only case in
@@ -1099,18 +1099,18 @@ QPDFWriter::PipelinePopper::~PipelinePopper() @@ -1099,18 +1099,18 @@ QPDFWriter::PipelinePopper::~PipelinePopper()
1099 qw->m->pipeline_stack.pop_back(); 1099 qw->m->pipeline_stack.pop_back();
1100 while (dynamic_cast<Pl_Count*>(qw->m->pipeline_stack.back()) == 0) 1100 while (dynamic_cast<Pl_Count*>(qw->m->pipeline_stack.back()) == 0)
1101 { 1101 {
1102 - Pipeline* p = qw->m->pipeline_stack.back(); 1102 + Pipeline* p = qw->m->pipeline_stack.back();
1103 if (dynamic_cast<Pl_MD5*>(p) == qw->m->md5_pipeline) 1103 if (dynamic_cast<Pl_MD5*>(p) == qw->m->md5_pipeline)
1104 { 1104 {
1105 qw->m->md5_pipeline = 0; 1105 qw->m->md5_pipeline = 0;
1106 } 1106 }
1107 - qw->m->pipeline_stack.pop_back();  
1108 - Pl_Buffer* buf = dynamic_cast<Pl_Buffer*>(p);  
1109 - if (bp && buf)  
1110 - {  
1111 - *bp = buf->getBufferSharedPointer();  
1112 - }  
1113 - delete p; 1107 + qw->m->pipeline_stack.pop_back();
  1108 + Pl_Buffer* buf = dynamic_cast<Pl_Buffer*>(p);
  1109 + if (bp && buf)
  1110 + {
  1111 + *bp = buf->getBufferSharedPointer();
  1112 + }
  1113 + delete p;
1114 } 1114 }
1115 qw->m->pipeline = dynamic_cast<Pl_Count*>(qw->m->pipeline_stack.back()); 1115 qw->m->pipeline = dynamic_cast<Pl_Count*>(qw->m->pipeline_stack.back());
1116 } 1116 }
@@ -1119,12 +1119,12 @@ void @@ -1119,12 +1119,12 @@ void
1119 QPDFWriter::adjustAESStreamLength(size_t& length) 1119 QPDFWriter::adjustAESStreamLength(size_t& length)
1120 { 1120 {
1121 if (this->m->encrypted && (! this->m->cur_data_key.empty()) && 1121 if (this->m->encrypted && (! this->m->cur_data_key.empty()) &&
1122 - this->m->encrypt_use_aes) 1122 + this->m->encrypt_use_aes)
1123 { 1123 {
1124 - // Stream length will be padded with 1 to 16 bytes to end up  
1125 - // as a multiple of 16. It will also be prepended by 16 bits  
1126 - // of random data.  
1127 - length += 32 - (length & 0xf); 1124 + // Stream length will be padded with 1 to 16 bytes to end up
  1125 + // as a multiple of 16. It will also be prepended by 16 bits
  1126 + // of random data.
  1127 + length += 32 - (length & 0xf);
1128 } 1128 }
1129 } 1129 }
1130 1130
@@ -1133,21 +1133,21 @@ QPDFWriter::pushEncryptionFilter(PipelinePopper&amp; pp) @@ -1133,21 +1133,21 @@ QPDFWriter::pushEncryptionFilter(PipelinePopper&amp; pp)
1133 { 1133 {
1134 if (this->m->encrypted && (! this->m->cur_data_key.empty())) 1134 if (this->m->encrypted && (! this->m->cur_data_key.empty()))
1135 { 1135 {
1136 - Pipeline* p = 0;  
1137 - if (this->m->encrypt_use_aes)  
1138 - {  
1139 - p = new Pl_AES_PDF(  
1140 - "aes stream encryption", this->m->pipeline, true,  
1141 - QUtil::unsigned_char_pointer(this->m->cur_data_key), 1136 + Pipeline* p = 0;
  1137 + if (this->m->encrypt_use_aes)
  1138 + {
  1139 + p = new Pl_AES_PDF(
  1140 + "aes stream encryption", this->m->pipeline, true,
  1141 + QUtil::unsigned_char_pointer(this->m->cur_data_key),
1142 this->m->cur_data_key.length()); 1142 this->m->cur_data_key.length());
1143 - }  
1144 - else  
1145 - {  
1146 - p = new Pl_RC4("rc4 stream encryption", this->m->pipeline,  
1147 - QUtil::unsigned_char_pointer(this->m->cur_data_key),  
1148 - QIntC::to_int(this->m->cur_data_key.length()));  
1149 - }  
1150 - pushPipeline(p); 1143 + }
  1144 + else
  1145 + {
  1146 + p = new Pl_RC4("rc4 stream encryption", this->m->pipeline,
  1147 + QUtil::unsigned_char_pointer(this->m->cur_data_key),
  1148 + QIntC::to_int(this->m->cur_data_key.length()));
  1149 + }
  1150 + pushPipeline(p);
1151 } 1151 }
1152 // Must call this unconditionally so we can call popPipelineStack 1152 // Must call this unconditionally so we can call popPipelineStack
1153 // to balance pushEncryptionFilter(). 1153 // to balance pushEncryptionFilter().
@@ -1196,7 +1196,7 @@ QPDFWriter::openObject(int objid) @@ -1196,7 +1196,7 @@ QPDFWriter::openObject(int objid)
1196 { 1196 {
1197 if (objid == 0) 1197 if (objid == 0)
1198 { 1198 {
1199 - objid = this->m->next_objid++; 1199 + objid = this->m->next_objid++;
1200 } 1200 }
1201 this->m->xref[objid] = QPDFXRefEntry(1, this->m->pipeline->getCount(), 0); 1201 this->m->xref[objid] = QPDFXRefEntry(1, this->m->pipeline->getCount(), 0);
1202 writeString(QUtil::int_to_string(objid)); 1202 writeString(QUtil::int_to_string(objid));
@@ -1223,17 +1223,17 @@ QPDFWriter::assignCompressedObjectNumbers(QPDFObjGen const&amp; og) @@ -1223,17 +1223,17 @@ QPDFWriter::assignCompressedObjectNumbers(QPDFObjGen const&amp; og)
1223 (this->m->object_stream_to_objects.count(objid) == 0)) 1223 (this->m->object_stream_to_objects.count(objid) == 0))
1224 { 1224 {
1225 // This is not an object stream. 1225 // This is not an object stream.
1226 - return; 1226 + return;
1227 } 1227 }
1228 1228
1229 // Reserve numbers for the objects that belong to this object 1229 // Reserve numbers for the objects that belong to this object
1230 // stream. 1230 // stream.
1231 for (std::set<QPDFObjGen>::iterator iter = 1231 for (std::set<QPDFObjGen>::iterator iter =
1232 - this->m->object_stream_to_objects[objid].begin();  
1233 - iter != this->m->object_stream_to_objects[objid].end();  
1234 - ++iter) 1232 + this->m->object_stream_to_objects[objid].begin();
  1233 + iter != this->m->object_stream_to_objects[objid].end();
  1234 + ++iter)
1235 { 1235 {
1236 - this->m->obj_renumber[*iter] = this->m->next_objid++; 1236 + this->m->obj_renumber[*iter] = this->m->next_objid++;
1237 } 1237 }
1238 } 1238 }
1239 1239
@@ -1264,45 +1264,45 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) @@ -1264,45 +1264,45 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object)
1264 return; 1264 return;
1265 } 1265 }
1266 1266
1267 - QPDFObjGen og = object.getObjGen(); 1267 + QPDFObjGen og = object.getObjGen();
1268 1268
1269 - if (this->m->obj_renumber.count(og) == 0)  
1270 - {  
1271 - if (this->m->object_to_object_stream.count(og))  
1272 - {  
1273 - // This is in an object stream. Don't process it  
1274 - // here. Instead, enqueue the object stream. Object  
1275 - // streams always have generation 0.  
1276 - int stream_id = this->m->object_to_object_stream[og]; 1269 + if (this->m->obj_renumber.count(og) == 0)
  1270 + {
  1271 + if (this->m->object_to_object_stream.count(og))
  1272 + {
  1273 + // This is in an object stream. Don't process it
  1274 + // here. Instead, enqueue the object stream. Object
  1275 + // streams always have generation 0.
  1276 + int stream_id = this->m->object_to_object_stream[og];
1277 // Detect loops by storing invalid object ID 0, which 1277 // Detect loops by storing invalid object ID 0, which
1278 // will get overwritten later. 1278 // will get overwritten later.
1279 this->m->obj_renumber[og] = 0; 1279 this->m->obj_renumber[og] = 0;
1280 - enqueueObject(this->m->pdf.getObjectByID(stream_id, 0));  
1281 - }  
1282 - else  
1283 - {  
1284 - this->m->object_queue.push_back(object);  
1285 - this->m->obj_renumber[og] = this->m->next_objid++;  
1286 -  
1287 - if ((og.getGen() == 0) && 1280 + enqueueObject(this->m->pdf.getObjectByID(stream_id, 0));
  1281 + }
  1282 + else
  1283 + {
  1284 + this->m->object_queue.push_back(object);
  1285 + this->m->obj_renumber[og] = this->m->next_objid++;
  1286 +
  1287 + if ((og.getGen() == 0) &&
1288 this->m->object_stream_to_objects.count(og.getObj())) 1288 this->m->object_stream_to_objects.count(og.getObj()))
1289 - {  
1290 - // For linearized files, uncompressed objects go  
1291 - // at end, and we take care of assigning numbers  
1292 - // to them elsewhere.  
1293 - if (! this->m->linearized)  
1294 - {  
1295 - assignCompressedObjectNumbers(og);  
1296 - }  
1297 - }  
1298 - else if ((! this->m->direct_stream_lengths) && 1289 + {
  1290 + // For linearized files, uncompressed objects go
  1291 + // at end, and we take care of assigning numbers
  1292 + // to them elsewhere.
  1293 + if (! this->m->linearized)
  1294 + {
  1295 + assignCompressedObjectNumbers(og);
  1296 + }
  1297 + }
  1298 + else if ((! this->m->direct_stream_lengths) &&
1299 object.isStream()) 1299 object.isStream())
1300 - {  
1301 - // reserve next object ID for length  
1302 - ++this->m->next_objid;  
1303 - }  
1304 - }  
1305 - } 1300 + {
  1301 + // reserve next object ID for length
  1302 + ++this->m->next_objid;
  1303 + }
  1304 + }
  1305 + }
1306 else if (this->m->obj_renumber[og] == 0) 1306 else if (this->m->obj_renumber[og] == 0)
1307 { 1307 {
1308 // This can happen if a specially constructed file 1308 // This can happen if a specially constructed file
@@ -1312,30 +1312,30 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) @@ -1312,30 +1312,30 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object)
1312 } 1312 }
1313 else if (object.isArray()) 1313 else if (object.isArray())
1314 { 1314 {
1315 - int n = object.getArrayNItems();  
1316 - for (int i = 0; i < n; ++i)  
1317 - {  
1318 - if (! this->m->linearized)  
1319 - {  
1320 - enqueueObject(object.getArrayItem(i));  
1321 - }  
1322 - } 1315 + int n = object.getArrayNItems();
  1316 + for (int i = 0; i < n; ++i)
  1317 + {
  1318 + if (! this->m->linearized)
  1319 + {
  1320 + enqueueObject(object.getArrayItem(i));
  1321 + }
  1322 + }
1323 } 1323 }
1324 else if (object.isDictionary()) 1324 else if (object.isDictionary())
1325 { 1325 {
1326 - std::set<std::string> keys = object.getKeys();  
1327 - for (std::set<std::string>::iterator iter = keys.begin();  
1328 - iter != keys.end(); ++iter)  
1329 - {  
1330 - if (! this->m->linearized)  
1331 - {  
1332 - enqueueObject(object.getKey(*iter));  
1333 - }  
1334 - } 1326 + std::set<std::string> keys = object.getKeys();
  1327 + for (std::set<std::string>::iterator iter = keys.begin();
  1328 + iter != keys.end(); ++iter)
  1329 + {
  1330 + if (! this->m->linearized)
  1331 + {
  1332 + enqueueObject(object.getKey(*iter));
  1333 + }
  1334 + }
1335 } 1335 }
1336 else 1336 else
1337 { 1337 {
1338 - // ignore 1338 + // ignore
1339 } 1339 }
1340 } 1340 }
1341 1341
@@ -1344,18 +1344,18 @@ QPDFWriter::unparseChild(QPDFObjectHandle child, int level, int flags) @@ -1344,18 +1344,18 @@ QPDFWriter::unparseChild(QPDFObjectHandle child, int level, int flags)
1344 { 1344 {
1345 if (! this->m->linearized) 1345 if (! this->m->linearized)
1346 { 1346 {
1347 - enqueueObject(child); 1347 + enqueueObject(child);
1348 } 1348 }
1349 if (child.isIndirect()) 1349 if (child.isIndirect())
1350 { 1350 {
1351 - QPDFObjGen old_og = child.getObjGen();  
1352 - int new_id = this->m->obj_renumber[old_og];  
1353 - writeString(QUtil::int_to_string(new_id));  
1354 - writeString(" 0 R"); 1351 + QPDFObjGen old_og = child.getObjGen();
  1352 + int new_id = this->m->obj_renumber[old_og];
  1353 + writeString(QUtil::int_to_string(new_id));
  1354 + writeString(" 0 R");
1355 } 1355 }
1356 else 1356 else
1357 { 1357 {
1358 - unparseObject(child, level, flags); 1358 + unparseObject(child, level, flags);
1359 } 1359 }
1360 } 1360 }
1361 1361
@@ -1370,49 +1370,49 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream, @@ -1370,49 +1370,49 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream,
1370 } 1370 }
1371 else 1371 else
1372 { 1372 {
1373 - writeString("trailer <<"); 1373 + writeString("trailer <<");
1374 } 1374 }
1375 writeStringQDF("\n"); 1375 writeStringQDF("\n");
1376 if (which == t_lin_second) 1376 if (which == t_lin_second)
1377 { 1377 {
1378 - writeString(" /Size ");  
1379 - writeString(QUtil::int_to_string(size)); 1378 + writeString(" /Size ");
  1379 + writeString(QUtil::int_to_string(size));
1380 } 1380 }
1381 else 1381 else
1382 { 1382 {
1383 - std::set<std::string> keys = trailer.getKeys();  
1384 - for (std::set<std::string>::iterator iter = keys.begin();  
1385 - iter != keys.end(); ++iter)  
1386 - {  
1387 - std::string const& key = *iter;  
1388 - writeStringQDF(" ");  
1389 - writeStringNoQDF(" ");  
1390 - writeString(QPDF_Name::normalizeName(key));  
1391 - writeString(" ");  
1392 - if (key == "/Size")  
1393 - {  
1394 - writeString(QUtil::int_to_string(size));  
1395 - if (which == t_lin_first)  
1396 - {  
1397 - writeString(" /Prev ");  
1398 - qpdf_offset_t pos = this->m->pipeline->getCount();  
1399 - writeString(QUtil::int_to_string(prev));  
1400 - int nspaces = 1383 + std::set<std::string> keys = trailer.getKeys();
  1384 + for (std::set<std::string>::iterator iter = keys.begin();
  1385 + iter != keys.end(); ++iter)
  1386 + {
  1387 + std::string const& key = *iter;
  1388 + writeStringQDF(" ");
  1389 + writeStringNoQDF(" ");
  1390 + writeString(QPDF_Name::normalizeName(key));
  1391 + writeString(" ");
  1392 + if (key == "/Size")
  1393 + {
  1394 + writeString(QUtil::int_to_string(size));
  1395 + if (which == t_lin_first)
  1396 + {
  1397 + writeString(" /Prev ");
  1398 + qpdf_offset_t pos = this->m->pipeline->getCount();
  1399 + writeString(QUtil::int_to_string(prev));
  1400 + int nspaces =
1401 QIntC::to_int(pos - this->m->pipeline->getCount() + 21); 1401 QIntC::to_int(pos - this->m->pipeline->getCount() + 21);
1402 - if (nspaces < 0) 1402 + if (nspaces < 0)
1403 { 1403 {
1404 throw std::logic_error( 1404 throw std::logic_error(
1405 "QPDFWriter: no padding required in trailer"); 1405 "QPDFWriter: no padding required in trailer");
1406 } 1406 }
1407 - writePad(nspaces);  
1408 - }  
1409 - }  
1410 - else  
1411 - {  
1412 - unparseChild(trailer.getKey(key), 1, 0);  
1413 - }  
1414 - writeStringQDF("\n");  
1415 - } 1407 + writePad(nspaces);
  1408 + }
  1409 + }
  1410 + else
  1411 + {
  1412 + unparseChild(trailer.getKey(key), 1, 0);
  1413 + }
  1414 + writeStringQDF("\n");
  1415 + }
1416 } 1416 }
1417 1417
1418 // Write ID 1418 // Write ID
@@ -1420,7 +1420,7 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream, @@ -1420,7 +1420,7 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream,
1420 writeString(" /ID ["); 1420 writeString(" /ID [");
1421 if (linearization_pass == 1) 1421 if (linearization_pass == 1)
1422 { 1422 {
1423 - std::string original_id1 = getOriginalID1(); 1423 + std::string original_id1 = getOriginalID1();
1424 if (original_id1.empty()) 1424 if (original_id1.empty())
1425 { 1425 {
1426 writeString("<00000000000000000000000000000000>"); 1426 writeString("<00000000000000000000000000000000>");
@@ -1457,13 +1457,13 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream, @@ -1457,13 +1457,13 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream,
1457 1457
1458 if (which != t_lin_second) 1458 if (which != t_lin_second)
1459 { 1459 {
1460 - // Write reference to encryption dictionary  
1461 - if (this->m->encrypted)  
1462 - {  
1463 - writeString(" /Encrypt ");  
1464 - writeString(QUtil::int_to_string(this->m->encryption_dict_objid));  
1465 - writeString(" 0 R");  
1466 - } 1460 + // Write reference to encryption dictionary
  1461 + if (this->m->encrypted)
  1462 + {
  1463 + writeString(" /Encrypt ");
  1464 + writeString(QUtil::int_to_string(this->m->encryption_dict_objid));
  1465 + writeString(" 0 R");
  1466 + }
1467 } 1467 }
1468 1468
1469 writeStringQDF("\n"); 1469 writeStringQDF("\n");
@@ -1569,7 +1569,7 @@ QPDFWriter::willFilterStream(QPDFObjectHandle stream, @@ -1569,7 +1569,7 @@ QPDFWriter::willFilterStream(QPDFObjectHandle stream,
1569 1569
1570 void 1570 void
1571 QPDFWriter::unparseObject(QPDFObjectHandle object, int level, 1571 QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
1572 - int flags, size_t stream_length, 1572 + int flags, size_t stream_length,
1573 bool compress) 1573 bool compress)
1574 { 1574 {
1575 QPDFObjGen old_og = object.getObjGen(); 1575 QPDFObjGen old_og = object.getObjGen();
@@ -1578,30 +1578,30 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, @@ -1578,30 +1578,30 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
1578 std::string indent; 1578 std::string indent;
1579 for (int i = 0; i < level; ++i) 1579 for (int i = 0; i < level; ++i)
1580 { 1580 {
1581 - indent += " "; 1581 + indent += " ";
1582 } 1582 }
1583 1583
1584 if (object.isArray()) 1584 if (object.isArray())
1585 { 1585 {
1586 - // Note: PDF spec 1.4 implementation note 121 states that  
1587 - // Acrobat requires a space after the [ in the /H key of the  
1588 - // linearization parameter dictionary. We'll do this  
1589 - // unconditionally for all arrays because it looks nicer and  
1590 - // doesn't make the files that much bigger.  
1591 - writeString("[");  
1592 - writeStringQDF("\n");  
1593 - int n = object.getArrayNItems();  
1594 - for (int i = 0; i < n; ++i)  
1595 - {  
1596 - writeStringQDF(indent);  
1597 - writeStringQDF(" ");  
1598 - writeStringNoQDF(" ");  
1599 - unparseChild(object.getArrayItem(i), level + 1, child_flags);  
1600 - writeStringQDF("\n");  
1601 - }  
1602 - writeStringQDF(indent);  
1603 - writeStringNoQDF(" ");  
1604 - writeString("]"); 1586 + // Note: PDF spec 1.4 implementation note 121 states that
  1587 + // Acrobat requires a space after the [ in the /H key of the
  1588 + // linearization parameter dictionary. We'll do this
  1589 + // unconditionally for all arrays because it looks nicer and
  1590 + // doesn't make the files that much bigger.
  1591 + writeString("[");
  1592 + writeStringQDF("\n");
  1593 + int n = object.getArrayNItems();
  1594 + for (int i = 0; i < n; ++i)
  1595 + {
  1596 + writeStringQDF(indent);
  1597 + writeStringQDF(" ");
  1598 + writeStringNoQDF(" ");
  1599 + unparseChild(object.getArrayItem(i), level + 1, child_flags);
  1600 + writeStringQDF("\n");
  1601 + }
  1602 + writeStringQDF(indent);
  1603 + writeStringNoQDF(" ");
  1604 + writeString("]");
1605 } 1605 }
1606 else if (object.isDictionary()) 1606 else if (object.isDictionary())
1607 { 1607 {
@@ -1742,7 +1742,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, @@ -1742,7 +1742,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
1742 object.removeKey("/DecodeParms"); 1742 object.removeKey("/DecodeParms");
1743 } 1743 }
1744 1744
1745 - if (flags & f_filtered) 1745 + if (flags & f_filtered)
1746 { 1746 {
1747 // We will supply our own filter and decode 1747 // We will supply our own filter and decode
1748 // parameters. 1748 // parameters.
@@ -1791,96 +1791,96 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, @@ -1791,96 +1791,96 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
1791 } 1791 }
1792 } 1792 }
1793 1793
1794 - writeString("<<");  
1795 - writeStringQDF("\n");  
1796 -  
1797 - std::set<std::string> keys = object.getKeys();  
1798 - for (std::set<std::string>::iterator iter = keys.begin();  
1799 - iter != keys.end(); ++iter)  
1800 - {  
1801 - std::string const& key = *iter;  
1802 -  
1803 - writeStringQDF(indent);  
1804 - writeStringQDF(" ");  
1805 - writeStringNoQDF(" ");  
1806 - writeString(QPDF_Name::normalizeName(key));  
1807 - writeString(" ");  
1808 - if (key == "/Contents" &&  
1809 - object.isDictionaryOfType("/Sig") &&  
1810 - object.hasKey("/ByteRange"))  
1811 - { 1794 + writeString("<<");
  1795 + writeStringQDF("\n");
  1796 +
  1797 + std::set<std::string> keys = object.getKeys();
  1798 + for (std::set<std::string>::iterator iter = keys.begin();
  1799 + iter != keys.end(); ++iter)
  1800 + {
  1801 + std::string const& key = *iter;
  1802 +
  1803 + writeStringQDF(indent);
  1804 + writeStringQDF(" ");
  1805 + writeStringNoQDF(" ");
  1806 + writeString(QPDF_Name::normalizeName(key));
  1807 + writeString(" ");
  1808 + if (key == "/Contents" &&
  1809 + object.isDictionaryOfType("/Sig") &&
  1810 + object.hasKey("/ByteRange"))
  1811 + {
1812 QTC::TC("qpdf", "QPDFWriter no encryption sig contents"); 1812 QTC::TC("qpdf", "QPDFWriter no encryption sig contents");
1813 - unparseChild(object.getKey(key), level + 1,  
1814 - child_flags | f_hex_string | f_no_encryption);  
1815 - }  
1816 - else  
1817 - {  
1818 - unparseChild(object.getKey(key), level + 1, child_flags);  
1819 - }  
1820 - writeStringQDF("\n");  
1821 - }  
1822 -  
1823 - if (flags & f_stream)  
1824 - {  
1825 - writeStringQDF(indent);  
1826 - writeStringQDF(" ");  
1827 - writeString(" /Length ");  
1828 -  
1829 - if (this->m->direct_stream_lengths)  
1830 - {  
1831 - writeString(QUtil::uint_to_string(stream_length));  
1832 - }  
1833 - else  
1834 - {  
1835 - writeString(  
1836 - QUtil::int_to_string(this->m->cur_stream_length_id));  
1837 - writeString(" 0 R");  
1838 - }  
1839 - writeStringQDF("\n");  
1840 - if (compress && (flags & f_filtered))  
1841 - {  
1842 - writeStringQDF(indent);  
1843 - writeStringQDF(" ");  
1844 - writeString(" /Filter /FlateDecode");  
1845 - writeStringQDF("\n");  
1846 - }  
1847 - }  
1848 -  
1849 - writeStringQDF(indent);  
1850 - writeStringNoQDF(" ");  
1851 - writeString(">>"); 1813 + unparseChild(object.getKey(key), level + 1,
  1814 + child_flags | f_hex_string | f_no_encryption);
  1815 + }
  1816 + else
  1817 + {
  1818 + unparseChild(object.getKey(key), level + 1, child_flags);
  1819 + }
  1820 + writeStringQDF("\n");
  1821 + }
  1822 +
  1823 + if (flags & f_stream)
  1824 + {
  1825 + writeStringQDF(indent);
  1826 + writeStringQDF(" ");
  1827 + writeString(" /Length ");
  1828 +
  1829 + if (this->m->direct_stream_lengths)
  1830 + {
  1831 + writeString(QUtil::uint_to_string(stream_length));
  1832 + }
  1833 + else
  1834 + {
  1835 + writeString(
  1836 + QUtil::int_to_string(this->m->cur_stream_length_id));
  1837 + writeString(" 0 R");
  1838 + }
  1839 + writeStringQDF("\n");
  1840 + if (compress && (flags & f_filtered))
  1841 + {
  1842 + writeStringQDF(indent);
  1843 + writeStringQDF(" ");
  1844 + writeString(" /Filter /FlateDecode");
  1845 + writeStringQDF("\n");
  1846 + }
  1847 + }
  1848 +
  1849 + writeStringQDF(indent);
  1850 + writeStringNoQDF(" ");
  1851 + writeString(">>");
1852 } 1852 }
1853 else if (object.isStream()) 1853 else if (object.isStream())
1854 { 1854 {
1855 - // Write stream data to a buffer.  
1856 - int new_id = this->m->obj_renumber[old_og];  
1857 - if (! this->m->direct_stream_lengths)  
1858 - {  
1859 - this->m->cur_stream_length_id = new_id + 1;  
1860 - } 1855 + // Write stream data to a buffer.
  1856 + int new_id = this->m->obj_renumber[old_og];
  1857 + if (! this->m->direct_stream_lengths)
  1858 + {
  1859 + this->m->cur_stream_length_id = new_id + 1;
  1860 + }
1861 1861
1862 - flags |= f_stream;  
1863 - bool compress_stream = false; 1862 + flags |= f_stream;
  1863 + bool compress_stream = false;
1864 bool is_metadata = false; 1864 bool is_metadata = false;
1865 PointerHolder<Buffer> stream_data; 1865 PointerHolder<Buffer> stream_data;
1866 if (willFilterStream(object, compress_stream, 1866 if (willFilterStream(object, compress_stream,
1867 is_metadata, &stream_data)) 1867 is_metadata, &stream_data))
1868 - {  
1869 - flags |= f_filtered;  
1870 - } 1868 + {
  1869 + flags |= f_filtered;
  1870 + }
1871 QPDFObjectHandle stream_dict = object.getDict(); 1871 QPDFObjectHandle stream_dict = object.getDict();
1872 1872
1873 - this->m->cur_stream_length = stream_data->getSize();  
1874 - if (is_metadata && this->m->encrypted && (! this->m->encrypt_metadata))  
1875 - {  
1876 - // Don't encrypt stream data for the metadata stream  
1877 - this->m->cur_data_key.clear();  
1878 - }  
1879 - adjustAESStreamLength(this->m->cur_stream_length);  
1880 - unparseObject(stream_dict, 0, flags, 1873 + this->m->cur_stream_length = stream_data->getSize();
  1874 + if (is_metadata && this->m->encrypted && (! this->m->encrypt_metadata))
  1875 + {
  1876 + // Don't encrypt stream data for the metadata stream
  1877 + this->m->cur_data_key.clear();
  1878 + }
  1879 + adjustAESStreamLength(this->m->cur_stream_length);
  1880 + unparseObject(stream_dict, 0, flags,
1881 this->m->cur_stream_length, compress_stream); 1881 this->m->cur_stream_length, compress_stream);
1882 - unsigned char last_char = '\0';  
1883 - writeString("\nstream\n"); 1882 + unsigned char last_char = '\0';
  1883 + writeString("\nstream\n");
1884 { 1884 {
1885 PipelinePopper pp_enc(this); 1885 PipelinePopper pp_enc(this);
1886 pushEncryptionFilter(pp_enc); 1886 pushEncryptionFilter(pp_enc);
@@ -1898,72 +1898,72 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, @@ -1898,72 +1898,72 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
1898 { 1898 {
1899 this->m->added_newline = false; 1899 this->m->added_newline = false;
1900 } 1900 }
1901 - writeString("endstream"); 1901 + writeString("endstream");
1902 } 1902 }
1903 else if (object.isString()) 1903 else if (object.isString())
1904 { 1904 {
1905 - std::string val;  
1906 - if (this->m->encrypted &&  
1907 - (! (flags & f_in_ostream)) &&  
1908 - (! (flags & f_no_encryption)) &&  
1909 - (! this->m->cur_data_key.empty()))  
1910 - {  
1911 - val = object.getStringValue();  
1912 - if (this->m->encrypt_use_aes)  
1913 - {  
1914 - Pl_Buffer bufpl("encrypted string");  
1915 - Pl_AES_PDF pl( 1905 + std::string val;
  1906 + if (this->m->encrypted &&
  1907 + (! (flags & f_in_ostream)) &&
  1908 + (! (flags & f_no_encryption)) &&
  1909 + (! this->m->cur_data_key.empty()))
  1910 + {
  1911 + val = object.getStringValue();
  1912 + if (this->m->encrypt_use_aes)
  1913 + {
  1914 + Pl_Buffer bufpl("encrypted string");
  1915 + Pl_AES_PDF pl(
1916 "aes encrypt string", &bufpl, true, 1916 "aes encrypt string", &bufpl, true,
1917 QUtil::unsigned_char_pointer(this->m->cur_data_key), 1917 QUtil::unsigned_char_pointer(this->m->cur_data_key),
1918 this->m->cur_data_key.length()); 1918 this->m->cur_data_key.length());
1919 - pl.write(QUtil::unsigned_char_pointer(val), val.length());  
1920 - pl.finish();  
1921 - auto buf = bufpl.getBufferSharedPointer();  
1922 - val = QPDF_String(  
1923 - std::string(reinterpret_cast<char*>(buf->getBuffer()),  
1924 - buf->getSize())).unparse(true);  
1925 - }  
1926 - else  
1927 - {  
1928 - auto tmp_ph = QUtil::make_unique_cstr(val); 1919 + pl.write(QUtil::unsigned_char_pointer(val), val.length());
  1920 + pl.finish();
  1921 + auto buf = bufpl.getBufferSharedPointer();
  1922 + val = QPDF_String(
  1923 + std::string(reinterpret_cast<char*>(buf->getBuffer()),
  1924 + buf->getSize())).unparse(true);
  1925 + }
  1926 + else
  1927 + {
  1928 + auto tmp_ph = QUtil::make_unique_cstr(val);
1929 char* tmp = tmp_ph.get(); 1929 char* tmp = tmp_ph.get();
1930 - size_t vlen = val.length();  
1931 - RC4 rc4(QUtil::unsigned_char_pointer(this->m->cur_data_key),  
1932 - QIntC::to_int(this->m->cur_data_key.length()));  
1933 - rc4.process(QUtil::unsigned_char_pointer(tmp), vlen);  
1934 - val = QPDF_String(std::string(tmp, vlen)).unparse();  
1935 - }  
1936 - }  
1937 - else if (flags & f_hex_string)  
1938 - {  
1939 - val = QPDF_String(object.getStringValue()).unparse(true);  
1940 - }  
1941 - else  
1942 - {  
1943 - val = object.unparseResolved();  
1944 - }  
1945 - writeString(val); 1930 + size_t vlen = val.length();
  1931 + RC4 rc4(QUtil::unsigned_char_pointer(this->m->cur_data_key),
  1932 + QIntC::to_int(this->m->cur_data_key.length()));
  1933 + rc4.process(QUtil::unsigned_char_pointer(tmp), vlen);
  1934 + val = QPDF_String(std::string(tmp, vlen)).unparse();
  1935 + }
  1936 + }
  1937 + else if (flags & f_hex_string)
  1938 + {
  1939 + val = QPDF_String(object.getStringValue()).unparse(true);
  1940 + }
  1941 + else
  1942 + {
  1943 + val = object.unparseResolved();
  1944 + }
  1945 + writeString(val);
1946 } 1946 }
1947 else 1947 else
1948 { 1948 {
1949 - writeString(object.unparseResolved()); 1949 + writeString(object.unparseResolved());
1950 } 1950 }
1951 } 1951 }
1952 1952
1953 void 1953 void
1954 QPDFWriter::writeObjectStreamOffsets(std::vector<qpdf_offset_t>& offsets, 1954 QPDFWriter::writeObjectStreamOffsets(std::vector<qpdf_offset_t>& offsets,
1955 - int first_obj) 1955 + int first_obj)
1956 { 1956 {
1957 for (size_t i = 0; i < offsets.size(); ++i) 1957 for (size_t i = 0; i < offsets.size(); ++i)
1958 { 1958 {
1959 - if (i != 0)  
1960 - {  
1961 - writeStringQDF("\n");  
1962 - writeStringNoQDF(" ");  
1963 - }  
1964 - writeString(QUtil::uint_to_string(i + QIntC::to_size(first_obj)));  
1965 - writeString(" ");  
1966 - writeString(QUtil::int_to_string(offsets.at(i))); 1959 + if (i != 0)
  1960 + {
  1961 + writeStringQDF("\n");
  1962 + writeStringNoQDF(" ");
  1963 + }
  1964 + writeString(QUtil::uint_to_string(i + QIntC::to_size(first_obj)));
  1965 + writeString(" ");
  1966 + writeString(QUtil::int_to_string(offsets.at(i)));
1967 } 1967 }
1968 writeString("\n"); 1968 writeString("\n");
1969 } 1969 }
@@ -1989,25 +1989,25 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) @@ -1989,25 +1989,25 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
1989 bool compressed = false; 1989 bool compressed = false;
1990 for (int pass = 1; pass <= 2; ++pass) 1990 for (int pass = 1; pass <= 2; ++pass)
1991 { 1991 {
1992 - // stream_buffer will be initialized only for pass 2 1992 + // stream_buffer will be initialized only for pass 2
1993 PipelinePopper pp_ostream(this, &stream_buffer); 1993 PipelinePopper pp_ostream(this, &stream_buffer);
1994 - if (pass == 1)  
1995 - {  
1996 - pushDiscardFilter(pp_ostream);  
1997 - }  
1998 - else  
1999 - {  
2000 - // Adjust offsets to skip over comment before first object  
2001 -  
2002 - first = offsets.at(0);  
2003 - for (std::vector<qpdf_offset_t>::iterator iter = offsets.begin();  
2004 - iter != offsets.end(); ++iter)  
2005 - {  
2006 - *iter -= first;  
2007 - }  
2008 -  
2009 - // Take one pass at writing pairs of numbers so we can get  
2010 - // their size information 1994 + if (pass == 1)
  1995 + {
  1996 + pushDiscardFilter(pp_ostream);
  1997 + }
  1998 + else
  1999 + {
  2000 + // Adjust offsets to skip over comment before first object
  2001 +
  2002 + first = offsets.at(0);
  2003 + for (std::vector<qpdf_offset_t>::iterator iter = offsets.begin();
  2004 + iter != offsets.end(); ++iter)
  2005 + {
  2006 + *iter -= first;
  2007 + }
  2008 +
  2009 + // Take one pass at writing pairs of numbers so we can get
  2010 + // their size information
2011 { 2011 {
2012 PipelinePopper pp_discard(this); 2012 PipelinePopper pp_discard(this);
2013 pushDiscardFilter(pp_discard); 2013 pushDiscardFilter(pp_discard);
@@ -2015,42 +2015,42 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) @@ -2015,42 +2015,42 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
2015 first += this->m->pipeline->getCount(); 2015 first += this->m->pipeline->getCount();
2016 } 2016 }
2017 2017
2018 - // Set up a stream to write the stream data into a buffer.  
2019 - Pipeline* next = pushPipeline(new Pl_Buffer("object stream")); 2018 + // Set up a stream to write the stream data into a buffer.
  2019 + Pipeline* next = pushPipeline(new Pl_Buffer("object stream"));
2020 if ((this->m->compress_streams || 2020 if ((this->m->compress_streams ||
2021 (this->m->stream_decode_level == qpdf_dl_none)) && 2021 (this->m->stream_decode_level == qpdf_dl_none)) &&
2022 (! this->m->qdf_mode)) 2022 (! this->m->qdf_mode))
2023 - {  
2024 - compressed = true;  
2025 - next = pushPipeline(  
2026 - new Pl_Flate("compress object stream", next,  
2027 - Pl_Flate::a_deflate));  
2028 - }  
2029 - activatePipelineStack(pp_ostream);  
2030 - writeObjectStreamOffsets(offsets, first_obj);  
2031 - }  
2032 -  
2033 - int count = 0;  
2034 - for (std::set<QPDFObjGen>::iterator iter =  
2035 - this->m->object_stream_to_objects[old_id].begin();  
2036 - iter != this->m->object_stream_to_objects[old_id].end();  
2037 - ++iter, ++count)  
2038 - {  
2039 - QPDFObjGen obj = *iter;  
2040 - int new_obj = this->m->obj_renumber[obj];  
2041 - if (first_obj == -1)  
2042 - {  
2043 - first_obj = new_obj;  
2044 - }  
2045 - if (this->m->qdf_mode)  
2046 - {  
2047 - writeString("%% Object stream: object " +  
2048 - QUtil::int_to_string(new_obj) + ", index " +  
2049 - QUtil::int_to_string(count));  
2050 - if (! this->m->suppress_original_object_ids)  
2051 - {  
2052 - writeString("; original object ID: " +  
2053 - QUtil::int_to_string(obj.getObj())); 2023 + {
  2024 + compressed = true;
  2025 + next = pushPipeline(
  2026 + new Pl_Flate("compress object stream", next,
  2027 + Pl_Flate::a_deflate));
  2028 + }
  2029 + activatePipelineStack(pp_ostream);
  2030 + writeObjectStreamOffsets(offsets, first_obj);
  2031 + }
  2032 +
  2033 + int count = 0;
  2034 + for (std::set<QPDFObjGen>::iterator iter =
  2035 + this->m->object_stream_to_objects[old_id].begin();
  2036 + iter != this->m->object_stream_to_objects[old_id].end();
  2037 + ++iter, ++count)
  2038 + {
  2039 + QPDFObjGen obj = *iter;
  2040 + int new_obj = this->m->obj_renumber[obj];
  2041 + if (first_obj == -1)
  2042 + {
  2043 + first_obj = new_obj;
  2044 + }
  2045 + if (this->m->qdf_mode)
  2046 + {
  2047 + writeString("%% Object stream: object " +
  2048 + QUtil::int_to_string(new_obj) + ", index " +
  2049 + QUtil::int_to_string(count));
  2050 + if (! this->m->suppress_original_object_ids)
  2051 + {
  2052 + writeString("; original object ID: " +
  2053 + QUtil::int_to_string(obj.getObj()));
2054 // For compatibility, only write the generation if 2054 // For compatibility, only write the generation if
2055 // non-zero. While object streams only allow 2055 // non-zero. While object streams only allow
2056 // objects with generation 0, if we are generating 2056 // objects with generation 0, if we are generating
@@ -2061,17 +2061,17 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) @@ -2061,17 +2061,17 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
2061 QTC::TC("qpdf", "QPDFWriter original obj non-zero gen"); 2061 QTC::TC("qpdf", "QPDFWriter original obj non-zero gen");
2062 writeString(" " + QUtil::int_to_string(obj.getGen())); 2062 writeString(" " + QUtil::int_to_string(obj.getGen()));
2063 } 2063 }
2064 - }  
2065 - writeString("\n");  
2066 - }  
2067 - if (pass == 1)  
2068 - {  
2069 - offsets.push_back(this->m->pipeline->getCount()); 2064 + }
  2065 + writeString("\n");
  2066 + }
  2067 + if (pass == 1)
  2068 + {
  2069 + offsets.push_back(this->m->pipeline->getCount());
2070 // To avoid double-counting objects being written in 2070 // To avoid double-counting objects being written in
2071 // object streams for progress reporting, decrement in 2071 // object streams for progress reporting, decrement in
2072 // pass 1. 2072 // pass 1.
2073 indicateProgress(true, false); 2073 indicateProgress(true, false);
2074 - } 2074 + }
2075 QPDFObjectHandle obj_to_write = 2075 QPDFObjectHandle obj_to_write =
2076 this->m->pdf.getObjectByObjGen(obj); 2076 this->m->pdf.getObjectByObjGen(obj);
2077 if (obj_to_write.isStream()) 2077 if (obj_to_write.isStream())
@@ -2084,10 +2084,10 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) @@ -2084,10 +2084,10 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
2084 "stream found inside object stream; treating as null"); 2084 "stream found inside object stream; treating as null");
2085 obj_to_write = QPDFObjectHandle::newNull(); 2085 obj_to_write = QPDFObjectHandle::newNull();
2086 } 2086 }
2087 - writeObject(obj_to_write, count); 2087 + writeObject(obj_to_write, count);
2088 2088
2089 - this->m->xref[new_obj] = QPDFXRefEntry(2, new_id, count);  
2090 - } 2089 + this->m->xref[new_obj] = QPDFXRefEntry(2, new_id, count);
  2090 + }
2091 } 2091 }
2092 2092
2093 // Write the object 2093 // Write the object
@@ -2103,30 +2103,30 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) @@ -2103,30 +2103,30 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
2103 writeStringQDF("\n "); 2103 writeStringQDF("\n ");
2104 if (compressed) 2104 if (compressed)
2105 { 2105 {
2106 - writeString(" /Filter /FlateDecode"); 2106 + writeString(" /Filter /FlateDecode");
2107 } 2107 }
2108 writeString(" /N " + QUtil::uint_to_string(offsets.size())); 2108 writeString(" /N " + QUtil::uint_to_string(offsets.size()));
2109 writeStringQDF("\n "); 2109 writeStringQDF("\n ");
2110 writeString(" /First " + QUtil::int_to_string(first)); 2110 writeString(" /First " + QUtil::int_to_string(first));
2111 if (! object.isNull()) 2111 if (! object.isNull())
2112 { 2112 {
2113 - // If the original object has an /Extends key, preserve it.  
2114 - QPDFObjectHandle dict = object.getDict();  
2115 - QPDFObjectHandle extends = dict.getKey("/Extends");  
2116 - if (extends.isIndirect())  
2117 - {  
2118 - QTC::TC("qpdf", "QPDFWriter copy Extends");  
2119 - writeStringQDF("\n ");  
2120 - writeString(" /Extends ");  
2121 - unparseChild(extends, 1, f_in_ostream);  
2122 - } 2113 + // If the original object has an /Extends key, preserve it.
  2114 + QPDFObjectHandle dict = object.getDict();
  2115 + QPDFObjectHandle extends = dict.getKey("/Extends");
  2116 + if (extends.isIndirect())
  2117 + {
  2118 + QTC::TC("qpdf", "QPDFWriter copy Extends");
  2119 + writeStringQDF("\n ");
  2120 + writeString(" /Extends ");
  2121 + unparseChild(extends, 1, f_in_ostream);
  2122 + }
2123 } 2123 }
2124 writeStringQDF("\n"); 2124 writeStringQDF("\n");
2125 writeStringNoQDF(" "); 2125 writeStringNoQDF(" ");
2126 writeString(">>\nstream\n"); 2126 writeString(">>\nstream\n");
2127 if (this->m->encrypted) 2127 if (this->m->encrypted)
2128 { 2128 {
2129 - QTC::TC("qpdf", "QPDFWriter encrypt object stream"); 2129 + QTC::TC("qpdf", "QPDFWriter encrypt object stream");
2130 } 2130 }
2131 { 2131 {
2132 PipelinePopper pp_enc(this); 2132 PipelinePopper pp_enc(this);
@@ -2149,65 +2149,65 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index) @@ -2149,65 +2149,65 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index)
2149 2149
2150 if ((object_stream_index == -1) && 2150 if ((object_stream_index == -1) &&
2151 (old_og.getGen() == 0) && 2151 (old_og.getGen() == 0) &&
2152 - (this->m->object_stream_to_objects.count(old_og.getObj()))) 2152 + (this->m->object_stream_to_objects.count(old_og.getObj())))
2153 { 2153 {
2154 - writeObjectStream(object);  
2155 - return; 2154 + writeObjectStream(object);
  2155 + return;
2156 } 2156 }
2157 2157
2158 indicateProgress(false, false); 2158 indicateProgress(false, false);
2159 int new_id = this->m->obj_renumber[old_og]; 2159 int new_id = this->m->obj_renumber[old_og];
2160 if (this->m->qdf_mode) 2160 if (this->m->qdf_mode)
2161 { 2161 {
2162 - if (this->m->page_object_to_seq.count(old_og))  
2163 - {  
2164 - writeString("%% Page ");  
2165 - writeString(  
2166 - QUtil::int_to_string(  
2167 - this->m->page_object_to_seq[old_og]));  
2168 - writeString("\n");  
2169 - }  
2170 - if (this->m->contents_to_page_seq.count(old_og))  
2171 - {  
2172 - writeString("%% Contents for page ");  
2173 - writeString(  
2174 - QUtil::int_to_string(  
2175 - this->m->contents_to_page_seq[old_og]));  
2176 - writeString("\n");  
2177 - } 2162 + if (this->m->page_object_to_seq.count(old_og))
  2163 + {
  2164 + writeString("%% Page ");
  2165 + writeString(
  2166 + QUtil::int_to_string(
  2167 + this->m->page_object_to_seq[old_og]));
  2168 + writeString("\n");
  2169 + }
  2170 + if (this->m->contents_to_page_seq.count(old_og))
  2171 + {
  2172 + writeString("%% Contents for page ");
  2173 + writeString(
  2174 + QUtil::int_to_string(
  2175 + this->m->contents_to_page_seq[old_og]));
  2176 + writeString("\n");
  2177 + }
2178 } 2178 }
2179 if (object_stream_index == -1) 2179 if (object_stream_index == -1)
2180 { 2180 {
2181 - if (this->m->qdf_mode && (! this->m->suppress_original_object_ids))  
2182 - {  
2183 - writeString("%% Original object ID: " +  
2184 - QUtil::int_to_string(object.getObjectID()) + " " +  
2185 - QUtil::int_to_string(object.getGeneration()) + "\n");  
2186 - }  
2187 - openObject(new_id);  
2188 - setDataKey(new_id);  
2189 - unparseObject(object, 0, 0);  
2190 - this->m->cur_data_key.clear();  
2191 - closeObject(new_id); 2181 + if (this->m->qdf_mode && (! this->m->suppress_original_object_ids))
  2182 + {
  2183 + writeString("%% Original object ID: " +
  2184 + QUtil::int_to_string(object.getObjectID()) + " " +
  2185 + QUtil::int_to_string(object.getGeneration()) + "\n");
  2186 + }
  2187 + openObject(new_id);
  2188 + setDataKey(new_id);
  2189 + unparseObject(object, 0, 0);
  2190 + this->m->cur_data_key.clear();
  2191 + closeObject(new_id);
2192 } 2192 }
2193 else 2193 else
2194 { 2194 {
2195 - unparseObject(object, 0, f_in_ostream);  
2196 - writeString("\n"); 2195 + unparseObject(object, 0, f_in_ostream);
  2196 + writeString("\n");
2197 } 2197 }
2198 2198
2199 if ((! this->m->direct_stream_lengths) && object.isStream()) 2199 if ((! this->m->direct_stream_lengths) && object.isStream())
2200 { 2200 {
2201 - if (this->m->qdf_mode)  
2202 - {  
2203 - if (this->m->added_newline)  
2204 - {  
2205 - writeString("%QDF: ignore_newline\n");  
2206 - }  
2207 - }  
2208 - openObject(new_id + 1);  
2209 - writeString(QUtil::uint_to_string(this->m->cur_stream_length));  
2210 - closeObject(new_id + 1); 2201 + if (this->m->qdf_mode)
  2202 + {
  2203 + if (this->m->added_newline)
  2204 + {
  2205 + writeString("%QDF: ignore_newline\n");
  2206 + }
  2207 + }
  2208 + openObject(new_id + 1);
  2209 + writeString(QUtil::uint_to_string(this->m->cur_stream_length));
  2210 + closeObject(new_id + 1);
2211 } 2211 }
2212 } 2212 }
2213 2213
@@ -2233,7 +2233,7 @@ QPDFWriter::generateID() @@ -2233,7 +2233,7 @@ QPDFWriter::generateID()
2233 2233
2234 if (! this->m->id2.empty()) 2234 if (! this->m->id2.empty())
2235 { 2235 {
2236 - return; 2236 + return;
2237 } 2237 }
2238 2238
2239 QPDFObjectHandle trailer = this->m->pdf.getTrailer(); 2239 QPDFObjectHandle trailer = this->m->pdf.getTrailer();
@@ -2242,30 +2242,30 @@ QPDFWriter::generateID() @@ -2242,30 +2242,30 @@ QPDFWriter::generateID()
2242 2242
2243 if (this->m->static_id) 2243 if (this->m->static_id)
2244 { 2244 {
2245 - // For test suite use only...  
2246 - static unsigned char tmp[] = {0x31, 0x41, 0x59, 0x26, 2245 + // For test suite use only...
  2246 + static unsigned char tmp[] = {0x31, 0x41, 0x59, 0x26,
2247 0x53, 0x58, 0x97, 0x93, 2247 0x53, 0x58, 0x97, 0x93,
2248 0x23, 0x84, 0x62, 0x64, 2248 0x23, 0x84, 0x62, 0x64,
2249 0x33, 0x83, 0x27, 0x95, 2249 0x33, 0x83, 0x27, 0x95,
2250 0x00}; 2250 0x00};
2251 - result = reinterpret_cast<char*>(tmp); 2251 + result = reinterpret_cast<char*>(tmp);
2252 } 2252 }
2253 else 2253 else
2254 { 2254 {
2255 - // The PDF specification has guidelines for creating IDs, but  
2256 - // it states clearly that the only thing that's really  
2257 - // important is that it is very likely to be unique. We can't  
2258 - // really follow the guidelines in the spec exactly because we  
2259 - // haven't written the file yet. This scheme should be fine  
2260 - // though. The deterministic ID case uses a digest of a  
2261 - // sufficient portion of the file's contents such no two  
2262 - // non-matching files would match in the subsets used for this  
2263 - // computation. Note that we explicitly omit the filename from  
2264 - // the digest calculation for deterministic ID so that the same  
2265 - // file converted with qpdf, in that case, would have the same  
2266 - // ID regardless of the output file's name.  
2267 -  
2268 - std::string seed; 2255 + // The PDF specification has guidelines for creating IDs, but
  2256 + // it states clearly that the only thing that's really
  2257 + // important is that it is very likely to be unique. We can't
  2258 + // really follow the guidelines in the spec exactly because we
  2259 + // haven't written the file yet. This scheme should be fine
  2260 + // though. The deterministic ID case uses a digest of a
  2261 + // sufficient portion of the file's contents such no two
  2262 + // non-matching files would match in the subsets used for this
  2263 + // computation. Note that we explicitly omit the filename from
  2264 + // the digest calculation for deterministic ID so that the same
  2265 + // file converted with qpdf, in that case, would have the same
  2266 + // ID regardless of the output file's name.
  2267 +
  2268 + std::string seed;
2269 if (this->m->deterministic_id) 2269 if (this->m->deterministic_id)
2270 { 2270 {
2271 if (this->m->deterministic_id_data.empty()) 2271 if (this->m->deterministic_id_data.empty())
@@ -2285,28 +2285,28 @@ QPDFWriter::generateID() @@ -2285,28 +2285,28 @@ QPDFWriter::generateID()
2285 seed += this->m->filename; 2285 seed += this->m->filename;
2286 seed += " "; 2286 seed += " ";
2287 } 2287 }
2288 - seed += " QPDF ";  
2289 - if (trailer.hasKey("/Info"))  
2290 - { 2288 + seed += " QPDF ";
  2289 + if (trailer.hasKey("/Info"))
  2290 + {
2291 QPDFObjectHandle info = trailer.getKey("/Info"); 2291 QPDFObjectHandle info = trailer.getKey("/Info");
2292 - std::set<std::string> keys = info.getKeys();  
2293 - for (std::set<std::string>::iterator iter = keys.begin();  
2294 - iter != keys.end(); ++iter)  
2295 - {  
2296 - QPDFObjectHandle obj = info.getKey(*iter);  
2297 - if (obj.isString())  
2298 - {  
2299 - seed += " ";  
2300 - seed += obj.getStringValue();  
2301 - }  
2302 - }  
2303 - }  
2304 -  
2305 - MD5 m;  
2306 - m.encodeString(seed.c_str());  
2307 - MD5::Digest digest;  
2308 - m.digest(digest);  
2309 - result = std::string(reinterpret_cast<char*>(digest), 2292 + std::set<std::string> keys = info.getKeys();
  2293 + for (std::set<std::string>::iterator iter = keys.begin();
  2294 + iter != keys.end(); ++iter)
  2295 + {
  2296 + QPDFObjectHandle obj = info.getKey(*iter);
  2297 + if (obj.isString())
  2298 + {
  2299 + seed += " ";
  2300 + seed += obj.getStringValue();
  2301 + }
  2302 + }
  2303 + }
  2304 +
  2305 + MD5 m;
  2306 + m.encodeString(seed.c_str());
  2307 + MD5::Digest digest;
  2308 + m.digest(digest);
  2309 + result = std::string(reinterpret_cast<char*>(digest),
2310 sizeof(MD5::Digest)); 2310 sizeof(MD5::Digest));
2311 } 2311 }
2312 2312
@@ -2319,7 +2319,7 @@ QPDFWriter::generateID() @@ -2319,7 +2319,7 @@ QPDFWriter::generateID()
2319 this->m->id1 = getOriginalID1(); 2319 this->m->id1 = getOriginalID1();
2320 if (this->m->id1.empty()) 2320 if (this->m->id1.empty())
2321 { 2321 {
2322 - this->m->id1 = this->m->id2; 2322 + this->m->id1 = this->m->id2;
2323 } 2323 }
2324 } 2324 }
2325 2325
@@ -2331,31 +2331,31 @@ QPDFWriter::initializeSpecialStreams() @@ -2331,31 +2331,31 @@ QPDFWriter::initializeSpecialStreams()
2331 std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages(); 2331 std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages();
2332 int num = 0; 2332 int num = 0;
2333 for (std::vector<QPDFObjectHandle>::iterator iter = pages.begin(); 2333 for (std::vector<QPDFObjectHandle>::iterator iter = pages.begin();
2334 - iter != pages.end(); ++iter)  
2335 - {  
2336 - QPDFObjectHandle& page = *iter;  
2337 - this->m->page_object_to_seq[page.getObjGen()] = ++num;  
2338 - QPDFObjectHandle contents = page.getKey("/Contents");  
2339 - std::vector<QPDFObjGen> contents_objects;  
2340 - if (contents.isArray())  
2341 - {  
2342 - int n = contents.getArrayNItems();  
2343 - for (int i = 0; i < n; ++i)  
2344 - {  
2345 - contents_objects.push_back(  
2346 - contents.getArrayItem(i).getObjGen());  
2347 - }  
2348 - }  
2349 - else if (contents.isStream())  
2350 - {  
2351 - contents_objects.push_back(contents.getObjGen());  
2352 - }  
2353 -  
2354 - for (auto const& c: contents_objects)  
2355 - {  
2356 - this->m->contents_to_page_seq[c] = num;  
2357 - this->m->normalized_streams.insert(c);  
2358 - } 2334 + iter != pages.end(); ++iter)
  2335 + {
  2336 + QPDFObjectHandle& page = *iter;
  2337 + this->m->page_object_to_seq[page.getObjGen()] = ++num;
  2338 + QPDFObjectHandle contents = page.getKey("/Contents");
  2339 + std::vector<QPDFObjGen> contents_objects;
  2340 + if (contents.isArray())
  2341 + {
  2342 + int n = contents.getArrayNItems();
  2343 + for (int i = 0; i < n; ++i)
  2344 + {
  2345 + contents_objects.push_back(
  2346 + contents.getArrayItem(i).getObjGen());
  2347 + }
  2348 + }
  2349 + else if (contents.isStream())
  2350 + {
  2351 + contents_objects.push_back(contents.getObjGen());
  2352 + }
  2353 +
  2354 + for (auto const& c: contents_objects)
  2355 + {
  2356 + this->m->contents_to_page_seq[c] = num;
  2357 + this->m->normalized_streams.insert(c);
  2358 + }
2359 } 2359 }
2360 } 2360 }
2361 2361
@@ -2424,31 +2424,31 @@ QPDFWriter::generateObjectStreams() @@ -2424,31 +2424,31 @@ QPDFWriter::generateObjectStreams()
2424 size_t n_per = eligible.size() / n_object_streams; 2424 size_t n_per = eligible.size() / n_object_streams;
2425 if (n_per * n_object_streams < eligible.size()) 2425 if (n_per * n_object_streams < eligible.size())
2426 { 2426 {
2427 - ++n_per; 2427 + ++n_per;
2428 } 2428 }
2429 unsigned int n = 0; 2429 unsigned int n = 0;
2430 int cur_ostream = 0; 2430 int cur_ostream = 0;
2431 for (std::vector<QPDFObjGen>::const_iterator iter = eligible.begin(); 2431 for (std::vector<QPDFObjGen>::const_iterator iter = eligible.begin();
2432 - iter != eligible.end(); ++iter)  
2433 - {  
2434 - if ((n % n_per) == 0)  
2435 - {  
2436 - if (n > 0)  
2437 - {  
2438 - QTC::TC("qpdf", "QPDFWriter generate >1 ostream");  
2439 - }  
2440 - n = 0;  
2441 - }  
2442 - if (n == 0)  
2443 - {  
2444 - // Construct a new null object as the "original" object  
2445 - // stream. The rest of the code knows that this means  
2446 - // we're creating the object stream from scratch.  
2447 - cur_ostream = this->m->pdf.makeIndirectObject(  
2448 - QPDFObjectHandle::newNull()).getObjectID();  
2449 - }  
2450 - this->m->object_to_object_stream[*iter] = cur_ostream;  
2451 - ++n; 2432 + iter != eligible.end(); ++iter)
  2433 + {
  2434 + if ((n % n_per) == 0)
  2435 + {
  2436 + if (n > 0)
  2437 + {
  2438 + QTC::TC("qpdf", "QPDFWriter generate >1 ostream");
  2439 + }
  2440 + n = 0;
  2441 + }
  2442 + if (n == 0)
  2443 + {
  2444 + // Construct a new null object as the "original" object
  2445 + // stream. The rest of the code knows that this means
  2446 + // we're creating the object stream from scratch.
  2447 + cur_ostream = this->m->pdf.makeIndirectObject(
  2448 + QPDFObjectHandle::newNull()).getObjectID();
  2449 + }
  2450 + this->m->object_to_object_stream[*iter] = cur_ostream;
  2451 + ++n;
2452 } 2452 }
2453 } 2453 }
2454 2454
@@ -2529,7 +2529,7 @@ QPDFWriter::doWriteSetup() @@ -2529,7 +2529,7 @@ QPDFWriter::doWriteSetup()
2529 2529
2530 if (this->m->linearized) 2530 if (this->m->linearized)
2531 { 2531 {
2532 - this->m->qdf_mode = false; 2532 + this->m->qdf_mode = false;
2533 } 2533 }
2534 2534
2535 if (this->m->pclm) 2535 if (this->m->pclm)
@@ -2541,14 +2541,14 @@ QPDFWriter::doWriteSetup() @@ -2541,14 +2541,14 @@ QPDFWriter::doWriteSetup()
2541 2541
2542 if (this->m->qdf_mode) 2542 if (this->m->qdf_mode)
2543 { 2543 {
2544 - if (! this->m->normalize_content_set)  
2545 - {  
2546 - this->m->normalize_content = true;  
2547 - }  
2548 - if (! this->m->compress_streams_set)  
2549 - {  
2550 - this->m->compress_streams = false;  
2551 - } 2544 + if (! this->m->normalize_content_set)
  2545 + {
  2546 + this->m->normalize_content = true;
  2547 + }
  2548 + if (! this->m->compress_streams_set)
  2549 + {
  2550 + this->m->compress_streams = false;
  2551 + }
2552 if (! this->m->stream_decode_level_set) 2552 if (! this->m->stream_decode_level_set)
2553 { 2553 {
2554 this->m->stream_decode_level = qpdf_dl_generalized; 2554 this->m->stream_decode_level = qpdf_dl_generalized;
@@ -2557,119 +2557,119 @@ QPDFWriter::doWriteSetup() @@ -2557,119 +2557,119 @@ QPDFWriter::doWriteSetup()
2557 2557
2558 if (this->m->encrypted) 2558 if (this->m->encrypted)
2559 { 2559 {
2560 - // Encryption has been explicitly set  
2561 - this->m->preserve_encryption = false; 2560 + // Encryption has been explicitly set
  2561 + this->m->preserve_encryption = false;
2562 } 2562 }
2563 else if (this->m->normalize_content || 2563 else if (this->m->normalize_content ||
2564 - this->m->stream_decode_level || 2564 + this->m->stream_decode_level ||
2565 this->m->pclm || 2565 this->m->pclm ||
2566 - this->m->qdf_mode) 2566 + this->m->qdf_mode)
2567 { 2567 {
2568 - // Encryption makes looking at contents pretty useless. If  
2569 - // the user explicitly encrypted though, we still obey that.  
2570 - this->m->preserve_encryption = false; 2568 + // Encryption makes looking at contents pretty useless. If
  2569 + // the user explicitly encrypted though, we still obey that.
  2570 + this->m->preserve_encryption = false;
2571 } 2571 }
2572 2572
2573 if (this->m->preserve_encryption) 2573 if (this->m->preserve_encryption)
2574 { 2574 {
2575 - copyEncryptionParameters(this->m->pdf); 2575 + copyEncryptionParameters(this->m->pdf);
2576 } 2576 }
2577 2577
2578 if (! this->m->forced_pdf_version.empty()) 2578 if (! this->m->forced_pdf_version.empty())
2579 { 2579 {
2580 - int major = 0;  
2581 - int minor = 0;  
2582 - parseVersion(this->m->forced_pdf_version, major, minor);  
2583 - disableIncompatibleEncryption(major, minor, 2580 + int major = 0;
  2581 + int minor = 0;
  2582 + parseVersion(this->m->forced_pdf_version, major, minor);
  2583 + disableIncompatibleEncryption(major, minor,
2584 this->m->forced_extension_level); 2584 this->m->forced_extension_level);
2585 - if (compareVersions(major, minor, 1, 5) < 0)  
2586 - {  
2587 - QTC::TC("qpdf", "QPDFWriter forcing object stream disable");  
2588 - this->m->object_stream_mode = qpdf_o_disable;  
2589 - } 2585 + if (compareVersions(major, minor, 1, 5) < 0)
  2586 + {
  2587 + QTC::TC("qpdf", "QPDFWriter forcing object stream disable");
  2588 + this->m->object_stream_mode = qpdf_o_disable;
  2589 + }
2590 } 2590 }
2591 2591
2592 if (this->m->qdf_mode || this->m->normalize_content || 2592 if (this->m->qdf_mode || this->m->normalize_content ||
2593 this->m->stream_decode_level) 2593 this->m->stream_decode_level)
2594 { 2594 {
2595 - initializeSpecialStreams(); 2595 + initializeSpecialStreams();
2596 } 2596 }
2597 2597
2598 if (this->m->qdf_mode) 2598 if (this->m->qdf_mode)
2599 { 2599 {
2600 - // Generate indirect stream lengths for qdf mode since fix-qdf  
2601 - // uses them for storing recomputed stream length data.  
2602 - // Certain streams such as object streams, xref streams, and  
2603 - // hint streams always get direct stream lengths.  
2604 - this->m->direct_stream_lengths = false; 2600 + // Generate indirect stream lengths for qdf mode since fix-qdf
  2601 + // uses them for storing recomputed stream length data.
  2602 + // Certain streams such as object streams, xref streams, and
  2603 + // hint streams always get direct stream lengths.
  2604 + this->m->direct_stream_lengths = false;
2605 } 2605 }
2606 2606
2607 switch (this->m->object_stream_mode) 2607 switch (this->m->object_stream_mode)
2608 { 2608 {
2609 case qpdf_o_disable: 2609 case qpdf_o_disable:
2610 - // no action required  
2611 - break; 2610 + // no action required
  2611 + break;
2612 2612
2613 case qpdf_o_preserve: 2613 case qpdf_o_preserve:
2614 - preserveObjectStreams();  
2615 - break; 2614 + preserveObjectStreams();
  2615 + break;
2616 2616
2617 case qpdf_o_generate: 2617 case qpdf_o_generate:
2618 - generateObjectStreams();  
2619 - break; 2618 + generateObjectStreams();
  2619 + break;
2620 2620
2621 - // no default so gcc will warn for missing case tag 2621 + // no default so gcc will warn for missing case tag
2622 } 2622 }
2623 2623
2624 if (this->m->linearized) 2624 if (this->m->linearized)
2625 { 2625 {
2626 - // Page dictionaries are not allowed to be compressed objects.  
2627 - std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages();  
2628 - for (std::vector<QPDFObjectHandle>::iterator iter = pages.begin();  
2629 - iter != pages.end(); ++iter)  
2630 - {  
2631 - QPDFObjectHandle& page = *iter;  
2632 - QPDFObjGen og = page.getObjGen();  
2633 - if (this->m->object_to_object_stream.count(og))  
2634 - {  
2635 - QTC::TC("qpdf", "QPDFWriter uncompressing page dictionary");  
2636 - this->m->object_to_object_stream.erase(og);  
2637 - }  
2638 - } 2626 + // Page dictionaries are not allowed to be compressed objects.
  2627 + std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages();
  2628 + for (std::vector<QPDFObjectHandle>::iterator iter = pages.begin();
  2629 + iter != pages.end(); ++iter)
  2630 + {
  2631 + QPDFObjectHandle& page = *iter;
  2632 + QPDFObjGen og = page.getObjGen();
  2633 + if (this->m->object_to_object_stream.count(og))
  2634 + {
  2635 + QTC::TC("qpdf", "QPDFWriter uncompressing page dictionary");
  2636 + this->m->object_to_object_stream.erase(og);
  2637 + }
  2638 + }
2639 } 2639 }
2640 2640
2641 if (this->m->linearized || this->m->encrypted) 2641 if (this->m->linearized || this->m->encrypted)
2642 { 2642 {
2643 - // The document catalog is not allowed to be compressed in  
2644 - // linearized files either. It also appears that Adobe Reader  
2645 - // 8.0.0 has a bug that prevents it from being able to handle  
2646 - // encrypted files with compressed document catalogs, so we  
2647 - // disable them in that case as well.  
2648 - QPDFObjGen og = this->m->pdf.getRoot().getObjGen();  
2649 - if (this->m->object_to_object_stream.count(og))  
2650 - {  
2651 - QTC::TC("qpdf", "QPDFWriter uncompressing root");  
2652 - this->m->object_to_object_stream.erase(og);  
2653 - } 2643 + // The document catalog is not allowed to be compressed in
  2644 + // linearized files either. It also appears that Adobe Reader
  2645 + // 8.0.0 has a bug that prevents it from being able to handle
  2646 + // encrypted files with compressed document catalogs, so we
  2647 + // disable them in that case as well.
  2648 + QPDFObjGen og = this->m->pdf.getRoot().getObjGen();
  2649 + if (this->m->object_to_object_stream.count(og))
  2650 + {
  2651 + QTC::TC("qpdf", "QPDFWriter uncompressing root");
  2652 + this->m->object_to_object_stream.erase(og);
  2653 + }
2654 } 2654 }
2655 2655
2656 // Generate reverse mapping from object stream to objects 2656 // Generate reverse mapping from object stream to objects
2657 for (std::map<QPDFObjGen, int>::iterator iter = 2657 for (std::map<QPDFObjGen, int>::iterator iter =
2658 - this->m->object_to_object_stream.begin();  
2659 - iter != this->m->object_to_object_stream.end(); ++iter)  
2660 - {  
2661 - QPDFObjGen obj = (*iter).first;  
2662 - int stream = (*iter).second;  
2663 - this->m->object_stream_to_objects[stream].insert(obj);  
2664 - this->m->max_ostream_index =  
2665 - std::max(this->m->max_ostream_index,  
2666 - QIntC::to_int( 2658 + this->m->object_to_object_stream.begin();
  2659 + iter != this->m->object_to_object_stream.end(); ++iter)
  2660 + {
  2661 + QPDFObjGen obj = (*iter).first;
  2662 + int stream = (*iter).second;
  2663 + this->m->object_stream_to_objects[stream].insert(obj);
  2664 + this->m->max_ostream_index =
  2665 + std::max(this->m->max_ostream_index,
  2666 + QIntC::to_int(
2667 this->m->object_stream_to_objects[stream].size()) - 1); 2667 this->m->object_stream_to_objects[stream].size()) - 1);
2668 } 2668 }
2669 2669
2670 if (! this->m->object_stream_to_objects.empty()) 2670 if (! this->m->object_stream_to_objects.empty())
2671 { 2671 {
2672 - setMinimumPDFVersion("1.5"); 2672 + setMinimumPDFVersion("1.5");
2673 } 2673 }
2674 2674
2675 setMinimumPDFVersion(this->m->pdf.getPDFVersion(), 2675 setMinimumPDFVersion(this->m->pdf.getPDFVersion(),
@@ -2678,8 +2678,8 @@ QPDFWriter::doWriteSetup() @@ -2678,8 +2678,8 @@ QPDFWriter::doWriteSetup()
2678 this->m->final_extension_level = this->m->min_extension_level; 2678 this->m->final_extension_level = this->m->min_extension_level;
2679 if (! this->m->forced_pdf_version.empty()) 2679 if (! this->m->forced_pdf_version.empty())
2680 { 2680 {
2681 - QTC::TC("qpdf", "QPDFWriter using forced PDF version");  
2682 - this->m->final_pdf_version = this->m->forced_pdf_version; 2681 + QTC::TC("qpdf", "QPDFWriter using forced PDF version");
  2682 + this->m->final_pdf_version = this->m->forced_pdf_version;
2683 this->m->final_extension_level = this->m->forced_extension_level; 2683 this->m->final_extension_level = this->m->forced_extension_level;
2684 } 2684 }
2685 } 2685 }
@@ -2699,23 +2699,23 @@ QPDFWriter::write() @@ -2699,23 +2699,23 @@ QPDFWriter::write()
2699 2699
2700 if (this->m->linearized) 2700 if (this->m->linearized)
2701 { 2701 {
2702 - writeLinearized(); 2702 + writeLinearized();
2703 } 2703 }
2704 else 2704 else
2705 { 2705 {
2706 - writeStandard(); 2706 + writeStandard();
2707 } 2707 }
2708 2708
2709 this->m->pipeline->finish(); 2709 this->m->pipeline->finish();
2710 if (this->m->close_file) 2710 if (this->m->close_file)
2711 { 2711 {
2712 - fclose(this->m->file); 2712 + fclose(this->m->file);
2713 } 2713 }
2714 this->m->file = 0; 2714 this->m->file = 0;
2715 if (this->m->buffer_pipeline) 2715 if (this->m->buffer_pipeline)
2716 { 2716 {
2717 - this->m->output_buffer = this->m->buffer_pipeline->getBuffer();  
2718 - this->m->buffer_pipeline = 0; 2717 + this->m->output_buffer = this->m->buffer_pipeline->getBuffer();
  2718 + this->m->buffer_pipeline = 0;
2719 } 2719 }
2720 indicateProgress(false, true); 2720 indicateProgress(false, true);
2721 } 2721 }
@@ -2747,9 +2747,9 @@ void @@ -2747,9 +2747,9 @@ void
2747 QPDFWriter::enqueuePart(std::vector<QPDFObjectHandle>& part) 2747 QPDFWriter::enqueuePart(std::vector<QPDFObjectHandle>& part)
2748 { 2748 {
2749 for (std::vector<QPDFObjectHandle>::iterator iter = part.begin(); 2749 for (std::vector<QPDFObjectHandle>::iterator iter = part.begin();
2750 - iter != part.end(); ++iter) 2750 + iter != part.end(); ++iter)
2751 { 2751 {
2752 - enqueueObject(*iter); 2752 + enqueueObject(*iter);
2753 } 2753 }
2754 } 2754 }
2755 2755
@@ -2759,13 +2759,13 @@ QPDFWriter::writeEncryptionDictionary() @@ -2759,13 +2759,13 @@ QPDFWriter::writeEncryptionDictionary()
2759 this->m->encryption_dict_objid = openObject(this->m->encryption_dict_objid); 2759 this->m->encryption_dict_objid = openObject(this->m->encryption_dict_objid);
2760 writeString("<<"); 2760 writeString("<<");
2761 for (std::map<std::string, std::string>::iterator iter = 2761 for (std::map<std::string, std::string>::iterator iter =
2762 - this->m->encryption_dictionary.begin();  
2763 - iter != this->m->encryption_dictionary.end(); ++iter) 2762 + this->m->encryption_dictionary.begin();
  2763 + iter != this->m->encryption_dictionary.end(); ++iter)
2764 { 2764 {
2765 - writeString(" ");  
2766 - writeString((*iter).first);  
2767 - writeString(" ");  
2768 - writeString((*iter).second); 2765 + writeString(" ");
  2766 + writeString((*iter).first);
  2767 + writeString(" ");
  2768 + writeString((*iter).second);
2769 } 2769 }
2770 writeString(" >>"); 2770 writeString(" >>");
2771 closeObject(this->m->encryption_dict_objid); 2771 closeObject(this->m->encryption_dict_objid);
@@ -2823,8 +2823,8 @@ QPDFWriter::writeHintStream(int hint_id) @@ -2823,8 +2823,8 @@ QPDFWriter::writeHintStream(int hint_id)
2823 writeString(QUtil::int_to_string(S)); 2823 writeString(QUtil::int_to_string(S));
2824 if (O) 2824 if (O)
2825 { 2825 {
2826 - writeString(" /O ");  
2827 - writeString(QUtil::int_to_string(O)); 2826 + writeString(" /O ");
  2827 + writeString(QUtil::int_to_string(O));
2828 } 2828 }
2829 writeString(" /Length "); 2829 writeString(" /Length ");
2830 adjustAESStreamLength(hlen); 2830 adjustAESStreamLength(hlen);
@@ -2833,7 +2833,7 @@ QPDFWriter::writeHintStream(int hint_id) @@ -2833,7 +2833,7 @@ QPDFWriter::writeHintStream(int hint_id)
2833 2833
2834 if (this->m->encrypted) 2834 if (this->m->encrypted)
2835 { 2835 {
2836 - QTC::TC("qpdf", "QPDFWriter encrypted hint stream"); 2836 + QTC::TC("qpdf", "QPDFWriter encrypted hint stream");
2837 } 2837 }
2838 unsigned char last_char = '\0'; 2838 unsigned char last_char = '\0';
2839 { 2839 {
@@ -2845,7 +2845,7 @@ QPDFWriter::writeHintStream(int hint_id) @@ -2845,7 +2845,7 @@ QPDFWriter::writeHintStream(int hint_id)
2845 2845
2846 if (last_char != '\n') 2846 if (last_char != '\n')
2847 { 2847 {
2848 - writeString("\n"); 2848 + writeString("\n");
2849 } 2849 }
2850 writeString("endstream"); 2850 writeString("endstream");
2851 closeObject(hint_id); 2851 closeObject(hint_id);
@@ -2862,8 +2862,8 @@ QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size) @@ -2862,8 +2862,8 @@ QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size)
2862 2862
2863 qpdf_offset_t 2863 qpdf_offset_t
2864 QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size, 2864 QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size,
2865 - qpdf_offset_t prev, bool suppress_offsets,  
2866 - int hint_id, qpdf_offset_t hint_offset, 2865 + qpdf_offset_t prev, bool suppress_offsets,
  2866 + int hint_id, qpdf_offset_t hint_offset,
2867 qpdf_offset_t hint_length, int linearization_pass) 2867 qpdf_offset_t hint_length, int linearization_pass)
2868 { 2868 {
2869 writeString("xref\n"); 2869 writeString("xref\n");
@@ -2874,26 +2874,26 @@ QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size, @@ -2874,26 +2874,26 @@ QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size,
2874 writeString("\n"); 2874 writeString("\n");
2875 for (int i = first; i <= last; ++i) 2875 for (int i = first; i <= last; ++i)
2876 { 2876 {
2877 - if (i == 0)  
2878 - {  
2879 - writeString("0000000000 65535 f \n");  
2880 - }  
2881 - else  
2882 - {  
2883 - qpdf_offset_t offset = 0;  
2884 - if (! suppress_offsets)  
2885 - {  
2886 - offset = this->m->xref[i].getOffset();  
2887 - if ((hint_id != 0) &&  
2888 - (i != hint_id) &&  
2889 - (offset >= hint_offset))  
2890 - {  
2891 - offset += hint_length;  
2892 - }  
2893 - }  
2894 - writeString(QUtil::int_to_string(offset, 10));  
2895 - writeString(" 00000 n \n");  
2896 - } 2877 + if (i == 0)
  2878 + {
  2879 + writeString("0000000000 65535 f \n");
  2880 + }
  2881 + else
  2882 + {
  2883 + qpdf_offset_t offset = 0;
  2884 + if (! suppress_offsets)
  2885 + {
  2886 + offset = this->m->xref[i].getOffset();
  2887 + if ((hint_id != 0) &&
  2888 + (i != hint_id) &&
  2889 + (offset >= hint_offset))
  2890 + {
  2891 + offset += hint_length;
  2892 + }
  2893 + }
  2894 + writeString(QUtil::int_to_string(offset, 10));
  2895 + writeString(" 00000 n \n");
  2896 + }
2897 } 2897 }
2898 writeTrailer(which, size, false, prev, linearization_pass); 2898 writeTrailer(which, size, false, prev, linearization_pass);
2899 writeString("\n"); 2899 writeString("\n");
@@ -2902,22 +2902,22 @@ QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size, @@ -2902,22 +2902,22 @@ QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size,
2902 2902
2903 qpdf_offset_t 2903 qpdf_offset_t
2904 QPDFWriter::writeXRefStream(int objid, int max_id, qpdf_offset_t max_offset, 2904 QPDFWriter::writeXRefStream(int objid, int max_id, qpdf_offset_t max_offset,
2905 - trailer_e which, int first, int last, int size) 2905 + trailer_e which, int first, int last, int size)
2906 { 2906 {
2907 // There are too many extra arguments to replace overloaded 2907 // There are too many extra arguments to replace overloaded
2908 // function with defaults in the header file...too much risk of 2908 // function with defaults in the header file...too much risk of
2909 // leaving something off. 2909 // leaving something off.
2910 return writeXRefStream(objid, max_id, max_offset, 2910 return writeXRefStream(objid, max_id, max_offset,
2911 - which, first, last, size, 0, 0, 0, 0, false, 0); 2911 + which, first, last, size, 0, 0, 0, 0, false, 0);
2912 } 2912 }
2913 2913
2914 qpdf_offset_t 2914 qpdf_offset_t
2915 QPDFWriter::writeXRefStream(int xref_id, int max_id, qpdf_offset_t max_offset, 2915 QPDFWriter::writeXRefStream(int xref_id, int max_id, qpdf_offset_t max_offset,
2916 - trailer_e which, int first, int last, int size,  
2917 - qpdf_offset_t prev, int hint_id,  
2918 - qpdf_offset_t hint_offset, 2916 + trailer_e which, int first, int last, int size,
  2917 + qpdf_offset_t prev, int hint_id,
  2918 + qpdf_offset_t hint_offset,
2919 qpdf_offset_t hint_length, 2919 qpdf_offset_t hint_length,
2920 - bool skip_compression, 2920 + bool skip_compression,
2921 int linearization_pass) 2921 int linearization_pass)
2922 { 2922 {
2923 qpdf_offset_t xref_offset = this->m->pipeline->getCount(); 2923 qpdf_offset_t xref_offset = this->m->pipeline->getCount();
@@ -2942,18 +2942,18 @@ QPDFWriter::writeXRefStream(int xref_id, int max_id, qpdf_offset_t max_offset, @@ -2942,18 +2942,18 @@ QPDFWriter::writeXRefStream(int xref_id, int max_id, qpdf_offset_t max_offset,
2942 (this->m->stream_decode_level == qpdf_dl_none)) && 2942 (this->m->stream_decode_level == qpdf_dl_none)) &&
2943 (! this->m->qdf_mode)) 2943 (! this->m->qdf_mode))
2944 { 2944 {
2945 - compressed = true;  
2946 - if (! skip_compression)  
2947 - {  
2948 - // Write the stream dictionary for compression but don't  
2949 - // actually compress. This helps us with computation of  
2950 - // padding for pass 1 of linearization.  
2951 - p = pushPipeline(  
2952 - new Pl_Flate("compress xref", p, Pl_Flate::a_deflate));  
2953 - }  
2954 - p = pushPipeline(  
2955 - new Pl_PNGFilter(  
2956 - "pngify xref", p, Pl_PNGFilter::a_encode, esize)); 2945 + compressed = true;
  2946 + if (! skip_compression)
  2947 + {
  2948 + // Write the stream dictionary for compression but don't
  2949 + // actually compress. This helps us with computation of
  2950 + // padding for pass 1 of linearization.
  2951 + p = pushPipeline(
  2952 + new Pl_Flate("compress xref", p, Pl_Flate::a_deflate));
  2953 + }
  2954 + p = pushPipeline(
  2955 + new Pl_PNGFilter(
  2956 + "pngify xref", p, Pl_PNGFilter::a_encode, esize));
2957 } 2957 }
2958 PointerHolder<Buffer> xref_data; 2958 PointerHolder<Buffer> xref_data;
2959 { 2959 {
@@ -3006,21 +3006,21 @@ QPDFWriter::writeXRefStream(int xref_id, int max_id, qpdf_offset_t max_offset, @@ -3006,21 +3006,21 @@ QPDFWriter::writeXRefStream(int xref_id, int max_id, qpdf_offset_t max_offset,
3006 writeString(" /Length " + QUtil::uint_to_string(xref_data->getSize())); 3006 writeString(" /Length " + QUtil::uint_to_string(xref_data->getSize()));
3007 if (compressed) 3007 if (compressed)
3008 { 3008 {
3009 - writeStringQDF("\n ");  
3010 - writeString(" /Filter /FlateDecode");  
3011 - writeStringQDF("\n ");  
3012 - writeString(" /DecodeParms << /Columns " +  
3013 - QUtil::int_to_string(esize) + " /Predictor 12 >>"); 3009 + writeStringQDF("\n ");
  3010 + writeString(" /Filter /FlateDecode");
  3011 + writeStringQDF("\n ");
  3012 + writeString(" /DecodeParms << /Columns " +
  3013 + QUtil::int_to_string(esize) + " /Predictor 12 >>");
3014 } 3014 }
3015 writeStringQDF("\n "); 3015 writeStringQDF("\n ");
3016 writeString(" /W [ 1 " + 3016 writeString(" /W [ 1 " +
3017 - QUtil::int_to_string(f1_size) + " " +  
3018 - QUtil::int_to_string(f2_size) + " ]"); 3017 + QUtil::int_to_string(f1_size) + " " +
  3018 + QUtil::int_to_string(f2_size) + " ]");
3019 if (! ((first == 0) && (last == size - 1))) 3019 if (! ((first == 0) && (last == size - 1)))
3020 { 3020 {
3021 - writeString(" /Index [ " +  
3022 - QUtil::int_to_string(first) + " " +  
3023 - QUtil::int_to_string(last - first + 1) + " ]"); 3021 + writeString(" /Index [ " +
  3022 + QUtil::int_to_string(first) + " " +
  3023 + QUtil::int_to_string(last - first + 1) + " ]");
3024 } 3024 }
3025 writeTrailer(which, size, true, prev, linearization_pass); 3025 writeTrailer(which, size, true, prev, linearization_pass);
3026 writeString("\nstream\n"); 3026 writeString("\nstream\n");
@@ -3138,17 +3138,17 @@ QPDFWriter::writeLinearized() @@ -3138,17 +3138,17 @@ QPDFWriter::writeLinearized()
3138 bool need_xref_stream = (! this->m->object_to_object_stream.empty()); 3138 bool need_xref_stream = (! this->m->object_to_object_stream.empty());
3139 if (need_xref_stream) 3139 if (need_xref_stream)
3140 { 3140 {
3141 - second_half_xref = this->m->next_objid++; 3141 + second_half_xref = this->m->next_objid++;
3142 } 3142 }
3143 // Assign numbers to all compressed objects in the second half. 3143 // Assign numbers to all compressed objects in the second half.
3144 std::vector<QPDFObjectHandle>* vecs2[] = {&part7, &part8, &part9}; 3144 std::vector<QPDFObjectHandle>* vecs2[] = {&part7, &part8, &part9};
3145 for (int i = 0; i < 3; ++i) 3145 for (int i = 0; i < 3; ++i)
3146 { 3146 {
3147 - for (std::vector<QPDFObjectHandle>::iterator iter = (*vecs2[i]).begin();  
3148 - iter != (*vecs2[i]).end(); ++iter)  
3149 - {  
3150 - assignCompressedObjectNumbers((*iter).getObjGen());  
3151 - } 3147 + for (std::vector<QPDFObjectHandle>::iterator iter = (*vecs2[i]).begin();
  3148 + iter != (*vecs2[i]).end(); ++iter)
  3149 + {
  3150 + assignCompressedObjectNumbers((*iter).getObjGen());
  3151 + }
3152 } 3152 }
3153 int second_half_end = this->m->next_objid - 1; 3153 int second_half_end = this->m->next_objid - 1;
3154 int second_trailer_size = this->m->next_objid; 3154 int second_trailer_size = this->m->next_objid;
@@ -3159,14 +3159,14 @@ QPDFWriter::writeLinearized() @@ -3159,14 +3159,14 @@ QPDFWriter::writeLinearized()
3159 int first_half_xref = 0; 3159 int first_half_xref = 0;
3160 if (need_xref_stream) 3160 if (need_xref_stream)
3161 { 3161 {
3162 - first_half_xref = this->m->next_objid++; 3162 + first_half_xref = this->m->next_objid++;
3163 } 3163 }
3164 int part4_first_obj = this->m->next_objid; 3164 int part4_first_obj = this->m->next_objid;
3165 this->m->next_objid += QIntC::to_int(part4.size()); 3165 this->m->next_objid += QIntC::to_int(part4.size());
3166 int after_part4 = this->m->next_objid; 3166 int after_part4 = this->m->next_objid;
3167 if (this->m->encrypted) 3167 if (this->m->encrypted)
3168 { 3168 {
3169 - this->m->encryption_dict_objid = this->m->next_objid++; 3169 + this->m->encryption_dict_objid = this->m->next_objid++;
3170 } 3170 }
3171 int hint_id = this->m->next_objid++; 3171 int hint_id = this->m->next_objid++;
3172 int part6_first_obj = this->m->next_objid; 3172 int part6_first_obj = this->m->next_objid;
@@ -3176,11 +3176,11 @@ QPDFWriter::writeLinearized() @@ -3176,11 +3176,11 @@ QPDFWriter::writeLinearized()
3176 std::vector<QPDFObjectHandle>* vecs1[] = {&part4, &part6}; 3176 std::vector<QPDFObjectHandle>* vecs1[] = {&part4, &part6};
3177 for (int i = 0; i < 2; ++i) 3177 for (int i = 0; i < 2; ++i)
3178 { 3178 {
3179 - for (std::vector<QPDFObjectHandle>::iterator iter = (*vecs1[i]).begin();  
3180 - iter != (*vecs1[i]).end(); ++iter)  
3181 - {  
3182 - assignCompressedObjectNumbers((*iter).getObjGen());  
3183 - } 3179 + for (std::vector<QPDFObjectHandle>::iterator iter = (*vecs1[i]).begin();
  3180 + iter != (*vecs1[i]).end(); ++iter)
  3181 + {
  3182 + assignCompressedObjectNumbers((*iter).getObjGen());
  3183 + }
3184 } 3184 }
3185 int first_half_end = this->m->next_objid - 1; 3185 int first_half_end = this->m->next_objid - 1;
3186 int first_trailer_size = this->m->next_objid; 3186 int first_trailer_size = this->m->next_objid;
@@ -3235,8 +3235,8 @@ QPDFWriter::writeLinearized() @@ -3235,8 +3235,8 @@ QPDFWriter::writeLinearized()
3235 auto pp_md5 = make_pointer_holder<PipelinePopper>(this); 3235 auto pp_md5 = make_pointer_holder<PipelinePopper>(this);
3236 for (int pass = 1; pass <= 2; ++pass) 3236 for (int pass = 1; pass <= 2; ++pass)
3237 { 3237 {
3238 - if (pass == 1)  
3239 - { 3238 + if (pass == 1)
  3239 + {
3240 if (! this->m->lin_pass1_filename.empty()) 3240 if (! this->m->lin_pass1_filename.empty())
3241 { 3241 {
3242 lin_pass1_file = 3242 lin_pass1_file =
@@ -3254,107 +3254,107 @@ QPDFWriter::writeLinearized() @@ -3254,107 +3254,107 @@ QPDFWriter::writeLinearized()
3254 { 3254 {
3255 pushMD5Pipeline(*pp_md5); 3255 pushMD5Pipeline(*pp_md5);
3256 } 3256 }
3257 - }  
3258 -  
3259 - // Part 1: header  
3260 -  
3261 - writeHeader();  
3262 -  
3263 - // Part 2: linearization parameter dictionary. Save enough  
3264 - // space to write real dictionary. 200 characters is enough  
3265 - // space if all numerical values in the parameter dictionary  
3266 - // that contain offsets are 20 digits long plus a few extra  
3267 - // characters for safety. The entire linearization parameter  
3268 - // dictionary must appear within the first 1024 characters of  
3269 - // the file.  
3270 -  
3271 - qpdf_offset_t pos = this->m->pipeline->getCount();  
3272 - openObject(lindict_id);  
3273 - writeString("<<");  
3274 - if (pass == 2)  
3275 - {  
3276 - std::vector<QPDFObjectHandle> const& pages = 3257 + }
  3258 +
  3259 + // Part 1: header
  3260 +
  3261 + writeHeader();
  3262 +
  3263 + // Part 2: linearization parameter dictionary. Save enough
  3264 + // space to write real dictionary. 200 characters is enough
  3265 + // space if all numerical values in the parameter dictionary
  3266 + // that contain offsets are 20 digits long plus a few extra
  3267 + // characters for safety. The entire linearization parameter
  3268 + // dictionary must appear within the first 1024 characters of
  3269 + // the file.
  3270 +
  3271 + qpdf_offset_t pos = this->m->pipeline->getCount();
  3272 + openObject(lindict_id);
  3273 + writeString("<<");
  3274 + if (pass == 2)
  3275 + {
  3276 + std::vector<QPDFObjectHandle> const& pages =
3277 this->m->pdf.getAllPages(); 3277 this->m->pdf.getAllPages();
3278 - int first_page_object = 3278 + int first_page_object =
3279 this->m->obj_renumber[pages.at(0).getObjGen()]; 3279 this->m->obj_renumber[pages.at(0).getObjGen()];
3280 - int npages = QIntC::to_int(pages.size());  
3281 -  
3282 - writeString(" /Linearized 1 /L ");  
3283 - writeString(QUtil::int_to_string(file_size + hint_length));  
3284 - // Implementation note 121 states that a space is  
3285 - // mandatory after this open bracket.  
3286 - writeString(" /H [ ");  
3287 - writeString(QUtil::int_to_string( 3280 + int npages = QIntC::to_int(pages.size());
  3281 +
  3282 + writeString(" /Linearized 1 /L ");
  3283 + writeString(QUtil::int_to_string(file_size + hint_length));
  3284 + // Implementation note 121 states that a space is
  3285 + // mandatory after this open bracket.
  3286 + writeString(" /H [ ");
  3287 + writeString(QUtil::int_to_string(
3288 this->m->xref[hint_id].getOffset())); 3288 this->m->xref[hint_id].getOffset()));
3289 - writeString(" ");  
3290 - writeString(QUtil::int_to_string(hint_length));  
3291 - writeString(" ] /O ");  
3292 - writeString(QUtil::int_to_string(first_page_object));  
3293 - writeString(" /E ");  
3294 - writeString(QUtil::int_to_string(part6_end_offset + hint_length));  
3295 - writeString(" /N ");  
3296 - writeString(QUtil::int_to_string(npages));  
3297 - writeString(" /T ");  
3298 - writeString(QUtil::int_to_string(space_before_zero + hint_length));  
3299 - }  
3300 - writeString(" >>");  
3301 - closeObject(lindict_id);  
3302 - static int const pad = 200;  
3303 - int spaces = QIntC::to_int(pos - this->m->pipeline->getCount() + pad);  
3304 - assert(spaces >= 0);  
3305 - writePad(spaces);  
3306 - writeString("\n"); 3289 + writeString(" ");
  3290 + writeString(QUtil::int_to_string(hint_length));
  3291 + writeString(" ] /O ");
  3292 + writeString(QUtil::int_to_string(first_page_object));
  3293 + writeString(" /E ");
  3294 + writeString(QUtil::int_to_string(part6_end_offset + hint_length));
  3295 + writeString(" /N ");
  3296 + writeString(QUtil::int_to_string(npages));
  3297 + writeString(" /T ");
  3298 + writeString(QUtil::int_to_string(space_before_zero + hint_length));
  3299 + }
  3300 + writeString(" >>");
  3301 + closeObject(lindict_id);
  3302 + static int const pad = 200;
  3303 + int spaces = QIntC::to_int(pos - this->m->pipeline->getCount() + pad);
  3304 + assert(spaces >= 0);
  3305 + writePad(spaces);
  3306 + writeString("\n");
3307 3307
3308 // If the user supplied any additional header text, write it 3308 // If the user supplied any additional header text, write it
3309 // here after the linearization parameter dictionary. 3309 // here after the linearization parameter dictionary.
3310 writeString(this->m->extra_header_text); 3310 writeString(this->m->extra_header_text);
3311 3311
3312 - // Part 3: first page cross reference table and trailer.  
3313 -  
3314 - qpdf_offset_t first_xref_offset = this->m->pipeline->getCount();  
3315 - qpdf_offset_t hint_offset = 0;  
3316 - if (pass == 2)  
3317 - {  
3318 - hint_offset = this->m->xref[hint_id].getOffset();  
3319 - }  
3320 - if (need_xref_stream)  
3321 - {  
3322 - // Must pad here too.  
3323 - if (pass == 1)  
3324 - {  
3325 - // Set first_half_max_obj_offset to a value large  
3326 - // enough to force four bytes to be reserved for each  
3327 - // file offset. This would provide adequate space for  
3328 - // the xref stream as long as the last object in page  
3329 - // 1 starts with in the first 4 GB of the file, which  
3330 - // is extremely likely. In the second pass, we will  
3331 - // know the actual value for this, but it's okay if  
3332 - // it's smaller.  
3333 - first_half_max_obj_offset = 1 << 25;  
3334 - }  
3335 - pos = this->m->pipeline->getCount();  
3336 - writeXRefStream(first_half_xref, first_half_end,  
3337 - first_half_max_obj_offset,  
3338 - t_lin_first, first_half_start, first_half_end,  
3339 - first_trailer_size,  
3340 - hint_length + second_xref_offset,  
3341 - hint_id, hint_offset, hint_length,  
3342 - (pass == 1), pass);  
3343 - qpdf_offset_t endpos = this->m->pipeline->getCount();  
3344 - if (pass == 1)  
3345 - {  
3346 - // Pad so we have enough room for the real xref  
3347 - // stream.  
3348 - writePad(calculateXrefStreamPadding(endpos - pos));  
3349 - first_xref_end = this->m->pipeline->getCount();  
3350 - }  
3351 - else  
3352 - {  
3353 - // Pad so that the next object starts at the same  
3354 - // place as in pass 1.  
3355 - writePad(QIntC::to_int(first_xref_end - endpos));  
3356 -  
3357 - if (this->m->pipeline->getCount() != first_xref_end) 3312 + // Part 3: first page cross reference table and trailer.
  3313 +
  3314 + qpdf_offset_t first_xref_offset = this->m->pipeline->getCount();
  3315 + qpdf_offset_t hint_offset = 0;
  3316 + if (pass == 2)
  3317 + {
  3318 + hint_offset = this->m->xref[hint_id].getOffset();
  3319 + }
  3320 + if (need_xref_stream)
  3321 + {
  3322 + // Must pad here too.
  3323 + if (pass == 1)
  3324 + {
  3325 + // Set first_half_max_obj_offset to a value large
  3326 + // enough to force four bytes to be reserved for each
  3327 + // file offset. This would provide adequate space for
  3328 + // the xref stream as long as the last object in page
  3329 + // 1 starts with in the first 4 GB of the file, which
  3330 + // is extremely likely. In the second pass, we will
  3331 + // know the actual value for this, but it's okay if
  3332 + // it's smaller.
  3333 + first_half_max_obj_offset = 1 << 25;
  3334 + }
  3335 + pos = this->m->pipeline->getCount();
  3336 + writeXRefStream(first_half_xref, first_half_end,
  3337 + first_half_max_obj_offset,
  3338 + t_lin_first, first_half_start, first_half_end,
  3339 + first_trailer_size,
  3340 + hint_length + second_xref_offset,
  3341 + hint_id, hint_offset, hint_length,
  3342 + (pass == 1), pass);
  3343 + qpdf_offset_t endpos = this->m->pipeline->getCount();
  3344 + if (pass == 1)
  3345 + {
  3346 + // Pad so we have enough room for the real xref
  3347 + // stream.
  3348 + writePad(calculateXrefStreamPadding(endpos - pos));
  3349 + first_xref_end = this->m->pipeline->getCount();
  3350 + }
  3351 + else
  3352 + {
  3353 + // Pad so that the next object starts at the same
  3354 + // place as in pass 1.
  3355 + writePad(QIntC::to_int(first_xref_end - endpos));
  3356 +
  3357 + if (this->m->pipeline->getCount() != first_xref_end)
3358 { 3358 {
3359 throw std::logic_error( 3359 throw std::logic_error(
3360 "insufficient padding for first pass xref stream; " 3360 "insufficient padding for first pass xref stream; "
@@ -3362,111 +3362,111 @@ QPDFWriter::writeLinearized() @@ -3362,111 +3362,111 @@ QPDFWriter::writeLinearized()
3362 QUtil::int_to_string(first_xref_end) + 3362 QUtil::int_to_string(first_xref_end) +
3363 "; endpos=" + QUtil::int_to_string(endpos)); 3363 "; endpos=" + QUtil::int_to_string(endpos));
3364 } 3364 }
3365 - }  
3366 - writeString("\n");  
3367 - }  
3368 - else  
3369 - {  
3370 - writeXRefTable(t_lin_first, first_half_start, first_half_end,  
3371 - first_trailer_size, hint_length + second_xref_offset,  
3372 - (pass == 1), hint_id, hint_offset, hint_length, 3365 + }
  3366 + writeString("\n");
  3367 + }
  3368 + else
  3369 + {
  3370 + writeXRefTable(t_lin_first, first_half_start, first_half_end,
  3371 + first_trailer_size, hint_length + second_xref_offset,
  3372 + (pass == 1), hint_id, hint_offset, hint_length,
3373 pass); 3373 pass);
3374 - writeString("startxref\n0\n%%EOF\n");  
3375 - }  
3376 -  
3377 - // Parts 4 through 9  
3378 -  
3379 - for (std::list<QPDFObjectHandle>::iterator iter =  
3380 - this->m->object_queue.begin();  
3381 - iter != this->m->object_queue.end(); ++iter)  
3382 - {  
3383 - QPDFObjectHandle cur_object = (*iter);  
3384 - if (cur_object.getObjectID() == part6_end_marker)  
3385 - {  
3386 - first_half_max_obj_offset = this->m->pipeline->getCount();  
3387 - }  
3388 - writeObject(cur_object);  
3389 - if (cur_object.getObjectID() == part4_end_marker)  
3390 - {  
3391 - if (this->m->encrypted)  
3392 - {  
3393 - writeEncryptionDictionary();  
3394 - }  
3395 - if (pass == 1)  
3396 - {  
3397 - this->m->xref[hint_id] =  
3398 - QPDFXRefEntry(1, this->m->pipeline->getCount(), 0);  
3399 - }  
3400 - else  
3401 - {  
3402 - // Part 5: hint stream  
3403 - writeBuffer(hint_buffer);  
3404 - }  
3405 - }  
3406 - if (cur_object.getObjectID() == part6_end_marker)  
3407 - {  
3408 - part6_end_offset = this->m->pipeline->getCount();  
3409 - }  
3410 - }  
3411 -  
3412 - // Part 10: overflow hint stream -- not used  
3413 -  
3414 - // Part 11: main cross reference table and trailer  
3415 -  
3416 - second_xref_offset = this->m->pipeline->getCount();  
3417 - if (need_xref_stream)  
3418 - {  
3419 - pos = this->m->pipeline->getCount();  
3420 - space_before_zero =  
3421 - writeXRefStream(second_half_xref,  
3422 - second_half_end, second_xref_offset,  
3423 - t_lin_second, 0, second_half_end,  
3424 - second_trailer_size,  
3425 - 0, 0, 0, 0, (pass == 1), pass);  
3426 - qpdf_offset_t endpos = this->m->pipeline->getCount();  
3427 -  
3428 - if (pass == 1)  
3429 - {  
3430 - // Pad so we have enough room for the real xref  
3431 - // stream. See comments for previous xref stream on  
3432 - // how we calculate the padding.  
3433 - writePad(calculateXrefStreamPadding(endpos - pos));  
3434 - writeString("\n");  
3435 - second_xref_end = this->m->pipeline->getCount();  
3436 - }  
3437 - else  
3438 - {  
3439 - // Make the file size the same.  
3440 - writePad( 3374 + writeString("startxref\n0\n%%EOF\n");
  3375 + }
  3376 +
  3377 + // Parts 4 through 9
  3378 +
  3379 + for (std::list<QPDFObjectHandle>::iterator iter =
  3380 + this->m->object_queue.begin();
  3381 + iter != this->m->object_queue.end(); ++iter)
  3382 + {
  3383 + QPDFObjectHandle cur_object = (*iter);
  3384 + if (cur_object.getObjectID() == part6_end_marker)
  3385 + {
  3386 + first_half_max_obj_offset = this->m->pipeline->getCount();
  3387 + }
  3388 + writeObject(cur_object);
  3389 + if (cur_object.getObjectID() == part4_end_marker)
  3390 + {
  3391 + if (this->m->encrypted)
  3392 + {
  3393 + writeEncryptionDictionary();
  3394 + }
  3395 + if (pass == 1)
  3396 + {
  3397 + this->m->xref[hint_id] =
  3398 + QPDFXRefEntry(1, this->m->pipeline->getCount(), 0);
  3399 + }
  3400 + else
  3401 + {
  3402 + // Part 5: hint stream
  3403 + writeBuffer(hint_buffer);
  3404 + }
  3405 + }
  3406 + if (cur_object.getObjectID() == part6_end_marker)
  3407 + {
  3408 + part6_end_offset = this->m->pipeline->getCount();
  3409 + }
  3410 + }
  3411 +
  3412 + // Part 10: overflow hint stream -- not used
  3413 +
  3414 + // Part 11: main cross reference table and trailer
  3415 +
  3416 + second_xref_offset = this->m->pipeline->getCount();
  3417 + if (need_xref_stream)
  3418 + {
  3419 + pos = this->m->pipeline->getCount();
  3420 + space_before_zero =
  3421 + writeXRefStream(second_half_xref,
  3422 + second_half_end, second_xref_offset,
  3423 + t_lin_second, 0, second_half_end,
  3424 + second_trailer_size,
  3425 + 0, 0, 0, 0, (pass == 1), pass);
  3426 + qpdf_offset_t endpos = this->m->pipeline->getCount();
  3427 +
  3428 + if (pass == 1)
  3429 + {
  3430 + // Pad so we have enough room for the real xref
  3431 + // stream. See comments for previous xref stream on
  3432 + // how we calculate the padding.
  3433 + writePad(calculateXrefStreamPadding(endpos - pos));
  3434 + writeString("\n");
  3435 + second_xref_end = this->m->pipeline->getCount();
  3436 + }
  3437 + else
  3438 + {
  3439 + // Make the file size the same.
  3440 + writePad(
3441 QIntC::to_int(second_xref_end + hint_length - 3441 QIntC::to_int(second_xref_end + hint_length -
3442 1 - this->m->pipeline->getCount())); 3442 1 - this->m->pipeline->getCount()));
3443 - writeString("\n"); 3443 + writeString("\n");
3444 3444
3445 - // If this assertion fails, maybe we didn't have  
3446 - // enough padding above.  
3447 - if (this->m->pipeline->getCount() != 3445 + // If this assertion fails, maybe we didn't have
  3446 + // enough padding above.
  3447 + if (this->m->pipeline->getCount() !=
3448 second_xref_end + hint_length) 3448 second_xref_end + hint_length)
3449 { 3449 {
3450 throw std::logic_error( 3450 throw std::logic_error(
3451 "count mismatch after xref stream;" 3451 "count mismatch after xref stream;"
3452 " possible insufficient padding?"); 3452 " possible insufficient padding?");
3453 } 3453 }
3454 - }  
3455 - }  
3456 - else  
3457 - {  
3458 - space_before_zero =  
3459 - writeXRefTable(t_lin_second, 0, second_half_end,  
3460 - second_trailer_size, 0, false, 0, 0, 0, pass);  
3461 - }  
3462 - writeString("startxref\n");  
3463 - writeString(QUtil::int_to_string(first_xref_offset));  
3464 - writeString("\n%%EOF\n"); 3454 + }
  3455 + }
  3456 + else
  3457 + {
  3458 + space_before_zero =
  3459 + writeXRefTable(t_lin_second, 0, second_half_end,
  3460 + second_trailer_size, 0, false, 0, 0, 0, pass);
  3461 + }
  3462 + writeString("startxref\n");
  3463 + writeString(QUtil::int_to_string(first_xref_offset));
  3464 + writeString("\n%%EOF\n");
3465 3465
3466 discardGeneration(this->m->obj_renumber, this->m->obj_renumber_no_gen); 3466 discardGeneration(this->m->obj_renumber, this->m->obj_renumber_no_gen);
3467 3467
3468 - if (pass == 1)  
3469 - { 3468 + if (pass == 1)
  3469 + {
3470 if (this->m->deterministic_id) 3470 if (this->m->deterministic_id)
3471 { 3471 {
3472 QTC::TC("qpdf", "QPDFWriter linearized deterministic ID", 3472 QTC::TC("qpdf", "QPDFWriter linearized deterministic ID",
@@ -3476,25 +3476,25 @@ QPDFWriter::writeLinearized() @@ -3476,25 +3476,25 @@ QPDFWriter::writeLinearized()
3476 assert(this->m->md5_pipeline == 0); 3476 assert(this->m->md5_pipeline == 0);
3477 } 3477 }
3478 3478
3479 - // Close first pass pipeline  
3480 - file_size = this->m->pipeline->getCount();  
3481 - pp_pass1 = 0; 3479 + // Close first pass pipeline
  3480 + file_size = this->m->pipeline->getCount();
  3481 + pp_pass1 = 0;
3482 3482
3483 - // Save hint offset since it will be set to zero by  
3484 - // calling openObject.  
3485 - qpdf_offset_t hint_offset1 = this->m->xref[hint_id].getOffset(); 3483 + // Save hint offset since it will be set to zero by
  3484 + // calling openObject.
  3485 + qpdf_offset_t hint_offset1 = this->m->xref[hint_id].getOffset();
3486 3486
3487 - // Write hint stream to a buffer 3487 + // Write hint stream to a buffer
3488 { 3488 {
3489 pushPipeline(new Pl_Buffer("hint buffer")); 3489 pushPipeline(new Pl_Buffer("hint buffer"));
3490 PipelinePopper pp_hint(this, &hint_buffer); 3490 PipelinePopper pp_hint(this, &hint_buffer);
3491 activatePipelineStack(pp_hint); 3491 activatePipelineStack(pp_hint);
3492 writeHintStream(hint_id); 3492 writeHintStream(hint_id);
3493 } 3493 }
3494 - hint_length = QIntC::to_offset(hint_buffer->getSize()); 3494 + hint_length = QIntC::to_offset(hint_buffer->getSize());
3495 3495
3496 - // Restore hint offset  
3497 - this->m->xref[hint_id] = QPDFXRefEntry(1, hint_offset1, 0); 3496 + // Restore hint offset
  3497 + this->m->xref[hint_id] = QPDFXRefEntry(1, hint_offset1, 0);
3498 if (lin_pass1_file) 3498 if (lin_pass1_file)
3499 { 3499 {
3500 // Write some debugging information 3500 // Write some debugging information
@@ -3509,7 +3509,7 @@ QPDFWriter::writeLinearized() @@ -3509,7 +3509,7 @@ QPDFWriter::writeLinearized()
3509 fclose(lin_pass1_file); 3509 fclose(lin_pass1_file);
3510 lin_pass1_file = 0; 3510 lin_pass1_file = 0;
3511 } 3511 }
3512 - } 3512 + }
3513 } 3513 }
3514 } 3514 }
3515 3515
@@ -3537,9 +3537,9 @@ QPDFWriter::enqueueObjectsStandard() @@ -3537,9 +3537,9 @@ QPDFWriter::enqueueObjectsStandard()
3537 // no-op. 3537 // no-op.
3538 std::set<std::string> keys = trailer.getKeys(); 3538 std::set<std::string> keys = trailer.getKeys();
3539 for (std::set<std::string>::iterator iter = keys.begin(); 3539 for (std::set<std::string>::iterator iter = keys.begin();
3540 - iter != keys.end(); ++iter) 3540 + iter != keys.end(); ++iter)
3541 { 3541 {
3542 - enqueueObject(trailer.getKey(*iter)); 3542 + enqueueObject(trailer.getKey(*iter));
3543 } 3543 }
3544 } 3544 }
3545 3545
@@ -3646,31 +3646,31 @@ QPDFWriter::writeStandard() @@ -3646,31 +3646,31 @@ QPDFWriter::writeStandard()
3646 // Now start walking queue, outputting each object. 3646 // Now start walking queue, outputting each object.
3647 while (this->m->object_queue.size()) 3647 while (this->m->object_queue.size())
3648 { 3648 {
3649 - QPDFObjectHandle cur_object = this->m->object_queue.front();  
3650 - this->m->object_queue.pop_front();  
3651 - writeObject(cur_object); 3649 + QPDFObjectHandle cur_object = this->m->object_queue.front();
  3650 + this->m->object_queue.pop_front();
  3651 + writeObject(cur_object);
3652 } 3652 }
3653 3653
3654 // Write out the encryption dictionary, if any 3654 // Write out the encryption dictionary, if any
3655 if (this->m->encrypted) 3655 if (this->m->encrypted)
3656 { 3656 {
3657 - writeEncryptionDictionary(); 3657 + writeEncryptionDictionary();
3658 } 3658 }
3659 3659
3660 // Now write out xref. next_objid is now the number of objects. 3660 // Now write out xref. next_objid is now the number of objects.
3661 qpdf_offset_t xref_offset = this->m->pipeline->getCount(); 3661 qpdf_offset_t xref_offset = this->m->pipeline->getCount();
3662 if (this->m->object_stream_to_objects.empty()) 3662 if (this->m->object_stream_to_objects.empty())
3663 { 3663 {
3664 - // Write regular cross-reference table  
3665 - writeXRefTable(t_normal, 0, this->m->next_objid - 1, 3664 + // Write regular cross-reference table
  3665 + writeXRefTable(t_normal, 0, this->m->next_objid - 1,
3666 this->m->next_objid); 3666 this->m->next_objid);
3667 } 3667 }
3668 else 3668 else
3669 { 3669 {
3670 - // Write cross-reference stream.  
3671 - int xref_id = this->m->next_objid++;  
3672 - writeXRefStream(xref_id, xref_id, xref_offset, t_normal,  
3673 - 0, this->m->next_objid - 1, this->m->next_objid); 3670 + // Write cross-reference stream.
  3671 + int xref_id = this->m->next_objid++;
  3672 + writeXRefStream(xref_id, xref_id, xref_offset, t_normal,
  3673 + 0, this->m->next_objid - 1, this->m->next_objid);
3674 } 3674 }
3675 writeString("startxref\n"); 3675 writeString("startxref\n");
3676 writeString(QUtil::int_to_string(xref_offset)); 3676 writeString(QUtil::int_to_string(xref_offset));
@@ -3678,7 +3678,7 @@ QPDFWriter::writeStandard() @@ -3678,7 +3678,7 @@ QPDFWriter::writeStandard()
3678 3678
3679 if (this->m->deterministic_id) 3679 if (this->m->deterministic_id)
3680 { 3680 {
3681 - QTC::TC("qpdf", "QPDFWriter standard deterministic ID", 3681 + QTC::TC("qpdf", "QPDFWriter standard deterministic ID",
3682 this->m->object_stream_to_objects.empty() ? 0 : 1); 3682 this->m->object_stream_to_objects.empty() ? 0 : 1);
3683 pp_md5 = 0; 3683 pp_md5 = 0;
3684 assert(this->m->md5_pipeline == 0); 3684 assert(this->m->md5_pipeline == 0);
libqpdf/QPDFXRefEntry.cc
@@ -18,8 +18,8 @@ QPDFXRefEntry::QPDFXRefEntry(int type, qpdf_offset_t field1, int field2) : @@ -18,8 +18,8 @@ QPDFXRefEntry::QPDFXRefEntry(int type, qpdf_offset_t field1, int field2) :
18 { 18 {
19 if ((type < 1) || (type > 2)) 19 if ((type < 1) || (type > 2))
20 { 20 {
21 - throw std::logic_error(  
22 - "invalid xref type " + QUtil::int_to_string(type)); 21 + throw std::logic_error(
  22 + "invalid xref type " + QUtil::int_to_string(type));
23 } 23 }
24 } 24 }
25 25
@@ -34,8 +34,8 @@ QPDFXRefEntry::getOffset() const @@ -34,8 +34,8 @@ QPDFXRefEntry::getOffset() const
34 { 34 {
35 if (this->type != 1) 35 if (this->type != 1)
36 { 36 {
37 - throw std::logic_error(  
38 - "getOffset called for xref entry of type != 1"); 37 + throw std::logic_error(
  38 + "getOffset called for xref entry of type != 1");
39 } 39 }
40 return this->field1; 40 return this->field1;
41 } 41 }
@@ -45,8 +45,8 @@ QPDFXRefEntry::getObjStreamNumber() const @@ -45,8 +45,8 @@ QPDFXRefEntry::getObjStreamNumber() const
45 { 45 {
46 if (this->type != 2) 46 if (this->type != 2)
47 { 47 {
48 - throw std::logic_error(  
49 - "getObjStreamNumber called for xref entry of type != 2"); 48 + throw std::logic_error(
  49 + "getObjStreamNumber called for xref entry of type != 2");
50 } 50 }
51 return QIntC::to_int(this->field1); 51 return QIntC::to_int(this->field1);
52 } 52 }
@@ -56,8 +56,8 @@ QPDFXRefEntry::getObjStreamIndex() const @@ -56,8 +56,8 @@ QPDFXRefEntry::getObjStreamIndex() const
56 { 56 {
57 if (this->type != 2) 57 if (this->type != 2)
58 { 58 {
59 - throw std::logic_error(  
60 - "getObjStreamIndex called for xref entry of type != 2"); 59 + throw std::logic_error(
  60 + "getObjStreamIndex called for xref entry of type != 2");
61 } 61 }
62 return this->field2; 62 return this->field2;
63 } 63 }
libqpdf/QPDF_Array.cc
@@ -31,8 +31,8 @@ QPDF_Array::unparse() @@ -31,8 +31,8 @@ QPDF_Array::unparse()
31 size_t size = this->elements.size(); 31 size_t size = this->elements.size();
32 for (size_t i = 0; i < size; ++i) 32 for (size_t i = 0; i < size; ++i)
33 { 33 {
34 - result += this->elements.at(i).unparse();  
35 - result += " "; 34 + result += this->elements.at(i).unparse();
  35 + result += " ";
36 } 36 }
37 result += "]"; 37 result += "]";
38 return result; 38 return result;
@@ -81,8 +81,8 @@ QPDF_Array::getItem(int n) const @@ -81,8 +81,8 @@ QPDF_Array::getItem(int n) const
81 { 81 {
82 if ((n < 0) || (n >= QIntC::to_int(elements.size()))) 82 if ((n < 0) || (n >= QIntC::to_int(elements.size())))
83 { 83 {
84 - throw std::logic_error(  
85 - "INTERNAL ERROR: bounds error accessing QPDF_Array element"); 84 + throw std::logic_error(
  85 + "INTERNAL ERROR: bounds error accessing QPDF_Array element");
86 } 86 }
87 return this->elements.at(QIntC::to_size(n)); 87 return this->elements.at(QIntC::to_size(n));
88 } 88 }
@@ -120,8 +120,8 @@ QPDF_Array::insertItem(int at, QPDFObjectHandle const&amp; item) @@ -120,8 +120,8 @@ QPDF_Array::insertItem(int at, QPDFObjectHandle const&amp; item)
120 // As special case, also allow insert beyond the end 120 // As special case, also allow insert beyond the end
121 if ((at < 0) || (at > QIntC::to_int(this->elements.size()))) 121 if ((at < 0) || (at > QIntC::to_int(this->elements.size())))
122 { 122 {
123 - throw std::logic_error(  
124 - "INTERNAL ERROR: bounds error accessing QPDF_Array element"); 123 + throw std::logic_error(
  124 + "INTERNAL ERROR: bounds error accessing QPDF_Array element");
125 } 125 }
126 this->elements.insert(QIntC::to_size(at), item); 126 this->elements.insert(QIntC::to_size(at), item);
127 } 127 }
libqpdf/QPDF_Dictionary.cc
@@ -17,10 +17,10 @@ void @@ -17,10 +17,10 @@ void
17 QPDF_Dictionary::releaseResolved() 17 QPDF_Dictionary::releaseResolved()
18 { 18 {
19 for (std::map<std::string, QPDFObjectHandle>::iterator iter = 19 for (std::map<std::string, QPDFObjectHandle>::iterator iter =
20 - this->items.begin();  
21 - iter != this->items.end(); ++iter) 20 + this->items.begin();
  21 + iter != this->items.end(); ++iter)
22 { 22 {
23 - QPDFObjectHandle::ReleaseResolver::releaseResolved((*iter).second); 23 + QPDFObjectHandle::ReleaseResolver::releaseResolved((*iter).second);
24 } 24 }
25 } 25 }
26 26
@@ -29,11 +29,11 @@ QPDF_Dictionary::unparse() @@ -29,11 +29,11 @@ QPDF_Dictionary::unparse()
29 { 29 {
30 std::string result = "<< "; 30 std::string result = "<< ";
31 for (std::map<std::string, QPDFObjectHandle>::iterator iter = 31 for (std::map<std::string, QPDFObjectHandle>::iterator iter =
32 - this->items.begin();  
33 - iter != this->items.end(); ++iter) 32 + this->items.begin();
  33 + iter != this->items.end(); ++iter)
34 { 34 {
35 - result += QPDF_Name::normalizeName((*iter).first) +  
36 - " " + (*iter).second.unparse() + " "; 35 + result += QPDF_Name::normalizeName((*iter).first) +
  36 + " " + (*iter).second.unparse() + " ";
37 } 37 }
38 result += ">>"; 38 result += ">>";
39 return result; 39 return result;
@@ -44,8 +44,8 @@ QPDF_Dictionary::getJSON() @@ -44,8 +44,8 @@ QPDF_Dictionary::getJSON()
44 { 44 {
45 JSON j = JSON::makeDictionary(); 45 JSON j = JSON::makeDictionary();
46 for (std::map<std::string, QPDFObjectHandle>::iterator iter = 46 for (std::map<std::string, QPDFObjectHandle>::iterator iter =
47 - this->items.begin();  
48 - iter != this->items.end(); ++iter) 47 + this->items.begin();
  48 + iter != this->items.end(); ++iter)
49 { 49 {
50 j.addDictionaryMember(QPDF_Name::normalizeName((*iter).first), 50 j.addDictionaryMember(QPDF_Name::normalizeName((*iter).first),
51 (*iter).second.getJSON()); 51 (*iter).second.getJSON());
@@ -75,7 +75,7 @@ bool @@ -75,7 +75,7 @@ bool
75 QPDF_Dictionary::hasKey(std::string const& key) 75 QPDF_Dictionary::hasKey(std::string const& key)
76 { 76 {
77 return ((this->items.count(key) > 0) && 77 return ((this->items.count(key) > 0) &&
78 - (! this->items[key].isNull())); 78 + (! this->items[key].isNull()));
79 } 79 }
80 80
81 QPDFObjectHandle 81 QPDFObjectHandle
@@ -85,8 +85,8 @@ QPDF_Dictionary::getKey(std::string const&amp; key) @@ -85,8 +85,8 @@ QPDF_Dictionary::getKey(std::string const&amp; key)
85 // returns the null object. 85 // returns the null object.
86 if (this->items.count(key)) 86 if (this->items.count(key))
87 { 87 {
88 - // May be a null object  
89 - return (*(this->items.find(key))).second; 88 + // May be a null object
  89 + return (*(this->items.find(key))).second;
90 } 90 }
91 else 91 else
92 { 92 {
@@ -98,7 +98,7 @@ QPDF_Dictionary::getKey(std::string const&amp; key) @@ -98,7 +98,7 @@ QPDF_Dictionary::getKey(std::string const&amp; key)
98 null.setObjectDescription( 98 null.setObjectDescription(
99 qpdf, description + " -> dictionary key " + key); 99 qpdf, description + " -> dictionary key " + key);
100 } 100 }
101 - return null; 101 + return null;
102 } 102 }
103 } 103 }
104 104
@@ -107,13 +107,13 @@ QPDF_Dictionary::getKeys() @@ -107,13 +107,13 @@ QPDF_Dictionary::getKeys()
107 { 107 {
108 std::set<std::string> result; 108 std::set<std::string> result;
109 for (std::map<std::string, QPDFObjectHandle>::const_iterator iter = 109 for (std::map<std::string, QPDFObjectHandle>::const_iterator iter =
110 - this->items.begin();  
111 - iter != this->items.end(); ++iter) 110 + this->items.begin();
  111 + iter != this->items.end(); ++iter)
112 { 112 {
113 - if (hasKey((*iter).first))  
114 - {  
115 - result.insert((*iter).first);  
116 - } 113 + if (hasKey((*iter).first))
  114 + {
  115 + result.insert((*iter).first);
  116 + }
117 } 117 }
118 return result; 118 return result;
119 } 119 }
@@ -126,7 +126,7 @@ QPDF_Dictionary::getAsMap() const @@ -126,7 +126,7 @@ QPDF_Dictionary::getAsMap() const
126 126
127 void 127 void
128 QPDF_Dictionary::replaceKey(std::string const& key, 128 QPDF_Dictionary::replaceKey(std::string const& key,
129 - QPDFObjectHandle value) 129 + QPDFObjectHandle value)
130 { 130 {
131 // add or replace value 131 // add or replace value
132 this->items[key] = value; 132 this->items[key] = value;
@@ -141,14 +141,14 @@ QPDF_Dictionary::removeKey(std::string const&amp; key) @@ -141,14 +141,14 @@ QPDF_Dictionary::removeKey(std::string const&amp; key)
141 141
142 void 142 void
143 QPDF_Dictionary::replaceOrRemoveKey(std::string const& key, 143 QPDF_Dictionary::replaceOrRemoveKey(std::string const& key,
144 - QPDFObjectHandle value) 144 + QPDFObjectHandle value)
145 { 145 {
146 if (value.isNull()) 146 if (value.isNull())
147 { 147 {
148 - removeKey(key); 148 + removeKey(key);
149 } 149 }
150 else 150 else
151 { 151 {
152 - replaceKey(key, value); 152 + replaceKey(key, value);
153 } 153 }
154 } 154 }
libqpdf/QPDF_Name.cc
@@ -18,28 +18,28 @@ QPDF_Name::normalizeName(std::string const&amp; name) @@ -18,28 +18,28 @@ QPDF_Name::normalizeName(std::string const&amp; name)
18 { 18 {
19 if (name.empty()) 19 if (name.empty())
20 { 20 {
21 - return name; 21 + return name;
22 } 22 }
23 std::string result; 23 std::string result;
24 result += name.at(0); 24 result += name.at(0);
25 for (size_t i = 1; i < name.length(); ++i) 25 for (size_t i = 1; i < name.length(); ++i)
26 { 26 {
27 - char ch = name.at(i);  
28 - // Don't use locale/ctype here; follow PDF spec guidelines. 27 + char ch = name.at(i);
  28 + // Don't use locale/ctype here; follow PDF spec guidelines.
29 if (ch == '\0') 29 if (ch == '\0')
30 { 30 {
31 // QPDFTokenizer embeds a null character to encode an 31 // QPDFTokenizer embeds a null character to encode an
32 // invalid #. 32 // invalid #.
33 result += "#"; 33 result += "#";
34 } 34 }
35 - else if (strchr("#()<>[]{}/%", ch) || (ch < 33) || (ch > 126))  
36 - { 35 + else if (strchr("#()<>[]{}/%", ch) || (ch < 33) || (ch > 126))
  36 + {
37 result += "#" + QUtil::hex_encode(std::string(&ch, 1)); 37 result += "#" + QUtil::hex_encode(std::string(&ch, 1));
38 - }  
39 - else  
40 - {  
41 - result += ch;  
42 - } 38 + }
  39 + else
  40 + {
  41 + result += ch;
  42 + }
43 } 43 }
44 return result; 44 return result;
45 } 45 }
libqpdf/QPDF_Stream.cc
@@ -83,8 +83,8 @@ QPDF_Stream::filter_factories = { @@ -83,8 +83,8 @@ QPDF_Stream::filter_factories = {
83 }; 83 };
84 84
85 QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation, 85 QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation,
86 - QPDFObjectHandle stream_dict,  
87 - qpdf_offset_t offset, size_t length) : 86 + QPDFObjectHandle stream_dict,
  87 + qpdf_offset_t offset, size_t length) :
88 qpdf(qpdf), 88 qpdf(qpdf),
89 objid(objid), 89 objid(objid),
90 generation(generation), 90 generation(generation),
@@ -95,9 +95,9 @@ QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation, @@ -95,9 +95,9 @@ QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation,
95 { 95 {
96 if (! stream_dict.isDictionary()) 96 if (! stream_dict.isDictionary())
97 { 97 {
98 - throw std::logic_error(  
99 - "stream object instantiated with non-dictionary "  
100 - "object for dictionary"); 98 + throw std::logic_error(
  99 + "stream object instantiated with non-dictionary "
  100 + "object for dictionary");
101 } 101 }
102 setStreamDescription(); 102 setStreamDescription();
103 } 103 }
@@ -138,9 +138,9 @@ QPDF_Stream::setObjGen(int objid, int generation) @@ -138,9 +138,9 @@ QPDF_Stream::setObjGen(int objid, int generation)
138 { 138 {
139 if (! ((this->objid == 0) && (this->generation == 0))) 139 if (! ((this->objid == 0) && (this->generation == 0)))
140 { 140 {
141 - throw std::logic_error(  
142 - "attempt to set object ID and generation of a stream"  
143 - " that already has them"); 141 + throw std::logic_error(
  142 + "attempt to set object ID and generation of a stream"
  143 + " that already has them");
144 } 144 }
145 this->objid = objid; 145 this->objid = objid;
146 this->generation = generation; 146 this->generation = generation;
@@ -151,7 +151,7 @@ QPDF_Stream::unparse() @@ -151,7 +151,7 @@ QPDF_Stream::unparse()
151 { 151 {
152 // Unparse stream objects as indirect references 152 // Unparse stream objects as indirect references
153 return QUtil::int_to_string(this->objid) + " " + 153 return QUtil::int_to_string(this->objid) + " " +
154 - QUtil::int_to_string(this->generation) + " R"; 154 + QUtil::int_to_string(this->generation) + " R";
155 } 155 }
156 156
157 JSON 157 JSON
@@ -246,7 +246,7 @@ QPDF_Stream::getStreamData(qpdf_stream_decode_level_e decode_level) @@ -246,7 +246,7 @@ QPDF_Stream::getStreamData(qpdf_stream_decode_level_e decode_level)
246 pipeStreamData(&buf, &filtered, 0, decode_level, false, false); 246 pipeStreamData(&buf, &filtered, 0, decode_level, false, false);
247 if (! filtered) 247 if (! filtered)
248 { 248 {
249 - throw QPDFExc(qpdf_e_unsupported, qpdf->getFilename(), 249 + throw QPDFExc(qpdf_e_unsupported, qpdf->getFilename(),
250 "", this->offset, 250 "", this->offset,
251 "getStreamData called on unfilterable stream"); 251 "getStreamData called on unfilterable stream");
252 } 252 }
@@ -260,7 +260,7 @@ QPDF_Stream::getRawStreamData() @@ -260,7 +260,7 @@ QPDF_Stream::getRawStreamData()
260 Pl_Buffer buf("stream data buffer"); 260 Pl_Buffer buf("stream data buffer");
261 if (! pipeStreamData(&buf, nullptr, 0, qpdf_dl_none, false, false)) 261 if (! pipeStreamData(&buf, nullptr, 0, qpdf_dl_none, false, false))
262 { 262 {
263 - throw QPDFExc(qpdf_e_unsupported, qpdf->getFilename(), 263 + throw QPDFExc(qpdf_e_unsupported, qpdf->getFilename(),
264 "", this->offset, 264 "", this->offset,
265 "error getting raw stream data"); 265 "error getting raw stream data");
266 } 266 }
@@ -283,39 +283,39 @@ QPDF_Stream::filterable( @@ -283,39 +283,39 @@ QPDF_Stream::filterable(
283 283
284 if (filter_obj.isNull()) 284 if (filter_obj.isNull())
285 { 285 {
286 - // No filters 286 + // No filters
287 } 287 }
288 else if (filter_obj.isName()) 288 else if (filter_obj.isName())
289 { 289 {
290 - // One filter  
291 - filter_names.push_back(filter_obj.getName()); 290 + // One filter
  291 + filter_names.push_back(filter_obj.getName());
292 } 292 }
293 else if (filter_obj.isArray()) 293 else if (filter_obj.isArray())
294 { 294 {
295 - // Potentially multiple filters  
296 - int n = filter_obj.getArrayNItems();  
297 - for (int i = 0; i < n; ++i)  
298 - {  
299 - QPDFObjectHandle item = filter_obj.getArrayItem(i);  
300 - if (item.isName())  
301 - {  
302 - filter_names.push_back(item.getName());  
303 - }  
304 - else  
305 - {  
306 - filters_okay = false;  
307 - }  
308 - } 295 + // Potentially multiple filters
  296 + int n = filter_obj.getArrayNItems();
  297 + for (int i = 0; i < n; ++i)
  298 + {
  299 + QPDFObjectHandle item = filter_obj.getArrayItem(i);
  300 + if (item.isName())
  301 + {
  302 + filter_names.push_back(item.getName());
  303 + }
  304 + else
  305 + {
  306 + filters_okay = false;
  307 + }
  308 + }
309 } 309 }
310 else 310 else
311 { 311 {
312 - filters_okay = false; 312 + filters_okay = false;
313 } 313 }
314 314
315 if (! filters_okay) 315 if (! filters_okay)
316 { 316 {
317 - QTC::TC("qpdf", "QPDF_Stream invalid filter");  
318 - warn(QPDFExc(qpdf_e_damaged_pdf, qpdf->getFilename(), 317 + QTC::TC("qpdf", "QPDF_Stream invalid filter");
  318 + warn(QPDFExc(qpdf_e_damaged_pdf, qpdf->getFilename(),
319 "", this->offset, 319 "", this->offset,
320 "stream filter type is not name or array")); 320 "stream filter type is not name or array"));
321 return false; 321 return false;
@@ -325,11 +325,11 @@ QPDF_Stream::filterable( @@ -325,11 +325,11 @@ QPDF_Stream::filterable(
325 325
326 for (auto& filter_name: filter_names) 326 for (auto& filter_name: filter_names)
327 { 327 {
328 - if (filter_abbreviations.count(filter_name))  
329 - {  
330 - QTC::TC("qpdf", "QPDF_Stream expand filter abbreviation");  
331 - filter_name = filter_abbreviations[filter_name];  
332 - } 328 + if (filter_abbreviations.count(filter_name))
  329 + {
  330 + QTC::TC("qpdf", "QPDF_Stream expand filter abbreviation");
  331 + filter_name = filter_abbreviations[filter_name];
  332 + }
333 333
334 auto ff = filter_factories.find(filter_name); 334 auto ff = filter_factories.find(filter_name);
335 if (ff == filter_factories.end()) 335 if (ff == filter_factories.end())
@@ -435,7 +435,7 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp, @@ -435,7 +435,7 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp,
435 bool success = true; 435 bool success = true;
436 if (filter) 436 if (filter)
437 { 437 {
438 - filter = filterable( 438 + filter = filterable(
439 filters, specialized_compression, lossy_compression); 439 filters, specialized_compression, lossy_compression);
440 if ((decode_level < qpdf_dl_all) && lossy_compression) 440 if ((decode_level < qpdf_dl_all) && lossy_compression)
441 { 441 {
@@ -454,9 +454,9 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp, @@ -454,9 +454,9 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp,
454 454
455 if (pipeline == 0) 455 if (pipeline == 0)
456 { 456 {
457 - QTC::TC("qpdf", "QPDF_Stream pipeStreamData with null pipeline"); 457 + QTC::TC("qpdf", "QPDF_Stream pipeStreamData with null pipeline");
458 // Return value is whether we can filter in this case. 458 // Return value is whether we can filter in this case.
459 - return filter; 459 + return filter;
460 } 460 }
461 461
462 // Construct the pipeline in reverse order. Force pipelines we 462 // Construct the pipeline in reverse order. Force pipelines we
@@ -469,22 +469,22 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp, @@ -469,22 +469,22 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp,
469 std::shared_ptr<Pipeline> new_pipeline; 469 std::shared_ptr<Pipeline> new_pipeline;
470 if (filter) 470 if (filter)
471 { 471 {
472 - if (encode_flags & qpdf_ef_compress)  
473 - {  
474 - new_pipeline = std::make_shared<Pl_Flate>( 472 + if (encode_flags & qpdf_ef_compress)
  473 + {
  474 + new_pipeline = std::make_shared<Pl_Flate>(
475 "compress stream", pipeline, Pl_Flate::a_deflate); 475 "compress stream", pipeline, Pl_Flate::a_deflate);
476 - to_delete.push_back(new_pipeline); 476 + to_delete.push_back(new_pipeline);
477 pipeline = new_pipeline.get(); 477 pipeline = new_pipeline.get();
478 - } 478 + }
479 479
480 - if (encode_flags & qpdf_ef_normalize)  
481 - { 480 + if (encode_flags & qpdf_ef_normalize)
  481 + {
482 normalizer = make_pointer_holder<ContentNormalizer>(); 482 normalizer = make_pointer_holder<ContentNormalizer>();
483 - new_pipeline = std::make_shared<Pl_QPDFTokenizer>( 483 + new_pipeline = std::make_shared<Pl_QPDFTokenizer>(
484 "normalizer", normalizer.get(), pipeline); 484 "normalizer", normalizer.get(), pipeline);
485 - to_delete.push_back(new_pipeline); 485 + to_delete.push_back(new_pipeline);
486 pipeline = new_pipeline.get(); 486 pipeline = new_pipeline.get();
487 - } 487 + }
488 488
489 for (auto iter = this->token_filters.rbegin(); 489 for (auto iter = this->token_filters.rbegin();
490 iter != this->token_filters.rend(); ++iter) 490 iter != this->token_filters.rend(); ++iter)
@@ -495,9 +495,9 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp, @@ -495,9 +495,9 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp,
495 pipeline = new_pipeline.get(); 495 pipeline = new_pipeline.get();
496 } 496 }
497 497
498 - for (auto f_iter = filters.rbegin(); 498 + for (auto f_iter = filters.rbegin();
499 f_iter != filters.rend(); ++f_iter) 499 f_iter != filters.rend(); ++f_iter)
500 - { 500 + {
501 auto decode_pipeline = (*f_iter)->getDecodePipeline(pipeline); 501 auto decode_pipeline = (*f_iter)->getDecodePipeline(pipeline);
502 if (decode_pipeline) 502 if (decode_pipeline)
503 { 503 {
@@ -511,19 +511,19 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp, @@ -511,19 +511,19 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp,
511 "", this->offset, msg)); 511 "", this->offset, msg));
512 }); 512 });
513 } 513 }
514 - } 514 + }
515 } 515 }
516 516
517 if (this->stream_data.get()) 517 if (this->stream_data.get())
518 { 518 {
519 - QTC::TC("qpdf", "QPDF_Stream pipe replaced stream data");  
520 - pipeline->write(this->stream_data->getBuffer(),  
521 - this->stream_data->getSize());  
522 - pipeline->finish(); 519 + QTC::TC("qpdf", "QPDF_Stream pipe replaced stream data");
  520 + pipeline->write(this->stream_data->getBuffer(),
  521 + this->stream_data->getSize());
  522 + pipeline->finish();
523 } 523 }
524 else if (this->stream_provider.get()) 524 else if (this->stream_provider.get())
525 { 525 {
526 - Pl_Count count("stream provider count", pipeline); 526 + Pl_Count count("stream provider count", pipeline);
527 if (this->stream_provider->supportsRetry()) 527 if (this->stream_provider->supportsRetry())
528 { 528 {
529 if (! this->stream_provider->provideStreamData( 529 if (! this->stream_provider->provideStreamData(
@@ -539,11 +539,11 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp, @@ -539,11 +539,11 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp,
539 this->stream_provider->provideStreamData( 539 this->stream_provider->provideStreamData(
540 this->objid, this->generation, &count); 540 this->objid, this->generation, &count);
541 } 541 }
542 - qpdf_offset_t actual_length = count.getCount();  
543 - qpdf_offset_t desired_length = 0; 542 + qpdf_offset_t actual_length = count.getCount();
  543 + qpdf_offset_t desired_length = 0;
544 if (success && this->stream_dict.hasKey("/Length")) 544 if (success && this->stream_dict.hasKey("/Length"))
545 { 545 {
546 - desired_length = this->stream_dict.getKey("/Length").getIntValue(); 546 + desired_length = this->stream_dict.getKey("/Length").getIntValue();
547 if (actual_length == desired_length) 547 if (actual_length == desired_length)
548 { 548 {
549 QTC::TC("qpdf", "QPDF_Stream pipe use stream provider"); 549 QTC::TC("qpdf", "QPDF_Stream pipe use stream provider");
@@ -572,14 +572,14 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp, @@ -572,14 +572,14 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp,
572 } 572 }
573 else if (this->offset == 0) 573 else if (this->offset == 0)
574 { 574 {
575 - QTC::TC("qpdf", "QPDF_Stream pipe no stream data");  
576 - throw std::logic_error(  
577 - "pipeStreamData called for stream with no data"); 575 + QTC::TC("qpdf", "QPDF_Stream pipe no stream data");
  576 + throw std::logic_error(
  577 + "pipeStreamData called for stream with no data");
578 } 578 }
579 else 579 else
580 { 580 {
581 - QTC::TC("qpdf", "QPDF_Stream pipe original stream data");  
582 - if (! QPDF::Pipe::pipeStreamData(this->qpdf, this->objid, this->generation, 581 + QTC::TC("qpdf", "QPDF_Stream pipe original stream data");
  582 + if (! QPDF::Pipe::pipeStreamData(this->qpdf, this->objid, this->generation,
583 this->offset, this->length, 583 this->offset, this->length,
584 this->stream_dict, pipeline, 584 this->stream_dict, pipeline,
585 suppress_warnings, 585 suppress_warnings,
@@ -622,8 +622,8 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp, @@ -622,8 +622,8 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp,
622 622
623 void 623 void
624 QPDF_Stream::replaceStreamData(PointerHolder<Buffer> data, 624 QPDF_Stream::replaceStreamData(PointerHolder<Buffer> data,
625 - QPDFObjectHandle const& filter,  
626 - QPDFObjectHandle const& decode_parms) 625 + QPDFObjectHandle const& filter,
  626 + QPDFObjectHandle const& decode_parms)
627 { 627 {
628 this->stream_data = data; 628 this->stream_data = data;
629 this->stream_provider = 0; 629 this->stream_provider = 0;
@@ -650,8 +650,8 @@ QPDF_Stream::addTokenFilter( @@ -650,8 +650,8 @@ QPDF_Stream::addTokenFilter(
650 650
651 void 651 void
652 QPDF_Stream::replaceFilterData(QPDFObjectHandle const& filter, 652 QPDF_Stream::replaceFilterData(QPDFObjectHandle const& filter,
653 - QPDFObjectHandle const& decode_parms,  
654 - size_t length) 653 + QPDFObjectHandle const& decode_parms,
  654 + size_t length)
655 { 655 {
656 this->stream_dict.replaceOrRemoveKey("/Filter", filter); 656 this->stream_dict.replaceOrRemoveKey("/Filter", filter);
657 this->stream_dict.replaceOrRemoveKey("/DecodeParms", decode_parms); 657 this->stream_dict.replaceOrRemoveKey("/DecodeParms", decode_parms);
libqpdf/QPDF_String.cc
@@ -70,102 +70,102 @@ QPDF_String::unparse(bool force_binary) @@ -70,102 +70,102 @@ QPDF_String::unparse(bool force_binary)
70 bool use_hexstring = force_binary; 70 bool use_hexstring = force_binary;
71 if (! use_hexstring) 71 if (! use_hexstring)
72 { 72 {
73 - unsigned int nonprintable = 0;  
74 - int consecutive_printable = 0;  
75 - for (unsigned int i = 0; i < this->val.length(); ++i)  
76 - {  
77 - char ch = this->val.at(i);  
78 - // Note: do not use locale to determine printability. The  
79 - // PDF specification accepts arbitrary binary data. Some  
80 - // locales imply multibyte characters. We'll consider  
81 - // something printable if it is printable in 7-bit ASCII.  
82 - // We'll code this manually rather than being rude and  
83 - // setting locale.  
84 - if ((ch == 0) || (! (is_ascii_printable(ch) ||  
85 - strchr("\n\r\t\b\f", ch))))  
86 - {  
87 - ++nonprintable;  
88 - consecutive_printable = 0;  
89 - }  
90 - else  
91 - {  
92 - if (++consecutive_printable > 5)  
93 - {  
94 - // If there are more than 5 consecutive printable  
95 - // characters, I want to see them as such.  
96 - nonprintable = 0;  
97 - break;  
98 - }  
99 - }  
100 - }  
101 -  
102 - // Use hex notation if more than 20% of the characters are not  
103 - // printable in plain ASCII.  
104 - if (5 * nonprintable > val.length())  
105 - {  
106 - use_hexstring = true;  
107 - } 73 + unsigned int nonprintable = 0;
  74 + int consecutive_printable = 0;
  75 + for (unsigned int i = 0; i < this->val.length(); ++i)
  76 + {
  77 + char ch = this->val.at(i);
  78 + // Note: do not use locale to determine printability. The
  79 + // PDF specification accepts arbitrary binary data. Some
  80 + // locales imply multibyte characters. We'll consider
  81 + // something printable if it is printable in 7-bit ASCII.
  82 + // We'll code this manually rather than being rude and
  83 + // setting locale.
  84 + if ((ch == 0) || (! (is_ascii_printable(ch) ||
  85 + strchr("\n\r\t\b\f", ch))))
  86 + {
  87 + ++nonprintable;
  88 + consecutive_printable = 0;
  89 + }
  90 + else
  91 + {
  92 + if (++consecutive_printable > 5)
  93 + {
  94 + // If there are more than 5 consecutive printable
  95 + // characters, I want to see them as such.
  96 + nonprintable = 0;
  97 + break;
  98 + }
  99 + }
  100 + }
  101 +
  102 + // Use hex notation if more than 20% of the characters are not
  103 + // printable in plain ASCII.
  104 + if (5 * nonprintable > val.length())
  105 + {
  106 + use_hexstring = true;
  107 + }
108 } 108 }
109 std::string result; 109 std::string result;
110 if (use_hexstring) 110 if (use_hexstring)
111 { 111 {
112 - result += "<" + QUtil::hex_encode(this->val) + ">"; 112 + result += "<" + QUtil::hex_encode(this->val) + ">";
113 } 113 }
114 else 114 else
115 { 115 {
116 - result += "(";  
117 - for (unsigned int i = 0; i < this->val.length(); ++i)  
118 - {  
119 - char ch = this->val.at(i);  
120 - switch (ch)  
121 - {  
122 - case '\n':  
123 - result += "\\n";  
124 - break;  
125 -  
126 - case '\r':  
127 - result += "\\r";  
128 - break;  
129 -  
130 - case '\t':  
131 - result += "\\t";  
132 - break;  
133 -  
134 - case '\b':  
135 - result += "\\b";  
136 - break;  
137 -  
138 - case '\f':  
139 - result += "\\f";  
140 - break;  
141 -  
142 - case '(':  
143 - result += "\\(";  
144 - break;  
145 -  
146 - case ')':  
147 - result += "\\)";  
148 - break;  
149 -  
150 - case '\\':  
151 - result += "\\\\";  
152 - break;  
153 -  
154 - default:  
155 - if (is_iso_latin1_printable(ch))  
156 - {  
157 - result += this->val.at(i);  
158 - }  
159 - else  
160 - {  
161 - result += "\\" + QUtil::int_to_string_base( 116 + result += "(";
  117 + for (unsigned int i = 0; i < this->val.length(); ++i)
  118 + {
  119 + char ch = this->val.at(i);
  120 + switch (ch)
  121 + {
  122 + case '\n':
  123 + result += "\\n";
  124 + break;
  125 +
  126 + case '\r':
  127 + result += "\\r";
  128 + break;
  129 +
  130 + case '\t':
  131 + result += "\\t";
  132 + break;
  133 +
  134 + case '\b':
  135 + result += "\\b";
  136 + break;
  137 +
  138 + case '\f':
  139 + result += "\\f";
  140 + break;
  141 +
  142 + case '(':
  143 + result += "\\(";
  144 + break;
  145 +
  146 + case ')':
  147 + result += "\\)";
  148 + break;
  149 +
  150 + case '\\':
  151 + result += "\\\\";
  152 + break;
  153 +
  154 + default:
  155 + if (is_iso_latin1_printable(ch))
  156 + {
  157 + result += this->val.at(i);
  158 + }
  159 + else
  160 + {
  161 + result += "\\" + QUtil::int_to_string_base(
162 static_cast<int>(static_cast<unsigned char>(ch)), 162 static_cast<int>(static_cast<unsigned char>(ch)),
163 8, 3); 163 8, 3);
164 - }  
165 - break;  
166 - }  
167 - }  
168 - result += ")"; 164 + }
  165 + break;
  166 + }
  167 + }
  168 + result += ")";
169 } 169 }
170 170
171 return result; 171 return result;
libqpdf/QPDF_encryption.cc
@@ -147,7 +147,7 @@ QPDF::trim_user_password(std::string&amp; user_password) @@ -147,7 +147,7 @@ QPDF::trim_user_password(std::string&amp; user_password)
147 size_t len = user_password.length(); 147 size_t len = user_password.length();
148 if (len < key_bytes) 148 if (len < key_bytes)
149 { 149 {
150 - return; 150 + return;
151 } 151 }
152 152
153 char const* p1 = cstr; 153 char const* p1 = cstr;
@@ -155,11 +155,11 @@ QPDF::trim_user_password(std::string&amp; user_password) @@ -155,11 +155,11 @@ QPDF::trim_user_password(std::string&amp; user_password)
155 while ((p2 = strchr(p1, '\x28')) != 0) 155 while ((p2 = strchr(p1, '\x28')) != 0)
156 { 156 {
157 size_t idx = toS(p2 - cstr); 157 size_t idx = toS(p2 - cstr);
158 - if (memcmp(p2, padding_string, len - idx) == 0)  
159 - {  
160 - user_password = user_password.substr(0, idx);  
161 - return;  
162 - } 158 + if (memcmp(p2, padding_string, len - idx) == 0)
  159 + {
  160 + user_password = user_password.substr(0, idx);
  161 + return;
  162 + }
163 else 163 else
164 { 164 {
165 QTC::TC("qpdf", "QPDF_encryption skip 0x28"); 165 QTC::TC("qpdf", "QPDF_encryption skip 0x28");
@@ -191,30 +191,30 @@ iterate_md5_digest(MD5&amp; md5, MD5::Digest&amp; digest, @@ -191,30 +191,30 @@ iterate_md5_digest(MD5&amp; md5, MD5::Digest&amp; digest,
191 191
192 for (int i = 0; i < iterations; ++i) 192 for (int i = 0; i < iterations; ++i)
193 { 193 {
194 - MD5 m;  
195 - m.encodeDataIncrementally(reinterpret_cast<char*>(digest), 194 + MD5 m;
  195 + m.encodeDataIncrementally(reinterpret_cast<char*>(digest),
196 QIntC::to_size(key_len)); 196 QIntC::to_size(key_len));
197 - m.digest(digest); 197 + m.digest(digest);
198 } 198 }
199 } 199 }
200 200
201 201
202 static void 202 static void
203 iterate_rc4(unsigned char* data, size_t data_len, 203 iterate_rc4(unsigned char* data, size_t data_len,
204 - unsigned char* okey, int key_len,  
205 - int iterations, bool reverse) 204 + unsigned char* okey, int key_len,
  205 + int iterations, bool reverse)
206 { 206 {
207 auto key_ph = std::make_unique<unsigned char[]>(QIntC::to_size(key_len)); 207 auto key_ph = std::make_unique<unsigned char[]>(QIntC::to_size(key_len));
208 unsigned char* key = key_ph.get(); 208 unsigned char* key = key_ph.get();
209 for (int i = 0; i < iterations; ++i) 209 for (int i = 0; i < iterations; ++i)
210 { 210 {
211 - int const xor_value = (reverse ? iterations - 1 - i : i);  
212 - for (int j = 0; j < key_len; ++j)  
213 - {  
214 - key[j] = static_cast<unsigned char>(okey[j] ^ xor_value);  
215 - }  
216 - RC4 rc4(key, QIntC::to_int(key_len));  
217 - rc4.process(data, data_len); 211 + int const xor_value = (reverse ? iterations - 1 - i : i);
  212 + for (int j = 0; j < key_len; ++j)
  213 + {
  214 + key[j] = static_cast<unsigned char>(okey[j] ^ xor_value);
  215 + }
  216 + RC4 rc4(key, QIntC::to_int(key_len));
  217 + rc4.process(data, data_len);
218 } 218 }
219 } 219 }
220 220
@@ -354,7 +354,7 @@ void pad_short_parameter(std::string&amp; param, size_t max_len) @@ -354,7 +354,7 @@ void pad_short_parameter(std::string&amp; param, size_t max_len)
354 354
355 std::string 355 std::string
356 QPDF::compute_data_key(std::string const& encryption_key, 356 QPDF::compute_data_key(std::string const& encryption_key,
357 - int objid, int generation, bool use_aes, 357 + int objid, int generation, bool use_aes,
358 int encryption_V, int encryption_R) 358 int encryption_V, int encryption_R)
359 { 359 {
360 // Algorithm 3.1 from the PDF 1.7 Reference Manual 360 // Algorithm 3.1 from the PDF 1.7 Reference Manual
@@ -376,7 +376,7 @@ QPDF::compute_data_key(std::string const&amp; encryption_key, @@ -376,7 +376,7 @@ QPDF::compute_data_key(std::string const&amp; encryption_key,
376 result.append(1, static_cast<char>((generation >> 8) & 0xff)); 376 result.append(1, static_cast<char>((generation >> 8) & 0xff));
377 if (use_aes) 377 if (use_aes)
378 { 378 {
379 - result += "sAlT"; 379 + result += "sAlT";
380 } 380 }
381 381
382 MD5 md5; 382 MD5 md5;
@@ -384,7 +384,7 @@ QPDF::compute_data_key(std::string const&amp; encryption_key, @@ -384,7 +384,7 @@ QPDF::compute_data_key(std::string const&amp; encryption_key,
384 MD5::Digest digest; 384 MD5::Digest digest;
385 md5.digest(digest); 385 md5.digest(digest);
386 return std::string(reinterpret_cast<char*>(digest), 386 return std::string(reinterpret_cast<char*>(digest),
387 - std::min(result.length(), toS(16))); 387 + std::min(result.length(), toS(16)));
388 } 388 }
389 389
390 std::string 390 std::string
@@ -421,7 +421,7 @@ QPDF::compute_encryption_key_from_password( @@ -421,7 +421,7 @@ QPDF::compute_encryption_key_from_password(
421 421
422 MD5 md5; 422 MD5 md5;
423 md5.encodeDataIncrementally( 423 md5.encodeDataIncrementally(
424 - pad_or_truncate_password_V4(password).c_str(), key_bytes); 424 + pad_or_truncate_password_V4(password).c_str(), key_bytes);
425 md5.encodeDataIncrementally(data.getO().c_str(), key_bytes); 425 md5.encodeDataIncrementally(data.getO().c_str(), key_bytes);
426 char pbytes[4]; 426 char pbytes[4];
427 int P = data.getP(); 427 int P = data.getP();
@@ -434,9 +434,9 @@ QPDF::compute_encryption_key_from_password( @@ -434,9 +434,9 @@ QPDF::compute_encryption_key_from_password(
434 data.getId1().length()); 434 data.getId1().length());
435 if ((data.getR() >= 4) && (! data.getEncryptMetadata())) 435 if ((data.getR() >= 4) && (! data.getEncryptMetadata()))
436 { 436 {
437 - char bytes[4];  
438 - memset(bytes, 0xff, 4);  
439 - md5.encodeDataIncrementally(bytes, 4); 437 + char bytes[4];
  438 + memset(bytes, 0xff, 4);
  439 + md5.encodeDataIncrementally(bytes, 4);
440 } 440 }
441 MD5::Digest digest; 441 MD5::Digest digest;
442 int key_len = 442 int key_len =
@@ -448,23 +448,23 @@ QPDF::compute_encryption_key_from_password( @@ -448,23 +448,23 @@ QPDF::compute_encryption_key_from_password(
448 448
449 static void 449 static void
450 compute_O_rc4_key(std::string const& user_password, 450 compute_O_rc4_key(std::string const& user_password,
451 - std::string const& owner_password,  
452 - QPDF::EncryptionData const& data,  
453 - unsigned char key[OU_key_bytes_V4]) 451 + std::string const& owner_password,
  452 + QPDF::EncryptionData const& data,
  453 + unsigned char key[OU_key_bytes_V4])
454 { 454 {
455 if (data.getV() >= 5) 455 if (data.getV() >= 5)
456 { 456 {
457 - throw std::logic_error(  
458 - "compute_O_rc4_key called for file with V >= 5"); 457 + throw std::logic_error(
  458 + "compute_O_rc4_key called for file with V >= 5");
459 } 459 }
460 std::string password = owner_password; 460 std::string password = owner_password;
461 if (password.empty()) 461 if (password.empty())
462 { 462 {
463 - password = user_password; 463 + password = user_password;
464 } 464 }
465 MD5 md5; 465 MD5 md5;
466 md5.encodeDataIncrementally( 466 md5.encodeDataIncrementally(
467 - pad_or_truncate_password_V4(password).c_str(), key_bytes); 467 + pad_or_truncate_password_V4(password).c_str(), key_bytes);
468 MD5::Digest digest; 468 MD5::Digest digest;
469 int key_len = std::min(QIntC::to_int(sizeof(digest)), 469 int key_len = std::min(QIntC::to_int(sizeof(digest)),
470 data.getLengthBytes()); 470 data.getLengthBytes());
@@ -474,8 +474,8 @@ compute_O_rc4_key(std::string const&amp; user_password, @@ -474,8 +474,8 @@ compute_O_rc4_key(std::string const&amp; user_password,
474 474
475 static std::string 475 static std::string
476 compute_O_value(std::string const& user_password, 476 compute_O_value(std::string const& user_password,
477 - std::string const& owner_password,  
478 - QPDF::EncryptionData const& data) 477 + std::string const& owner_password,
  478 + QPDF::EncryptionData const& data)
479 { 479 {
480 // Algorithm 3.3 from the PDF 1.7 Reference Manual 480 // Algorithm 3.3 from the PDF 1.7 Reference Manual
481 481
@@ -487,7 +487,7 @@ compute_O_value(std::string const&amp; user_password, @@ -487,7 +487,7 @@ compute_O_value(std::string const&amp; user_password,
487 std::string k1(reinterpret_cast<char*>(O_key), OU_key_bytes_V4); 487 std::string k1(reinterpret_cast<char*>(O_key), OU_key_bytes_V4);
488 pad_short_parameter(k1, QIntC::to_size(data.getLengthBytes())); 488 pad_short_parameter(k1, QIntC::to_size(data.getLengthBytes()));
489 iterate_rc4(QUtil::unsigned_char_pointer(upass), key_bytes, 489 iterate_rc4(QUtil::unsigned_char_pointer(upass), key_bytes,
490 - O_key, data.getLengthBytes(), 490 + O_key, data.getLengthBytes(),
491 (data.getR() >= 3) ? 20 : 1, false); 491 (data.getR() >= 3) ? 20 : 1, false);
492 return std::string(upass, key_bytes); 492 return std::string(upass, key_bytes);
493 } 493 }
@@ -495,7 +495,7 @@ compute_O_value(std::string const&amp; user_password, @@ -495,7 +495,7 @@ compute_O_value(std::string const&amp; user_password,
495 static 495 static
496 std::string 496 std::string
497 compute_U_value_R2(std::string const& user_password, 497 compute_U_value_R2(std::string const& user_password,
498 - QPDF::EncryptionData const& data) 498 + QPDF::EncryptionData const& data)
499 { 499 {
500 // Algorithm 3.4 from the PDF 1.7 Reference Manual 500 // Algorithm 3.4 from the PDF 1.7 Reference Manual
501 501
@@ -504,7 +504,7 @@ compute_U_value_R2(std::string const&amp; user_password, @@ -504,7 +504,7 @@ compute_U_value_R2(std::string const&amp; user_password,
504 pad_or_truncate_password_V4("", udata); 504 pad_or_truncate_password_V4("", udata);
505 pad_short_parameter(k1, QIntC::to_size(data.getLengthBytes())); 505 pad_short_parameter(k1, QIntC::to_size(data.getLengthBytes()));
506 iterate_rc4(QUtil::unsigned_char_pointer(udata), key_bytes, 506 iterate_rc4(QUtil::unsigned_char_pointer(udata), key_bytes,
507 - QUtil::unsigned_char_pointer(k1), 507 + QUtil::unsigned_char_pointer(k1),
508 data.getLengthBytes(), 1, false); 508 data.getLengthBytes(), 1, false);
509 return std::string(udata, key_bytes); 509 return std::string(udata, key_bytes);
510 } 510 }
@@ -512,21 +512,21 @@ compute_U_value_R2(std::string const&amp; user_password, @@ -512,21 +512,21 @@ compute_U_value_R2(std::string const&amp; user_password,
512 static 512 static
513 std::string 513 std::string
514 compute_U_value_R3(std::string const& user_password, 514 compute_U_value_R3(std::string const& user_password,
515 - QPDF::EncryptionData const& data) 515 + QPDF::EncryptionData const& data)
516 { 516 {
517 // Algorithm 3.5 from the PDF 1.7 Reference Manual 517 // Algorithm 3.5 from the PDF 1.7 Reference Manual
518 518
519 std::string k1 = QPDF::compute_encryption_key(user_password, data); 519 std::string k1 = QPDF::compute_encryption_key(user_password, data);
520 MD5 md5; 520 MD5 md5;
521 md5.encodeDataIncrementally( 521 md5.encodeDataIncrementally(
522 - pad_or_truncate_password_V4("").c_str(), key_bytes); 522 + pad_or_truncate_password_V4("").c_str(), key_bytes);
523 md5.encodeDataIncrementally(data.getId1().c_str(), 523 md5.encodeDataIncrementally(data.getId1().c_str(),
524 data.getId1().length()); 524 data.getId1().length());
525 MD5::Digest digest; 525 MD5::Digest digest;
526 md5.digest(digest); 526 md5.digest(digest);
527 pad_short_parameter(k1, QIntC::to_size(data.getLengthBytes())); 527 pad_short_parameter(k1, QIntC::to_size(data.getLengthBytes()));
528 iterate_rc4(digest, sizeof(MD5::Digest), 528 iterate_rc4(digest, sizeof(MD5::Digest),
529 - QUtil::unsigned_char_pointer(k1), 529 + QUtil::unsigned_char_pointer(k1),
530 data.getLengthBytes(), 20, false); 530 data.getLengthBytes(), 20, false);
531 char result[key_bytes]; 531 char result[key_bytes];
532 memcpy(result, digest, sizeof(MD5::Digest)); 532 memcpy(result, digest, sizeof(MD5::Digest));
@@ -534,18 +534,18 @@ compute_U_value_R3(std::string const&amp; user_password, @@ -534,18 +534,18 @@ compute_U_value_R3(std::string const&amp; user_password,
534 // testing 534 // testing
535 for (unsigned int i = sizeof(MD5::Digest); i < key_bytes; ++i) 535 for (unsigned int i = sizeof(MD5::Digest); i < key_bytes; ++i)
536 { 536 {
537 - result[i] = static_cast<char>((i * i) % 0xff); 537 + result[i] = static_cast<char>((i * i) % 0xff);
538 } 538 }
539 return std::string(result, key_bytes); 539 return std::string(result, key_bytes);
540 } 540 }
541 541
542 static std::string 542 static std::string
543 compute_U_value(std::string const& user_password, 543 compute_U_value(std::string const& user_password,
544 - QPDF::EncryptionData const& data) 544 + QPDF::EncryptionData const& data)
545 { 545 {
546 if (data.getR() >= 3) 546 if (data.getR() >= 3)
547 { 547 {
548 - return compute_U_value_R3(user_password, data); 548 + return compute_U_value_R3(user_password, data);
549 } 549 }
550 550
551 return compute_U_value_R2(user_password, data); 551 return compute_U_value_R2(user_password, data);
@@ -577,7 +577,7 @@ check_user_password_V5(std::string const&amp; user_password, @@ -577,7 +577,7 @@ check_user_password_V5(std::string const&amp; user_password,
577 577
578 static bool 578 static bool
579 check_user_password(std::string const& user_password, 579 check_user_password(std::string const& user_password,
580 - QPDF::EncryptionData const& data) 580 + QPDF::EncryptionData const& data)
581 { 581 {
582 if (data.getV() < 5) 582 if (data.getV() < 5)
583 { 583 {
@@ -632,8 +632,8 @@ check_owner_password_V5(std::string const&amp; owner_password, @@ -632,8 +632,8 @@ check_owner_password_V5(std::string const&amp; owner_password,
632 632
633 static bool 633 static bool
634 check_owner_password(std::string& user_password, 634 check_owner_password(std::string& user_password,
635 - std::string const& owner_password,  
636 - QPDF::EncryptionData const& data) 635 + std::string const& owner_password,
  636 + QPDF::EncryptionData const& data)
637 { 637 {
638 if (data.getV() < 5) 638 if (data.getV() < 5)
639 { 639 {
@@ -773,24 +773,24 @@ QPDF::interpretCF( @@ -773,24 +773,24 @@ QPDF::interpretCF(
773 { 773 {
774 if (cf.isName()) 774 if (cf.isName())
775 { 775 {
776 - std::string filter = cf.getName();  
777 - if (encp->crypt_filters.count(filter) != 0)  
778 - {  
779 - return encp->crypt_filters[filter];  
780 - }  
781 - else if (filter == "/Identity")  
782 - {  
783 - return e_none;  
784 - }  
785 - else  
786 - {  
787 - return e_unknown;  
788 - } 776 + std::string filter = cf.getName();
  777 + if (encp->crypt_filters.count(filter) != 0)
  778 + {
  779 + return encp->crypt_filters[filter];
  780 + }
  781 + else if (filter == "/Identity")
  782 + {
  783 + return e_none;
  784 + }
  785 + else
  786 + {
  787 + return e_unknown;
  788 + }
789 } 789 }
790 else 790 else
791 { 791 {
792 - // Default: /Identity  
793 - return e_none; 792 + // Default: /Identity
  793 + return e_none;
794 } 794 }
795 } 795 }
796 796
@@ -799,7 +799,7 @@ QPDF::initializeEncryption() @@ -799,7 +799,7 @@ QPDF::initializeEncryption()
799 { 799 {
800 if (this->m->encp->encryption_initialized) 800 if (this->m->encp->encryption_initialized)
801 { 801 {
802 - return; 802 + return;
803 } 803 }
804 this->m->encp->encryption_initialized = true; 804 this->m->encp->encryption_initialized = true;
805 805
@@ -810,7 +810,7 @@ QPDF::initializeEncryption() @@ -810,7 +810,7 @@ QPDF::initializeEncryption()
810 810
811 if (! this->m->trailer.hasKey("/Encrypt")) 811 if (! this->m->trailer.hasKey("/Encrypt"))
812 { 812 {
813 - return; 813 + return;
814 } 814 }
815 815
816 // Go ahead and set this->m->encrypted here. That way, isEncrypted 816 // Go ahead and set this->m->encrypted here. That way, isEncrypted
@@ -831,7 +831,7 @@ QPDF::initializeEncryption() @@ -831,7 +831,7 @@ QPDF::initializeEncryption()
831 // Treating a missing ID as the empty string enables qpdf to 831 // Treating a missing ID as the empty string enables qpdf to
832 // decrypt some invalid encrypted files with no /ID that 832 // decrypt some invalid encrypted files with no /ID that
833 // poppler can read but Adobe Reader can't. 833 // poppler can read but Adobe Reader can't.
834 - warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), 834 + warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
835 "trailer", this->m->file->getLastOffset(), 835 "trailer", this->m->file->getLastOffset(),
836 "invalid /ID in trailer dictionary")); 836 "invalid /ID in trailer dictionary"));
837 } 837 }
@@ -839,37 +839,37 @@ QPDF::initializeEncryption() @@ -839,37 +839,37 @@ QPDF::initializeEncryption()
839 QPDFObjectHandle encryption_dict = this->m->trailer.getKey("/Encrypt"); 839 QPDFObjectHandle encryption_dict = this->m->trailer.getKey("/Encrypt");
840 if (! encryption_dict.isDictionary()) 840 if (! encryption_dict.isDictionary())
841 { 841 {
842 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
843 - this->m->last_object_description,  
844 - this->m->file->getLastOffset(),  
845 - "/Encrypt in trailer dictionary is not a dictionary"); 842 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  843 + this->m->last_object_description,
  844 + this->m->file->getLastOffset(),
  845 + "/Encrypt in trailer dictionary is not a dictionary");
846 } 846 }
847 847
848 if (! (encryption_dict.getKey("/Filter").isName() && 848 if (! (encryption_dict.getKey("/Filter").isName() &&
849 - (encryption_dict.getKey("/Filter").getName() == "/Standard"))) 849 + (encryption_dict.getKey("/Filter").getName() == "/Standard")))
850 { 850 {
851 throw QPDFExc(qpdf_e_unsupported, this->m->file->getName(), 851 throw QPDFExc(qpdf_e_unsupported, this->m->file->getName(),
852 - "encryption dictionary", this->m->file->getLastOffset(),  
853 - "unsupported encryption filter"); 852 + "encryption dictionary", this->m->file->getLastOffset(),
  853 + "unsupported encryption filter");
854 } 854 }
855 if (! encryption_dict.getKey("/SubFilter").isNull()) 855 if (! encryption_dict.getKey("/SubFilter").isNull())
856 { 856 {
857 - warn(QPDFExc(qpdf_e_unsupported, this->m->file->getName(),  
858 - "encryption dictionary", this->m->file->getLastOffset(),  
859 - "file uses encryption SubFilters,"  
860 - " which qpdf does not support")); 857 + warn(QPDFExc(qpdf_e_unsupported, this->m->file->getName(),
  858 + "encryption dictionary", this->m->file->getLastOffset(),
  859 + "file uses encryption SubFilters,"
  860 + " which qpdf does not support"));
861 } 861 }
862 862
863 if (! (encryption_dict.getKey("/V").isInteger() && 863 if (! (encryption_dict.getKey("/V").isInteger() &&
864 - encryption_dict.getKey("/R").isInteger() &&  
865 - encryption_dict.getKey("/O").isString() &&  
866 - encryption_dict.getKey("/U").isString() &&  
867 - encryption_dict.getKey("/P").isInteger())) 864 + encryption_dict.getKey("/R").isInteger() &&
  865 + encryption_dict.getKey("/O").isString() &&
  866 + encryption_dict.getKey("/U").isString() &&
  867 + encryption_dict.getKey("/P").isInteger()))
868 { 868 {
869 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
870 - "encryption dictionary", this->m->file->getLastOffset(),  
871 - "some encryption dictionary parameters are missing "  
872 - "or the wrong type"); 869 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  870 + "encryption dictionary", this->m->file->getLastOffset(),
  871 + "some encryption dictionary parameters are missing "
  872 + "or the wrong type");
873 } 873 }
874 874
875 int V = encryption_dict.getKey("/V").getIntValueAsInt(); 875 int V = encryption_dict.getKey("/V").getIntValueAsInt();
@@ -881,11 +881,11 @@ QPDF::initializeEncryption() @@ -881,11 +881,11 @@ QPDF::initializeEncryption()
881 // If supporting new encryption R/V values, remember to update 881 // If supporting new encryption R/V values, remember to update
882 // error message inside this if statement. 882 // error message inside this if statement.
883 if (! (((R >= 2) && (R <= 6)) && 883 if (! (((R >= 2) && (R <= 6)) &&
884 - ((V == 1) || (V == 2) || (V == 4) || (V == 5)))) 884 + ((V == 1) || (V == 2) || (V == 4) || (V == 5))))
885 { 885 {
886 - throw QPDFExc(qpdf_e_unsupported, this->m->file->getName(),  
887 - "encryption dictionary", this->m->file->getLastOffset(),  
888 - "Unsupported /R or /V in encryption dictionary; R = " + 886 + throw QPDFExc(qpdf_e_unsupported, this->m->file->getName(),
  887 + "encryption dictionary", this->m->file->getLastOffset(),
  888 + "Unsupported /R or /V in encryption dictionary; R = " +
889 QUtil::int_to_string(R) + " (max 6), V = " + 889 QUtil::int_to_string(R) + " (max 6), V = " +
890 QUtil::int_to_string(V) + " (max 5)"); 890 QUtil::int_to_string(V) + " (max 5)");
891 } 891 }
@@ -969,58 +969,58 @@ QPDF::initializeEncryption() @@ -969,58 +969,58 @@ QPDF::initializeEncryption()
969 this->m->encp->encrypt_metadata = true; 969 this->m->encp->encrypt_metadata = true;
970 if ((V >= 4) && (encryption_dict.getKey("/EncryptMetadata").isBool())) 970 if ((V >= 4) && (encryption_dict.getKey("/EncryptMetadata").isBool()))
971 { 971 {
972 - this->m->encp->encrypt_metadata =  
973 - encryption_dict.getKey("/EncryptMetadata").getBoolValue(); 972 + this->m->encp->encrypt_metadata =
  973 + encryption_dict.getKey("/EncryptMetadata").getBoolValue();
974 } 974 }
975 975
976 if ((V == 4) || (V == 5)) 976 if ((V == 4) || (V == 5))
977 { 977 {
978 - QPDFObjectHandle CF = encryption_dict.getKey("/CF");  
979 - std::set<std::string> keys = CF.getKeys();  
980 - for (std::set<std::string>::iterator iter = keys.begin();  
981 - iter != keys.end(); ++iter)  
982 - {  
983 - std::string const& filter = *iter;  
984 - QPDFObjectHandle cdict = CF.getKey(filter);  
985 - if (cdict.isDictionary())  
986 - {  
987 - encryption_method_e method = e_none;  
988 - if (cdict.getKey("/CFM").isName())  
989 - {  
990 - std::string method_name = cdict.getKey("/CFM").getName();  
991 - if (method_name == "/V2")  
992 - {  
993 - QTC::TC("qpdf", "QPDF_encryption CFM V2");  
994 - method = e_rc4;  
995 - }  
996 - else if (method_name == "/AESV2")  
997 - {  
998 - QTC::TC("qpdf", "QPDF_encryption CFM AESV2");  
999 - method = e_aes;  
1000 - }  
1001 - else if (method_name == "/AESV3")  
1002 - {  
1003 - QTC::TC("qpdf", "QPDF_encryption CFM AESV3");  
1004 - method = e_aesv3;  
1005 - }  
1006 - else  
1007 - {  
1008 - // Don't complain now -- maybe we won't need  
1009 - // to reference this type.  
1010 - method = e_unknown;  
1011 - }  
1012 - }  
1013 - this->m->encp->crypt_filters[filter] = method;  
1014 - }  
1015 - }  
1016 -  
1017 - QPDFObjectHandle StmF = encryption_dict.getKey("/StmF");  
1018 - QPDFObjectHandle StrF = encryption_dict.getKey("/StrF");  
1019 - QPDFObjectHandle EFF = encryption_dict.getKey("/EFF");  
1020 - this->m->encp->cf_stream = interpretCF(this->m->encp, StmF);  
1021 - this->m->encp->cf_string = interpretCF(this->m->encp, StrF);  
1022 - if (EFF.isName())  
1023 - { 978 + QPDFObjectHandle CF = encryption_dict.getKey("/CF");
  979 + std::set<std::string> keys = CF.getKeys();
  980 + for (std::set<std::string>::iterator iter = keys.begin();
  981 + iter != keys.end(); ++iter)
  982 + {
  983 + std::string const& filter = *iter;
  984 + QPDFObjectHandle cdict = CF.getKey(filter);
  985 + if (cdict.isDictionary())
  986 + {
  987 + encryption_method_e method = e_none;
  988 + if (cdict.getKey("/CFM").isName())
  989 + {
  990 + std::string method_name = cdict.getKey("/CFM").getName();
  991 + if (method_name == "/V2")
  992 + {
  993 + QTC::TC("qpdf", "QPDF_encryption CFM V2");
  994 + method = e_rc4;
  995 + }
  996 + else if (method_name == "/AESV2")
  997 + {
  998 + QTC::TC("qpdf", "QPDF_encryption CFM AESV2");
  999 + method = e_aes;
  1000 + }
  1001 + else if (method_name == "/AESV3")
  1002 + {
  1003 + QTC::TC("qpdf", "QPDF_encryption CFM AESV3");
  1004 + method = e_aesv3;
  1005 + }
  1006 + else
  1007 + {
  1008 + // Don't complain now -- maybe we won't need
  1009 + // to reference this type.
  1010 + method = e_unknown;
  1011 + }
  1012 + }
  1013 + this->m->encp->crypt_filters[filter] = method;
  1014 + }
  1015 + }
  1016 +
  1017 + QPDFObjectHandle StmF = encryption_dict.getKey("/StmF");
  1018 + QPDFObjectHandle StrF = encryption_dict.getKey("/StrF");
  1019 + QPDFObjectHandle EFF = encryption_dict.getKey("/EFF");
  1020 + this->m->encp->cf_stream = interpretCF(this->m->encp, StmF);
  1021 + this->m->encp->cf_string = interpretCF(this->m->encp, StrF);
  1022 + if (EFF.isName())
  1023 + {
1024 // qpdf does not use this for anything other than 1024 // qpdf does not use this for anything other than
1025 // informational purposes. This is intended to instruct 1025 // informational purposes. This is intended to instruct
1026 // conforming writers on which crypt filter should be used 1026 // conforming writers on which crypt filter should be used
@@ -1035,12 +1035,12 @@ QPDF::initializeEncryption() @@ -1035,12 +1035,12 @@ QPDF::initializeEncryption()
1035 // at a file generated by something else, such as Acrobat 1035 // at a file generated by something else, such as Acrobat
1036 // when specifying that only attachments should be 1036 // when specifying that only attachments should be
1037 // encrypted. 1037 // encrypted.
1038 - this->m->encp->cf_file = interpretCF(this->m->encp, EFF);  
1039 - }  
1040 - else  
1041 - {  
1042 - this->m->encp->cf_file = this->m->encp->cf_stream;  
1043 - } 1038 + this->m->encp->cf_file = interpretCF(this->m->encp, EFF);
  1039 + }
  1040 + else
  1041 + {
  1042 + this->m->encp->cf_file = this->m->encp->cf_stream;
  1043 + }
1044 } 1044 }
1045 1045
1046 EncryptionData data(V, R, Length / 8, 1046 EncryptionData data(V, R, Length / 8,
@@ -1128,19 +1128,19 @@ QPDF::getKeyForObject( @@ -1128,19 +1128,19 @@ QPDF::getKeyForObject(
1128 { 1128 {
1129 if (! encp->encrypted) 1129 if (! encp->encrypted)
1130 { 1130 {
1131 - throw std::logic_error(  
1132 - "request for encryption key in non-encrypted PDF"); 1131 + throw std::logic_error(
  1132 + "request for encryption key in non-encrypted PDF");
1133 } 1133 }
1134 1134
1135 if (! ((objid == encp->cached_key_objid) && 1135 if (! ((objid == encp->cached_key_objid) &&
1136 - (generation == encp->cached_key_generation))) 1136 + (generation == encp->cached_key_generation)))
1137 { 1137 {
1138 - encp->cached_object_encryption_key =  
1139 - compute_data_key(encp->encryption_key, objid, generation, 1138 + encp->cached_object_encryption_key =
  1139 + compute_data_key(encp->encryption_key, objid, generation,
1140 use_aes, encp->encryption_V, 1140 use_aes, encp->encryption_V,
1141 encp->encryption_R); 1141 encp->encryption_R);
1142 - encp->cached_key_objid = objid;  
1143 - encp->cached_key_generation = generation; 1142 + encp->cached_key_objid = objid;
  1143 + encp->cached_key_generation = generation;
1144 } 1144 }
1145 1145
1146 return encp->cached_object_encryption_key; 1146 return encp->cached_object_encryption_key;
@@ -1151,83 +1151,83 @@ QPDF::decryptString(std::string&amp; str, int objid, int generation) @@ -1151,83 +1151,83 @@ QPDF::decryptString(std::string&amp; str, int objid, int generation)
1151 { 1151 {
1152 if (objid == 0) 1152 if (objid == 0)
1153 { 1153 {
1154 - return; 1154 + return;
1155 } 1155 }
1156 bool use_aes = false; 1156 bool use_aes = false;
1157 if (this->m->encp->encryption_V >= 4) 1157 if (this->m->encp->encryption_V >= 4)
1158 { 1158 {
1159 - switch (this->m->encp->cf_string)  
1160 - {  
1161 - case e_none:  
1162 - return;  
1163 -  
1164 - case e_aes:  
1165 - use_aes = true;  
1166 - break;  
1167 -  
1168 - case e_aesv3:  
1169 - use_aes = true;  
1170 - break;  
1171 -  
1172 - case e_rc4:  
1173 - break;  
1174 -  
1175 - default:  
1176 - warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
1177 - this->m->last_object_description,  
1178 - this->m->file->getLastOffset(),  
1179 - "unknown encryption filter for strings"  
1180 - " (check /StrF in /Encrypt dictionary);"  
1181 - " strings may be decrypted improperly"));  
1182 - // To avoid repeated warnings, reset cf_string. Assume  
1183 - // we'd want to use AES if V == 4.  
1184 - this->m->encp->cf_string = e_aes; 1159 + switch (this->m->encp->cf_string)
  1160 + {
  1161 + case e_none:
  1162 + return;
  1163 +
  1164 + case e_aes:
  1165 + use_aes = true;
  1166 + break;
  1167 +
  1168 + case e_aesv3:
  1169 + use_aes = true;
  1170 + break;
  1171 +
  1172 + case e_rc4:
  1173 + break;
  1174 +
  1175 + default:
  1176 + warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  1177 + this->m->last_object_description,
  1178 + this->m->file->getLastOffset(),
  1179 + "unknown encryption filter for strings"
  1180 + " (check /StrF in /Encrypt dictionary);"
  1181 + " strings may be decrypted improperly"));
  1182 + // To avoid repeated warnings, reset cf_string. Assume
  1183 + // we'd want to use AES if V == 4.
  1184 + this->m->encp->cf_string = e_aes;
1185 use_aes = true; 1185 use_aes = true;
1186 - break;  
1187 - } 1186 + break;
  1187 + }
1188 } 1188 }
1189 1189
1190 std::string key = getKeyForObject( 1190 std::string key = getKeyForObject(
1191 this->m->encp, objid, generation, use_aes); 1191 this->m->encp, objid, generation, use_aes);
1192 try 1192 try
1193 { 1193 {
1194 - if (use_aes)  
1195 - {  
1196 - QTC::TC("qpdf", "QPDF_encryption aes decode string");  
1197 - Pl_Buffer bufpl("decrypted string");  
1198 - Pl_AES_PDF pl("aes decrypt string", &bufpl, false,  
1199 - QUtil::unsigned_char_pointer(key), 1194 + if (use_aes)
  1195 + {
  1196 + QTC::TC("qpdf", "QPDF_encryption aes decode string");
  1197 + Pl_Buffer bufpl("decrypted string");
  1198 + Pl_AES_PDF pl("aes decrypt string", &bufpl, false,
  1199 + QUtil::unsigned_char_pointer(key),
1200 key.length()); 1200 key.length());
1201 - pl.write(QUtil::unsigned_char_pointer(str), str.length());  
1202 - pl.finish();  
1203 - auto buf = bufpl.getBufferSharedPointer();  
1204 - str = std::string(reinterpret_cast<char*>(buf->getBuffer()), 1201 + pl.write(QUtil::unsigned_char_pointer(str), str.length());
  1202 + pl.finish();
  1203 + auto buf = bufpl.getBufferSharedPointer();
  1204 + str = std::string(reinterpret_cast<char*>(buf->getBuffer()),
1205 buf->getSize()); 1205 buf->getSize());
1206 - }  
1207 - else  
1208 - {  
1209 - QTC::TC("qpdf", "QPDF_encryption rc4 decode string");  
1210 - size_t vlen = str.length();  
1211 - // Using PointerHolder guarantees that tmp will  
1212 - // be freed even if rc4.process throws an exception.  
1213 - auto tmp = QUtil::make_unique_cstr(str);  
1214 - RC4 rc4(QUtil::unsigned_char_pointer(key), toI(key.length()));  
1215 - rc4.process(QUtil::unsigned_char_pointer(tmp.get()), vlen);  
1216 - str = std::string(tmp.get(), vlen);  
1217 - } 1206 + }
  1207 + else
  1208 + {
  1209 + QTC::TC("qpdf", "QPDF_encryption rc4 decode string");
  1210 + size_t vlen = str.length();
  1211 + // Using PointerHolder guarantees that tmp will
  1212 + // be freed even if rc4.process throws an exception.
  1213 + auto tmp = QUtil::make_unique_cstr(str);
  1214 + RC4 rc4(QUtil::unsigned_char_pointer(key), toI(key.length()));
  1215 + rc4.process(QUtil::unsigned_char_pointer(tmp.get()), vlen);
  1216 + str = std::string(tmp.get(), vlen);
  1217 + }
1218 } 1218 }
1219 catch (QPDFExc&) 1219 catch (QPDFExc&)
1220 { 1220 {
1221 - throw; 1221 + throw;
1222 } 1222 }
1223 catch (std::runtime_error& e) 1223 catch (std::runtime_error& e)
1224 { 1224 {
1225 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
1226 - this->m->last_object_description,  
1227 - this->m->file->getLastOffset(),  
1228 - "error decrypting string for object " +  
1229 - QUtil::int_to_string(objid) + " " +  
1230 - QUtil::int_to_string(generation) + ": " + e.what()); 1225 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  1226 + this->m->last_object_description,
  1227 + this->m->file->getLastOffset(),
  1228 + "error decrypting string for object " +
  1229 + QUtil::int_to_string(objid) + " " +
  1230 + QUtil::int_to_string(generation) + ": " + e.what());
1231 } 1231 }
1232 } 1232 }
1233 1233
@@ -1236,26 +1236,26 @@ QPDF::decryptStream(PointerHolder&lt;EncryptionParameters&gt; encp, @@ -1236,26 +1236,26 @@ QPDF::decryptStream(PointerHolder&lt;EncryptionParameters&gt; encp,
1236 PointerHolder<InputSource> file, 1236 PointerHolder<InputSource> file,
1237 QPDF& qpdf_for_warning, Pipeline*& pipeline, 1237 QPDF& qpdf_for_warning, Pipeline*& pipeline,
1238 int objid, int generation, 1238 int objid, int generation,
1239 - QPDFObjectHandle& stream_dict,  
1240 - std::vector<std::shared_ptr<Pipeline>>& heap) 1239 + QPDFObjectHandle& stream_dict,
  1240 + std::vector<std::shared_ptr<Pipeline>>& heap)
1241 { 1241 {
1242 std::string type; 1242 std::string type;
1243 if (stream_dict.getKey("/Type").isName()) 1243 if (stream_dict.getKey("/Type").isName())
1244 { 1244 {
1245 - type = stream_dict.getKey("/Type").getName(); 1245 + type = stream_dict.getKey("/Type").getName();
1246 } 1246 }
1247 if (type == "/XRef") 1247 if (type == "/XRef")
1248 { 1248 {
1249 - QTC::TC("qpdf", "QPDF_encryption xref stream from encrypted file");  
1250 - return; 1249 + QTC::TC("qpdf", "QPDF_encryption xref stream from encrypted file");
  1250 + return;
1251 } 1251 }
1252 bool use_aes = false; 1252 bool use_aes = false;
1253 if (encp->encryption_V >= 4) 1253 if (encp->encryption_V >= 4)
1254 { 1254 {
1255 - encryption_method_e method = e_unknown;  
1256 - std::string method_source = "/StmF from /Encrypt dictionary"; 1255 + encryption_method_e method = e_unknown;
  1256 + std::string method_source = "/StmF from /Encrypt dictionary";
1257 1257
1258 - if (stream_dict.getKey("/Filter").isOrHasName("/Crypt")) 1258 + if (stream_dict.getKey("/Filter").isOrHasName("/Crypt"))
1259 { 1259 {
1260 if (stream_dict.getKey("/DecodeParms").isDictionary()) 1260 if (stream_dict.getKey("/DecodeParms").isDictionary())
1261 { 1261 {
@@ -1294,67 +1294,67 @@ QPDF::decryptStream(PointerHolder&lt;EncryptionParameters&gt; encp, @@ -1294,67 +1294,67 @@ QPDF::decryptStream(PointerHolder&lt;EncryptionParameters&gt; encp,
1294 } 1294 }
1295 } 1295 }
1296 } 1296 }
1297 - }  
1298 -  
1299 - if (method == e_unknown)  
1300 - {  
1301 - if ((! encp->encrypt_metadata) && (type == "/Metadata"))  
1302 - {  
1303 - QTC::TC("qpdf", "QPDF_encryption cleartext metadata");  
1304 - method = e_none;  
1305 - }  
1306 - else  
1307 - { 1297 + }
  1298 +
  1299 + if (method == e_unknown)
  1300 + {
  1301 + if ((! encp->encrypt_metadata) && (type == "/Metadata"))
  1302 + {
  1303 + QTC::TC("qpdf", "QPDF_encryption cleartext metadata");
  1304 + method = e_none;
  1305 + }
  1306 + else
  1307 + {
1308 method = encp->cf_stream; 1308 method = encp->cf_stream;
1309 - }  
1310 - }  
1311 - use_aes = false;  
1312 - switch (method)  
1313 - {  
1314 - case e_none:  
1315 - return;  
1316 - break;  
1317 -  
1318 - case e_aes:  
1319 - use_aes = true;  
1320 - break;  
1321 -  
1322 - case e_aesv3:  
1323 - use_aes = true;  
1324 - break;  
1325 -  
1326 - case e_rc4:  
1327 - break;  
1328 -  
1329 - default:  
1330 - // filter local to this stream.  
1331 - qpdf_for_warning.warn( 1309 + }
  1310 + }
  1311 + use_aes = false;
  1312 + switch (method)
  1313 + {
  1314 + case e_none:
  1315 + return;
  1316 + break;
  1317 +
  1318 + case e_aes:
  1319 + use_aes = true;
  1320 + break;
  1321 +
  1322 + case e_aesv3:
  1323 + use_aes = true;
  1324 + break;
  1325 +
  1326 + case e_rc4:
  1327 + break;
  1328 +
  1329 + default:
  1330 + // filter local to this stream.
  1331 + qpdf_for_warning.warn(
1332 QPDFExc(qpdf_e_damaged_pdf, file->getName(), 1332 QPDFExc(qpdf_e_damaged_pdf, file->getName(),
1333 "", file->getLastOffset(), 1333 "", file->getLastOffset(),
1334 "unknown encryption filter for streams" 1334 "unknown encryption filter for streams"
1335 " (check " + method_source + ");" 1335 " (check " + method_source + ");"
1336 " streams may be decrypted improperly")); 1336 " streams may be decrypted improperly"));
1337 - // To avoid repeated warnings, reset cf_stream. Assume  
1338 - // we'd want to use AES if V == 4.  
1339 - encp->cf_stream = e_aes; 1337 + // To avoid repeated warnings, reset cf_stream. Assume
  1338 + // we'd want to use AES if V == 4.
  1339 + encp->cf_stream = e_aes;
1340 use_aes = true; 1340 use_aes = true;
1341 - break;  
1342 - } 1341 + break;
  1342 + }
1343 } 1343 }
1344 std::string key = getKeyForObject(encp, objid, generation, use_aes); 1344 std::string key = getKeyForObject(encp, objid, generation, use_aes);
1345 std::shared_ptr<Pipeline> new_pipeline; 1345 std::shared_ptr<Pipeline> new_pipeline;
1346 if (use_aes) 1346 if (use_aes)
1347 { 1347 {
1348 - QTC::TC("qpdf", "QPDF_encryption aes decode stream");  
1349 - new_pipeline = std::make_shared<Pl_AES_PDF>( 1348 + QTC::TC("qpdf", "QPDF_encryption aes decode stream");
  1349 + new_pipeline = std::make_shared<Pl_AES_PDF>(
1350 "AES stream decryption", pipeline, 1350 "AES stream decryption", pipeline,
1351 false, QUtil::unsigned_char_pointer(key), 1351 false, QUtil::unsigned_char_pointer(key),
1352 key.length()); 1352 key.length());
1353 } 1353 }
1354 else 1354 else
1355 { 1355 {
1356 - QTC::TC("qpdf", "QPDF_encryption rc4 decode stream");  
1357 - new_pipeline = std::make_shared<Pl_RC4>( 1356 + QTC::TC("qpdf", "QPDF_encryption rc4 decode stream");
  1357 + new_pipeline = std::make_shared<Pl_RC4>(
1358 "RC4 stream decryption", pipeline, 1358 "RC4 stream decryption", pipeline,
1359 QUtil::unsigned_char_pointer(key), 1359 QUtil::unsigned_char_pointer(key),
1360 toI(key.length())); 1360 toI(key.length()));
@@ -1371,8 +1371,8 @@ QPDF::compute_encryption_O_U( @@ -1371,8 +1371,8 @@ QPDF::compute_encryption_O_U(
1371 { 1371 {
1372 if (V >= 5) 1372 if (V >= 5)
1373 { 1373 {
1374 - throw std::logic_error(  
1375 - "compute_encryption_O_U called for file with V >= 5"); 1374 + throw std::logic_error(
  1375 + "compute_encryption_O_U called for file with V >= 5");
1376 } 1376 }
1377 EncryptionData data(V, R, key_len, P, "", "", "", "", "", 1377 EncryptionData data(V, R, key_len, P, "", "", "", "", "",
1378 id1, encrypt_metadata); 1378 id1, encrypt_metadata);
@@ -1444,22 +1444,22 @@ QPDF::isEncrypted(int&amp; R, int&amp; P, int&amp; V, @@ -1444,22 +1444,22 @@ QPDF::isEncrypted(int&amp; R, int&amp; P, int&amp; V,
1444 { 1444 {
1445 if (this->m->encp->encrypted) 1445 if (this->m->encp->encrypted)
1446 { 1446 {
1447 - QPDFObjectHandle trailer = getTrailer();  
1448 - QPDFObjectHandle encrypt = trailer.getKey("/Encrypt");  
1449 - QPDFObjectHandle Pkey = encrypt.getKey("/P");  
1450 - QPDFObjectHandle Rkey = encrypt.getKey("/R"); 1447 + QPDFObjectHandle trailer = getTrailer();
  1448 + QPDFObjectHandle encrypt = trailer.getKey("/Encrypt");
  1449 + QPDFObjectHandle Pkey = encrypt.getKey("/P");
  1450 + QPDFObjectHandle Rkey = encrypt.getKey("/R");
1451 QPDFObjectHandle Vkey = encrypt.getKey("/V"); 1451 QPDFObjectHandle Vkey = encrypt.getKey("/V");
1452 - P = static_cast<int>(Pkey.getIntValue());  
1453 - R = Rkey.getIntValueAsInt(); 1452 + P = static_cast<int>(Pkey.getIntValue());
  1453 + R = Rkey.getIntValueAsInt();
1454 V = Vkey.getIntValueAsInt(); 1454 V = Vkey.getIntValueAsInt();
1455 stream_method = this->m->encp->cf_stream; 1455 stream_method = this->m->encp->cf_stream;
1456 string_method = this->m->encp->cf_string; 1456 string_method = this->m->encp->cf_string;
1457 file_method = this->m->encp->cf_file; 1457 file_method = this->m->encp->cf_file;
1458 - return true; 1458 + return true;
1459 } 1459 }
1460 else 1460 else
1461 { 1461 {
1462 - return false; 1462 + return false;
1463 } 1463 }
1464 } 1464 }
1465 1465
@@ -1490,14 +1490,14 @@ QPDF::allowAccessibility() @@ -1490,14 +1490,14 @@ QPDF::allowAccessibility()
1490 bool status = true; 1490 bool status = true;
1491 if (isEncrypted(R, P)) 1491 if (isEncrypted(R, P))
1492 { 1492 {
1493 - if (R < 3)  
1494 - {  
1495 - status = is_bit_set(P, 5);  
1496 - }  
1497 - else  
1498 - {  
1499 - status = is_bit_set(P, 10);  
1500 - } 1493 + if (R < 3)
  1494 + {
  1495 + status = is_bit_set(P, 5);
  1496 + }
  1497 + else
  1498 + {
  1499 + status = is_bit_set(P, 10);
  1500 + }
1501 } 1501 }
1502 return status; 1502 return status;
1503 } 1503 }
@@ -1510,7 +1510,7 @@ QPDF::allowExtractAll() @@ -1510,7 +1510,7 @@ QPDF::allowExtractAll()
1510 bool status = true; 1510 bool status = true;
1511 if (isEncrypted(R, P)) 1511 if (isEncrypted(R, P))
1512 { 1512 {
1513 - status = is_bit_set(P, 5); 1513 + status = is_bit_set(P, 5);
1514 } 1514 }
1515 return status; 1515 return status;
1516 } 1516 }
@@ -1523,7 +1523,7 @@ QPDF::allowPrintLowRes() @@ -1523,7 +1523,7 @@ QPDF::allowPrintLowRes()
1523 bool status = true; 1523 bool status = true;
1524 if (isEncrypted(R, P)) 1524 if (isEncrypted(R, P))
1525 { 1525 {
1526 - status = is_bit_set(P, 3); 1526 + status = is_bit_set(P, 3);
1527 } 1527 }
1528 return status; 1528 return status;
1529 } 1529 }
@@ -1536,11 +1536,11 @@ QPDF::allowPrintHighRes() @@ -1536,11 +1536,11 @@ QPDF::allowPrintHighRes()
1536 bool status = true; 1536 bool status = true;
1537 if (isEncrypted(R, P)) 1537 if (isEncrypted(R, P))
1538 { 1538 {
1539 - status = is_bit_set(P, 3);  
1540 - if ((R >= 3) && (! is_bit_set(P, 12)))  
1541 - {  
1542 - status = false;  
1543 - } 1539 + status = is_bit_set(P, 3);
  1540 + if ((R >= 3) && (! is_bit_set(P, 12)))
  1541 + {
  1542 + status = false;
  1543 + }
1544 } 1544 }
1545 return status; 1545 return status;
1546 } 1546 }
@@ -1553,14 +1553,14 @@ QPDF::allowModifyAssembly() @@ -1553,14 +1553,14 @@ QPDF::allowModifyAssembly()
1553 bool status = true; 1553 bool status = true;
1554 if (isEncrypted(R, P)) 1554 if (isEncrypted(R, P))
1555 { 1555 {
1556 - if (R < 3)  
1557 - {  
1558 - status = is_bit_set(P, 4);  
1559 - }  
1560 - else  
1561 - {  
1562 - status = is_bit_set(P, 11);  
1563 - } 1556 + if (R < 3)
  1557 + {
  1558 + status = is_bit_set(P, 4);
  1559 + }
  1560 + else
  1561 + {
  1562 + status = is_bit_set(P, 11);
  1563 + }
1564 } 1564 }
1565 return status; 1565 return status;
1566 } 1566 }
@@ -1573,14 +1573,14 @@ QPDF::allowModifyForm() @@ -1573,14 +1573,14 @@ QPDF::allowModifyForm()
1573 bool status = true; 1573 bool status = true;
1574 if (isEncrypted(R, P)) 1574 if (isEncrypted(R, P))
1575 { 1575 {
1576 - if (R < 3)  
1577 - {  
1578 - status = is_bit_set(P, 6);  
1579 - }  
1580 - else  
1581 - {  
1582 - status = is_bit_set(P, 9);  
1583 - } 1576 + if (R < 3)
  1577 + {
  1578 + status = is_bit_set(P, 6);
  1579 + }
  1580 + else
  1581 + {
  1582 + status = is_bit_set(P, 9);
  1583 + }
1584 } 1584 }
1585 return status; 1585 return status;
1586 } 1586 }
@@ -1593,7 +1593,7 @@ QPDF::allowModifyAnnotation() @@ -1593,7 +1593,7 @@ QPDF::allowModifyAnnotation()
1593 bool status = true; 1593 bool status = true;
1594 if (isEncrypted(R, P)) 1594 if (isEncrypted(R, P))
1595 { 1595 {
1596 - status = is_bit_set(P, 6); 1596 + status = is_bit_set(P, 6);
1597 } 1597 }
1598 return status; 1598 return status;
1599 } 1599 }
@@ -1606,7 +1606,7 @@ QPDF::allowModifyOther() @@ -1606,7 +1606,7 @@ QPDF::allowModifyOther()
1606 bool status = true; 1606 bool status = true;
1607 if (isEncrypted(R, P)) 1607 if (isEncrypted(R, P))
1608 { 1608 {
1609 - status = is_bit_set(P, 4); 1609 + status = is_bit_set(P, 4);
1610 } 1610 }
1611 return status; 1611 return status;
1612 } 1612 }
@@ -1619,11 +1619,11 @@ QPDF::allowModifyAll() @@ -1619,11 +1619,11 @@ QPDF::allowModifyAll()
1619 bool status = true; 1619 bool status = true;
1620 if (isEncrypted(R, P)) 1620 if (isEncrypted(R, P))
1621 { 1621 {
1622 - status = (is_bit_set(P, 4) && is_bit_set(P, 6));  
1623 - if (R >= 3)  
1624 - {  
1625 - status = status && (is_bit_set(P, 9) && is_bit_set(P, 11));  
1626 - } 1622 + status = (is_bit_set(P, 4) && is_bit_set(P, 6));
  1623 + if (R >= 3)
  1624 + {
  1625 + status = status && (is_bit_set(P, 9) && is_bit_set(P, 11));
  1626 + }
1627 } 1627 }
1628 return status; 1628 return status;
1629 } 1629 }
libqpdf/QPDF_linearization.cc
@@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
20 template <class T, class int_type> 20 template <class T, class int_type>
21 static void 21 static void
22 load_vector_int(BitStream& bit_stream, int nitems, std::vector<T>& vec, 22 load_vector_int(BitStream& bit_stream, int nitems, std::vector<T>& vec,
23 - int bits_wanted, int_type T::*field) 23 + int bits_wanted, int_type T::*field)
24 { 24 {
25 bool append = vec.empty(); 25 bool append = vec.empty();
26 // nitems times, read bits_wanted from the given bit stream, 26 // nitems times, read bits_wanted from the given bit stream,
@@ -32,7 +32,7 @@ load_vector_int(BitStream&amp; bit_stream, int nitems, std::vector&lt;T&gt;&amp; vec, @@ -32,7 +32,7 @@ load_vector_int(BitStream&amp; bit_stream, int nitems, std::vector&lt;T&gt;&amp; vec,
32 { 32 {
33 vec.push_back(T()); 33 vec.push_back(T());
34 } 34 }
35 - vec.at(i).*field = bit_stream.getBitsInt(QIntC::to_size(bits_wanted)); 35 + vec.at(i).*field = bit_stream.getBitsInt(QIntC::to_size(bits_wanted));
36 } 36 }
37 if (QIntC::to_int(vec.size()) != nitems) 37 if (QIntC::to_int(vec.size()) != nitems)
38 { 38 {
@@ -46,18 +46,18 @@ load_vector_int(BitStream&amp; bit_stream, int nitems, std::vector&lt;T&gt;&amp; vec, @@ -46,18 +46,18 @@ load_vector_int(BitStream&amp; bit_stream, int nitems, std::vector&lt;T&gt;&amp; vec,
46 template <class T> 46 template <class T>
47 static void 47 static void
48 load_vector_vector(BitStream& bit_stream, 48 load_vector_vector(BitStream& bit_stream,
49 - int nitems1, std::vector<T>& vec1, int T::*nitems2,  
50 - int bits_wanted, std::vector<int> T::*vec2) 49 + int nitems1, std::vector<T>& vec1, int T::*nitems2,
  50 + int bits_wanted, std::vector<int> T::*vec2)
51 { 51 {
52 // nitems1 times, read nitems2 (from the ith element of vec1) items 52 // nitems1 times, read nitems2 (from the ith element of vec1) items
53 // into the vec2 vector field of the ith item of vec1. 53 // into the vec2 vector field of the ith item of vec1.
54 for (size_t i1 = 0; i1 < QIntC::to_size(nitems1); ++i1) 54 for (size_t i1 = 0; i1 < QIntC::to_size(nitems1); ++i1)
55 { 55 {
56 - for (int i2 = 0; i2 < vec1.at(i1).*nitems2; ++i2)  
57 - {  
58 - (vec1.at(i1).*vec2).push_back( 56 + for (int i2 = 0; i2 < vec1.at(i1).*nitems2; ++i2)
  57 + {
  58 + (vec1.at(i1).*vec2).push_back(
59 bit_stream.getBitsInt(QIntC::to_size(bits_wanted))); 59 bit_stream.getBitsInt(QIntC::to_size(bits_wanted)));
60 - } 60 + }
61 } 61 }
62 bit_stream.skipToNextByte(); 62 bit_stream.skipToNextByte();
63 } 63 }
@@ -68,12 +68,12 @@ QPDF::checkLinearization() @@ -68,12 +68,12 @@ QPDF::checkLinearization()
68 bool result = false; 68 bool result = false;
69 try 69 try
70 { 70 {
71 - readLinearizationData();  
72 - result = checkLinearizationInternal(); 71 + readLinearizationData();
  72 + result = checkLinearizationInternal();
73 } 73 }
74 catch (std::runtime_error& e) 74 catch (std::runtime_error& e)
75 { 75 {
76 - *this->m->err_stream 76 + *this->m->err_stream
77 << "WARNING: error encountered while checking linearization data: " 77 << "WARNING: error encountered while checking linearization data: "
78 << e.what() << std::endl; 78 << e.what() << std::endl;
79 } 79 }
@@ -133,44 +133,44 @@ QPDF::isLinearized() @@ -133,44 +133,44 @@ QPDF::isLinearized()
133 (t3 == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "obj")) && 133 (t3 == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "obj")) &&
134 (t4.getType() == QPDFTokenizer::tt_dict_open)) 134 (t4.getType() == QPDFTokenizer::tt_dict_open))
135 { 135 {
136 - lindict_obj = 136 + lindict_obj =
137 QIntC::to_int(QUtil::string_to_ll(t1.getValue().c_str())); 137 QIntC::to_int(QUtil::string_to_ll(t1.getValue().c_str()));
138 - } 138 + }
139 } 139 }
140 140
141 if (lindict_obj <= 0) 141 if (lindict_obj <= 0)
142 { 142 {
143 - return false; 143 + return false;
144 } 144 }
145 145
146 QPDFObjectHandle candidate = QPDFObjectHandle::Factory::newIndirect( 146 QPDFObjectHandle candidate = QPDFObjectHandle::Factory::newIndirect(
147 - this, lindict_obj, 0); 147 + this, lindict_obj, 0);
148 if (! candidate.isDictionary()) 148 if (! candidate.isDictionary())
149 { 149 {
150 - return false; 150 + return false;
151 } 151 }
152 152
153 QPDFObjectHandle linkey = candidate.getKey("/Linearized"); 153 QPDFObjectHandle linkey = candidate.getKey("/Linearized");
154 if (! (linkey.isNumber() && 154 if (! (linkey.isNumber() &&
155 (QIntC::to_int(floor(linkey.getNumericValue())) == 1))) 155 (QIntC::to_int(floor(linkey.getNumericValue())) == 1)))
156 { 156 {
157 - return false; 157 + return false;
158 } 158 }
159 159
160 QPDFObjectHandle L = candidate.getKey("/L"); 160 QPDFObjectHandle L = candidate.getKey("/L");
161 if (L.isInteger()) 161 if (L.isInteger())
162 { 162 {
163 - qpdf_offset_t Li = L.getIntValue();  
164 - this->m->file->seek(0, SEEK_END);  
165 - if (Li != this->m->file->tell())  
166 - {  
167 - QTC::TC("qpdf", "QPDF /L mismatch");  
168 - return false;  
169 - }  
170 - else  
171 - {  
172 - this->m->linp.file_size = Li;  
173 - } 163 + qpdf_offset_t Li = L.getIntValue();
  164 + this->m->file->seek(0, SEEK_END);
  165 + if (Li != this->m->file->tell())
  166 + {
  167 + QTC::TC("qpdf", "QPDF /L mismatch");
  168 + return false;
  169 + }
  170 + else
  171 + {
  172 + this->m->linp.file_size = Li;
  173 + }
174 } 174 }
175 175
176 this->m->lindict = candidate; 176 this->m->lindict = candidate;
@@ -189,8 +189,8 @@ QPDF::readLinearizationData() @@ -189,8 +189,8 @@ QPDF::readLinearizationData()
189 189
190 if (! isLinearized()) 190 if (! isLinearized())
191 { 191 {
192 - throw std::logic_error("called readLinearizationData for file"  
193 - " that is not linearized"); 192 + throw std::logic_error("called readLinearizationData for file"
  193 + " that is not linearized");
194 } 194 }
195 195
196 // /L is read and stored in linp by isLinearized() 196 // /L is read and stored in linp by isLinearized()
@@ -202,44 +202,44 @@ QPDF::readLinearizationData() @@ -202,44 +202,44 @@ QPDF::readLinearizationData()
202 QPDFObjectHandle P = this->m->lindict.getKey("/P"); 202 QPDFObjectHandle P = this->m->lindict.getKey("/P");
203 203
204 if (! (H.isArray() && 204 if (! (H.isArray() &&
205 - O.isInteger() &&  
206 - E.isInteger() &&  
207 - N.isInteger() &&  
208 - T.isInteger() &&  
209 - (P.isInteger() || P.isNull()))) 205 + O.isInteger() &&
  206 + E.isInteger() &&
  207 + N.isInteger() &&
  208 + T.isInteger() &&
  209 + (P.isInteger() || P.isNull())))
210 { 210 {
211 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
212 - "linearization dictionary",  
213 - this->m->file->getLastOffset(),  
214 - "some keys in linearization dictionary are of "  
215 - "the wrong type"); 211 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  212 + "linearization dictionary",
  213 + this->m->file->getLastOffset(),
  214 + "some keys in linearization dictionary are of "
  215 + "the wrong type");
216 } 216 }
217 217
218 // Hint table array: offset length [ offset length ] 218 // Hint table array: offset length [ offset length ]
219 size_t n_H_items = toS(H.getArrayNItems()); 219 size_t n_H_items = toS(H.getArrayNItems());
220 if (! ((n_H_items == 2) || (n_H_items == 4))) 220 if (! ((n_H_items == 2) || (n_H_items == 4)))
221 { 221 {
222 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
223 - "linearization dictionary",  
224 - this->m->file->getLastOffset(),  
225 - "H has the wrong number of items"); 222 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  223 + "linearization dictionary",
  224 + this->m->file->getLastOffset(),
  225 + "H has the wrong number of items");
226 } 226 }
227 227
228 std::vector<int> H_items; 228 std::vector<int> H_items;
229 for (size_t i = 0; i < n_H_items; ++i) 229 for (size_t i = 0; i < n_H_items; ++i)
230 { 230 {
231 - QPDFObjectHandle oh(H.getArrayItem(toI(i)));  
232 - if (oh.isInteger())  
233 - {  
234 - H_items.push_back(oh.getIntValueAsInt());  
235 - }  
236 - else  
237 - {  
238 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
239 - "linearization dictionary",  
240 - this->m->file->getLastOffset(),  
241 - "some H items are of the wrong type");  
242 - } 231 + QPDFObjectHandle oh(H.getArrayItem(toI(i)));
  232 + if (oh.isInteger())
  233 + {
  234 + H_items.push_back(oh.getIntValueAsInt());
  235 + }
  236 + else
  237 + {
  238 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  239 + "linearization dictionary",
  240 + this->m->file->getLastOffset(),
  241 + "some H items are of the wrong type");
  242 + }
243 } 243 }
244 244
245 // H: hint table offset/length for primary and overflow hint tables 245 // H: hint table offset/length for primary and overflow hint tables
@@ -249,23 +249,23 @@ QPDF::readLinearizationData() @@ -249,23 +249,23 @@ QPDF::readLinearizationData()
249 int H1_length = 0; 249 int H1_length = 0;
250 if (H_items.size() == 4) 250 if (H_items.size() == 4)
251 { 251 {
252 - // Acrobat doesn't read or write these (as PDF 1.4), so we  
253 - // don't have a way to generate a test case.  
254 - // QTC::TC("qpdf", "QPDF overflow hint table");  
255 - H1_offset = H_items.at(2);  
256 - H1_length = H_items.at(3); 252 + // Acrobat doesn't read or write these (as PDF 1.4), so we
  253 + // don't have a way to generate a test case.
  254 + // QTC::TC("qpdf", "QPDF overflow hint table");
  255 + H1_offset = H_items.at(2);
  256 + H1_length = H_items.at(3);
257 } 257 }
258 258
259 // P: first page number 259 // P: first page number
260 int first_page = 0; 260 int first_page = 0;
261 if (P.isInteger()) 261 if (P.isInteger())
262 { 262 {
263 - QTC::TC("qpdf", "QPDF P present in lindict");  
264 - first_page = P.getIntValueAsInt(); 263 + QTC::TC("qpdf", "QPDF P present in lindict");
  264 + first_page = P.getIntValueAsInt();
265 } 265 }
266 else 266 else
267 { 267 {
268 - QTC::TC("qpdf", "QPDF P absent in lindict"); 268 + QTC::TC("qpdf", "QPDF P absent in lindict");
269 } 269 }
270 270
271 // Store linearization parameter data 271 // Store linearization parameter data
@@ -296,7 +296,7 @@ QPDF::readLinearizationData() @@ -296,7 +296,7 @@ QPDF::readLinearizationData()
296 QPDFObjectHandle H0 = readHintStream(pb, H0_offset, toS(H0_length)); 296 QPDFObjectHandle H0 = readHintStream(pb, H0_offset, toS(H0_length));
297 if (H1_offset) 297 if (H1_offset)
298 { 298 {
299 - (void) readHintStream(pb, H1_offset, toS(H1_length)); 299 + (void) readHintStream(pb, H1_offset, toS(H1_length));
300 } 300 }
301 301
302 // PDF 1.4 hint tables that we ignore: 302 // PDF 1.4 hint tables that we ignore:
@@ -332,7 +332,7 @@ QPDF::readLinearizationData() @@ -332,7 +332,7 @@ QPDF::readLinearizationData()
332 332
333 if (HO.isInteger()) 333 if (HO.isInteger())
334 { 334 {
335 - int HOi = HO.getIntValueAsInt(); 335 + int HOi = HO.getIntValueAsInt();
336 if ((HOi < 0) || (toS(HOi) >= h_size)) 336 if ((HOi < 0) || (toS(HOi) >= h_size))
337 { 337 {
338 throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), 338 throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
@@ -340,8 +340,8 @@ QPDF::readLinearizationData() @@ -340,8 +340,8 @@ QPDF::readLinearizationData()
340 this->m->file->getLastOffset(), 340 this->m->file->getLastOffset(),
341 "/O (outline) offset is out of bounds"); 341 "/O (outline) offset is out of bounds");
342 } 342 }
343 - readHGeneric(BitStream(h_buf + HOi, h_size - toS(HOi)),  
344 - this->m->outline_hints); 343 + readHGeneric(BitStream(h_buf + HOi, h_size - toS(HOi)),
  344 + this->m->outline_hints);
345 } 345 }
346 } 346 }
347 347
@@ -351,16 +351,16 @@ QPDF::readHintStream(Pipeline&amp; pl, qpdf_offset_t offset, size_t length) @@ -351,16 +351,16 @@ QPDF::readHintStream(Pipeline&amp; pl, qpdf_offset_t offset, size_t length)
351 int obj; 351 int obj;
352 int gen; 352 int gen;
353 QPDFObjectHandle H = readObjectAtOffset( 353 QPDFObjectHandle H = readObjectAtOffset(
354 - false, offset, "linearization hint stream", -1, 0, obj, gen); 354 + false, offset, "linearization hint stream", -1, 0, obj, gen);
355 ObjCache& oc = this->m->obj_cache[QPDFObjGen(obj, gen)]; 355 ObjCache& oc = this->m->obj_cache[QPDFObjGen(obj, gen)];
356 qpdf_offset_t min_end_offset = oc.end_before_space; 356 qpdf_offset_t min_end_offset = oc.end_before_space;
357 qpdf_offset_t max_end_offset = oc.end_after_space; 357 qpdf_offset_t max_end_offset = oc.end_after_space;
358 if (! H.isStream()) 358 if (! H.isStream())
359 { 359 {
360 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
361 - "linearization dictionary",  
362 - this->m->file->getLastOffset(),  
363 - "hint table is not a stream"); 360 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  361 + "linearization dictionary",
  362 + this->m->file->getLastOffset(),
  363 + "hint table is not a stream");
364 } 364 }
365 365
366 QPDFObjectHandle Hdict = H.getDict(); 366 QPDFObjectHandle Hdict = H.getDict();
@@ -373,28 +373,28 @@ QPDF::readHintStream(Pipeline&amp; pl, qpdf_offset_t offset, size_t length) @@ -373,28 +373,28 @@ QPDF::readHintStream(Pipeline&amp; pl, qpdf_offset_t offset, size_t length)
373 QPDFObjectHandle length_obj = Hdict.getKey("/Length"); 373 QPDFObjectHandle length_obj = Hdict.getKey("/Length");
374 if (length_obj.isIndirect()) 374 if (length_obj.isIndirect())
375 { 375 {
376 - QTC::TC("qpdf", "QPDF hint table length indirect");  
377 - // Force resolution  
378 - (void) length_obj.getIntValue();  
379 - ObjCache& oc2 = this->m->obj_cache[length_obj.getObjGen()];  
380 - min_end_offset = oc2.end_before_space;  
381 - max_end_offset = oc2.end_after_space; 376 + QTC::TC("qpdf", "QPDF hint table length indirect");
  377 + // Force resolution
  378 + (void) length_obj.getIntValue();
  379 + ObjCache& oc2 = this->m->obj_cache[length_obj.getObjGen()];
  380 + min_end_offset = oc2.end_before_space;
  381 + max_end_offset = oc2.end_after_space;
382 } 382 }
383 else 383 else
384 { 384 {
385 - QTC::TC("qpdf", "QPDF hint table length direct"); 385 + QTC::TC("qpdf", "QPDF hint table length direct");
386 } 386 }
387 qpdf_offset_t computed_end = offset + toO(length); 387 qpdf_offset_t computed_end = offset + toO(length);
388 if ((computed_end < min_end_offset) || 388 if ((computed_end < min_end_offset) ||
389 - (computed_end > max_end_offset)) 389 + (computed_end > max_end_offset))
390 { 390 {
391 - *this->m->err_stream << "expected = " << computed_end 391 + *this->m->err_stream << "expected = " << computed_end
392 << "; actual = " << min_end_offset << ".." 392 << "; actual = " << min_end_offset << ".."
393 << max_end_offset << std::endl; 393 << max_end_offset << std::endl;
394 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
395 - "linearization dictionary",  
396 - this->m->file->getLastOffset(),  
397 - "hint table length mismatch"); 394 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  395 + "linearization dictionary",
  396 + this->m->file->getLastOffset(),
  397 + "hint table length mismatch");
398 } 398 }
399 H.pipeStreamData(&pl, 0, qpdf_dl_specialized); 399 H.pipeStreamData(&pl, 0, qpdf_dl_specialized);
400 return Hdict; 400 return Hdict;
@@ -426,28 +426,28 @@ QPDF::readHPageOffset(BitStream h) @@ -426,28 +426,28 @@ QPDF::readHPageOffset(BitStream h)
426 entries.clear(); 426 entries.clear();
427 int nitems = this->m->linp.npages; 427 int nitems = this->m->linp.npages;
428 load_vector_int(h, nitems, entries, 428 load_vector_int(h, nitems, entries,
429 - t.nbits_delta_nobjects,  
430 - &HPageOffsetEntry::delta_nobjects); 429 + t.nbits_delta_nobjects,
  430 + &HPageOffsetEntry::delta_nobjects);
431 load_vector_int(h, nitems, entries, 431 load_vector_int(h, nitems, entries,
432 - t.nbits_delta_page_length,  
433 - &HPageOffsetEntry::delta_page_length); 432 + t.nbits_delta_page_length,
  433 + &HPageOffsetEntry::delta_page_length);
434 load_vector_int(h, nitems, entries, 434 load_vector_int(h, nitems, entries,
435 - t.nbits_nshared_objects,  
436 - &HPageOffsetEntry::nshared_objects); 435 + t.nbits_nshared_objects,
  436 + &HPageOffsetEntry::nshared_objects);
437 load_vector_vector(h, nitems, entries, 437 load_vector_vector(h, nitems, entries,
438 - &HPageOffsetEntry::nshared_objects,  
439 - t.nbits_shared_identifier,  
440 - &HPageOffsetEntry::shared_identifiers); 438 + &HPageOffsetEntry::nshared_objects,
  439 + t.nbits_shared_identifier,
  440 + &HPageOffsetEntry::shared_identifiers);
441 load_vector_vector(h, nitems, entries, 441 load_vector_vector(h, nitems, entries,
442 - &HPageOffsetEntry::nshared_objects,  
443 - t.nbits_shared_numerator,  
444 - &HPageOffsetEntry::shared_numerators); 442 + &HPageOffsetEntry::nshared_objects,
  443 + t.nbits_shared_numerator,
  444 + &HPageOffsetEntry::shared_numerators);
445 load_vector_int(h, nitems, entries, 445 load_vector_int(h, nitems, entries,
446 - t.nbits_delta_content_offset,  
447 - &HPageOffsetEntry::delta_content_offset); 446 + t.nbits_delta_content_offset,
  447 + &HPageOffsetEntry::delta_content_offset);
448 load_vector_int(h, nitems, entries, 448 load_vector_int(h, nitems, entries,
449 - t.nbits_delta_content_length,  
450 - &HPageOffsetEntry::delta_content_length); 449 + t.nbits_delta_content_length,
  450 + &HPageOffsetEntry::delta_content_length);
451 } 451 }
452 452
453 void 453 void
@@ -464,32 +464,32 @@ QPDF::readHSharedObject(BitStream h) @@ -464,32 +464,32 @@ QPDF::readHSharedObject(BitStream h)
464 t.nbits_delta_group_length = h.getBitsInt(16); // 7 464 t.nbits_delta_group_length = h.getBitsInt(16); // 7
465 465
466 QTC::TC("qpdf", "QPDF lin nshared_total > nshared_first_page", 466 QTC::TC("qpdf", "QPDF lin nshared_total > nshared_first_page",
467 - (t.nshared_total > t.nshared_first_page) ? 1 : 0); 467 + (t.nshared_total > t.nshared_first_page) ? 1 : 0);
468 468
469 std::vector<HSharedObjectEntry>& entries = t.entries; 469 std::vector<HSharedObjectEntry>& entries = t.entries;
470 entries.clear(); 470 entries.clear();
471 int nitems = t.nshared_total; 471 int nitems = t.nshared_total;
472 load_vector_int(h, nitems, entries, 472 load_vector_int(h, nitems, entries,
473 - t.nbits_delta_group_length,  
474 - &HSharedObjectEntry::delta_group_length); 473 + t.nbits_delta_group_length,
  474 + &HSharedObjectEntry::delta_group_length);
475 load_vector_int(h, nitems, entries, 475 load_vector_int(h, nitems, entries,
476 - 1, &HSharedObjectEntry::signature_present); 476 + 1, &HSharedObjectEntry::signature_present);
477 for (size_t i = 0; i < toS(nitems); ++i) 477 for (size_t i = 0; i < toS(nitems); ++i)
478 { 478 {
479 - if (entries.at(i).signature_present)  
480 - {  
481 - // Skip 128-bit MD5 hash. These are not supported by  
482 - // acrobat, so they should probably never be there. We  
483 - // have no test case for this.  
484 - for (int j = 0; j < 4; ++j)  
485 - {  
486 - (void) h.getBits(32);  
487 - }  
488 - } 479 + if (entries.at(i).signature_present)
  480 + {
  481 + // Skip 128-bit MD5 hash. These are not supported by
  482 + // acrobat, so they should probably never be there. We
  483 + // have no test case for this.
  484 + for (int j = 0; j < 4; ++j)
  485 + {
  486 + (void) h.getBits(32);
  487 + }
  488 + }
489 } 489 }
490 load_vector_int(h, nitems, entries, 490 load_vector_int(h, nitems, entries,
491 - t.nbits_nobjects,  
492 - &HSharedObjectEntry::nobjects_minus_one); 491 + t.nbits_nobjects,
  492 + &HSharedObjectEntry::nobjects_minus_one);
493 } 493 }
494 494
495 void 495 void
@@ -520,49 +520,49 @@ QPDF::checkLinearizationInternal() @@ -520,49 +520,49 @@ QPDF::checkLinearizationInternal()
520 std::vector<QPDFObjectHandle> const& pages = getAllPages(); 520 std::vector<QPDFObjectHandle> const& pages = getAllPages();
521 if (p.first_page_object != pages.at(0).getObjectID()) 521 if (p.first_page_object != pages.at(0).getObjectID())
522 { 522 {
523 - QTC::TC("qpdf", "QPDF err /O mismatch");  
524 - errors.push_back("first page object (/O) mismatch"); 523 + QTC::TC("qpdf", "QPDF err /O mismatch");
  524 + errors.push_back("first page object (/O) mismatch");
525 } 525 }
526 526
527 // N: number of pages 527 // N: number of pages
528 int npages = toI(pages.size()); 528 int npages = toI(pages.size());
529 if (p.npages != npages) 529 if (p.npages != npages)
530 { 530 {
531 - // Not tested in the test suite  
532 - errors.push_back("page count (/N) mismatch"); 531 + // Not tested in the test suite
  532 + errors.push_back("page count (/N) mismatch");
533 } 533 }
534 534
535 for (size_t i = 0; i < toS(npages); ++i) 535 for (size_t i = 0; i < toS(npages); ++i)
536 { 536 {
537 - QPDFObjectHandle const& page = pages.at(i);  
538 - QPDFObjGen og(page.getObjGen());  
539 - if (this->m->xref_table[og].getType() == 2)  
540 - {  
541 - errors.push_back("page dictionary for page " +  
542 - QUtil::uint_to_string(i) + " is compressed");  
543 - } 537 + QPDFObjectHandle const& page = pages.at(i);
  538 + QPDFObjGen og(page.getObjGen());
  539 + if (this->m->xref_table[og].getType() == 2)
  540 + {
  541 + errors.push_back("page dictionary for page " +
  542 + QUtil::uint_to_string(i) + " is compressed");
  543 + }
544 } 544 }
545 545
546 // T: offset of whitespace character preceding xref entry for object 0 546 // T: offset of whitespace character preceding xref entry for object 0
547 this->m->file->seek(p.xref_zero_offset, SEEK_SET); 547 this->m->file->seek(p.xref_zero_offset, SEEK_SET);
548 while (1) 548 while (1)
549 { 549 {
550 - char ch;  
551 - this->m->file->read(&ch, 1);  
552 - if (! ((ch == ' ') || (ch == '\r') || (ch == '\n')))  
553 - {  
554 - this->m->file->seek(-1, SEEK_CUR);  
555 - break;  
556 - } 550 + char ch;
  551 + this->m->file->read(&ch, 1);
  552 + if (! ((ch == ' ') || (ch == '\r') || (ch == '\n')))
  553 + {
  554 + this->m->file->seek(-1, SEEK_CUR);
  555 + break;
  556 + }
557 } 557 }
558 if (this->m->file->tell() != this->m->first_xref_item_offset) 558 if (this->m->file->tell() != this->m->first_xref_item_offset)
559 { 559 {
560 - QTC::TC("qpdf", "QPDF err /T mismatch");  
561 - errors.push_back("space before first xref item (/T) mismatch "  
562 - "(computed = " +  
563 - QUtil::int_to_string(this->m->first_xref_item_offset) +  
564 - "; file = " +  
565 - QUtil::int_to_string(this->m->file->tell())); 560 + QTC::TC("qpdf", "QPDF err /T mismatch");
  561 + errors.push_back("space before first xref item (/T) mismatch "
  562 + "(computed = " +
  563 + QUtil::int_to_string(this->m->first_xref_item_offset) +
  564 + "; file = " +
  565 + QUtil::int_to_string(this->m->file->tell()));
566 } 566 }
567 567
568 // P: first page number -- Implementation note 124 says Acrobat 568 // P: first page number -- Implementation note 124 says Acrobat
@@ -575,8 +575,8 @@ QPDF::checkLinearizationInternal() @@ -575,8 +575,8 @@ QPDF::checkLinearizationInternal()
575 575
576 if (this->m->uncompressed_after_compressed) 576 if (this->m->uncompressed_after_compressed)
577 { 577 {
578 - errors.push_back("linearized file contains an uncompressed object"  
579 - " after a compressed one in a cross-reference stream"); 578 + errors.push_back("linearized file contains an uncompressed object"
  579 + " after a compressed one in a cross-reference stream");
580 } 580 }
581 581
582 // Further checking requires optimization and order calculation. 582 // Further checking requires optimization and order calculation.
@@ -585,20 +585,20 @@ QPDF::checkLinearizationInternal() @@ -585,20 +585,20 @@ QPDF::checkLinearizationInternal()
585 // figure out which objects are compressed and which are 585 // figure out which objects are compressed and which are
586 // uncompressed. 586 // uncompressed.
587 { // local scope 587 { // local scope
588 - std::map<int, int> object_stream_data;  
589 - for (std::map<QPDFObjGen, QPDFXRefEntry>::const_iterator iter =  
590 - this->m->xref_table.begin();  
591 - iter != this->m->xref_table.end(); ++iter)  
592 - {  
593 - QPDFObjGen const& og = (*iter).first;  
594 - QPDFXRefEntry const& entry = (*iter).second;  
595 - if (entry.getType() == 2)  
596 - {  
597 - object_stream_data[og.getObj()] = entry.getObjStreamNumber();  
598 - }  
599 - }  
600 - optimize(object_stream_data, false);  
601 - calculateLinearizationData(object_stream_data); 588 + std::map<int, int> object_stream_data;
  589 + for (std::map<QPDFObjGen, QPDFXRefEntry>::const_iterator iter =
  590 + this->m->xref_table.begin();
  591 + iter != this->m->xref_table.end(); ++iter)
  592 + {
  593 + QPDFObjGen const& og = (*iter).first;
  594 + QPDFXRefEntry const& entry = (*iter).second;
  595 + if (entry.getType() == 2)
  596 + {
  597 + object_stream_data[og.getObj()] = entry.getObjStreamNumber();
  598 + }
  599 + }
  600 + optimize(object_stream_data, false);
  601 + calculateLinearizationData(object_stream_data);
602 } 602 }
603 603
604 // E: offset of end of first page -- Implementation note 123 says 604 // E: offset of end of first page -- Implementation note 123 says
@@ -619,26 +619,26 @@ QPDF::checkLinearizationInternal() @@ -619,26 +619,26 @@ QPDF::checkLinearizationInternal()
619 qpdf_offset_t min_E = -1; 619 qpdf_offset_t min_E = -1;
620 qpdf_offset_t max_E = -1; 620 qpdf_offset_t max_E = -1;
621 for (std::vector<QPDFObjectHandle>::iterator iter = this->m->part6.begin(); 621 for (std::vector<QPDFObjectHandle>::iterator iter = this->m->part6.begin();
622 - iter != this->m->part6.end(); ++iter) 622 + iter != this->m->part6.end(); ++iter)
623 { 623 {
624 - QPDFObjGen og((*iter).getObjGen());  
625 - if (this->m->obj_cache.count(og) == 0) 624 + QPDFObjGen og((*iter).getObjGen());
  625 + if (this->m->obj_cache.count(og) == 0)
626 { 626 {
627 // All objects have to have been dereferenced to be classified. 627 // All objects have to have been dereferenced to be classified.
628 throw std::logic_error("linearization part6 object not in cache"); 628 throw std::logic_error("linearization part6 object not in cache");
629 } 629 }
630 - ObjCache const& oc = this->m->obj_cache[og];  
631 - min_E = std::max(min_E, oc.end_before_space);  
632 - max_E = std::max(max_E, oc.end_after_space); 630 + ObjCache const& oc = this->m->obj_cache[og];
  631 + min_E = std::max(min_E, oc.end_before_space);
  632 + max_E = std::max(max_E, oc.end_after_space);
633 } 633 }
634 if ((p.first_page_end < min_E) || (p.first_page_end > max_E)) 634 if ((p.first_page_end < min_E) || (p.first_page_end > max_E))
635 { 635 {
636 - QTC::TC("qpdf", "QPDF warn /E mismatch");  
637 - warnings.push_back("end of first page section (/E) mismatch: /E = " +  
638 - QUtil::int_to_string(p.first_page_end) +  
639 - "; computed = " +  
640 - QUtil::int_to_string(min_E) + ".." +  
641 - QUtil::int_to_string(max_E)); 636 + QTC::TC("qpdf", "QPDF warn /E mismatch");
  637 + warnings.push_back("end of first page section (/E) mismatch: /E = " +
  638 + QUtil::int_to_string(p.first_page_end) +
  639 + "; computed = " +
  640 + QUtil::int_to_string(min_E) + ".." +
  641 + QUtil::int_to_string(max_E));
642 } 642 }
643 643
644 // Check hint tables 644 // Check hint tables
@@ -659,22 +659,22 @@ QPDF::checkLinearizationInternal() @@ -659,22 +659,22 @@ QPDF::checkLinearizationInternal()
659 // code. 659 // code.
660 if (! errors.empty()) 660 if (! errors.empty())
661 { 661 {
662 - result = false;  
663 - for (std::list<std::string>::iterator iter = errors.begin();  
664 - iter != errors.end(); ++iter)  
665 - {  
666 - *this->m->err_stream << "WARNING: " << (*iter) << std::endl;  
667 - } 662 + result = false;
  663 + for (std::list<std::string>::iterator iter = errors.begin();
  664 + iter != errors.end(); ++iter)
  665 + {
  666 + *this->m->err_stream << "WARNING: " << (*iter) << std::endl;
  667 + }
668 } 668 }
669 669
670 if (! warnings.empty()) 670 if (! warnings.empty())
671 { 671 {
672 - result = false;  
673 - for (std::list<std::string>::iterator iter = warnings.begin();  
674 - iter != warnings.end(); ++iter)  
675 - {  
676 - *this->m->err_stream << "WARNING: " << (*iter) << std::endl;  
677 - } 672 + result = false;
  673 + for (std::list<std::string>::iterator iter = warnings.begin();
  674 + iter != warnings.end(); ++iter)
  675 + {
  676 + *this->m->err_stream << "WARNING: " << (*iter) << std::endl;
  677 + }
678 } 678 }
679 679
680 return result; 680 return result;
@@ -690,14 +690,14 @@ QPDF::maxEnd(ObjUser const&amp; ou) @@ -690,14 +690,14 @@ QPDF::maxEnd(ObjUser const&amp; ou)
690 std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou]; 690 std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou];
691 qpdf_offset_t end = 0; 691 qpdf_offset_t end = 0;
692 for (std::set<QPDFObjGen>::const_iterator iter = ogs.begin(); 692 for (std::set<QPDFObjGen>::const_iterator iter = ogs.begin();
693 - iter != ogs.end(); ++iter) 693 + iter != ogs.end(); ++iter)
694 { 694 {
695 - QPDFObjGen const& og = *iter;  
696 - if (this->m->obj_cache.count(og) == 0) 695 + QPDFObjGen const& og = *iter;
  696 + if (this->m->obj_cache.count(og) == 0)
697 { 697 {
698 stopOnError("unknown object referenced in object user table"); 698 stopOnError("unknown object referenced in object user table");
699 } 699 }
700 - end = std::max(end, this->m->obj_cache[og].end_after_space); 700 + end = std::max(end, this->m->obj_cache[og].end_after_space);
701 } 701 }
702 return end; 702 return end;
703 } 703 }
@@ -710,72 +710,72 @@ QPDF::getLinearizationOffset(QPDFObjGen const&amp; og) @@ -710,72 +710,72 @@ QPDF::getLinearizationOffset(QPDFObjGen const&amp; og)
710 switch (entry.getType()) 710 switch (entry.getType())
711 { 711 {
712 case 1: 712 case 1:
713 - result = entry.getOffset();  
714 - break; 713 + result = entry.getOffset();
  714 + break;
715 715
716 case 2: 716 case 2:
717 - // For compressed objects, return the offset of the object  
718 - // stream that contains them.  
719 - result = getLinearizationOffset( 717 + // For compressed objects, return the offset of the object
  718 + // stream that contains them.
  719 + result = getLinearizationOffset(
720 QPDFObjGen(entry.getObjStreamNumber(), 0)); 720 QPDFObjGen(entry.getObjStreamNumber(), 0));
721 - break; 721 + break;
722 722
723 default: 723 default:
724 - stopOnError(  
725 - "getLinearizationOffset called for xref entry not of type 1 or 2");  
726 - break; 724 + stopOnError(
  725 + "getLinearizationOffset called for xref entry not of type 1 or 2");
  726 + break;
727 } 727 }
728 return result; 728 return result;
729 } 729 }
730 730
731 QPDFObjectHandle 731 QPDFObjectHandle
732 QPDF::getUncompressedObject(QPDFObjectHandle& obj, 732 QPDF::getUncompressedObject(QPDFObjectHandle& obj,
733 - std::map<int, int> const& object_stream_data) 733 + std::map<int, int> const& object_stream_data)
734 { 734 {
735 if (obj.isNull() || (object_stream_data.count(obj.getObjectID()) == 0)) 735 if (obj.isNull() || (object_stream_data.count(obj.getObjectID()) == 0))
736 { 736 {
737 - return obj; 737 + return obj;
738 } 738 }
739 else 739 else
740 { 740 {
741 - int repl = (*(object_stream_data.find(obj.getObjectID()))).second;  
742 - return objGenToIndirect(QPDFObjGen(repl, 0)); 741 + int repl = (*(object_stream_data.find(obj.getObjectID()))).second;
  742 + return objGenToIndirect(QPDFObjGen(repl, 0));
743 } 743 }
744 } 744 }
745 745
746 int 746 int
747 QPDF::lengthNextN(int first_object, int n, 747 QPDF::lengthNextN(int first_object, int n,
748 - std::list<std::string>& errors) 748 + std::list<std::string>& errors)
749 { 749 {
750 int length = 0; 750 int length = 0;
751 for (int i = 0; i < n; ++i) 751 for (int i = 0; i < n; ++i)
752 { 752 {
753 - QPDFObjGen og(first_object + i, 0);  
754 - if (this->m->xref_table.count(og) == 0)  
755 - {  
756 - errors.push_back(  
757 - "no xref table entry for " +  
758 - QUtil::int_to_string(first_object + i) + " 0");  
759 - }  
760 - else  
761 - {  
762 - if (this->m->obj_cache.count(og) == 0) 753 + QPDFObjGen og(first_object + i, 0);
  754 + if (this->m->xref_table.count(og) == 0)
  755 + {
  756 + errors.push_back(
  757 + "no xref table entry for " +
  758 + QUtil::int_to_string(first_object + i) + " 0");
  759 + }
  760 + else
  761 + {
  762 + if (this->m->obj_cache.count(og) == 0)
763 { 763 {
764 stopOnError("found unknown object while" 764 stopOnError("found unknown object while"
765 " calculating length for linearization data"); 765 " calculating length for linearization data");
766 } 766 }
767 - length += toI(this->m->obj_cache[og].end_after_space - 767 + length += toI(this->m->obj_cache[og].end_after_space -
768 getLinearizationOffset(og)); 768 getLinearizationOffset(og));
769 - } 769 + }
770 } 770 }
771 return length; 771 return length;
772 } 772 }
773 773
774 void 774 void
775 QPDF::checkHPageOffset(std::list<std::string>& errors, 775 QPDF::checkHPageOffset(std::list<std::string>& errors,
776 - std::list<std::string>& warnings,  
777 - std::vector<QPDFObjectHandle> const& pages,  
778 - std::map<int, int>& shared_idx_to_obj) 776 + std::list<std::string>& warnings,
  777 + std::vector<QPDFObjectHandle> const& pages,
  778 + std::map<int, int>& shared_idx_to_obj)
779 { 779 {
780 // Implementation note 126 says Acrobat always sets 780 // Implementation note 126 says Acrobat always sets
781 // delta_content_offset and delta_content_length in the page 781 // delta_content_offset and delta_content_length in the page
@@ -796,7 +796,7 @@ QPDF::checkHPageOffset(std::list&lt;std::string&gt;&amp; errors, @@ -796,7 +796,7 @@ QPDF::checkHPageOffset(std::list&lt;std::string&gt;&amp; errors,
796 796
797 int npages = toI(pages.size()); 797 int npages = toI(pages.size());
798 qpdf_offset_t table_offset = adjusted_offset( 798 qpdf_offset_t table_offset = adjusted_offset(
799 - this->m->page_offset_hints.first_page_offset); 799 + this->m->page_offset_hints.first_page_offset);
800 QPDFObjGen first_page_og(pages.at(0).getObjGen()); 800 QPDFObjGen first_page_og(pages.at(0).getObjGen());
801 if (this->m->xref_table.count(first_page_og) == 0) 801 if (this->m->xref_table.count(first_page_og) == 0)
802 { 802 {
@@ -805,124 +805,124 @@ QPDF::checkHPageOffset(std::list&lt;std::string&gt;&amp; errors, @@ -805,124 +805,124 @@ QPDF::checkHPageOffset(std::list&lt;std::string&gt;&amp; errors,
805 qpdf_offset_t offset = getLinearizationOffset(first_page_og); 805 qpdf_offset_t offset = getLinearizationOffset(first_page_og);
806 if (table_offset != offset) 806 if (table_offset != offset)
807 { 807 {
808 - warnings.push_back("first page object offset mismatch"); 808 + warnings.push_back("first page object offset mismatch");
809 } 809 }
810 810
811 for (int pageno = 0; pageno < npages; ++pageno) 811 for (int pageno = 0; pageno < npages; ++pageno)
812 { 812 {
813 - QPDFObjGen page_og(pages.at(toS(pageno)).getObjGen());  
814 - int first_object = page_og.getObj();  
815 - if (this->m->xref_table.count(page_og) == 0) 813 + QPDFObjGen page_og(pages.at(toS(pageno)).getObjGen());
  814 + int first_object = page_og.getObj();
  815 + if (this->m->xref_table.count(page_og) == 0)
816 { 816 {
817 stopOnError("unknown object in page offset hint table"); 817 stopOnError("unknown object in page offset hint table");
818 } 818 }
819 - offset = getLinearizationOffset(page_og); 819 + offset = getLinearizationOffset(page_og);
820 820
821 - HPageOffsetEntry& he = 821 + HPageOffsetEntry& he =
822 this->m->page_offset_hints.entries.at(toS(pageno)); 822 this->m->page_offset_hints.entries.at(toS(pageno));
823 - CHPageOffsetEntry& ce = 823 + CHPageOffsetEntry& ce =
824 this->m->c_page_offset_data.entries.at(toS(pageno)); 824 this->m->c_page_offset_data.entries.at(toS(pageno));
825 - int h_nobjects = he.delta_nobjects +  
826 - this->m->page_offset_hints.min_nobjects;  
827 - if (h_nobjects != ce.nobjects)  
828 - {  
829 - // This happens with pdlin when there are thumbnails.  
830 - warnings.push_back(  
831 - "object count mismatch for page " +  
832 - QUtil::int_to_string(pageno) + ": hint table = " +  
833 - QUtil::int_to_string(h_nobjects) + "; computed = " +  
834 - QUtil::int_to_string(ce.nobjects));  
835 - }  
836 -  
837 - // Use value for number of objects in hint table rather than  
838 - // computed value if there is a discrepancy.  
839 - int length = lengthNextN(first_object, h_nobjects, errors);  
840 - int h_length = toI(he.delta_page_length + 825 + int h_nobjects = he.delta_nobjects +
  826 + this->m->page_offset_hints.min_nobjects;
  827 + if (h_nobjects != ce.nobjects)
  828 + {
  829 + // This happens with pdlin when there are thumbnails.
  830 + warnings.push_back(
  831 + "object count mismatch for page " +
  832 + QUtil::int_to_string(pageno) + ": hint table = " +
  833 + QUtil::int_to_string(h_nobjects) + "; computed = " +
  834 + QUtil::int_to_string(ce.nobjects));
  835 + }
  836 +
  837 + // Use value for number of objects in hint table rather than
  838 + // computed value if there is a discrepancy.
  839 + int length = lengthNextN(first_object, h_nobjects, errors);
  840 + int h_length = toI(he.delta_page_length +
841 this->m->page_offset_hints.min_page_length); 841 this->m->page_offset_hints.min_page_length);
842 - if (length != h_length)  
843 - {  
844 - // This condition almost certainly indicates a bad hint  
845 - // table or a bug in this code.  
846 - errors.push_back(  
847 - "page length mismatch for page " +  
848 - QUtil::int_to_string(pageno) + ": hint table = " +  
849 - QUtil::int_to_string(h_length) + "; computed length = " +  
850 - QUtil::int_to_string(length) + " (offset = " +  
851 - QUtil::int_to_string(offset) + ")");  
852 - }  
853 -  
854 - offset += h_length;  
855 -  
856 - // Translate shared object indexes to object numbers.  
857 - std::set<int> hint_shared;  
858 - std::set<int> computed_shared;  
859 -  
860 - if ((pageno == 0) && (he.nshared_objects > 0))  
861 - {  
862 - // pdlin and Acrobat both do this even though the spec  
863 - // states clearly and unambiguously that they should not.  
864 - warnings.push_back("page 0 has shared identifier entries");  
865 - }  
866 -  
867 - for (size_t i = 0; i < toS(he.nshared_objects); ++i)  
868 - {  
869 - int idx = he.shared_identifiers.at(i);  
870 - if (shared_idx_to_obj.count(idx) == 0) 842 + if (length != h_length)
  843 + {
  844 + // This condition almost certainly indicates a bad hint
  845 + // table or a bug in this code.
  846 + errors.push_back(
  847 + "page length mismatch for page " +
  848 + QUtil::int_to_string(pageno) + ": hint table = " +
  849 + QUtil::int_to_string(h_length) + "; computed length = " +
  850 + QUtil::int_to_string(length) + " (offset = " +
  851 + QUtil::int_to_string(offset) + ")");
  852 + }
  853 +
  854 + offset += h_length;
  855 +
  856 + // Translate shared object indexes to object numbers.
  857 + std::set<int> hint_shared;
  858 + std::set<int> computed_shared;
  859 +
  860 + if ((pageno == 0) && (he.nshared_objects > 0))
  861 + {
  862 + // pdlin and Acrobat both do this even though the spec
  863 + // states clearly and unambiguously that they should not.
  864 + warnings.push_back("page 0 has shared identifier entries");
  865 + }
  866 +
  867 + for (size_t i = 0; i < toS(he.nshared_objects); ++i)
  868 + {
  869 + int idx = he.shared_identifiers.at(i);
  870 + if (shared_idx_to_obj.count(idx) == 0)
871 { 871 {
872 stopOnError( 872 stopOnError(
873 "unable to get object for item in" 873 "unable to get object for item in"
874 " shared objects hint table"); 874 " shared objects hint table");
875 } 875 }
876 - hint_shared.insert(shared_idx_to_obj[idx]);  
877 - } 876 + hint_shared.insert(shared_idx_to_obj[idx]);
  877 + }
878 878
879 - for (size_t i = 0; i < toS(ce.nshared_objects); ++i)  
880 - {  
881 - int idx = ce.shared_identifiers.at(i);  
882 - if (idx >= this->m->c_shared_object_data.nshared_total) 879 + for (size_t i = 0; i < toS(ce.nshared_objects); ++i)
  880 + {
  881 + int idx = ce.shared_identifiers.at(i);
  882 + if (idx >= this->m->c_shared_object_data.nshared_total)
883 { 883 {
884 stopOnError( 884 stopOnError(
885 "index out of bounds for shared object hint table"); 885 "index out of bounds for shared object hint table");
886 } 886 }
887 - int obj = this->m->c_shared_object_data.entries.at(toS(idx)).object;  
888 - computed_shared.insert(obj);  
889 - }  
890 -  
891 - for (std::set<int>::iterator iter = hint_shared.begin();  
892 - iter != hint_shared.end(); ++iter)  
893 - {  
894 - if (! computed_shared.count(*iter))  
895 - {  
896 - // pdlin puts thumbnails here even though it shouldn't  
897 - warnings.push_back(  
898 - "page " + QUtil::int_to_string(pageno) +  
899 - ": shared object " + QUtil::int_to_string(*iter) +  
900 - ": in hint table but not computed list");  
901 - }  
902 - }  
903 -  
904 - for (std::set<int>::iterator iter = computed_shared.begin();  
905 - iter != computed_shared.end(); ++iter)  
906 - {  
907 - if (! hint_shared.count(*iter))  
908 - {  
909 - // Acrobat does not put some things including at least  
910 - // built-in fonts and procsets here, at least in some  
911 - // cases.  
912 - warnings.push_back(  
913 - "page " + QUtil::int_to_string(pageno) +  
914 - ": shared object " + QUtil::int_to_string(*iter) +  
915 - ": in computed list but not hint table");  
916 - }  
917 - } 887 + int obj = this->m->c_shared_object_data.entries.at(toS(idx)).object;
  888 + computed_shared.insert(obj);
  889 + }
  890 +
  891 + for (std::set<int>::iterator iter = hint_shared.begin();
  892 + iter != hint_shared.end(); ++iter)
  893 + {
  894 + if (! computed_shared.count(*iter))
  895 + {
  896 + // pdlin puts thumbnails here even though it shouldn't
  897 + warnings.push_back(
  898 + "page " + QUtil::int_to_string(pageno) +
  899 + ": shared object " + QUtil::int_to_string(*iter) +
  900 + ": in hint table but not computed list");
  901 + }
  902 + }
  903 +
  904 + for (std::set<int>::iterator iter = computed_shared.begin();
  905 + iter != computed_shared.end(); ++iter)
  906 + {
  907 + if (! hint_shared.count(*iter))
  908 + {
  909 + // Acrobat does not put some things including at least
  910 + // built-in fonts and procsets here, at least in some
  911 + // cases.
  912 + warnings.push_back(
  913 + "page " + QUtil::int_to_string(pageno) +
  914 + ": shared object " + QUtil::int_to_string(*iter) +
  915 + ": in computed list but not hint table");
  916 + }
  917 + }
918 } 918 }
919 } 919 }
920 920
921 void 921 void
922 QPDF::checkHSharedObject(std::list<std::string>& errors, 922 QPDF::checkHSharedObject(std::list<std::string>& errors,
923 - std::list<std::string>& warnings,  
924 - std::vector<QPDFObjectHandle> const& pages,  
925 - std::map<int, int>& idx_to_obj) 923 + std::list<std::string>& warnings,
  924 + std::vector<QPDFObjectHandle> const& pages,
  925 + std::map<int, int>& idx_to_obj)
926 { 926 {
927 // Implementation note 125 says shared object groups always 927 // Implementation note 125 says shared object groups always
928 // contain only one object. Implementation note 128 says that 928 // contain only one object. Implementation note 128 says that
@@ -945,73 +945,73 @@ QPDF::checkHSharedObject(std::list&lt;std::string&gt;&amp; errors, @@ -945,73 +945,73 @@ QPDF::checkHSharedObject(std::list&lt;std::string&gt;&amp; errors,
945 HSharedObject& so = this->m->shared_object_hints; 945 HSharedObject& so = this->m->shared_object_hints;
946 if (so.nshared_total < so.nshared_first_page) 946 if (so.nshared_total < so.nshared_first_page)
947 { 947 {
948 - errors.push_back("shared object hint table: ntotal < nfirst_page"); 948 + errors.push_back("shared object hint table: ntotal < nfirst_page");
949 } 949 }
950 else 950 else
951 { 951 {
952 - // The first nshared_first_page objects are consecutive  
953 - // objects starting with the first page object. The rest are  
954 - // consecutive starting from the first_shared_obj object.  
955 - int cur_object = pages.at(0).getObjectID();  
956 - for (int i = 0; i < so.nshared_total; ++i)  
957 - {  
958 - if (i == so.nshared_first_page)  
959 - {  
960 - QTC::TC("qpdf", "QPDF lin check shared past first page");  
961 - if (this->m->part8.empty())  
962 - {  
963 - errors.push_back(  
964 - "part 8 is empty but nshared_total > "  
965 - "nshared_first_page");  
966 - }  
967 - else  
968 - {  
969 - int obj = this->m->part8.at(0).getObjectID();  
970 - if (obj != so.first_shared_obj)  
971 - {  
972 - errors.push_back(  
973 - "first shared object number mismatch: "  
974 - "hint table = " +  
975 - QUtil::int_to_string(so.first_shared_obj) +  
976 - "; computed = " +  
977 - QUtil::int_to_string(obj));  
978 - }  
979 - }  
980 -  
981 - cur_object = so.first_shared_obj;  
982 -  
983 - QPDFObjGen og(cur_object, 0);  
984 - if (this->m->xref_table.count(og) == 0) 952 + // The first nshared_first_page objects are consecutive
  953 + // objects starting with the first page object. The rest are
  954 + // consecutive starting from the first_shared_obj object.
  955 + int cur_object = pages.at(0).getObjectID();
  956 + for (int i = 0; i < so.nshared_total; ++i)
  957 + {
  958 + if (i == so.nshared_first_page)
  959 + {
  960 + QTC::TC("qpdf", "QPDF lin check shared past first page");
  961 + if (this->m->part8.empty())
  962 + {
  963 + errors.push_back(
  964 + "part 8 is empty but nshared_total > "
  965 + "nshared_first_page");
  966 + }
  967 + else
  968 + {
  969 + int obj = this->m->part8.at(0).getObjectID();
  970 + if (obj != so.first_shared_obj)
  971 + {
  972 + errors.push_back(
  973 + "first shared object number mismatch: "
  974 + "hint table = " +
  975 + QUtil::int_to_string(so.first_shared_obj) +
  976 + "; computed = " +
  977 + QUtil::int_to_string(obj));
  978 + }
  979 + }
  980 +
  981 + cur_object = so.first_shared_obj;
  982 +
  983 + QPDFObjGen og(cur_object, 0);
  984 + if (this->m->xref_table.count(og) == 0)
985 { 985 {
986 stopOnError("unknown object in shared object hint table"); 986 stopOnError("unknown object in shared object hint table");
987 } 987 }
988 - qpdf_offset_t offset = getLinearizationOffset(og);  
989 - qpdf_offset_t h_offset = 988 + qpdf_offset_t offset = getLinearizationOffset(og);
  989 + qpdf_offset_t h_offset =
990 adjusted_offset(so.first_shared_offset); 990 adjusted_offset(so.first_shared_offset);
991 - if (offset != h_offset)  
992 - {  
993 - errors.push_back(  
994 - "first shared object offset mismatch: hint table = " +  
995 - QUtil::int_to_string(h_offset) + "; computed = " +  
996 - QUtil::int_to_string(offset));  
997 - }  
998 - }  
999 -  
1000 - idx_to_obj[i] = cur_object;  
1001 - HSharedObjectEntry& se = so.entries.at(toS(i));  
1002 - int nobjects = se.nobjects_minus_one + 1;  
1003 - int length = lengthNextN(cur_object, nobjects, errors);  
1004 - int h_length = so.min_group_length + se.delta_group_length;  
1005 - if (length != h_length)  
1006 - {  
1007 - errors.push_back(  
1008 - "shared object " + QUtil::int_to_string(i) +  
1009 - " length mismatch: hint table = " +  
1010 - QUtil::int_to_string(h_length) + "; computed = " +  
1011 - QUtil::int_to_string(length));  
1012 - }  
1013 - cur_object += nobjects;  
1014 - } 991 + if (offset != h_offset)
  992 + {
  993 + errors.push_back(
  994 + "first shared object offset mismatch: hint table = " +
  995 + QUtil::int_to_string(h_offset) + "; computed = " +
  996 + QUtil::int_to_string(offset));
  997 + }
  998 + }
  999 +
  1000 + idx_to_obj[i] = cur_object;
  1001 + HSharedObjectEntry& se = so.entries.at(toS(i));
  1002 + int nobjects = se.nobjects_minus_one + 1;
  1003 + int length = lengthNextN(cur_object, nobjects, errors);
  1004 + int h_length = so.min_group_length + se.delta_group_length;
  1005 + if (length != h_length)
  1006 + {
  1007 + errors.push_back(
  1008 + "shared object " + QUtil::int_to_string(i) +
  1009 + " length mismatch: hint table = " +
  1010 + QUtil::int_to_string(h_length) + "; computed = " +
  1011 + QUtil::int_to_string(length));
  1012 + }
  1013 + cur_object += nobjects;
  1014 + }
1015 } 1015 }
1016 } 1016 }
1017 1017
@@ -1028,60 +1028,60 @@ QPDF::checkHOutlines(std::list&lt;std::string&gt;&amp; warnings) @@ -1028,60 +1028,60 @@ QPDF::checkHOutlines(std::list&lt;std::string&gt;&amp; warnings)
1028 1028
1029 if (this->m->c_outline_data.nobjects == this->m->outline_hints.nobjects) 1029 if (this->m->c_outline_data.nobjects == this->m->outline_hints.nobjects)
1030 { 1030 {
1031 - if (this->m->c_outline_data.nobjects == 0)  
1032 - {  
1033 - return;  
1034 - } 1031 + if (this->m->c_outline_data.nobjects == 0)
  1032 + {
  1033 + return;
  1034 + }
1035 1035
1036 - if (this->m->c_outline_data.first_object ==  
1037 - this->m->outline_hints.first_object)  
1038 - {  
1039 - // Check length and offset. Acrobat gets these wrong.  
1040 - QPDFObjectHandle outlines = getRoot().getKey("/Outlines"); 1036 + if (this->m->c_outline_data.first_object ==
  1037 + this->m->outline_hints.first_object)
  1038 + {
  1039 + // Check length and offset. Acrobat gets these wrong.
  1040 + QPDFObjectHandle outlines = getRoot().getKey("/Outlines");
1041 if (! outlines.isIndirect()) 1041 if (! outlines.isIndirect())
1042 { 1042 {
1043 // This case is not exercised in test suite since not 1043 // This case is not exercised in test suite since not
1044 // permitted by the spec, but if this does occur, the 1044 // permitted by the spec, but if this does occur, the
1045 // code below would fail. 1045 // code below would fail.
1046 - warnings.push_back(  
1047 - "/Outlines key of root dictionary is not indirect"); 1046 + warnings.push_back(
  1047 + "/Outlines key of root dictionary is not indirect");
1048 return; 1048 return;
1049 } 1049 }
1050 - QPDFObjGen og(outlines.getObjGen());  
1051 - if (this->m->xref_table.count(og) == 0) 1050 + QPDFObjGen og(outlines.getObjGen());
  1051 + if (this->m->xref_table.count(og) == 0)
1052 { 1052 {
1053 stopOnError("unknown object in outlines hint table"); 1053 stopOnError("unknown object in outlines hint table");
1054 } 1054 }
1055 - qpdf_offset_t offset = getLinearizationOffset(og);  
1056 - ObjUser ou(ObjUser::ou_root_key, "/Outlines");  
1057 - int length = toI(maxEnd(ou) - offset);  
1058 - qpdf_offset_t table_offset =  
1059 - adjusted_offset(this->m->outline_hints.first_object_offset);  
1060 - if (offset != table_offset)  
1061 - {  
1062 - warnings.push_back(  
1063 - "incorrect offset in outlines table: hint table = " +  
1064 - QUtil::int_to_string(table_offset) +  
1065 - "; computed = " + QUtil::int_to_string(offset));  
1066 - }  
1067 - int table_length = this->m->outline_hints.group_length;  
1068 - if (length != table_length)  
1069 - {  
1070 - warnings.push_back(  
1071 - "incorrect length in outlines table: hint table = " +  
1072 - QUtil::int_to_string(table_length) +  
1073 - "; computed = " + QUtil::int_to_string(length));  
1074 - }  
1075 - }  
1076 - else  
1077 - {  
1078 - warnings.push_back("incorrect first object number in outline "  
1079 - "hints table.");  
1080 - } 1055 + qpdf_offset_t offset = getLinearizationOffset(og);
  1056 + ObjUser ou(ObjUser::ou_root_key, "/Outlines");
  1057 + int length = toI(maxEnd(ou) - offset);
  1058 + qpdf_offset_t table_offset =
  1059 + adjusted_offset(this->m->outline_hints.first_object_offset);
  1060 + if (offset != table_offset)
  1061 + {
  1062 + warnings.push_back(
  1063 + "incorrect offset in outlines table: hint table = " +
  1064 + QUtil::int_to_string(table_offset) +
  1065 + "; computed = " + QUtil::int_to_string(offset));
  1066 + }
  1067 + int table_length = this->m->outline_hints.group_length;
  1068 + if (length != table_length)
  1069 + {
  1070 + warnings.push_back(
  1071 + "incorrect length in outlines table: hint table = " +
  1072 + QUtil::int_to_string(table_length) +
  1073 + "; computed = " + QUtil::int_to_string(length));
  1074 + }
  1075 + }
  1076 + else
  1077 + {
  1078 + warnings.push_back("incorrect first object number in outline "
  1079 + "hints table.");
  1080 + }
1081 } 1081 }
1082 else 1082 else
1083 { 1083 {
1084 - warnings.push_back("incorrect object count in outline hint table"); 1084 + warnings.push_back("incorrect object count in outline hint table");
1085 } 1085 }
1086 } 1086 }
1087 1087
@@ -1090,13 +1090,13 @@ QPDF::showLinearizationData() @@ -1090,13 +1090,13 @@ QPDF::showLinearizationData()
1090 { 1090 {
1091 try 1091 try
1092 { 1092 {
1093 - readLinearizationData();  
1094 - checkLinearizationInternal();  
1095 - dumpLinearizationDataInternal(); 1093 + readLinearizationData();
  1094 + checkLinearizationInternal();
  1095 + dumpLinearizationDataInternal();
1096 } 1096 }
1097 catch (QPDFExc& e) 1097 catch (QPDFExc& e)
1098 { 1098 {
1099 - *this->m->err_stream << e.what() << std::endl; 1099 + *this->m->err_stream << e.what() << std::endl;
1100 } 1100 }
1101 } 1101 }
1102 1102
@@ -1108,15 +1108,15 @@ QPDF::dumpLinearizationDataInternal() @@ -1108,15 +1108,15 @@ QPDF::dumpLinearizationDataInternal()
1108 << std::endl; 1108 << std::endl;
1109 1109
1110 *this->m->out_stream 1110 *this->m->out_stream
1111 - << "file_size: " << this->m->linp.file_size << std::endl  
1112 - << "first_page_object: " << this->m->linp.first_page_object << std::endl  
1113 - << "first_page_end: " << this->m->linp.first_page_end << std::endl  
1114 - << "npages: " << this->m->linp.npages << std::endl  
1115 - << "xref_zero_offset: " << this->m->linp.xref_zero_offset << std::endl  
1116 - << "first_page: " << this->m->linp.first_page << std::endl  
1117 - << "H_offset: " << this->m->linp.H_offset << std::endl  
1118 - << "H_length: " << this->m->linp.H_length << std::endl  
1119 - << std::endl; 1111 + << "file_size: " << this->m->linp.file_size << std::endl
  1112 + << "first_page_object: " << this->m->linp.first_page_object << std::endl
  1113 + << "first_page_end: " << this->m->linp.first_page_end << std::endl
  1114 + << "npages: " << this->m->linp.npages << std::endl
  1115 + << "xref_zero_offset: " << this->m->linp.xref_zero_offset << std::endl
  1116 + << "first_page: " << this->m->linp.first_page << std::endl
  1117 + << "H_offset: " << this->m->linp.H_offset << std::endl
  1118 + << "H_length: " << this->m->linp.H_length << std::endl
  1119 + << std::endl;
1120 1120
1121 *this->m->out_stream << "Page Offsets Hint Table" << std::endl 1121 *this->m->out_stream << "Page Offsets Hint Table" << std::endl
1122 << std::endl; 1122 << std::endl;
@@ -1128,10 +1128,10 @@ QPDF::dumpLinearizationDataInternal() @@ -1128,10 +1128,10 @@ QPDF::dumpLinearizationDataInternal()
1128 1128
1129 if (this->m->outline_hints.nobjects > 0) 1129 if (this->m->outline_hints.nobjects > 0)
1130 { 1130 {
1131 - *this->m->out_stream << std::endl 1131 + *this->m->out_stream << std::endl
1132 << "Outlines Hint Table" << std::endl 1132 << "Outlines Hint Table" << std::endl
1133 << std::endl; 1133 << std::endl;
1134 - dumpHGeneric(this->m->outline_hints); 1134 + dumpHGeneric(this->m->outline_hints);
1135 } 1135 }
1136 } 1136 }
1137 1137
@@ -1143,7 +1143,7 @@ QPDF::adjusted_offset(qpdf_offset_t offset) @@ -1143,7 +1143,7 @@ QPDF::adjusted_offset(qpdf_offset_t offset)
1143 // itself. 1143 // itself.
1144 if (offset >= this->m->linp.H_offset) 1144 if (offset >= this->m->linp.H_offset)
1145 { 1145 {
1146 - return offset + this->m->linp.H_length; 1146 + return offset + this->m->linp.H_length;
1147 } 1147 }
1148 return offset; 1148 return offset;
1149 } 1149 }
@@ -1154,55 +1154,55 @@ QPDF::dumpHPageOffset() @@ -1154,55 +1154,55 @@ QPDF::dumpHPageOffset()
1154 { 1154 {
1155 HPageOffset& t = this->m->page_offset_hints; 1155 HPageOffset& t = this->m->page_offset_hints;
1156 *this->m->out_stream 1156 *this->m->out_stream
1157 - << "min_nobjects: " << t.min_nobjects  
1158 - << std::endl  
1159 - << "first_page_offset: " << adjusted_offset(t.first_page_offset)  
1160 - << std::endl  
1161 - << "nbits_delta_nobjects: " << t.nbits_delta_nobjects  
1162 - << std::endl  
1163 - << "min_page_length: " << t.min_page_length  
1164 - << std::endl  
1165 - << "nbits_delta_page_length: " << t.nbits_delta_page_length  
1166 - << std::endl  
1167 - << "min_content_offset: " << t.min_content_offset  
1168 - << std::endl  
1169 - << "nbits_delta_content_offset: " << t.nbits_delta_content_offset  
1170 - << std::endl  
1171 - << "min_content_length: " << t.min_content_length  
1172 - << std::endl  
1173 - << "nbits_delta_content_length: " << t.nbits_delta_content_length  
1174 - << std::endl  
1175 - << "nbits_nshared_objects: " << t.nbits_nshared_objects  
1176 - << std::endl  
1177 - << "nbits_shared_identifier: " << t.nbits_shared_identifier  
1178 - << std::endl  
1179 - << "nbits_shared_numerator: " << t.nbits_shared_numerator  
1180 - << std::endl  
1181 - << "shared_denominator: " << t.shared_denominator  
1182 - << std::endl; 1157 + << "min_nobjects: " << t.min_nobjects
  1158 + << std::endl
  1159 + << "first_page_offset: " << adjusted_offset(t.first_page_offset)
  1160 + << std::endl
  1161 + << "nbits_delta_nobjects: " << t.nbits_delta_nobjects
  1162 + << std::endl
  1163 + << "min_page_length: " << t.min_page_length
  1164 + << std::endl
  1165 + << "nbits_delta_page_length: " << t.nbits_delta_page_length
  1166 + << std::endl
  1167 + << "min_content_offset: " << t.min_content_offset
  1168 + << std::endl
  1169 + << "nbits_delta_content_offset: " << t.nbits_delta_content_offset
  1170 + << std::endl
  1171 + << "min_content_length: " << t.min_content_length
  1172 + << std::endl
  1173 + << "nbits_delta_content_length: " << t.nbits_delta_content_length
  1174 + << std::endl
  1175 + << "nbits_nshared_objects: " << t.nbits_nshared_objects
  1176 + << std::endl
  1177 + << "nbits_shared_identifier: " << t.nbits_shared_identifier
  1178 + << std::endl
  1179 + << "nbits_shared_numerator: " << t.nbits_shared_numerator
  1180 + << std::endl
  1181 + << "shared_denominator: " << t.shared_denominator
  1182 + << std::endl;
1183 1183
1184 for (size_t i1 = 0; i1 < toS(this->m->linp.npages); ++i1) 1184 for (size_t i1 = 0; i1 < toS(this->m->linp.npages); ++i1)
1185 { 1185 {
1186 - HPageOffsetEntry& pe = t.entries.at(i1);  
1187 - *this->m->out_stream  
1188 - << "Page " << i1 << ":" << std::endl  
1189 - << " nobjects: " << pe.delta_nobjects + t.min_nobjects  
1190 - << std::endl  
1191 - << " length: " << pe.delta_page_length + t.min_page_length  
1192 - << std::endl  
1193 - // content offset is relative to page, not file  
1194 - << " content_offset: "  
1195 - << pe.delta_content_offset + t.min_content_offset << std::endl  
1196 - << " content_length: "  
1197 - << pe.delta_content_length + t.min_content_length << std::endl  
1198 - << " nshared_objects: " << pe.nshared_objects << std::endl;  
1199 - for (size_t i2 = 0; i2 < toS(pe.nshared_objects); ++i2)  
1200 - {  
1201 - *this->m->out_stream << " identifier " << i2 << ": " 1186 + HPageOffsetEntry& pe = t.entries.at(i1);
  1187 + *this->m->out_stream
  1188 + << "Page " << i1 << ":" << std::endl
  1189 + << " nobjects: " << pe.delta_nobjects + t.min_nobjects
  1190 + << std::endl
  1191 + << " length: " << pe.delta_page_length + t.min_page_length
  1192 + << std::endl
  1193 + // content offset is relative to page, not file
  1194 + << " content_offset: "
  1195 + << pe.delta_content_offset + t.min_content_offset << std::endl
  1196 + << " content_length: "
  1197 + << pe.delta_content_length + t.min_content_length << std::endl
  1198 + << " nshared_objects: " << pe.nshared_objects << std::endl;
  1199 + for (size_t i2 = 0; i2 < toS(pe.nshared_objects); ++i2)
  1200 + {
  1201 + *this->m->out_stream << " identifier " << i2 << ": "
1202 << pe.shared_identifiers.at(i2) << std::endl; 1202 << pe.shared_identifiers.at(i2) << std::endl;
1203 - *this->m->out_stream << " numerator " << i2 << ": " 1203 + *this->m->out_stream << " numerator " << i2 << ": "
1204 << pe.shared_numerators.at(i2) << std::endl; 1204 << pe.shared_numerators.at(i2) << std::endl;
1205 - } 1205 + }
1206 } 1206 }
1207 } 1207 }
1208 1208
@@ -1211,39 +1211,39 @@ QPDF::dumpHSharedObject() @@ -1211,39 +1211,39 @@ QPDF::dumpHSharedObject()
1211 { 1211 {
1212 HSharedObject& t = this->m->shared_object_hints; 1212 HSharedObject& t = this->m->shared_object_hints;
1213 *this->m->out_stream 1213 *this->m->out_stream
1214 - << "first_shared_obj: " << t.first_shared_obj  
1215 - << std::endl  
1216 - << "first_shared_offset: " << adjusted_offset(t.first_shared_offset)  
1217 - << std::endl  
1218 - << "nshared_first_page: " << t.nshared_first_page  
1219 - << std::endl  
1220 - << "nshared_total: " << t.nshared_total  
1221 - << std::endl  
1222 - << "nbits_nobjects: " << t.nbits_nobjects  
1223 - << std::endl  
1224 - << "min_group_length: " << t.min_group_length  
1225 - << std::endl  
1226 - << "nbits_delta_group_length: " << t.nbits_delta_group_length  
1227 - << std::endl; 1214 + << "first_shared_obj: " << t.first_shared_obj
  1215 + << std::endl
  1216 + << "first_shared_offset: " << adjusted_offset(t.first_shared_offset)
  1217 + << std::endl
  1218 + << "nshared_first_page: " << t.nshared_first_page
  1219 + << std::endl
  1220 + << "nshared_total: " << t.nshared_total
  1221 + << std::endl
  1222 + << "nbits_nobjects: " << t.nbits_nobjects
  1223 + << std::endl
  1224 + << "min_group_length: " << t.min_group_length
  1225 + << std::endl
  1226 + << "nbits_delta_group_length: " << t.nbits_delta_group_length
  1227 + << std::endl;
1228 1228
1229 for (size_t i = 0; i < toS(t.nshared_total); ++i) 1229 for (size_t i = 0; i < toS(t.nshared_total); ++i)
1230 { 1230 {
1231 - HSharedObjectEntry& se = t.entries.at(i);  
1232 - *this->m->out_stream 1231 + HSharedObjectEntry& se = t.entries.at(i);
  1232 + *this->m->out_stream
1233 << "Shared Object " << i << ":" << std::endl 1233 << "Shared Object " << i << ":" << std::endl
1234 << " group length: " 1234 << " group length: "
1235 << se.delta_group_length + t.min_group_length << std::endl; 1235 << se.delta_group_length + t.min_group_length << std::endl;
1236 - // PDF spec says signature present nobjects_minus_one are  
1237 - // always 0, so print them only if they have a non-zero value.  
1238 - if (se.signature_present)  
1239 - {  
1240 - *this->m->out_stream << " signature present" << std::endl;  
1241 - }  
1242 - if (se.nobjects_minus_one != 0)  
1243 - {  
1244 - *this->m->out_stream << " nobjects: " 1236 + // PDF spec says signature present nobjects_minus_one are
  1237 + // always 0, so print them only if they have a non-zero value.
  1238 + if (se.signature_present)
  1239 + {
  1240 + *this->m->out_stream << " signature present" << std::endl;
  1241 + }
  1242 + if (se.nobjects_minus_one != 0)
  1243 + {
  1244 + *this->m->out_stream << " nobjects: "
1245 << se.nobjects_minus_one + 1 << std::endl; 1245 << se.nobjects_minus_one + 1 << std::endl;
1246 - } 1246 + }
1247 } 1247 }
1248 } 1248 }
1249 1249
@@ -1251,14 +1251,14 @@ void @@ -1251,14 +1251,14 @@ void
1251 QPDF::dumpHGeneric(HGeneric& t) 1251 QPDF::dumpHGeneric(HGeneric& t)
1252 { 1252 {
1253 *this->m->out_stream 1253 *this->m->out_stream
1254 - << "first_object: " << t.first_object  
1255 - << std::endl  
1256 - << "first_object_offset: " << adjusted_offset(t.first_object_offset)  
1257 - << std::endl  
1258 - << "nobjects: " << t.nobjects  
1259 - << std::endl  
1260 - << "group_length: " << t.group_length  
1261 - << std::endl; 1254 + << "first_object: " << t.first_object
  1255 + << std::endl
  1256 + << "first_object_offset: " << adjusted_offset(t.first_object_offset)
  1257 + << std::endl
  1258 + << "nobjects: " << t.nobjects
  1259 + << std::endl
  1260 + << "group_length: " << t.group_length
  1261 + << std::endl;
1262 } 1262 }
1263 1263
1264 QPDFObjectHandle 1264 QPDFObjectHandle
@@ -1279,11 +1279,11 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1279,11 +1279,11 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1279 1279
1280 if (this->m->object_to_obj_users.empty()) 1280 if (this->m->object_to_obj_users.empty())
1281 { 1281 {
1282 - // Note that we can't call optimize here because we don't know  
1283 - // whether it should be called with or without allow changes.  
1284 - throw std::logic_error(  
1285 - "INTERNAL ERROR: QPDF::calculateLinearizationData "  
1286 - "called before optimize()"); 1282 + // Note that we can't call optimize here because we don't know
  1283 + // whether it should be called with or without allow changes.
  1284 + throw std::logic_error(
  1285 + "INTERNAL ERROR: QPDF::calculateLinearizationData "
  1286 + "called before optimize()");
1287 } 1287 }
1288 1288
1289 // Separate objects into the categories sufficient for us to 1289 // Separate objects into the categories sufficient for us to
@@ -1347,22 +1347,22 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1347,22 +1347,22 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1347 bool outlines_in_first_page = false; 1347 bool outlines_in_first_page = false;
1348 QPDFObjectHandle pagemode = root.getKey("/PageMode"); 1348 QPDFObjectHandle pagemode = root.getKey("/PageMode");
1349 QTC::TC("qpdf", "QPDF categorize pagemode present", 1349 QTC::TC("qpdf", "QPDF categorize pagemode present",
1350 - pagemode.isName() ? 1 : 0); 1350 + pagemode.isName() ? 1 : 0);
1351 if (pagemode.isName()) 1351 if (pagemode.isName())
1352 { 1352 {
1353 - if (pagemode.getName() == "/UseOutlines")  
1354 - {  
1355 - if (root.hasKey("/Outlines"))  
1356 - {  
1357 - outlines_in_first_page = true;  
1358 - }  
1359 - else  
1360 - {  
1361 - QTC::TC("qpdf", "QPDF UseOutlines but no Outlines");  
1362 - }  
1363 - }  
1364 - QTC::TC("qpdf", "QPDF categorize pagemode outlines",  
1365 - outlines_in_first_page ? 1 : 0); 1353 + if (pagemode.getName() == "/UseOutlines")
  1354 + {
  1355 + if (root.hasKey("/Outlines"))
  1356 + {
  1357 + outlines_in_first_page = true;
  1358 + }
  1359 + else
  1360 + {
  1361 + QTC::TC("qpdf", "QPDF UseOutlines but no Outlines");
  1362 + }
  1363 + }
  1364 + QTC::TC("qpdf", "QPDF categorize pagemode outlines",
  1365 + outlines_in_first_page ? 1 : 0);
1366 } 1366 }
1367 1367
1368 std::set<std::string> open_document_keys; 1368 std::set<std::string> open_document_keys;
@@ -1384,121 +1384,121 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1384,121 +1384,121 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1384 std::set<QPDFObjGen> lc_root; 1384 std::set<QPDFObjGen> lc_root;
1385 1385
1386 for (std::map<QPDFObjGen, std::set<ObjUser> >::iterator oiter = 1386 for (std::map<QPDFObjGen, std::set<ObjUser> >::iterator oiter =
1387 - this->m->object_to_obj_users.begin();  
1388 - oiter != this->m->object_to_obj_users.end(); ++oiter)  
1389 - {  
1390 - QPDFObjGen const& og = (*oiter).first;  
1391 -  
1392 - std::set<ObjUser>& ous = (*oiter).second;  
1393 -  
1394 - bool in_open_document = false;  
1395 - bool in_first_page = false;  
1396 - int other_pages = 0;  
1397 - int thumbs = 0;  
1398 - int others = 0;  
1399 - bool in_outlines = false;  
1400 - bool is_root = false;  
1401 -  
1402 - for (std::set<ObjUser>::iterator uiter = ous.begin();  
1403 - uiter != ous.end(); ++uiter)  
1404 - {  
1405 - ObjUser const& ou = *uiter;  
1406 - switch (ou.ou_type)  
1407 - {  
1408 - case ObjUser::ou_trailer_key:  
1409 - if (ou.key == "/Encrypt")  
1410 - {  
1411 - in_open_document = true;  
1412 - }  
1413 - else  
1414 - {  
1415 - ++others;  
1416 - }  
1417 - break;  
1418 -  
1419 - case ObjUser::ou_thumb:  
1420 - ++thumbs;  
1421 - break;  
1422 -  
1423 - case ObjUser::ou_root_key:  
1424 - if (open_document_keys.count(ou.key) > 0)  
1425 - {  
1426 - in_open_document = true;  
1427 - }  
1428 - else if (ou.key == "/Outlines")  
1429 - {  
1430 - in_outlines = true;  
1431 - }  
1432 - else  
1433 - {  
1434 - ++others;  
1435 - }  
1436 - break;  
1437 -  
1438 - case ObjUser::ou_page:  
1439 - if (ou.pageno == 0)  
1440 - {  
1441 - in_first_page = true;  
1442 - }  
1443 - else  
1444 - {  
1445 - ++other_pages;  
1446 - }  
1447 - break;  
1448 -  
1449 - case ObjUser::ou_root:  
1450 - is_root = true;  
1451 - break;  
1452 -  
1453 - case ObjUser::ou_bad:  
1454 - stopOnError(  
1455 - "INTERNAL ERROR: QPDF::calculateLinearizationData: "  
1456 - "invalid user type");  
1457 - break;  
1458 - }  
1459 - }  
1460 -  
1461 - if (is_root)  
1462 - {  
1463 - lc_root.insert(og);  
1464 - }  
1465 - else if (in_outlines)  
1466 - {  
1467 - lc_outlines.insert(og);  
1468 - }  
1469 - else if (in_open_document)  
1470 - {  
1471 - lc_open_document.insert(og);  
1472 - }  
1473 - else if ((in_first_page) &&  
1474 - (others == 0) && (other_pages == 0) && (thumbs == 0))  
1475 - {  
1476 - lc_first_page_private.insert(og);  
1477 - }  
1478 - else if (in_first_page)  
1479 - {  
1480 - lc_first_page_shared.insert(og);  
1481 - }  
1482 - else if ((other_pages == 1) && (others == 0) && (thumbs == 0))  
1483 - {  
1484 - lc_other_page_private.insert(og);  
1485 - }  
1486 - else if (other_pages > 1)  
1487 - {  
1488 - lc_other_page_shared.insert(og);  
1489 - }  
1490 - else if ((thumbs == 1) && (others == 0))  
1491 - {  
1492 - lc_thumbnail_private.insert(og);  
1493 - }  
1494 - else if (thumbs > 1)  
1495 - {  
1496 - lc_thumbnail_shared.insert(og);  
1497 - }  
1498 - else  
1499 - {  
1500 - lc_other.insert(og);  
1501 - } 1387 + this->m->object_to_obj_users.begin();
  1388 + oiter != this->m->object_to_obj_users.end(); ++oiter)
  1389 + {
  1390 + QPDFObjGen const& og = (*oiter).first;
  1391 +
  1392 + std::set<ObjUser>& ous = (*oiter).second;
  1393 +
  1394 + bool in_open_document = false;
  1395 + bool in_first_page = false;
  1396 + int other_pages = 0;
  1397 + int thumbs = 0;
  1398 + int others = 0;
  1399 + bool in_outlines = false;
  1400 + bool is_root = false;
  1401 +
  1402 + for (std::set<ObjUser>::iterator uiter = ous.begin();
  1403 + uiter != ous.end(); ++uiter)
  1404 + {
  1405 + ObjUser const& ou = *uiter;
  1406 + switch (ou.ou_type)
  1407 + {
  1408 + case ObjUser::ou_trailer_key:
  1409 + if (ou.key == "/Encrypt")
  1410 + {
  1411 + in_open_document = true;
  1412 + }
  1413 + else
  1414 + {
  1415 + ++others;
  1416 + }
  1417 + break;
  1418 +
  1419 + case ObjUser::ou_thumb:
  1420 + ++thumbs;
  1421 + break;
  1422 +
  1423 + case ObjUser::ou_root_key:
  1424 + if (open_document_keys.count(ou.key) > 0)
  1425 + {
  1426 + in_open_document = true;
  1427 + }
  1428 + else if (ou.key == "/Outlines")
  1429 + {
  1430 + in_outlines = true;
  1431 + }
  1432 + else
  1433 + {
  1434 + ++others;
  1435 + }
  1436 + break;
  1437 +
  1438 + case ObjUser::ou_page:
  1439 + if (ou.pageno == 0)
  1440 + {
  1441 + in_first_page = true;
  1442 + }
  1443 + else
  1444 + {
  1445 + ++other_pages;
  1446 + }
  1447 + break;
  1448 +
  1449 + case ObjUser::ou_root:
  1450 + is_root = true;
  1451 + break;
  1452 +
  1453 + case ObjUser::ou_bad:
  1454 + stopOnError(
  1455 + "INTERNAL ERROR: QPDF::calculateLinearizationData: "
  1456 + "invalid user type");
  1457 + break;
  1458 + }
  1459 + }
  1460 +
  1461 + if (is_root)
  1462 + {
  1463 + lc_root.insert(og);
  1464 + }
  1465 + else if (in_outlines)
  1466 + {
  1467 + lc_outlines.insert(og);
  1468 + }
  1469 + else if (in_open_document)
  1470 + {
  1471 + lc_open_document.insert(og);
  1472 + }
  1473 + else if ((in_first_page) &&
  1474 + (others == 0) && (other_pages == 0) && (thumbs == 0))
  1475 + {
  1476 + lc_first_page_private.insert(og);
  1477 + }
  1478 + else if (in_first_page)
  1479 + {
  1480 + lc_first_page_shared.insert(og);
  1481 + }
  1482 + else if ((other_pages == 1) && (others == 0) && (thumbs == 0))
  1483 + {
  1484 + lc_other_page_private.insert(og);
  1485 + }
  1486 + else if (other_pages > 1)
  1487 + {
  1488 + lc_other_page_shared.insert(og);
  1489 + }
  1490 + else if ((thumbs == 1) && (others == 0))
  1491 + {
  1492 + lc_thumbnail_private.insert(og);
  1493 + }
  1494 + else if (thumbs > 1)
  1495 + {
  1496 + lc_thumbnail_shared.insert(og);
  1497 + }
  1498 + else
  1499 + {
  1500 + lc_other.insert(og);
  1501 + }
1502 } 1502 }
1503 1503
1504 // Generate ordering for objects in the output file. Sometimes we 1504 // Generate ordering for objects in the output file. Sometimes we
@@ -1518,14 +1518,14 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1518,14 +1518,14 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1518 // Premature optimization is the root of all evil. 1518 // Premature optimization is the root of all evil.
1519 std::vector<QPDFObjectHandle> pages; 1519 std::vector<QPDFObjectHandle> pages;
1520 { // local scope 1520 { // local scope
1521 - // Map all page objects to the containing object stream. This  
1522 - // should be a no-op in a properly linearized file.  
1523 - std::vector<QPDFObjectHandle> t = getAllPages();  
1524 - for (std::vector<QPDFObjectHandle>::iterator iter = t.begin();  
1525 - iter != t.end(); ++iter)  
1526 - {  
1527 - pages.push_back(getUncompressedObject(*iter, object_stream_data));  
1528 - } 1521 + // Map all page objects to the containing object stream. This
  1522 + // should be a no-op in a properly linearized file.
  1523 + std::vector<QPDFObjectHandle> t = getAllPages();
  1524 + for (std::vector<QPDFObjectHandle>::iterator iter = t.begin();
  1525 + iter != t.end(); ++iter)
  1526 + {
  1527 + pages.push_back(getUncompressedObject(*iter, object_stream_data));
  1528 + }
1529 } 1529 }
1530 int npages = toI(pages.size()); 1530 int npages = toI(pages.size());
1531 1531
@@ -1553,9 +1553,9 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1553,9 +1553,9 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1553 } 1553 }
1554 this->m->part4.push_back(objGenToIndirect(*(lc_root.begin()))); 1554 this->m->part4.push_back(objGenToIndirect(*(lc_root.begin())));
1555 for (std::set<QPDFObjGen>::iterator iter = lc_open_document.begin(); 1555 for (std::set<QPDFObjGen>::iterator iter = lc_open_document.begin();
1556 - iter != lc_open_document.end(); ++iter) 1556 + iter != lc_open_document.end(); ++iter)
1557 { 1557 {
1558 - this->m->part4.push_back(objGenToIndirect(*iter)); 1558 + this->m->part4.push_back(objGenToIndirect(*iter));
1559 } 1559 }
1560 1560
1561 // Part 6: first page objects. Note: implementation note 124 1561 // Part 6: first page objects. Note: implementation note 124
@@ -1572,9 +1572,9 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1572,9 +1572,9 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1572 QPDFObjGen first_page_og(pages.at(0).getObjGen()); 1572 QPDFObjGen first_page_og(pages.at(0).getObjGen());
1573 if (! lc_first_page_private.count(first_page_og)) 1573 if (! lc_first_page_private.count(first_page_og))
1574 { 1574 {
1575 - stopOnError(  
1576 - "INTERNAL ERROR: QPDF::calculateLinearizationData: first page "  
1577 - "object not in lc_first_page_private"); 1575 + stopOnError(
  1576 + "INTERNAL ERROR: QPDF::calculateLinearizationData: first page "
  1577 + "object not in lc_first_page_private");
1578 } 1578 }
1579 lc_first_page_private.erase(first_page_og); 1579 lc_first_page_private.erase(first_page_og);
1580 this->m->c_linp.first_page_object = pages.at(0).getObjectID(); 1580 this->m->c_linp.first_page_object = pages.at(0).getObjectID();
@@ -1586,21 +1586,21 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1586,21 +1586,21 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1586 // hint tables. 1586 // hint tables.
1587 1587
1588 for (std::set<QPDFObjGen>::iterator iter = lc_first_page_private.begin(); 1588 for (std::set<QPDFObjGen>::iterator iter = lc_first_page_private.begin();
1589 - iter != lc_first_page_private.end(); ++iter) 1589 + iter != lc_first_page_private.end(); ++iter)
1590 { 1590 {
1591 - this->m->part6.push_back(objGenToIndirect(*iter)); 1591 + this->m->part6.push_back(objGenToIndirect(*iter));
1592 } 1592 }
1593 1593
1594 for (std::set<QPDFObjGen>::iterator iter = lc_first_page_shared.begin(); 1594 for (std::set<QPDFObjGen>::iterator iter = lc_first_page_shared.begin();
1595 - iter != lc_first_page_shared.end(); ++iter) 1595 + iter != lc_first_page_shared.end(); ++iter)
1596 { 1596 {
1597 - this->m->part6.push_back(objGenToIndirect(*iter)); 1597 + this->m->part6.push_back(objGenToIndirect(*iter));
1598 } 1598 }
1599 1599
1600 // Place the outline dictionary if it goes in the first page section. 1600 // Place the outline dictionary if it goes in the first page section.
1601 if (outlines_in_first_page) 1601 if (outlines_in_first_page)
1602 { 1602 {
1603 - pushOutlinesToPart(this->m->part6, lc_outlines, object_stream_data); 1603 + pushOutlinesToPart(this->m->part6, lc_outlines, object_stream_data);
1604 } 1604 }
1605 1605
1606 // Fill in page offset hint table information for the first page. 1606 // Fill in page offset hint table information for the first page.
@@ -1617,59 +1617,59 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1617,59 +1617,59 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1617 // For each page in order: 1617 // For each page in order:
1618 for (size_t i = 1; i < toS(npages); ++i) 1618 for (size_t i = 1; i < toS(npages); ++i)
1619 { 1619 {
1620 - // Place this page's page object 1620 + // Place this page's page object
1621 1621
1622 - QPDFObjGen page_og(pages.at(i).getObjGen());  
1623 - if (! lc_other_page_private.count(page_og))  
1624 - {  
1625 - stopOnError(  
1626 - "INTERNAL ERROR: "  
1627 - "QPDF::calculateLinearizationData: page object for page " +  
1628 - QUtil::uint_to_string(i) + " not in lc_other_page_private");  
1629 - }  
1630 - lc_other_page_private.erase(page_og);  
1631 - this->m->part7.push_back(pages.at(i)); 1622 + QPDFObjGen page_og(pages.at(i).getObjGen());
  1623 + if (! lc_other_page_private.count(page_og))
  1624 + {
  1625 + stopOnError(
  1626 + "INTERNAL ERROR: "
  1627 + "QPDF::calculateLinearizationData: page object for page " +
  1628 + QUtil::uint_to_string(i) + " not in lc_other_page_private");
  1629 + }
  1630 + lc_other_page_private.erase(page_og);
  1631 + this->m->part7.push_back(pages.at(i));
1632 1632
1633 - // Place all non-shared objects referenced by this page,  
1634 - // updating the page object count for the hint table. 1633 + // Place all non-shared objects referenced by this page,
  1634 + // updating the page object count for the hint table.
1635 1635
1636 - this->m->c_page_offset_data.entries.at(i).nobjects = 1; 1636 + this->m->c_page_offset_data.entries.at(i).nobjects = 1;
1637 1637
1638 - ObjUser ou(ObjUser::ou_page, toI(i));  
1639 - if (this->m->obj_user_to_objects.count(ou) == 0) 1638 + ObjUser ou(ObjUser::ou_page, toI(i));
  1639 + if (this->m->obj_user_to_objects.count(ou) == 0)
1640 { 1640 {
1641 stopOnError("found unreferenced page while" 1641 stopOnError("found unreferenced page while"
1642 " calculating linearization data"); 1642 " calculating linearization data");
1643 } 1643 }
1644 - std::set<QPDFObjGen> ogs = this->m->obj_user_to_objects[ou];  
1645 - for (std::set<QPDFObjGen>::iterator iter = ogs.begin();  
1646 - iter != ogs.end(); ++iter)  
1647 - {  
1648 - QPDFObjGen const& og = (*iter);  
1649 - if (lc_other_page_private.count(og))  
1650 - {  
1651 - lc_other_page_private.erase(og);  
1652 - this->m->part7.push_back(objGenToIndirect(og));  
1653 - ++this->m->c_page_offset_data.entries.at(i).nobjects;  
1654 - }  
1655 - } 1644 + std::set<QPDFObjGen> ogs = this->m->obj_user_to_objects[ou];
  1645 + for (std::set<QPDFObjGen>::iterator iter = ogs.begin();
  1646 + iter != ogs.end(); ++iter)
  1647 + {
  1648 + QPDFObjGen const& og = (*iter);
  1649 + if (lc_other_page_private.count(og))
  1650 + {
  1651 + lc_other_page_private.erase(og);
  1652 + this->m->part7.push_back(objGenToIndirect(og));
  1653 + ++this->m->c_page_offset_data.entries.at(i).nobjects;
  1654 + }
  1655 + }
1656 } 1656 }
1657 // That should have covered all part7 objects. 1657 // That should have covered all part7 objects.
1658 if (! lc_other_page_private.empty()) 1658 if (! lc_other_page_private.empty())
1659 { 1659 {
1660 - stopOnError(  
1661 - "INTERNAL ERROR:"  
1662 - " QPDF::calculateLinearizationData: lc_other_page_private is "  
1663 - "not empty after generation of part7"); 1660 + stopOnError(
  1661 + "INTERNAL ERROR:"
  1662 + " QPDF::calculateLinearizationData: lc_other_page_private is "
  1663 + "not empty after generation of part7");
1664 } 1664 }
1665 1665
1666 // Part 8: other pages' shared objects 1666 // Part 8: other pages' shared objects
1667 1667
1668 // Order is unimportant. 1668 // Order is unimportant.
1669 for (std::set<QPDFObjGen>::iterator iter = lc_other_page_shared.begin(); 1669 for (std::set<QPDFObjGen>::iterator iter = lc_other_page_shared.begin();
1670 - iter != lc_other_page_shared.end(); ++iter) 1670 + iter != lc_other_page_shared.end(); ++iter)
1671 { 1671 {
1672 - this->m->part8.push_back(objGenToIndirect(*iter)); 1672 + this->m->part8.push_back(objGenToIndirect(*iter));
1673 } 1673 }
1674 1674
1675 // Part 9: other objects 1675 // Part 9: other objects
@@ -1683,21 +1683,21 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1683,21 +1683,21 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1683 1683
1684 // Place the pages tree. 1684 // Place the pages tree.
1685 std::set<QPDFObjGen> pages_ogs = 1685 std::set<QPDFObjGen> pages_ogs =
1686 - this->m->obj_user_to_objects[ObjUser(ObjUser::ou_root_key, "/Pages")]; 1686 + this->m->obj_user_to_objects[ObjUser(ObjUser::ou_root_key, "/Pages")];
1687 if (pages_ogs.empty()) 1687 if (pages_ogs.empty())
1688 { 1688 {
1689 stopOnError("found empty pages tree while" 1689 stopOnError("found empty pages tree while"
1690 " calculating linearization data"); 1690 " calculating linearization data");
1691 } 1691 }
1692 for (std::set<QPDFObjGen>::iterator iter = pages_ogs.begin(); 1692 for (std::set<QPDFObjGen>::iterator iter = pages_ogs.begin();
1693 - iter != pages_ogs.end(); ++iter) 1693 + iter != pages_ogs.end(); ++iter)
1694 { 1694 {
1695 - QPDFObjGen const& og = *iter;  
1696 - if (lc_other.count(og))  
1697 - {  
1698 - lc_other.erase(og);  
1699 - this->m->part9.push_back(objGenToIndirect(og));  
1700 - } 1695 + QPDFObjGen const& og = *iter;
  1696 + if (lc_other.count(og))
  1697 + {
  1698 + lc_other.erase(og);
  1699 + this->m->part9.push_back(objGenToIndirect(og));
  1700 + }
1701 } 1701 }
1702 1702
1703 // Place private thumbnail images in page order. Slightly more 1703 // Place private thumbnail images in page order. Slightly more
@@ -1705,67 +1705,67 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1705,67 +1705,67 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1705 // thumbnail hint tables. 1705 // thumbnail hint tables.
1706 for (size_t i = 0; i < toS(npages); ++i) 1706 for (size_t i = 0; i < toS(npages); ++i)
1707 { 1707 {
1708 - QPDFObjectHandle thumb = pages.at(i).getKey("/Thumb");  
1709 - thumb = getUncompressedObject(thumb, object_stream_data);  
1710 - if (! thumb.isNull())  
1711 - {  
1712 - // Output the thumbnail itself  
1713 - QPDFObjGen thumb_og(thumb.getObjGen());  
1714 - if (lc_thumbnail_private.count(thumb_og))  
1715 - {  
1716 - lc_thumbnail_private.erase(thumb_og);  
1717 - this->m->part9.push_back(thumb);  
1718 - }  
1719 - else  
1720 - {  
1721 - // No internal error this time...there's nothing to  
1722 - // stop this object from having been referred to  
1723 - // somewhere else outside of a page's /Thumb, and if  
1724 - // it had been, there's nothing to prevent it from  
1725 - // having been in some set other than  
1726 - // lc_thumbnail_private.  
1727 - }  
1728 - std::set<QPDFObjGen>& ogs =  
1729 - this->m->obj_user_to_objects[ 1708 + QPDFObjectHandle thumb = pages.at(i).getKey("/Thumb");
  1709 + thumb = getUncompressedObject(thumb, object_stream_data);
  1710 + if (! thumb.isNull())
  1711 + {
  1712 + // Output the thumbnail itself
  1713 + QPDFObjGen thumb_og(thumb.getObjGen());
  1714 + if (lc_thumbnail_private.count(thumb_og))
  1715 + {
  1716 + lc_thumbnail_private.erase(thumb_og);
  1717 + this->m->part9.push_back(thumb);
  1718 + }
  1719 + else
  1720 + {
  1721 + // No internal error this time...there's nothing to
  1722 + // stop this object from having been referred to
  1723 + // somewhere else outside of a page's /Thumb, and if
  1724 + // it had been, there's nothing to prevent it from
  1725 + // having been in some set other than
  1726 + // lc_thumbnail_private.
  1727 + }
  1728 + std::set<QPDFObjGen>& ogs =
  1729 + this->m->obj_user_to_objects[
1730 ObjUser(ObjUser::ou_thumb, toI(i))]; 1730 ObjUser(ObjUser::ou_thumb, toI(i))];
1731 - for (std::set<QPDFObjGen>::iterator iter = ogs.begin();  
1732 - iter != ogs.end(); ++iter)  
1733 - {  
1734 - QPDFObjGen const& og = *iter;  
1735 - if (lc_thumbnail_private.count(og))  
1736 - {  
1737 - lc_thumbnail_private.erase(og);  
1738 - this->m->part9.push_back(objGenToIndirect(og));  
1739 - }  
1740 - }  
1741 - } 1731 + for (std::set<QPDFObjGen>::iterator iter = ogs.begin();
  1732 + iter != ogs.end(); ++iter)
  1733 + {
  1734 + QPDFObjGen const& og = *iter;
  1735 + if (lc_thumbnail_private.count(og))
  1736 + {
  1737 + lc_thumbnail_private.erase(og);
  1738 + this->m->part9.push_back(objGenToIndirect(og));
  1739 + }
  1740 + }
  1741 + }
1742 } 1742 }
1743 if (! lc_thumbnail_private.empty()) 1743 if (! lc_thumbnail_private.empty())
1744 { 1744 {
1745 - stopOnError(  
1746 - "INTERNAL ERROR: "  
1747 - "QPDF::calculateLinearizationData: lc_thumbnail_private "  
1748 - "not empty after placing thumbnails"); 1745 + stopOnError(
  1746 + "INTERNAL ERROR: "
  1747 + "QPDF::calculateLinearizationData: lc_thumbnail_private "
  1748 + "not empty after placing thumbnails");
1749 } 1749 }
1750 1750
1751 // Place shared thumbnail objects 1751 // Place shared thumbnail objects
1752 for (std::set<QPDFObjGen>::iterator iter = lc_thumbnail_shared.begin(); 1752 for (std::set<QPDFObjGen>::iterator iter = lc_thumbnail_shared.begin();
1753 - iter != lc_thumbnail_shared.end(); ++iter) 1753 + iter != lc_thumbnail_shared.end(); ++iter)
1754 { 1754 {
1755 - this->m->part9.push_back(objGenToIndirect(*iter)); 1755 + this->m->part9.push_back(objGenToIndirect(*iter));
1756 } 1756 }
1757 1757
1758 // Place outlines unless in first page 1758 // Place outlines unless in first page
1759 if (! outlines_in_first_page) 1759 if (! outlines_in_first_page)
1760 { 1760 {
1761 - pushOutlinesToPart(this->m->part9, lc_outlines, object_stream_data); 1761 + pushOutlinesToPart(this->m->part9, lc_outlines, object_stream_data);
1762 } 1762 }
1763 1763
1764 // Place all remaining objects 1764 // Place all remaining objects
1765 for (std::set<QPDFObjGen>::iterator iter = lc_other.begin(); 1765 for (std::set<QPDFObjGen>::iterator iter = lc_other.begin();
1766 - iter != lc_other.end(); ++iter) 1766 + iter != lc_other.end(); ++iter)
1767 { 1767 {
1768 - this->m->part9.push_back(objGenToIndirect(*iter)); 1768 + this->m->part9.push_back(objGenToIndirect(*iter));
1769 } 1769 }
1770 1770
1771 // Make sure we got everything exactly once. 1771 // Make sure we got everything exactly once.
@@ -1776,12 +1776,12 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1776,12 +1776,12 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1776 size_t num_wanted = this->m->object_to_obj_users.size(); 1776 size_t num_wanted = this->m->object_to_obj_users.size();
1777 if (num_placed != num_wanted) 1777 if (num_placed != num_wanted)
1778 { 1778 {
1779 - stopOnError(  
1780 - "INTERNAL ERROR: QPDF::calculateLinearizationData: wrong "  
1781 - "number of objects placed (num_placed = " +  
1782 - QUtil::uint_to_string(num_placed) +  
1783 - "; number of objects: " +  
1784 - QUtil::uint_to_string(num_wanted)); 1779 + stopOnError(
  1780 + "INTERNAL ERROR: QPDF::calculateLinearizationData: wrong "
  1781 + "number of objects placed (num_placed = " +
  1782 + QUtil::uint_to_string(num_placed) +
  1783 + "; number of objects: " +
  1784 + QUtil::uint_to_string(num_wanted));
1785 } 1785 }
1786 1786
1787 // Calculate shared object hint table information including 1787 // Calculate shared object hint table information including
@@ -1800,33 +1800,33 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1800,33 +1800,33 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1800 this->m->c_shared_object_data.nshared_first_page = 1800 this->m->c_shared_object_data.nshared_first_page =
1801 toI(this->m->part6.size()); 1801 toI(this->m->part6.size());
1802 this->m->c_shared_object_data.nshared_total = 1802 this->m->c_shared_object_data.nshared_total =
1803 - this->m->c_shared_object_data.nshared_first_page + 1803 + this->m->c_shared_object_data.nshared_first_page +
1804 toI(this->m->part8.size()); 1804 toI(this->m->part8.size());
1805 1805
1806 std::vector<CHSharedObjectEntry>& shared = 1806 std::vector<CHSharedObjectEntry>& shared =
1807 - this->m->c_shared_object_data.entries; 1807 + this->m->c_shared_object_data.entries;
1808 for (std::vector<QPDFObjectHandle>::iterator iter = this->m->part6.begin(); 1808 for (std::vector<QPDFObjectHandle>::iterator iter = this->m->part6.begin();
1809 - iter != this->m->part6.end(); ++iter) 1809 + iter != this->m->part6.end(); ++iter)
1810 { 1810 {
1811 - QPDFObjectHandle& oh = *iter;  
1812 - int obj = oh.getObjectID();  
1813 - obj_to_index[obj] = toI(shared.size());  
1814 - shared.push_back(CHSharedObjectEntry(obj)); 1811 + QPDFObjectHandle& oh = *iter;
  1812 + int obj = oh.getObjectID();
  1813 + obj_to_index[obj] = toI(shared.size());
  1814 + shared.push_back(CHSharedObjectEntry(obj));
1815 } 1815 }
1816 QTC::TC("qpdf", "QPDF lin part 8 empty", this->m->part8.empty() ? 1 : 0); 1816 QTC::TC("qpdf", "QPDF lin part 8 empty", this->m->part8.empty() ? 1 : 0);
1817 if (! this->m->part8.empty()) 1817 if (! this->m->part8.empty())
1818 { 1818 {
1819 - this->m->c_shared_object_data.first_shared_obj =  
1820 - this->m->part8.at(0).getObjectID();  
1821 - for (std::vector<QPDFObjectHandle>::iterator iter =  
1822 - this->m->part8.begin();  
1823 - iter != this->m->part8.end(); ++iter)  
1824 - {  
1825 - QPDFObjectHandle& oh = *iter;  
1826 - int obj = oh.getObjectID();  
1827 - obj_to_index[obj] = toI(shared.size());  
1828 - shared.push_back(CHSharedObjectEntry(obj));  
1829 - } 1819 + this->m->c_shared_object_data.first_shared_obj =
  1820 + this->m->part8.at(0).getObjectID();
  1821 + for (std::vector<QPDFObjectHandle>::iterator iter =
  1822 + this->m->part8.begin();
  1823 + iter != this->m->part8.end(); ++iter)
  1824 + {
  1825 + QPDFObjectHandle& oh = *iter;
  1826 + int obj = oh.getObjectID();
  1827 + obj_to_index[obj] = toI(shared.size());
  1828 + shared.push_back(CHSharedObjectEntry(obj));
  1829 + }
1830 } 1830 }
1831 if (static_cast<size_t>(this->m->c_shared_object_data.nshared_total) != 1831 if (static_cast<size_t>(this->m->c_shared_object_data.nshared_total) !=
1832 this->m->c_shared_object_data.entries.size()) 1832 this->m->c_shared_object_data.entries.size())
@@ -1840,26 +1840,26 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1840,26 +1840,26 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1840 1840
1841 for (size_t i = 1; i < toS(npages); ++i) 1841 for (size_t i = 1; i < toS(npages); ++i)
1842 { 1842 {
1843 - CHPageOffsetEntry& pe = this->m->c_page_offset_data.entries.at(i);  
1844 - ObjUser ou(ObjUser::ou_page, toI(i));  
1845 - if (this->m->obj_user_to_objects.count(ou) == 0) 1843 + CHPageOffsetEntry& pe = this->m->c_page_offset_data.entries.at(i);
  1844 + ObjUser ou(ObjUser::ou_page, toI(i));
  1845 + if (this->m->obj_user_to_objects.count(ou) == 0)
1846 { 1846 {
1847 stopOnError("found unreferenced page while" 1847 stopOnError("found unreferenced page while"
1848 " calculating linearization data"); 1848 " calculating linearization data");
1849 } 1849 }
1850 - std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou];  
1851 - for (std::set<QPDFObjGen>::const_iterator iter = ogs.begin();  
1852 - iter != ogs.end(); ++iter)  
1853 - {  
1854 - QPDFObjGen const& og = *iter;  
1855 - if ((this->m->object_to_obj_users[og].size() > 1) &&  
1856 - (obj_to_index.count(og.getObj()) > 0))  
1857 - {  
1858 - int idx = obj_to_index[og.getObj()];  
1859 - ++pe.nshared_objects;  
1860 - pe.shared_identifiers.push_back(idx);  
1861 - }  
1862 - } 1850 + std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou];
  1851 + for (std::set<QPDFObjGen>::const_iterator iter = ogs.begin();
  1852 + iter != ogs.end(); ++iter)
  1853 + {
  1854 + QPDFObjGen const& og = *iter;
  1855 + if ((this->m->object_to_obj_users[og].size() > 1) &&
  1856 + (obj_to_index.count(og.getObj()) > 0))
  1857 + {
  1858 + int idx = obj_to_index[og.getObj()];
  1859 + ++pe.nshared_objects;
  1860 + pe.shared_identifiers.push_back(idx);
  1861 + }
  1862 + }
1863 } 1863 }
1864 } 1864 }
1865 1865
@@ -1873,23 +1873,23 @@ QPDF::pushOutlinesToPart( @@ -1873,23 +1873,23 @@ QPDF::pushOutlinesToPart(
1873 QPDFObjectHandle outlines = root.getKey("/Outlines"); 1873 QPDFObjectHandle outlines = root.getKey("/Outlines");
1874 if (outlines.isNull()) 1874 if (outlines.isNull())
1875 { 1875 {
1876 - return; 1876 + return;
1877 } 1877 }
1878 outlines = getUncompressedObject(outlines, object_stream_data); 1878 outlines = getUncompressedObject(outlines, object_stream_data);
1879 QPDFObjGen outlines_og(outlines.getObjGen()); 1879 QPDFObjGen outlines_og(outlines.getObjGen());
1880 QTC::TC("qpdf", "QPDF lin outlines in part", 1880 QTC::TC("qpdf", "QPDF lin outlines in part",
1881 - ((&part == (&this->m->part6)) ? 0  
1882 - : (&part == (&this->m->part9)) ? 1  
1883 - : 9999)); // can't happen 1881 + ((&part == (&this->m->part6)) ? 0
  1882 + : (&part == (&this->m->part9)) ? 1
  1883 + : 9999)); // can't happen
1884 this->m->c_outline_data.first_object = outlines_og.getObj(); 1884 this->m->c_outline_data.first_object = outlines_og.getObj();
1885 this->m->c_outline_data.nobjects = 1; 1885 this->m->c_outline_data.nobjects = 1;
1886 lc_outlines.erase(outlines_og); 1886 lc_outlines.erase(outlines_og);
1887 part.push_back(outlines); 1887 part.push_back(outlines);
1888 for (std::set<QPDFObjGen>::iterator iter = lc_outlines.begin(); 1888 for (std::set<QPDFObjGen>::iterator iter = lc_outlines.begin();
1889 - iter != lc_outlines.end(); ++iter) 1889 + iter != lc_outlines.end(); ++iter)
1890 { 1890 {
1891 - part.push_back(objGenToIndirect(*iter));  
1892 - ++this->m->c_outline_data.nobjects; 1891 + part.push_back(objGenToIndirect(*iter));
  1892 + ++this->m->c_outline_data.nobjects;
1893 } 1893 }
1894 } 1894 }
1895 1895
@@ -1934,12 +1934,12 @@ QPDF::outputLengthNextN( @@ -1934,12 +1934,12 @@ QPDF::outputLengthNextN(
1934 int length = 0; 1934 int length = 0;
1935 for (int i = 0; i < n; ++i) 1935 for (int i = 0; i < n; ++i)
1936 { 1936 {
1937 - if (lengths.count(first + i) == 0) 1937 + if (lengths.count(first + i) == 0)
1938 { 1938 {
1939 stopOnError("found item with unknown length" 1939 stopOnError("found item with unknown length"
1940 " while writing linearization data"); 1940 " while writing linearization data");
1941 } 1941 }
1942 - length += toI((*(lengths.find(first + toI(i)))).second); 1942 + length += toI((*(lengths.find(first + toI(i)))).second);
1943 } 1943 }
1944 return length; 1944 return length;
1945 } 1945 }
@@ -1966,7 +1966,7 @@ QPDF::calculateHPageOffset( @@ -1966,7 +1966,7 @@ QPDF::calculateHPageOffset(
1966 int min_nobjects = cphe.at(0).nobjects; 1966 int min_nobjects = cphe.at(0).nobjects;
1967 int max_nobjects = min_nobjects; 1967 int max_nobjects = min_nobjects;
1968 int min_length = outputLengthNextN( 1968 int min_length = outputLengthNextN(
1969 - pages.at(0).getObjectID(), min_nobjects, lengths, obj_renumber); 1969 + pages.at(0).getObjectID(), min_nobjects, lengths, obj_renumber);
1970 int max_length = min_length; 1970 int max_length = min_length;
1971 int max_shared = cphe.at(0).nshared_objects; 1971 int max_shared = cphe.at(0).nshared_objects;
1972 1972
@@ -1977,26 +1977,26 @@ QPDF::calculateHPageOffset( @@ -1977,26 +1977,26 @@ QPDF::calculateHPageOffset(
1977 1977
1978 for (unsigned int i = 0; i < npages; ++i) 1978 for (unsigned int i = 0; i < npages; ++i)
1979 { 1979 {
1980 - // Calculate values for each page, assigning full values to  
1981 - // the delta items. They will be adjusted later. 1980 + // Calculate values for each page, assigning full values to
  1981 + // the delta items. They will be adjusted later.
1982 1982
1983 - // Repeat calculations for page 0 so we can assign to phe[i]  
1984 - // without duplicating those assignments. 1983 + // Repeat calculations for page 0 so we can assign to phe[i]
  1984 + // without duplicating those assignments.
1985 1985
1986 - int nobjects = cphe.at(i).nobjects;  
1987 - int length = outputLengthNextN(  
1988 - pages.at(i).getObjectID(), nobjects, lengths, obj_renumber);  
1989 - int nshared = cphe.at(i).nshared_objects; 1986 + int nobjects = cphe.at(i).nobjects;
  1987 + int length = outputLengthNextN(
  1988 + pages.at(i).getObjectID(), nobjects, lengths, obj_renumber);
  1989 + int nshared = cphe.at(i).nshared_objects;
1990 1990
1991 - min_nobjects = std::min(min_nobjects, nobjects);  
1992 - max_nobjects = std::max(max_nobjects, nobjects);  
1993 - min_length = std::min(min_length, length);  
1994 - max_length = std::max(max_length, length);  
1995 - max_shared = std::max(max_shared, nshared); 1991 + min_nobjects = std::min(min_nobjects, nobjects);
  1992 + max_nobjects = std::max(max_nobjects, nobjects);
  1993 + min_length = std::min(min_length, length);
  1994 + max_length = std::max(max_length, length);
  1995 + max_shared = std::max(max_shared, nshared);
1996 1996
1997 - phe.at(i).delta_nobjects = nobjects;  
1998 - phe.at(i).delta_page_length = length;  
1999 - phe.at(i).nshared_objects = nshared; 1997 + phe.at(i).delta_nobjects = nobjects;
  1998 + phe.at(i).delta_page_length = length;
  1999 + phe.at(i).nshared_objects = nshared;
2000 } 2000 }
2001 2001
2002 ph.min_nobjects = min_nobjects; 2002 ph.min_nobjects = min_nobjects;
@@ -2008,8 +2008,8 @@ QPDF::calculateHPageOffset( @@ -2008,8 +2008,8 @@ QPDF::calculateHPageOffset(
2008 ph.nbits_delta_page_length = nbits(max_length - min_length); 2008 ph.nbits_delta_page_length = nbits(max_length - min_length);
2009 ph.nbits_nshared_objects = nbits(max_shared); 2009 ph.nbits_nshared_objects = nbits(max_shared);
2010 ph.nbits_shared_identifier = 2010 ph.nbits_shared_identifier =
2011 - nbits(this->m->c_shared_object_data.nshared_total);  
2012 - ph.shared_denominator = 4; // doesn't matter 2011 + nbits(this->m->c_shared_object_data.nshared_total);
  2012 + ph.shared_denominator = 4; // doesn't matter
2013 2013
2014 // It isn't clear how to compute content offset and content 2014 // It isn't clear how to compute content offset and content
2015 // length. Since we are not interleaving page objects with the 2015 // length. Since we are not interleaving page objects with the
@@ -2021,23 +2021,23 @@ QPDF::calculateHPageOffset( @@ -2021,23 +2021,23 @@ QPDF::calculateHPageOffset(
2021 2021
2022 for (size_t i = 0; i < npages; ++i) 2022 for (size_t i = 0; i < npages; ++i)
2023 { 2023 {
2024 - // Adjust delta entries  
2025 - if ((phe.at(i).delta_nobjects < min_nobjects) || 2024 + // Adjust delta entries
  2025 + if ((phe.at(i).delta_nobjects < min_nobjects) ||
2026 (phe.at(i).delta_page_length < min_length)) 2026 (phe.at(i).delta_page_length < min_length))
2027 { 2027 {
2028 stopOnError("found too small delta nobjects or delta page length" 2028 stopOnError("found too small delta nobjects or delta page length"
2029 " while writing linearization data"); 2029 " while writing linearization data");
2030 } 2030 }
2031 - phe.at(i).delta_nobjects -= min_nobjects;  
2032 - phe.at(i).delta_page_length -= min_length;  
2033 - phe.at(i).delta_content_length = phe.at(i).delta_page_length; 2031 + phe.at(i).delta_nobjects -= min_nobjects;
  2032 + phe.at(i).delta_page_length -= min_length;
  2033 + phe.at(i).delta_content_length = phe.at(i).delta_page_length;
2034 2034
2035 - for (size_t j = 0; j < toS(cphe.at(i).nshared_objects); ++j)  
2036 - {  
2037 - phe.at(i).shared_identifiers.push_back(  
2038 - cphe.at(i).shared_identifiers.at(j));  
2039 - phe.at(i).shared_numerators.push_back(0);  
2040 - } 2035 + for (size_t j = 0; j < toS(cphe.at(i).nshared_objects); ++j)
  2036 + {
  2037 + phe.at(i).shared_identifiers.push_back(
  2038 + cphe.at(i).shared_identifiers.at(j));
  2039 + phe.at(i).shared_numerators.push_back(0);
  2040 + }
2041 } 2041 }
2042 } 2042 }
2043 2043
@@ -2054,18 +2054,18 @@ QPDF::calculateHSharedObject( @@ -2054,18 +2054,18 @@ QPDF::calculateHSharedObject(
2054 soe.clear(); 2054 soe.clear();
2055 2055
2056 int min_length = outputLengthNextN( 2056 int min_length = outputLengthNextN(
2057 - csoe.at(0).object, 1, lengths, obj_renumber); 2057 + csoe.at(0).object, 1, lengths, obj_renumber);
2058 int max_length = min_length; 2058 int max_length = min_length;
2059 2059
2060 for (size_t i = 0; i < toS(cso.nshared_total); ++i) 2060 for (size_t i = 0; i < toS(cso.nshared_total); ++i)
2061 { 2061 {
2062 - // Assign absolute numbers to deltas; adjust later  
2063 - int length = outputLengthNextN(  
2064 - csoe.at(i).object, 1, lengths, obj_renumber);  
2065 - min_length = std::min(min_length, length);  
2066 - max_length = std::max(max_length, length); 2062 + // Assign absolute numbers to deltas; adjust later
  2063 + int length = outputLengthNextN(
  2064 + csoe.at(i).object, 1, lengths, obj_renumber);
  2065 + min_length = std::min(min_length, length);
  2066 + max_length = std::max(max_length, length);
2067 soe.push_back(HSharedObjectEntry()); 2067 soe.push_back(HSharedObjectEntry());
2068 - soe.at(i).delta_group_length = length; 2068 + soe.at(i).delta_group_length = length;
2069 } 2069 }
2070 if (soe.size() != QIntC::to_size(cso.nshared_total)) 2070 if (soe.size() != QIntC::to_size(cso.nshared_total))
2071 { 2071 {
@@ -2076,23 +2076,23 @@ QPDF::calculateHSharedObject( @@ -2076,23 +2076,23 @@ QPDF::calculateHSharedObject(
2076 so.nshared_first_page = cso.nshared_first_page; 2076 so.nshared_first_page = cso.nshared_first_page;
2077 if (so.nshared_total > so.nshared_first_page) 2077 if (so.nshared_total > so.nshared_first_page)
2078 { 2078 {
2079 - so.first_shared_obj =  
2080 - (*(obj_renumber.find(cso.first_shared_obj))).second;  
2081 - so.first_shared_offset =  
2082 - (*(xref.find(so.first_shared_obj))).second.getOffset(); 2079 + so.first_shared_obj =
  2080 + (*(obj_renumber.find(cso.first_shared_obj))).second;
  2081 + so.first_shared_offset =
  2082 + (*(xref.find(so.first_shared_obj))).second.getOffset();
2083 } 2083 }
2084 so.min_group_length = min_length; 2084 so.min_group_length = min_length;
2085 so.nbits_delta_group_length = nbits(max_length - min_length); 2085 so.nbits_delta_group_length = nbits(max_length - min_length);
2086 2086
2087 for (size_t i = 0; i < toS(cso.nshared_total); ++i) 2087 for (size_t i = 0; i < toS(cso.nshared_total); ++i)
2088 { 2088 {
2089 - // Adjust deltas  
2090 - if (soe.at(i).delta_group_length < min_length) 2089 + // Adjust deltas
  2090 + if (soe.at(i).delta_group_length < min_length)
2091 { 2091 {
2092 stopOnError("found too small group length while" 2092 stopOnError("found too small group length while"
2093 " writing linearization data"); 2093 " writing linearization data");
2094 } 2094 }
2095 - soe.at(i).delta_group_length -= min_length; 2095 + soe.at(i).delta_group_length -= min_length;
2096 } 2096 }
2097 } 2097 }
2098 2098
@@ -2106,31 +2106,31 @@ QPDF::calculateHOutline( @@ -2106,31 +2106,31 @@ QPDF::calculateHOutline(
2106 2106
2107 if (cho.nobjects == 0) 2107 if (cho.nobjects == 0)
2108 { 2108 {
2109 - return; 2109 + return;
2110 } 2110 }
2111 2111
2112 HGeneric& ho = this->m->outline_hints; 2112 HGeneric& ho = this->m->outline_hints;
2113 2113
2114 ho.first_object = 2114 ho.first_object =
2115 - (*(obj_renumber.find(cho.first_object))).second; 2115 + (*(obj_renumber.find(cho.first_object))).second;
2116 ho.first_object_offset = 2116 ho.first_object_offset =
2117 - (*(xref.find(ho.first_object))).second.getOffset(); 2117 + (*(xref.find(ho.first_object))).second.getOffset();
2118 ho.nobjects = cho.nobjects; 2118 ho.nobjects = cho.nobjects;
2119 ho.group_length = outputLengthNextN( 2119 ho.group_length = outputLengthNextN(
2120 - cho.first_object, ho.nobjects, lengths, obj_renumber); 2120 + cho.first_object, ho.nobjects, lengths, obj_renumber);
2121 } 2121 }
2122 2122
2123 template <class T, class int_type> 2123 template <class T, class int_type>
2124 static void 2124 static void
2125 write_vector_int(BitWriter& w, int nitems, std::vector<T>& vec, 2125 write_vector_int(BitWriter& w, int nitems, std::vector<T>& vec,
2126 - int bits, int_type T::*field) 2126 + int bits, int_type T::*field)
2127 { 2127 {
2128 // nitems times, write bits bits from the given field of the ith 2128 // nitems times, write bits bits from the given field of the ith
2129 // vector to the given bit writer. 2129 // vector to the given bit writer.
2130 2130
2131 for (size_t i = 0; i < QIntC::to_size(nitems); ++i) 2131 for (size_t i = 0; i < QIntC::to_size(nitems); ++i)
2132 { 2132 {
2133 - w.writeBits(QIntC::to_ulonglong(vec.at(i).*field), 2133 + w.writeBits(QIntC::to_ulonglong(vec.at(i).*field),
2134 QIntC::to_size(bits)); 2134 QIntC::to_size(bits));
2135 } 2135 }
2136 // The PDF spec says that each hint table starts at a byte 2136 // The PDF spec says that each hint table starts at a byte
@@ -2141,18 +2141,18 @@ write_vector_int(BitWriter&amp; w, int nitems, std::vector&lt;T&gt;&amp; vec, @@ -2141,18 +2141,18 @@ write_vector_int(BitWriter&amp; w, int nitems, std::vector&lt;T&gt;&amp; vec,
2141 template <class T> 2141 template <class T>
2142 static void 2142 static void
2143 write_vector_vector(BitWriter& w, 2143 write_vector_vector(BitWriter& w,
2144 - int nitems1, std::vector<T>& vec1, int T::*nitems2,  
2145 - int bits, std::vector<int> T::*vec2) 2144 + int nitems1, std::vector<T>& vec1, int T::*nitems2,
  2145 + int bits, std::vector<int> T::*vec2)
2146 { 2146 {
2147 // nitems1 times, write nitems2 (from the ith element of vec1) items 2147 // nitems1 times, write nitems2 (from the ith element of vec1) items
2148 // from the vec2 vector field of the ith item of vec1. 2148 // from the vec2 vector field of the ith item of vec1.
2149 for (size_t i1 = 0; i1 < QIntC::to_size(nitems1); ++i1) 2149 for (size_t i1 = 0; i1 < QIntC::to_size(nitems1); ++i1)
2150 { 2150 {
2151 - for (size_t i2 = 0; i2 < QIntC::to_size(vec1.at(i1).*nitems2); ++i2)  
2152 - {  
2153 - w.writeBits(QIntC::to_ulonglong((vec1.at(i1).*vec2).at(i2)), 2151 + for (size_t i2 = 0; i2 < QIntC::to_size(vec1.at(i1).*nitems2); ++i2)
  2152 + {
  2153 + w.writeBits(QIntC::to_ulonglong((vec1.at(i1).*vec2).at(i2)),
2154 QIntC::to_size(bits)); 2154 QIntC::to_size(bits));
2155 - } 2155 + }
2156 } 2156 }
2157 w.flush(); 2157 w.flush();
2158 } 2158 }
@@ -2181,28 +2181,28 @@ QPDF::writeHPageOffset(BitWriter&amp; w) @@ -2181,28 +2181,28 @@ QPDF::writeHPageOffset(BitWriter&amp; w)
2181 std::vector<HPageOffsetEntry>& entries = t.entries; 2181 std::vector<HPageOffsetEntry>& entries = t.entries;
2182 2182
2183 write_vector_int(w, nitems, entries, 2183 write_vector_int(w, nitems, entries,
2184 - t.nbits_delta_nobjects,  
2185 - &HPageOffsetEntry::delta_nobjects); 2184 + t.nbits_delta_nobjects,
  2185 + &HPageOffsetEntry::delta_nobjects);
2186 write_vector_int(w, nitems, entries, 2186 write_vector_int(w, nitems, entries,
2187 - t.nbits_delta_page_length,  
2188 - &HPageOffsetEntry::delta_page_length); 2187 + t.nbits_delta_page_length,
  2188 + &HPageOffsetEntry::delta_page_length);
2189 write_vector_int(w, nitems, entries, 2189 write_vector_int(w, nitems, entries,
2190 - t.nbits_nshared_objects,  
2191 - &HPageOffsetEntry::nshared_objects); 2190 + t.nbits_nshared_objects,
  2191 + &HPageOffsetEntry::nshared_objects);
2192 write_vector_vector(w, nitems, entries, 2192 write_vector_vector(w, nitems, entries,
2193 - &HPageOffsetEntry::nshared_objects,  
2194 - t.nbits_shared_identifier,  
2195 - &HPageOffsetEntry::shared_identifiers); 2193 + &HPageOffsetEntry::nshared_objects,
  2194 + t.nbits_shared_identifier,
  2195 + &HPageOffsetEntry::shared_identifiers);
2196 write_vector_vector(w, nitems, entries, 2196 write_vector_vector(w, nitems, entries,
2197 - &HPageOffsetEntry::nshared_objects,  
2198 - t.nbits_shared_numerator,  
2199 - &HPageOffsetEntry::shared_numerators); 2197 + &HPageOffsetEntry::nshared_objects,
  2198 + t.nbits_shared_numerator,
  2199 + &HPageOffsetEntry::shared_numerators);
2200 write_vector_int(w, nitems, entries, 2200 write_vector_int(w, nitems, entries,
2201 - t.nbits_delta_content_offset,  
2202 - &HPageOffsetEntry::delta_content_offset); 2201 + t.nbits_delta_content_offset,
  2202 + &HPageOffsetEntry::delta_content_offset);
2203 write_vector_int(w, nitems, entries, 2203 write_vector_int(w, nitems, entries,
2204 - t.nbits_delta_content_length,  
2205 - &HPageOffsetEntry::delta_content_length); 2204 + t.nbits_delta_content_length,
  2205 + &HPageOffsetEntry::delta_content_length);
2206 } 2206 }
2207 2207
2208 void 2208 void
@@ -2219,28 +2219,28 @@ QPDF::writeHSharedObject(BitWriter&amp; w) @@ -2219,28 +2219,28 @@ QPDF::writeHSharedObject(BitWriter&amp; w)
2219 w.writeBitsInt(t.nbits_delta_group_length, 16); // 7 2219 w.writeBitsInt(t.nbits_delta_group_length, 16); // 7
2220 2220
2221 QTC::TC("qpdf", "QPDF lin write nshared_total > nshared_first_page", 2221 QTC::TC("qpdf", "QPDF lin write nshared_total > nshared_first_page",
2222 - (t.nshared_total > t.nshared_first_page) ? 1 : 0); 2222 + (t.nshared_total > t.nshared_first_page) ? 1 : 0);
2223 2223
2224 int nitems = t.nshared_total; 2224 int nitems = t.nshared_total;
2225 std::vector<HSharedObjectEntry>& entries = t.entries; 2225 std::vector<HSharedObjectEntry>& entries = t.entries;
2226 2226
2227 write_vector_int(w, nitems, entries, 2227 write_vector_int(w, nitems, entries,
2228 - t.nbits_delta_group_length,  
2229 - &HSharedObjectEntry::delta_group_length); 2228 + t.nbits_delta_group_length,
  2229 + &HSharedObjectEntry::delta_group_length);
2230 write_vector_int(w, nitems, entries, 2230 write_vector_int(w, nitems, entries,
2231 - 1, &HSharedObjectEntry::signature_present); 2231 + 1, &HSharedObjectEntry::signature_present);
2232 for (size_t i = 0; i < toS(nitems); ++i) 2232 for (size_t i = 0; i < toS(nitems); ++i)
2233 { 2233 {
2234 - // If signature were present, we'd have to write a 128-bit hash.  
2235 - if (entries.at(i).signature_present != 0) 2234 + // If signature were present, we'd have to write a 128-bit hash.
  2235 + if (entries.at(i).signature_present != 0)
2236 { 2236 {
2237 stopOnError("found unexpected signature present" 2237 stopOnError("found unexpected signature present"
2238 " while writing linearization data"); 2238 " while writing linearization data");
2239 } 2239 }
2240 } 2240 }
2241 write_vector_int(w, nitems, entries, 2241 write_vector_int(w, nitems, entries,
2242 - t.nbits_nobjects,  
2243 - &HSharedObjectEntry::nobjects_minus_one); 2242 + t.nbits_nobjects,
  2243 + &HSharedObjectEntry::nobjects_minus_one);
2244 } 2244 }
2245 2245
2246 void 2246 void
@@ -2254,10 +2254,10 @@ QPDF::writeHGeneric(BitWriter&amp; w, HGeneric&amp; t) @@ -2254,10 +2254,10 @@ QPDF::writeHGeneric(BitWriter&amp; w, HGeneric&amp; t)
2254 2254
2255 void 2255 void
2256 QPDF::generateHintStream(std::map<int, QPDFXRefEntry> const& xref, 2256 QPDF::generateHintStream(std::map<int, QPDFXRefEntry> const& xref,
2257 - std::map<int, qpdf_offset_t> const& lengths,  
2258 - std::map<int, int> const& obj_renumber,  
2259 - PointerHolder<Buffer>& hint_buffer,  
2260 - int& S, int& O) 2257 + std::map<int, qpdf_offset_t> const& lengths,
  2258 + std::map<int, int> const& obj_renumber,
  2259 + PointerHolder<Buffer>& hint_buffer,
  2260 + int& S, int& O)
2261 { 2261 {
2262 // Populate actual hint table values 2262 // Populate actual hint table values
2263 calculateHPageOffset(xref, lengths, obj_renumber); 2263 calculateHPageOffset(xref, lengths, obj_renumber);
@@ -2277,8 +2277,8 @@ QPDF::generateHintStream(std::map&lt;int, QPDFXRefEntry&gt; const&amp; xref, @@ -2277,8 +2277,8 @@ QPDF::generateHintStream(std::map&lt;int, QPDFXRefEntry&gt; const&amp; xref,
2277 O = 0; 2277 O = 0;
2278 if (this->m->outline_hints.nobjects > 0) 2278 if (this->m->outline_hints.nobjects > 0)
2279 { 2279 {
2280 - O = toI(c.getCount());  
2281 - writeHGeneric(w, this->m->outline_hints); 2280 + O = toI(c.getCount());
  2281 + writeHGeneric(w, this->m->outline_hints);
2282 } 2282 }
2283 c.finish(); 2283 c.finish();
2284 2284
libqpdf/QPDF_optimization.cc
@@ -41,18 +41,18 @@ QPDF::ObjUser::operator&lt;(ObjUser const&amp; rhs) const @@ -41,18 +41,18 @@ QPDF::ObjUser::operator&lt;(ObjUser const&amp; rhs) const
41 { 41 {
42 if (this->ou_type < rhs.ou_type) 42 if (this->ou_type < rhs.ou_type)
43 { 43 {
44 - return true; 44 + return true;
45 } 45 }
46 else if (this->ou_type == rhs.ou_type) 46 else if (this->ou_type == rhs.ou_type)
47 { 47 {
48 - if (this->pageno < rhs.pageno)  
49 - {  
50 - return true;  
51 - }  
52 - else if (this->pageno == rhs.pageno)  
53 - {  
54 - return (this->key < rhs.key);  
55 - } 48 + if (this->pageno < rhs.pageno)
  49 + {
  50 + return true;
  51 + }
  52 + else if (this->pageno == rhs.pageno)
  53 + {
  54 + return (this->key < rhs.key);
  55 + }
56 } 56 }
57 57
58 return false; 58 return false;
@@ -60,20 +60,20 @@ QPDF::ObjUser::operator&lt;(ObjUser const&amp; rhs) const @@ -60,20 +60,20 @@ QPDF::ObjUser::operator&lt;(ObjUser const&amp; rhs) const
60 60
61 void 61 void
62 QPDF::optimize(std::map<int, int> const& object_stream_data, 62 QPDF::optimize(std::map<int, int> const& object_stream_data,
63 - bool allow_changes) 63 + bool allow_changes)
64 { 64 {
65 optimize(object_stream_data, allow_changes, nullptr); 65 optimize(object_stream_data, allow_changes, nullptr);
66 } 66 }
67 67
68 void 68 void
69 QPDF::optimize(std::map<int, int> const& object_stream_data, 69 QPDF::optimize(std::map<int, int> const& object_stream_data,
70 - bool allow_changes, 70 + bool allow_changes,
71 std::function<int(QPDFObjectHandle&)> skip_stream_parameters) 71 std::function<int(QPDFObjectHandle&)> skip_stream_parameters)
72 { 72 {
73 if (! this->m->obj_user_to_objects.empty()) 73 if (! this->m->obj_user_to_objects.empty())
74 { 74 {
75 - // already optimized  
76 - return; 75 + // already optimized
  76 + return;
77 } 77 }
78 78
79 // The PDF specification indicates that /Outlines is supposed to 79 // The PDF specification indicates that /Outlines is supposed to
@@ -106,35 +106,35 @@ QPDF::optimize(std::map&lt;int, int&gt; const&amp; object_stream_data, @@ -106,35 +106,35 @@ QPDF::optimize(std::map&lt;int, int&gt; const&amp; object_stream_data,
106 // Traverse document-level items 106 // Traverse document-level items
107 std::set<std::string> keys = this->m->trailer.getKeys(); 107 std::set<std::string> keys = this->m->trailer.getKeys();
108 for (std::set<std::string>::iterator iter = keys.begin(); 108 for (std::set<std::string>::iterator iter = keys.begin();
109 - iter != keys.end(); ++iter) 109 + iter != keys.end(); ++iter)
110 { 110 {
111 - std::string const& key = *iter;  
112 - if (key == "/Root")  
113 - {  
114 - // handled separately  
115 - }  
116 - else  
117 - {  
118 - updateObjectMaps(ObjUser(ObjUser::ou_trailer_key, key),  
119 - this->m->trailer.getKey(key), 111 + std::string const& key = *iter;
  112 + if (key == "/Root")
  113 + {
  114 + // handled separately
  115 + }
  116 + else
  117 + {
  118 + updateObjectMaps(ObjUser(ObjUser::ou_trailer_key, key),
  119 + this->m->trailer.getKey(key),
120 skip_stream_parameters); 120 skip_stream_parameters);
121 - } 121 + }
122 } 122 }
123 123
124 keys = root.getKeys(); 124 keys = root.getKeys();
125 for (std::set<std::string>::iterator iter = keys.begin(); 125 for (std::set<std::string>::iterator iter = keys.begin();
126 - iter != keys.end(); ++iter) 126 + iter != keys.end(); ++iter)
127 { 127 {
128 - // Technically, /I keys from /Thread dictionaries are supposed  
129 - // to be handled separately, but we are going to disregard  
130 - // that specification for now. There is loads of evidence  
131 - // that pdlin and Acrobat both disregard things like this from  
132 - // time to time, so this is almost certain not to cause any  
133 - // problems.  
134 -  
135 - std::string const& key = *iter;  
136 - updateObjectMaps(ObjUser(ObjUser::ou_root_key, key),  
137 - root.getKey(key), 128 + // Technically, /I keys from /Thread dictionaries are supposed
  129 + // to be handled separately, but we are going to disregard
  130 + // that specification for now. There is loads of evidence
  131 + // that pdlin and Acrobat both disregard things like this from
  132 + // time to time, so this is almost certain not to cause any
  133 + // problems.
  134 +
  135 + std::string const& key = *iter;
  136 + updateObjectMaps(ObjUser(ObjUser::ou_root_key, key),
  137 + root.getKey(key),
138 skip_stream_parameters); 138 skip_stream_parameters);
139 } 139 }
140 140
@@ -208,10 +208,10 @@ QPDF::pushInheritedAttributesToPageInternal( @@ -208,10 +208,10 @@ QPDF::pushInheritedAttributesToPageInternal(
208 208
209 if (! cur_pages.isDictionary()) 209 if (! cur_pages.isDictionary())
210 { 210 {
211 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
212 - this->m->last_object_description,  
213 - this->m->file->getLastOffset(),  
214 - "invalid object in page tree"); 211 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  212 + this->m->last_object_description,
  213 + this->m->file->getLastOffset(),
  214 + "invalid object in page tree");
215 } 215 }
216 216
217 // Extract the underlying dictionary object 217 // Extract the underlying dictionary object
@@ -219,60 +219,60 @@ QPDF::pushInheritedAttributesToPageInternal( @@ -219,60 +219,60 @@ QPDF::pushInheritedAttributesToPageInternal(
219 219
220 if (type == "/Pages") 220 if (type == "/Pages")
221 { 221 {
222 - // Make a list of inheritable keys. Only the keys /MediaBox,  
223 - // /CropBox, /Resources, and /Rotate are inheritable  
224 - // attributes. Push this object onto the stack of pages nodes  
225 - // that have values for this attribute.  
226 -  
227 - std::set<std::string> inheritable_keys;  
228 - std::set<std::string> keys = cur_pages.getKeys();  
229 - for (std::set<std::string>::iterator iter = keys.begin();  
230 - iter != keys.end(); ++iter)  
231 - {  
232 - std::string const& key = *iter; 222 + // Make a list of inheritable keys. Only the keys /MediaBox,
  223 + // /CropBox, /Resources, and /Rotate are inheritable
  224 + // attributes. Push this object onto the stack of pages nodes
  225 + // that have values for this attribute.
  226 +
  227 + std::set<std::string> inheritable_keys;
  228 + std::set<std::string> keys = cur_pages.getKeys();
  229 + for (std::set<std::string>::iterator iter = keys.begin();
  230 + iter != keys.end(); ++iter)
  231 + {
  232 + std::string const& key = *iter;
233 if ( (key == "/MediaBox") || (key == "/CropBox") || 233 if ( (key == "/MediaBox") || (key == "/CropBox") ||
234 (key == "/Resources") || (key == "/Rotate") ) 234 (key == "/Resources") || (key == "/Rotate") )
235 - {  
236 - if (! allow_changes)  
237 - {  
238 - throw QPDFExc(qpdf_e_internal, this->m->file->getName(),  
239 - this->m->last_object_description,  
240 - this->m->file->getLastOffset(),  
241 - "optimize detected an " 235 + {
  236 + if (! allow_changes)
  237 + {
  238 + throw QPDFExc(qpdf_e_internal, this->m->file->getName(),
  239 + this->m->last_object_description,
  240 + this->m->file->getLastOffset(),
  241 + "optimize detected an "
242 "inheritable attribute when called " 242 "inheritable attribute when called "
243 - "in no-change mode");  
244 - }  
245 -  
246 - // This is an inheritable resource  
247 - inheritable_keys.insert(key);  
248 - QPDFObjectHandle oh = cur_pages.getKey(key);  
249 - QTC::TC("qpdf", "QPDF opt direct pages resource",  
250 - oh.isIndirect() ? 0 : 1);  
251 - if (! oh.isIndirect())  
252 - {  
253 - if (! oh.isScalar())  
254 - {  
255 - // Replace shared direct object non-scalar  
256 - // resources with indirect objects to avoid  
257 - // copying large structures around.  
258 - cur_pages.replaceKey(key, makeIndirectObject(oh));  
259 - oh = cur_pages.getKey(key);  
260 - }  
261 - else  
262 - {  
263 - // It's okay to copy scalars.  
264 - QTC::TC("qpdf", "QPDF opt inherited scalar");  
265 - }  
266 - }  
267 - key_ancestors[key].push_back(oh);  
268 - if (key_ancestors[key].size() > 1)  
269 - {  
270 - QTC::TC("qpdf", "QPDF opt key ancestors depth > 1");  
271 - }  
272 - // Remove this resource from this node. It will be  
273 - // reattached at the page level.  
274 - cur_pages.removeKey(key);  
275 - } 243 + "in no-change mode");
  244 + }
  245 +
  246 + // This is an inheritable resource
  247 + inheritable_keys.insert(key);
  248 + QPDFObjectHandle oh = cur_pages.getKey(key);
  249 + QTC::TC("qpdf", "QPDF opt direct pages resource",
  250 + oh.isIndirect() ? 0 : 1);
  251 + if (! oh.isIndirect())
  252 + {
  253 + if (! oh.isScalar())
  254 + {
  255 + // Replace shared direct object non-scalar
  256 + // resources with indirect objects to avoid
  257 + // copying large structures around.
  258 + cur_pages.replaceKey(key, makeIndirectObject(oh));
  259 + oh = cur_pages.getKey(key);
  260 + }
  261 + else
  262 + {
  263 + // It's okay to copy scalars.
  264 + QTC::TC("qpdf", "QPDF opt inherited scalar");
  265 + }
  266 + }
  267 + key_ancestors[key].push_back(oh);
  268 + if (key_ancestors[key].size() > 1)
  269 + {
  270 + QTC::TC("qpdf", "QPDF opt key ancestors depth > 1");
  271 + }
  272 + // Remove this resource from this node. It will be
  273 + // reattached at the page level.
  274 + cur_pages.removeKey(key);
  275 + }
276 else if (! ((key == "/Type") || (key == "/Parent") || 276 else if (! ((key == "/Type") || (key == "/Parent") ||
277 (key == "/Kids") || (key == "/Count"))) 277 (key == "/Kids") || (key == "/Count")))
278 { 278 {
@@ -292,71 +292,71 @@ QPDF::pushInheritedAttributesToPageInternal( @@ -292,71 +292,71 @@ QPDF::pushInheritedAttributesToPageInternal(
292 " flattening the /Pages tree")); 292 " flattening the /Pages tree"));
293 } 293 }
294 } 294 }
295 - } 295 + }
296 296
297 - // Visit descendant nodes.  
298 - QPDFObjectHandle kids = cur_pages.getKey("/Kids");  
299 - int n = kids.getArrayNItems();  
300 - for (int i = 0; i < n; ++i)  
301 - { 297 + // Visit descendant nodes.
  298 + QPDFObjectHandle kids = cur_pages.getKey("/Kids");
  299 + int n = kids.getArrayNItems();
  300 + for (int i = 0; i < n; ++i)
  301 + {
302 pushInheritedAttributesToPageInternal( 302 pushInheritedAttributesToPageInternal(
303 kids.getArrayItem(i), key_ancestors, pages, 303 kids.getArrayItem(i), key_ancestors, pages,
304 allow_changes, warn_skipped_keys, visited); 304 allow_changes, warn_skipped_keys, visited);
305 - }  
306 -  
307 - // For each inheritable key, pop the stack. If the stack  
308 - // becomes empty, remove it from the map. That way, the  
309 - // invariant that the list of keys in key_ancestors is exactly  
310 - // those keys for which inheritable attributes are available.  
311 -  
312 - if (! inheritable_keys.empty())  
313 - {  
314 - QTC::TC("qpdf", "QPDF opt inheritable keys");  
315 - for (std::set<std::string>::iterator iter =  
316 - inheritable_keys.begin();  
317 - iter != inheritable_keys.end(); ++iter)  
318 - {  
319 - std::string const& key = (*iter);  
320 - key_ancestors[key].pop_back();  
321 - if (key_ancestors[key].empty())  
322 - {  
323 - QTC::TC("qpdf", "QPDF opt erase empty key ancestor");  
324 - key_ancestors.erase(key);  
325 - }  
326 - }  
327 - }  
328 - else  
329 - {  
330 - QTC::TC("qpdf", "QPDF opt no inheritable keys");  
331 - } 305 + }
  306 +
  307 + // For each inheritable key, pop the stack. If the stack
  308 + // becomes empty, remove it from the map. That way, the
  309 + // invariant that the list of keys in key_ancestors is exactly
  310 + // those keys for which inheritable attributes are available.
  311 +
  312 + if (! inheritable_keys.empty())
  313 + {
  314 + QTC::TC("qpdf", "QPDF opt inheritable keys");
  315 + for (std::set<std::string>::iterator iter =
  316 + inheritable_keys.begin();
  317 + iter != inheritable_keys.end(); ++iter)
  318 + {
  319 + std::string const& key = (*iter);
  320 + key_ancestors[key].pop_back();
  321 + if (key_ancestors[key].empty())
  322 + {
  323 + QTC::TC("qpdf", "QPDF opt erase empty key ancestor");
  324 + key_ancestors.erase(key);
  325 + }
  326 + }
  327 + }
  328 + else
  329 + {
  330 + QTC::TC("qpdf", "QPDF opt no inheritable keys");
  331 + }
332 } 332 }
333 else if (type == "/Page") 333 else if (type == "/Page")
334 { 334 {
335 - // Add all available inheritable attributes not present in  
336 - // this object to this object.  
337 - for (std::map<std::string, std::vector<QPDFObjectHandle> >::iterator  
338 - iter = key_ancestors.begin();  
339 - iter != key_ancestors.end(); ++iter)  
340 - {  
341 - std::string const& key = (*iter).first;  
342 - if (! cur_pages.hasKey(key))  
343 - {  
344 - QTC::TC("qpdf", "QPDF opt resource inherited");  
345 - cur_pages.replaceKey(key, (*iter).second.back());  
346 - }  
347 - else  
348 - {  
349 - QTC::TC("qpdf", "QPDF opt page resource hides ancestor");  
350 - }  
351 - } 335 + // Add all available inheritable attributes not present in
  336 + // this object to this object.
  337 + for (std::map<std::string, std::vector<QPDFObjectHandle> >::iterator
  338 + iter = key_ancestors.begin();
  339 + iter != key_ancestors.end(); ++iter)
  340 + {
  341 + std::string const& key = (*iter).first;
  342 + if (! cur_pages.hasKey(key))
  343 + {
  344 + QTC::TC("qpdf", "QPDF opt resource inherited");
  345 + cur_pages.replaceKey(key, (*iter).second.back());
  346 + }
  347 + else
  348 + {
  349 + QTC::TC("qpdf", "QPDF opt page resource hides ancestor");
  350 + }
  351 + }
352 pages.push_back(cur_pages); 352 pages.push_back(cur_pages);
353 } 353 }
354 else 354 else
355 { 355 {
356 - throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),  
357 - this->m->last_object_description,  
358 - this->m->file->getLastOffset(),  
359 - "invalid Type " + type + " in page tree"); 356 + throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
  357 + this->m->last_object_description,
  358 + this->m->file->getLastOffset(),
  359 + "invalid Type " + type + " in page tree");
360 } 360 }
361 visited.erase(this_og); 361 visited.erase(this_og);
362 } 362 }
@@ -393,59 +393,59 @@ QPDF::updateObjectMapsInternal( @@ -393,59 +393,59 @@ QPDF::updateObjectMapsInternal(
393 393
394 if (oh.isIndirect()) 394 if (oh.isIndirect())
395 { 395 {
396 - QPDFObjGen og(oh.getObjGen());  
397 - if (visited.count(og))  
398 - {  
399 - QTC::TC("qpdf", "QPDF opt loop detected");  
400 - return;  
401 - }  
402 - this->m->obj_user_to_objects[ou].insert(og);  
403 - this->m->object_to_obj_users[og].insert(ou);  
404 - visited.insert(og); 396 + QPDFObjGen og(oh.getObjGen());
  397 + if (visited.count(og))
  398 + {
  399 + QTC::TC("qpdf", "QPDF opt loop detected");
  400 + return;
  401 + }
  402 + this->m->obj_user_to_objects[ou].insert(og);
  403 + this->m->object_to_obj_users[og].insert(ou);
  404 + visited.insert(og);
405 } 405 }
406 406
407 if (oh.isArray()) 407 if (oh.isArray())
408 { 408 {
409 - int n = oh.getArrayNItems();  
410 - for (int i = 0; i < n; ++i)  
411 - {  
412 - updateObjectMapsInternal( 409 + int n = oh.getArrayNItems();
  410 + for (int i = 0; i < n; ++i)
  411 + {
  412 + updateObjectMapsInternal(
413 ou, oh.getArrayItem(i), skip_stream_parameters, 413 ou, oh.getArrayItem(i), skip_stream_parameters,
414 visited, false, 1 + depth); 414 visited, false, 1 + depth);
415 - } 415 + }
416 } 416 }
417 else if (oh.isDictionary() || oh.isStream()) 417 else if (oh.isDictionary() || oh.isStream())
418 { 418 {
419 - QPDFObjectHandle dict = oh; 419 + QPDFObjectHandle dict = oh;
420 bool is_stream = oh.isStream(); 420 bool is_stream = oh.isStream();
421 int ssp = 0; 421 int ssp = 0;
422 - if (is_stream)  
423 - {  
424 - dict = oh.getDict(); 422 + if (is_stream)
  423 + {
  424 + dict = oh.getDict();
425 if (skip_stream_parameters) 425 if (skip_stream_parameters)
426 { 426 {
427 ssp = skip_stream_parameters(oh); 427 ssp = skip_stream_parameters(oh);
428 } 428 }
429 - }  
430 -  
431 - std::set<std::string> keys = dict.getKeys();  
432 - for (std::set<std::string>::iterator iter = keys.begin();  
433 - iter != keys.end(); ++iter)  
434 - {  
435 - std::string const& key = *iter;  
436 - if (is_page_node && (key == "/Thumb"))  
437 - {  
438 - // Traverse page thumbnail dictionaries as a special  
439 - // case.  
440 - updateObjectMapsInternal( 429 + }
  430 +
  431 + std::set<std::string> keys = dict.getKeys();
  432 + for (std::set<std::string>::iterator iter = keys.begin();
  433 + iter != keys.end(); ++iter)
  434 + {
  435 + std::string const& key = *iter;
  436 + if (is_page_node && (key == "/Thumb"))
  437 + {
  438 + // Traverse page thumbnail dictionaries as a special
  439 + // case.
  440 + updateObjectMapsInternal(
441 ObjUser(ObjUser::ou_thumb, ou.pageno), 441 ObjUser(ObjUser::ou_thumb, ou.pageno),
442 dict.getKey(key), skip_stream_parameters, 442 dict.getKey(key), skip_stream_parameters,
443 visited, false, 1 + depth); 443 visited, false, 1 + depth);
444 - }  
445 - else if (is_page_node && (key == "/Parent"))  
446 - {  
447 - // Don't traverse back up the page tree  
448 - } 444 + }
  445 + else if (is_page_node && (key == "/Parent"))
  446 + {
  447 + // Don't traverse back up the page tree
  448 + }
449 else if (((ssp >= 1) && (key == "/Length")) || 449 else if (((ssp >= 1) && (key == "/Length")) ||
450 ((ssp >= 2) && ((key == "/Filter") || 450 ((ssp >= 2) && ((key == "/Filter") ||
451 (key == "/DecodeParms")))) 451 (key == "/DecodeParms"))))
@@ -453,13 +453,13 @@ QPDF::updateObjectMapsInternal( @@ -453,13 +453,13 @@ QPDF::updateObjectMapsInternal(
453 // Don't traverse into stream parameters that we are 453 // Don't traverse into stream parameters that we are
454 // not going to write. 454 // not going to write.
455 } 455 }
456 - else  
457 - {  
458 - updateObjectMapsInternal( 456 + else
  457 + {
  458 + updateObjectMapsInternal(
459 ou, dict.getKey(key), skip_stream_parameters, 459 ou, dict.getKey(key), skip_stream_parameters,
460 visited, false, 1 + depth); 460 visited, false, 1 + depth);
461 - }  
462 - } 461 + }
  462 + }
463 } 463 }
464 } 464 }
465 465
@@ -468,7 +468,7 @@ QPDF::filterCompressedObjects(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -468,7 +468,7 @@ QPDF::filterCompressedObjects(std::map&lt;int, int&gt; const&amp; object_stream_data)
468 { 468 {
469 if (object_stream_data.empty()) 469 if (object_stream_data.empty())
470 { 470 {
471 - return; 471 + return;
472 } 472 }
473 473
474 // Transform object_to_obj_users and obj_user_to_objects so that 474 // Transform object_to_obj_users and obj_user_to_objects so that
@@ -480,49 +480,49 @@ QPDF::filterCompressedObjects(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -480,49 +480,49 @@ QPDF::filterCompressedObjects(std::map&lt;int, int&gt; const&amp; object_stream_data)
480 std::map<QPDFObjGen, std::set<ObjUser> > t_object_to_obj_users; 480 std::map<QPDFObjGen, std::set<ObjUser> > t_object_to_obj_users;
481 481
482 for (std::map<ObjUser, std::set<QPDFObjGen> >::iterator i1 = 482 for (std::map<ObjUser, std::set<QPDFObjGen> >::iterator i1 =
483 - this->m->obj_user_to_objects.begin();  
484 - i1 != this->m->obj_user_to_objects.end(); ++i1) 483 + this->m->obj_user_to_objects.begin();
  484 + i1 != this->m->obj_user_to_objects.end(); ++i1)
485 { 485 {
486 - ObjUser const& ou = (*i1).first;  
487 - std::set<QPDFObjGen> const& objects = (*i1).second;  
488 - for (std::set<QPDFObjGen>::const_iterator i2 = objects.begin();  
489 - i2 != objects.end(); ++i2)  
490 - {  
491 - QPDFObjGen const& og = (*i2);  
492 - std::map<int, int>::const_iterator i3 =  
493 - object_stream_data.find(og.getObj());  
494 - if (i3 == object_stream_data.end())  
495 - {  
496 - t_obj_user_to_objects[ou].insert(og);  
497 - }  
498 - else  
499 - {  
500 - t_obj_user_to_objects[ou].insert(QPDFObjGen((*i3).second, 0));  
501 - }  
502 - } 486 + ObjUser const& ou = (*i1).first;
  487 + std::set<QPDFObjGen> const& objects = (*i1).second;
  488 + for (std::set<QPDFObjGen>::const_iterator i2 = objects.begin();
  489 + i2 != objects.end(); ++i2)
  490 + {
  491 + QPDFObjGen const& og = (*i2);
  492 + std::map<int, int>::const_iterator i3 =
  493 + object_stream_data.find(og.getObj());
  494 + if (i3 == object_stream_data.end())
  495 + {
  496 + t_obj_user_to_objects[ou].insert(og);
  497 + }
  498 + else
  499 + {
  500 + t_obj_user_to_objects[ou].insert(QPDFObjGen((*i3).second, 0));
  501 + }
  502 + }
503 } 503 }
504 504
505 for (std::map<QPDFObjGen, std::set<ObjUser> >::iterator i1 = 505 for (std::map<QPDFObjGen, std::set<ObjUser> >::iterator i1 =
506 - this->m->object_to_obj_users.begin();  
507 - i1 != this->m->object_to_obj_users.end(); ++i1) 506 + this->m->object_to_obj_users.begin();
  507 + i1 != this->m->object_to_obj_users.end(); ++i1)
508 { 508 {
509 - QPDFObjGen const& og = (*i1).first;  
510 - std::set<ObjUser> const& objusers = (*i1).second;  
511 - for (std::set<ObjUser>::const_iterator i2 = objusers.begin();  
512 - i2 != objusers.end(); ++i2)  
513 - {  
514 - ObjUser const& ou = (*i2);  
515 - std::map<int, int>::const_iterator i3 =  
516 - object_stream_data.find(og.getObj());  
517 - if (i3 == object_stream_data.end())  
518 - {  
519 - t_object_to_obj_users[og].insert(ou);  
520 - }  
521 - else  
522 - {  
523 - t_object_to_obj_users[QPDFObjGen((*i3).second, 0)].insert(ou);  
524 - }  
525 - } 509 + QPDFObjGen const& og = (*i1).first;
  510 + std::set<ObjUser> const& objusers = (*i1).second;
  511 + for (std::set<ObjUser>::const_iterator i2 = objusers.begin();
  512 + i2 != objusers.end(); ++i2)
  513 + {
  514 + ObjUser const& ou = (*i2);
  515 + std::map<int, int>::const_iterator i3 =
  516 + object_stream_data.find(og.getObj());
  517 + if (i3 == object_stream_data.end())
  518 + {
  519 + t_object_to_obj_users[og].insert(ou);
  520 + }
  521 + else
  522 + {
  523 + t_object_to_obj_users[QPDFObjGen((*i3).second, 0)].insert(ou);
  524 + }
  525 + }
526 } 526 }
527 527
528 this->m->obj_user_to_objects = t_obj_user_to_objects; 528 this->m->obj_user_to_objects = t_obj_user_to_objects;
libqpdf/QPDF_pages.cc
@@ -86,7 +86,7 @@ QPDF::getAllPages() @@ -86,7 +86,7 @@ QPDF::getAllPages()
86 getRoot().replaceKey("/Pages", pages); 86 getRoot().replaceKey("/Pages", pages);
87 } 87 }
88 seen.clear(); 88 seen.clear();
89 - getAllPagesInternal(pages, this->m->all_pages, visited, seen); 89 + getAllPagesInternal(pages, this->m->all_pages, visited, seen);
90 } 90 }
91 return this->m->all_pages; 91 return this->m->all_pages;
92 } 92 }
@@ -110,10 +110,10 @@ QPDF::getAllPagesInternal(QPDFObjectHandle cur_node, @@ -110,10 +110,10 @@ QPDF::getAllPagesInternal(QPDFObjectHandle cur_node,
110 if (cur_node.hasKey("/Kids")) 110 if (cur_node.hasKey("/Kids"))
111 { 111 {
112 wanted_type = "/Pages"; 112 wanted_type = "/Pages";
113 - QPDFObjectHandle kids = cur_node.getKey("/Kids");  
114 - int n = kids.getArrayNItems();  
115 - for (int i = 0; i < n; ++i)  
116 - { 113 + QPDFObjectHandle kids = cur_node.getKey("/Kids");
  114 + int n = kids.getArrayNItems();
  115 + for (int i = 0; i < n; ++i)
  116 + {
117 QPDFObjectHandle kid = kids.getArrayItem(i); 117 QPDFObjectHandle kid = kids.getArrayItem(i);
118 if (! kid.isIndirect()) 118 if (! kid.isIndirect())
119 { 119 {
@@ -129,14 +129,14 @@ QPDF::getAllPagesInternal(QPDFObjectHandle cur_node, @@ -129,14 +129,14 @@ QPDF::getAllPagesInternal(QPDFObjectHandle cur_node,
129 kid = makeIndirectObject(QPDFObjectHandle(kid).shallowCopy()); 129 kid = makeIndirectObject(QPDFObjectHandle(kid).shallowCopy());
130 kids.setArrayItem(i, kid); 130 kids.setArrayItem(i, kid);
131 } 131 }
132 - getAllPagesInternal(kid, result, visited, seen);  
133 - } 132 + getAllPagesInternal(kid, result, visited, seen);
  133 + }
134 } 134 }
135 else 135 else
136 { 136 {
137 wanted_type = "/Page"; 137 wanted_type = "/Page";
138 seen.insert(this_og); 138 seen.insert(this_og);
139 - result.push_back(cur_node); 139 + result.push_back(cur_node);
140 } 140 }
141 141
142 if (! cur_node.isDictionaryOfType(wanted_type)) 142 if (! cur_node.isDictionaryOfType(wanted_type))
libqpdf/QTC.cc
@@ -16,7 +16,7 @@ void QTC::TC(char const* const scope, char const* const ccase, int n) @@ -16,7 +16,7 @@ void QTC::TC(char const* const scope, char const* const ccase, int n)
16 16
17 if (! tc_active(scope)) 17 if (! tc_active(scope))
18 { 18 {
19 - return; 19 + return;
20 } 20 }
21 21
22 std::string filename; 22 std::string filename;
@@ -27,13 +27,13 @@ void QTC::TC(char const* const scope, char const* const ccase, int n) @@ -27,13 +27,13 @@ void QTC::TC(char const* const scope, char const* const ccase, int n)
27 #endif 27 #endif
28 if (! QUtil::get_env(TC_ENV, &filename)) 28 if (! QUtil::get_env(TC_ENV, &filename))
29 { 29 {
30 - return; 30 + return;
31 } 31 }
32 #undef TC_ENV 32 #undef TC_ENV
33 33
34 if (cache.count(std::make_pair(ccase, n))) 34 if (cache.count(std::make_pair(ccase, n)))
35 { 35 {
36 - return; 36 + return;
37 } 37 }
38 cache.insert(std::make_pair(ccase, n)); 38 cache.insert(std::make_pair(ccase, n));
39 39
libqpdf/QUtil.cc
@@ -300,12 +300,12 @@ int_to_string_base_internal(T num, int base, int length) @@ -300,12 +300,12 @@ int_to_string_base_internal(T num, int base, int length)
300 int str_length = QIntC::to_int(cvt.length()); 300 int str_length = QIntC::to_int(cvt.length());
301 if ((length > 0) && (str_length < length)) 301 if ((length > 0) && (str_length < length))
302 { 302 {
303 - result.append(QIntC::to_size(length - str_length), '0'); 303 + result.append(QIntC::to_size(length - str_length), '0');
304 } 304 }
305 result += cvt; 305 result += cvt;
306 if ((length < 0) && (str_length < -length)) 306 if ((length < 0) && (str_length < -length))
307 { 307 {
308 - result.append(QIntC::to_size(-length - str_length), ' '); 308 + result.append(QIntC::to_size(-length - str_length), ' ');
309 } 309 }
310 return result; 310 return result;
311 } 311 }
@@ -455,7 +455,7 @@ QUtil::os_wrapper(std::string const&amp; description, int status) @@ -455,7 +455,7 @@ QUtil::os_wrapper(std::string const&amp; description, int status)
455 { 455 {
456 if (status == -1) 456 if (status == -1)
457 { 457 {
458 - throw_system_error(description); 458 + throw_system_error(description);
459 } 459 }
460 return status; 460 return status;
461 } 461 }
@@ -523,7 +523,7 @@ QUtil::fopen_wrapper(std::string const&amp; description, FILE* f) @@ -523,7 +523,7 @@ QUtil::fopen_wrapper(std::string const&amp; description, FILE* f)
523 { 523 {
524 if (f == 0) 524 if (f == 0)
525 { 525 {
526 - throw_system_error(description); 526 + throw_system_error(description);
527 } 527 }
528 return f; 528 return f;
529 } 529 }
@@ -841,17 +841,17 @@ QUtil::getWhoami(char* argv0) @@ -841,17 +841,17 @@ QUtil::getWhoami(char* argv0)
841 if (((whoami = strrchr(argv0, '/')) == NULL) && 841 if (((whoami = strrchr(argv0, '/')) == NULL) &&
842 ((whoami = strrchr(argv0, '\\')) == NULL)) 842 ((whoami = strrchr(argv0, '\\')) == NULL))
843 { 843 {
844 - whoami = argv0; 844 + whoami = argv0;
845 } 845 }
846 else 846 else
847 { 847 {
848 - ++whoami; 848 + ++whoami;
849 } 849 }
850 850
851 if ((strlen(whoami) > 4) && 851 if ((strlen(whoami) > 4) &&
852 - (strcmp(whoami + strlen(whoami) - 4, ".exe") == 0)) 852 + (strcmp(whoami + strlen(whoami) - 4, ".exe") == 0))
853 { 853 {
854 - whoami[strlen(whoami) - 4] = 'whoami[strlen(whoami) - 4] = '\0';'; 854 + whoami[strlen(whoami) - 4] = 'whoami[strlen(whoami) - 4] = '\0';';
855 } 855 }
856 856
857 return whoami; 857 return whoami;
@@ -875,9 +875,9 @@ QUtil::get_env(std::string const&amp; var, std::string* value) @@ -875,9 +875,9 @@ QUtil::get_env(std::string const&amp; var, std::string* value)
875 875
876 if (value) 876 if (value)
877 { 877 {
878 - PointerHolder<char> t = PointerHolder<char>(true, new char[len + 1]); 878 + PointerHolder<char> t = PointerHolder<char>(true, new char[len + 1]);
879 ::GetEnvironmentVariable(var.c_str(), t.get(), len); 879 ::GetEnvironmentVariable(var.c_str(), t.get(), len);
880 - *value = t.get(); 880 + *value = t.get();
881 } 881 }
882 882
883 return true; 883 return true;
@@ -1057,42 +1057,42 @@ QUtil::toUTF8(unsigned long uval) @@ -1057,42 +1057,42 @@ QUtil::toUTF8(unsigned long uval)
1057 1057
1058 if (uval > 0x7fffffff) 1058 if (uval > 0x7fffffff)
1059 { 1059 {
1060 - throw std::runtime_error("bounds error in QUtil::toUTF8"); 1060 + throw std::runtime_error("bounds error in QUtil::toUTF8");
1061 } 1061 }
1062 else if (uval < 128) 1062 else if (uval < 128)
1063 { 1063 {
1064 - result += static_cast<char>(uval); 1064 + result += static_cast<char>(uval);
1065 } 1065 }
1066 else 1066 else
1067 { 1067 {
1068 - unsigned char bytes[7];  
1069 - bytes[6] = '\0';  
1070 - unsigned char* cur_byte = &bytes[5];  
1071 -  
1072 - // maximum value that will fit in the current number of bytes  
1073 - unsigned char maxval = 0x3f; // six bits  
1074 -  
1075 - while (uval > QIntC::to_ulong(maxval))  
1076 - {  
1077 - // Assign low six bits plus 10000000 to lowest unused  
1078 - // byte position, then shift  
1079 - *cur_byte = static_cast<unsigned char>(0x80 + (uval & 0x3f));  
1080 - uval >>= 6;  
1081 - // Maximum that will fit in high byte now shrinks by one bit  
1082 - maxval = static_cast<unsigned char>(maxval >> 1);  
1083 - // Slide to the left one byte  
1084 - if (cur_byte <= bytes)  
1085 - {  
1086 - throw std::logic_error("QUtil::toUTF8: overflow error");  
1087 - }  
1088 - --cur_byte;  
1089 - }  
1090 - // If maxval is k bits long, the high (7 - k) bits of the  
1091 - // resulting byte must be high.  
1092 - *cur_byte = static_cast<unsigned char>( 1068 + unsigned char bytes[7];
  1069 + bytes[6] = '\0';
  1070 + unsigned char* cur_byte = &bytes[5];
  1071 +
  1072 + // maximum value that will fit in the current number of bytes
  1073 + unsigned char maxval = 0x3f; // six bits
  1074 +
  1075 + while (uval > QIntC::to_ulong(maxval))
  1076 + {
  1077 + // Assign low six bits plus 10000000 to lowest unused
  1078 + // byte position, then shift
  1079 + *cur_byte = static_cast<unsigned char>(0x80 + (uval & 0x3f));
  1080 + uval >>= 6;
  1081 + // Maximum that will fit in high byte now shrinks by one bit
  1082 + maxval = static_cast<unsigned char>(maxval >> 1);
  1083 + // Slide to the left one byte
  1084 + if (cur_byte <= bytes)
  1085 + {
  1086 + throw std::logic_error("QUtil::toUTF8: overflow error");
  1087 + }
  1088 + --cur_byte;
  1089 + }
  1090 + // If maxval is k bits long, the high (7 - k) bits of the
  1091 + // resulting byte must be high.
  1092 + *cur_byte = static_cast<unsigned char>(
1093 QIntC::to_ulong(0xff - (1 + (maxval << 1))) + uval); 1093 QIntC::to_ulong(0xff - (1 + (maxval << 1))) + uval);
1094 1094
1095 - result += reinterpret_cast<char*>(cur_byte); 1095 + result += reinterpret_cast<char*>(cur_byte);
1096 } 1096 }
1097 1097
1098 return result; 1098 return result;
@@ -1350,19 +1350,19 @@ QUtil::read_lines_from_file(std::function&lt;bool(char&amp;)&gt; next_char, @@ -1350,19 +1350,19 @@ QUtil::read_lines_from_file(std::function&lt;bool(char&amp;)&gt; next_char,
1350 char c; 1350 char c;
1351 while (next_char(c)) 1351 while (next_char(c))
1352 { 1352 {
1353 - if (buf == 0)  
1354 - {  
1355 - lines.push_back("");  
1356 - buf = &(lines.back());  
1357 - buf->reserve(80);  
1358 - }  
1359 -  
1360 - if (buf->capacity() == buf->size())  
1361 - {  
1362 - buf->reserve(buf->capacity() * 2);  
1363 - }  
1364 - if (c == '\n')  
1365 - { 1353 + if (buf == 0)
  1354 + {
  1355 + lines.push_back("");
  1356 + buf = &(lines.back());
  1357 + buf->reserve(80);
  1358 + }
  1359 +
  1360 + if (buf->capacity() == buf->size())
  1361 + {
  1362 + buf->reserve(buf->capacity() * 2);
  1363 + }
  1364 + if (c == '\n')
  1365 + {
1366 if (preserve_eol) 1366 if (preserve_eol)
1367 { 1367 {
1368 buf->append(1, c); 1368 buf->append(1, c);
@@ -1376,12 +1376,12 @@ QUtil::read_lines_from_file(std::function&lt;bool(char&amp;)&gt; next_char, @@ -1376,12 +1376,12 @@ QUtil::read_lines_from_file(std::function&lt;bool(char&amp;)&gt; next_char,
1376 buf->erase(buf->length() - 1); 1376 buf->erase(buf->length() - 1);
1377 } 1377 }
1378 } 1378 }
1379 - buf = 0;  
1380 - }  
1381 - else  
1382 - {  
1383 - buf->append(1, c);  
1384 - } 1379 + buf = 0;
  1380 + }
  1381 + else
  1382 + {
  1383 + buf->append(1, c);
  1384 + }
1385 } 1385 }
1386 } 1386 }
1387 1387
libqpdf/RC4_native.cc
@@ -17,7 +17,7 @@ RC4_native::RC4_native(unsigned char const* key_data, int key_len) @@ -17,7 +17,7 @@ RC4_native::RC4_native(unsigned char const* key_data, int key_len)
17 { 17 {
18 if (key_len == -1) 18 if (key_len == -1)
19 { 19 {
20 - key_len = QIntC::to_int( 20 + key_len = QIntC::to_int(
21 strlen(reinterpret_cast<char const*>(key_data))); 21 strlen(reinterpret_cast<char const*>(key_data)));
22 } 22 }
23 23
@@ -32,9 +32,9 @@ RC4_native::RC4_native(unsigned char const* key_data, int key_len) @@ -32,9 +32,9 @@ RC4_native::RC4_native(unsigned char const* key_data, int key_len)
32 int i2 = 0; 32 int i2 = 0;
33 for (int i = 0; i < 256; ++i) 33 for (int i = 0; i < 256; ++i)
34 { 34 {
35 - i2 = (key_data[i1] + key.state[i] + i2) % 256;  
36 - swap_byte(key.state[i], key.state[i2]);  
37 - i1 = (i1 + 1) % key_len; 35 + i2 = (key_data[i1] + key.state[i] + i2) % 256;
  36 + swap_byte(key.state[i], key.state[i2]);
  37 + i1 = (i1 + 1) % key_len;
38 } 38 }
39 } 39 }
40 40
@@ -43,16 +43,16 @@ RC4_native::process(unsigned char *in_data, size_t len, unsigned char* out_data) @@ -43,16 +43,16 @@ RC4_native::process(unsigned char *in_data, size_t len, unsigned char* out_data)
43 { 43 {
44 if (out_data == 0) 44 if (out_data == 0)
45 { 45 {
46 - // Convert in place  
47 - out_data = in_data; 46 + // Convert in place
  47 + out_data = in_data;
48 } 48 }
49 49
50 for (size_t i = 0; i < len; ++i) 50 for (size_t i = 0; i < len; ++i)
51 { 51 {
52 - key.x = static_cast<unsigned char>((key.x + 1) % 256);  
53 - key.y = static_cast<unsigned char>((key.state[key.x] + key.y) % 256);  
54 - swap_byte(key.state[key.x], key.state[key.y]);  
55 - int xor_index = (key.state[key.x] + key.state[key.y]) % 256;  
56 - out_data[i] = in_data[i] ^ key.state[xor_index]; 52 + key.x = static_cast<unsigned char>((key.x + 1) % 256);
  53 + key.y = static_cast<unsigned char>((key.state[key.x] + key.y) % 256);
  54 + swap_byte(key.state[key.x], key.state[key.y]);
  55 + int xor_index = (key.state[key.x] + key.state[key.y]) % 256;
  56 + out_data[i] = in_data[i] ^ key.state[xor_index];
57 } 57 }
58 } 58 }
libqpdf/SF_FlateLzwDecode.cc
@@ -92,7 +92,7 @@ SF_FlateLzwDecode::setDecodeParms(QPDFObjectHandle decode_parms) @@ -92,7 +92,7 @@ SF_FlateLzwDecode::setDecodeParms(QPDFObjectHandle decode_parms)
92 92
93 if ((this->predictor > 1) && (this->columns == 0)) 93 if ((this->predictor > 1) && (this->columns == 0))
94 { 94 {
95 - filterable = false; 95 + filterable = false;
96 } 96 }
97 97
98 return filterable; 98 return filterable;
libqpdf/SparseOHArray.cc
@@ -28,8 +28,8 @@ SparseOHArray::at(size_t idx) const @@ -28,8 +28,8 @@ SparseOHArray::at(size_t idx) const
28 { 28 {
29 if (idx >= this->n_elements) 29 if (idx >= this->n_elements)
30 { 30 {
31 - throw std::logic_error(  
32 - "INTERNAL ERROR: bounds error accessing SparseOHArray element"); 31 + throw std::logic_error(
  32 + "INTERNAL ERROR: bounds error accessing SparseOHArray element");
33 } 33 }
34 auto const& iter = this->elements.find(idx); 34 auto const& iter = this->elements.find(idx);
35 if (iter == this->elements.end()) 35 if (iter == this->elements.end())
@@ -47,8 +47,8 @@ SparseOHArray::remove_last() @@ -47,8 +47,8 @@ SparseOHArray::remove_last()
47 { 47 {
48 if (this->n_elements == 0) 48 if (this->n_elements == 0)
49 { 49 {
50 - throw std::logic_error(  
51 - "INTERNAL ERROR: attempt to remove" 50 + throw std::logic_error(
  51 + "INTERNAL ERROR: attempt to remove"
52 " last item from empty SparseOHArray"); 52 " last item from empty SparseOHArray");
53 } 53 }
54 --this->n_elements; 54 --this->n_elements;
@@ -60,7 +60,7 @@ SparseOHArray::releaseResolved() @@ -60,7 +60,7 @@ SparseOHArray::releaseResolved()
60 { 60 {
61 for (auto& iter: this->elements) 61 for (auto& iter: this->elements)
62 { 62 {
63 - QPDFObjectHandle::ReleaseResolver::releaseResolved(iter.second); 63 + QPDFObjectHandle::ReleaseResolver::releaseResolved(iter.second);
64 } 64 }
65 } 65 }
66 66
@@ -69,7 +69,7 @@ SparseOHArray::setAt(size_t idx, QPDFObjectHandle oh) @@ -69,7 +69,7 @@ SparseOHArray::setAt(size_t idx, QPDFObjectHandle oh)
69 { 69 {
70 if (idx >= this->n_elements) 70 if (idx >= this->n_elements)
71 { 71 {
72 - throw std::logic_error("bounds error setting item in SparseOHArray"); 72 + throw std::logic_error("bounds error setting item in SparseOHArray");
73 } 73 }
74 if (oh.isDirectNull()) 74 if (oh.isDirectNull())
75 { 75 {
@@ -86,7 +86,7 @@ SparseOHArray::erase(size_t idx) @@ -86,7 +86,7 @@ SparseOHArray::erase(size_t idx)
86 { 86 {
87 if (idx >= this->n_elements) 87 if (idx >= this->n_elements)
88 { 88 {
89 - throw std::logic_error("bounds error erasing item from SparseOHArray"); 89 + throw std::logic_error("bounds error erasing item from SparseOHArray");
90 } 90 }
91 decltype(this->elements) dest; 91 decltype(this->elements) dest;
92 for (auto const& iter: this->elements) 92 for (auto const& iter: this->elements)
libqpdf/bits.icc
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 #ifdef BITS_READ 18 #ifdef BITS_READ
19 static unsigned long long 19 static unsigned long long
20 read_bits(unsigned char const*& p, size_t& bit_offset, 20 read_bits(unsigned char const*& p, size_t& bit_offset,
21 - size_t& bits_available, size_t bits_wanted) 21 + size_t& bits_available, size_t bits_wanted)
22 { 22 {
23 // View p as a stream of bits: 23 // View p as a stream of bits:
24 24
@@ -29,67 +29,67 @@ read_bits(unsigned char const*&amp; p, size_t&amp; bit_offset, @@ -29,67 +29,67 @@ read_bits(unsigned char const*&amp; p, size_t&amp; bit_offset,
29 29
30 if (bits_wanted > bits_available) 30 if (bits_wanted > bits_available)
31 { 31 {
32 - throw std::runtime_error( 32 + throw std::runtime_error(
33 "overflow reading bit stream: wanted = " + 33 "overflow reading bit stream: wanted = " +
34 QUtil::uint_to_string(bits_wanted) + "; available = " + 34 QUtil::uint_to_string(bits_wanted) + "; available = " +
35 QUtil::uint_to_string(bits_available)); 35 QUtil::uint_to_string(bits_available));
36 } 36 }
37 if (bits_wanted > 32) 37 if (bits_wanted > 32)
38 { 38 {
39 - throw std::out_of_range("read_bits: too many bits requested"); 39 + throw std::out_of_range("read_bits: too many bits requested");
40 } 40 }
41 41
42 unsigned long result = 0; 42 unsigned long result = 0;
43 #ifdef BITS_TESTING 43 #ifdef BITS_TESTING
44 if (bits_wanted == 0) 44 if (bits_wanted == 0)
45 { 45 {
46 - QTC::TC("libtests", "bits zero bits wanted"); 46 + QTC::TC("libtests", "bits zero bits wanted");
47 } 47 }
48 #endif 48 #endif
49 while (bits_wanted > 0) 49 while (bits_wanted > 0)
50 { 50 {
51 - // Grab bits from the first byte clearing anything before  
52 - // bit_offset.  
53 - unsigned char byte = static_cast<unsigned char>( 51 + // Grab bits from the first byte clearing anything before
  52 + // bit_offset.
  53 + unsigned char byte = static_cast<unsigned char>(
54 *p & ((1U << (bit_offset + 1U)) - 1U)); 54 *p & ((1U << (bit_offset + 1U)) - 1U));
55 55
56 - // There are bit_offset + 1 bits available in the first byte.  
57 - size_t to_copy = std::min(bits_wanted, bit_offset + 1);  
58 - size_t leftover = (bit_offset + 1) - to_copy; 56 + // There are bit_offset + 1 bits available in the first byte.
  57 + size_t to_copy = std::min(bits_wanted, bit_offset + 1);
  58 + size_t leftover = (bit_offset + 1) - to_copy;
59 59
60 #ifdef BITS_TESTING 60 #ifdef BITS_TESTING
61 - QTC::TC("libtests", "bits bit_offset",  
62 - ((bit_offset == 0) ? 0 :  
63 - (bit_offset == 7) ? 1 :  
64 - 2));  
65 - QTC::TC("libtests", "bits leftover", (leftover > 0) ? 1 : 0); 61 + QTC::TC("libtests", "bits bit_offset",
  62 + ((bit_offset == 0) ? 0 :
  63 + (bit_offset == 7) ? 1 :
  64 + 2));
  65 + QTC::TC("libtests", "bits leftover", (leftover > 0) ? 1 : 0);
66 #endif 66 #endif
67 67
68 - // Right shift so that all the bits we want are right justified.  
69 - byte = static_cast<unsigned char>(byte >> leftover);  
70 -  
71 - // Copy the bits into result  
72 - result <<= to_copy;  
73 - result |= byte;  
74 -  
75 - // Update pointers  
76 - if (leftover)  
77 - {  
78 - bit_offset = leftover - 1;  
79 - }  
80 - else  
81 - {  
82 - bit_offset = 7;  
83 - ++p;  
84 - }  
85 - bits_wanted -= to_copy;  
86 - bits_available -= to_copy; 68 + // Right shift so that all the bits we want are right justified.
  69 + byte = static_cast<unsigned char>(byte >> leftover);
  70 +
  71 + // Copy the bits into result
  72 + result <<= to_copy;
  73 + result |= byte;
  74 +
  75 + // Update pointers
  76 + if (leftover)
  77 + {
  78 + bit_offset = leftover - 1;
  79 + }
  80 + else
  81 + {
  82 + bit_offset = 7;
  83 + ++p;
  84 + }
  85 + bits_wanted -= to_copy;
  86 + bits_available -= to_copy;
87 87
88 #ifdef BITS_TESTING 88 #ifdef BITS_TESTING
89 - QTC::TC("libtests", "bits iterations",  
90 - ((bits_wanted > 8) ? 0 :  
91 - (bits_wanted > 0) ? 1 :  
92 - 2)); 89 + QTC::TC("libtests", "bits iterations",
  90 + ((bits_wanted > 8) ? 0 :
  91 + (bits_wanted > 0) ? 1 :
  92 + 2));
93 #endif 93 #endif
94 } 94 }
95 95
@@ -100,50 +100,50 @@ read_bits(unsigned char const*&amp; p, size_t&amp; bit_offset, @@ -100,50 +100,50 @@ read_bits(unsigned char const*&amp; p, size_t&amp; bit_offset,
100 #ifdef BITS_WRITE 100 #ifdef BITS_WRITE
101 static void 101 static void
102 write_bits(unsigned char& ch, size_t& bit_offset, 102 write_bits(unsigned char& ch, size_t& bit_offset,
103 - unsigned long long val, size_t bits, Pipeline* pipeline) 103 + unsigned long long val, size_t bits, Pipeline* pipeline)
104 { 104 {
105 if (bits > 32) 105 if (bits > 32)
106 { 106 {
107 - throw std::out_of_range("write_bits: too many bits requested"); 107 + throw std::out_of_range("write_bits: too many bits requested");
108 } 108 }
109 109
110 // bit_offset + 1 is the number of bits left in ch 110 // bit_offset + 1 is the number of bits left in ch
111 #ifdef BITS_TESTING 111 #ifdef BITS_TESTING
112 if (bits == 0) 112 if (bits == 0)
113 { 113 {
114 - QTC::TC("libtests", "bits write zero bits"); 114 + QTC::TC("libtests", "bits write zero bits");
115 } 115 }
116 #endif 116 #endif
117 while (bits > 0) 117 while (bits > 0)
118 { 118 {
119 - size_t bits_to_write = std::min(bits, bit_offset + 1);  
120 - unsigned char newval = static_cast<unsigned char>(  
121 - (val >> (bits - bits_to_write)) & ((1U << bits_to_write) - 1));  
122 - size_t bits_left_in_ch = bit_offset + 1 - bits_to_write;  
123 - newval = static_cast<unsigned char>(newval << bits_left_in_ch);  
124 - ch |= newval;  
125 - if (bits_left_in_ch == 0)  
126 - { 119 + size_t bits_to_write = std::min(bits, bit_offset + 1);
  120 + unsigned char newval = static_cast<unsigned char>(
  121 + (val >> (bits - bits_to_write)) & ((1U << bits_to_write) - 1));
  122 + size_t bits_left_in_ch = bit_offset + 1 - bits_to_write;
  123 + newval = static_cast<unsigned char>(newval << bits_left_in_ch);
  124 + ch |= newval;
  125 + if (bits_left_in_ch == 0)
  126 + {
127 #ifdef BITS_TESTING 127 #ifdef BITS_TESTING
128 - QTC::TC("libtests", "bits write pipeline"); 128 + QTC::TC("libtests", "bits write pipeline");
129 #endif 129 #endif
130 - pipeline->write(&ch, 1);  
131 - bit_offset = 7;  
132 - ch = 0;  
133 - }  
134 - else  
135 - { 130 + pipeline->write(&ch, 1);
  131 + bit_offset = 7;
  132 + ch = 0;
  133 + }
  134 + else
  135 + {
136 #ifdef BITS_TESTING 136 #ifdef BITS_TESTING
137 - QTC::TC("libtests", "bits write leftover"); 137 + QTC::TC("libtests", "bits write leftover");
138 #endif 138 #endif
139 - bit_offset -= bits_to_write;  
140 - }  
141 - bits -= bits_to_write; 139 + bit_offset -= bits_to_write;
  140 + }
  141 + bits -= bits_to_write;
142 #ifdef BITS_TESTING 142 #ifdef BITS_TESTING
143 - QTC::TC("libtests", "bits write iterations",  
144 - ((bits > 8) ? 0 :  
145 - (bits > 0) ? 1 :  
146 - 2)); 143 + QTC::TC("libtests", "bits write iterations",
  144 + ((bits > 8) ? 0 :
  145 + (bits > 0) ? 1 :
  146 + 2));
147 #endif 147 #endif
148 } 148 }
149 149
libqpdf/qpdf-c.cc
@@ -35,7 +35,7 @@ struct _qpdf_data @@ -35,7 +35,7 @@ struct _qpdf_data
35 std::string tmp_string; 35 std::string tmp_string;
36 36
37 // Parameters for functions we call 37 // Parameters for functions we call
38 - char const* filename; // or description 38 + char const* filename; // or description
39 char const* buffer; 39 char const* buffer;
40 unsigned long long size; 40 unsigned long long size;
41 char const* password; 41 char const* password;
@@ -98,7 +98,7 @@ static void call_read(qpdf_data qpdf) @@ -98,7 +98,7 @@ static void call_read(qpdf_data qpdf)
98 static void call_read_memory(qpdf_data qpdf) 98 static void call_read_memory(qpdf_data qpdf)
99 { 99 {
100 qpdf->qpdf->processMemoryFile(qpdf->filename, qpdf->buffer, 100 qpdf->qpdf->processMemoryFile(qpdf->filename, qpdf->buffer,
101 - QIntC::to_size(qpdf->size), qpdf->password); 101 + QIntC::to_size(qpdf->size), qpdf->password);
102 } 102 }
103 103
104 // must set qpdf->filename 104 // must set qpdf->filename
@@ -134,29 +134,29 @@ static QPDF_ERROR_CODE trap_errors( @@ -134,29 +134,29 @@ static QPDF_ERROR_CODE trap_errors(
134 QPDF_ERROR_CODE status = QPDF_SUCCESS; 134 QPDF_ERROR_CODE status = QPDF_SUCCESS;
135 try 135 try
136 { 136 {
137 - fn(qpdf); 137 + fn(qpdf);
138 } 138 }
139 catch (QPDFExc& e) 139 catch (QPDFExc& e)
140 { 140 {
141 - qpdf->error = make_pointer_holder<QPDFExc>(e);  
142 - status |= QPDF_ERRORS; 141 + qpdf->error = make_pointer_holder<QPDFExc>(e);
  142 + status |= QPDF_ERRORS;
143 } 143 }
144 catch (std::runtime_error& e) 144 catch (std::runtime_error& e)
145 { 145 {
146 - qpdf->error = make_pointer_holder<QPDFExc>( 146 + qpdf->error = make_pointer_holder<QPDFExc>(
147 qpdf_e_system, "", "", 0, e.what()); 147 qpdf_e_system, "", "", 0, e.what());
148 - status |= QPDF_ERRORS; 148 + status |= QPDF_ERRORS;
149 } 149 }
150 catch (std::exception& e) 150 catch (std::exception& e)
151 { 151 {
152 - qpdf->error = make_pointer_holder<QPDFExc>( 152 + qpdf->error = make_pointer_holder<QPDFExc>(
153 qpdf_e_internal, "", "", 0, e.what()); 153 qpdf_e_internal, "", "", 0, e.what());
154 - status |= QPDF_ERRORS; 154 + status |= QPDF_ERRORS;
155 } 155 }
156 156
157 if (qpdf_more_warnings(qpdf)) 157 if (qpdf_more_warnings(qpdf))
158 { 158 {
159 - status |= QPDF_WARNINGS; 159 + status |= QPDF_WARNINGS;
160 } 160 }
161 return status; 161 return status;
162 } 162 }
@@ -202,19 +202,19 @@ QPDF_BOOL qpdf_more_warnings(qpdf_data qpdf) @@ -202,19 +202,19 @@ QPDF_BOOL qpdf_more_warnings(qpdf_data qpdf)
202 202
203 if (qpdf->warnings.empty()) 203 if (qpdf->warnings.empty())
204 { 204 {
205 - std::vector<QPDFExc> w = qpdf->qpdf->getWarnings();  
206 - if (! w.empty())  
207 - {  
208 - qpdf->warnings.assign(w.begin(), w.end());  
209 - } 205 + std::vector<QPDFExc> w = qpdf->qpdf->getWarnings();
  206 + if (! w.empty())
  207 + {
  208 + qpdf->warnings.assign(w.begin(), w.end());
  209 + }
210 } 210 }
211 if (qpdf->warnings.empty()) 211 if (qpdf->warnings.empty())
212 { 212 {
213 - return QPDF_FALSE; 213 + return QPDF_FALSE;
214 } 214 }
215 else 215 else
216 { 216 {
217 - return QPDF_TRUE; 217 + return QPDF_TRUE;
218 } 218 }
219 } 219 }
220 220
@@ -228,14 +228,14 @@ qpdf_error qpdf_get_error(qpdf_data qpdf) @@ -228,14 +228,14 @@ qpdf_error qpdf_get_error(qpdf_data qpdf)
228 { 228 {
229 if (qpdf->error.get()) 229 if (qpdf->error.get())
230 { 230 {
231 - qpdf->tmp_error.exc = qpdf->error;  
232 - qpdf->error = 0;  
233 - QTC::TC("qpdf", "qpdf-c qpdf_get_error returned error");  
234 - return &qpdf->tmp_error; 231 + qpdf->tmp_error.exc = qpdf->error;
  232 + qpdf->error = 0;
  233 + QTC::TC("qpdf", "qpdf-c qpdf_get_error returned error");
  234 + return &qpdf->tmp_error;
235 } 235 }
236 else 236 else
237 { 237 {
238 - return 0; 238 + return 0;
239 } 239 }
240 } 240 }
241 241
@@ -243,15 +243,15 @@ qpdf_error qpdf_next_warning(qpdf_data qpdf) @@ -243,15 +243,15 @@ qpdf_error qpdf_next_warning(qpdf_data qpdf)
243 { 243 {
244 if (qpdf_more_warnings(qpdf)) 244 if (qpdf_more_warnings(qpdf))
245 { 245 {
246 - qpdf->tmp_error.exc = make_pointer_holder<QPDFExc>( 246 + qpdf->tmp_error.exc = make_pointer_holder<QPDFExc>(
247 qpdf->warnings.front()); 247 qpdf->warnings.front());
248 - qpdf->warnings.pop_front();  
249 - QTC::TC("qpdf", "qpdf-c qpdf_next_warning returned warning");  
250 - return &qpdf->tmp_error; 248 + qpdf->warnings.pop_front();
  249 + QTC::TC("qpdf", "qpdf-c qpdf_next_warning returned warning");
  250 + return &qpdf->tmp_error;
251 } 251 }
252 else 252 else
253 { 253 {
254 - return 0; 254 + return 0;
255 } 255 }
256 } 256 }
257 257
@@ -259,7 +259,7 @@ char const* qpdf_get_error_full_text(qpdf_data qpdf, qpdf_error e) @@ -259,7 +259,7 @@ char const* qpdf_get_error_full_text(qpdf_data qpdf, qpdf_error e)
259 { 259 {
260 if (e == 0) 260 if (e == 0)
261 { 261 {
262 - return ""; 262 + return "";
263 } 263 }
264 return e->exc->what(); 264 return e->exc->what();
265 } 265 }
@@ -268,7 +268,7 @@ enum qpdf_error_code_e qpdf_get_error_code(qpdf_data qpdf, qpdf_error e) @@ -268,7 +268,7 @@ enum qpdf_error_code_e qpdf_get_error_code(qpdf_data qpdf, qpdf_error e)
268 { 268 {
269 if (e == 0) 269 if (e == 0)
270 { 270 {
271 - return qpdf_e_success; 271 + return qpdf_e_success;
272 } 272 }
273 return e->exc->getErrorCode(); 273 return e->exc->getErrorCode();
274 } 274 }
@@ -277,7 +277,7 @@ char const* qpdf_get_error_filename(qpdf_data qpdf, qpdf_error e) @@ -277,7 +277,7 @@ char const* qpdf_get_error_filename(qpdf_data qpdf, qpdf_error e)
277 { 277 {
278 if (e == 0) 278 if (e == 0)
279 { 279 {
280 - return ""; 280 + return "";
281 } 281 }
282 return e->exc->getFilename().c_str(); 282 return e->exc->getFilename().c_str();
283 } 283 }
@@ -286,7 +286,7 @@ unsigned long long qpdf_get_error_file_position(qpdf_data qpdf, qpdf_error e) @@ -286,7 +286,7 @@ unsigned long long qpdf_get_error_file_position(qpdf_data qpdf, qpdf_error e)
286 { 286 {
287 if (e == 0) 287 if (e == 0)
288 { 288 {
289 - return 0; 289 + return 0;
290 } 290 }
291 return QIntC::to_ulonglong(e->exc->getFilePosition()); 291 return QIntC::to_ulonglong(e->exc->getFilePosition());
292 } 292 }
@@ -295,7 +295,7 @@ char const* qpdf_get_error_message_detail(qpdf_data qpdf, qpdf_error e) @@ -295,7 +295,7 @@ char const* qpdf_get_error_message_detail(qpdf_data qpdf, qpdf_error e)
295 { 295 {
296 if (e == 0) 296 if (e == 0)
297 { 297 {
298 - return ""; 298 + return "";
299 } 299 }
300 return e->exc->getMessageDetail().c_str(); 300 return e->exc->getMessageDetail().c_str();
301 } 301 }
@@ -326,7 +326,7 @@ void qpdf_set_attempt_recovery(qpdf_data qpdf, QPDF_BOOL value) @@ -326,7 +326,7 @@ void qpdf_set_attempt_recovery(qpdf_data qpdf, QPDF_BOOL value)
326 } 326 }
327 327
328 QPDF_ERROR_CODE qpdf_read(qpdf_data qpdf, char const* filename, 328 QPDF_ERROR_CODE qpdf_read(qpdf_data qpdf, char const* filename,
329 - char const* password) 329 + char const* password)
330 { 330 {
331 QPDF_ERROR_CODE status = QPDF_SUCCESS; 331 QPDF_ERROR_CODE status = QPDF_SUCCESS;
332 qpdf->filename = filename; 332 qpdf->filename = filename;
@@ -345,10 +345,10 @@ QPDF_ERROR_CODE qpdf_read(qpdf_data qpdf, char const* filename, @@ -345,10 +345,10 @@ QPDF_ERROR_CODE qpdf_read(qpdf_data qpdf, char const* filename,
345 } 345 }
346 346
347 QPDF_ERROR_CODE qpdf_read_memory(qpdf_data qpdf, 347 QPDF_ERROR_CODE qpdf_read_memory(qpdf_data qpdf,
348 - char const* description,  
349 - char const* buffer,  
350 - unsigned long long size,  
351 - char const* password) 348 + char const* description,
  349 + char const* buffer,
  350 + unsigned long long size,
  351 + char const* password)
352 { 352 {
353 QPDF_ERROR_CODE status = QPDF_SUCCESS; 353 QPDF_ERROR_CODE status = QPDF_SUCCESS;
354 qpdf->filename = description; 354 qpdf->filename = description;
@@ -394,16 +394,16 @@ char const* qpdf_get_info_key(qpdf_data qpdf, char const* key) @@ -394,16 +394,16 @@ char const* qpdf_get_info_key(qpdf_data qpdf, char const* key)
394 QPDFObjectHandle trailer = qpdf->qpdf->getTrailer(); 394 QPDFObjectHandle trailer = qpdf->qpdf->getTrailer();
395 if (trailer.hasKey("/Info")) 395 if (trailer.hasKey("/Info"))
396 { 396 {
397 - QPDFObjectHandle info = trailer.getKey("/Info");  
398 - if (info.hasKey(key))  
399 - {  
400 - QPDFObjectHandle value = info.getKey(key);  
401 - if (value.isString())  
402 - {  
403 - qpdf->tmp_string = value.getStringValue();  
404 - result = qpdf->tmp_string.c_str();  
405 - }  
406 - } 397 + QPDFObjectHandle info = trailer.getKey("/Info");
  398 + if (info.hasKey(key))
  399 + {
  400 + QPDFObjectHandle value = info.getKey(key);
  401 + if (value.isString())
  402 + {
  403 + qpdf->tmp_string = value.getStringValue();
  404 + result = qpdf->tmp_string.c_str();
  405 + }
  406 + }
407 } 407 }
408 QTC::TC("qpdf", "qpdf-c get_info_key", (result == 0 ? 0 : 1)); 408 QTC::TC("qpdf", "qpdf-c get_info_key", (result == 0 ? 0 : 1));
409 return result; 409 return result;
@@ -413,31 +413,31 @@ void qpdf_set_info_key(qpdf_data qpdf, char const* key, char const* value) @@ -413,31 +413,31 @@ void qpdf_set_info_key(qpdf_data qpdf, char const* key, char const* value)
413 { 413 {
414 if ((key == 0) || (std::strlen(key) == 0) || (key[0] != '/')) 414 if ((key == 0) || (std::strlen(key) == 0) || (key[0] != '/'))
415 { 415 {
416 - return; 416 + return;
417 } 417 }
418 QPDFObjectHandle value_object; 418 QPDFObjectHandle value_object;
419 if (value) 419 if (value)
420 { 420 {
421 - QTC::TC("qpdf", "qpdf-c set_info_key to value");  
422 - value_object = QPDFObjectHandle::newString(value); 421 + QTC::TC("qpdf", "qpdf-c set_info_key to value");
  422 + value_object = QPDFObjectHandle::newString(value);
423 } 423 }
424 else 424 else
425 { 425 {
426 - QTC::TC("qpdf", "qpdf-c set_info_key to null");  
427 - value_object = QPDFObjectHandle::newNull(); 426 + QTC::TC("qpdf", "qpdf-c set_info_key to null");
  427 + value_object = QPDFObjectHandle::newNull();
428 } 428 }
429 429
430 QPDFObjectHandle trailer = qpdf->qpdf->getTrailer(); 430 QPDFObjectHandle trailer = qpdf->qpdf->getTrailer();
431 if (! trailer.hasKey("/Info")) 431 if (! trailer.hasKey("/Info"))
432 { 432 {
433 - QTC::TC("qpdf", "qpdf-c add info to trailer");  
434 - trailer.replaceKey(  
435 - "/Info",  
436 - qpdf->qpdf->makeIndirectObject(QPDFObjectHandle::newDictionary())); 433 + QTC::TC("qpdf", "qpdf-c add info to trailer");
  434 + trailer.replaceKey(
  435 + "/Info",
  436 + qpdf->qpdf->makeIndirectObject(QPDFObjectHandle::newDictionary()));
437 } 437 }
438 else 438 else
439 { 439 {
440 - QTC::TC("qpdf", "qpdf-c set-info-key use existing info"); 440 + QTC::TC("qpdf", "qpdf-c set-info-key use existing info");
441 } 441 }
442 442
443 QPDFObjectHandle info = trailer.getKey("/Info"); 443 QPDFObjectHandle info = trailer.getKey("/Info");
@@ -514,14 +514,14 @@ static void qpdf_init_write_internal(qpdf_data qpdf) @@ -514,14 +514,14 @@ static void qpdf_init_write_internal(qpdf_data qpdf)
514 { 514 {
515 if (qpdf->qpdf_writer.get()) 515 if (qpdf->qpdf_writer.get())
516 { 516 {
517 - QTC::TC("qpdf", "qpdf-c called qpdf_init_write multiple times");  
518 - qpdf->qpdf_writer = 0;  
519 - if (qpdf->output_buffer.get())  
520 - {  
521 - qpdf->output_buffer = 0;  
522 - qpdf->write_memory = false;  
523 - qpdf->filename = 0;  
524 - } 517 + QTC::TC("qpdf", "qpdf-c called qpdf_init_write multiple times");
  518 + qpdf->qpdf_writer = 0;
  519 + if (qpdf->output_buffer.get())
  520 + {
  521 + qpdf->output_buffer = 0;
  522 + qpdf->write_memory = false;
  523 + qpdf->filename = 0;
  524 + }
525 } 525 }
526 } 526 }
527 527
@@ -547,7 +547,7 @@ static void qpdf_get_buffer_internal(qpdf_data qpdf) @@ -547,7 +547,7 @@ static void qpdf_get_buffer_internal(qpdf_data qpdf)
547 { 547 {
548 if (qpdf->write_memory && (qpdf->output_buffer == 0)) 548 if (qpdf->write_memory && (qpdf->output_buffer == 0))
549 { 549 {
550 - qpdf->output_buffer = qpdf->qpdf_writer->getBufferSharedPointer(); 550 + qpdf->output_buffer = qpdf->qpdf_writer->getBufferSharedPointer();
551 } 551 }
552 } 552 }
553 553
@@ -557,7 +557,7 @@ size_t qpdf_get_buffer_length(qpdf_data qpdf) @@ -557,7 +557,7 @@ size_t qpdf_get_buffer_length(qpdf_data qpdf)
557 size_t result = 0; 557 size_t result = 0;
558 if (qpdf->output_buffer.get()) 558 if (qpdf->output_buffer.get())
559 { 559 {
560 - result = qpdf->output_buffer->getSize(); 560 + result = qpdf->output_buffer->getSize();
561 } 561 }
562 return result; 562 return result;
563 } 563 }
@@ -568,7 +568,7 @@ unsigned char const* qpdf_get_buffer(qpdf_data qpdf) @@ -568,7 +568,7 @@ unsigned char const* qpdf_get_buffer(qpdf_data qpdf)
568 qpdf_get_buffer_internal(qpdf); 568 qpdf_get_buffer_internal(qpdf);
569 if (qpdf->output_buffer.get()) 569 if (qpdf->output_buffer.get())
570 { 570 {
571 - result = qpdf->output_buffer->getBuffer(); 571 + result = qpdf->output_buffer->getBuffer();
572 } 572 }
573 return result; 573 return result;
574 } 574 }
@@ -659,8 +659,8 @@ void qpdf_set_r2_encryption_parameters( @@ -659,8 +659,8 @@ void qpdf_set_r2_encryption_parameters(
659 { 659 {
660 QTC::TC("qpdf", "qpdf-c called qpdf_set_r2_encryption_parameters"); 660 QTC::TC("qpdf", "qpdf-c called qpdf_set_r2_encryption_parameters");
661 qpdf->qpdf_writer->setR2EncryptionParameters( 661 qpdf->qpdf_writer->setR2EncryptionParameters(
662 - user_password, owner_password,  
663 - allow_print != QPDF_FALSE, allow_modify != QPDF_FALSE, 662 + user_password, owner_password,
  663 + allow_print != QPDF_FALSE, allow_modify != QPDF_FALSE,
664 allow_extract != QPDF_FALSE, allow_annotate != QPDF_FALSE); 664 allow_extract != QPDF_FALSE, allow_annotate != QPDF_FALSE);
665 } 665 }
666 666
@@ -743,8 +743,8 @@ void qpdf_set_r3_encryption_parameters( @@ -743,8 +743,8 @@ void qpdf_set_r3_encryption_parameters(
743 # pragma GCC diagnostic ignored "-Wdeprecated-declarations" 743 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
744 #endif 744 #endif
745 qpdf->qpdf_writer->setR3EncryptionParameters( 745 qpdf->qpdf_writer->setR3EncryptionParameters(
746 - user_password, owner_password,  
747 - allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE, 746 + user_password, owner_password,
  747 + allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE,
748 print, modify); 748 print, modify);
749 #if (defined(__GNUC__) || defined(__clang__)) 749 #if (defined(__GNUC__) || defined(__clang__))
750 # pragma GCC diagnostic pop 750 # pragma GCC diagnostic pop
@@ -765,10 +765,10 @@ void qpdf_set_r4_encryption_parameters( @@ -765,10 +765,10 @@ void qpdf_set_r4_encryption_parameters(
765 # pragma GCC diagnostic ignored "-Wdeprecated-declarations" 765 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
766 #endif 766 #endif
767 qpdf->qpdf_writer->setR4EncryptionParameters( 767 qpdf->qpdf_writer->setR4EncryptionParameters(
768 - user_password, owner_password,  
769 - allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE, 768 + user_password, owner_password,
  769 + allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE,
770 print, modify, 770 print, modify,
771 - encrypt_metadata != QPDF_FALSE, use_aes != QPDF_FALSE); 771 + encrypt_metadata != QPDF_FALSE, use_aes != QPDF_FALSE);
772 #if (defined(__GNUC__) || defined(__clang__)) 772 #if (defined(__GNUC__) || defined(__clang__))
773 # pragma GCC diagnostic pop 773 # pragma GCC diagnostic pop
774 #endif 774 #endif
@@ -788,10 +788,10 @@ void qpdf_set_r5_encryption_parameters( @@ -788,10 +788,10 @@ void qpdf_set_r5_encryption_parameters(
788 # pragma GCC diagnostic ignored "-Wdeprecated-declarations" 788 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
789 #endif 789 #endif
790 qpdf->qpdf_writer->setR5EncryptionParameters( 790 qpdf->qpdf_writer->setR5EncryptionParameters(
791 - user_password, owner_password,  
792 - allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE, 791 + user_password, owner_password,
  792 + allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE,
793 print, modify, 793 print, modify,
794 - encrypt_metadata != QPDF_FALSE); 794 + encrypt_metadata != QPDF_FALSE);
795 #if (defined(__GNUC__) || defined(__clang__)) 795 #if (defined(__GNUC__) || defined(__clang__))
796 # pragma GCC diagnostic pop 796 # pragma GCC diagnostic pop
797 #endif 797 #endif
@@ -811,8 +811,8 @@ void qpdf_set_r6_encryption_parameters( @@ -811,8 +811,8 @@ void qpdf_set_r6_encryption_parameters(
811 # pragma GCC diagnostic ignored "-Wdeprecated-declarations" 811 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
812 #endif 812 #endif
813 qpdf->qpdf_writer->setR6EncryptionParameters( 813 qpdf->qpdf_writer->setR6EncryptionParameters(
814 - user_password, owner_password,  
815 - allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE, 814 + user_password, owner_password,
  815 + allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE,
816 print, modify, encrypt_metadata != QPDF_FALSE); 816 print, modify, encrypt_metadata != QPDF_FALSE);
817 #if (defined(__GNUC__) || defined(__clang__)) 817 #if (defined(__GNUC__) || defined(__clang__))
818 # pragma GCC diagnostic pop 818 # pragma GCC diagnostic pop
libqpdf/qpdf/MD5.hh
@@ -51,13 +51,13 @@ class MD5 @@ -51,13 +51,13 @@ class MD5
51 static std::string getDataChecksum(char const* buf, size_t len); 51 static std::string getDataChecksum(char const* buf, size_t len);
52 QPDF_DLL 52 QPDF_DLL
53 static std::string getFileChecksum(char const* filename, 53 static std::string getFileChecksum(char const* filename,
54 - qpdf_offset_t up_to_offset = -1); 54 + qpdf_offset_t up_to_offset = -1);
55 QPDF_DLL 55 QPDF_DLL
56 static bool checkDataChecksum(char const* const checksum, 56 static bool checkDataChecksum(char const* const checksum,
57 - char const* buf, size_t len); 57 + char const* buf, size_t len);
58 QPDF_DLL 58 QPDF_DLL
59 static bool checkFileChecksum(char const* const checksum, 59 static bool checkFileChecksum(char const* const checksum,
60 - char const* filename, 60 + char const* filename,
61 qpdf_offset_t up_to_offset = -1); 61 qpdf_offset_t up_to_offset = -1);
62 62
63 private: 63 private:
libqpdf/qpdf/MD5_native.hh
@@ -21,9 +21,9 @@ class MD5_native @@ -21,9 +21,9 @@ class MD5_native
21 static void encode(unsigned char *, uint32_t *, size_t); 21 static void encode(unsigned char *, uint32_t *, size_t);
22 static void decode(uint32_t *, unsigned char *, size_t); 22 static void decode(uint32_t *, unsigned char *, size_t);
23 23
24 - uint32_t state[4]; // state (ABCD)  
25 - uint32_t count[2]; // number of bits, modulo 2^64 (lsb first)  
26 - unsigned char buffer[64]; // input buffer 24 + uint32_t state[4]; // state (ABCD)
  25 + uint32_t count[2]; // number of bits, modulo 2^64 (lsb first)
  26 + unsigned char buffer[64]; // input buffer
27 27
28 bool finalized; 28 bool finalized;
29 Digest digest_val; 29 Digest digest_val;