Commit 44dce4e2988ec09e36dfb6d1fc527a143e6f597f
Committed by
GitHub
Merge pull request #978 from m-holger/reflow
Code tidy - reflow comments and strings
Showing
137 changed files
with
2381 additions
and
3384 deletions
Too many changes.
To preserve performance only 100 of 137 files are displayed.
.git-blame-ignore-revs
examples/pdf-attach-file.cc
| ... | ... | @@ -8,11 +8,10 @@ |
| 8 | 8 | #include <iostream> |
| 9 | 9 | |
| 10 | 10 | // |
| 11 | -// This example attaches a file to an input file, adds a page to the | |
| 12 | -// beginning of the file that includes a file attachment annotation, | |
| 13 | -// and writes the result to an output file. It also illustrates a | |
| 14 | -// number of new API calls that were added in qpdf 10.2 as well as | |
| 15 | -// the use of the qpdf literal syntax introduced in qpdf 10.6. | |
| 11 | +// This example attaches a file to an input file, adds a page to the beginning of the file that | |
| 12 | +// includes a file attachment annotation, and writes the result to an output file. It also | |
| 13 | +// illustrates a number of new API calls that were added in qpdf 10.2 as well as the use of the qpdf | |
| 14 | +// literal syntax introduced in qpdf 10.6. | |
| 16 | 15 | // |
| 17 | 16 | |
| 18 | 17 | static char const* whoami = nullptr; |
| ... | ... | @@ -43,8 +42,8 @@ process( |
| 43 | 42 | QPDF q; |
| 44 | 43 | q.processFile(infilename, password); |
| 45 | 44 | |
| 46 | - // Create an indirect object for the built-in Helvetica font. This | |
| 47 | - // uses the qpdf literal syntax introduced in qpdf 10.6. | |
| 45 | + // Create an indirect object for the built-in Helvetica font. This uses the qpdf literal syntax | |
| 46 | + // introduced in qpdf 10.6. | |
| 48 | 47 | auto f1 = q.makeIndirectObject( |
| 49 | 48 | // force line-break |
| 50 | 49 | "<<" |
| ... | ... | @@ -55,9 +54,8 @@ process( |
| 55 | 54 | " /Encoding /WinAnsiEncoding" |
| 56 | 55 | ">>"_qpdf); |
| 57 | 56 | |
| 58 | - // Create a resources dictionary with fonts. This uses the new | |
| 59 | - // parse introduced in qpdf 10.2 that takes a QPDF* and allows | |
| 60 | - // indirect object references. | |
| 57 | + // Create a resources dictionary with fonts. This uses the new parse introduced in qpdf 10.2 | |
| 58 | + // that takes a QPDF* and allows indirect object references. | |
| 61 | 59 | auto resources = q.makeIndirectObject( |
| 62 | 60 | // line-break |
| 63 | 61 | QPDFObjectHandle::parse( |
| ... | ... | @@ -97,8 +95,8 @@ process( |
| 97 | 95 | "S\n"); |
| 98 | 96 | auto apdict = ap.getDict(); |
| 99 | 97 | |
| 100 | - // The following four lines demonstrate the use of the qpdf literal syntax | |
| 101 | - // introduced in qpdf 10.6. They could have been written as: | |
| 98 | + // The following four lines demonstrate the use of the qpdf literal syntax introduced in | |
| 99 | + // qpdf 10.6. They could have been written as: | |
| 102 | 100 | // apdict.replaceKey("/Resources", QPDFObjectHandle::newDictionary()); |
| 103 | 101 | // apdict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject")); |
| 104 | 102 | // apdict.replaceKey("/Subtype", QPDFObjectHandle::newName("/Form")); | ... | ... |
examples/pdf-bookmarks.cc
| ... | ... | @@ -8,9 +8,9 @@ |
| 8 | 8 | #include <cstring> |
| 9 | 9 | #include <iostream> |
| 10 | 10 | |
| 11 | -// This program demonstrates extraction of bookmarks using the qpdf | |
| 12 | -// outlines API. Note that all the information shown by this program | |
| 13 | -// can also be obtained from a PDF file using qpdf's --json option. | |
| 11 | +// This program demonstrates extraction of bookmarks using the qpdf outlines API. Note that all the | |
| 12 | +// information shown by this program can also be obtained from a PDF file using qpdf's --json | |
| 13 | +// option. | |
| 14 | 14 | // |
| 15 | 15 | // Ignore calls to QTC::TC - they are for qpdf CI testing only. |
| 16 | 16 | |
| ... | ... | @@ -118,11 +118,10 @@ show_bookmark_details(QPDFOutlineObjectHelper outline, std::vector<int> numbers) |
| 118 | 118 | void |
| 119 | 119 | extract_bookmarks(std::vector<QPDFOutlineObjectHelper> outlines, std::vector<int>& numbers) |
| 120 | 120 | { |
| 121 | - // For style == st_numbers, numbers.at(n) contains the numerical | |
| 122 | - // label for the outline, so we count up from 1. | |
| 123 | - // For style == st_lines, numbers.at(n) == 0 indicates the last | |
| 124 | - // outline at level n, and we don't otherwise care what the value | |
| 125 | - // is, so we count up to zero. | |
| 121 | + // For style == st_numbers, numbers.at(n) contains the numerical label for the outline, so we | |
| 122 | + // count up from 1. | |
| 123 | + // For style == st_lines, numbers.at(n) == 0 indicates the last outline at level n, and we don't | |
| 124 | + // otherwise care what the value is, so we count up to zero. | |
| 126 | 125 | numbers.push_back((style == st_lines) ? -QIntC::to_int(outlines.size()) : 0); |
| 127 | 126 | for (auto& outline: outlines) { |
| 128 | 127 | ++(numbers.back()); | ... | ... |
examples/pdf-c-objects.c
| 1 | -/* | |
| 2 | - * This is an example program to demonstrate use of object handle | |
| 3 | - * functions in the C API. | |
| 4 | - */ | |
| 1 | +/* This is an example program to demonstrate use of object handle functions in the C API. */ | |
| 5 | 2 | |
| 6 | 3 | #include <qpdf/qpdf-c.h> |
| 7 | 4 | #include <stdio.h> |
| ... | ... | @@ -20,8 +17,7 @@ usage() |
| 20 | 17 | QPDF_BOOL |
| 21 | 18 | modify_file(qpdf_data qpdf) |
| 22 | 19 | { |
| 23 | - /* This small example performs the following operation on the | |
| 24 | - * document catalog (a.k.a. root): | |
| 20 | + /* This small example performs the following operation on the document catalog (a.k.a. root): | |
| 25 | 21 | * - Remove PageLayout |
| 26 | 22 | * - Remove OpenAction |
| 27 | 23 | * - If there are outlines, set PageMode to UseOutlines; otherwise, |
| ... | ... | @@ -72,8 +68,7 @@ main(int argc, char* argv[]) |
| 72 | 68 | |
| 73 | 69 | if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) && modify_file(qpdf) && |
| 74 | 70 | ((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0)) { |
| 75 | - /* Use static ID for testing only. For production, a | |
| 76 | - * non-static ID is used. See also | |
| 71 | + /* Use static ID for testing only. For production, a non-static ID is used. See also | |
| 77 | 72 | * qpdf_set_deterministic_ID. */ |
| 78 | 73 | qpdf_set_static_ID(qpdf, QPDF_TRUE); /* for testing only */ |
| 79 | 74 | qpdf_write(qpdf); | ... | ... |
examples/pdf-count-strings.cc
| 1 | 1 | // |
| 2 | -// This example illustrates the use of QPDFObjectHandle::TokenFilter | |
| 3 | -// with filterContents. See also pdf-filter-tokens.cc for an example | |
| 4 | -// that uses QPDFObjectHandle::TokenFilter with addContentTokenFilter. | |
| 2 | +// This example illustrates the use of QPDFObjectHandle::TokenFilter with filterContents. See also | |
| 3 | +// pdf-filter-tokens.cc for an example that uses QPDFObjectHandle::TokenFilter with | |
| 4 | +// addContentTokenFilter. | |
| 5 | 5 | // |
| 6 | 6 | |
| 7 | 7 | #include <cstdlib> |
| ... | ... | @@ -46,16 +46,15 @@ StringCounter::handleToken(QPDFTokenizer::Token const& token) |
| 46 | 46 | if (token.getType() == QPDFTokenizer::tt_string) { |
| 47 | 47 | ++this->count; |
| 48 | 48 | } |
| 49 | - // Preserve input verbatim by passing each token to any specified | |
| 50 | - // downstream filter. | |
| 49 | + // Preserve input verbatim by passing each token to any specified downstream filter. | |
| 51 | 50 | writeToken(token); |
| 52 | 51 | } |
| 53 | 52 | |
| 54 | 53 | void |
| 55 | 54 | StringCounter::handleEOF() |
| 56 | 55 | { |
| 57 | - // Write a comment at the end of the stream just to show how we | |
| 58 | - // can enhance the output if we want. | |
| 56 | + // Write a comment at the end of the stream just to show how we can enhance the output if we | |
| 57 | + // want. | |
| 59 | 58 | write("\n% strings found: "); |
| 60 | 59 | write(std::to_string(this->count)); |
| 61 | 60 | } |
| ... | ... | @@ -82,10 +81,9 @@ main(int argc, char* argv[]) |
| 82 | 81 | int pageno = 0; |
| 83 | 82 | for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 84 | 83 | ++pageno; |
| 85 | - // Pass the contents of a page through our string counter. | |
| 86 | - // If it's an even page, capture the output. This | |
| 87 | - // illustrates that you may capture any output generated | |
| 88 | - // by the filter, or you may ignore it. | |
| 84 | + // Pass the contents of a page through our string counter. If it's an even page, capture | |
| 85 | + // the output. This illustrates that you may capture any output generated by the filter, | |
| 86 | + // or you may ignore it. | |
| 89 | 87 | StringCounter counter; |
| 90 | 88 | if (pageno % 2) { |
| 91 | 89 | // Ignore output for odd pages. | ... | ... |
examples/pdf-create.cc
| 1 | 1 | // |
| 2 | -// This is an example of creating a PDF file from scratch. It | |
| 3 | -// illustrates use of several QPDF operations for creating objects and | |
| 4 | -// streams. It also serves as an illustration of how to use | |
| 2 | +// This is an example of creating a PDF file from scratch. It illustrates use of several QPDF | |
| 3 | +// operations for creating objects and streams. It also serves as an illustration of how to use | |
| 5 | 4 | // StreamDataProvider with different types of filters. |
| 6 | 5 | // |
| 7 | 6 | |
| ... | ... | @@ -20,8 +19,8 @@ |
| 20 | 19 | |
| 21 | 20 | static char const* whoami = nullptr; |
| 22 | 21 | |
| 23 | -// This is a simple StreamDataProvider that writes image data for an | |
| 24 | -// orange square of the given width and height. | |
| 22 | +// This is a simple StreamDataProvider that writes image data for an orange square of the given | |
| 23 | +// width and height. | |
| 25 | 24 | class ImageProvider: public QPDFObjectHandle::StreamDataProvider |
| 26 | 25 | { |
| 27 | 26 | public: |
| ... | ... | @@ -130,8 +129,7 @@ usage() |
| 130 | 129 | static QPDFObjectHandle |
| 131 | 130 | createPageContents(QPDF& pdf, std::string const& text) |
| 132 | 131 | { |
| 133 | - // Create a stream that displays our image and the given text in | |
| 134 | - // our font. | |
| 132 | + // Create a stream that displays our image and the given text in our font. | |
| 135 | 133 | std::string contents = "BT /F1 24 Tf 72 320 Td (" + text + |
| 136 | 134 | ") Tj ET\n" |
| 137 | 135 | "q 244 0 0 144 184 100 cm /Im1 Do Q\n"; |
| ... | ... | @@ -159,11 +157,9 @@ add_page( |
| 159 | 157 | { |
| 160 | 158 | QPDF& pdf(dh.getQPDF()); |
| 161 | 159 | |
| 162 | - // Create a stream to encode our image. QPDFWriter will fill in | |
| 163 | - // the length and will respect our filters based on stream data | |
| 164 | - // mode. Since we are not specifying, QPDFWriter will compress | |
| 165 | - // with /FlateDecode if we don't provide any other form of | |
| 166 | - // compression. | |
| 160 | + // Create a stream to encode our image. QPDFWriter will fill in the length and will respect our | |
| 161 | + // filters based on stream data mode. Since we are not specifying, QPDFWriter will compress with | |
| 162 | + // /FlateDecode if we don't provide any other form of compression. | |
| 167 | 163 | auto* p = new ImageProvider(color_space, filter); |
| 168 | 164 | std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider(p); |
| 169 | 165 | size_t width = p->getWidth(); |
| ... | ... | @@ -219,20 +215,17 @@ check( |
| 219 | 215 | std::vector<std::string> const& color_spaces, |
| 220 | 216 | std::vector<std::string> const& filters) |
| 221 | 217 | { |
| 222 | - // Each stream is compressed the way it is supposed to be. We will | |
| 223 | - // add additional tests in qpdf.test to exercise QPDFWriter more | |
| 224 | - // fully. In this case, we want to make sure that we actually have | |
| 225 | - // RunLengthDecode and DCTDecode where we are supposed to and | |
| 226 | - // FlateDecode where we provided no filters. | |
| 218 | + // Each stream is compressed the way it is supposed to be. We will add additional tests in | |
| 219 | + // qpdf.test to exercise QPDFWriter more fully. In this case, we want to make sure that we | |
| 220 | + // actually have RunLengthDecode and DCTDecode where we are supposed to and FlateDecode where we | |
| 221 | + // provided no filters. | |
| 227 | 222 | |
| 228 | - // Each image is correct. For non-lossy image compression, the | |
| 229 | - // uncompressed image data should exactly match what ImageProvider | |
| 230 | - // provided. For the DCTDecode data, allow for some fuzz to handle | |
| 231 | - // jpeg compression as well as its variance on different systems. | |
| 223 | + // Each image is correct. For non-lossy image compression, the uncompressed image data should | |
| 224 | + // exactly match what ImageProvider provided. For the DCTDecode data, allow for some fuzz to | |
| 225 | + // handle jpeg compression as well as its variance on different systems. | |
| 232 | 226 | |
| 233 | - // These tests should use QPDFObjectHandle's stream data retrieval | |
| 234 | - // methods, but don't try to fully exercise them here. That is | |
| 235 | - // done elsewhere. | |
| 227 | + // These tests should use QPDFObjectHandle's stream data retrieval methods, but don't try to | |
| 228 | + // fully exercise them here. That is done elsewhere. | |
| 236 | 229 | |
| 237 | 230 | size_t n_color_spaces = color_spaces.size(); |
| 238 | 231 | size_t n_filters = filters.size(); |
| ... | ... | @@ -254,8 +247,8 @@ check( |
| 254 | 247 | // Check filter and color space. |
| 255 | 248 | std::string desired_color_space = color_spaces[(pageno - 1) / n_color_spaces]; |
| 256 | 249 | std::string desired_filter = filters[(pageno - 1) % n_filters]; |
| 257 | - // In the default mode, QPDFWriter will compress with | |
| 258 | - // /FlateDecode if no filters are provided. | |
| 250 | + // In the default mode, QPDFWriter will compress with /FlateDecode if no filters are | |
| 251 | + // provided. | |
| 259 | 252 | if (desired_filter == "null") { |
| 260 | 253 | desired_filter = "/FlateDecode"; |
| 261 | 254 | } |
| ... | ... | @@ -288,11 +281,9 @@ check( |
| 288 | 281 | std::cout << "page " << pageno << ": image data length mismatch" << std::endl; |
| 289 | 282 | this_errors = errors = true; |
| 290 | 283 | } else { |
| 291 | - // Compare bytes. For JPEG, allow a certain number of | |
| 292 | - // the bytes to be off desired by more than a given | |
| 293 | - // tolerance. Any of the samples may be a little off | |
| 294 | - // because of lossy compression, and around sharp | |
| 295 | - // edges, things can be quite off. For non-lossy | |
| 284 | + // Compare bytes. For JPEG, allow a certain number of the bytes to be off desired by | |
| 285 | + // more than a given tolerance. Any of the samples may be a little off because of | |
| 286 | + // lossy compression, and around sharp edges, things can be quite off. For non-lossy | |
| 296 | 287 | // compression, do not allow any tolerance. |
| 297 | 288 | unsigned char const* actual_bytes = actual_data->getBuffer(); |
| 298 | 289 | unsigned char const* desired_bytes = desired_data->getBuffer(); |
| ... | ... | @@ -332,8 +323,7 @@ create_pdf(char const* filename) |
| 332 | 323 | // Start with an empty PDF that has no pages or non-required objects. |
| 333 | 324 | pdf.emptyPDF(); |
| 334 | 325 | |
| 335 | - // Add an indirect object to contain a font descriptor for the | |
| 336 | - // built-in Helvetica font. | |
| 326 | + // Add an indirect object to contain a font descriptor for the built-in Helvetica font. | |
| 337 | 327 | QPDFObjectHandle font = pdf.makeIndirectObject( |
| 338 | 328 | // line-break |
| 339 | 329 | "<<" |
| ... | ... | @@ -362,8 +352,7 @@ create_pdf(char const* filename) |
| 362 | 352 | QPDFWriter w(pdf, filename); |
| 363 | 353 | w.write(); |
| 364 | 354 | |
| 365 | - // For test suite, verify that everything is the way it is | |
| 366 | - // supposed to be. | |
| 355 | + // For test suite, verify that everything is the way it is supposed to be. | |
| 367 | 356 | check(filename, color_spaces, filters); |
| 368 | 357 | } |
| 369 | 358 | ... | ... |
examples/pdf-custom-filter.cc
| ... | ... | @@ -8,43 +8,35 @@ |
| 8 | 8 | #include <iostream> |
| 9 | 9 | #include <memory> |
| 10 | 10 | |
| 11 | -// This example shows you everything you need to know to implement a | |
| 12 | -// custom stream filter for encoding and decoding as well as a stream | |
| 13 | -// data provider that modifies the stream's dictionary. This example | |
| 14 | -// uses the pattern of having the stream data provider class use a | |
| 15 | -// second QPDF instance with copies of streams from the original QPDF | |
| 16 | -// so that the stream data provider can access the original stream | |
| 17 | -// data. This is implemented very efficiently inside the qpdf library as | |
| 18 | -// the second QPDF instance knows how to read the stream data from the | |
| 19 | -// original input file, so no extra copies of the original stream data | |
| 20 | -// are made. | |
| 21 | - | |
| 22 | -// This example creates an imaginary filter called /XORDecode. There | |
| 23 | -// is no such filter in PDF, so the streams created by the example | |
| 24 | -// would not be usable by any PDF reader. However, the techniques here | |
| 25 | -// would work if you were going to implement support for a filter that | |
| 26 | -// qpdf does not support natively. For example, using the techniques | |
| 27 | -// shown here, it would be possible to create an application that | |
| 28 | -// downsampled or re-encoded images or that re-compressed streams | |
| 29 | -// using a more efficient "deflate" implementation than zlib. | |
| 30 | - | |
| 31 | -// Comments appear throughout the code describing each piece of code | |
| 32 | -// and its purpose. You can read the file top to bottom, or you can | |
| 33 | -// start with main() and follow the flow. | |
| 34 | - | |
| 35 | -// Please also see the test suite, qtest/custom-filter.test, which | |
| 36 | -// contains additional comments describing how to observe the results | |
| 37 | -// of running this example on test files that are specifically crafted | |
| 38 | -// for it. | |
| 11 | +// This example shows you everything you need to know to implement a custom stream filter for | |
| 12 | +// encoding and decoding as well as a stream data provider that modifies the stream's dictionary. | |
| 13 | +// This example uses the pattern of having the stream data provider class use a second QPDF instance | |
| 14 | +// with copies of streams from the original QPDF so that the stream data provider can access the | |
| 15 | +// original stream data. This is implemented very efficiently inside the qpdf library as the second | |
| 16 | +// QPDF instance knows how to read the stream data from the original input file, so no extra copies | |
| 17 | +// of the original stream data are made. | |
| 18 | + | |
| 19 | +// This example creates an imaginary filter called /XORDecode. There is no such filter in PDF, so | |
| 20 | +// the streams created by the example would not be usable by any PDF reader. However, the techniques | |
| 21 | +// here would work if you were going to implement support for a filter that qpdf does not support | |
| 22 | +// natively. For example, using the techniques shown here, it would be possible to create an | |
| 23 | +// application that downsampled or re-encoded images or that re-compressed streams using a more | |
| 24 | +// efficient "deflate" implementation than zlib. | |
| 25 | + | |
| 26 | +// Comments appear throughout the code describing each piece of code and its purpose. You can read | |
| 27 | +// the file top to bottom, or you can start with main() and follow the flow. | |
| 28 | + | |
| 29 | +// Please also see the test suite, qtest/custom-filter.test, which contains additional comments | |
| 30 | +// describing how to observe the results of running this example on test files that are specifically | |
| 31 | +// crafted for it. | |
| 39 | 32 | |
| 40 | 33 | static char const* whoami = nullptr; |
| 41 | 34 | |
| 42 | 35 | class Pl_XOR: public Pipeline |
| 43 | 36 | { |
| 44 | - // This class implements a Pipeline for the made-up XOR decoder. | |
| 45 | - // It is initialized with a single-byte "key" and just XORs each | |
| 46 | - // byte with that key. This makes it reversible, so there is no | |
| 47 | - // distinction between encoding and decoding. | |
| 37 | + // This class implements a Pipeline for the made-up XOR decoder. It is initialized with a | |
| 38 | + // single-byte "key" and just XORs each byte with that key. This makes it reversible, so there | |
| 39 | + // is no distinction between encoding and decoding. | |
| 48 | 40 | |
| 49 | 41 | public: |
| 50 | 42 | Pl_XOR(char const* identifier, Pipeline* next, unsigned char key); |
| ... | ... | @@ -79,17 +71,14 @@ Pl_XOR::finish() |
| 79 | 71 | |
| 80 | 72 | class SF_XORDecode: public QPDFStreamFilter |
| 81 | 73 | { |
| 82 | - // This class implements a QPDFStreamFilter that knows how to | |
| 83 | - // validate and interpret decode parameters (/DecodeParms) for the | |
| 84 | - // made-up /XORDecode stream filter. Since this is not a real | |
| 85 | - // stream filter, no actual PDF reader would know how to interpret | |
| 86 | - // it. This is just to illustrate how to create a stream filter. | |
| 87 | - // In main(), we call QPDF::registerStreamFilter to tell the | |
| 88 | - // library about the filter. See comments in QPDFStreamFilter.hh | |
| 89 | - // for details on how to implement the methods. For purposes of | |
| 90 | - // example, we are calling this a "specialized" compression | |
| 91 | - // filter, which just means QPDF assumes that it should not | |
| 92 | - // "uncompress" the stream by default. | |
| 74 | + // This class implements a QPDFStreamFilter that knows how to validate and interpret decode | |
| 75 | + // parameters (/DecodeParms) for the made-up /XORDecode stream filter. Since this is not a real | |
| 76 | + // stream filter, no actual PDF reader would know how to interpret it. This is just to | |
| 77 | + // illustrate how to create a stream filter. In main(), we call QPDF::registerStreamFilter to | |
| 78 | + // tell the library about the filter. See comments in QPDFStreamFilter.hh for details on how to | |
| 79 | + // implement the methods. For purposes of example, we are calling this a "specialized" | |
| 80 | + // compression filter, which just means QPDF assumes that it should not "uncompress" the stream | |
| 81 | + // by default. | |
| 93 | 82 | public: |
| 94 | 83 | ~SF_XORDecode() override = default; |
| 95 | 84 | bool setDecodeParms(QPDFObjectHandle decode_parms) override; |
| ... | ... | @@ -98,33 +87,28 @@ class SF_XORDecode: public QPDFStreamFilter |
| 98 | 87 | |
| 99 | 88 | private: |
| 100 | 89 | unsigned char key; |
| 101 | - // It is the responsibility of the QPDFStreamFilter implementation | |
| 102 | - // to ensure that the pipeline returned by getDecodePipeline() is | |
| 103 | - // deleted when the class is deleted. The easiest way to do this | |
| 104 | - // is to stash the pipeline in a std::shared_ptr, which enables us | |
| 105 | - // to use the default destructor implementation. | |
| 90 | + // It is the responsibility of the QPDFStreamFilter implementation to ensure that the pipeline | |
| 91 | + // returned by getDecodePipeline() is deleted when the class is deleted. The easiest way to do | |
| 92 | + // this is to stash the pipeline in a std::shared_ptr, which enables us to use the default | |
| 93 | + // destructor implementation. | |
| 106 | 94 | std::shared_ptr<Pl_XOR> pipeline; |
| 107 | 95 | }; |
| 108 | 96 | |
| 109 | 97 | bool |
| 110 | 98 | SF_XORDecode::setDecodeParms(QPDFObjectHandle decode_parms) |
| 111 | 99 | { |
| 112 | - // For purposes of example, we store the key in a separate stream. | |
| 113 | - // We could just as well store the key directly in /DecodeParms, | |
| 114 | - // but this example uses a stream to illustrate how one might do | |
| 115 | - // that. For example, if implementing /JBIG2Decode, one would need | |
| 116 | - // to handle the /JBIG2Globals key, which points to a stream. See | |
| 117 | - // comments in SF_XORDecode::registerStream for additional notes | |
| 118 | - // on this. | |
| 100 | + // For purposes of example, we store the key in a separate stream. We could just as well store | |
| 101 | + // the key directly in /DecodeParms, but this example uses a stream to illustrate how one might | |
| 102 | + // do that. For example, if implementing /JBIG2Decode, one would need to handle the | |
| 103 | + // /JBIG2Globals key, which points to a stream. See comments in SF_XORDecode::registerStream for | |
| 104 | + // additional notes on this. | |
| 119 | 105 | try { |
| 120 | - // Expect /DecodeParms to be a dictionary with a /KeyStream | |
| 121 | - // key that points to a one-byte stream whose single byte is | |
| 122 | - // the key. If we are successful at retrieving the key, return | |
| 123 | - // true, indicating that we are able to process with the given | |
| 124 | - // decode parameters. Under any other circumstances, return | |
| 125 | - // false. For other examples of QPDFStreamFilter | |
| 126 | - // implementations, look at the classes whose names start with | |
| 127 | - // SF_ in the qpdf library implementation. | |
| 106 | + // Expect /DecodeParms to be a dictionary with a /KeyStream key that points to a one-byte | |
| 107 | + // stream whose single byte is the key. If we are successful at retrieving the key, return | |
| 108 | + // true, indicating that we are able to process with the given decode parameters. Under any | |
| 109 | + // other circumstances, return false. For other examples of QPDFStreamFilter | |
| 110 | + // implementations, look at the classes whose names start with SF_ in the qpdf library | |
| 111 | + // implementation. | |
| 128 | 112 | auto buf = decode_parms.getKey("/KeyStream").getStreamData(); |
| 129 | 113 | if (buf->getSize() != 1) { |
| 130 | 114 | return false; |
| ... | ... | @@ -140,14 +124,12 @@ SF_XORDecode::setDecodeParms(QPDFObjectHandle decode_parms) |
| 140 | 124 | Pipeline* |
| 141 | 125 | SF_XORDecode::getDecodePipeline(Pipeline* next) |
| 142 | 126 | { |
| 143 | - // Return a pipeline that the qpdf library should pass the stream | |
| 144 | - // data through. The pipeline should receive encoded data and pass | |
| 145 | - // decoded data to "next". getDecodePipeline() can always count on | |
| 146 | - // setDecodeParms() having been called first. The setDecodeParms() | |
| 147 | - // method should store any parameters needed by the pipeline. To | |
| 148 | - // ensure that the pipeline we return disappears when the class | |
| 149 | - // disappears, stash it in a std::shared_ptr<Pl_XOR> and retrieve | |
| 150 | - // the raw pointer from there. | |
| 127 | + // Return a pipeline that the qpdf library should pass the stream data through. The pipeline | |
| 128 | + // should receive encoded data and pass decoded data to "next". getDecodePipeline() can always | |
| 129 | + // count on setDecodeParms() having been called first. The setDecodeParms() method should store | |
| 130 | + // any parameters needed by the pipeline. To ensure that the pipeline we return disappears when | |
| 131 | + // the class disappears, stash it in a std::shared_ptr<Pl_XOR> and retrieve the raw pointer from | |
| 132 | + // there. | |
| 151 | 133 | this->pipeline = std::make_shared<Pl_XOR>("xor", next, this->key); |
| 152 | 134 | return this->pipeline.get(); |
| 153 | 135 | } |
| ... | ... | @@ -155,46 +137,37 @@ SF_XORDecode::getDecodePipeline(Pipeline* next) |
| 155 | 137 | bool |
| 156 | 138 | SF_XORDecode::isSpecializedCompression() |
| 157 | 139 | { |
| 158 | - // The default implementation of QPDFStreamFilter would return | |
| 159 | - // false, so if you want a specialized or lossy compression | |
| 160 | - // filter, override one of the methods as described in | |
| 140 | + // The default implementation of QPDFStreamFilter would return false, so if you want a | |
| 141 | + // specialized or lossy compression filter, override one of the methods as described in | |
| 161 | 142 | // QPDFStreamFilter.hh. |
| 162 | 143 | return true; |
| 163 | 144 | } |
| 164 | 145 | |
| 165 | 146 | class StreamReplacer: public QPDFObjectHandle::StreamDataProvider |
| 166 | 147 | { |
| 167 | - // This class implements a StreamDataProvider that, under specific | |
| 168 | - // conditions, replaces the stream data with data encoded with the | |
| 169 | - // made-up /XORDecode filter. | |
| 148 | + // This class implements a StreamDataProvider that, under specific conditions, replaces the | |
| 149 | + // stream data with data encoded with the made-up /XORDecode filter. | |
| 170 | 150 | |
| 171 | 151 | // The flow for this class is as follows: |
| 172 | 152 | // |
| 173 | - // * The main application iterates through streams that should be | |
| 174 | - // replaced and calls registerStream. registerStream in turn | |
| 175 | - // calls maybeReplace passing nullptr to pipeline and the | |
| 176 | - // address of a valid QPDFObjectHandle to dict_updates. The | |
| 177 | - // stream passed in for this call is the stream for the original | |
| 178 | - // QPDF object. It has not yet been altered, so we have access | |
| 179 | - // to its original dictionary and data. As described in the | |
| 180 | - // method, the method when called in this way makes a | |
| 181 | - // determination as to whether the stream should be replaced. If | |
| 182 | - // so, registerStream makes whatever changes are required. We | |
| 183 | - // have to do this now because we can't modify the stream during | |
| 184 | - // the writing process. | |
| 153 | + // * The main application iterates through streams that should be replaced and calls | |
| 154 | + // registerStream. registerStream in turn calls maybeReplace passing nullptr to pipeline and | |
| 155 | + // the address of a valid QPDFObjectHandle to dict_updates. The stream passed in for this call | |
| 156 | + // is the stream for the original QPDF object. It has not yet been altered, so we have access | |
| 157 | + // to its original dictionary and data. As described in the method, the method when called in | |
| 158 | + // this way makes a determination as to whether the stream should be replaced. If so, | |
| 159 | + // registerStream makes whatever changes are required. We have to do this now because we can't | |
| 160 | + // modify the stream during the writing process. | |
| 185 | 161 | // |
| 186 | - // * provideStreamData(), which is called by QPDFWriter during the | |
| 187 | - // write process, actually writes the modified stream data. It | |
| 188 | - // calls maybeReplace again, but this time it passes a valid | |
| 189 | - // pipeline and passes nullptr to dict_updates. In this mode, | |
| 190 | - // the stream dictionary has already been altered, and the | |
| 191 | - // original stream data is no longer directly accessible. Trying | |
| 192 | - // to retrieve the stream data would cause an infinite loop because | |
| 193 | - // it would just end up calling provideStreamData again. This is | |
| 194 | - // why maybeReplace uses a stashed copy of the original stream. | |
| 195 | - | |
| 196 | - // Additional explanation can be found in the method | |
| 197 | - // implementations. | |
| 162 | + // * provideStreamData(), which is called by QPDFWriter during the write process, actually | |
| 163 | + // writes the modified stream data. It calls maybeReplace again, but this time it passes a | |
| 164 | + // valid pipeline and passes nullptr to dict_updates. In this mode, the stream dictionary has | |
| 165 | + // already been altered, and the original stream data is no longer directly accessible. Trying | |
| 166 | + // to retrieve the stream data would cause an infinite loop because it would just end up | |
| 167 | + // calling provideStreamData again. This is why maybeReplace uses a stashed copy of the | |
| 168 | + // original stream. | |
| 169 | + | |
| 170 | + // Additional explanation can be found in the method implementations. | |
| 198 | 171 | |
| 199 | 172 | public: |
| 200 | 173 | StreamReplacer(QPDF* pdf); |
| ... | ... | @@ -211,17 +184,16 @@ class StreamReplacer: public QPDFObjectHandle::StreamDataProvider |
| 211 | 184 | Pipeline* pipeline, |
| 212 | 185 | QPDFObjectHandle* dict_updates); |
| 213 | 186 | |
| 214 | - // Hang onto a reference to the QPDF object containing the streams | |
| 215 | - // we are replacing. We need this to create a new stream. | |
| 187 | + // Hang onto a reference to the QPDF object containing the streams we are replacing. We need | |
| 188 | + // this to create a new stream. | |
| 216 | 189 | QPDF* pdf; |
| 217 | 190 | |
| 218 | - // Map the object/generation in original file to the copied stream | |
| 219 | - // in "other". We use this to retrieve the original data. | |
| 191 | + // Map the object/generation in original file to the copied stream in "other". We use this to | |
| 192 | + // retrieve the original data. | |
| 220 | 193 | std::map<QPDFObjGen, QPDFObjectHandle> copied_streams; |
| 221 | 194 | |
| 222 | - // Each stream gets is own "key" for the XOR filter. We use a | |
| 223 | - // single instance of StreamReplacer for all streams, so stash all | |
| 224 | - // the keys here. | |
| 195 | + // Each stream gets is own "key" for the XOR filter. We use a single instance of StreamReplacer | |
| 196 | + // for all streams, so stash all the keys here. | |
| 225 | 197 | std::map<QPDFObjGen, unsigned char> keys; |
| 226 | 198 | }; |
| 227 | 199 | |
| ... | ... | @@ -237,49 +209,38 @@ StreamReplacer::maybeReplace( |
| 237 | 209 | Pipeline* pipeline, |
| 238 | 210 | QPDFObjectHandle* dict_updates) |
| 239 | 211 | { |
| 240 | - // As described in the class comments, this method is called | |
| 241 | - // twice. Before writing has started pipeline is nullptr, and | |
| 242 | - // dict_updates is provided. In this mode, we figure out whether | |
| 243 | - // we should replace the stream and, if so, take care of the | |
| 244 | - // necessary setup. When we are actually ready to supply the data, | |
| 245 | - // this method is called again with pipeline populated and | |
| 246 | - // dict_updates as a nullptr. In this mode, we are not allowed to | |
| 247 | - // change anything, since writing is already in progress. We | |
| 248 | - // must simply provide the stream data. | |
| 249 | - | |
| 250 | - // The return value indicates whether or not we should replace the | |
| 251 | - // stream. If the first call returns false, there will be no | |
| 252 | - // second call. If the second call returns false, something went | |
| 253 | - // wrong since the method should always make the same decision for | |
| 254 | - // a given stream. | |
| 255 | - | |
| 256 | - // For this example, all the determination logic could have | |
| 257 | - // appeared inside the if (dict_updates) block rather than being | |
| 258 | - // duplicated, but in some cases, there may be a reason to | |
| 259 | - // duplicate things. For example, if you wanted to write code that | |
| 260 | - // re-encoded an image if the new encoding was more efficient, | |
| 261 | - // you'd have to actually try it out. Then you would either have | |
| 262 | - // to cache the result somewhere or just repeat the calculations, | |
| 263 | - // depending on space/time constraints, etc. | |
| 264 | - | |
| 265 | - // In our contrived example, we are replacing the data for all | |
| 266 | - // streams that have /DoXOR = true in the stream dictionary. If | |
| 267 | - // this were a more realistic application, our criteria would be | |
| 268 | - // more sensible. For example, an image downsampler might choose | |
| 269 | - // to replace a stream that represented an image with a high pixel | |
| 270 | - // density. | |
| 212 | + // As described in the class comments, this method is called twice. Before writing has started | |
| 213 | + // pipeline is nullptr, and dict_updates is provided. In this mode, we figure out whether we | |
| 214 | + // should replace the stream and, if so, take care of the necessary setup. When we are actually | |
| 215 | + // ready to supply the data, this method is called again with pipeline populated and | |
| 216 | + // dict_updates as a nullptr. In this mode, we are not allowed to change anything, since writing | |
| 217 | + // is already in progress. We must simply provide the stream data. | |
| 218 | + | |
| 219 | + // The return value indicates whether or not we should replace the stream. If the first call | |
| 220 | + // returns false, there will be no second call. If the second call returns false, something went | |
| 221 | + // wrong since the method should always make the same decision for a given stream. | |
| 222 | + | |
| 223 | + // For this example, all the determination logic could have appeared inside the if | |
| 224 | + // (dict_updates) block rather than being duplicated, but in some cases, there may be a reason | |
| 225 | + // to duplicate things. For example, if you wanted to write code that re-encoded an image if the | |
| 226 | + // new encoding was more efficient, you'd have to actually try it out. Then you would either | |
| 227 | + // have to cache the result somewhere or just repeat the calculations, depending on space/time | |
| 228 | + // constraints, etc. | |
| 229 | + | |
| 230 | + // In our contrived example, we are replacing the data for all streams that have /DoXOR = true | |
| 231 | + // in the stream dictionary. If this were a more realistic application, our criteria would be | |
| 232 | + // more sensible. For example, an image downsampler might choose to replace a stream that | |
| 233 | + // represented an image with a high pixel density. | |
| 271 | 234 | auto dict = stream.getDict(); |
| 272 | 235 | auto mark = dict.getKey("/DoXOR"); |
| 273 | 236 | if (!(mark.isBool() && mark.getBoolValue())) { |
| 274 | 237 | return false; |
| 275 | 238 | } |
| 276 | 239 | |
| 277 | - // We can't replace the stream data if we can't get the original | |
| 278 | - // stream data for any reason. A more realistic application may | |
| 279 | - // actually look at the data here as well, or it may be able to | |
| 280 | - // make all its decisions from the stream dictionary. However, | |
| 281 | - // it's a good idea to make sure we can retrieve the filtered data | |
| 282 | - // if we are going to need it later. | |
| 240 | + // We can't replace the stream data if we can't get the original stream data for any reason. A | |
| 241 | + // more realistic application may actually look at the data here as well, or it may be able to | |
| 242 | + // make all its decisions from the stream dictionary. However, it's a good idea to make sure we | |
| 243 | + // can retrieve the filtered data if we are going to need it later. | |
| 283 | 244 | std::shared_ptr<Buffer> out; |
| 284 | 245 | try { |
| 285 | 246 | out = stream.getStreamData(); |
| ... | ... | @@ -288,19 +249,15 @@ StreamReplacer::maybeReplace( |
| 288 | 249 | } |
| 289 | 250 | |
| 290 | 251 | if (dict_updates) { |
| 291 | - // It's not safe to make any modifications to any objects | |
| 292 | - // during the writing process since the updated objects may | |
| 293 | - // have already been written. In this mode, when dict_updates | |
| 294 | - // is provided, we have not started writing. Store the | |
| 295 | - // modifications we intend to make to the stream dictionary | |
| 296 | - // here. We're just storing /OrigLength for purposes of | |
| 297 | - // example. Again, a realistic application would make other | |
| 298 | - // changes. For example, an image resampler might change the | |
| 299 | - // dimensions or other properties of the image. | |
| 252 | + // It's not safe to make any modifications to any objects during the writing process since | |
| 253 | + // the updated objects may have already been written. In this mode, when dict_updates is | |
| 254 | + // provided, we have not started writing. Store the modifications we intend to make to the | |
| 255 | + // stream dictionary here. We're just storing /OrigLength for purposes of example. Again, a | |
| 256 | + // realistic application would make other changes. For example, an image resampler might | |
| 257 | + // change the dimensions or other properties of the image. | |
| 300 | 258 | dict_updates->replaceKey( |
| 301 | 259 | "/OrigLength", QPDFObjectHandle::newInteger(QIntC::to_longlong(out->getSize()))); |
| 302 | - // We are also storing the "key" that we will access when | |
| 303 | - // writing the data. | |
| 260 | + // We are also storing the "key" that we will access when writing the data. | |
| 304 | 261 | this->keys[og] = QIntC::to_uchar((og.getObj() * QIntC::to_int(out->getSize())) & 0xff); |
| 305 | 262 | } |
| 306 | 263 | |
| ... | ... | @@ -319,21 +276,18 @@ StreamReplacer::registerStream( |
| 319 | 276 | { |
| 320 | 277 | QPDFObjGen og(stream.getObjGen()); |
| 321 | 278 | |
| 322 | - // We don't need to process a stream more than once. In this | |
| 323 | - // example, we are just iterating through objects, but if we were | |
| 324 | - // doing something like iterating through images on pages, we | |
| 279 | + // We don't need to process a stream more than once. In this example, we are just iterating | |
| 280 | + // through objects, but if we were doing something like iterating through images on pages, we | |
| 325 | 281 | // might realistically encounter the same stream more than once. |
| 326 | 282 | if (this->copied_streams.count(og) > 0) { |
| 327 | 283 | return; |
| 328 | 284 | } |
| 329 | - // Store something in copied_streams so that we don't | |
| 330 | - // double-process even in the negative case. This gets replaced | |
| 331 | - // later if needed. | |
| 285 | + // Store something in copied_streams so that we don't double-process even in the negative case. | |
| 286 | + // This gets replaced later if needed. | |
| 332 | 287 | this->copied_streams[og] = QPDFObjectHandle::newNull(); |
| 333 | 288 | |
| 334 | - // Call maybeReplace with dict_updates. In this mode, it | |
| 335 | - // determines whether we should replace the stream data and, if | |
| 336 | - // so, supplies dictionary updates we should make. | |
| 289 | + // Call maybeReplace with dict_updates. In this mode, it determines whether we should replace | |
| 290 | + // the stream data and, if so, supplies dictionary updates we should make. | |
| 337 | 291 | bool should_replace = false; |
| 338 | 292 | QPDFObjectHandle dict_updates = QPDFObjectHandle::newDictionary(); |
| 339 | 293 | try { |
| ... | ... | @@ -343,9 +297,8 @@ StreamReplacer::registerStream( |
| 343 | 297 | } |
| 344 | 298 | |
| 345 | 299 | if (should_replace) { |
| 346 | - // Copy the stream so we can get to the original data from the | |
| 347 | - // stream data provider. This doesn't actually copy any data, | |
| 348 | - // but the copy retains the original stream data after the | |
| 300 | + // Copy the stream so we can get to the original data from the stream data provider. This | |
| 301 | + // doesn't actually copy any data, but the copy retains the original stream data after the | |
| 349 | 302 | // original one is modified. |
| 350 | 303 | this->copied_streams[og] = stream.copyStream(); |
| 351 | 304 | // Update the stream dictionary with any changes. |
| ... | ... | @@ -353,20 +306,17 @@ StreamReplacer::registerStream( |
| 353 | 306 | for (auto const& k: dict_updates.getKeys()) { |
| 354 | 307 | dict.replaceKey(k, dict_updates.getKey(k)); |
| 355 | 308 | } |
| 356 | - // Create the key stream that will be referenced from | |
| 357 | - // /DecodeParms. We have to do this now since you can't modify | |
| 358 | - // or create objects during write. | |
| 309 | + // Create the key stream that will be referenced from /DecodeParms. We have to do this now | |
| 310 | + // since you can't modify or create objects during write. | |
| 359 | 311 | char p[1] = {static_cast<char>(this->keys[og])}; |
| 360 | 312 | std::string p_str(p, 1); |
| 361 | 313 | QPDFObjectHandle dp_stream = this->pdf->newStream(p_str); |
| 362 | - // Create /DecodeParms as expected by our fictitious | |
| 363 | - // /XORDecode filter. | |
| 314 | + // Create /DecodeParms as expected by our fictitious /XORDecode filter. | |
| 364 | 315 | QPDFObjectHandle decode_parms = |
| 365 | 316 | QPDFObjectHandle::newDictionary({{"/KeyStream", dp_stream}}); |
| 366 | 317 | stream.replaceStreamData(self, QPDFObjectHandle::newName("/XORDecode"), decode_parms); |
| 367 | - // Further, if /ProtectXOR = true, we disable filtering on write | |
| 368 | - // so that QPDFWriter will not decode the stream even though we | |
| 369 | - // have registered a stream filter for /XORDecode. | |
| 318 | + // Further, if /ProtectXOR = true, we disable filtering on write so that QPDFWriter will not | |
| 319 | + // decode the stream even though we have registered a stream filter for /XORDecode. | |
| 370 | 320 | auto protect = dict.getKey("/ProtectXOR"); |
| 371 | 321 | if (protect.isBool() && protect.getBoolValue()) { |
| 372 | 322 | stream.setFilterOnWrite(false); |
| ... | ... | @@ -378,14 +328,12 @@ void |
| 378 | 328 | StreamReplacer::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) |
| 379 | 329 | { |
| 380 | 330 | QPDFObjectHandle orig = this->copied_streams[og]; |
| 381 | - // call maybeReplace again, this time with the pipeline and no | |
| 382 | - // dict_updates. In this mode, maybeReplace doesn't make any | |
| 383 | - // changes. We have to hand it the original stream data, which we | |
| 331 | + // call maybeReplace again, this time with the pipeline and no dict_updates. In this mode, | |
| 332 | + // maybeReplace doesn't make any changes. We have to hand it the original stream data, which we | |
| 384 | 333 | // get from copied_streams. |
| 385 | 334 | if (!maybeReplace(og, orig, pipeline, nullptr)) { |
| 386 | - // Since this only gets called for streams we already | |
| 387 | - // determined we are replacing, a false return would indicate | |
| 388 | - // a logic error. | |
| 335 | + // Since this only gets called for streams we already determined we are replacing, a false | |
| 336 | + // return would indicate a logic error. | |
| 389 | 337 | throw std::logic_error("should_replace return false in provideStreamData"); |
| 390 | 338 | } |
| 391 | 339 | } |
| ... | ... | @@ -396,17 +344,15 @@ process(char const* infilename, char const* outfilename, bool decode_specialized |
| 396 | 344 | QPDF qpdf; |
| 397 | 345 | qpdf.processFile(infilename); |
| 398 | 346 | |
| 399 | - // Create a single StreamReplacer instance. The interface requires | |
| 400 | - // a std::shared_ptr in various places, so allocate a StreamReplacer | |
| 401 | - // and stash it in a std::shared_ptr. | |
| 347 | + // Create a single StreamReplacer instance. The interface requires a std::shared_ptr in various | |
| 348 | + // places, so allocate a StreamReplacer and stash it in a std::shared_ptr. | |
| 402 | 349 | auto* replacer = new StreamReplacer(&qpdf); |
| 403 | 350 | std::shared_ptr<QPDFObjectHandle::StreamDataProvider> p(replacer); |
| 404 | 351 | |
| 405 | 352 | for (auto& o: qpdf.getAllObjects()) { |
| 406 | 353 | if (o.isStream()) { |
| 407 | - // Call registerStream for every stream. Only ones that | |
| 408 | - // registerStream decides to replace will actually be | |
| 409 | - // replaced. | |
| 354 | + // Call registerStream for every stream. Only ones that registerStream decides to | |
| 355 | + // replace will actually be replaced. | |
| 410 | 356 | replacer->registerStream(o, p); |
| 411 | 357 | } |
| 412 | 358 | } |
| ... | ... | @@ -454,9 +400,8 @@ main(int argc, char* argv[]) |
| 454 | 400 | } |
| 455 | 401 | |
| 456 | 402 | try { |
| 457 | - // Register our fictitious filter. This enables QPDFWriter to | |
| 458 | - // decode our streams. This is not a real filter, so no real | |
| 459 | - // PDF reading application would be able to interpret it. This | |
| 403 | + // Register our fictitious filter. This enables QPDFWriter to decode our streams. This is | |
| 404 | + // not a real filter, so no real PDF reading application would be able to interpret it. This | |
| 460 | 405 | // is just for illustrative purposes. |
| 461 | 406 | QPDF::registerStreamFilter("/XORDecode", [] { return std::make_shared<SF_XORDecode>(); }); |
| 462 | 407 | // Do the actual processing. | ... | ... |
examples/pdf-double-page-size.cc
| ... | ... | @@ -14,18 +14,16 @@ void |
| 14 | 14 | usage() |
| 15 | 15 | { |
| 16 | 16 | std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" << std::endl |
| 17 | - << "Double size of all pages in infile.pdf;" | |
| 18 | - << " write output to outfile.pdf" << std::endl; | |
| 17 | + << "Double size of all pages in infile.pdf; write output to outfile.pdf" << std::endl; | |
| 19 | 18 | exit(2); |
| 20 | 19 | } |
| 21 | 20 | |
| 22 | -// If there is a box of name box_name, replace it with a new box whose | |
| 23 | -// elements are double the values of the original box. | |
| 21 | +// If there is a box of name box_name, replace it with a new box whose elements are double the | |
| 22 | +// values of the original box. | |
| 24 | 23 | static void |
| 25 | 24 | doubleBoxSize(QPDFPageObjectHelper& page, char const* box_name) |
| 26 | 25 | { |
| 27 | - // We need to use getAttribute rather than getKey as some boxes could | |
| 28 | - // be inherited. | |
| 26 | + // We need to use getAttribute rather than getKey as some boxes could be inherited. | |
| 29 | 27 | auto box = page.getAttribute(box_name, true); |
| 30 | 28 | if (box.isNull()) { |
| 31 | 29 | return; | ... | ... |
examples/pdf-filter-tokens.cc
| 1 | 1 | // |
| 2 | -// This example illustrates the use of QPDFObjectHandle::TokenFilter | |
| 3 | -// with addContentTokenFilter. Please see comments inline for details. | |
| 4 | -// See also pdf-count-strings.cc for a use of | |
| 2 | +// This example illustrates the use of QPDFObjectHandle::TokenFilter with addContentTokenFilter. | |
| 3 | +// Please see comments inline for details. See also pdf-count-strings.cc for a use of | |
| 5 | 4 | // QPDFObjectHandle::TokenFilter with filterContents. |
| 6 | 5 | // |
| 7 | 6 | |
| ... | ... | @@ -26,9 +25,8 @@ usage() |
| 26 | 25 | exit(2); |
| 27 | 26 | } |
| 28 | 27 | |
| 29 | -// The StringReverser class is a trivial example of using a token | |
| 30 | -// filter. This class only overrides the pure virtual handleToken | |
| 31 | -// function and preserves the default handleEOF function. | |
| 28 | +// The StringReverser class is a trivial example of using a token filter. This class only overrides | |
| 29 | +// the pure virtual handleToken function and preserves the default handleEOF function. | |
| 32 | 30 | class StringReverser: public QPDFObjectHandle::TokenFilter |
| 33 | 31 | { |
| 34 | 32 | public: |
| ... | ... | @@ -39,15 +37,12 @@ class StringReverser: public QPDFObjectHandle::TokenFilter |
| 39 | 37 | void |
| 40 | 38 | StringReverser::handleToken(QPDFTokenizer::Token const& token) |
| 41 | 39 | { |
| 42 | - // For string tokens, reverse the characters. For other tokens, | |
| 43 | - // just pass them through. Notice that we construct a new string | |
| 44 | - // token and write that, thus allowing the library to handle any | |
| 45 | - // subtleties about properly encoding unprintable characters. This | |
| 46 | - // function doesn't handle multibyte characters at all. It's not | |
| 47 | - // intended to be an example of the correct way to reverse | |
| 48 | - // strings. It's just intended to give a simple example of a | |
| 49 | - // pretty minimal filter and to show an example of writing a | |
| 50 | - // constructed token. | |
| 40 | + // For string tokens, reverse the characters. For other tokens, just pass them through. Notice | |
| 41 | + // that we construct a new string token and write that, thus allowing the library to handle any | |
| 42 | + // subtleties about properly encoding unprintable characters. This function doesn't handle | |
| 43 | + // multibyte characters at all. It's not intended to be an example of the correct way to reverse | |
| 44 | + // strings. It's just intended to give a simple example of a pretty minimal filter and to show | |
| 45 | + // an example of writing a constructed token. | |
| 51 | 46 | if (token.getType() == QPDFTokenizer::tt_string) { |
| 52 | 47 | std::string value = token.getValue(); |
| 53 | 48 | std::reverse(value.begin(), value.end()); |
| ... | ... | @@ -57,9 +52,8 @@ StringReverser::handleToken(QPDFTokenizer::Token const& token) |
| 57 | 52 | } |
| 58 | 53 | } |
| 59 | 54 | |
| 60 | -// The ColorToGray filter finds all "rg" operators in the content | |
| 61 | -// stream and replaces them with "g" operators, thus mapping color to | |
| 62 | -// grayscale. Note that it only applies to content streams, not | |
| 55 | +// The ColorToGray filter finds all "rg" operators in the content stream and replaces them with "g" | |
| 56 | +// operators, thus mapping color to grayscale. Note that it only applies to content streams, not | |
| 63 | 57 | // images, so this will not replace color images with grayscale |
| 64 | 58 | // images. |
| 65 | 59 | class ColorToGray: public QPDFObjectHandle::TokenFilter |
| ... | ... | @@ -99,29 +93,23 @@ ColorToGray::numericValue(QPDFTokenizer::Token const& token) |
| 99 | 93 | void |
| 100 | 94 | ColorToGray::handleToken(QPDFTokenizer::Token const& token) |
| 101 | 95 | { |
| 102 | - // Track the number of non-ignorable tokens we've seen. If we see | |
| 103 | - // an "rg" following three numbers, convert it to a grayscale | |
| 104 | - // value. Keep writing tokens to the output as we can. | |
| 105 | - | |
| 106 | - // There are several things to notice here. We keep two stacks: | |
| 107 | - // one of "meaningful" tokens, and one of all tokens. This way we | |
| 108 | - // can preserve whitespace or comments that we encounter in the | |
| 109 | - // stream and there preserve layout. As we receive tokens, we keep | |
| 110 | - // the last four meaningful tokens. If we see three numbers | |
| 111 | - // followed by rg, we use the three numbers to calculate a gray | |
| 112 | - // value that is perceptually similar to the color value and then | |
| 113 | - // write the "g" operator to the output, discarding any spaces or | |
| 114 | - // comments encountered embedded in the "rg" operator. | |
| 115 | - | |
| 116 | - // The stack and all_stack members are updated in such a way that | |
| 117 | - // they always contain exactly the same non-ignorable tokens. The | |
| 118 | - // stack member contains the tokens that would be left if you | |
| 96 | + // Track the number of non-ignorable tokens we've seen. If we see an "rg" following three | |
| 97 | + // numbers, convert it to a grayscale value. Keep writing tokens to the output as we can. | |
| 98 | + | |
| 99 | + // There are several things to notice here. We keep two stacks: one of "meaningful" tokens, and | |
| 100 | + // one of all tokens. This way we can preserve whitespace or comments that we encounter in the | |
| 101 | + // stream and there preserve layout. As we receive tokens, we keep the last four meaningful | |
| 102 | + // tokens. If we see three numbers followed by rg, we use the three numbers to calculate a gray | |
| 103 | + // value that is perceptually similar to the color value and then write the "g" operator to the | |
| 104 | + // output, discarding any spaces or comments encountered embedded in the "rg" operator. | |
| 105 | + | |
| 106 | + // The stack and all_stack members are updated in such a way that they always contain exactly | |
| 107 | + // the same non-ignorable tokens. The stack member contains the tokens that would be left if you | |
| 119 | 108 | // removed all space and comment tokens from all_stack. |
| 120 | 109 | |
| 121 | - // On each new token, flush out any space or comment tokens. Store | |
| 122 | - // the incoming token. If we just got an rg preceded by the right | |
| 123 | - // kinds of operands, replace the command. Flush any additional | |
| 124 | - // accumulated tokens to keep the stack only four tokens deep. | |
| 110 | + // On each new token, flush out any space or comment tokens. Store the incoming token. If we | |
| 111 | + // just got an rg preceded by the right kinds of operands, replace the command. Flush any | |
| 112 | + // additional accumulated tokens to keep the stack only four tokens deep. | |
| 125 | 113 | |
| 126 | 114 | while ((!this->all_stack.empty()) && isIgnorable(this->all_stack.at(0).getType())) { |
| 127 | 115 | writeToken(this->all_stack.at(0)); |
| ... | ... | @@ -182,11 +170,9 @@ main(int argc, char* argv[]) |
| 182 | 170 | QPDF pdf; |
| 183 | 171 | pdf.processFile(infilename); |
| 184 | 172 | for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 185 | - // Attach two token filters to each page of this file. | |
| 186 | - // When the file is written, or when the pages' contents | |
| 187 | - // are retrieved in any other way, the filters will be | |
| 188 | - // applied. See comments on the filters for additional | |
| 189 | - // details. | |
| 173 | + // Attach two token filters to each page of this file. When the file is written, or when | |
| 174 | + // the pages' contents are retrieved in any other way, the filters will be applied. See | |
| 175 | + // comments on the filters for additional details. | |
| 190 | 176 | page.addContentTokenFilter( |
| 191 | 177 | std::shared_ptr<QPDFObjectHandle::TokenFilter>(new StringReverser)); |
| 192 | 178 | page.addContentTokenFilter( | ... | ... |
examples/pdf-invert-images.cc
| ... | ... | @@ -20,15 +20,12 @@ usage() |
| 20 | 20 | exit(2); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | -// Derive a class from StreamDataProvider to provide updated stream | |
| 24 | -// data. The main purpose of using this object is to avoid having to | |
| 25 | -// allocate memory up front for the objects. We want to replace the | |
| 26 | -// stream data with a function of the original stream data. In order | |
| 27 | -// to do this without actually holding all the images in memory, we | |
| 28 | -// create copies of the streams. Copying the streams doesn't actually | |
| 29 | -// copy the data. Internally, the qpdf library is holding onto the | |
| 30 | -// location of the original stream data, which makes it possible for | |
| 31 | -// the StreamDataProvider to access it when it needs it. | |
| 23 | +// Derive a class from StreamDataProvider to provide updated stream data. The main purpose of using | |
| 24 | +// this object is to avoid having to allocate memory up front for the objects. We want to replace | |
| 25 | +// the stream data with a function of the original stream data. In order to do this without actually | |
| 26 | +// holding all the images in memory, we create copies of the streams. Copying the streams doesn't | |
| 27 | +// actually copy the data. Internally, the qpdf library is holding onto the location of the original | |
| 28 | +// stream data, which makes it possible for the StreamDataProvider to access it when it needs it. | |
| 32 | 29 | class ImageInverter: public QPDFObjectHandle::StreamDataProvider |
| 33 | 30 | { |
| 34 | 31 | public: |
| ... | ... | @@ -46,42 +43,35 @@ void |
| 46 | 43 | ImageInverter::registerImage( |
| 47 | 44 | QPDFObjectHandle image, std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self) |
| 48 | 45 | { |
| 49 | - // replaceStreamData requires a pointer holder to the stream data | |
| 50 | - // provider, but there's no way for us to generate one ourselves, | |
| 51 | - // so we have to have it handed to us. Don't be tempted to have | |
| 52 | - // the class contain a std::shared_ptr to itself as a member. Doing | |
| 53 | - // this will prevent the class from ever being deleted since the | |
| 54 | - // reference count will never drop to zero (and std::shared_ptr | |
| 55 | - // doesn't have weak references). | |
| 46 | + // replaceStreamData requires a pointer holder to the stream data provider, but there's no way | |
| 47 | + // for us to generate one ourselves, so we have to have it handed to us. Don't be tempted to | |
| 48 | + // have the class contain a std::shared_ptr to itself as a member. Doing this will prevent the | |
| 49 | + // class from ever being deleted since the reference count will never drop to zero (and | |
| 50 | + // std::shared_ptr doesn't have weak references). | |
| 56 | 51 | |
| 57 | 52 | QPDFObjGen og(image.getObjGen()); |
| 58 | - // Store information about the images based on the object and | |
| 59 | - // generation number. Recall that a single image object may be | |
| 60 | - // used more than once, so no need to update the same stream | |
| 61 | - // multiple times. | |
| 53 | + // Store information about the images based on the object and generation number. Recall that a | |
| 54 | + // single image object may be used more than once, so no need to update the same stream multiple | |
| 55 | + // times. | |
| 62 | 56 | if (this->copied_images.count(og) > 0) { |
| 63 | 57 | return; |
| 64 | 58 | } |
| 65 | 59 | this->copied_images[og] = image.copyStream(); |
| 66 | 60 | |
| 67 | - // Register our stream data provider for this stream. Future calls | |
| 68 | - // to getStreamData or pipeStreamData will use the new | |
| 69 | - // information. Provide null for both filter and decode | |
| 70 | - // parameters. Note that this does not mean the image data will be | |
| 71 | - // uncompressed when we write the file. By default, QPDFWriter | |
| 72 | - // will use /FlateDecode for anything that is uncompressed or | |
| 73 | - // filterable in the input QPDF object, so we don't have to deal | |
| 74 | - // with it explicitly here. We could explicitly use /DCTDecode and | |
| 75 | - // write through a DCT filter if we wanted. | |
| 61 | + // Register our stream data provider for this stream. Future calls to getStreamData or | |
| 62 | + // pipeStreamData will use the new information. Provide null for both filter and decode | |
| 63 | + // parameters. Note that this does not mean the image data will be uncompressed when we write | |
| 64 | + // the file. By default, QPDFWriter will use /FlateDecode for anything that is uncompressed or | |
| 65 | + // filterable in the input QPDF object, so we don't have to deal with it explicitly here. We | |
| 66 | + // could explicitly use /DCTDecode and write through a DCT filter if we wanted. | |
| 76 | 67 | image.replaceStreamData(self, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); |
| 77 | 68 | } |
| 78 | 69 | |
| 79 | 70 | void |
| 80 | 71 | ImageInverter::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) |
| 81 | 72 | { |
| 82 | - // Use the object and generation number supplied to look up the | |
| 83 | - // image data. Then invert the image data and write the inverted | |
| 84 | - // data to the pipeline. | |
| 73 | + // Use the object and generation number supplied to look up the image data. Then invert the | |
| 74 | + // image data and write the inverted data to the pipeline. | |
| 85 | 75 | std::shared_ptr<Buffer> data = this->copied_images[og].getStreamData(qpdf_dl_all); |
| 86 | 76 | size_t size = data->getSize(); |
| 87 | 77 | unsigned char* buf = data->getBuffer(); |
| ... | ... | @@ -130,11 +120,9 @@ main(int argc, char* argv[]) |
| 130 | 120 | QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace"); |
| 131 | 121 | QPDFObjectHandle bits_per_component = image_dict.getKey("/BitsPerComponent"); |
| 132 | 122 | |
| 133 | - // For our example, we can only work with images 8-bit | |
| 134 | - // grayscale images that we can fully decode. Use | |
| 135 | - // pipeStreamData with a null pipeline to determine | |
| 136 | - // whether the image is filterable. Directly inspect | |
| 137 | - // keys to determine the image type. | |
| 123 | + // For our example, we can only work with 8-bit grayscale images that we can fully | |
| 124 | + // decode. Use pipeStreamData with a null pipeline to determine whether the image | |
| 125 | + // is filterable. Directly inspect keys to determine the image type. | |
| 138 | 126 | if (image.pipeStreamData(nullptr, qpdf_ef_compress, qpdf_dl_all) && |
| 139 | 127 | color_space.isNameAndEquals("/DeviceGray") && bits_per_component.isInteger() && |
| 140 | 128 | (bits_per_component.getIntValue() == 8)) { |
| ... | ... | @@ -146,8 +134,7 @@ main(int argc, char* argv[]) |
| 146 | 134 | // Write out a new file |
| 147 | 135 | QPDFWriter w(qpdf, outfilename); |
| 148 | 136 | if (static_id) { |
| 149 | - // For the test suite, uncompress streams and use static | |
| 150 | - // IDs. | |
| 137 | + // For the test suite, uncompress streams and use static IDs. | |
| 151 | 138 | w.setStaticID(true); // for testing only |
| 152 | 139 | } |
| 153 | 140 | w.write(); | ... | ... |
examples/pdf-linearize.c
| ... | ... | @@ -51,8 +51,7 @@ main(int argc, char* argv[]) |
| 51 | 51 | |
| 52 | 52 | if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) && |
| 53 | 53 | ((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0)) { |
| 54 | - /* Use static ID for testing only. For production, a | |
| 55 | - * non-static ID is used. See also | |
| 54 | + /* Use static ID for testing only. For production, a non-static ID is used. See also | |
| 56 | 55 | * qpdf_set_deterministic_ID. */ |
| 57 | 56 | qpdf_set_static_ID(qpdf, QPDF_TRUE); /* for testing only */ |
| 58 | 57 | qpdf_set_linearization(qpdf, QPDF_TRUE); | ... | ... |
examples/pdf-name-number-tree.cc
| ... | ... | @@ -29,24 +29,19 @@ main(int argc, char* argv[]) |
| 29 | 29 | QPDF qpdf; |
| 30 | 30 | qpdf.emptyPDF(); |
| 31 | 31 | |
| 32 | - // This example doesn't do anything particularly useful other than | |
| 33 | - // just illustrate how to use the APIs for name and number trees. | |
| 34 | - // It also demonstrates use of the iterators for dictionaries and | |
| 35 | - // arrays introduced at the same time with qpdf 10.2. | |
| 36 | - | |
| 37 | - // To use this example, compile it and run it. Study the output | |
| 38 | - // and compare it to what you expect. When done, look at the | |
| 39 | - // generated output file in a text editor to inspect the structure | |
| 40 | - // of the trees as left in the file. | |
| 41 | - | |
| 42 | - // We're just going to create some name and number trees, hang | |
| 43 | - // them off the document catalog (root), and write an empty PDF to | |
| 44 | - // a file. The PDF will have no pages and won't be viewable, but | |
| 45 | - // you can look at it in a text editor to see the resulting | |
| 46 | - // structure of the PDF. | |
| 47 | - | |
| 48 | - // Create a dictionary off the root where we will hang our name | |
| 49 | - // and number tree. | |
| 32 | + // This example doesn't do anything particularly useful other than just illustrate how to use | |
| 33 | + // the APIs for name and number trees. It also demonstrates use of the iterators for | |
| 34 | + // dictionaries and arrays introduced at the same time with qpdf 10.2. | |
| 35 | + | |
| 36 | + // To use this example, compile it and run it. Study the output and compare it to what you | |
| 37 | + // expect. When done, look at the generated output file in a text editor to inspect the | |
| 38 | + // structure of the trees as left in the file. | |
| 39 | + | |
| 40 | + // We're just going to create some name and number trees, hang them off the document catalog | |
| 41 | + // (root), and write an empty PDF to a file. The PDF will have no pages and won't be viewable, | |
| 42 | + // but you can look at it in a text editor to see the resulting structure of the PDF. | |
| 43 | + | |
| 44 | + // Create a dictionary off the root where we will hang our name and number trees. | |
| 50 | 45 | auto root = qpdf.getRoot(); |
| 51 | 46 | auto example = QPDFObjectHandle::newDictionary(); |
| 52 | 47 | root.replaceKey("/Example", example); |
| ... | ... | @@ -75,8 +70,8 @@ main(int argc, char* argv[]) |
| 75 | 70 | std::cout << " " << i.first << " -> " << i.second.unparse() << std::endl; |
| 76 | 71 | } |
| 77 | 72 | |
| 78 | - // This is a small tree, so everything will be at the root. We can | |
| 79 | - // look at it using dictionary and array iterators. | |
| 73 | + // This is a small tree, so everything will be at the root. We can look at it using dictionary | |
| 74 | + // and array iterators. | |
| 80 | 75 | std::cout << "Keys in name tree object:" << std::endl; |
| 81 | 76 | QPDFObjectHandle names; |
| 82 | 77 | for (auto const& i: name_tree_oh.ditems()) { |
| ... | ... | @@ -121,15 +116,12 @@ main(int argc, char* argv[]) |
| 121 | 116 | << std::endl; |
| 122 | 117 | std::cout << "Has K?: " << name_tree.hasName("K") << std::endl; |
| 123 | 118 | |
| 124 | - // Illustrate some more advanced usage using number trees. These | |
| 125 | - // calls work for name trees too. | |
| 119 | + // Illustrate some more advanced usage using number trees. These calls work for name trees too. | |
| 126 | 120 | |
| 127 | - // The safe way to populate a tree is to call insert repeatedly as | |
| 128 | - // above, but if you know you are definitely inserting items in | |
| 129 | - // order, it is more efficient to insert them using insertAfter, | |
| 130 | - // which avoids doing a binary search through the tree for each | |
| 131 | - // insertion. Note that if you don't insert items in order using | |
| 132 | - // this method, you will create an invalid tree. | |
| 121 | + // The safe way to populate a tree is to call insert repeatedly as above, but if you know you | |
| 122 | + // are definitely inserting items in order, it is more efficient to insert them using | |
| 123 | + // insertAfter, which avoids doing a binary search through the tree for each insertion. Note | |
| 124 | + // that if you don't insert items in order using this method, you will create an invalid tree. | |
| 133 | 125 | auto number_tree = QPDFNumberTreeObjectHelper::newEmpty(qpdf); |
| 134 | 126 | auto number_tree_oh = number_tree.getObjectHandle(); |
| 135 | 127 | example.replaceKey("/NumberTree", number_tree_oh); |
| ... | ... | @@ -149,9 +141,8 @@ main(int argc, char* argv[]) |
| 149 | 141 | ++n; |
| 150 | 142 | } |
| 151 | 143 | |
| 152 | - // When you remove an item with an iterator, the iterator | |
| 153 | - // advances. This makes it possible to filter while iterating. | |
| 154 | - // Remove all items that are multiples of 5. | |
| 144 | + // When you remove an item with an iterator, the iterator advances. This makes it possible to | |
| 145 | + // filter while iterating. Remove all items that are multiples of 5. | |
| 155 | 146 | iter2 = number_tree.begin(); |
| 156 | 147 | while (iter2 != number_tree.end()) { |
| 157 | 148 | if (iter2->first % 5 == 0) { | ... | ... |
examples/pdf-overlay-page.cc
| ... | ... | @@ -6,10 +6,9 @@ |
| 6 | 6 | #include <cstdlib> |
| 7 | 7 | #include <iostream> |
| 8 | 8 | |
| 9 | -// This program demonstrates use of form XObjects to overlay a page | |
| 10 | -// from one file onto all pages of another file. The qpdf program's | |
| 11 | -// --overlay and --underlay options provide a more general version of | |
| 12 | -// this capability. | |
| 9 | +// This program demonstrates use of form XObjects to overlay a page from one file onto all pages of | |
| 10 | +// another file. The qpdf program's --overlay and --underlay options provide a more general version | |
| 11 | +// of this capability. | |
| 13 | 12 | |
| 14 | 13 | static char const* whoami = nullptr; |
| 15 | 14 | |
| ... | ... | @@ -44,24 +43,21 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile) |
| 44 | 43 | int min_suffix = 1; |
| 45 | 44 | std::string name = resources.getUniqueResourceName("/Fx", min_suffix); |
| 46 | 45 | |
| 47 | - // Generate content to place the form XObject centered within | |
| 48 | - // destination page's trim box. | |
| 46 | + // Generate content to place the form XObject centered within destination page's trim box. | |
| 49 | 47 | QPDFMatrix m; |
| 50 | 48 | std::string content = |
| 51 | 49 | ph.placeFormXObject(stamp_fo, name, ph.getTrimBox().getArrayAsRectangle(), m); |
| 52 | 50 | if (!content.empty()) { |
| 53 | - // Append the content to the page's content. Surround the | |
| 54 | - // original content with q...Q to the new content from the | |
| 55 | - // page's original content. | |
| 51 | + // Append the content to the page's content. Surround the original content with q...Q to | |
| 52 | + // the new content from the page's original content. | |
| 56 | 53 | resources.mergeResources("<< /XObject << >> >>"_qpdf); |
| 57 | 54 | resources.getKey("/XObject").replaceKey(name, stamp_fo); |
| 58 | 55 | ph.addPageContents(inpdf.newStream("q\n"), true); |
| 59 | 56 | ph.addPageContents(inpdf.newStream("\nQ\n" + content), false); |
| 60 | 57 | } |
| 61 | - // Copy the annotations and form fields from the original page | |
| 62 | - // to the new page. For more efficiency when copying multiple | |
| 63 | - // pages, we can create a QPDFAcroFormDocumentHelper and pass | |
| 64 | - // it in. See comments in QPDFPageObjectHelper.hh for details. | |
| 58 | + // Copy the annotations and form fields from the original page to the new page. For more | |
| 59 | + // efficiency when copying multiple pages, we can create a QPDFAcroFormDocumentHelper and | |
| 60 | + // pass it in. See comments in QPDFPageObjectHelper.hh for details. | |
| 65 | 61 | ph.copyAnnotations(stamp_page_1, m); |
| 66 | 62 | } |
| 67 | 63 | ... | ... |
examples/pdf-parse-content.cc
| ... | ... | @@ -13,8 +13,8 @@ void |
| 13 | 13 | usage() |
| 14 | 14 | { |
| 15 | 15 | std::cerr << "Usage: " << whoami << " filename page-number" << std::endl |
| 16 | - << "Prints a dump of the objects in the content streams" | |
| 17 | - << " of the given page." << std::endl | |
| 16 | + << "Prints a dump of the objects in the content streams of the given page." | |
| 17 | + << std::endl | |
| 18 | 18 | << "Pages are numbered from 1." << std::endl; |
| 19 | 19 | exit(2); |
| 20 | 20 | } | ... | ... |
examples/pdf-set-form-values.cc
| ... | ... | @@ -29,42 +29,34 @@ main(int argc, char* argv[]) |
| 29 | 29 | char const* outfilename = argv[2]; |
| 30 | 30 | char const* value = argv[3]; |
| 31 | 31 | |
| 32 | - // This is a contrived example that just goes through a file page | |
| 33 | - // by page and sets the value of any text fields it finds to a | |
| 34 | - // fixed value as given on the command line. The purpose here is | |
| 35 | - // to illustrate use of the helper classes around interactive | |
| 36 | - // forms. | |
| 32 | + // This is a contrived example that just goes through a file page by page and sets the value of | |
| 33 | + // any text fields it finds to a fixed value as given on the command line. The purpose here is | |
| 34 | + // to illustrate use of the helper classes around interactive forms. | |
| 37 | 35 | |
| 38 | 36 | try { |
| 39 | 37 | QPDF qpdf; |
| 40 | 38 | qpdf.processFile(infilename); |
| 41 | 39 | |
| 42 | - // We will iterate through form fields by starting at the page | |
| 43 | - // level and looking at each field for each page. We could | |
| 44 | - // also called QPDFAcroFormDocumentHelper::getFormFields to | |
| 45 | - // iterate at the field level, but doing it as below | |
| 46 | - // illustrates how we can map from annotations to fields. | |
| 40 | + // We will iterate through form fields by starting at the page level and looking at each | |
| 41 | + // field for each page. We could also call QPDFAcroFormDocumentHelper::getFormFields to | |
| 42 | + // iterate at the field level, but doing it as below illustrates how we can map from | |
| 43 | + // annotations to fields. | |
| 47 | 44 | |
| 48 | 45 | QPDFAcroFormDocumentHelper afdh(qpdf); |
| 49 | 46 | for (auto const& page: QPDFPageDocumentHelper(qpdf).getAllPages()) { |
| 50 | - // Get all widget annotations for each page. Widget | |
| 51 | - // annotations are the ones that contain the details of | |
| 52 | - // what's in a form field. | |
| 47 | + // Get all widget annotations for each page. Widget annotations are the ones that | |
| 48 | + // contain the details of what's in a form field. | |
| 53 | 49 | for (auto& annot: afdh.getWidgetAnnotationsForPage(page)) { |
| 54 | - // For each annotation, find its associated field. If | |
| 55 | - // it's a text field, set its value. | |
| 50 | + // For each annotation, find its associated field. If it's a text field, set its | |
| 51 | + // value. | |
| 56 | 52 | QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(annot); |
| 57 | 53 | if (ffh.getFieldType() == "/Tx") { |
| 58 | - // Set the value. Passing false as the second | |
| 59 | - // value prevents qpdf from setting | |
| 60 | - // /NeedAppearances to true (but will not turn it | |
| 61 | - // off if it's already on), so we call | |
| 62 | - // generateAppearance after setting the value. You | |
| 63 | - // may or may not want to do this depending on | |
| 64 | - // whether the appearance streams generated by | |
| 65 | - // qpdf are good enough for your purposes. For | |
| 66 | - // additional details, please see comments in | |
| 67 | - // QPDFFormFieldObjectHelper.hh for this method. | |
| 54 | + // Set the value. Passing false as the second parameter prevents qpdf from | |
| 55 | + // setting /NeedAppearances to true (but will not turn it off if it's already | |
| 56 | + // on), so we call generateAppearance after setting the value. You may or may | |
| 57 | + // not want to do this depending on whether the appearance streams generated by | |
| 58 | + // qpdf are good enough for your purposes. For additional details, please see | |
| 59 | + // comments in QPDFFormFieldObjectHelper.hh for this method. | |
| 68 | 60 | ffh.setV(value, false); |
| 69 | 61 | ffh.generateAppearance(annot); |
| 70 | 62 | } | ... | ... |
examples/pdf-split-pages.cc
| 1 | 1 | // |
| 2 | -// This is a stand-alone example of splitting a PDF into individual | |
| 3 | -// pages. It does essentially the same thing that qpdf --split-pages | |
| 4 | -// does. | |
| 2 | +// This is a stand-alone example of splitting a PDF into individual pages. It does essentially the | |
| 3 | +// same thing that qpdf --split-pages does. | |
| 5 | 4 | // |
| 6 | 5 | |
| 7 | 6 | #include <qpdf/QIntC.hh> |
| ... | ... | @@ -32,8 +31,7 @@ process(char const* whoami, char const* infile, std::string outprefix) |
| 32 | 31 | QPDFPageDocumentHelper(outpdf).addPage(page, false); |
| 33 | 32 | QPDFWriter outpdfw(outpdf, outfile.c_str()); |
| 34 | 33 | if (static_id) { |
| 35 | - // For the test suite, uncompress streams and use static | |
| 36 | - // IDs. | |
| 34 | + // For the test suite, uncompress streams and use static IDs. | |
| 37 | 35 | outpdfw.setStaticID(true); // for testing only |
| 38 | 36 | outpdfw.setStreamDataMode(qpdf_s_uncompress); |
| 39 | 37 | } | ... | ... |
examples/qpdf-job.cc
| ... | ... | @@ -3,8 +3,7 @@ |
| 3 | 3 | |
| 4 | 4 | #include <iostream> |
| 5 | 5 | |
| 6 | -// This program is a simple demonstration of different ways to use the | |
| 7 | -// QPDFJob API. | |
| 6 | +// This program is a simple demonstration of different ways to use the QPDFJob API. | |
| 8 | 7 | |
| 9 | 8 | static char const* whoami = nullptr; |
| 10 | 9 | |
| ... | ... | @@ -28,10 +27,9 @@ main(int argc, char* argv[]) |
| 28 | 27 | usage(); |
| 29 | 28 | } |
| 30 | 29 | |
| 31 | - // The examples below all catch std::exception. Note that | |
| 32 | - // QPDFUsage can be caught separately to report on errors in using | |
| 33 | - // the API itself. For CLI, this is command-line usage. For JSON | |
| 34 | - // or the API, it would be errors from the equivalent invocation. | |
| 30 | + // The examples below all catch std::exception. Note that QPDFUsage can be caught separately to | |
| 31 | + // report on errors in using the API itself. For CLI, this is command-line usage. For JSON or | |
| 32 | + // the API, it would be errors from the equivalent invocation. | |
| 35 | 33 | |
| 36 | 34 | // Note that staticId is used for testing only. |
| 37 | 35 | ... | ... |
examples/qpdfjob-c-save-attachment.c
| ... | ... | @@ -6,10 +6,9 @@ |
| 6 | 6 | #include <stdlib.h> |
| 7 | 7 | #include <string.h> |
| 8 | 8 | |
| 9 | -// This example demonstrates how we can redirect where saved output | |
| 10 | -// goes by calling the default logger's setSave method before running | |
| 11 | -// something with QPDFJob. See qpdfjob-c-save-attachment.c for an | |
| 12 | -// implementation that uses the C API. | |
| 9 | +// This example demonstrates how we can redirect where saved output goes by calling the default | |
| 10 | +// logger's setSave method before running something with QPDFJob. See qpdfjob-c-save-attachment.c | |
| 11 | +// for an implementation that uses the C API. | |
| 13 | 12 | |
| 14 | 13 | static int |
| 15 | 14 | save_to_file(char const* data, size_t len, void* udata) |
| ... | ... | @@ -79,9 +78,8 @@ main(int argc, char* argv[]) |
| 79 | 78 | }; |
| 80 | 79 | outfile = do_fopen(outfilename); |
| 81 | 80 | |
| 82 | - /* Use qpdflogger_set_save with a callback function to redirect | |
| 83 | - * saved data. You can use other qpdf logger functions to capture | |
| 84 | - * informational output, warnings, and errors. | |
| 81 | + /* Use qpdflogger_set_save with a callback function to redirect saved data. You can use other | |
| 82 | + * qpdf logger functions to capture informational output, warnings, and errors. | |
| 85 | 83 | */ |
| 86 | 84 | qpdflogger_set_save(l, qpdf_log_dest_custom, save_to_file, (void*)outfile, 0); |
| 87 | 85 | qpdflogger_cleanup(&l); | ... | ... |
examples/qpdfjob-c.c
| 1 | -/* | |
| 2 | - * This is an example program to linearize a PDF file using the C | |
| 3 | - * QPDFJob API. | |
| 4 | - */ | |
| 1 | +/* This is an example program to linearize a PDF file using the C QPDFJob API. */ | |
| 5 | 2 | |
| 6 | 3 | #include <qpdf/qpdfjob-c.h> |
| 7 | 4 | #include <stdio.h> |
| ... | ... | @@ -48,14 +45,12 @@ main(int argc, char* argv[]) |
| 48 | 45 | new_argv[4] = "--static-id"; /* for testing only */ |
| 49 | 46 | new_argv[5] = NULL; |
| 50 | 47 | |
| 51 | - /* See qpdf-job.cc for a C++ example of using the json interface. | |
| 52 | - * To use that from C just like the argv one, call | |
| 53 | - * qpdfjob_run_from_json instead and pass the json string as a | |
| 54 | - * single char const* argument. | |
| 48 | + /* See qpdf-job.cc for a C++ example of using the json interface. To use that from C just like | |
| 49 | + * the argv one, call qpdfjob_run_from_json instead and pass the json string as a single char | |
| 50 | + * const* argument. | |
| 55 | 51 | * |
| 56 | - * See qpdfjob-c-save-attachment.c for an example of using the | |
| 57 | - * full form of the qpdfjob interface with init and cleanup | |
| 58 | - * functions. | |
| 52 | + * See qpdfjob-c-save-attachment.c for an example of using the full form of the qpdfjob | |
| 53 | + * interface with init and cleanup functions. | |
| 59 | 54 | */ |
| 60 | 55 | r = qpdfjob_run_from_argv(new_argv); |
| 61 | 56 | return r; | ... | ... |
examples/qpdfjob-remove-annotations.cc
| ... | ... | @@ -6,10 +6,9 @@ |
| 6 | 6 | #include <cstdlib> |
| 7 | 7 | #include <iostream> |
| 8 | 8 | |
| 9 | -// This example demonstrates how we can use the QPDFJob createQPDF and writeQPDF | |
| 10 | -// methods to add custom transformations to the output produced by QPDFJob runs. | |
| 11 | -// The example is a full copy of the qpdf program modified to allways remove all | |
| 12 | -// annotations from the final output. | |
| 9 | +// This example demonstrates how we can use the QPDFJob createQPDF and writeQPDF methods to add | |
| 10 | +// custom transformations to the output produced by QPDFJob runs. The example is a full copy of the | |
| 11 | +// qpdf program modified to allways remove all annotations from the final output. | |
| 13 | 12 | |
| 14 | 13 | static char const* whoami = nullptr; |
| 15 | 14 | ... | ... |
examples/qpdfjob-save-attachment.cc
| ... | ... | @@ -3,10 +3,9 @@ |
| 3 | 3 | #include <qpdf/QPDFLogger.hh> |
| 4 | 4 | #include <qpdf/QUtil.hh> |
| 5 | 5 | |
| 6 | -// This example demonstrates how we can redirect where saved output | |
| 7 | -// goes by calling the default logger's setSave method before running | |
| 8 | -// something with QPDFJob. See qpdfjob-c-save-attachment.c for an | |
| 9 | -// implementation that uses the C API. | |
| 6 | +// This example demonstrates how we can redirect where saved output goes by calling the default | |
| 7 | +// logger's setSave method before running something with QPDFJob. See qpdfjob-c-save-attachment.c | |
| 8 | +// for an implementation that uses the C API. | |
| 10 | 9 | |
| 11 | 10 | int |
| 12 | 11 | main(int argc, char* argv[]) | ... | ... |
include/qpdf/BufferInputSource.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDF_BUFFERINPUTSOURCE_HH |
| 23 | 20 | #define QPDF_BUFFERINPUTSOURCE_HH |
| ... | ... | @@ -28,8 +25,8 @@ |
| 28 | 25 | class QPDF_DLL_CLASS BufferInputSource: public InputSource |
| 29 | 26 | { |
| 30 | 27 | public: |
| 31 | - // If own_memory is true, BufferInputSource will delete the buffer | |
| 32 | - // when finished with it. Otherwise, the caller owns the memory. | |
| 28 | + // If own_memory is true, BufferInputSource will delete the buffer when finished with it. | |
| 29 | + // Otherwise, the caller owns the memory. | |
| 33 | 30 | QPDF_DLL |
| 34 | 31 | BufferInputSource(std::string const& description, Buffer* buf, bool own_memory = false); |
| 35 | 32 | QPDF_DLL | ... | ... |
include/qpdf/ClosedFileInputSource.hh
| ... | ... | @@ -2,31 +2,27 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDF_CLOSEDFILEINPUTSOURCE_HH |
| 23 | 20 | #define QPDF_CLOSEDFILEINPUTSOURCE_HH |
| 24 | 21 | |
| 25 | -// This is an input source that reads from files, like | |
| 26 | -// FileInputSource, except that it opens and close the file | |
| 27 | -// surrounding every operation. This decreases efficiency, but it allows | |
| 28 | -// many more of these to exist at once than the maximum number of open | |
| 29 | -// file descriptors. This is used for merging large numbers of files. | |
| 22 | +// This is an input source that reads from files, like FileInputSource, except that it opens and | |
| 23 | +// closes the file surrounding every operation. This decreases efficiency, but it allows many more | |
| 24 | +// of these to exist at once than the maximum number of open file descriptors. This is used for | |
| 25 | +// merging large numbers of files. | |
| 30 | 26 | |
| 31 | 27 | #include <qpdf/InputSource.hh> |
| 32 | 28 | #include <qpdf/PointerHolder.hh> // unused -- remove in qpdf 12 (see #785) |
| ... | ... | @@ -57,10 +53,9 @@ class QPDF_DLL_CLASS ClosedFileInputSource: public InputSource |
| 57 | 53 | QPDF_DLL |
| 58 | 54 | virtual void unreadCh(char ch); |
| 59 | 55 | |
| 60 | - // The file stays open between calls to stayOpen(true) and | |
| 61 | - // stayOpen(false). You can use this to surround multiple | |
| 62 | - // operations on a single ClosedFileInputSource to reduce the | |
| 63 | - // overhead of a separate open/close on each call. | |
| 56 | + // The file stays open between calls to stayOpen(true) and stayOpen(false). You can use this to | |
| 57 | + // surround multiple operations on a single ClosedFileInputSource to reduce the overhead of a | |
| 58 | + // separate open/close on each call. | |
| 64 | 59 | QPDF_DLL |
| 65 | 60 | void stayOpen(bool); |
| 66 | 61 | ... | ... |
include/qpdf/FileInputSource.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDF_FILEINPUTSOURCE_HH |
| 23 | 20 | #define QPDF_FILEINPUTSOURCE_HH | ... | ... |
include/qpdf/InputSource.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDF_INPUTSOURCE_HH |
| 23 | 20 | #define QPDF_INPUTSOURCE_HH |
| ... | ... | @@ -30,9 +27,8 @@ |
| 30 | 27 | #include <memory> |
| 31 | 28 | #include <string> |
| 32 | 29 | |
| 33 | -// Remember to use QPDF_DLL_CLASS on anything derived from InputSource | |
| 34 | -// so it will work with dynamic_cast across the shared object | |
| 35 | -// boundary. | |
| 30 | +// Remember to use QPDF_DLL_CLASS on anything derived from InputSource so it will work with | |
| 31 | +// dynamic_cast across the shared object boundary. | |
| 36 | 32 | class QPDF_DLL_CLASS InputSource |
| 37 | 33 | { |
| 38 | 34 | public: |
| ... | ... | @@ -61,12 +57,10 @@ class QPDF_DLL_CLASS InputSource |
| 61 | 57 | QPDF_DLL |
| 62 | 58 | std::string readLine(size_t max_line_length); |
| 63 | 59 | |
| 64 | - // Find first or last occurrence of a sequence of characters | |
| 65 | - // starting within the range defined by offset and len such that, | |
| 66 | - // when the input source is positioned at the beginning of that | |
| 67 | - // sequence, finder.check() returns true. If len is 0, the search | |
| 68 | - // proceeds until EOF. If a qualifying pattern is found, these | |
| 69 | - // methods return true and leave the input source positioned | |
| 60 | + // Find first or last occurrence of a sequence of characters starting within the range defined | |
| 61 | + // by offset and len such that, when the input source is positioned at the beginning of that | |
| 62 | + // sequence, finder.check() returns true. If len is 0, the search proceeds until EOF. If a | |
| 63 | + // qualifying pattern is found, these methods return true and leave the input source positioned | |
| 70 | 64 | // wherever check() left it at the end of the matching pattern. |
| 71 | 65 | QPDF_DLL |
| 72 | 66 | bool findFirst(char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder); |
| ... | ... | @@ -80,11 +74,9 @@ class QPDF_DLL_CLASS InputSource |
| 80 | 74 | virtual void rewind() = 0; |
| 81 | 75 | virtual size_t read(char* buffer, size_t length) = 0; |
| 82 | 76 | |
| 83 | - // Note: you can only unread the character you just read. The | |
| 84 | - // specific character is ignored by some implementations, and the | |
| 85 | - // implementation doesn't check this. Use of unreadCh is | |
| 86 | - // semantically equivalent to seek(-1, SEEK_CUR) but is much more | |
| 87 | - // efficient. | |
| 77 | + // Note: you can only unread the character you just read. The specific character is ignored by | |
| 78 | + // some implementations, and the implementation doesn't check this. Use of unreadCh is | |
| 79 | + // semantically equivalent to seek(-1, SEEK_CUR) but is much more efficient. | |
| 88 | 80 | virtual void unreadCh(char ch) = 0; |
| 89 | 81 | |
| 90 | 82 | // The following methods are for use by QPDFTokenizer |
| ... | ... | @@ -149,9 +141,8 @@ InputSource::fastTell() |
| 149 | 141 | inline bool |
| 150 | 142 | InputSource::fastRead(char& ch) |
| 151 | 143 | { |
| 152 | - // Before calling fastRead, fastTell must be called to prepare the buffer. | |
| 153 | - // Once reading is complete, fastUnread must be called to set the correct | |
| 154 | - // file position. | |
| 144 | + // Before calling fastRead, fastTell must be called to prepare the buffer. Once reading is | |
| 145 | + // complete, fastUnread must be called to set the correct file position. | |
| 155 | 146 | if (this->buf_idx < this->buf_len) { |
| 156 | 147 | ch = this->buffer[this->buf_idx]; |
| 157 | 148 | ++(this->buf_idx); | ... | ... |
include/qpdf/JSON.hh
| ... | ... | @@ -69,7 +69,7 @@ class JSON |
| 69 | 69 | // to pass that `first` through to all the methods that are called to add top-level items to the |
| 70 | 70 | // container as well as to close the container. This lets the JSON object use it to keep track |
| 71 | 71 | // of when it's writing a first object and when it's not. If incrementally writing multiple |
| 72 | - // levels of depth, a new `first` should used for each new container that is opened. | |
| 72 | + // levels of depth, a new `first` should be used for each new container that is opened. | |
| 73 | 73 | // |
| 74 | 74 | // "depth" -- Indicate the level of depth. This is used for consistent indentation. When writing |
| 75 | 75 | // incrementally, whenever you call a method to add an item to a container, the value of `depth` |
| ... | ... | @@ -208,7 +208,7 @@ class JSON |
| 208 | 208 | QPDF_DLL |
| 209 | 209 | bool checkSchema(JSON schema, std::list<std::string>& errors); |
| 210 | 210 | |
| 211 | - // An pointer to a Reactor class can be passed to parse, which will enable the caller to react | |
| 211 | + // A pointer to a Reactor class can be passed to parse, which will enable the caller to react | |
| 212 | 212 | // to incremental events in the construction of the JSON object. This makes it possible to |
| 213 | 213 | // implement SAX-like handling of very large JSON objects. |
| 214 | 214 | class QPDF_DLL_CLASS Reactor | ... | ... |
include/qpdf/PDFVersion.hh
| ... | ... | @@ -2,26 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 21 | - | |
| 22 | -// This class implements a simple writer for saving QPDF objects to | |
| 23 | -// new PDF files. See comments through the header file for additional | |
| 24 | -// details. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 25 | 18 | |
| 26 | 19 | #ifndef PDFVERSION_HH |
| 27 | 20 | #define PDFVERSION_HH |
| ... | ... | @@ -32,10 +25,9 @@ |
| 32 | 25 | class PDFVersion |
| 33 | 26 | { |
| 34 | 27 | public: |
| 35 | - // Represent a PDF version. PDF versions are typically | |
| 36 | - // major.minor, but PDF 1.7 has several extension levels as the | |
| 37 | - // ISO 32000 spec was in progress. This class helps with | |
| 38 | - // comparison of versions. | |
| 28 | + // Represent a PDF version. PDF versions are typically major.minor, but PDF 1.7 has several | |
| 29 | + // extension levels as the ISO 32000 spec was in progress. This class helps with comparison of | |
| 30 | + // versions. | |
| 39 | 31 | QPDF_DLL |
| 40 | 32 | PDFVersion(); |
| 41 | 33 | QPDF_DLL |
| ... | ... | @@ -49,13 +41,12 @@ class PDFVersion |
| 49 | 41 | QPDF_DLL |
| 50 | 42 | bool operator==(PDFVersion const& rhs) const; |
| 51 | 43 | |
| 52 | - // Replace this version with the other one if the other one is | |
| 53 | - // greater. | |
| 44 | + // Replace this version with the other one if the other one is greater. | |
| 54 | 45 | QPDF_DLL |
| 55 | 46 | void updateIfGreater(PDFVersion const& other); |
| 56 | 47 | |
| 57 | - // Initialize a string and integer suitable for passing to | |
| 58 | - // QPDFWriter::setMinimumPDFVersion or QPDFWriter::forcePDFVersion. | |
| 48 | + // Initialize a string and integer suitable for passing to QPDFWriter::setMinimumPDFVersion or | |
| 49 | + // QPDFWriter::forcePDFVersion. | |
| 59 | 50 | QPDF_DLL |
| 60 | 51 | void getVersion(std::string& version, int& extension_level) const; |
| 61 | 52 | ... | ... |
include/qpdf/Pipeline.hh
| ... | ... | @@ -26,8 +26,7 @@ |
| 26 | 26 | // |
| 27 | 27 | // The client is required to call finish() before destroying a Pipeline in order to avoid loss of |
| 28 | 28 | // data. A Pipeline class should not throw an exception in the destructor if this hasn't been done |
| 29 | -// though since doing so causes too much trouble when deleting | |
| 30 | -// pipelines during error conditions. | |
| 29 | +// though since doing so causes too much trouble when deleting pipelines during error conditions. | |
| 31 | 30 | // |
| 32 | 31 | // Some pipelines are reusable (i.e., you can call write() after calling finish() and can call |
| 33 | 32 | // finish() multiple times) while others are not. It is up to the caller to use a pipeline | ... | ... |
include/qpdf/Pl_Buffer.hh
| ... | ... | @@ -47,8 +47,8 @@ class QPDF_DLL_CLASS Pl_Buffer: public Pipeline |
| 47 | 47 | void finish() override; |
| 48 | 48 | |
| 49 | 49 | // Each call to getBuffer() resets this object -- see notes above. |
| 50 | - // The caller is responsible for deleting the returned Buffer | |
| 51 | - // object. See also getBufferSharedPointer() and getMallocBuffer(). | |
| 50 | + // The caller is responsible for deleting the returned Buffer object. See also | |
| 51 | + // getBufferSharedPointer() and getMallocBuffer(). | |
| 52 | 52 | QPDF_DLL |
| 53 | 53 | Buffer* getBuffer(); |
| 54 | 54 | ... | ... |
include/qpdf/Pl_Concatenate.hh
| ... | ... | @@ -2,31 +2,27 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef PL_CONCATENATE_HH |
| 23 | 20 | #define PL_CONCATENATE_HH |
| 24 | 21 | |
| 25 | -// This pipeline will drop all regular finished calls rather than | |
| 26 | -// passing them onto next. To finish downstream streams, call | |
| 27 | -// manualFinish. This makes it possible to pipe multiple streams | |
| 28 | -// (e.g. with QPDFObjectHandle::pipeStreamData) to a downstream like | |
| 29 | -// Pl_Flate that can't handle multiple calls to finish(). | |
| 22 | +// This pipeline will drop all regular finish calls rather than passing them onto next. To finish | |
| 23 | +// downstream streams, call manualFinish. This makes it possible to pipe multiple streams (e.g. | |
| 24 | +// with QPDFObjectHandle::pipeStreamData) to a downstream like Pl_Flate that can't handle multiple | |
| 25 | +// calls to finish(). | |
| 30 | 26 | |
| 31 | 27 | #include <qpdf/Pipeline.hh> |
| 32 | 28 | |
| ... | ... | @@ -44,8 +40,7 @@ class QPDF_DLL_CLASS Pl_Concatenate: public Pipeline |
| 44 | 40 | QPDF_DLL |
| 45 | 41 | virtual void finish(); |
| 46 | 42 | |
| 47 | - // At the very end, call manualFinish to actually finish the rest of | |
| 48 | - // the pipeline. | |
| 43 | + // At the very end, call manualFinish to actually finish the rest of the pipeline. | |
| 49 | 44 | QPDF_DLL |
| 50 | 45 | void manualFinish(); |
| 51 | 46 | ... | ... |
include/qpdf/Pl_Count.hh
| ... | ... | @@ -2,28 +2,24 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef PL_COUNT_HH |
| 23 | 20 | #define PL_COUNT_HH |
| 24 | 21 | |
| 25 | -// This pipeline is reusable; i.e., it is safe to call write() after | |
| 26 | -// calling finish(). | |
| 22 | +// This pipeline is reusable; i.e., it is safe to call write() after calling finish(). | |
| 27 | 23 | |
| 28 | 24 | #include <qpdf/Pipeline.hh> |
| 29 | 25 | #include <qpdf/Types.h> |
| ... | ... | @@ -42,8 +38,8 @@ class QPDF_DLL_CLASS Pl_Count: public Pipeline |
| 42 | 38 | // Returns the number of bytes written |
| 43 | 39 | QPDF_DLL |
| 44 | 40 | qpdf_offset_t getCount() const; |
| 45 | - // Returns the last character written, or '\0' if no characters | |
| 46 | - // have been written (in which case getCount() returns 0) | |
| 41 | + // Returns the last character written, or '\0' if no characters have been written (in which case | |
| 42 | + // getCount() returns 0) | |
| 47 | 43 | QPDF_DLL |
| 48 | 44 | unsigned char getLastChar() const; |
| 49 | 45 | |
| ... | ... | @@ -60,8 +56,7 @@ class QPDF_DLL_CLASS Pl_Count: public Pipeline |
| 60 | 56 | Members(); |
| 61 | 57 | Members(Members const&) = delete; |
| 62 | 58 | |
| 63 | - // Must be qpdf_offset_t, not size_t, to handle writing more than | |
| 64 | - // size_t can handle. | |
| 59 | + // Must be qpdf_offset_t, not size_t, to handle writing more than size_t can handle. | |
| 65 | 60 | qpdf_offset_t count; |
| 66 | 61 | unsigned char last_char; |
| 67 | 62 | }; | ... | ... |
include/qpdf/Pl_DCT.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef PL_DCT_HH |
| 23 | 20 | #define PL_DCT_HH |
| ... | ... | @@ -27,8 +24,7 @@ |
| 27 | 24 | #include <qpdf/Pl_Buffer.hh> |
| 28 | 25 | #include <cstddef> |
| 29 | 26 | |
| 30 | -// jpeglib.h must be included after cstddef or else it messes up the | |
| 31 | -// definition of size_t. | |
| 27 | +// jpeglib.h must be included after cstddef or else it messes up the definition of size_t. | |
| 32 | 28 | #include <jpeglib.h> |
| 33 | 29 | |
| 34 | 30 | class QPDF_DLL_CLASS Pl_DCT: public Pipeline | ... | ... |
include/qpdf/Pl_Discard.hh
| ... | ... | @@ -2,31 +2,26 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef PL_DISCARD_HH |
| 23 | 20 | #define PL_DISCARD_HH |
| 24 | 21 | |
| 25 | -// This pipeline discards its output. It is an end-of-line pipeline | |
| 26 | -// (with no next). | |
| 22 | +// This pipeline discards its output. It is an end-of-line pipeline (with no next). | |
| 27 | 23 | |
| 28 | -// This pipeline is reusable; i.e., it is safe to call write() after | |
| 29 | -// calling finish(). | |
| 24 | +// This pipeline is reusable; i.e., it is safe to call write() after calling finish(). | |
| 30 | 25 | |
| 31 | 26 | #include <qpdf/Pipeline.hh> |
| 32 | 27 | ... | ... |
include/qpdf/Pl_Function.hh
| ... | ... | @@ -2,38 +2,33 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef PL_FUNCTION_HH |
| 23 | 20 | #define PL_FUNCTION_HH |
| 24 | 21 | |
| 25 | -// This pipeline calls an arbitrary function with whatever data is | |
| 26 | -// passed to it. This pipeline can be reused. | |
| 22 | +// This pipeline calls an arbitrary function with whatever data is passed to it. This pipeline can | |
| 23 | +// be reused. | |
| 27 | 24 | // |
| 28 | -// For this pipeline, "next" may be null. If a next pointer is | |
| 29 | -// provided, this pipeline will also pass the data through to it and | |
| 30 | -// will forward finish() to it. | |
| 25 | +// For this pipeline, "next" may be null. If a next pointer is provided, this pipeline will also | |
| 26 | +// pass the data through to it and will forward finish() to it. | |
| 31 | 27 | // |
| 32 | -// It is okay to not call finish() on this pipeline if it has no | |
| 33 | -// "next". | |
| 28 | +// It is okay to not call finish() on this pipeline if it has no "next". | |
| 34 | 29 | // |
| 35 | -// It is okay to keep calling write() after a previous write throws an | |
| 36 | -// exception as long as the delegated function allows it. | |
| 30 | +// It is okay to keep calling write() after a previous write throws an exception as long as the | |
| 31 | +// delegated function allows it. | |
| 37 | 32 | |
| 38 | 33 | #include <qpdf/Pipeline.hh> |
| 39 | 34 | |
| ... | ... | @@ -48,10 +43,9 @@ class QPDF_DLL_CLASS Pl_Function: public Pipeline |
| 48 | 43 | QPDF_DLL |
| 49 | 44 | Pl_Function(char const* identifier, Pipeline* next, writer_t fn); |
| 50 | 45 | |
| 51 | - // The supplied C-style function is called every time write is | |
| 52 | - // called. The udata option is passed into the function with each | |
| 53 | - // call. If the function returns a non-zero value, a runtime error | |
| 54 | - // is thrown. | |
| 46 | + // The supplied C-style function is called every time write is called. The udata option is | |
| 47 | + // passed into the function with each call. If the function returns a non-zero value, a runtime | |
| 48 | + // error is thrown. | |
| 55 | 49 | typedef int (*writer_c_t)(unsigned char const*, size_t, void*); |
| 56 | 50 | QPDF_DLL |
| 57 | 51 | Pl_Function(char const* identifier, Pipeline* next, writer_c_t fn, void* udata); | ... | ... |
include/qpdf/Pl_OStream.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | // End-of-line pipeline that simply writes its data to a stdio FILE* object. |
| 23 | 20 | |
| ... | ... | @@ -35,8 +32,7 @@ |
| 35 | 32 | class QPDF_DLL_CLASS Pl_OStream: public Pipeline |
| 36 | 33 | { |
| 37 | 34 | public: |
| 38 | - // os is externally maintained; this class just writes to and | |
| 39 | - // flushes it. It does not close it. | |
| 35 | + // os is externally maintained; this class just writes to and flushes it. It does not close it. | |
| 40 | 36 | QPDF_DLL |
| 41 | 37 | Pl_OStream(char const* identifier, std::ostream& os); |
| 42 | 38 | QPDF_DLL | ... | ... |
include/qpdf/Pl_QPDFTokenizer.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef PL_QPDFTOKENIZER_HH |
| 23 | 20 | #define PL_QPDFTOKENIZER_HH |
| ... | ... | @@ -31,22 +28,19 @@ |
| 31 | 28 | |
| 32 | 29 | #include <memory> |
| 33 | 30 | |
| 34 | -// Tokenize the incoming text using QPDFTokenizer and pass the tokens | |
| 35 | -// in turn to a QPDFObjectHandle::TokenFilter object. All bytes of | |
| 36 | -// incoming content will be included in exactly one token and passed | |
| 37 | -// downstream. | |
| 31 | +// Tokenize the incoming text using QPDFTokenizer and pass the tokens in turn to a | |
| 32 | +// QPDFObjectHandle::TokenFilter object. All bytes of incoming content will be included in exactly | |
| 33 | +// one token and passed downstream. | |
| 38 | 34 | |
| 39 | -// This is a very low-level interface for working with token filters. | |
| 40 | -// Most code will want to use QPDFObjectHandle::filterPageContents or | |
| 41 | -// QPDFObjectHandle::addTokenFilter. See QPDFObjectHandle.hh for | |
| 42 | -// details. | |
| 35 | +// This is a very low-level interface for working with token filters. Most code will want to use | |
| 36 | +// QPDFObjectHandle::filterPageContents or QPDFObjectHandle::addTokenFilter. See QPDFObjectHandle.hh | |
| 37 | +// for details. | |
| 43 | 38 | |
| 44 | 39 | class QPDF_DLL_CLASS Pl_QPDFTokenizer: public Pipeline |
| 45 | 40 | { |
| 46 | 41 | public: |
| 47 | - // Whatever pipeline is provided as "next" will be set as the | |
| 48 | - // pipeline that the token filter writes to. If next is not | |
| 49 | - // provided, any output written by the filter will be discarded. | |
| 42 | + // Whatever pipeline is provided as "next" will be set as the pipeline that the token filter | |
| 43 | + // writes to. If next is not provided, any output written by the filter will be discarded. | |
| 50 | 44 | QPDF_DLL |
| 51 | 45 | Pl_QPDFTokenizer( |
| 52 | 46 | char const* identifier, QPDFObjectHandle::TokenFilter* filter, Pipeline* next = nullptr); | ... | ... |
include/qpdf/Pl_RunLength.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef PL_RUNLENGTH_HH |
| 23 | 20 | #define PL_RUNLENGTH_HH | ... | ... |
include/qpdf/Pl_StdioFile.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | // End-of-line pipeline that simply writes its data to a stdio FILE* object. |
| 23 | 20 | |
| ... | ... | @@ -35,8 +32,7 @@ |
| 35 | 32 | class QPDF_DLL_CLASS Pl_StdioFile: public Pipeline |
| 36 | 33 | { |
| 37 | 34 | public: |
| 38 | - // f is externally maintained; this class just writes to and | |
| 39 | - // flushes it. It does not close it. | |
| 35 | + // f is externally maintained; this class just writes to and flushes it. It does not close it. | |
| 40 | 36 | QPDF_DLL |
| 41 | 37 | Pl_StdioFile(char const* identifier, FILE* f); |
| 42 | 38 | QPDF_DLL | ... | ... |
include/qpdf/Pl_String.hh
| ... | ... | @@ -2,39 +2,34 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef PL_STRING_HH |
| 23 | 20 | #define PL_STRING_HH |
| 24 | 21 | |
| 25 | -// This pipeline accumulates the data passed to it into a std::string, | |
| 26 | -// a reference to which is passed in at construction. Each subsequent | |
| 27 | -// use of this pipeline appends to the data accumulated so far. | |
| 22 | +// This pipeline accumulates the data passed to it into a std::string, a reference to which is | |
| 23 | +// passed in at construction. Each subsequent use of this pipeline appends to the data accumulated | |
| 24 | +// so far. | |
| 28 | 25 | // |
| 29 | -// For this pipeline, "next" may be null. If a next pointer is | |
| 30 | -// provided, this pipeline will also pass the data through to it and | |
| 31 | -// will forward finish() to it. | |
| 26 | +// For this pipeline, "next" may be null. If a next pointer is provided, this pipeline will also | |
| 27 | +// pass the data through to it and will forward finish() to it. | |
| 32 | 28 | // |
| 33 | -// It is okay to not call finish() on this pipeline if it has no | |
| 34 | -// "next". This makes it easy to stick this in front of another | |
| 35 | -// pipeline to capture data that is written to the other pipeline | |
| 36 | -// without interfering with when finish is called on the other | |
| 37 | -// pipeline and without having to put a Pl_Concatenate after it. | |
| 29 | +// It is okay to not call finish() on this pipeline if it has no "next". This makes it easy to stick | |
| 30 | +// this in front of another pipeline to capture data that is written to the other pipeline without | |
| 31 | +// interfering with when finish is called on the other pipeline and without having to put a | |
| 32 | +// Pl_Concatenate after it. | |
| 38 | 33 | |
| 39 | 34 | #include <qpdf/Pipeline.hh> |
| 40 | 35 | ... | ... |
include/qpdf/QPDF.hh
| ... | ... | @@ -68,7 +68,7 @@ class QPDF |
| 68 | 68 | // read until they are needed. A QPDF object may be associated with only one file in its |
| 69 | 69 | // lifetime. This method must be called before any methods that potentially ask for information |
| 70 | 70 | // about the PDF file are called. Prior to calling this, the only methods that are allowed are |
| 71 | - // those that set parameters. If the input file is not encrypted,either a null password or an | |
| 71 | + // those that set parameters. If the input file is not encrypted, either a null password or an | |
| 72 | 72 | // empty password can be used. If the file is encrypted, either the user password or the owner |
| 73 | 73 | // password may be supplied. The method setPasswordIsHexKey may be called prior to calling this |
| 74 | 74 | // method or any of the other process methods to force the password to be interpreted as a raw | ... | ... |
include/qpdf/QPDFAnnotationObjectHelper.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFANNOTATIONOBJECTHELPER_HH |
| 23 | 20 | #define QPDFANNOTATIONOBJECTHELPER_HH |
| ... | ... | @@ -35,19 +32,16 @@ class QPDFAnnotationObjectHelper: public QPDFObjectHelper |
| 35 | 32 | QPDF_DLL |
| 36 | 33 | virtual ~QPDFAnnotationObjectHelper() = default; |
| 37 | 34 | |
| 38 | - // This class provides helper methods for annotations. More | |
| 39 | - // functionality will likely be added in the future. | |
| 35 | + // This class provides helper methods for annotations. More functionality will likely be added | |
| 36 | + // in the future. | |
| 40 | 37 | |
| 41 | - // Some functionality for annotations is also implemented in | |
| 42 | - // QPDFAcroFormDocumentHelper and QPDFFormFieldObjectHelper. In | |
| 43 | - // some cases, functions defined there work for other annotations | |
| 44 | - // besides widget annotations, but they are implemented with form | |
| 45 | - // fields so that they can properly handle form fields when | |
| 46 | - // needed. | |
| 38 | + // Some functionality for annotations is also implemented in QPDFAcroFormDocumentHelper and | |
| 39 | + // QPDFFormFieldObjectHelper. In some cases, functions defined there work for other annotations | |
| 40 | + // besides widget annotations, but they are implemented with form fields so that they can | |
| 41 | + // properly handle form fields when needed. | |
| 47 | 42 | |
| 48 | - // Return the subtype of the annotation as a string (e.g. | |
| 49 | - // "/Widget"). Returns the empty string if the subtype (which is | |
| 50 | - // required by the spec) is missing. | |
| 43 | + // Return the subtype of the annotation as a string (e.g. "/Widget"). Returns an empty string | |
| 44 | + // if the subtype (which is required by the spec) is missing. | |
| 51 | 45 | QPDF_DLL |
| 52 | 46 | std::string getSubtype(); |
| 53 | 47 | |
| ... | ... | @@ -57,39 +51,32 @@ class QPDFAnnotationObjectHelper: public QPDFObjectHelper |
| 57 | 51 | QPDF_DLL |
| 58 | 52 | QPDFObjectHandle getAppearanceDictionary(); |
| 59 | 53 | |
| 60 | - // Return the appearance state as given in "/AS", or the empty | |
| 61 | - // string if none is given. | |
| 54 | + // Return the appearance state as given in "/AS", or an empty string if none is given. | |
| 62 | 55 | QPDF_DLL |
| 63 | 56 | std::string getAppearanceState(); |
| 64 | 57 | |
| 65 | - // Return flags from "/F". The value is a logical or of | |
| 66 | - // pdf_annotation_flag_e as defined in qpdf/Constants.h. | |
| 58 | + // Return flags from "/F". The value is a logical or of pdf_annotation_flag_e as defined in | |
| 59 | + // qpdf/Constants.h. | |
| 67 | 60 | QPDF_DLL |
| 68 | 61 | int getFlags(); |
| 69 | 62 | |
| 70 | - // Return a specific stream. "which" may be one of "/N", "/R", or | |
| 71 | - // "/D" to indicate the normal, rollover, or down appearance | |
| 72 | - // stream. (Any value may be passed to "which"; if an appearance | |
| 73 | - // stream of that name exists, it will be returned.) If the value | |
| 74 | - // associated with "which" in the appearance dictionary is a | |
| 75 | - // subdictionary, an appearance state may be specified to select | |
| 76 | - // which appearance stream is desired. If not specified, the | |
| 77 | - // appearance state in "/AS" will used. | |
| 63 | + // Return a specific stream. "which" may be one of "/N", "/R", or "/D" to indicate the normal, | |
| 64 | + // rollover, or down appearance stream. (Any value may be passed to "which"; if an appearance | |
| 65 | + // stream of that name exists, it will be returned.) If the value associated with "which" in the | |
| 66 | + // appearance dictionary is a subdictionary, an appearance state may be specified to select | |
| 67 | + // which appearance stream is desired. If not specified, the appearance state in "/AS" will | |
| 68 | + // used. | |
| 78 | 69 | QPDF_DLL |
| 79 | 70 | QPDFObjectHandle getAppearanceStream(std::string const& which, std::string const& state = ""); |
| 80 | 71 | |
| 81 | - // Generate text suitable for addition to the containing page's | |
| 82 | - // content stream that draws this annotation's appearance stream | |
| 83 | - // as a form XObject. The value "name" is the resource name that | |
| 84 | - // will be used to refer to the form xobject. The value "rotate" | |
| 85 | - // should be set to the page's /Rotate value or 0 if none. The | |
| 86 | - // values of required_flags and forbidden_flags are constructed by | |
| 87 | - // logically "or"ing annotation flags of type | |
| 88 | - // pdf_annotation_flag_e defined in qpdf/Constants.h. Content will | |
| 89 | - // be returned only if all required_flags are set and no | |
| 90 | - // forbidden_flags are set. For example, including an_no_view in | |
| 91 | - // forbidden_flags could be useful for creating an on-screen view, | |
| 92 | - // and including an_print to required_flags could be useful if | |
| 72 | + // Generate text suitable for addition to the containing page's content stream that draws this | |
| 73 | + // annotation's appearance stream as a form XObject. The value "name" is the resource name that | |
| 74 | + // will be used to refer to the form xobject. The value "rotate" should be set to the page's | |
| 75 | + // /Rotate value or 0 if none. The values of required_flags and forbidden_flags are constructed | |
| 76 | + // by logically "or"ing annotation flags of type pdf_annotation_flag_e defined in | |
| 77 | + // qpdf/Constants.h. Content will be returned only if all required_flags are set and no | |
| 78 | + // forbidden_flags are set. For example, including an_no_view in forbidden_flags could be useful | |
| 79 | + // for creating an on-screen view, and including an_print to required_flags could be useful if | |
| 93 | 80 | // preparing to print. |
| 94 | 81 | QPDF_DLL |
| 95 | 82 | std::string getPageContentForAppearance( | ... | ... |
include/qpdf/QPDFCryptoProvider.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFCRYPTOPROVIDER_HH |
| 23 | 20 | #define QPDFCRYPTOPROVIDER_HH |
| ... | ... | @@ -30,35 +27,30 @@ |
| 30 | 27 | #include <set> |
| 31 | 28 | #include <string> |
| 32 | 29 | |
| 33 | -// This class is part of qpdf's pluggable crypto provider support. | |
| 34 | -// Most users won't need to know or care about this class, but you can | |
| 35 | -// use it if you want to supply your own crypto implementation. See | |
| 36 | -// also comments in QPDFCryptoImpl.hh. | |
| 30 | +// This class is part of qpdf's pluggable crypto provider support. Most users won't need to know or | |
| 31 | +// care about this class, but you can use it if you want to supply your own crypto implementation. | |
| 32 | +// See also comments in QPDFCryptoImpl.hh. | |
| 37 | 33 | |
| 38 | 34 | class QPDFCryptoProvider |
| 39 | 35 | { |
| 40 | 36 | public: |
| 41 | - // Methods for getting and registering crypto implementations. | |
| 42 | - // These methods are not thread-safe. | |
| 37 | + // Methods for getting and registering crypto implementations. These methods are not | |
| 38 | + // thread-safe. | |
| 43 | 39 | |
| 44 | - // Return an instance of a crypto provider using the default | |
| 45 | - // implementation. | |
| 40 | + // Return an instance of a crypto provider using the default implementation. | |
| 46 | 41 | QPDF_DLL |
| 47 | 42 | static std::shared_ptr<QPDFCryptoImpl> getImpl(); |
| 48 | 43 | |
| 49 | - // Return an instance of the crypto provider registered using the | |
| 50 | - // given name. | |
| 44 | + // Return an instance of the crypto provider registered using the given name. | |
| 51 | 45 | QPDF_DLL |
| 52 | 46 | static std::shared_ptr<QPDFCryptoImpl> getImpl(std::string const& name); |
| 53 | 47 | |
| 54 | - // Register the given type (T) as a crypto implementation. T must | |
| 55 | - // be derived from QPDFCryptoImpl and must have a constructor that | |
| 56 | - // takes no arguments. | |
| 48 | + // Register the given type (T) as a crypto implementation. T must be derived from QPDFCryptoImpl | |
| 49 | + // and must have a constructor that takes no arguments. | |
| 57 | 50 | template <typename T> |
| 58 | 51 | QPDF_DLL static void registerImpl(std::string const& name); |
| 59 | 52 | |
| 60 | - // Set the crypto provider registered with the given name as the | |
| 61 | - // default crypto implementation. | |
| 53 | + // Set the crypto provider registered with the given name as the default crypto implementation. | |
| 62 | 54 | QPDF_DLL |
| 63 | 55 | static void setDefaultProvider(std::string const& name); |
| 64 | 56 | ... | ... |
include/qpdf/QPDFDocumentHelper.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFDOCUMENTHELPER_HH |
| 23 | 20 | #define QPDFDOCUMENTHELPER_HH |
| ... | ... | @@ -25,16 +22,13 @@ |
| 25 | 22 | #include <qpdf/DLL.h> |
| 26 | 23 | #include <qpdf/QPDF.hh> |
| 27 | 24 | |
| 28 | -// This is a base class for QPDF Document Helper classes. Document | |
| 29 | -// helpers are classes that provide a convenient, higher-level API for | |
| 30 | -// accessing document-level structures with a PDF file. Document | |
| 31 | -// helpers are always initialized with a reference to a QPDF object, | |
| 32 | -// and the object can always be retrieved. The intention is that you | |
| 33 | -// may freely intermix use of document helpers with the underlying | |
| 34 | -// QPDF object unless there is a specific comment in a specific helper | |
| 35 | -// method that says otherwise. The pattern of using helper objects was | |
| 36 | -// introduced to allow creation of higher level helper functions | |
| 37 | -// without polluting the public interface of QPDF. | |
| 25 | +// This is a base class for QPDF Document Helper classes. Document helpers are classes that provide | |
| 26 | +// a convenient, higher-level API for accessing document-level structures within a PDF file. | |
| 27 | +// Document helpers are always initialized with a reference to a QPDF object, and the object can | |
| 28 | +// always be retrieved. The intention is that you may freely intermix use of document helpers with | |
| 29 | +// the underlying QPDF object unless there is a specific comment in a specific helper method that | |
| 30 | +// says otherwise. The pattern of using helper objects was introduced to allow creation of higher | |
| 31 | +// level helper functions without polluting the public interface of QPDF. | |
| 38 | 32 | |
| 39 | 33 | class QPDF_DLL_CLASS QPDFDocumentHelper |
| 40 | 34 | { | ... | ... |
include/qpdf/QPDFEFStreamObjectHelper.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFEFSTREAMOBJECTHELPER_HH |
| 23 | 20 | #define QPDFEFSTREAMOBJECTHELPER_HH |
| ... | ... | @@ -29,9 +26,8 @@ |
| 29 | 26 | #include <qpdf/QPDFObjectHandle.hh> |
| 30 | 27 | #include <functional> |
| 31 | 28 | |
| 32 | -// This class provides a higher level interface around Embedded File | |
| 33 | -// Streams, which are discussed in section 7.11.4 of the ISO-32000 PDF | |
| 34 | -// specification. | |
| 29 | +// This class provides a higher level interface around Embedded File Streams, which are discussed in | |
| 30 | +// section 7.11.4 of the ISO-32000 PDF specification. | |
| 35 | 31 | |
| 36 | 32 | class QPDFEFStreamObjectHelper: public QPDFObjectHelper |
| 37 | 33 | { |
| ... | ... | @@ -41,11 +37,10 @@ class QPDFEFStreamObjectHelper: public QPDFObjectHelper |
| 41 | 37 | QPDF_DLL |
| 42 | 38 | virtual ~QPDFEFStreamObjectHelper() = default; |
| 43 | 39 | |
| 44 | - // Date parameters are strings that conform to the PDF spec for | |
| 45 | - // date/time strings, which is "D:yyyymmddhhmmss<z>" where <z> is | |
| 46 | - // either "Z" for UTC or "-hh'mm'" or "+hh'mm'" for timezone | |
| 47 | - // offset. Examples: "D:20210207161528-05'00'", | |
| 48 | - // "D:20210207211528Z". See QUtil::qpdf_time_to_pdf_time. | |
| 40 | + // Date parameters are strings that conform to the PDF spec for date/time strings, which is | |
| 41 | + // "D:yyyymmddhhmmss<z>" where <z> is either "Z" for UTC or "-hh'mm'" or "+hh'mm'" for timezone | |
| 42 | + // offset. Examples: "D:20210207161528-05'00'", "D:20210207211528Z". See | |
| 43 | + // QUtil::qpdf_time_to_pdf_time. | |
| 49 | 44 | |
| 50 | 45 | QPDF_DLL |
| 51 | 46 | std::string getCreationDate(); |
| ... | ... | @@ -57,32 +52,27 @@ class QPDFEFStreamObjectHelper: public QPDFObjectHelper |
| 57 | 52 | // Subtype is a mime type such as "text/plain" |
| 58 | 53 | QPDF_DLL |
| 59 | 54 | std::string getSubtype(); |
| 60 | - // Return the checksum as stored in the object as a binary string. | |
| 61 | - // This does not check consistency with the data. If not present, | |
| 62 | - // return an empty string. The PDF spec specifies this as an MD5 | |
| 63 | - // checksum and notes that it is not to be used for security | |
| 64 | - // purposes since MD5 is known not to be secure. | |
| 55 | + // Return the checksum as stored in the object as a binary string. This does not check | |
| 56 | + // consistency with the data. If not present, return an empty string. The PDF spec specifies | |
| 57 | + // this as an MD5 checksum and notes that it is not to be used for security purposes since MD5 | |
| 58 | + // is known to be insecure. | |
| 65 | 59 | QPDF_DLL |
| 66 | 60 | std::string getChecksum(); |
| 67 | 61 | |
| 68 | - // Setters return a reference to this object so that they can be | |
| 69 | - // used as fluent interfaces, e.g. | |
| 62 | + // Setters return a reference to this object so that they can be used as fluent interfaces, e.g. | |
| 70 | 63 | // efsoh.setCreationDate(x).setModDate(y); |
| 71 | 64 | |
| 72 | - // Create a new embedded file stream with the given stream data, | |
| 73 | - // which can be provided in any of several ways. To get the new | |
| 74 | - // object back, call getObjectHandle() on the returned object. The | |
| 75 | - // checksum and size are computed automatically and stored. Other | |
| 76 | - // parameters may be supplied using setters defined below. | |
| 65 | + // Create a new embedded file stream with the given stream data, which can be provided in any of | |
| 66 | + // several ways. To get the new object back, call getObjectHandle() on the returned object. The | |
| 67 | + // checksum and size are computed automatically and stored. Other parameters may be supplied | |
| 68 | + // using setters defined below. | |
| 77 | 69 | QPDF_DLL |
| 78 | 70 | static QPDFEFStreamObjectHelper createEFStream(QPDF& qpdf, std::shared_ptr<Buffer> data); |
| 79 | 71 | QPDF_DLL |
| 80 | 72 | static QPDFEFStreamObjectHelper createEFStream(QPDF& qpdf, std::string const& data); |
| 81 | - // The provider function must write the data to the given | |
| 82 | - // pipeline. The function may be called multiple times by the qpdf | |
| 83 | - // library. You can pass QUtil::file_provider(filename) as the | |
| 84 | - // provider to have the qpdf library provide the contents of | |
| 85 | - // filename as a binary. | |
| 73 | + // The provider function must write the data to the given pipeline. The function may be called | |
| 74 | + // multiple times by the qpdf library. You can pass QUtil::file_provider(filename) as the | |
| 75 | + // provider to have the qpdf library provide the contents of filename as a binary. | |
| 86 | 76 | QPDF_DLL |
| 87 | 77 | static QPDFEFStreamObjectHelper |
| 88 | 78 | createEFStream(QPDF& qpdf, std::function<void(Pipeline*)> provider); |
| ... | ... | @@ -93,8 +83,7 @@ class QPDFEFStreamObjectHelper: public QPDFObjectHelper |
| 93 | 83 | QPDF_DLL |
| 94 | 84 | QPDFEFStreamObjectHelper& setModDate(std::string const&); |
| 95 | 85 | |
| 96 | - // Set subtype as a mime-type, e.g. "text/plain" or | |
| 97 | - // "application/pdf". | |
| 86 | + // Set subtype as a mime-type, e.g. "text/plain" or "application/pdf". | |
| 98 | 87 | QPDF_DLL |
| 99 | 88 | QPDFEFStreamObjectHelper& setSubtype(std::string const&); |
| 100 | 89 | ... | ... |
include/qpdf/QPDFEmbeddedFileDocumentHelper.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFEMBEDDEDFILEDOCUMENTHELPER_HH |
| 23 | 20 | #define QPDFEMBEDDEDFILEDOCUMENTHELPER_HH |
| ... | ... | @@ -32,9 +29,9 @@ |
| 32 | 29 | #include <map> |
| 33 | 30 | #include <memory> |
| 34 | 31 | |
| 35 | -// This class provides a higher level interface around document-level | |
| 36 | -// file attachments, also known as embedded files. These are discussed | |
| 37 | -// in sections 7.7.4 and 7.11 of the ISO-32000 PDF specification. | |
| 32 | +// This class provides a higher level interface around document-level file attachments, also known | |
| 33 | +// as embedded files. These are discussed in sections 7.7.4 and 7.11 of the ISO-32000 PDF | |
| 34 | +// specification. | |
| 38 | 35 | |
| 39 | 36 | class QPDFEmbeddedFileDocumentHelper: public QPDFDocumentHelper |
| 40 | 37 | { |
| ... | ... | @@ -50,8 +47,8 @@ class QPDFEmbeddedFileDocumentHelper: public QPDFDocumentHelper |
| 50 | 47 | QPDF_DLL |
| 51 | 48 | std::map<std::string, std::shared_ptr<QPDFFileSpecObjectHelper>> getEmbeddedFiles(); |
| 52 | 49 | |
| 53 | - // If an embedded file with the given name exists, return a | |
| 54 | - // (shared) pointer to it. Otherwise, return nullptr. | |
| 50 | + // If an embedded file with the given name exists, return a (shared) pointer to it. Otherwise, | |
| 51 | + // return nullptr. | |
| 55 | 52 | QPDF_DLL |
| 56 | 53 | std::shared_ptr<QPDFFileSpecObjectHelper> getEmbeddedFile(std::string const& name); |
| 57 | 54 | |
| ... | ... | @@ -59,14 +56,11 @@ class QPDFEmbeddedFileDocumentHelper: public QPDFDocumentHelper |
| 59 | 56 | QPDF_DLL |
| 60 | 57 | void replaceEmbeddedFile(std::string const& name, QPDFFileSpecObjectHelper const&); |
| 61 | 58 | |
| 62 | - // Remove an embedded file if present. Return value is true if the | |
| 63 | - // file was present and was removed. This method not only removes | |
| 64 | - // the embedded file from the embedded files name tree but also | |
| 65 | - // nulls out the file specification dictionary. This means that | |
| 66 | - // any references to this file from file attachment annotations | |
| 67 | - // will also stop working. This is the best way to make the | |
| 68 | - // attachment actually disappear from the file and not just from | |
| 69 | - // the list of attachments. | |
| 59 | + // Remove an embedded file if present. Return value is true if the file was present and was | |
| 60 | + // removed. This method not only removes the embedded file from the embedded files name tree but | |
| 61 | + // also nulls out the file specification dictionary. This means that any references to this file | |
| 62 | + // from file attachment annotations will also stop working. This is the best way to make the | |
| 63 | + // attachment actually disappear from the file and not just from the list of attachments. | |
| 70 | 64 | QPDF_DLL |
| 71 | 65 | bool removeEmbeddedFile(std::string const& name); |
| 72 | 66 | ... | ... |
include/qpdf/QPDFFileSpecObjectHelper.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFFILESPECOBJECTHELPER_HH |
| 23 | 20 | #define QPDFFILESPECOBJECTHELPER_HH |
| ... | ... | @@ -29,9 +26,8 @@ |
| 29 | 26 | #include <qpdf/QPDFEFStreamObjectHelper.hh> |
| 30 | 27 | #include <qpdf/QPDFObjectHandle.hh> |
| 31 | 28 | |
| 32 | -// This class provides a higher level interface around File | |
| 33 | -// Specification dictionaries, which are discussed in section 7.11 of | |
| 34 | -// the ISO-32000 PDF specification. | |
| 29 | +// This class provides a higher level interface around File Specification dictionaries, which are | |
| 30 | +// discussed in section 7.11 of the ISO-32000 PDF specification. | |
| 35 | 31 | |
| 36 | 32 | class QPDFFileSpecObjectHelper: public QPDFObjectHelper |
| 37 | 33 | { |
| ... | ... | @@ -44,45 +40,38 @@ class QPDFFileSpecObjectHelper: public QPDFObjectHelper |
| 44 | 40 | QPDF_DLL |
| 45 | 41 | std::string getDescription(); |
| 46 | 42 | |
| 47 | - // Get the main filename for this file specification. In priority | |
| 48 | - // order, check /UF, /F, /Unix, /DOS, /Mac. | |
| 43 | + // Get the main filename for this file specification. In priority order, check /UF, /F, /Unix, | |
| 44 | + // /DOS, /Mac. | |
| 49 | 45 | QPDF_DLL |
| 50 | 46 | std::string getFilename(); |
| 51 | 47 | |
| 52 | - // Return any of /UF, /F, /Unix, /DOS, /Mac filename keys that may | |
| 53 | - // be present in the object. | |
| 48 | + // Return any of /UF, /F, /Unix, /DOS, /Mac filename keys that may be present in the object. | |
| 54 | 49 | QPDF_DLL |
| 55 | 50 | std::map<std::string, std::string> getFilenames(); |
| 56 | 51 | |
| 57 | - // Get the requested embedded file stream for this file | |
| 58 | - // specification. If key is empty, In priority order, check /UF, | |
| 59 | - // /F, /Unix, /DOS, /Mac. Returns a null object if not found. If | |
| 60 | - // this is an actual embedded file stream, its data is the content | |
| 61 | - // of the attachment. You can also use | |
| 62 | - // QPDFEFStreamObjectHelper for higher level access to | |
| 63 | - // the parameters. | |
| 52 | + // Get the requested embedded file stream for this file specification. If key is empty, In | |
| 53 | + // priority order, check /UF, /F, /Unix, /DOS, /Mac. Returns a null object if not found. If this | |
| 54 | + // is an actual embedded file stream, its data is the content of the attachment. You can also | |
| 55 | + // use QPDFEFStreamObjectHelper for higher level access to the parameters. | |
| 64 | 56 | QPDF_DLL |
| 65 | 57 | QPDFObjectHandle getEmbeddedFileStream(std::string const& key = ""); |
| 66 | 58 | |
| 67 | - // Return the /EF key of the file spec, which is a map from file | |
| 68 | - // name key to embedded file stream. | |
| 59 | + // Return the /EF key of the file spec, which is a map from file name key to embedded file | |
| 60 | + // stream. | |
| 69 | 61 | QPDF_DLL |
| 70 | 62 | QPDFObjectHandle getEmbeddedFileStreams(); |
| 71 | 63 | |
| 72 | - // Setters return a reference to this object so that they can be | |
| 73 | - // used as fluent interfaces, e.g. | |
| 64 | + // Setters return a reference to this object so that they can be used as fluent interfaces, e.g. | |
| 74 | 65 | // fsoh.setDescription(x).setFilename(y); |
| 75 | 66 | |
| 76 | - // Create a new filespec as an indirect object with the given | |
| 77 | - // filename, and attach the contents of the specified file as data | |
| 78 | - // in an embedded file stream. | |
| 67 | + // Create a new filespec as an indirect object with the given filename, and attach the contents | |
| 68 | + // of the specified file as data in an embedded file stream. | |
| 79 | 69 | QPDF_DLL |
| 80 | 70 | static QPDFFileSpecObjectHelper |
| 81 | 71 | createFileSpec(QPDF& qpdf, std::string const& filename, std::string const& fullpath); |
| 82 | 72 | |
| 83 | - // Create a new filespec as an indirect object with the given | |
| 84 | - // unicode filename and embedded file stream. The file name will | |
| 85 | - // be used as both /UF and /F. If you need to override, call | |
| 73 | + // Create a new filespec as an indirect object with the given unicode filename and embedded file | |
| 74 | + // stream. The file name will be used as both /UF and /F. If you need to override, call | |
| 86 | 75 | // setFilename. |
| 87 | 76 | QPDF_DLL |
| 88 | 77 | static QPDFFileSpecObjectHelper |
| ... | ... | @@ -90,11 +79,9 @@ class QPDFFileSpecObjectHelper: public QPDFObjectHelper |
| 90 | 79 | |
| 91 | 80 | QPDF_DLL |
| 92 | 81 | QPDFFileSpecObjectHelper& setDescription(std::string const&); |
| 93 | - // setFilename sets /UF to unicode_name. If compat_name is empty, | |
| 94 | - // it is also set to unicode_name. unicode_name should be a UTF-8 | |
| 95 | - // encoded string. compat_name is converted to a string | |
| 96 | - // QPDFObjectHandle literally, preserving whatever encoding it | |
| 97 | - // might happen to have. | |
| 82 | + // setFilename sets /UF to unicode_name. If compat_name is empty, it is also set to | |
| 83 | + // unicode_name. unicode_name should be a UTF-8 encoded string. compat_name is converted to a | |
| 84 | + // string QPDFObjectHandle literally, preserving whatever encoding it might happen to have. | |
| 98 | 85 | QPDF_DLL |
| 99 | 86 | QPDFFileSpecObjectHelper& |
| 100 | 87 | setFilename(std::string const& unicode_name, std::string const& compat_name = ""); | ... | ... |
include/qpdf/QPDFLogger.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFLOGGER_HH |
| 23 | 20 | #define QPDFLOGGER_HH |
| ... | ... | @@ -33,19 +30,15 @@ class QPDFLogger |
| 33 | 30 | QPDF_DLL |
| 34 | 31 | static std::shared_ptr<QPDFLogger> create(); |
| 35 | 32 | |
| 36 | - // Return the default logger. In general, you should use the | |
| 37 | - // default logger. You can also create your own loggers and use | |
| 38 | - // them QPDF and QPDFJob objects, but there are few reasons to do | |
| 39 | - // so. One reason may if you are using multiple QPDF or QPDFJob | |
| 40 | - // objects in different threads and want to capture output and | |
| 41 | - // errors to different streams. (Note that a single QPDF or | |
| 42 | - // QPDFJob can't be safely used from multiple threads, but it is | |
| 43 | - // safe to use separate QPDF and QPDFJob objects on separate | |
| 44 | - // threads.) Another possible reason would be if you are writing | |
| 45 | - // an application that uses the qpdf library directly and qpdf is | |
| 46 | - // also used by a downstream library or if you are using qpdf from | |
| 47 | - // a library and don't want to interfere with potential uses of | |
| 48 | - // qpdf by other libraries or applications. | |
| 33 | + // Return the default logger. In general, you should use the default logger. You can also create | |
| 34 | + // your own loggers and use them with QPDF and QPDFJob objects, but there are few reasons to do | |
| 35 | + // so. One reason may be that you are using multiple QPDF or QPDFJob objects in different | |
| 36 | + // threads and want to capture output and errors to different streams. (Note that a single QPDF | |
| 37 | + // or QPDFJob can't be safely used from multiple threads, but it is safe to use separate QPDF | |
| 38 | + // and QPDFJob objects on separate threads.) Another possible reason would be if you are writing | |
| 39 | + // an application that uses the qpdf library directly and qpdf is also used by a downstream | |
| 40 | + // library or if you are using qpdf from a library and don't want to interfere with potential | |
| 41 | + // uses of qpdf by other libraries or applications. | |
| 49 | 42 | QPDF_DLL |
| 50 | 43 | static std::shared_ptr<QPDFLogger> defaultLogger(); |
| 51 | 44 | |
| ... | ... | @@ -56,50 +49,40 @@ class QPDFLogger |
| 56 | 49 | // error -- standard error |
| 57 | 50 | // save -- undefined unless set |
| 58 | 51 | // |
| 59 | - // "info" is used for diagnostic messages, verbose messages, and | |
| 60 | - // progress messages. "warn" is used for warnings. "error" is used | |
| 61 | - // for errors. "save" is used for saving output -- see below. | |
| 52 | + // "info" is used for diagnostic messages, verbose messages, and progress messages. "warn" is | |
| 53 | + // used for warnings. "error" is used for errors. "save" is used for saving output -- see below. | |
| 62 | 54 | // |
| 63 | - // On deletion, finish() is called for the standard output and | |
| 64 | - // standard error pipelines, which flushes output. If you supply | |
| 65 | - // any custom pipelines, you must call finish() on them yourself. | |
| 66 | - // Note that calling finish is not needed for string, stdio, or | |
| 67 | - // ostream pipelines. | |
| 55 | + // On deletion, finish() is called for the standard output and standard error pipelines, which | |
| 56 | + // flushes output. If you supply any custom pipelines, you must call finish() on them yourself. | |
| 57 | + // Note that calling finish is not needed for string, stdio, or ostream pipelines. | |
| 68 | 58 | // |
| 69 | 59 | // NOTES ABOUT THE SAVE PIPELINE |
| 70 | 60 | // |
| 71 | - // The save pipeline is used by QPDFJob when some kind of binary | |
| 72 | - // output is being saved. This includes saving attachments and | |
| 73 | - // stream data and also includes when the output file is standard | |
| 74 | - // output. If you want to grab that output, you can call setSave. | |
| 75 | - // See examples/qpdfjob-save-attachment.cc and | |
| 76 | - // examples/qpdfjob-c-save-attachment.c. | |
| 61 | + // The save pipeline is used by QPDFJob when some kind of binary output is being saved. This | |
| 62 | + // includes saving attachments and stream data and also includes when the output file is | |
| 63 | + // standard output. If you want to grab that output, you can call setSave. See | |
| 64 | + // examples/qpdfjob-save-attachment.cc and examples/qpdfjob-c-save-attachment.c. | |
| 77 | 65 | // |
| 78 | - // You should never set the save pipeline to the same destination | |
| 79 | - // as something else. Doing so will corrupt your save output. If | |
| 80 | - // you want to save to standard output, use the method | |
| 81 | - // saveToStandardOutput(). In addition to setting the save | |
| 82 | - // pipeline, that does the following extra things: | |
| 66 | + // You should never set the save pipeline to the same destination as something else. Doing so | |
| 67 | + // will corrupt your save output. If you want to save to standard output, use the method | |
| 68 | + // saveToStandardOutput(). In addition to setting the save pipeline, that does the following | |
| 69 | + // extra things: | |
| 83 | 70 | // |
| 84 | 71 | // * If standard output has been used, a logic error is thrown |
| 85 | - // * If info is set to standard output at the time of the set save | |
| 86 | - // call, it is switched to standard error. | |
| 72 | + // * If info is set to standard output at the time of the set save call, it is switched to | |
| 73 | + // standard error. | |
| 87 | 74 | // |
| 88 | - // This is not a guarantee. You can still mess this up in ways | |
| 89 | - // that are not checked. Here are a few examples: | |
| 75 | + // This is not a guarantee. You can still mess this up in ways that are not checked. Here are a | |
| 76 | + // few examples: | |
| 90 | 77 | // |
| 91 | - // * Don't set any pipeline to standard output *after* passing it | |
| 92 | - // to setSave() | |
| 93 | - // * Don't use a separate mechanism to write stdout/stderr other | |
| 94 | - // than QPDFLogger::standardOutput() | |
| 95 | - // * Don't set anything to the same custom pipeline that save is | |
| 96 | - // set to. | |
| 78 | + // * Don't set any pipeline to standard output *after* passing it to setSave() | |
| 79 | + // * Don't use a separate mechanism to write stdout/stderr other than | |
| 80 | + // QPDFLogger::standardOutput() | |
| 81 | + // * Don't set anything to the same custom pipeline that save is set to. | |
| 97 | 82 | // |
| 98 | - // Just be sure that if you change pipelines around, you should | |
| 99 | - // avoid having the save pipeline also be used for any other | |
| 100 | - // purpose. The special case for saving to standard output allows | |
| 101 | - // you to call saveToStandardOutput() early without having to | |
| 102 | - // worry about the info pipeline. | |
| 83 | + // Just be sure that if you change pipelines around, you should avoid having the save pipeline | |
| 84 | + // also be used for any other purpose. The special case for saving to standard output allows you | |
| 85 | + // to call saveToStandardOutput() early without having to worry about the info pipeline. | |
| 103 | 86 | |
| 104 | 87 | QPDF_DLL |
| 105 | 88 | void info(char const*); |
| ... | ... | @@ -145,9 +128,8 @@ class QPDFLogger |
| 145 | 128 | QPDF_DLL |
| 146 | 129 | void saveToStandardOutput(bool only_if_not_set); |
| 147 | 130 | |
| 148 | - // Shortcut for logic to reset output to new output/error streams. | |
| 149 | - // out_stream is used for info, err_stream is used for error, and | |
| 150 | - // warning is cleared so that it follows error. | |
| 131 | + // Shortcut for logic to reset output to new output/error streams. out_stream is used for info, | |
| 132 | + // err_stream is used for error, and warning is cleared so that it follows error. | |
| 151 | 133 | QPDF_DLL |
| 152 | 134 | void setOutputStreams(std::ostream* out_stream, std::ostream* err_stream); |
| 153 | 135 | ... | ... |
include/qpdf/QPDFMatrix.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFMATRIX_HH |
| 23 | 20 | #define QPDFMATRIX_HH |
| ... | ... | @@ -26,8 +23,7 @@ |
| 26 | 23 | #include <qpdf/QPDFObjectHandle.hh> |
| 27 | 24 | #include <string> |
| 28 | 25 | |
| 29 | -// This class represents a PDF transformation matrix using a tuple | |
| 30 | -// such that | |
| 26 | +// This class represents a PDF transformation matrix using a tuple such that | |
| 31 | 27 | // |
| 32 | 28 | // โ โ |
| 33 | 29 | // โ a b 0 โ |
| ... | ... | @@ -45,8 +41,7 @@ class QPDFMatrix |
| 45 | 41 | QPDF_DLL |
| 46 | 42 | QPDFMatrix(QPDFObjectHandle::Matrix const&); |
| 47 | 43 | |
| 48 | - // Returns the six values separated by spaces as real numbers with | |
| 49 | - // trimmed zeroes. | |
| 44 | + // Returns the six values separated by spaces as real numbers with trimmed zeroes. | |
| 50 | 45 | QPDF_DLL |
| 51 | 46 | std::string unparse() const; |
| 52 | 47 | |
| ... | ... | @@ -75,14 +70,12 @@ class QPDFMatrix |
| 75 | 70 | QPDF_DLL |
| 76 | 71 | void transform(double x, double y, double& xp, double& yp) const; |
| 77 | 72 | |
| 78 | - // Transform a rectangle by creating a new rectangle that tightly | |
| 79 | - // bounds the polygon resulting from transforming the four | |
| 80 | - // corners. | |
| 73 | + // Transform a rectangle by creating a new rectangle that tightly bounds the polygon resulting | |
| 74 | + // from transforming the four corners. | |
| 81 | 75 | QPDF_DLL |
| 82 | 76 | QPDFObjectHandle::Rectangle transformRectangle(QPDFObjectHandle::Rectangle r) const; |
| 83 | 77 | |
| 84 | - // operator== tests for exact equality, not considering deltas for | |
| 85 | - // floating point. | |
| 78 | + // operator== tests for exact equality, not considering deltas for floating point. | |
| 86 | 79 | QPDF_DLL |
| 87 | 80 | bool operator==(QPDFMatrix const& rhs) const; |
| 88 | 81 | QPDF_DLL | ... | ... |
include/qpdf/QPDFNameTreeObjectHelper.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFNAMETREEOBJECTHELPER_HH |
| 23 | 20 | #define QPDFNAMETREEOBJECTHELPER_HH |
| ... | ... | @@ -30,13 +27,11 @@ |
| 30 | 27 | |
| 31 | 28 | #include <qpdf/DLL.h> |
| 32 | 29 | |
| 33 | -// This is an object helper for name trees. See section 7.9.6 in the | |
| 34 | -// PDF spec (ISO 32000) for a description of name trees. When looking | |
| 35 | -// up items in the name tree, use UTF-8 strings. All names are | |
| 36 | -// normalized for lookup purposes. | |
| 30 | +// This is an object helper for name trees. See section 7.9.6 in the PDF spec (ISO 32000) for a | |
| 31 | +// description of name trees. When looking up items in the name tree, use UTF-8 strings. All names | |
| 32 | +// are normalized for lookup purposes. | |
| 37 | 33 | |
| 38 | -// See examples/pdf-name-number-tree.cc for a demonstration of using | |
| 39 | -// QPDFNameTreeObjectHelper. | |
| 34 | +// See examples/pdf-name-number-tree.cc for a demonstration of using QPDFNameTreeObjectHelper. | |
| 40 | 35 | |
| 41 | 36 | class NNTreeImpl; |
| 42 | 37 | class NNTreeIterator; |
| ... | ... | @@ -45,8 +40,8 @@ class NNTreeDetails; |
| 45 | 40 | class QPDF_DLL_CLASS QPDFNameTreeObjectHelper: public QPDFObjectHelper |
| 46 | 41 | { |
| 47 | 42 | public: |
| 48 | - // The qpdf object is required so that this class can issue | |
| 49 | - // warnings, attempt repairs, and add indirect objects. | |
| 43 | + // The qpdf object is required so that this class can issue warnings, attempt repairs, and add | |
| 44 | + // indirect objects. | |
| 50 | 45 | QPDF_DLL |
| 51 | 46 | QPDFNameTreeObjectHelper(QPDFObjectHandle, QPDF&, bool auto_repair = true); |
| 52 | 47 | |
| ... | ... | @@ -57,13 +52,11 @@ class QPDF_DLL_CLASS QPDFNameTreeObjectHelper: public QPDFObjectHelper |
| 57 | 52 | QPDF_DLL |
| 58 | 53 | virtual ~QPDFNameTreeObjectHelper(); |
| 59 | 54 | |
| 60 | - // Return whether the number tree has an explicit entry for this | |
| 61 | - // number. | |
| 55 | + // Return whether the name tree has an explicit entry for this name. | |
| 62 | 56 | QPDF_DLL |
| 63 | 57 | bool hasName(std::string const& utf8); |
| 64 | 58 | |
| 65 | - // Find an object by name. If found, returns true and initializes | |
| 66 | - // oh. See also find(). | |
| 59 | + // Find an object by name. If found, returns true and initializes oh. See also find(). | |
| 67 | 60 | QPDF_DLL |
| 68 | 61 | bool findObject(std::string const& utf8, QPDFObjectHandle& oh); |
| 69 | 62 | |
| ... | ... | @@ -115,21 +108,17 @@ class QPDF_DLL_CLASS QPDFNameTreeObjectHelper: public QPDFObjectHelper |
| 115 | 108 | return !operator==(other); |
| 116 | 109 | } |
| 117 | 110 | |
| 118 | - // DANGER: this method can create inconsistent trees if not | |
| 119 | - // used properly! Insert a new item immediately after the | |
| 120 | - // current iterator and increment so that it points to the new | |
| 121 | - // item. If the current iterator is end(), insert at the | |
| 122 | - // beginning. This method does not check for proper ordering, | |
| 123 | - // so if you use it, you must ensure that the item you are | |
| 124 | - // inserting belongs where you are putting it. The reason for | |
| 125 | - // this method is that it is more efficient than insert() and | |
| 126 | - // can be used safely when you are creating a new tree and | |
| 127 | - // inserting items in sorted order. | |
| 111 | + // DANGER: this method can create inconsistent trees if not used properly! Insert a new item | |
| 112 | + // immediately after the current iterator and increment so that it points to the new item. | |
| 113 | + // If the current iterator is end(), insert at the beginning. This method does not check for | |
| 114 | + // proper ordering, so if you use it, you must ensure that the item you are inserting | |
| 115 | + // belongs where you are putting it. The reason for this method is that it is more efficient | |
| 116 | + // than insert() and can be used safely when you are creating a new tree and inserting items | |
| 117 | + // in sorted order. | |
| 128 | 118 | QPDF_DLL |
| 129 | 119 | void insertAfter(std::string const& key, QPDFObjectHandle value); |
| 130 | 120 | |
| 131 | - // Remove the current item and advance the iterator to the | |
| 132 | - // next item. | |
| 121 | + // Remove the current item and advance the iterator to the next item. | |
| 133 | 122 | QPDF_DLL |
| 134 | 123 | void remove(); |
| 135 | 124 | |
| ... | ... | @@ -141,10 +130,9 @@ class QPDF_DLL_CLASS QPDFNameTreeObjectHelper: public QPDFObjectHelper |
| 141 | 130 | value_type ivalue; |
| 142 | 131 | }; |
| 143 | 132 | |
| 144 | - // The iterator looks like map iterator, so i.first is a string | |
| 145 | - // and i.second is a QPDFObjectHandle. Incrementing end() brings | |
| 146 | - // you to the first item. Decrementing end() brings you to the | |
| 147 | - // last item. | |
| 133 | + // The iterator looks like map iterator, so i.first is a string and i.second is a | |
| 134 | + // QPDFObjectHandle. Incrementing end() brings you to the first item. Decrementing end() brings | |
| 135 | + // you to the last item. | |
| 148 | 136 | QPDF_DLL |
| 149 | 137 | iterator begin() const; |
| 150 | 138 | QPDF_DLL |
| ... | ... | @@ -153,8 +141,8 @@ class QPDF_DLL_CLASS QPDFNameTreeObjectHelper: public QPDFObjectHelper |
| 153 | 141 | QPDF_DLL |
| 154 | 142 | iterator last() const; |
| 155 | 143 | |
| 156 | - // Find the entry with the given key. If return_prev_if_not_found | |
| 157 | - // is true and the item is not found, return the next lower item. | |
| 144 | + // Find the entry with the given key. If return_prev_if_not_found is true and the item is not | |
| 145 | + // found, return the next lower item. | |
| 158 | 146 | QPDF_DLL |
| 159 | 147 | iterator find(std::string const& key, bool return_prev_if_not_found = false); |
| 160 | 148 | |
| ... | ... | @@ -162,20 +150,18 @@ class QPDF_DLL_CLASS QPDFNameTreeObjectHelper: public QPDFObjectHelper |
| 162 | 150 | QPDF_DLL |
| 163 | 151 | iterator insert(std::string const& key, QPDFObjectHandle value); |
| 164 | 152 | |
| 165 | - // Remove an item. Return true if the item was found and removed; | |
| 166 | - // otherwise return false. If value is not null, initialize it to | |
| 167 | - // the value that was removed. | |
| 153 | + // Remove an item. Return true if the item was found and removed; otherwise return false. If | |
| 154 | + // value is not nullptr, initialize it to the value that was removed. | |
| 168 | 155 | QPDF_DLL |
| 169 | 156 | bool remove(std::string const& key, QPDFObjectHandle* value = nullptr); |
| 170 | 157 | |
| 171 | - // Return the contents of the name tree as a map. Note that name | |
| 172 | - // trees may be very large, so this may use a lot of RAM. It is | |
| 173 | - // more efficient to use QPDFNameTreeObjectHelper's iterator. | |
| 158 | + // Return the contents of the name tree as a map. Note that name trees may be very large, so | |
| 159 | + // this may use a lot of RAM. It is more efficient to use QPDFNameTreeObjectHelper's iterator. | |
| 174 | 160 | QPDF_DLL |
| 175 | 161 | std::map<std::string, QPDFObjectHandle> getAsMap() const; |
| 176 | 162 | |
| 177 | - // Split a node if the number of items exceeds this value. There's | |
| 178 | - // no real reason to ever set this except for testing. | |
| 163 | + // Split a node if the number of items exceeds this value. There's no real reason to ever set | |
| 164 | + // this except for testing. | |
| 179 | 165 | QPDF_DLL |
| 180 | 166 | void setSplitThreshold(int); |
| 181 | 167 | ... | ... |
include/qpdf/QPDFNumberTreeObjectHelper.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFNUMBERTREEOBJECTHELPER_HH |
| 23 | 20 | #define QPDFNUMBERTREEOBJECTHELPER_HH |
| ... | ... | @@ -29,11 +26,10 @@ |
| 29 | 26 | |
| 30 | 27 | #include <qpdf/DLL.h> |
| 31 | 28 | |
| 32 | -// This is an object helper for number trees. See section 7.9.7 in the | |
| 33 | -// PDF spec (ISO 32000) for a description of number trees. | |
| 29 | +// This is an object helper for number trees. See section 7.9.7 in the PDF spec (ISO 32000) for a | |
| 30 | +// description of number trees. | |
| 34 | 31 | |
| 35 | -// See examples/pdf-name-number-tree.cc for a demonstration of using | |
| 36 | -// QPDFNumberTreeObjectHelper. | |
| 32 | +// See examples/pdf-name-number-tree.cc for a demonstration of using QPDFNumberTreeObjectHelper. | |
| 37 | 33 | |
| 38 | 34 | class NNTreeImpl; |
| 39 | 35 | class NNTreeIterator; |
| ... | ... | @@ -42,8 +38,8 @@ class NNTreeDetails; |
| 42 | 38 | class QPDF_DLL_CLASS QPDFNumberTreeObjectHelper: public QPDFObjectHelper |
| 43 | 39 | { |
| 44 | 40 | public: |
| 45 | - // The qpdf object is required so that this class can issue | |
| 46 | - // warnings, attempt repairs, and add indirect objects. | |
| 41 | + // The qpdf object is required so that this class can issue warnings, attempt repairs, and add | |
| 42 | + // indirect objects. | |
| 47 | 43 | QPDF_DLL |
| 48 | 44 | QPDFNumberTreeObjectHelper(QPDFObjectHandle, QPDF&, bool auto_repair = true); |
| 49 | 45 | |
| ... | ... | @@ -62,24 +58,20 @@ class QPDF_DLL_CLASS QPDFNumberTreeObjectHelper: public QPDFObjectHelper |
| 62 | 58 | QPDF_DLL |
| 63 | 59 | numtree_number getMax(); |
| 64 | 60 | |
| 65 | - // Return whether the number tree has an explicit entry for this | |
| 66 | - // number. | |
| 61 | + // Return whether the number tree has an explicit entry for this number. | |
| 67 | 62 | QPDF_DLL |
| 68 | 63 | bool hasIndex(numtree_number idx); |
| 69 | 64 | |
| 70 | - // Find an object with a specific index. If found, returns true | |
| 71 | - // and initializes oh. See also find(). | |
| 65 | + // Find an object with a specific index. If found, returns true and initializes oh. See also | |
| 66 | + // find(). | |
| 72 | 67 | QPDF_DLL |
| 73 | 68 | bool findObject(numtree_number idx, QPDFObjectHandle& oh); |
| 74 | - // Find the object at the index or, if not found, the object whose | |
| 75 | - // index is the highest index less than the requested index. If | |
| 76 | - // the requested index is less than the minimum, return false. | |
| 77 | - // Otherwise, return true, initialize oh to the object, and set | |
| 78 | - // offset to the difference between the requested index and the | |
| 79 | - // actual index. For example, if a number tree has values for 3 | |
| 80 | - // and 6 and idx is 5, this method would return true, initialize | |
| 81 | - // oh to the value with index 3, and set offset to 2 (5 - 3). See | |
| 82 | - // also find(). | |
| 69 | + // Find the object at the index or, if not found, the object whose index is the highest index | |
| 70 | + // less than the requested index. If the requested index is less than the minimum, return false. | |
| 71 | + // Otherwise, return true, initialize oh to the object, and set offset to the difference between | |
| 72 | + // the requested index and the actual index. For example, if a number tree has values for 3 and | |
| 73 | + // 6 and idx is 5, this method would return true, initialize oh to the value with index 3, and | |
| 74 | + // set offset to 2 (5 - 3). See also find(). | |
| 83 | 75 | QPDF_DLL |
| 84 | 76 | bool findObjectAtOrBelow(numtree_number idx, QPDFObjectHandle& oh, numtree_number& offset); |
| 85 | 77 | |
| ... | ... | @@ -131,21 +123,17 @@ class QPDF_DLL_CLASS QPDFNumberTreeObjectHelper: public QPDFObjectHelper |
| 131 | 123 | return !operator==(other); |
| 132 | 124 | } |
| 133 | 125 | |
| 134 | - // DANGER: this method can create inconsistent trees if not | |
| 135 | - // used properly! Insert a new item immediately after the | |
| 136 | - // current iterator and increment so that it points to the new | |
| 137 | - // item. If the current iterator is end(), insert at the | |
| 138 | - // beginning. This method does not check for proper ordering, | |
| 139 | - // so if you use it, you must ensure that the item you are | |
| 140 | - // inserting belongs where you are putting it. The reason for | |
| 141 | - // this method is that it is more efficient than insert() and | |
| 142 | - // can be used safely when you are creating a new tree and | |
| 143 | - // inserting items in sorted order. | |
| 126 | + // DANGER: this method can create inconsistent trees if not used properly! Insert a new item | |
| 127 | + // immediately after the current iterator and increment so that it points to the new item. | |
| 128 | + // If the current iterator is end(), insert at the beginning. This method does not check for | |
| 129 | + // proper ordering, so if you use it, you must ensure that the item you are inserting | |
| 130 | + // belongs where you are putting it. The reason for this method is that it is more efficient | |
| 131 | + // than insert() and can be used safely when you are creating a new tree and inserting items | |
| 132 | + // in sorted order. | |
| 144 | 133 | QPDF_DLL |
| 145 | 134 | void insertAfter(numtree_number key, QPDFObjectHandle value); |
| 146 | 135 | |
| 147 | - // Remove the current item and advance the iterator to the | |
| 148 | - // next item. | |
| 136 | + // Remove the current item and advance the iterator to the next item. | |
| 149 | 137 | QPDF_DLL |
| 150 | 138 | void remove(); |
| 151 | 139 | |
| ... | ... | @@ -157,10 +145,9 @@ class QPDF_DLL_CLASS QPDFNumberTreeObjectHelper: public QPDFObjectHelper |
| 157 | 145 | value_type ivalue; |
| 158 | 146 | }; |
| 159 | 147 | |
| 160 | - // The iterator looks like map iterator, so i.first is a string | |
| 161 | - // and i.second is a QPDFObjectHandle. Incrementing end() brings | |
| 162 | - // you to the first item. Decrementing end() brings you to the | |
| 163 | - // last item. | |
| 148 | + // The iterator looks like map iterator, so i.first is a numtree_number and i.second is a | |
| 149 | + // QPDFObjectHandle. Incrementing end() brings you to the first item. Decrementing end() brings | |
| 150 | + // you to the last item. | |
| 164 | 151 | QPDF_DLL |
| 165 | 152 | iterator begin() const; |
| 166 | 153 | QPDF_DLL |
| ... | ... | @@ -169,8 +156,8 @@ class QPDF_DLL_CLASS QPDFNumberTreeObjectHelper: public QPDFObjectHelper |
| 169 | 156 | QPDF_DLL |
| 170 | 157 | iterator last() const; |
| 171 | 158 | |
| 172 | - // Find the entry with the given key. If return_prev_if_not_found | |
| 173 | - // is true and the item is not found, return the next lower item. | |
| 159 | + // Find the entry with the given key. If return_prev_if_not_found is true and the item is not | |
| 160 | + // found, return the next lower item. | |
| 174 | 161 | QPDF_DLL |
| 175 | 162 | iterator find(numtree_number key, bool return_prev_if_not_found = false); |
| 176 | 163 | |
| ... | ... | @@ -178,22 +165,19 @@ class QPDF_DLL_CLASS QPDFNumberTreeObjectHelper: public QPDFObjectHelper |
| 178 | 165 | QPDF_DLL |
| 179 | 166 | iterator insert(numtree_number key, QPDFObjectHandle value); |
| 180 | 167 | |
| 181 | - // Remove an item. Return true if the item was found and removed; | |
| 182 | - // otherwise return false. If value is not null, initialize it to | |
| 183 | - // the value that was removed. | |
| 168 | + // Remove an item. Return true if the item was found and removed; otherwise return false. If | |
| 169 | + // value is not nullptr, initialize it to the value that was removed. | |
| 184 | 170 | QPDF_DLL |
| 185 | 171 | bool remove(numtree_number key, QPDFObjectHandle* value = nullptr); |
| 186 | 172 | |
| 187 | - // Return the contents of the number tree as a map. Note that | |
| 188 | - // number trees may be very large, so this may use a lot of RAM. | |
| 189 | - // It is more efficient to use QPDFNumberTreeObjectHelper's | |
| 190 | - // iterator. | |
| 173 | + // Return the contents of the number tree as a map. Note that number trees may be very large, so | |
| 174 | + // this may use a lot of RAM. It is more efficient to use QPDFNumberTreeObjectHelper's iterator. | |
| 191 | 175 | typedef std::map<numtree_number, QPDFObjectHandle> idx_map; |
| 192 | 176 | QPDF_DLL |
| 193 | 177 | idx_map getAsMap() const; |
| 194 | 178 | |
| 195 | - // Split a node if the number of items exceeds this value. There's | |
| 196 | - // no real reason to ever set this except for testing. | |
| 179 | + // Split a node if the number of items exceeds this value. There's no real reason to ever set | |
| 180 | + // this except for testing. | |
| 197 | 181 | QPDF_DLL |
| 198 | 182 | void setSplitThreshold(int); |
| 199 | 183 | ... | ... |
include/qpdf/QPDFObjGen.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFOBJGEN_HH |
| 23 | 20 | #define QPDFOBJGEN_HH |
| ... | ... | @@ -29,8 +26,8 @@ |
| 29 | 26 | class QPDFObjectHandle; |
| 30 | 27 | class QPDFObjectHelper; |
| 31 | 28 | |
| 32 | -// This class represents an object ID and generation pair. It is | |
| 33 | -// suitable to use as a key in a map or set. | |
| 29 | +// This class represents an object ID and generation pair. It is suitable to use as a key in a map | |
| 30 | +// or set. | |
| 34 | 31 | |
| 35 | 32 | class QPDFObjGen |
| 36 | 33 | { |
| ... | ... | @@ -91,13 +88,11 @@ class QPDFObjGen |
| 91 | 88 | |
| 92 | 89 | // Convenience class for loop detection when processing objects. |
| 93 | 90 | // |
| 94 | - // The class adds 'add' methods to a std::set<QPDFObjGen> which allows | |
| 95 | - // to test whether an QPDFObjGen is present in the set and to insert it in | |
| 96 | - // a single operation. The 'add' method is overloaded to take a QPDFObjGen, | |
| 97 | - // QPDFObjectHandle or an QPDFObjectHelper as parameter. | |
| 91 | + // The class adds 'add' methods to a std::set<QPDFObjGen> which allows to test whether an | |
| 92 | + // QPDFObjGen is present in the set and to insert it in a single operation. The 'add' method is | |
| 93 | + // overloaded to take a QPDFObjGen, QPDFObjectHandle or an QPDFObjectHelper as parameter. | |
| 98 | 94 | // |
| 99 | - // The erase method is modified to ignore requests to erase | |
| 100 | - // QPDFObjGen(0, 0). | |
| 95 | + // The erase method is modified to ignore requests to erase QPDFObjGen(0, 0). | |
| 101 | 96 | // |
| 102 | 97 | // Usage example: |
| 103 | 98 | // |
| ... | ... | @@ -112,8 +107,8 @@ class QPDFObjGen |
| 112 | 107 | class QPDF_DLL_CLASS set: public std::set<QPDFObjGen> |
| 113 | 108 | { |
| 114 | 109 | public: |
| 115 | - // Add 'og' to the set. Return false if 'og' is already present in | |
| 116 | - // the set. Attempts to insert QPDFObjGen(0, 0) are ignored. | |
| 110 | + // Add 'og' to the set. Return false if 'og' is already present in the set. Attempts to | |
| 111 | + // insert QPDFObjGen(0, 0) are ignored. | |
| 117 | 112 | QPDF_DLL |
| 118 | 113 | bool |
| 119 | 114 | add(QPDFObjGen og) |
| ... | ... | @@ -150,9 +145,8 @@ class QPDFObjGen |
| 150 | 145 | }; |
| 151 | 146 | |
| 152 | 147 | private: |
| 153 | - // This class does not use the Members pattern to avoid a memory | |
| 154 | - // allocation for every one of these. A lot of these get created | |
| 155 | - // and destroyed. | |
| 148 | + // This class does not use the Members pattern to avoid a memory allocation for every one of | |
| 149 | + // these. A lot of these get created and destroyed. | |
| 156 | 150 | int obj{0}; |
| 157 | 151 | int gen{0}; |
| 158 | 152 | }; | ... | ... |
include/qpdf/QPDFObjectHelper.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFOBJECTHELPER_HH |
| 23 | 20 | #define QPDFOBJECTHELPER_HH |
| ... | ... | @@ -26,16 +23,13 @@ |
| 26 | 23 | |
| 27 | 24 | #include <qpdf/QPDFObjectHandle.hh> |
| 28 | 25 | |
| 29 | -// This is a base class for QPDF Object Helper classes. Object helpers | |
| 30 | -// are classes that provide a convenient, higher-level API for working | |
| 31 | -// with specific types of QPDF objects. Object helpers are always | |
| 32 | -// initialized with a QPDFObjectHandle, and the underlying object | |
| 33 | -// handle can always be retrieved. The intention is that you may | |
| 34 | -// freely intermix use of document helpers with the underlying QPDF | |
| 35 | -// objects unless there is a specific comment in a specific helper | |
| 36 | -// method that says otherwise. The pattern of using helper objects was | |
| 37 | -// introduced to allow creation of higher level helper functions | |
| 38 | -// without polluting the public interface of QPDFObjectHandle. | |
| 26 | +// This is a base class for QPDF Object Helper classes. Object helpers are classes that provide a | |
| 27 | +// convenient, higher-level API for working with specific types of QPDF objects. Object helpers are | |
| 28 | +// always initialized with a QPDFObjectHandle, and the underlying object handle can always be | |
| 29 | +// retrieved. The intention is that you may freely intermix use of object helpers with the | |
| 30 | +// underlying QPDF objects unless there is a specific comment in a specific helper method that says | |
| 31 | +// otherwise. The pattern of using helper objects was introduced to allow creation of higher level | |
| 32 | +// helper functions without polluting the public interface of QPDFObjectHandle. | |
| 39 | 33 | |
| 40 | 34 | class QPDF_DLL_CLASS QPDFObjectHelper |
| 41 | 35 | { | ... | ... |
include/qpdf/QPDFOutlineDocumentHelper.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFOUTLINEDOCUMENTHELPER_HH |
| 23 | 20 | #define QPDFOUTLINEDOCUMENTHELPER_HH |
| ... | ... | @@ -33,11 +30,10 @@ |
| 33 | 30 | |
| 34 | 31 | #include <qpdf/DLL.h> |
| 35 | 32 | |
| 36 | -// This is a document helper for outlines, also known as bookmarks. | |
| 37 | -// Outlines are discussed in section 12.3.3 of the PDF spec | |
| 38 | -// (ISO-32000). With the help of QPDFOutlineObjectHelper, the outlines | |
| 39 | -// tree is traversed, and a bidirectional map is made between pages | |
| 40 | -// and outlines. See also QPDFOutlineObjectHelper. | |
| 33 | +// This is a document helper for outlines, also known as bookmarks. Outlines are discussed in | |
| 34 | +// section 12.3.3 of the PDF spec (ISO-32000). With the help of QPDFOutlineObjectHelper, the | |
| 35 | +// outlines tree is traversed, and a bidirectional map is made between pages and outlines. See also | |
| 36 | +// QPDFOutlineObjectHelper. | |
| 41 | 37 | |
| 42 | 38 | class QPDFOutlineDocumentHelper: public QPDFDocumentHelper |
| 43 | 39 | { |
| ... | ... | @@ -53,15 +49,13 @@ class QPDFOutlineDocumentHelper: public QPDFDocumentHelper |
| 53 | 49 | QPDF_DLL |
| 54 | 50 | std::vector<QPDFOutlineObjectHelper> getTopLevelOutlines(); |
| 55 | 51 | |
| 56 | - // If the name is a name object, look it up in the /Dests key of | |
| 57 | - // the document catalog. If the name is a string, look it up in | |
| 58 | - // the name tree pointed to by the /Dests key of the names | |
| 52 | + // If the name is a name object, look it up in the /Dests key of the document catalog. If the | |
| 53 | + // name is a string, look it up in the name tree pointed to by the /Dests key of the names | |
| 59 | 54 | // dictionary. |
| 60 | 55 | QPDF_DLL |
| 61 | 56 | QPDFObjectHandle resolveNamedDest(QPDFObjectHandle name); |
| 62 | 57 | |
| 63 | - // Return a list outlines that are known to target the specified | |
| 64 | - // page | |
| 58 | + // Return a list outlines that are known to target the specified page. | |
| 65 | 59 | QPDF_DLL |
| 66 | 60 | std::vector<QPDFOutlineObjectHelper> getOutlinesForPage(QPDFObjGen const&); |
| 67 | 61 | ... | ... |
include/qpdf/QPDFOutlineObjectHelper.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFOUTLINEOBJECTHELPER_HH |
| 23 | 20 | #define QPDFOUTLINEOBJECTHELPER_HH |
| ... | ... | @@ -30,9 +27,8 @@ class QPDFOutlineDocumentHelper; |
| 30 | 27 | |
| 31 | 28 | #include <qpdf/DLL.h> |
| 32 | 29 | |
| 33 | -// This is an object helper for outline items. Outlines, also known as | |
| 34 | -// bookmarks, are described in section 12.3.3 of the PDF spec | |
| 35 | -// (ISO-32000). See comments below for details. | |
| 30 | +// This is an object helper for outline items. Outlines, also known as bookmarks, are described in | |
| 31 | +// section 12.3.3 of the PDF spec (ISO-32000). See comments below for details. | |
| 36 | 32 | |
| 37 | 33 | class QPDFOutlineObjectHelper: public QPDFObjectHelper |
| 38 | 34 | { |
| ... | ... | @@ -40,16 +36,15 @@ class QPDFOutlineObjectHelper: public QPDFObjectHelper |
| 40 | 36 | QPDF_DLL |
| 41 | 37 | virtual ~QPDFOutlineObjectHelper() |
| 42 | 38 | { |
| 43 | - // This must be cleared explicitly to avoid circular references | |
| 44 | - // that prevent cleanup of pointer holders. | |
| 39 | + // This must be cleared explicitly to avoid circular references that prevent cleanup of | |
| 40 | + // shared pointers. | |
| 45 | 41 | m->parent = nullptr; |
| 46 | 42 | } |
| 47 | 43 | |
| 48 | - // All constructors are private. You can only create one of these | |
| 49 | - // using QPDFOutlineDocumentHelper. | |
| 44 | + // All constructors are private. You can only create one of these using | |
| 45 | + // QPDFOutlineDocumentHelper. | |
| 50 | 46 | |
| 51 | - // Return parent pointer. Returns a null pointer if this is a | |
| 52 | - // top-level outline. | |
| 47 | + // Return parent pointer. Returns a null pointer if this is a top-level outline. | |
| 53 | 48 | QPDF_DLL |
| 54 | 49 | std::shared_ptr<QPDFOutlineObjectHelper> getParent(); |
| 55 | 50 | |
| ... | ... | @@ -57,29 +52,25 @@ class QPDFOutlineObjectHelper: public QPDFObjectHelper |
| 57 | 52 | QPDF_DLL |
| 58 | 53 | std::vector<QPDFOutlineObjectHelper> getKids(); |
| 59 | 54 | |
| 60 | - // Return the destination, regardless of whether it is named or | |
| 61 | - // explicit and whether it is directly provided or in a GoTo | |
| 62 | - // action. Returns a null object if the destination can't be | |
| 63 | - // determined. Named destinations can be resolved using the older | |
| 64 | - // root /Dest dictionary or the current names tree. | |
| 55 | + // Return the destination, regardless of whether it is named or explicit and whether it is | |
| 56 | + // directly provided or in a GoTo action. Returns a null object if the destination can't be | |
| 57 | + // determined. Named destinations can be resolved using the older root /Dest dictionary or the | |
| 58 | + // current names tree. | |
| 65 | 59 | QPDF_DLL |
| 66 | 60 | QPDFObjectHandle getDest(); |
| 67 | 61 | |
| 68 | - // Return the page that the outline points to. Returns a null | |
| 69 | - // object if the destination page can't be determined. | |
| 62 | + // Return the page that the outline points to. Returns a null object if the destination page | |
| 63 | + // can't be determined. | |
| 70 | 64 | QPDF_DLL |
| 71 | 65 | QPDFObjectHandle getDestPage(); |
| 72 | 66 | |
| 73 | - // Returns the value of /Count as present in the object, or 0 if | |
| 74 | - // not present. If count is positive, the outline is open. If | |
| 75 | - // negative, it is closed. Either way, the absolute value is the | |
| 76 | - // number descendant items that would be visible if this were | |
| 77 | - // open. | |
| 67 | + // Returns the value of /Count as present in the object, or 0 if not present. If count is | |
| 68 | + // positive, the outline is open. If negative, it is closed. Either way, the absolute value is | |
| 69 | + // the number of descendant items that would be visible if this were open. | |
| 78 | 70 | QPDF_DLL |
| 79 | 71 | int getCount(); |
| 80 | 72 | |
| 81 | - // Returns the title as a UTF-8 string. Returns the empty string | |
| 82 | - // if there is no title. | |
| 73 | + // Returns the title as a UTF-8 string. Returns an empty string if there is no title. | |
| 83 | 74 | QPDF_DLL |
| 84 | 75 | std::string getTitle(); |
| 85 | 76 | ... | ... |
include/qpdf/QPDFPageDocumentHelper.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFPAGEDOCUMENTHELPER_HH |
| 23 | 20 | #define QPDFPAGEDOCUMENTHELPER_HH |
| ... | ... | @@ -42,67 +39,53 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper |
| 42 | 39 | QPDF_DLL |
| 43 | 40 | virtual ~QPDFPageDocumentHelper() = default; |
| 44 | 41 | |
| 45 | - // Traverse page tree, and return all /Page objects wrapped in | |
| 46 | - // QPDFPageObjectHelper objects. Unlike with | |
| 47 | - // QPDF::getAllPages, the vector of pages returned by | |
| 48 | - // this call is not affected by additions or removals of pages. If | |
| 49 | - // you manipulate pages, you will have to call this again to get a | |
| 50 | - // new copy. Please see comments in QPDF.hh for getAllPages() for | |
| 51 | - // additional details. | |
| 42 | + // Traverse page tree, and return all /Page objects wrapped in QPDFPageObjectHelper objects. | |
| 43 | + // Unlike with QPDF::getAllPages, the vector of pages returned by this call is not affected by | |
| 44 | + // additions or removals of pages. If you manipulate pages, you will have to call this again to | |
| 45 | + // get a new copy. Please see comments in QPDF.hh for getAllPages() for additional details. | |
| 52 | 46 | QPDF_DLL |
| 53 | 47 | std::vector<QPDFPageObjectHelper> getAllPages(); |
| 54 | 48 | |
| 55 | - // The PDF /Pages tree allows inherited values. Working with the | |
| 56 | - // pages of a pdf is much easier when the inheritance is resolved | |
| 57 | - // by explicitly setting the values in each /Page. | |
| 49 | + // The PDF /Pages tree allows inherited values. Working with the pages of a pdf is much easier | |
| 50 | + // when the inheritance is resolved by explicitly setting the values in each /Page. | |
| 58 | 51 | QPDF_DLL |
| 59 | 52 | void pushInheritedAttributesToPage(); |
| 60 | 53 | |
| 61 | - // This calls QPDFPageObjectHelper::removeUnreferencedResources | |
| 62 | - // for every page in the document. See comments in | |
| 63 | - // QPDFPageObjectHelper.hh for details. | |
| 54 | + // This calls QPDFPageObjectHelper::removeUnreferencedResources for every page in the document. | |
| 55 | + // See comments in QPDFPageObjectHelper.hh for details. | |
| 64 | 56 | QPDF_DLL |
| 65 | 57 | void removeUnreferencedResources(); |
| 66 | 58 | |
| 67 | - // Add new page at the beginning or the end of the current pdf. | |
| 68 | - // The newpage parameter may be either a direct object, an | |
| 69 | - // indirect object from this QPDF, or an indirect object from | |
| 70 | - // another QPDF. If it is a direct object, it will be made | |
| 71 | - // indirect. If it is an indirect object from another QPDF, this | |
| 72 | - // method will call pushInheritedAttributesToPage on the other | |
| 73 | - // file and then copy the page to this QPDF using the same | |
| 74 | - // underlying code as copyForeignObject. At this stage, if the | |
| 75 | - // indirect object is already in the pages tree, a shallow copy is | |
| 76 | - // made to avoid adding the same page more than once. In version | |
| 77 | - // 10.3.1 and earlier, adding a page that already existed would | |
| 78 | - // throw an exception and could cause qpdf to crash on subsequent | |
| 79 | - // page insertions in some cases. Note that this means that, in | |
| 80 | - // some cases, the page actually added won't be exactly the same | |
| 81 | - // object as the one passed in. If you want to do subsequent | |
| 59 | + // Add a new page at the beginning or the end of the current pdf. The newpage parameter may be | |
| 60 | + // either a direct object, an indirect object from this QPDF, or an indirect object from another | |
| 61 | + // QPDF. If it is a direct object, it will be made indirect. If it is an indirect object from | |
| 62 | + // another QPDF, this method will call pushInheritedAttributesToPage on the other file and then | |
| 63 | + // copy the page to this QPDF using the same underlying code as copyForeignObject. At this | |
| 64 | + // stage, if the indirect object is already in the pages tree, a shallow copy is made to avoid | |
| 65 | + // adding the same page more than once. In version 10.3.1 and earlier, adding a page that | |
| 66 | + // already existed would throw an exception and could cause qpdf to crash on subsequent page | |
| 67 | + // insertions in some cases. Note that this means that, in some cases, the page actually added | |
| 68 | + // won't be exactly the same object as the one passed in. If you want to do subsequent | |
| 82 | 69 | // modification on the page, you should retrieve it again. |
| 83 | 70 | // |
| 84 | - // Note that you can call copyForeignObject directly to copy a | |
| 85 | - // page from a different file, but the resulting object will not | |
| 86 | - // be a page in the new file. You could do this, for example, to | |
| 87 | - // convert a page into a form XObject, though for that, you're | |
| 88 | - // better off using QPDFPageObjectHelper::getFormXObjectForPage. | |
| 71 | + // Note that you can call copyForeignObject directly to copy a page from a different file, but | |
| 72 | + // the resulting object will not be a page in the new file. You could do this, for example, to | |
| 73 | + // convert a page into a form XObject, though for that, you're better off using | |
| 74 | + // QPDFPageObjectHelper::getFormXObjectForPage. | |
| 89 | 75 | // |
| 90 | - // This method does not have any specific awareness of annotations | |
| 91 | - // or form fields, so if you just add a page without thinking | |
| 92 | - // about it, you might end up with two pages that share form | |
| 93 | - // fields or annotations. While the page may look fine, it will | |
| 94 | - // probably not function properly with regard to interactive | |
| 95 | - // features. To work around this, you should called | |
| 96 | - // QPDFAcroFormDocumentHelper::fixCopiedAnnotations. A future | |
| 97 | - // version of qpdf will likely provide a higher-level interface | |
| 98 | - // for copying pages around that will handle document-level | |
| 76 | + // This method does not have any specific awareness of annotations or form fields, so if you | |
| 77 | + // just add a page without thinking about it, you might end up with two pages that share form | |
| 78 | + // fields or annotations. While the page may look fine, it will probably not function properly | |
| 79 | + // with regard to interactive features. To work around this, you should call | |
| 80 | + // QPDFAcroFormDocumentHelper::fixCopiedAnnotations. A future version of qpdf will likely | |
| 81 | + // provide a higher-level interface for copying pages around that will handle document-level | |
| 99 | 82 | // constructs in a less error-prone fashion. |
| 100 | 83 | |
| 101 | 84 | QPDF_DLL |
| 102 | 85 | void addPage(QPDFPageObjectHelper newpage, bool first); |
| 103 | 86 | |
| 104 | - // Add new page before or after refpage. See comments for addPage | |
| 105 | - // for details about what newpage should be. | |
| 87 | + // Add new page before or after refpage. See comments for addPage for details about what newpage | |
| 88 | + // should be. | |
| 106 | 89 | QPDF_DLL |
| 107 | 90 | void addPageAt(QPDFPageObjectHelper newpage, bool before, QPDFPageObjectHelper refpage); |
| 108 | 91 | |
| ... | ... | @@ -110,17 +93,13 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper |
| 110 | 93 | QPDF_DLL |
| 111 | 94 | void removePage(QPDFPageObjectHelper page); |
| 112 | 95 | |
| 113 | - // For every annotation, integrate the annotation's appearance | |
| 114 | - // stream into the containing page's content streams, merge the | |
| 115 | - // annotation's resources with the page's resources, and remove | |
| 116 | - // the annotation from the page. Handles widget annotations | |
| 117 | - // associated with interactive form fields as a special case, | |
| 118 | - // including removing the /AcroForm key from the document catalog. | |
| 119 | - // The values passed to required_flags and forbidden_flags are | |
| 120 | - // passed along to | |
| 121 | - // QPDFAnnotationObjectHelper::getPageContentForAppearance. See | |
| 122 | - // comments there in QPDFAnnotationObjectHelper.hh for meanings of | |
| 123 | - // those flags. | |
| 96 | + // For every annotation, integrate the annotation's appearance stream into the containing page's | |
| 97 | + // content streams, merge the annotation's resources with the page's resources, and remove the | |
| 98 | + // annotation from the page. Handles widget annotations associated with interactive form fields | |
| 99 | + // as a special case, including removing the /AcroForm key from the document catalog. The values | |
| 100 | + // passed to required_flags and forbidden_flags are passed along to | |
| 101 | + // QPDFAnnotationObjectHelper::getPageContentForAppearance. See comments there in | |
| 102 | + // QPDFAnnotationObjectHelper.hh for meanings of those flags. | |
| 124 | 103 | QPDF_DLL |
| 125 | 104 | void flattenAnnotations(int required_flags = 0, int forbidden_flags = an_invisible | an_hidden); |
| 126 | 105 | ... | ... |
include/qpdf/QPDFPageLabelDocumentHelper.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFPAGELABELDOCUMENTHELPER_HH |
| 23 | 20 | #define QPDFPAGELABELDOCUMENTHELPER_HH |
| ... | ... | @@ -30,18 +27,15 @@ |
| 30 | 27 | |
| 31 | 28 | #include <qpdf/DLL.h> |
| 32 | 29 | |
| 33 | -// Page labels are discussed in the PDF spec (ISO-32000) in section | |
| 34 | -// 12.4.2. | |
| 30 | +// Page labels are discussed in the PDF spec (ISO-32000) in section 12.4.2. | |
| 35 | 31 | // |
| 36 | -// Page labels are implemented as a number tree. Each key is a page | |
| 37 | -// index, numbered from 0. The values are dictionaries with the | |
| 38 | -// following keys, all optional: | |
| 32 | +// Page labels are implemented as a number tree. Each key is a page index, numbered from 0. The | |
| 33 | +// values are dictionaries with the following keys, all optional: | |
| 39 | 34 | // |
| 40 | 35 | // * /Type: if present, must be /PageLabel |
| 41 | -// * /S: one of /D, /R, /r, /A, or /a for decimal, upper-case and | |
| 42 | -// lower-case Roman numeral, or upper-case and lower-case alphabetic | |
| 43 | -// * /P: if present, a fixed prefix string that is prepended to each | |
| 44 | -// page number | |
| 36 | +// * /S: one of /D, /R, /r, /A, or /a for decimal, upper-case and lower-case Roman numeral, or | |
| 37 | +// upper-case and lower-case alphabetic | |
| 38 | +// * /P: if present, a fixed prefix string that is prepended to each page number | |
| 45 | 39 | // * /St: the starting number, or 1 if not specified |
| 46 | 40 | |
| 47 | 41 | class QPDFPageLabelDocumentHelper: public QPDFDocumentHelper |
| ... | ... | @@ -55,25 +49,20 @@ class QPDFPageLabelDocumentHelper: public QPDFDocumentHelper |
| 55 | 49 | QPDF_DLL |
| 56 | 50 | bool hasPageLabels(); |
| 57 | 51 | |
| 58 | - // Return a page label dictionary representing the page label for | |
| 59 | - // the given page. The page does not need to appear explicitly in | |
| 60 | - // the page label dictionary. This method will adjust /St as | |
| 52 | + // Return a page label dictionary representing the page label for the given page. The page does | |
| 53 | + // not need to appear explicitly in the page label dictionary. This method will adjust /St as | |
| 61 | 54 | // needed to produce a label that is suitable for the page. |
| 62 | 55 | QPDF_DLL |
| 63 | 56 | QPDFObjectHandle getLabelForPage(long long page_idx); |
| 64 | 57 | |
| 65 | - // Append to the incoming vector a list of objects suitable for | |
| 66 | - // inclusion in a /PageLabels dictionary's /Nums field. start_idx | |
| 67 | - // and end_idx are the indexes to the starting and ending pages | |
| 68 | - // (inclusive) in the original file, and new_start_idx is the | |
| 69 | - // index to the first page in the new file. For example, if pages | |
| 70 | - // 10 through 12 of one file are being copied to a new file as | |
| 71 | - // pages 6 through 8, you would call getLabelsForPageRange(10, 12, | |
| 72 | - // 6), which would return as many entries as are required to add | |
| 73 | - // to the new file's PageLabels. This method fabricates a suitable | |
| 74 | - // entry even if the original document has no page labels. This | |
| 75 | - // behavior facilitates using this function to incrementally build | |
| 76 | - // up a page labels tree when merging files. | |
| 58 | + // Append to the incoming vector a list of objects suitable for inclusion in a /PageLabels | |
| 59 | + // dictionary's /Nums field. start_idx and end_idx are the indexes to the starting and ending | |
| 60 | + // pages (inclusive) in the original file, and new_start_idx is the index to the first page in | |
| 61 | + // the new file. For example, if pages 10 through 12 of one file are being copied to a new file | |
| 62 | + // as pages 6 through 8, you would call getLabelsForPageRange(10, 12, 6), which would return as | |
| 63 | + // many entries as are required to add to the new file's PageLabels. This method fabricates a | |
| 64 | + // suitable entry even if the original document has no page labels. This behavior facilitates | |
| 65 | + // using this function to incrementally build up a page labels tree when merging files. | |
| 77 | 66 | QPDF_DLL |
| 78 | 67 | void getLabelsForPageRange( |
| 79 | 68 | long long start_idx, | ... | ... |
include/qpdf/QPDFStreamFilter.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFSTREAMFILTER_HH |
| 23 | 20 | #define QPDFSTREAMFILTER_HH |
| ... | ... | @@ -35,36 +32,29 @@ class QPDF_DLL_CLASS QPDFStreamFilter |
| 35 | 32 | QPDF_DLL |
| 36 | 33 | virtual ~QPDFStreamFilter() = default; |
| 37 | 34 | |
| 38 | - // A QPDFStreamFilter class must implement, at a minimum, | |
| 39 | - // setDecodeParms() and getDecodePipeline(). QPDF will always call | |
| 40 | - // setDecodeParms() before calling getDecodePipeline(). It is | |
| 41 | - // expected that you will store any needed information from | |
| 42 | - // decode_parms (or the decode_parms object itself) in your | |
| 43 | - // instance so that it can be used to construct the decode | |
| 44 | - // pipeline. | |
| 35 | + // A QPDFStreamFilter class must implement, at a minimum, setDecodeParms() and | |
| 36 | + // getDecodePipeline(). QPDF will always call setDecodeParms() before calling | |
| 37 | + // getDecodePipeline(). It is expected that you will store any needed information from | |
| 38 | + // decode_parms (or the decode_parms object itself) in your instance so that it can be used to | |
| 39 | + // construct the decode pipeline. | |
| 45 | 40 | |
| 46 | - // Return a boolean indicating whether your filter can proceed | |
| 47 | - // with the given /DecodeParms. The default implementation accepts | |
| 48 | - // a null object and rejects everything else. | |
| 41 | + // Return a boolean indicating whether your filter can proceed with the given /DecodeParms. The | |
| 42 | + // default implementation accepts a null object and rejects everything else. | |
| 49 | 43 | QPDF_DLL |
| 50 | 44 | virtual bool setDecodeParms(QPDFObjectHandle decode_parms); |
| 51 | 45 | |
| 52 | - // Return a pipeline that will decode data encoded with your | |
| 53 | - // filter. Your implementation must ensure that the pipeline is | |
| 54 | - // deleted when the instance of your class is destroyed. | |
| 46 | + // Return a pipeline that will decode data encoded with your filter. Your implementation must | |
| 47 | + // ensure that the pipeline is deleted when the instance of your class is destroyed. | |
| 55 | 48 | QPDF_DLL |
| 56 | 49 | virtual Pipeline* getDecodePipeline(Pipeline* next) = 0; |
| 57 | 50 | |
| 58 | - // If your filter implements "specialized" compression or lossy | |
| 59 | - // compression, override one or both of these methods. The default | |
| 60 | - // implementations return false. See comments in QPDFWriter for | |
| 61 | - // details. QPDF defines specialized compression as non-lossy | |
| 62 | - // compression not intended for general-purpose data. qpdf, by | |
| 63 | - // default, doesn't mess with streams that are compressed with | |
| 64 | - // specialized compression, the idea being that the decision to | |
| 65 | - // use that compression scheme would fall outside of what | |
| 66 | - // QPDFWriter would know anything about, so any attempt to decode | |
| 67 | - // and re-encode would probably be undesirable. | |
| 51 | + // If your filter implements "specialized" compression or lossy compression, override one or | |
| 52 | + // both of these methods. The default implementations return false. See comments in QPDFWriter | |
| 53 | + // for details. QPDF defines specialized compression as non-lossy compression not intended for | |
| 54 | + // general-purpose data. qpdf, by default, doesn't mess with streams that are compressed with | |
| 55 | + // specialized compression, the idea being that the decision to use that compression scheme | |
| 56 | + // would fall outside of what QPDFWriter would know anything about, so any attempt to decode and | |
| 57 | + // re-encode would probably be undesirable. | |
| 68 | 58 | QPDF_DLL |
| 69 | 59 | virtual bool isSpecializedCompression(); |
| 70 | 60 | QPDF_DLL | ... | ... |
include/qpdf/QPDFSystemError.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFSYSTEMERROR_HH |
| 23 | 20 | #define QPDFSYSTEMERROR_HH |
| ... | ... | @@ -37,9 +34,8 @@ class QPDF_DLL_CLASS QPDFSystemError: public std::runtime_error |
| 37 | 34 | QPDF_DLL |
| 38 | 35 | virtual ~QPDFSystemError() noexcept = default; |
| 39 | 36 | |
| 40 | - // To get a complete error string, call what(), provided by | |
| 41 | - // std::exception. The accessors below return the original values | |
| 42 | - // used to create the exception. | |
| 37 | + // To get a complete error string, call what(), provided by std::exception. The accessors below | |
| 38 | + // return the original values used to create the exception. | |
| 43 | 39 | |
| 44 | 40 | QPDF_DLL |
| 45 | 41 | std::string const& getDescription() const; |
| ... | ... | @@ -50,8 +46,8 @@ class QPDF_DLL_CLASS QPDFSystemError: public std::runtime_error |
| 50 | 46 | QPDF_DLL_PRIVATE |
| 51 | 47 | static std::string createWhat(std::string const& description, int system_errno); |
| 52 | 48 | |
| 53 | - // This class does not use the Members pattern to avoid needless | |
| 54 | - // memory allocations during exception handling. | |
| 49 | + // This class does not use the Members pattern to avoid needless memory allocations during | |
| 50 | + // exception handling. | |
| 55 | 51 | |
| 56 | 52 | std::string description; |
| 57 | 53 | int system_errno; | ... | ... |
include/qpdf/QPDFUsage.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFUSAGE_HH |
| 23 | 20 | #define QPDFUSAGE_HH | ... | ... |
include/qpdf/QPDFWriter.hh
| ... | ... | @@ -2,26 +2,22 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | -// This class implements a simple writer for saving QPDF objects to | |
| 23 | -// new PDF files. See comments through the header file for additional | |
| 24 | -// details. | |
| 19 | +// This class implements a simple writer for saving QPDF objects to new PDF files. See comments | |
| 20 | +// through the header file for additional details. | |
| 25 | 21 | |
| 26 | 22 | #ifndef QPDFWRITER_HH |
| 27 | 23 | #define QPDFWRITER_HH |
| ... | ... | @@ -57,21 +53,19 @@ class Pl_MD5; |
| 57 | 53 | class QPDFWriter |
| 58 | 54 | { |
| 59 | 55 | public: |
| 60 | - // Construct a QPDFWriter object without specifying output. You | |
| 61 | - // must call one of the output setting routines defined below. | |
| 56 | + // Construct a QPDFWriter object without specifying output. You must call one of the output | |
| 57 | + // setting routines defined below. | |
| 62 | 58 | QPDF_DLL |
| 63 | 59 | QPDFWriter(QPDF& pdf); |
| 64 | 60 | |
| 65 | - // Create a QPDFWriter object that writes its output to a file or | |
| 66 | - // to stdout. This is equivalent to using the previous | |
| 67 | - // constructor and then calling setOutputFilename(). See | |
| 61 | + // Create a QPDFWriter object that writes its output to a file or to stdout. This is equivalent | |
| 62 | + // to using the previous constructor and then calling setOutputFilename(). See | |
| 68 | 63 | // setOutputFilename() for details. |
| 69 | 64 | QPDF_DLL |
| 70 | 65 | QPDFWriter(QPDF& pdf, char const* filename); |
| 71 | 66 | |
| 72 | - // Create a QPDFWriter object that writes its output to an already | |
| 73 | - // open FILE*. This is equivalent to calling the first | |
| 74 | - // constructor and then calling setOutputFile(). See | |
| 67 | + // Create a QPDFWriter object that writes its output to an already open FILE*. This is | |
| 68 | + // equivalent to calling the first constructor and then calling setOutputFile(). See | |
| 75 | 69 | // setOutputFile() for details. |
| 76 | 70 | QPDF_DLL |
| 77 | 71 | QPDFWriter(QPDF& pdf, char const* description, FILE* file, bool close_file); |
| ... | ... | @@ -85,15 +79,13 @@ class QPDFWriter |
| 85 | 79 | QPDF_DLL |
| 86 | 80 | virtual ~ProgressReporter(); |
| 87 | 81 | |
| 88 | - // This method is called with a value from 0 to 100 to | |
| 89 | - // indicate approximate progress through the write process. | |
| 90 | - // See registerProgressReporter. | |
| 82 | + // This method is called with a value from 0 to 100 to indicate approximate progress through | |
| 83 | + // the write process. See registerProgressReporter. | |
| 91 | 84 | virtual void reportProgress(int) = 0; |
| 92 | 85 | }; |
| 93 | 86 | |
| 94 | - // This is a progress reporter that takes a function. It is used | |
| 95 | - // by the C APIs, but it is available if you want to just register | |
| 96 | - // a C function as a handler. | |
| 87 | + // This is a progress reporter that takes a function. It is used by the C APIs, but it is | |
| 88 | + // available if you want to just register a C function as a handler. | |
| 97 | 89 | class QPDF_DLL_CLASS FunctionProgressReporter: public ProgressReporter |
| 98 | 90 | { |
| 99 | 91 | public: |
| ... | ... | @@ -108,39 +100,31 @@ class QPDFWriter |
| 108 | 100 | std::function<void(int)> handler; |
| 109 | 101 | }; |
| 110 | 102 | |
| 111 | - // Setting Output. Output may be set only one time. If you don't | |
| 112 | - // use the filename version of the QPDFWriter constructor, you | |
| 113 | - // must call exactly one of these methods. | |
| 103 | + // Setting Output. Output may be set only one time. If you don't use the filename version of | |
| 104 | + // the QPDFWriter constructor, you must call exactly one of these methods. | |
| 114 | 105 | |
| 115 | - // Passing null as filename means write to stdout. QPDFWriter | |
| 116 | - // will create a zero-length output file upon construction. If | |
| 117 | - // write fails, the empty or partially written file will not be | |
| 118 | - // deleted. This is by design: sometimes the partial file may be | |
| 119 | - // useful for tracking down problems. If your application doesn't | |
| 120 | - // want the partially written file to be left behind, you should | |
| 121 | - // delete it the eventual call to write fails. | |
| 106 | + // Passing nullptr as filename means write to stdout. QPDFWriter will create a zero-length | |
| 107 | + // output file upon construction. If write fails, the empty or partially written file will not | |
| 108 | + // be deleted. This is by design: sometimes the partial file may be useful for tracking down | |
| 109 | + // problems. If your application doesn't want the partially written file to be left behind, you | |
| 110 | + // should delete it if the eventual call to write fails. | |
| 122 | 111 | QPDF_DLL |
| 123 | 112 | void setOutputFilename(char const* filename); |
| 124 | 113 | |
| 125 | - // Write to the given FILE*, which must be opened by the caller. | |
| 126 | - // If close_file is true, QPDFWriter will close the file. | |
| 127 | - // Otherwise, the caller must close the file. The file does not | |
| 128 | - // need to be seekable; it will be written to in a single pass. | |
| 129 | - // It must be open in binary mode. | |
| 114 | + // Write to the given FILE*, which must be opened by the caller. If close_file is true, | |
| 115 | + // QPDFWriter will close the file. Otherwise, the caller must close the file. The file does not | |
| 116 | + // need to be seekable; it will be written to in a single pass. It must be open in binary mode. | |
| 130 | 117 | QPDF_DLL |
| 131 | 118 | void setOutputFile(char const* description, FILE* file, bool close_file); |
| 132 | 119 | |
| 133 | - // Indicate that QPDFWriter should create a memory buffer to | |
| 134 | - // contain the final PDF file. Obtain the memory by calling | |
| 135 | - // getBuffer(). | |
| 120 | + // Indicate that QPDFWriter should create a memory buffer to contain the final PDF file. Obtain | |
| 121 | + // the memory by calling getBuffer(). | |
| 136 | 122 | QPDF_DLL |
| 137 | 123 | void setOutputMemory(); |
| 138 | 124 | |
| 139 | - // Return the buffer object containing the PDF file. If | |
| 140 | - // setOutputMemory() has been called, this method may be called | |
| 141 | - // exactly one time after write() has returned. The caller is | |
| 142 | - // responsible for deleting the buffer when done. See also | |
| 143 | - // getBufferSharedPointer(). | |
| 125 | + // Return the buffer object containing the PDF file. If setOutputMemory() has been called, this | |
| 126 | + // method may be called exactly one time after write() has returned. The caller is responsible | |
| 127 | + // for deleting the buffer when done. See also getBufferSharedPointer(). | |
| 144 | 128 | QPDF_DLL |
| 145 | 129 | Buffer* getBuffer(); |
| 146 | 130 | |
| ... | ... | @@ -148,33 +132,27 @@ class QPDFWriter |
| 148 | 132 | QPDF_DLL |
| 149 | 133 | std::shared_ptr<Buffer> getBufferSharedPointer(); |
| 150 | 134 | |
| 151 | - // Supply your own pipeline object. Output will be written to | |
| 152 | - // this pipeline, and QPDFWriter will call finish() on the | |
| 153 | - // pipeline. It is the caller's responsibility to manage the | |
| 154 | - // memory for the pipeline. The pipeline is never deleted by | |
| 155 | - // QPDFWriter, which makes it possible for you to call additional | |
| 156 | - // methods on the pipeline after the writing is finished. | |
| 135 | + // Supply your own pipeline object. Output will be written to this pipeline, and QPDFWriter | |
| 136 | + // will call finish() on the pipeline. It is the caller's responsibility to manage the memory | |
| 137 | + // for the pipeline. The pipeline is never deleted by QPDFWriter, which makes it possible for | |
| 138 | + // you to call additional methods on the pipeline after the writing is finished. | |
| 157 | 139 | QPDF_DLL |
| 158 | 140 | void setOutputPipeline(Pipeline*); |
| 159 | 141 | |
| 160 | 142 | // Setting Parameters |
| 161 | 143 | |
| 162 | - // Set the value of object stream mode. In disable mode, we never | |
| 163 | - // generate any object streams. In preserve mode, we preserve | |
| 164 | - // object stream structure from the original file. In generate | |
| 165 | - // mode, we generate our own object streams. In all cases, we | |
| 166 | - // generate a conventional cross-reference table if there are no | |
| 167 | - // object streams and a cross-reference stream if there are object | |
| 168 | - // streams. The default is o_preserve. | |
| 144 | + // Set the value of object stream mode. In disable mode, we never generate any object streams. | |
| 145 | + // In preserve mode, we preserve object stream structure from the original file. In generate | |
| 146 | + // mode, we generate our own object streams. In all cases, we generate a conventional | |
| 147 | + // cross-reference table if there are no object streams and a cross-reference stream if there | |
| 148 | + // are object streams. The default is o_preserve. | |
| 169 | 149 | QPDF_DLL |
| 170 | 150 | void setObjectStreamMode(qpdf_object_stream_e); |
| 171 | 151 | |
| 172 | - // Set value of stream data mode. This is an older interface. | |
| 173 | - // Instead of using this, prefer setCompressStreams() and | |
| 174 | - // setDecodeLevel(). This method is retained for compatibility, | |
| 175 | - // but it does not cover the full range of available | |
| 176 | - // configurations. The mapping between this and the new methods is | |
| 177 | - // as follows: | |
| 152 | + // Set value of stream data mode. This is an older interface. Instead of using this, prefer | |
| 153 | + // setCompressStreams() and setDecodeLevel(). This method is retained for compatibility, but it | |
| 154 | + // does not cover the full range of available configurations. The mapping between this and the | |
| 155 | + // new methods is as follows: | |
| 178 | 156 | // |
| 179 | 157 | // qpdf_s_uncompress: |
| 180 | 158 | // setCompressStreams(false) |
| ... | ... | @@ -190,205 +168,161 @@ class QPDFWriter |
| 190 | 168 | QPDF_DLL |
| 191 | 169 | void setStreamDataMode(qpdf_stream_data_e); |
| 192 | 170 | |
| 193 | - // If true, compress any uncompressed streams when writing them. | |
| 194 | - // Metadata streams are a special case and are not compressed even | |
| 195 | - // if this is true. This is true by default for QPDFWriter. If you | |
| 196 | - // want QPDFWriter to leave uncompressed streams uncompressed, | |
| 197 | - // pass false to this method. | |
| 171 | + // If true, compress any uncompressed streams when writing them. Metadata streams are a special | |
| 172 | + // case and are not compressed even if this is true. This is true by default for QPDFWriter. If | |
| 173 | + // you want QPDFWriter to leave uncompressed streams uncompressed, pass false to this method. | |
| 198 | 174 | QPDF_DLL |
| 199 | 175 | void setCompressStreams(bool); |
| 200 | 176 | |
| 201 | - // When QPDFWriter encounters streams, this parameter controls the | |
| 202 | - // behavior with respect to attempting to apply any filters to the | |
| 203 | - // streams when copying to the output. The decode levels are as | |
| 204 | - // follows: | |
| 177 | + // When QPDFWriter encounters streams, this parameter controls the behavior with respect to | |
| 178 | + // attempting to apply any filters to the streams when copying to the output. The decode levels | |
| 179 | + // are as follows: | |
| 205 | 180 | // |
| 206 | - // qpdf_dl_none: Do not attempt to apply any filters. Streams | |
| 207 | - // remain as they appear in the original file. Note that | |
| 208 | - // uncompressed streams may still be compressed on output. You can | |
| 181 | + // qpdf_dl_none: Do not attempt to apply any filters. Streams remain as they appear in the | |
| 182 | + // original file. Note that uncompressed streams may still be compressed on output. You can | |
| 209 | 183 | // disable that by calling setCompressStreams(false). |
| 210 | 184 | // |
| 211 | - // qpdf_dl_generalized: This is the default. QPDFWriter will apply | |
| 212 | - // LZWDecode, ASCII85Decode, ASCIIHexDecode, and FlateDecode | |
| 213 | - // filters on the input. When combined with | |
| 214 | - // setCompressStreams(true), which the default, the effect of this | |
| 215 | - // is that streams filtered with these older and less efficient | |
| 216 | - // filters will be recompressed with the Flate filter. By default, | |
| 217 | - // as a special case, if a stream is already compressed with | |
| 218 | - // FlateDecode and setCompressStreams is enabled, the original | |
| 219 | - // compressed data will be preserved. This behavior can be | |
| 220 | - // overridden by calling setRecompressFlate(true). | |
| 185 | + // qpdf_dl_generalized: This is the default. QPDFWriter will apply LZWDecode, ASCII85Decode, | |
| 186 | + // ASCIIHexDecode, and FlateDecode filters on the input. When combined with | |
| 187 | + // setCompressStreams(true), which is the default, the effect of this is that streams filtered | |
| 188 | + // with these older and less efficient filters will be recompressed with the Flate filter. By | |
| 189 | + // default, as a special case, if a stream is already compressed with FlateDecode and | |
| 190 | + // setCompressStreams is enabled, the original compressed data will be preserved. This behavior | |
| 191 | + // can be overridden by calling setRecompressFlate(true). | |
| 221 | 192 | // |
| 222 | - // qpdf_dl_specialized: In addition to uncompressing the | |
| 223 | - // generalized compression formats, supported non-lossy | |
| 224 | - // compression will also be decoded. At present, this includes | |
| 225 | - // the RunLengthDecode filter. | |
| 193 | + // qpdf_dl_specialized: In addition to uncompressing the generalized compression formats, | |
| 194 | + // supported non-lossy compression will also be decoded. At present, this includes the | |
| 195 | + // RunLengthDecode filter. | |
| 226 | 196 | // |
| 227 | - // qpdf_dl_all: In addition to generalized and non-lossy | |
| 228 | - // specialized filters, supported lossy compression filters will | |
| 229 | - // be applied. At present, this includes DCTDecode (JPEG) | |
| 230 | - // compression. Note that compressing the resulting data with | |
| 231 | - // DCTDecode again will accumulate loss, so avoid multiple | |
| 232 | - // compression and decompression cycles. This is mostly useful for | |
| 233 | - // retrieving image data. | |
| 197 | + // qpdf_dl_all: In addition to generalized and non-lossy specialized filters, supported lossy | |
| 198 | + // compression filters will be applied. At present, this includes DCTDecode (JPEG) compression. | |
| 199 | + // Note that compressing the resulting data with DCTDecode again will accumulate loss, so avoid | |
| 200 | + // multiple compression and decompression cycles. This is mostly useful for retrieving image | |
| 201 | + // data. | |
| 234 | 202 | QPDF_DLL |
| 235 | 203 | void setDecodeLevel(qpdf_stream_decode_level_e); |
| 236 | 204 | |
| 237 | - // By default, when both the input and output contents of a stream | |
| 238 | - // are compressed with Flate, qpdf does not uncompress and | |
| 239 | - // recompress the stream. Passing true here causes it to do so. | |
| 240 | - // This can be useful if recompressing all streams with a higher | |
| 241 | - // compression level, which can be set by calling the static | |
| 242 | - // method Pl_Flate::setCompressionLevel. | |
| 205 | + // By default, when both the input and output contents of a stream are compressed with Flate, | |
| 206 | + // qpdf does not uncompress and recompress the stream. Passing true here causes it to do so. | |
| 207 | + // This can be useful if recompressing all streams with a higher compression level, which can be | |
| 208 | + // set by calling the static method Pl_Flate::setCompressionLevel. | |
| 243 | 209 | QPDF_DLL |
| 244 | 210 | void setRecompressFlate(bool); |
| 245 | 211 | |
| 246 | - // Set value of content stream normalization. The default is | |
| 247 | - // "false". If true, we attempt to normalize newlines inside of | |
| 248 | - // content streams. Some constructs such as inline images may | |
| 249 | - // thwart our efforts. There may be some cases where this can | |
| 250 | - // damage the content stream. This flag should be used only for | |
| 251 | - // debugging and experimenting with PDF content streams. Never | |
| 252 | - // use it for production files. | |
| 212 | + // Set value of content stream normalization. The default is "false". If true, we attempt to | |
| 213 | + // normalize newlines inside of content streams. Some constructs such as inline images may | |
| 214 | + // thwart our efforts. There may be some cases where this can damage the content stream. This | |
| 215 | + // flag should be used only for debugging and experimenting with PDF content streams. Never use | |
| 216 | + // it for production files. | |
| 253 | 217 | QPDF_DLL |
| 254 | 218 | void setContentNormalization(bool); |
| 255 | 219 | |
| 256 | - // Set QDF mode. QDF mode causes special "pretty printing" of | |
| 257 | - // PDF objects, adds comments for easier perusing of files. | |
| 258 | - // Resulting PDF files can be edited in a text editor and then run | |
| 259 | - // through fix-qdf to update cross reference tables and stream | |
| 260 | - // lengths. | |
| 220 | + // Set QDF mode. QDF mode causes special "pretty printing" of PDF objects, adds comments for | |
| 221 | + // easier perusing of files. Resulting PDF files can be edited in a text editor and then run | |
| 222 | + // through fix-qdf to update cross reference tables and stream lengths. | |
| 261 | 223 | QPDF_DLL |
| 262 | 224 | void setQDFMode(bool); |
| 263 | 225 | |
| 264 | - // Preserve unreferenced objects. The default behavior is to | |
| 265 | - // discard any object that is not visited during a traversal of | |
| 266 | - // the object structure from the trailer. | |
| 226 | + // Preserve unreferenced objects. The default behavior is to discard any object that is not | |
| 227 | + // visited during a traversal of the object structure from the trailer. | |
| 267 | 228 | QPDF_DLL |
| 268 | 229 | void setPreserveUnreferencedObjects(bool); |
| 269 | 230 | |
| 270 | - // Always write a newline before the endstream keyword. This helps | |
| 271 | - // with PDF/A compliance, though it is not sufficient for it. | |
| 231 | + // Always write a newline before the endstream keyword. This helps with PDF/A compliance, though | |
| 232 | + // it is not sufficient for it. | |
| 272 | 233 | QPDF_DLL |
| 273 | 234 | void setNewlineBeforeEndstream(bool); |
| 274 | 235 | |
| 275 | - // Set the minimum PDF version. If the PDF version of the input | |
| 276 | - // file (or previously set minimum version) is less than the | |
| 277 | - // version passed to this method, the PDF version of the output | |
| 278 | - // file will be set to this value. If the original PDF file's | |
| 279 | - // version or previously set minimum version is already this | |
| 280 | - // version or later, the original file's version will be used. | |
| 281 | - // QPDFWriter automatically sets the minimum version to 1.4 when | |
| 282 | - // R3 encryption parameters are used, and to 1.5 when object | |
| 283 | - // streams are used. | |
| 236 | + // Set the minimum PDF version. If the PDF version of the input file (or previously set minimum | |
| 237 | + // version) is less than the version passed to this method, the PDF version of the output file | |
| 238 | + // will be set to this value. If the original PDF file's version or previously set minimum | |
| 239 | + // version is already this version or later, the original file's version will be used. | |
| 240 | + // QPDFWriter automatically sets the minimum version to 1.4 when R3 encryption parameters are | |
| 241 | + // used, and to 1.5 when object streams are used. | |
| 284 | 242 | QPDF_DLL |
| 285 | 243 | void setMinimumPDFVersion(std::string const&, int extension_level = 0); |
| 286 | 244 | QPDF_DLL |
| 287 | 245 | void setMinimumPDFVersion(PDFVersion const&); |
| 288 | 246 | |
| 289 | - // Force the PDF version of the output file to be a given version. | |
| 290 | - // Use of this function may create PDF files that will not work | |
| 291 | - // properly with older PDF viewers. When a PDF version is set | |
| 292 | - // using this function, qpdf will use this version even if the | |
| 293 | - // file contains features that are not supported in that version | |
| 294 | - // of PDF. In other words, you should only use this function if | |
| 295 | - // you are sure the PDF file in question has no features of newer | |
| 296 | - // versions of PDF or if you are willing to create files that old | |
| 297 | - // viewers may try to open but not be able to properly interpret. | |
| 298 | - // If any encryption has been applied to the document either | |
| 299 | - // explicitly or by preserving the encryption of the source | |
| 300 | - // document, forcing the PDF version to a value too low to support | |
| 301 | - // that type of encryption will explicitly disable decryption. | |
| 302 | - // Additionally, forcing to a version below 1.5 will disable | |
| 303 | - // object streams. | |
| 247 | + // Force the PDF version of the output file to be a given version. Use of this function may | |
| 248 | + // create PDF files that will not work properly with older PDF viewers. When a PDF version is | |
| 249 | + // set using this function, qpdf will use this version even if the file contains features that | |
| 250 | + // are not supported in that version of PDF. In other words, you should only use this function | |
| 251 | + // if you are sure the PDF file in question has no features of newer versions of PDF or if you | |
| 252 | + // are willing to create files that old viewers may try to open but not be able to properly | |
| 253 | + // interpret. If any encryption has been applied to the document either explicitly or by | |
| 254 | + // preserving the encryption of the source document, forcing the PDF version to a value too low | |
| 255 | + // to support that type of encryption will explicitly disable decryption. Additionally, forcing | |
| 256 | + // to a version below 1.5 will disable object streams. | |
| 304 | 257 | QPDF_DLL |
| 305 | 258 | void forcePDFVersion(std::string const&, int extension_level = 0); |
| 306 | 259 | |
| 307 | - // Provide additional text to insert in the PDF file somewhere | |
| 308 | - // near the beginning of the file. This can be used to add | |
| 309 | - // comments to the beginning of a PDF file, for example, if those | |
| 310 | - // comments are to be consumed by some other application. No | |
| 311 | - // checks are performed to ensure that the text inserted here is | |
| 312 | - // valid PDF. If you want to insert multiline comments, you will | |
| 313 | - // need to include \n in the string yourself and start each line | |
| 314 | - // with %. An extra newline will be appended if one is not | |
| 315 | - // already present at the end of your text. | |
| 260 | + // Provide additional text to insert in the PDF file somewhere near the beginning of the file. | |
| 261 | + // This can be used to add comments to the beginning of a PDF file, for example, if those | |
| 262 | + // comments are to be consumed by some other application. No checks are performed to ensure | |
| 263 | + // that the text inserted here is valid PDF. If you want to insert multiline comments, you will | |
| 264 | + // need to include \n in the string yourself and start each line with %. An extra newline will | |
| 265 | + // be appended if one is not already present at the end of your text. | |
| 316 | 266 | QPDF_DLL |
| 317 | 267 | void setExtraHeaderText(std::string const&); |
| 318 | 268 | |
| 319 | - // Causes a deterministic /ID value to be generated. When this is | |
| 320 | - // set, the current time and output file name are not used as part | |
| 321 | - // of /ID generation. Instead, a digest of all significant parts | |
| 322 | - // of the output file's contents is included in the /ID | |
| 323 | - // calculation. Use of a deterministic /ID can be handy when it is | |
| 324 | - // desirable for a repeat of the same qpdf operation on the same | |
| 325 | - // inputs being written to the same outputs with the same | |
| 326 | - // parameters to generate exactly the same results. This feature | |
| 327 | - // is incompatible with encrypted files because, for encrypted | |
| 328 | - // files, the /ID is generated before any part of the file is | |
| 329 | - // written since it is an input to the encryption process. | |
| 269 | + // Causes a deterministic /ID value to be generated. When this is set, the current time and | |
| 270 | + // output file name are not used as part of /ID generation. Instead, a digest of all significant | |
| 271 | + // parts of the output file's contents is included in the /ID calculation. Use of a | |
| 272 | + // deterministic /ID can be handy when it is desirable for a repeat of the same qpdf operation | |
| 273 | + // on the same inputs being written to the same outputs with the same parameters to generate | |
| 274 | + // exactly the same results. This feature is incompatible with encrypted files because, for | |
| 275 | + // encrypted files, the /ID is generated before any part of the file is written since it is an | |
| 276 | + // input to the encryption process. | |
| 330 | 277 | QPDF_DLL |
| 331 | 278 | void setDeterministicID(bool); |
| 332 | 279 | |
| 333 | - // Cause a static /ID value to be generated. Use only in test | |
| 334 | - // suites. See also setDeterministicID. | |
| 280 | + // Cause a static /ID value to be generated. Use only in test suites. See also | |
| 281 | + // setDeterministicID. | |
| 335 | 282 | QPDF_DLL |
| 336 | 283 | void setStaticID(bool); |
| 337 | 284 | |
| 338 | - // Use a fixed initialization vector for AES-CBC encryption. This | |
| 339 | - // is not secure. It should be used only in test suites for | |
| 340 | - // creating predictable encrypted output. | |
| 285 | + // Use a fixed initialization vector for AES-CBC encryption. This is not secure. It should be | |
| 286 | + // used only in test suites for creating predictable encrypted output. | |
| 341 | 287 | QPDF_DLL |
| 342 | 288 | void setStaticAesIV(bool); |
| 343 | 289 | |
| 344 | - // Suppress inclusion of comments indicating original object IDs | |
| 345 | - // when writing QDF files. This can also be useful for testing, | |
| 346 | - // particularly when using comparison of two qdf files to | |
| 290 | + // Suppress inclusion of comments indicating original object IDs when writing QDF files. This | |
| 291 | + // can also be useful for testing, particularly when using comparison of two qdf files to | |
| 347 | 292 | // determine whether two PDF files have identical content. |
| 348 | 293 | QPDF_DLL |
| 349 | 294 | void setSuppressOriginalObjectIDs(bool); |
| 350 | 295 | |
| 351 | - // Preserve encryption. The default is true unless prefilering, | |
| 352 | - // content normalization, or qdf mode has been selected in which | |
| 353 | - // case encryption is never preserved. Encryption is also not | |
| 296 | + // Preserve encryption. The default is true unless prefilering, content normalization, or qdf | |
| 297 | + // mode has been selected in which case encryption is never preserved. Encryption is also not | |
| 354 | 298 | // preserved if we explicitly set encryption parameters. |
| 355 | 299 | QPDF_DLL |
| 356 | 300 | void setPreserveEncryption(bool); |
| 357 | 301 | |
| 358 | - // Copy encryption parameters from another QPDF object. If you | |
| 359 | - // want to copy encryption from the object you are writing, call | |
| 360 | - // setPreserveEncryption(true) instead. | |
| 302 | + // Copy encryption parameters from another QPDF object. If you want to copy encryption from the | |
| 303 | + // object you are writing, call setPreserveEncryption(true) instead. | |
| 361 | 304 | QPDF_DLL |
| 362 | 305 | void copyEncryptionParameters(QPDF&); |
| 363 | 306 | |
| 364 | - // Set up for encrypted output. User and owner password both must | |
| 365 | - // be specified. Either or both may be the empty string. Note | |
| 366 | - // that qpdf does not apply any special treatment to the empty | |
| 367 | - // string, which makes it possible to create encrypted files with | |
| 368 | - // empty owner passwords and non-empty user passwords or with the | |
| 369 | - // same password for both user and owner. Some PDF reading | |
| 370 | - // products don't handle such files very well. Enabling | |
| 371 | - // encryption disables stream prefiltering and content | |
| 372 | - // normalization. Note that setting R2 encryption parameters sets | |
| 373 | - // the PDF version to at least 1.3, setting R3 encryption | |
| 374 | - // parameters pushes the PDF version number to at least 1.4, | |
| 375 | - // setting R4 parameters pushes the version to at least 1.5, or if | |
| 376 | - // AES is used, 1.6, and setting R5 or R6 parameters pushes the | |
| 377 | - // version to at least 1.7 with extension level 3. | |
| 307 | + // Set up for encrypted output. User and owner password both must be specified. Either or both | |
| 308 | + // may be the empty string. Note that qpdf does not apply any special treatment to the empty | |
| 309 | + // string, which makes it possible to create encrypted files with empty owner passwords and | |
| 310 | + // non-empty user passwords or with the same password for both user and owner. Some PDF reading | |
| 311 | + // products don't handle such files very well. Enabling encryption disables stream prefiltering | |
| 312 | + // and content normalization. Note that setting R2 encryption parameters sets the PDF version | |
| 313 | + // to at least 1.3, setting R3 encryption parameters pushes the PDF version number to at | |
| 314 | + // least 1.4, setting R4 parameters pushes the version to at least 1.5, or if AES is used, 1.6, | |
| 315 | + // and setting R5 or R6 parameters pushes the version to at least 1.7 with extension level 3. | |
| 378 | 316 | // |
| 379 | - // Note about Unicode passwords: the PDF specification requires | |
| 380 | - // passwords to be encoded with PDF Doc encoding for R <= 4 and | |
| 381 | - // UTF-8 for R >= 5. In all cases, these methods take strings of | |
| 382 | - // bytes as passwords. It is up to the caller to ensure that | |
| 383 | - // passwords are properly encoded. The qpdf command-line tool | |
| 384 | - // tries to do this, as discussed in the manual. If you are doing | |
| 385 | - // this from your own application, QUtil contains many transcoding | |
| 386 | - // functions that could be useful to you, most notably | |
| 387 | - // utf8_to_pdf_doc. | |
| 388 | - | |
| 389 | - // R2 uses RC4, which is a weak cryptographic algorithm. Don't use | |
| 390 | - // it unless you have to. See "Weak Cryptography" in the manual. | |
| 391 | - // This encryption format is deprecated in the PDF 2.0 | |
| 317 | + // Note about Unicode passwords: the PDF specification requires passwords to be encoded with PDF | |
| 318 | + // Doc encoding for R <= 4 and UTF-8 for R >= 5. In all cases, these methods take strings of | |
| 319 | + // bytes as passwords. It is up to the caller to ensure that passwords are properly encoded. The | |
| 320 | + // qpdf command-line tool tries to do this, as discussed in the manual. If you are doing this | |
| 321 | + // from your own application, QUtil contains many transcoding functions that could be useful to | |
| 322 | + // you, most notably utf8_to_pdf_doc. | |
| 323 | + | |
| 324 | + // R2 uses RC4, which is a weak cryptographic algorithm. Don't use it unless you have to. See | |
| 325 | + // "Weak Cryptography" in the manual. This encryption format is deprecated in the PDF 2.0 | |
| 392 | 326 | // specification. |
| 393 | 327 | QPDF_DLL |
| 394 | 328 | void setR2EncryptionParametersInsecure( |
| ... | ... | @@ -398,9 +332,8 @@ class QPDFWriter |
| 398 | 332 | bool allow_modify, |
| 399 | 333 | bool allow_extract, |
| 400 | 334 | bool allow_annotate); |
| 401 | - // R3 uses RC4, which is a weak cryptographic algorithm. Don't use | |
| 402 | - // it unless you have to. See "Weak Cryptography" in the manual. | |
| 403 | - // This encryption format is deprecated in the PDF 2.0 | |
| 335 | + // R3 uses RC4, which is a weak cryptographic algorithm. Don't use it unless you have to. See | |
| 336 | + // "Weak Cryptography" in the manual. This encryption format is deprecated in the PDF 2.0 | |
| 404 | 337 | // specification. |
| 405 | 338 | QPDF_DLL |
| 406 | 339 | void setR3EncryptionParametersInsecure( |
| ... | ... | @@ -413,11 +346,10 @@ class QPDFWriter |
| 413 | 346 | bool allow_form_filling, |
| 414 | 347 | bool allow_modify_other, |
| 415 | 348 | qpdf_r3_print_e print); |
| 416 | - // When use_aes=false, this call enables R4 with RC4, which is a | |
| 417 | - // weak cryptographic algorithm. Even with use_aes=true, the | |
| 418 | - // overall encryption scheme is weak. Don't use it unless you have | |
| 419 | - // to. See "Weak Cryptography" in the manual. This encryption | |
| 420 | - // format is deprecated in the PDF 2.0 specification. | |
| 349 | + // When use_aes=false, this call enables R4 with RC4, which is a weak cryptographic algorithm. | |
| 350 | + // Even with use_aes=true, the overall encryption scheme is weak. Don't use it unless you have | |
| 351 | + // to. See "Weak Cryptography" in the manual. This encryption format is deprecated in the | |
| 352 | + // PDF 2.0 specification. | |
| 421 | 353 | QPDF_DLL |
| 422 | 354 | void setR4EncryptionParametersInsecure( |
| 423 | 355 | char const* user_password, |
| ... | ... | @@ -431,9 +363,8 @@ class QPDFWriter |
| 431 | 363 | qpdf_r3_print_e print, |
| 432 | 364 | bool encrypt_metadata, |
| 433 | 365 | bool use_aes); |
| 434 | - // R5 is deprecated. Do not use it for production use. Writing | |
| 435 | - // R5 is supported by qpdf primarily to generate test files for | |
| 436 | - // applications that may need to test R5 support. | |
| 366 | + // R5 is deprecated. Do not use it for production use. Writing R5 is supported by qpdf | |
| 367 | + // primarily to generate test files for applications that may need to test R5 support. | |
| 437 | 368 | QPDF_DLL |
| 438 | 369 | void setR5EncryptionParameters( |
| 439 | 370 | char const* user_password, |
| ... | ... | @@ -446,8 +377,7 @@ class QPDFWriter |
| 446 | 377 | bool allow_modify_other, |
| 447 | 378 | qpdf_r3_print_e print, |
| 448 | 379 | bool encrypt_metadata); |
| 449 | - // This is the only password-based encryption format supported by | |
| 450 | - // the PDF specification. | |
| 380 | + // This is the only password-based encryption format supported by the PDF specification. | |
| 451 | 381 | QPDF_DLL |
| 452 | 382 | void setR6EncryptionParameters( |
| 453 | 383 | char const* user_password, |
| ... | ... | @@ -461,57 +391,49 @@ class QPDFWriter |
| 461 | 391 | qpdf_r3_print_e print, |
| 462 | 392 | bool encrypt_metadata_aes); |
| 463 | 393 | |
| 464 | - // Create linearized output. Disables qdf mode, content | |
| 465 | - // normalization, and stream prefiltering. | |
| 394 | + // Create linearized output. Disables qdf mode, content normalization, and stream prefiltering. | |
| 466 | 395 | QPDF_DLL |
| 467 | 396 | void setLinearization(bool); |
| 468 | 397 | |
| 469 | - // For debugging QPDF: provide the name of a file to write pass1 | |
| 470 | - // of linearization to. The only reason to use this is to debug | |
| 471 | - // QPDF. To linearize, QPDF writes out the file in two passes. | |
| 472 | - // Usually the first pass is discarded, but lots of computations | |
| 473 | - // are made in pass 1. If a linearized file comes out wrong, it | |
| 474 | - // can be helpful to look at the first pass. | |
| 398 | + // For debugging QPDF: provide the name of a file to write pass1 of linearization to. The only | |
| 399 | + // reason to use this is to debug QPDF. To linearize, QPDF writes out the file in two passes. | |
| 400 | + // Usually the first pass is discarded, but lots of computations are made in pass 1. If a | |
| 401 | + // linearized file comes out wrong, it can be helpful to look at the first pass. | |
| 475 | 402 | QPDF_DLL |
| 476 | 403 | void setLinearizationPass1Filename(std::string const&); |
| 477 | 404 | |
| 478 | - // Create PCLm output. This is only useful for clients that know | |
| 479 | - // how to create PCLm files. If a file is structured exactly as | |
| 480 | - // PCLm requires, this call will tell QPDFWriter to write the PCLm | |
| 481 | - // header, create certain unreferenced streams required by the | |
| 482 | - // standard, and write the objects in the required order. Calling | |
| 483 | - // this on an ordinary PDF serves no purpose. There is no | |
| 405 | + // Create PCLm output. This is only useful for clients that know how to create PCLm files. If a | |
| 406 | + // file is structured exactly as PCLm requires, this call will tell QPDFWriter to write the PCLm | |
| 407 | + // header, create certain unreferenced streams required by the standard, and write the objects | |
| 408 | + // in the required order. Calling this on an ordinary PDF serves no purpose. There is no | |
| 484 | 409 | // command-line argument that causes this method to be called. |
| 485 | 410 | QPDF_DLL |
| 486 | 411 | void setPCLm(bool); |
| 487 | 412 | |
| 488 | - // If you want to be notified of progress, derive a class from | |
| 489 | - // ProgressReporter and override the reportProgress method. | |
| 413 | + // If you want to be notified of progress, derive a class from ProgressReporter and override the | |
| 414 | + // reportProgress method. | |
| 490 | 415 | QPDF_DLL |
| 491 | 416 | void registerProgressReporter(std::shared_ptr<ProgressReporter>); |
| 492 | 417 | |
| 493 | - // Return the PDF version that will be written into the header. | |
| 494 | - // Calling this method does all the preparation for writing, so it | |
| 495 | - // is an error to call any methods that may cause a change to the | |
| 496 | - // version. Adding new objects to the original file after calling | |
| 497 | - // this may also cause problems. It is safe to update existing | |
| 498 | - // objects or stream contents after calling this method, e.g., to | |
| 418 | + // Return the PDF version that will be written into the header. Calling this method does all the | |
| 419 | + // preparation for writing, so it is an error to call any methods that may cause a change to the | |
| 420 | + // version. Adding new objects to the original file after calling this may also cause problems. | |
| 421 | + // It is safe to update existing objects or stream contents after calling this method, e.g., to | |
| 499 | 422 | // include the final version number in metadata. |
| 500 | 423 | QPDF_DLL |
| 501 | 424 | std::string getFinalVersion(); |
| 502 | 425 | |
| 503 | - // Write the final file. There is no expectation of being able to | |
| 504 | - // call write() more than once. | |
| 426 | + // Write the final file. There is no expectation of being able to call write() more than once. | |
| 505 | 427 | QPDF_DLL |
| 506 | 428 | void write(); |
| 507 | 429 | |
| 508 | - // Return renumbered ObjGen that was written into the final file. | |
| 509 | - // This method can be used after calling write(). | |
| 430 | + // Return renumbered ObjGen that was written into the final file. This method can be used after | |
| 431 | + // calling write(). | |
| 510 | 432 | QPDF_DLL |
| 511 | 433 | QPDFObjGen getRenumberedObjGen(QPDFObjGen); |
| 512 | 434 | |
| 513 | - // Return XRef entry that was written into the final file. | |
| 514 | - // This method can be used after calling write(). | |
| 435 | + // Return XRef entry that was written into the final file. This method can be used after calling | |
| 436 | + // write(). | |
| 515 | 437 | QPDF_DLL |
| 516 | 438 | std::map<QPDFObjGen, QPDFXRefEntry> getWrittenXRefTable(); |
| 517 | 439 | |
| ... | ... | @@ -525,15 +447,12 @@ class QPDFWriter |
| 525 | 447 | |
| 526 | 448 | enum trailer_e { t_normal, t_lin_first, t_lin_second }; |
| 527 | 449 | |
| 528 | - // An reference to a PipelinePopper instance is passed into | |
| 529 | - // activatePipelineStack. When the PipelinePopper goes out of | |
| 530 | - // scope, the pipeline stack is popped. PipelinePopper's | |
| 531 | - // destructor calls finish on the current pipeline and pops the | |
| 532 | - // pipeline stack until the top of stack is a previous active top | |
| 533 | - // of stack, and restores the pipeline to that point. It deletes | |
| 534 | - // any pipelines that it pops. If the bp argument is non-null and | |
| 535 | - // any of the stack items are of type Pl_Buffer, the buffer is | |
| 536 | - // retrieved. | |
| 450 | + // An reference to a PipelinePopper instance is passed into activatePipelineStack. When the | |
| 451 | + // PipelinePopper goes out of scope, the pipeline stack is popped. PipelinePopper's destructor | |
| 452 | + // calls finish on the current pipeline and pops the pipeline stack until the top of stack is a | |
| 453 | + // previous active top of stack, and restores the pipeline to that point. It deletes any | |
| 454 | + // pipelines that it pops. If the bp argument is non-null and any of the stack items are of type | |
| 455 | + // Pl_Buffer, the buffer is retrieved. | |
| 537 | 456 | class PipelinePopper |
| 538 | 457 | { |
| 539 | 458 | friend class QPDFWriter; |
| ... | ... | @@ -672,10 +591,9 @@ class QPDFWriter |
| 672 | 591 | int linearization_pass); |
| 673 | 592 | size_t calculateXrefStreamPadding(qpdf_offset_t xref_bytes); |
| 674 | 593 | |
| 675 | - // When filtering subsections, push additional pipelines to the | |
| 676 | - // stack. When ready to switch, activate the pipeline stack. When | |
| 677 | - // the passed in PipelinePopper goes out of scope, the stack is | |
| 678 | - // popped. | |
| 594 | + // When filtering subsections, push additional pipelines to the stack. When ready to switch, | |
| 595 | + // activate the pipeline stack. When the passed in PipelinePopper goes out of scope, the stack | |
| 596 | + // is popped. | |
| 679 | 597 | Pipeline* pushPipeline(Pipeline*); |
| 680 | 598 | void activatePipelineStack(PipelinePopper&); |
| 681 | 599 | void initializePipelineStack(Pipeline*); |
| ... | ... | @@ -779,9 +697,8 @@ class QPDFWriter |
| 779 | 697 | int next_progress_report{0}; |
| 780 | 698 | }; |
| 781 | 699 | |
| 782 | - // Keep all member variables inside the Members object, which we | |
| 783 | - // dynamically allocate. This makes it possible to add new private | |
| 784 | - // members without breaking binary compatibility. | |
| 700 | + // Keep all member variables inside the Members object, which we dynamically allocate. This | |
| 701 | + // makes it possible to add new private members without breaking binary compatibility. | |
| 785 | 702 | std::shared_ptr<Members> m; |
| 786 | 703 | }; |
| 787 | 704 | ... | ... |
include/qpdf/QPDFXRefEntry.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QPDFXREFENTRY_HH |
| 23 | 20 | #define QPDFXREFENTRY_HH |
| ... | ... | @@ -28,8 +25,7 @@ |
| 28 | 25 | class QPDFXRefEntry |
| 29 | 26 | { |
| 30 | 27 | public: |
| 31 | - // Type constants are from the PDF spec section | |
| 32 | - // "Cross-Reference Streams": | |
| 28 | + // Type constants are from the PDF spec section "Cross-Reference Streams": | |
| 33 | 29 | // 0 = free entry; not used |
| 34 | 30 | // 1 = "uncompressed"; field 1 = offset |
| 35 | 31 | // 2 = "compressed"; field 1 = object stream number, field 2 = index |
| ... | ... | @@ -65,8 +61,8 @@ class QPDFXRefEntry |
| 65 | 61 | int getObjStreamIndex() const; // only for type 2 |
| 66 | 62 | |
| 67 | 63 | private: |
| 68 | - // This class does not use the Members pattern to avoid a memory | |
| 69 | - // allocation for every one of these. A lot of these get created. | |
| 64 | + // This class does not use the Members pattern to avoid a memory allocation for every one of | |
| 65 | + // these. A lot of these get created. | |
| 70 | 66 | int type{0}; |
| 71 | 67 | qpdf_offset_t field1{0}; |
| 72 | 68 | int field2{0}; | ... | ... |
include/qpdf/QTC.hh
| ... | ... | @@ -2,33 +2,28 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QTC_HH |
| 23 | 20 | #define QTC_HH |
| 24 | 21 | |
| 25 | 22 | #include <qpdf/DLL.h> |
| 26 | 23 | |
| 27 | -// Defining QPDF_DISABLE_QTC will effectively compile out any QTC::TC | |
| 28 | -// calls in any code that includes this file, but QTC will still be | |
| 29 | -// built into the library. That way, it is possible to build and | |
| 30 | -// package qpdf with QPDF_DISABLE_QTC while still making QTC::TC | |
| 31 | -// available to end users. | |
| 24 | +// Defining QPDF_DISABLE_QTC will effectively compile out any QTC::TC calls in any code that | |
| 25 | +// includes this file, but QTC will still be built into the library. That way, it is possible to | |
| 26 | +// build and package qpdf with QPDF_DISABLE_QTC while still making QTC::TC available to end users. | |
| 32 | 27 | |
| 33 | 28 | namespace QTC |
| 34 | 29 | { | ... | ... |
include/qpdf/QUtil.hh
| ... | ... | @@ -2,22 +2,19 @@ |
| 2 | 2 | // |
| 3 | 3 | // This file is part of qpdf. |
| 4 | 4 | // |
| 5 | -// Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | -// you may not use this file except in compliance with the License. | |
| 7 | -// You may obtain a copy of the License at | |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | +// in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | // |
| 9 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | // |
| 11 | -// Unless required by applicable law or agreed to in writing, software | |
| 12 | -// distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | -// See the License for the specific language governing permissions and | |
| 15 | -// limitations under the License. | |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | +// or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | +// the License. | |
| 16 | 14 | // |
| 17 | -// Versions of qpdf prior to version 7 were released under the terms | |
| 18 | -// of version 2.0 of the Artistic License. At your option, you may | |
| 19 | -// continue to consider qpdf to be licensed under those terms. Please | |
| 20 | -// see the manual for additional information. | |
| 15 | +// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | +// License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | +// Please see the manual for additional information. | |
| 21 | 18 | |
| 22 | 19 | #ifndef QUTIL_HH |
| 23 | 20 | #define QUTIL_HH |
| ... | ... | @@ -40,8 +37,7 @@ class Pipeline; |
| 40 | 37 | |
| 41 | 38 | namespace QUtil |
| 42 | 39 | { |
| 43 | - // This is a collection of useful utility functions that don't | |
| 44 | - // really go anywhere else. | |
| 40 | + // This is a collection of useful utility functions that don't really go anywhere else. | |
| 45 | 41 | QPDF_DLL |
| 46 | 42 | std::string int_to_string(long long, int length = 0); |
| 47 | 43 | QPDF_DLL |
| ... | ... | @@ -53,8 +49,7 @@ namespace QUtil |
| 53 | 49 | QPDF_DLL |
| 54 | 50 | std::string double_to_string(double, int decimal_places = 0, bool trim_trailing_zeroes = true); |
| 55 | 51 | |
| 56 | - // These string to number methods throw std::runtime_error on | |
| 57 | - // underflow/overflow. | |
| 52 | + // These string to number methods throw std::runtime_error on underflow/overflow. | |
| 58 | 53 | QPDF_DLL |
| 59 | 54 | long long string_to_ll(char const* str); |
| 60 | 55 | QPDF_DLL |
| ... | ... | @@ -64,63 +59,53 @@ namespace QUtil |
| 64 | 59 | QPDF_DLL |
| 65 | 60 | unsigned int string_to_uint(char const* str); |
| 66 | 61 | |
| 67 | - // Returns true if this exactly represents a long long. The | |
| 68 | - // determination is made by converting the string to a long long, | |
| 69 | - // then converting the result back to a string, and then comparing | |
| 62 | + // Returns true if this exactly represents a long long. The determination is made by converting | |
| 63 | + // the string to a long long, then converting the result back to a string, and then comparing | |
| 70 | 64 | // that result with the original string. |
| 71 | 65 | QPDF_DLL |
| 72 | 66 | bool is_long_long(char const* str); |
| 73 | 67 | |
| 74 | - // Pipeline's write method wants unsigned char*, but we often have | |
| 75 | - // some other type of string. These methods do combinations of | |
| 76 | - // const_cast and reinterpret_cast to give us an unsigned char*. | |
| 77 | - // They should only be used when it is known that it is safe. | |
| 78 | - // None of the pipelines in qpdf modify the data passed to them, | |
| 79 | - // so within qpdf, it should always be safe. | |
| 68 | + // Pipeline's write method wants unsigned char*, but we often have some other type of string. | |
| 69 | + // These methods do combinations of const_cast and reinterpret_cast to give us an unsigned | |
| 70 | + // char*. They should only be used when it is known that it is safe. None of the pipelines in | |
| 71 | + // qpdf modify the data passed to them, so within qpdf, it should always be safe. | |
| 80 | 72 | QPDF_DLL |
| 81 | 73 | unsigned char* unsigned_char_pointer(std::string const& str); |
| 82 | 74 | QPDF_DLL |
| 83 | 75 | unsigned char* unsigned_char_pointer(char const* str); |
| 84 | 76 | |
| 85 | - // Throw QPDFSystemError, which is derived from | |
| 86 | - // std::runtime_error, with a string formed by appending to | |
| 87 | - // "description: " the standard string corresponding to the | |
| 88 | - // current value of errno. You can retrieve the value of errno by | |
| 89 | - // calling getErrno() on the QPDFSystemError. Prior to qpdf 8.2.0, | |
| 90 | - // this method threw system::runtime_error directly, but since | |
| 91 | - // QPDFSystemError is derived from system::runtime_error, old code | |
| 92 | - // that specifically catches std::runtime_error will still work. | |
| 77 | + // Throw QPDFSystemError, which is derived from std::runtime_error, with a string formed by | |
| 78 | + // appending to "description: " the standard string corresponding to the current value of errno. | |
| 79 | + // You can retrieve the value of errno by calling getErrno() on the QPDFSystemError. Prior to | |
| 80 | + // qpdf 8.2.0, this method threw system::runtime_error directly, but since QPDFSystemError is | |
| 81 | + // derived from system::runtime_error, old code that specifically catches std::runtime_error | |
| 82 | + // will still work. | |
| 93 | 83 | QPDF_DLL |
| 94 | 84 | void throw_system_error(std::string const& description); |
| 95 | 85 | |
| 96 | - // The status argument is assumed to be the return value of a | |
| 97 | - // standard library call that sets errno when it fails. If status | |
| 98 | - // is -1, convert the current value of errno to a | |
| 99 | - // std::runtime_error that includes the standard error string. | |
| 100 | - // Otherwise, return status. | |
| 86 | + // The status argument is assumed to be the return value of a standard library call that sets | |
| 87 | + // errno when it fails. If status is -1, convert the current value of errno to a | |
| 88 | + // std::runtime_error that includes the standard error string. Otherwise, return status. | |
| 101 | 89 | QPDF_DLL |
| 102 | 90 | int os_wrapper(std::string const& description, int status); |
| 103 | 91 | |
| 104 | - // If the open fails, throws std::runtime_error. Otherwise, the | |
| 105 | - // FILE* is returned. The filename should be UTF-8 encoded, even | |
| 106 | - // on Windows. It will be converted as needed on Windows. | |
| 92 | + // If the open fails, throws std::runtime_error. Otherwise, the FILE* is returned. The filename | |
| 93 | + // should be UTF-8 encoded, even on Windows. It will be converted as needed on Windows. | |
| 107 | 94 | QPDF_DLL |
| 108 | 95 | FILE* safe_fopen(char const* filename, char const* mode); |
| 109 | 96 | |
| 110 | - // The FILE* argument is assumed to be the return of fopen. If | |
| 111 | - // null, throw std::runtime_error. Otherwise, return the FILE* | |
| 112 | - // argument. | |
| 97 | + // The FILE* argument is assumed to be the return of fopen. If null, throw std::runtime_error. | |
| 98 | + // Otherwise, return the FILE* argument. | |
| 113 | 99 | QPDF_DLL |
| 114 | 100 | FILE* fopen_wrapper(std::string const&, FILE*); |
| 115 | 101 | |
| 116 | - // This is a little class to help with automatic closing files. | |
| 117 | - // You can do something like | |
| 102 | + // This is a little class to help with automatic closing files. You can do something like | |
| 118 | 103 | // |
| 119 | 104 | // QUtil::FileCloser fc(QUtil::safe_fopen(filename, "rb")); |
| 120 | 105 | // |
| 121 | - // and then use fc.f to the file. Be sure to actually declare a | |
| 122 | - // variable of type FileCloser. Using it as a temporary won't work | |
| 123 | - // because it will close the file as soon as it goes out of scope. | |
| 106 | + // and then use fc.f to the file. Be sure to actually declare a variable of type FileCloser. | |
| 107 | + // Using it as a temporary won't work because it will close the file as soon as it goes out of | |
| 108 | + // scope. | |
| 124 | 109 | class FileCloser |
| 125 | 110 | { |
| 126 | 111 | public: |
| ... | ... | @@ -160,28 +145,24 @@ namespace QUtil |
| 160 | 145 | QPDF_DLL |
| 161 | 146 | void rename_file(char const* oldname, char const* newname); |
| 162 | 147 | |
| 163 | - // Write the contents of filename as a binary file to the | |
| 164 | - // pipeline. | |
| 148 | + // Write the contents of filename as a binary file to the pipeline. | |
| 165 | 149 | QPDF_DLL |
| 166 | 150 | void pipe_file(char const* filename, Pipeline* p); |
| 167 | 151 | |
| 168 | - // Return a function that will send the contents of the given file | |
| 169 | - // through the given pipeline as binary data. | |
| 152 | + // Return a function that will send the contents of the given file through the given pipeline as | |
| 153 | + // binary data. | |
| 170 | 154 | QPDF_DLL |
| 171 | 155 | std::function<void(Pipeline*)> file_provider(std::string const& filename); |
| 172 | 156 | |
| 173 | - // Return the last path element. On Windows, either / or \ are | |
| 174 | - // path separators. Otherwise, only / is a path separator. Strip | |
| 175 | - // any trailing path separators. Then, if any path separators | |
| 176 | - // remain, return everything after the last path separator. | |
| 177 | - // Otherwise, return the whole string. As a special case, if a | |
| 178 | - // string consists entirely of path separators, the first | |
| 179 | - // character is returned. | |
| 157 | + // Return the last path element. On Windows, either / or \ are path separators. Otherwise, only | |
| 158 | + // / is a path separator. Strip any trailing path separators. Then, if any path separators | |
| 159 | + // remain, return everything after the last path separator. Otherwise, return the whole string. | |
| 160 | + // As a special case, if a string consists entirely of path separators, the first character is | |
| 161 | + // returned. | |
| 180 | 162 | QPDF_DLL |
| 181 | 163 | std::string path_basename(std::string const& filename); |
| 182 | 164 | |
| 183 | - // Returns a dynamically allocated copy of a string that the | |
| 184 | - // caller has to delete with delete[]. | |
| 165 | + // Returns a dynamically allocated copy of a string that the caller has to delete with delete[]. | |
| 185 | 166 | QPDF_DLL |
| 186 | 167 | char* copy_string(std::string const&); |
| 187 | 168 | |
| ... | ... | @@ -193,8 +174,7 @@ namespace QUtil |
| 193 | 174 | QPDF_DLL |
| 194 | 175 | std::unique_ptr<char[]> make_unique_cstr(std::string const&); |
| 195 | 176 | |
| 196 | - // Create a shared pointer to an array. From c++20, | |
| 197 | - // std::make_shared<T[]>(n) does this. | |
| 177 | + // Create a shared pointer to an array. From c++20, std::make_shared<T[]>(n) does this. | |
| 198 | 178 | template <typename T> |
| 199 | 179 | std::shared_ptr<T> |
| 200 | 180 | make_shared_array(size_t n) |
| ... | ... | @@ -202,27 +182,24 @@ namespace QUtil |
| 202 | 182 | return std::shared_ptr<T>(new T[n], std::default_delete<T[]>()); |
| 203 | 183 | } |
| 204 | 184 | |
| 205 | - // Returns lower-case hex-encoded version of the string, treating | |
| 206 | - // each character in the input string as unsigned. The output | |
| 207 | - // string will be twice as long as the input string. | |
| 185 | + // Returns lower-case hex-encoded version of the string, treating each character in the input | |
| 186 | + // string as unsigned. The output string will be twice as long as the input string. | |
| 208 | 187 | QPDF_DLL |
| 209 | 188 | std::string hex_encode(std::string const&); |
| 210 | 189 | |
| 211 | - // Returns lower-case hex-encoded version of the char including a leading | |
| 212 | - // "#". | |
| 190 | + // Returns lower-case hex-encoded version of the char including a leading "#". | |
| 213 | 191 | QPDF_DLL |
| 214 | 192 | inline std::string hex_encode_char(char); |
| 215 | 193 | |
| 216 | - // Returns a string that is the result of decoding the input | |
| 217 | - // string. The input string may consist of mixed case hexadecimal | |
| 218 | - // digits. Any characters that are not hexadecimal digits will be | |
| 219 | - // silently ignored. If there are an odd number of hexadecimal | |
| 220 | - // digits, a trailing 0 will be assumed. | |
| 194 | + // Returns a string that is the result of decoding the input string. The input string may | |
| 195 | + // consist of mixed case hexadecimal digits. Any characters that are not hexadecimal digits will | |
| 196 | + // be silently ignored. If there are an odd number of hexadecimal digits, a trailing 0 will be | |
| 197 | + // assumed. | |
| 221 | 198 | QPDF_DLL |
| 222 | 199 | std::string hex_decode(std::string const&); |
| 223 | 200 | |
| 224 | - // Decode a single hex digit into a char in the range 0 <= char < 16. Return | |
| 225 | - // a char >= 16 if digit is not a valid hex digit. | |
| 201 | + // Decode a single hex digit into a char in the range 0 <= char < 16. Return a char >= 16 if | |
| 202 | + // digit is not a valid hex digit. | |
| 226 | 203 | QPDF_DLL |
| 227 | 204 | inline constexpr char hex_decode_char(char digit) noexcept; |
| 228 | 205 | |
| ... | ... | @@ -239,17 +216,15 @@ namespace QUtil |
| 239 | 216 | QPDF_DLL |
| 240 | 217 | char* getWhoami(char* argv0); |
| 241 | 218 | |
| 242 | - // Get the value of an environment variable in a portable fashion. | |
| 243 | - // Returns true iff the variable is defined. If `value' is | |
| 244 | - // non-null, initializes it with the value of the variable. | |
| 219 | + // Get the value of an environment variable in a portable fashion. Returns true iff the variable | |
| 220 | + // is defined. If `value' is non-null, initializes it with the value of the variable. | |
| 245 | 221 | QPDF_DLL |
| 246 | 222 | bool get_env(std::string const& var, std::string* value = nullptr); |
| 247 | 223 | |
| 248 | 224 | QPDF_DLL |
| 249 | 225 | time_t get_current_time(); |
| 250 | 226 | |
| 251 | - // Portable structure representing a point in time with second | |
| 252 | - // granularity and time zone offset | |
| 227 | + // Portable structure representing a point in time with second granularity and time zone offset. | |
| 253 | 228 | struct QPDFTime |
| 254 | 229 | { |
| 255 | 230 | QPDFTime() = default; |
| ... | ... | @@ -277,12 +252,11 @@ namespace QUtil |
| 277 | 252 | QPDF_DLL |
| 278 | 253 | QPDFTime get_current_qpdf_time(); |
| 279 | 254 | |
| 280 | - // Convert a QPDFTime structure to a PDF timestamp string, which | |
| 281 | - // is "D:yyyymmddhhmmss<z>" where <z> is either "Z" for UTC or | |
| 282 | - // "-hh'mm'" or "+hh'mm'" for timezone offset. <z> may also be | |
| 283 | - // omitted. Examples: "D:20210207161528-05'00'", | |
| 284 | - // "D:20210207211528Z", "D:20210207211528". See | |
| 285 | - // get_current_qpdf_time and the QPDFTime structure above. | |
| 255 | + // Convert a QPDFTime structure to a PDF timestamp string, which is "D:yyyymmddhhmmss<z>" where | |
| 256 | + // <z> is either "Z" for UTC or "-hh'mm'" or "+hh'mm'" for timezone offset. <z> may also be | |
| 257 | + // omitted. | |
| 258 | + // Examples: "D:20210207161528-05'00'", "D:20210207211528Z", "D:20210207211528". | |
| 259 | + // See get_current_qpdf_time and the QPDFTime structure above. | |
| 286 | 260 | QPDF_DLL |
| 287 | 261 | std::string qpdf_time_to_pdf_time(QPDFTime const&); |
| 288 | 262 | |
| ... | ... | @@ -290,63 +264,53 @@ namespace QUtil |
| 290 | 264 | QPDF_DLL |
| 291 | 265 | std::string qpdf_time_to_iso8601(QPDFTime const&); |
| 292 | 266 | |
| 293 | - // Convert a PDF timestamp string to a QPDFTime. If syntactically | |
| 294 | - // valid, return true and fill in qtm. If not valid, return false, | |
| 295 | - // and do not modify qtm. If qtm is null, just check the validity | |
| 296 | - // of the string. | |
| 267 | + // Convert a PDF timestamp string to a QPDFTime. If syntactically valid, return true and fill in | |
| 268 | + // qtm. If not valid, return false, and do not modify qtm. If qtm is null, just check the | |
| 269 | + // validity of the string. | |
| 297 | 270 | QPDF_DLL |
| 298 | 271 | bool pdf_time_to_qpdf_time(std::string const&, QPDFTime* qtm = nullptr); |
| 299 | 272 | |
| 300 | - // Convert PDF timestamp to a second-granularity ISO-8601 | |
| 301 | - // timestamp. If syntactically valid, return true and initialize | |
| 302 | - // iso8601. Otherwise, return false. | |
| 273 | + // Convert PDF timestamp to a second-granularity ISO-8601 timestamp. If syntactically valid, | |
| 274 | + // return true and initialize iso8601. Otherwise, return false. | |
| 303 | 275 | bool pdf_time_to_iso8601(std::string const& pdf_time, std::string& iso8601); |
| 304 | 276 | |
| 305 | - // Return a string containing the byte representation of the UTF-8 | |
| 306 | - // encoding for the unicode value passed in. | |
| 277 | + // Return a string containing the byte representation of the UTF-8 encoding for the unicode | |
| 278 | + // value passed in. | |
| 307 | 279 | QPDF_DLL |
| 308 | 280 | std::string toUTF8(unsigned long uval); |
| 309 | 281 | |
| 310 | - // Return a string containing the byte representation of the | |
| 311 | - // UTF-16 big-endian encoding for the unicode value passed in. | |
| 312 | - // Unrepresentable code points are converted to U+FFFD. | |
| 282 | + // Return a string containing the byte representation of the UTF-16 big-endian encoding for the | |
| 283 | + // unicode value passed in. Unrepresentable code points are converted to U+FFFD. | |
| 313 | 284 | QPDF_DLL |
| 314 | 285 | std::string toUTF16(unsigned long uval); |
| 315 | 286 | |
| 316 | - // If utf8_val.at(pos) points to the beginning of a valid | |
| 317 | - // UTF-8-encoded character, return the codepoint of the character | |
| 318 | - // and set error to false. Otherwise, return 0xfffd and set error | |
| 319 | - // to true. In all cases, pos is advanced to the next position | |
| 320 | - // that may begin a valid character. When the string has been | |
| 321 | - // consumed, pos will be set to the string length. It is an error | |
| 322 | - // to pass a value of pos that is greater than or equal to the | |
| 323 | - // length of the string. | |
| 287 | + // If utf8_val.at(pos) points to the beginning of a valid UTF-8-encoded character, return the | |
| 288 | + // codepoint of the character and set error to false. Otherwise, return 0xfffd and set error to | |
| 289 | + // true. In all cases, pos is advanced to the next position that may begin a valid character. | |
| 290 | + // When the string has been consumed, pos will be set to the string length. It is an error to | |
| 291 | + // pass a value of pos that is greater than or equal to the length of the string. | |
| 324 | 292 | QPDF_DLL |
| 325 | 293 | unsigned long get_next_utf8_codepoint(std::string const& utf8_val, size_t& pos, bool& error); |
| 326 | 294 | |
| 327 | - // Test whether this is a UTF-16 string. This is indicated by | |
| 328 | - // first two bytes being 0xFE 0xFF (big-endian) or 0xFF 0xFE | |
| 329 | - // (little-endian), each of which is the encoding of U+FEFF, the | |
| 330 | - // Unicode marker. Starting in qpdf 10.6.2, this detects | |
| 331 | - // little-endian as well as big-endian. Even though the PDF spec | |
| 332 | - // doesn't allow little-endian, most readers seem to accept it. | |
| 295 | + // Test whether this is a UTF-16 string. This is indicated by first two bytes being 0xFE 0xFF | |
| 296 | + // (big-endian) or 0xFF 0xFE (little-endian), each of which is the encoding of U+FEFF, the | |
| 297 | + // Unicode marker. Starting in qpdf 10.6.2, this detects little-endian as well as big-endian. | |
| 298 | + // Even though the PDF spec doesn't allow little-endian, most readers seem to accept it. | |
| 333 | 299 | QPDF_DLL |
| 334 | 300 | bool is_utf16(std::string const&); |
| 335 | 301 | |
| 336 | - // Test whether this is an explicit UTF-8 string as allowed by the | |
| 337 | - // PDF 2.0 spec. This is indicated by first three bytes being 0xEF | |
| 338 | - // 0xBB 0xBF, which is the UTF-8 encoding of U+FEFF. | |
| 302 | + // Test whether this is an explicit UTF-8 string as allowed by the PDF 2.0 spec. This is | |
| 303 | + // indicated by first three bytes being 0xEF 0xBB 0xBF, which is the UTF-8 encoding of U+FEFF. | |
| 339 | 304 | QPDF_DLL |
| 340 | 305 | bool is_explicit_utf8(std::string const&); |
| 341 | 306 | |
| 342 | - // Convert a UTF-8 encoded string to UTF-16 big-endian. | |
| 343 | - // Unrepresentable code points are converted to U+FFFD. | |
| 307 | + // Convert a UTF-8 encoded string to UTF-16 big-endian. Unrepresentable code points are | |
| 308 | + // converted to U+FFFD. | |
| 344 | 309 | QPDF_DLL |
| 345 | 310 | std::string utf8_to_utf16(std::string const& utf8); |
| 346 | 311 | |
| 347 | - // Convert a UTF-8 encoded string to the specified single-byte | |
| 348 | - // encoding system by replacing all unsupported characters with | |
| 349 | - // the given unknown_char. | |
| 312 | + // Convert a UTF-8 encoded string to the specified single-byte encoding system by replacing all | |
| 313 | + // unsupported characters with the given unknown_char. | |
| 350 | 314 | QPDF_DLL |
| 351 | 315 | std::string utf8_to_ascii(std::string const& utf8, char unknown_char = '?'); |
| 352 | 316 | QPDF_DLL |
| ... | ... | @@ -356,9 +320,8 @@ namespace QUtil |
| 356 | 320 | QPDF_DLL |
| 357 | 321 | std::string utf8_to_pdf_doc(std::string const& utf8, char unknown_char = '?'); |
| 358 | 322 | |
| 359 | - // These versions return true if the conversion was successful and | |
| 360 | - // false if any unrepresentable characters were found and had to | |
| 361 | - // be substituted with the unknown character. | |
| 323 | + // These versions return true if the conversion was successful and false if any unrepresentable | |
| 324 | + // characters were found and had to be substituted with the unknown character. | |
| 362 | 325 | QPDF_DLL |
| 363 | 326 | bool utf8_to_ascii(std::string const& utf8, std::string& ascii, char unknown_char = '?'); |
| 364 | 327 | QPDF_DLL |
| ... | ... | @@ -373,9 +336,8 @@ namespace QUtil |
| 373 | 336 | QPDF_DLL |
| 374 | 337 | std::string utf16_to_utf8(std::string const& utf16); |
| 375 | 338 | |
| 376 | - // Convert from the specified single-byte encoding system to | |
| 377 | - // UTF-8. There is no ascii_to_utf8 because all ASCII strings are | |
| 378 | - // already valid UTF-8. | |
| 339 | + // Convert from the specified single-byte encoding system to UTF-8. There is no ascii_to_utf8 | |
| 340 | + // because all ASCII strings are already valid UTF-8. | |
| 379 | 341 | QPDF_DLL |
| 380 | 342 | std::string win_ansi_to_utf8(std::string const& win); |
| 381 | 343 | QPDF_DLL |
| ... | ... | @@ -383,39 +345,33 @@ namespace QUtil |
| 383 | 345 | QPDF_DLL |
| 384 | 346 | std::string pdf_doc_to_utf8(std::string const& pdfdoc); |
| 385 | 347 | |
| 386 | - // Analyze a string for encoding. We can't tell the difference | |
| 387 | - // between any single-byte encodings, and we can't tell for sure | |
| 388 | - // whether a string that happens to be valid UTF-8 isn't a | |
| 389 | - // different encoding, but we can at least tell a few things to | |
| 390 | - // help us guess. If there are no characters with the high bit | |
| 391 | - // set, has_8bit_chars is false, and the other values are also | |
| 392 | - // false, even though ASCII strings are valid UTF-8. is_valid_utf8 | |
| 393 | - // means that the string is non-trivially valid UTF-8. Although | |
| 394 | - // the PDF spec requires UTF-16 to be UTF-16BE, qpdf (and just | |
| 395 | - // about everything else) accepts UTF-16LE (as of 10.6.2). | |
| 348 | + // Analyze a string for encoding. We can't tell the difference between any single-byte | |
| 349 | + // encodings, and we can't tell for sure whether a string that happens to be valid UTF-8 isn't a | |
| 350 | + // different encoding, but we can at least tell a few things to help us guess. If there are no | |
| 351 | + // characters with the high bit set, has_8bit_chars is false, and the other values are also | |
| 352 | + // false, even though ASCII strings are valid UTF-8. is_valid_utf8 means that the string is | |
| 353 | + // non-trivially valid UTF-8. Although the PDF spec requires UTF-16 to be UTF-16BE, qpdf (and | |
| 354 | + // just about everything else) accepts UTF-16LE (as of 10.6.2). | |
| 396 | 355 | QPDF_DLL |
| 397 | 356 | void analyze_encoding( |
| 398 | 357 | std::string const& str, bool& has_8bit_chars, bool& is_valid_utf8, bool& is_utf16); |
| 399 | 358 | |
| 400 | - // Try to compensate for previously incorrectly encoded strings. | |
| 401 | - // We want to compensate for the following errors: | |
| 359 | + // Try to compensate for previously incorrectly encoded strings. We want to compensate for the | |
| 360 | + // following errors: | |
| 402 | 361 | // |
| 403 | - // * The string was supposed to be UTF-8 but was one of the | |
| 404 | - // single-byte encodings | |
| 405 | - // * The string was supposed to be PDF Doc but was either UTF-8 or | |
| 406 | - // one of the other single-byte encodings | |
| 362 | + // * The string was supposed to be UTF-8 but was one of the single-byte encodings | |
| 363 | + // * The string was supposed to be PDF Doc but was either UTF-8 or one of the other single-byte | |
| 364 | + // encodings | |
| 407 | 365 | // |
| 408 | - // The returned vector always contains the original string first, | |
| 409 | - // and then it contains what the correct string would be in the | |
| 410 | - // event that the original string was the result of any of the | |
| 366 | + // The returned vector always contains the original string first, and then it contains what the | |
| 367 | + // correct string would be in the event that the original string was the result of any of the | |
| 411 | 368 | // above errors. |
| 412 | 369 | // |
| 413 | - // This method is useful for attempting to recover a password that | |
| 414 | - // may have been previously incorrectly encoded. For example, the | |
| 415 | - // password was supposed to be UTF-8 but the previous application | |
| 416 | - // used a password encoded in WinAnsi, or if the previous password | |
| 417 | - // was supposed to be PDFDoc but was actually given as UTF-8 or | |
| 418 | - // WinAnsi, this method would find the correct password. | |
| 370 | + // This method is useful for attempting to recover a password that may have been previously | |
| 371 | + // incorrectly encoded. For example, the password was supposed to be UTF-8 but the previous | |
| 372 | + // application used a password encoded in WinAnsi, or if the previous password was supposed to | |
| 373 | + // be PDFDoc but was actually given as UTF-8 or WinAnsi, this method would find the correct | |
| 374 | + // password. | |
| 419 | 375 | QPDF_DLL |
| 420 | 376 | std::vector<std::string> possible_repaired_encodings(std::string); |
| 421 | 377 | |
| ... | ... | @@ -427,30 +383,25 @@ namespace QUtil |
| 427 | 383 | QPDF_DLL |
| 428 | 384 | void initializeWithRandomBytes(unsigned char* data, size_t len); |
| 429 | 385 | |
| 430 | - // Supply a random data provider. Starting in qpdf 10.0.0, qpdf | |
| 431 | - // uses the crypto provider as its source of random numbers. If | |
| 432 | - // you are using the native crypto provider, then qpdf will either | |
| 433 | - // use the operating system's secure random number source or, only | |
| 434 | - // if enabled at build time, an insecure random source from | |
| 435 | - // stdlib. The caller is responsible for managing the memory for | |
| 436 | - // the RandomDataProvider. This method modifies a static variable. | |
| 437 | - // If you are providing your own random data provider, you should | |
| 438 | - // call this at the beginning of your program before creating any | |
| 439 | - // QPDF objects. Passing a null to this method will reset the | |
| 440 | - // library back to its default random data provider. | |
| 386 | + // Supply a random data provider. Starting in qpdf 10.0.0, qpdf uses the crypto provider as its | |
| 387 | + // source of random numbers. If you are using the native crypto provider, then qpdf will either | |
| 388 | + // use the operating system's secure random number source or, only if enabled at build time, an | |
| 389 | + // insecure random source from stdlib. The caller is responsible for managing the memory for the | |
| 390 | + // RandomDataProvider. This method modifies a static variable. If you are providing your own | |
| 391 | + // random data provider, you should call this at the beginning of your program before creating | |
| 392 | + // any QPDF objects. Passing a null to this method will reset the library back to its default | |
| 393 | + // random data provider. | |
| 441 | 394 | QPDF_DLL |
| 442 | 395 | void setRandomDataProvider(RandomDataProvider*); |
| 443 | 396 | |
| 444 | - // This returns the random data provider that would be used the | |
| 445 | - // next time qpdf needs random data. It will never return null. | |
| 446 | - // If no random data provider has been provided and the library | |
| 447 | - // was not compiled with any random data provider available, an | |
| 448 | - // exception will be thrown. | |
| 397 | + // This returns the random data provider that would be used the next time qpdf needs random | |
| 398 | + // data. It will never return null. If no random data provider has been provided and the | |
| 399 | + // library was not compiled with any random data provider available, an exception will be | |
| 400 | + // thrown. | |
| 449 | 401 | QPDF_DLL |
| 450 | 402 | RandomDataProvider* getRandomDataProvider(); |
| 451 | 403 | |
| 452 | - // Filename is UTF-8 encoded, even on Windows, as described in the | |
| 453 | - // comments for safe_fopen. | |
| 404 | + // Filename is UTF-8 encoded, even on Windows, as described in the comments for safe_fopen. | |
| 454 | 405 | QPDF_DLL |
| 455 | 406 | std::list<std::string> read_lines_from_file(char const* filename, bool preserve_eol = false); |
| 456 | 407 | QPDF_DLL |
| ... | ... | @@ -471,15 +422,13 @@ namespace QUtil |
| 471 | 422 | QPDF_DLL |
| 472 | 423 | std::string read_file_into_string(FILE* f, std::string_view filename = ""); |
| 473 | 424 | |
| 474 | - // This used to be called strcasecmp, but that is a macro on some | |
| 475 | - // platforms, so we have to give it a name that is not likely to | |
| 476 | - // be a macro anywhere. | |
| 425 | + // This used to be called strcasecmp, but that is a macro on some platforms, so we have to give | |
| 426 | + // it a name that is not likely to be a macro anywhere. | |
| 477 | 427 | QPDF_DLL |
| 478 | 428 | int str_compare_nocase(char const*, char const*); |
| 479 | 429 | |
| 480 | - // These routines help the tokenizer recognize certain character | |
| 481 | - // classes without using ctype, which we avoid because of locale | |
| 482 | - // considerations. | |
| 430 | + // These routines help the tokenizer recognize certain character classes without using ctype, | |
| 431 | + // which we avoid because of locale considerations. | |
| 483 | 432 | QPDF_DLL |
| 484 | 433 | inline bool is_hex_digit(char); |
| 485 | 434 | |
| ... | ... | @@ -492,21 +441,19 @@ namespace QUtil |
| 492 | 441 | QPDF_DLL |
| 493 | 442 | inline bool is_number(char const*); |
| 494 | 443 | |
| 495 | - // This method parses the numeric range syntax used by the qpdf | |
| 496 | - // command-line tool. May throw std::runtime_error. | |
| 444 | + // This method parses the numeric range syntax used by the qpdf command-line tool. May throw | |
| 445 | + // std::runtime_error. | |
| 497 | 446 | QPDF_DLL |
| 498 | 447 | std::vector<int> parse_numrange(char const* range, int max); |
| 499 | 448 | |
| 500 | 449 | #ifndef QPDF_NO_WCHAR_T |
| 501 | - // If you are building qpdf on a stripped down system that doesn't | |
| 502 | - // have wchar_t, such as may be the case in some embedded | |
| 503 | - // environments, you may define QPDF_NO_WCHAR_T in your build. | |
| 504 | - // This symbol is never defined automatically. Search for wchar_t | |
| 505 | - // in qpdf's top-level README.md file for details. | |
| 450 | + // If you are building qpdf on a stripped down system that doesn't have wchar_t, such as may be | |
| 451 | + // the case in some embedded environments, you may define QPDF_NO_WCHAR_T in your build. This | |
| 452 | + // symbol is never defined automatically. Search for wchar_t in qpdf's top-level README.md file | |
| 453 | + // for details. | |
| 506 | 454 | |
| 507 | - // Take an argv array consisting of wchar_t, as when wmain is | |
| 508 | - // invoked, convert all UTF-16 encoded strings to UTF-8, and call | |
| 509 | - // another main. | |
| 455 | + // Take an argv array consisting of wchar_t, as when wmain is invoked, convert all UTF-16 | |
| 456 | + // encoded strings to UTF-8, and call another main. | |
| 510 | 457 | QPDF_DLL |
| 511 | 458 | int call_main_from_wmain(int argc, wchar_t* argv[], std::function<int(int, char*[])> realmain); |
| 512 | 459 | QPDF_DLL |
| ... | ... | @@ -516,13 +463,10 @@ namespace QUtil |
| 516 | 463 | std::function<int(int, char const* const[])> realmain); |
| 517 | 464 | #endif // QPDF_NO_WCHAR_T |
| 518 | 465 | |
| 519 | - // Try to return the maximum amount of memory allocated by the | |
| 520 | - // current process and its threads. Return 0 if unable to | |
| 521 | - // determine. This is Linux-specific and not implemented to be | |
| 522 | - // completely reliable. It is used during development for | |
| 523 | - // performance testing to detect changes that may significantly | |
| 524 | - // change memory usage. It is not recommended for use for other | |
| 525 | - // purposes. | |
| 466 | + // Try to return the maximum amount of memory allocated by the current process and its threads. | |
| 467 | + // Return 0 if unable to determine. This is Linux-specific and not implemented to be completely | |
| 468 | + // reliable. It is used during development for performance testing to detect changes that may | |
| 469 | + // significantly change memory usage. It is not recommended for use for other purposes. | |
| 526 | 470 | QPDF_DLL |
| 527 | 471 | size_t get_max_memory_usage(); |
| 528 | 472 | }; // namespace QUtil | ... | ... |
include/qpdf/qpdf-c.h
| ... | ... | @@ -2,138 +2,113 @@ |
| 2 | 2 | * |
| 3 | 3 | * This file is part of qpdf. |
| 4 | 4 | * |
| 5 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | - * you may not use this file except in compliance with the License. | |
| 7 | - * You may obtain a copy of the License at | |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | + * in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | * |
| 9 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | * |
| 11 | - * Unless required by applicable law or agreed to in writing, software | |
| 12 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | - * See the License for the specific language governing permissions and | |
| 15 | - * limitations under the License. | |
| 10 | + * Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | + * or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | + * the License. | |
| 16 | 14 | * |
| 17 | - * Versions of qpdf prior to version 7 were released under the terms | |
| 18 | - * of version 2.0 of the Artistic License. At your option, you may | |
| 19 | - * continue to consider qpdf to be licensed under those terms. Please | |
| 20 | - * see the manual for additional information. | |
| 15 | + * Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | + * License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | + * Please see the manual for additional information. | |
| 21 | 18 | */ |
| 22 | 19 | |
| 23 | 20 | #ifndef QPDF_C_H |
| 24 | 21 | #define QPDF_C_H |
| 25 | 22 | |
| 26 | 23 | /* |
| 27 | - * This file defines a basic "C" API for qpdf. It provides access to | |
| 28 | - * a subset of the QPDF library's capabilities to make them accessible | |
| 29 | - * to callers who can't handle calling C++ functions or working with | |
| 30 | - * C++ classes. This may be especially useful to Windows users who | |
| 31 | - * are accessing the qpdf DLL directly or to other people programming | |
| 32 | - * in non-C/C++ languages that can call C code but not C++ code. | |
| 24 | + * This file defines a basic "C" API for qpdf. It provides access to a subset of the QPDF library's | |
| 25 | + * capabilities to make them accessible to callers who can't handle calling C++ functions or working | |
| 26 | + * with C++ classes. This may be especially useful to Windows users who are accessing the qpdf DLL | |
| 27 | + * directly or to other people programming in non-C/C++ languages that can call C code but not C++ | |
| 28 | + * code. | |
| 33 | 29 | * |
| 34 | 30 | * There are several things to keep in mind when using the C API. |
| 35 | 31 | * |
| 36 | - * Error handling is tricky because the underlying C++ API uses | |
| 37 | - * exception handling. See "ERROR HANDLING" below for a detailed | |
| 38 | - * explanation. | |
| 32 | + * Error handling is tricky because the underlying C++ API uses exception handling. See "ERROR | |
| 33 | + * HANDLING" below for a detailed explanation. | |
| 39 | 34 | * |
| 40 | - * The C API is not as rich as the C++ API. For any operations | |
| 41 | - * that involve actually manipulating PDF objects, you must use | |
| 42 | - * the C++ API. The C API is primarily useful for doing basic | |
| 43 | - * transformations on PDF files similar to what you might do with | |
| 44 | - * the qpdf command-line tool. | |
| 35 | + * The C API is not as rich as the C++ API. For any operations that involve actually | |
| 36 | + * manipulating PDF objects, you must use the C++ API. The C API is primarily useful for doing | |
| 37 | + * basic transformations on PDF files similar to what you might do with the qpdf command-line | |
| 38 | + * tool. | |
| 45 | 39 | * |
| 46 | - * These functions store their state in a qpdf_data object. | |
| 47 | - * Individual instances of qpdf_data are not thread-safe: although | |
| 48 | - * you may access different qpdf_data objects from different | |
| 49 | - * threads, you may not access one qpdf_data simultaneously from | |
| 50 | - * multiple threads. | |
| 40 | + * These functions store their state in a qpdf_data object. Individual instances of qpdf_data | |
| 41 | + * are not thread-safe: although you may access different qpdf_data objects from different | |
| 42 | + * threads, you may not access one qpdf_data simultaneously from multiple threads. | |
| 51 | 43 | * |
| 52 | - * All dynamic memory, except for that of the qpdf_data object | |
| 53 | - * itself, is managed by the library unless otherwise noted. You | |
| 54 | - * must create a qpdf_data object using qpdf_init and free it | |
| 55 | - * using qpdf_cleanup. | |
| 44 | + * All dynamic memory, except for that of the qpdf_data object itself, is managed by the library | |
| 45 | + * unless otherwise noted. You must create a qpdf_data object using qpdf_init and free it using | |
| 46 | + * qpdf_cleanup. | |
| 56 | 47 | * |
| 57 | - * Many functions return char*. In all cases, the char* values | |
| 58 | - * returned are pointers to data inside the qpdf_data object. As | |
| 59 | - * such, they are always freed by qpdf_cleanup. In most cases, | |
| 60 | - * strings returned by functions here may be invalidated by | |
| 61 | - * subsequent function calls, sometimes even to different | |
| 62 | - * functions. If you want a string to last past the next qpdf call | |
| 63 | - * or after a call to qpdf_cleanup, you should make a copy of it. | |
| 48 | + * Many functions return char*. In all cases, the char* values returned are pointers to data | |
| 49 | + * inside the qpdf_data object. As such, they are always freed by qpdf_cleanup. In most cases, | |
| 50 | + * strings returned by functions here may be invalidated by subsequent function calls, sometimes | |
| 51 | + * even to different functions. If you want a string to last past the next qpdf call or after a | |
| 52 | + * call to qpdf_cleanup, you should make a copy of it. | |
| 64 | 53 | * |
| 65 | - * Since it is possible for a PDF string to contain null | |
| 66 | - * characters, a function that returns data originating from a PDF | |
| 67 | - * string may also contain null characters. To handle that case, | |
| 68 | - * you call qpdf_get_last_string_length() to get the length of | |
| 69 | - * whatever string was just returned. See STRING FUNCTIONS below. | |
| 54 | + * Since it is possible for a PDF string to contain null characters, a function that returns | |
| 55 | + * data originating from a PDF string may also contain null characters. To handle that case, you | |
| 56 | + * call qpdf_get_last_string_length() to get the length of whatever string was just returned. | |
| 57 | + * See STRING FUNCTIONS below. | |
| 70 | 58 | * |
| 71 | - * Most functions defined here have obvious counterparts that are | |
| 72 | - * methods to either QPDF or QPDFWriter. Please see comments in | |
| 73 | - * QPDF.hh and QPDFWriter.hh for details on their use. In order | |
| 74 | - * to avoid duplication of information, comments here focus | |
| 75 | - * primarily on differences between the C and C++ API. | |
| 59 | + * Most functions defined here have obvious counterparts that are methods to either QPDF or | |
| 60 | + * QPDFWriter. Please see comments in QPDF.hh and QPDFWriter.hh for details on their use. In | |
| 61 | + * order to avoid duplication of information, comments here focus primarily on differences | |
| 62 | + * between the C and C++ API. | |
| 76 | 63 | */ |
| 77 | 64 | |
| 78 | 65 | /* ERROR HANDLING -- changed in qpdf 10.5 */ |
| 79 | 66 | |
| 80 | -/* SUMMARY: The only way to know whether a function that does not | |
| 81 | - * return an error code has encountered an error is to call | |
| 82 | - * qpdf_has_error after each function. You can do this even for | |
| 83 | - * functions that do return error codes. You can also call | |
| 84 | - * qpdf_silence_errors to prevent qpdf from writing these errors to | |
| 85 | - * stderr. | |
| 67 | +/* SUMMARY: The only way to know whether a function that does not return an error code has | |
| 68 | + * encountered an error is to call qpdf_has_error after each function. You can do this even for | |
| 69 | + * functions that do return error codes. You can also call qpdf_silence_errors to prevent qpdf from | |
| 70 | + * writing these errors to stderr. | |
| 86 | 71 | * |
| 87 | 72 | * DETAILS: |
| 88 | 73 | * |
| 89 | - * The data type underlying qpdf_data maintains a list of warnings and | |
| 90 | - * a single error. To retrieve warnings, call qpdf_next_warning while | |
| 91 | - * qpdf_more_warnings is true. To retrieve the error, call | |
| 74 | + * The data type underlying qpdf_data maintains a list of warnings and a single error. To retrieve | |
| 75 | + * warnings, call qpdf_next_warning while qpdf_more_warnings is true. To retrieve the error, call | |
| 92 | 76 | * qpdf_get_error when qpdf_has_error is true. |
| 93 | 77 | * |
| 94 | 78 | * There are several things that are important to understand. |
| 95 | 79 | * |
| 96 | - * Some functions return an error code. The value of the error code is | |
| 97 | - * made up of a bitwise-OR of QPDF_WARNINGS and QPDF_ERRORS. The | |
| 98 | - * QPDF_ERRORS bit is set if there was an error during the *most | |
| 99 | - * recent call* to the API. The QPDF_WARNINGS bit is set if there are | |
| 100 | - * any warnings that have not yet been retrieved by calling | |
| 101 | - * qpdf_more_warnings. It is possible for both its or neither bit to | |
| 102 | - * be set. | |
| 80 | + * Some functions return an error code. The value of the error code is made up of a bitwise-OR of | |
| 81 | + * QPDF_WARNINGS and QPDF_ERRORS. The QPDF_ERRORS bit is set if there was an error during the *most | |
| 82 | + * recent call* to the API. The QPDF_WARNINGS bit is set if there are any warnings that have not yet | |
| 83 | + * been retrieved by calling qpdf_more_warnings. It is possible for both its or neither bit to be | |
| 84 | + * set. | |
| 103 | 85 | * |
| 104 | - * The expected mode of operation is to go through a series of | |
| 105 | - * operations, checking for errors after each call, but only checking | |
| 106 | - * for warnings at the end. This is similar to how it works in the C++ | |
| 107 | - * API where warnings are handled in exactly this way but errors | |
| 108 | - * result in exceptions being thrown. However, in both the C and C++ | |
| 109 | - * API, it is possible to check for and handle warnings as they arise. | |
| 86 | + * The expected mode of operation is to go through a series of operations, checking for errors after | |
| 87 | + * each call, but only checking for warnings at the end. This is similar to how it works in the C++ | |
| 88 | + * API where warnings are handled in exactly this way but errors result in exceptions being thrown. | |
| 89 | + * However, in both the C and C++ API, it is possible to check for and handle warnings as they | |
| 90 | + * arise. | |
| 110 | 91 | * |
| 111 | - * Some functions return values (or void) rather than an error code. | |
| 112 | - * This is especially true with the object handling functions. Those | |
| 113 | - * functions can still generate errors. To handle errors in those | |
| 114 | - * cases, you should explicitly call qpdf_has_error(). Note that, if | |
| 115 | - * you want to avoid the inconsistencies in the interface, you can | |
| 116 | - * always check for error conditions in this way rather than looking | |
| 117 | - * at status return codes. | |
| 92 | + * Some functions return values (or void) rather than an error code. This is especially true with | |
| 93 | + * the object handling functions. Those functions can still generate errors. To handle errors in | |
| 94 | + * those cases, you should explicitly call qpdf_has_error(). Note that, if you want to avoid the | |
| 95 | + * inconsistencies in the interface, you can always check for error conditions in this way rather | |
| 96 | + * than looking at status return codes. | |
| 118 | 97 | * |
| 119 | - * Prior to qpdf 10.5, if one of the functions that does not return an | |
| 120 | - * error code encountered an exception, it would cause the entire | |
| 121 | - * program to crash. Starting in qpdf 10.5, the default response to an | |
| 122 | - * error condition in these situations is to print the error to | |
| 123 | - * standard error, issue exactly one warning indicating that such an | |
| 124 | - * error occurred, and return a sensible fallback value (0 for | |
| 125 | - * numbers, QPDF_FALSE for booleans, "" for strings, or a null or | |
| 126 | - * uninitialized object handle). This is better than the old behavior | |
| 127 | - * but still undesirable as the best option is to explicitly check for | |
| 128 | - * error conditions. | |
| 98 | + * Prior to qpdf 10.5, if one of the functions that does not return an error code encountered an | |
| 99 | + * exception, it would cause the entire program to crash. Starting in qpdf 10.5, the default | |
| 100 | + * response to an error condition in these situations is to print the error to standard error, issue | |
| 101 | + * exactly one warning indicating that such an error occurred, and return a sensible fallback value | |
| 102 | + * (0 for numbers, QPDF_FALSE for booleans, "" for strings, or a null or uninitialized object | |
| 103 | + * handle). This is better than the old behavior but still undesirable as the best option is to | |
| 104 | + * explicitly check for error conditions. | |
| 129 | 105 | * |
| 130 | - * To prevent qpdf from writing error messages to stderr in this way, | |
| 131 | - * you can call qpdf_silence_errors(). This signals to the qpdf | |
| 132 | - * library that you intend to check the error codes yourself. | |
| 106 | + * To prevent qpdf from writing error messages to stderr in this way, you can call | |
| 107 | + * qpdf_silence_errors(). This signals to the qpdf library that you intend to check the error codes | |
| 108 | + * yourself. | |
| 133 | 109 | * |
| 134 | - * If you encounter a situation where an exception from the C++ code | |
| 135 | - * is not properly converted to an error as described above, it is a | |
| 136 | - * bug in qpdf, which should be reported at | |
| 110 | + * If you encounter a situation where an exception from the C++ code is not properly converted to an | |
| 111 | + * error as described above, it is a bug in qpdf, which should be reported at | |
| 137 | 112 | * https://github.com/qpdf/qpdf/issues/new. |
| 138 | 113 | */ |
| 139 | 114 | |
| ... | ... | @@ -150,9 +125,8 @@ extern "C" { |
| 150 | 125 | typedef struct _qpdf_data* qpdf_data; |
| 151 | 126 | typedef struct _qpdf_error* qpdf_error; |
| 152 | 127 | |
| 153 | - /* Many functions return an integer error code. Codes are defined | |
| 154 | - * below. See comments at the top of the file for details. Note | |
| 155 | - * that the values below can be logically orred together. | |
| 128 | + /* Many functions return an integer error code. Codes are defined below. See comments at the | |
| 129 | + * top of the file for details. Note that the values below can be logically orred together. | |
| 156 | 130 | */ |
| 157 | 131 | typedef int QPDF_ERROR_CODE; |
| 158 | 132 | #define QPDF_SUCCESS 0 |
| ... | ... | @@ -163,76 +137,68 @@ extern "C" { |
| 163 | 137 | #define QPDF_TRUE 1 |
| 164 | 138 | #define QPDF_FALSE 0 |
| 165 | 139 | |
| 166 | - /* From qpdf 10.5: call this method to signal to the library that | |
| 167 | - * you are explicitly handling errors from functions that don't | |
| 168 | - * return error codes. Otherwise, the library will print these | |
| 169 | - * error conditions to stderr and issue a warning. Prior to 10.5, | |
| 170 | - * the program would have crashed from an unhandled exception. | |
| 140 | + /* From qpdf 10.5: call this method to signal to the library that you are explicitly handling | |
| 141 | + * errors from functions that don't return error codes. Otherwise, the library will print these | |
| 142 | + * error conditions to stderr and issue a warning. Prior to 10.5, the program would have | |
| 143 | + * crashed from an unhandled exception. | |
| 171 | 144 | */ |
| 172 | 145 | QPDF_DLL |
| 173 | 146 | void qpdf_silence_errors(qpdf_data qpdf); |
| 174 | 147 | |
| 175 | - /* Returns the version of the qpdf software. This is guaranteed to | |
| 176 | - * be a static value. | |
| 148 | + /* Returns the version of the qpdf software. This is guaranteed to be a static value. | |
| 177 | 149 | */ |
| 178 | 150 | QPDF_DLL |
| 179 | 151 | char const* qpdf_get_qpdf_version(); |
| 180 | 152 | |
| 181 | - /* Returns dynamically allocated qpdf_data pointer; must be freed | |
| 182 | - * by calling qpdf_cleanup. You must call qpdf_read, one of the | |
| 183 | - * other qpdf_read_* functions, or qpdf_empty_pdf before calling | |
| 153 | + /* Returns dynamically allocated qpdf_data pointer; must be freed by calling qpdf_cleanup. You | |
| 154 | + * must call qpdf_read, one of the other qpdf_read_* functions, or qpdf_empty_pdf before calling | |
| 184 | 155 | * any function that would need to operate on the PDF file. |
| 185 | 156 | */ |
| 186 | 157 | QPDF_DLL |
| 187 | 158 | qpdf_data qpdf_init(); |
| 188 | 159 | |
| 189 | - /* Pass a pointer to the qpdf_data pointer created by qpdf_init to | |
| 190 | - * clean up resources. This does not include buffers initialized | |
| 191 | - * by functions that return stream data but it otherwise includes | |
| 192 | - * all data associated with the QPDF object or any object handles. | |
| 160 | + /* Pass a pointer to the qpdf_data pointer created by qpdf_init to clean up resources. This does | |
| 161 | + * not include buffers initialized by functions that return stream data but it otherwise | |
| 162 | + * includes all data associated with the QPDF object or any object handles. | |
| 193 | 163 | */ |
| 194 | 164 | QPDF_DLL |
| 195 | 165 | void qpdf_cleanup(qpdf_data* qpdf); |
| 196 | 166 | |
| 197 | 167 | /* ERROR REPORTING */ |
| 198 | 168 | |
| 199 | - /* Returns 1 if there is an error condition. The error condition | |
| 200 | - * can be retrieved by a single call to qpdf_get_error. | |
| 169 | + /* Returns 1 if there is an error condition. The error condition can be retrieved by a single | |
| 170 | + * call to qpdf_get_error. | |
| 201 | 171 | */ |
| 202 | 172 | QPDF_DLL |
| 203 | 173 | QPDF_BOOL qpdf_has_error(qpdf_data qpdf); |
| 204 | 174 | |
| 205 | - /* Returns the error condition, if any. The return value is a | |
| 206 | - * pointer to data that will become invalid after the next call to | |
| 207 | - * this function, qpdf_next_warning, or qpdf_cleanup. After this | |
| 208 | - * function is called, qpdf_has_error will return QPDF_FALSE until | |
| 209 | - * the next error condition occurs. If there is no error | |
| 210 | - * condition, this function returns a null pointer. | |
| 175 | + /* Returns the error condition, if any. The return value is a pointer to data that will become | |
| 176 | + * invalid after the next call to this function, qpdf_next_warning, or qpdf_cleanup. After this | |
| 177 | + * function is called, qpdf_has_error will return QPDF_FALSE until the next error condition | |
| 178 | + * occurs. If there is no error condition, this function returns a null pointer. | |
| 211 | 179 | */ |
| 212 | 180 | QPDF_DLL |
| 213 | 181 | qpdf_error qpdf_get_error(qpdf_data qpdf); |
| 214 | 182 | |
| 215 | - /* Returns 1 if there are any unretrieved warnings, and zero | |
| 216 | - * otherwise. | |
| 183 | + /* Returns 1 if there are any unretrieved warnings, and zero otherwise. | |
| 217 | 184 | */ |
| 218 | 185 | QPDF_DLL |
| 219 | 186 | QPDF_BOOL qpdf_more_warnings(qpdf_data qpdf); |
| 220 | 187 | |
| 221 | - /* If there are any warnings, returns a pointer to the next | |
| 222 | - * warning. Otherwise returns a null pointer. | |
| 188 | + /* If there are any warnings, returns a pointer to the next warning. Otherwise returns a null | |
| 189 | + * pointer. | |
| 223 | 190 | */ |
| 224 | 191 | QPDF_DLL |
| 225 | 192 | qpdf_error qpdf_next_warning(qpdf_data qpdf); |
| 226 | 193 | |
| 227 | 194 | /* Extract fields of the error. */ |
| 228 | 195 | |
| 229 | - /* Use this function to get a full error message suitable for | |
| 230 | - * showing to the user. */ | |
| 196 | + /* Use this function to get a full error message suitable for showing to the user. */ | |
| 231 | 197 | QPDF_DLL |
| 232 | 198 | char const* qpdf_get_error_full_text(qpdf_data q, qpdf_error e); |
| 233 | 199 | |
| 234 | - /* Use these functions to extract individual fields from the | |
| 235 | - * error; see QPDFExc.hh for details. */ | |
| 200 | + /* Use these functions to extract individual fields from the error; see QPDFExc.hh for details. | |
| 201 | + */ | |
| 236 | 202 | QPDF_DLL |
| 237 | 203 | enum qpdf_error_code_e qpdf_get_error_code(qpdf_data q, qpdf_error e); |
| 238 | 204 | QPDF_DLL |
| ... | ... | @@ -242,9 +208,8 @@ extern "C" { |
| 242 | 208 | QPDF_DLL |
| 243 | 209 | char const* qpdf_get_error_message_detail(qpdf_data q, qpdf_error e); |
| 244 | 210 | |
| 245 | - /* By default, warnings are written to stderr. Passing true to | |
| 246 | - * this function will prevent warnings from being written to | |
| 247 | - * stderr. They will still be available by calls to | |
| 211 | + /* By default, warnings are written to stderr. Passing true to this function will prevent | |
| 212 | + * warnings from being written to stderr. They will still be available by calls to | |
| 248 | 213 | * qpdf_next_warning. |
| 249 | 214 | */ |
| 250 | 215 | QPDF_DLL |
| ... | ... | @@ -252,11 +217,9 @@ extern "C" { |
| 252 | 217 | |
| 253 | 218 | /* LOG FUNCTIONS */ |
| 254 | 219 | |
| 255 | - /* Set or get the current logger. You need to call | |
| 256 | - * qpdflogger_cleanup on the logger handles when you are done with | |
| 257 | - * the handles. The underlying logger is cleaned up automatically | |
| 258 | - * and persists if needed after the logger handle is destroyed. | |
| 259 | - * See comments in qpdflogger-c.h for details. | |
| 220 | + /* Set or get the current logger. You need to call qpdflogger_cleanup on the logger handles when | |
| 221 | + * you are done with the handles. The underlying logger is cleaned up automatically and persists | |
| 222 | + * if needed after the logger handle is destroyed. See comments in qpdflogger-c.h for details. | |
| 260 | 223 | */ |
| 261 | 224 | |
| 262 | 225 | QPDF_DLL |
| ... | ... | @@ -266,8 +229,7 @@ extern "C" { |
| 266 | 229 | |
| 267 | 230 | /* CHECK FUNCTIONS */ |
| 268 | 231 | |
| 269 | - /* Attempt to read the entire PDF file to see if there are any | |
| 270 | - * errors qpdf can detect. | |
| 232 | + /* Attempt to read the entire PDF file to see if there are any errors qpdf can detect. | |
| 271 | 233 | */ |
| 272 | 234 | QPDF_DLL |
| 273 | 235 | QPDF_ERROR_CODE qpdf_check_pdf(qpdf_data qpdf); |
| ... | ... | @@ -284,20 +246,17 @@ extern "C" { |
| 284 | 246 | |
| 285 | 247 | /* This functions process a PDF or JSON input source. */ |
| 286 | 248 | |
| 287 | - /* Calling qpdf_read causes processFile to be called in the C++ | |
| 288 | - * API. Basic parsing is performed, but data from the file is | |
| 289 | - * only read as needed. For files without passwords, pass a null | |
| 290 | - * pointer or an empty string as the password. | |
| 249 | + /* Calling qpdf_read causes processFile to be called in the C++ API. Basic parsing is | |
| 250 | + * performed, but data from the file is only read as needed. For files without passwords, pass | |
| 251 | + * a null pointer or an empty string as the password. | |
| 291 | 252 | */ |
| 292 | 253 | QPDF_DLL |
| 293 | 254 | QPDF_ERROR_CODE |
| 294 | 255 | qpdf_read(qpdf_data qpdf, char const* filename, char const* password); |
| 295 | 256 | |
| 296 | - /* Calling qpdf_read_memory causes processMemoryFile to be called | |
| 297 | - * in the C++ API. Otherwise, it behaves in the same way as | |
| 298 | - * qpdf_read. The description argument will be used in place of | |
| 299 | - * the file name in any error or warning messages generated by the | |
| 300 | - * library. | |
| 257 | + /* Calling qpdf_read_memory causes processMemoryFile to be called in the C++ API. Otherwise, it | |
| 258 | + * behaves in the same way as qpdf_read. The description argument will be used in place of the | |
| 259 | + * file name in any error or warning messages generated by the library. | |
| 301 | 260 | */ |
| 302 | 261 | QPDF_DLL |
| 303 | 262 | QPDF_ERROR_CODE qpdf_read_memory( |
| ... | ... | @@ -307,22 +266,20 @@ extern "C" { |
| 307 | 266 | unsigned long long size, |
| 308 | 267 | char const* password); |
| 309 | 268 | |
| 310 | - /* Calling qpdf_empty_pdf initializes this qpdf object with an | |
| 311 | - * empty PDF, making it possible to create a PDF from scratch | |
| 312 | - * using the C API. Added in 10.6. | |
| 269 | + /* Calling qpdf_empty_pdf initializes this qpdf object with an empty PDF, making it possible to | |
| 270 | + * create a PDF from scratch using the C API. Added in 10.6. | |
| 313 | 271 | */ |
| 314 | 272 | QPDF_DLL |
| 315 | 273 | QPDF_ERROR_CODE qpdf_empty_pdf(qpdf_data qpdf); |
| 316 | 274 | |
| 317 | - /* Create a PDF from a JSON file. This calls createFromJSON in the | |
| 318 | - * C++ API. | |
| 275 | + /* Create a PDF from a JSON file. This calls createFromJSON in the C++ API. | |
| 319 | 276 | */ |
| 320 | 277 | QPDF_DLL |
| 321 | 278 | QPDF_ERROR_CODE |
| 322 | 279 | qpdf_create_from_json_file(qpdf_data qpdf, char const* filename); |
| 323 | 280 | |
| 324 | - /* Create a PDF from JSON data in a null-terminated string. This | |
| 325 | - * calls createFromJSON in the C++ API. | |
| 281 | + /* Create a PDF from JSON data in a null-terminated string. This calls createFromJSON in the C++ | |
| 282 | + * API. | |
| 326 | 283 | */ |
| 327 | 284 | QPDF_DLL |
| 328 | 285 | QPDF_ERROR_CODE |
| ... | ... | @@ -330,10 +287,9 @@ extern "C" { |
| 330 | 287 | |
| 331 | 288 | /* JSON UPDATE FUNCTIONS */ |
| 332 | 289 | |
| 333 | - /* Update a QPDF object from a JSON file or buffer. These | |
| 334 | - * functions call updateFromJSON. One of the other processing | |
| 335 | - * functions has to be called first so that the QPDF object is | |
| 336 | - * initialized with PDF data. | |
| 290 | + /* Update a QPDF object from a JSON file or buffer. These functions call updateFromJSON. One of | |
| 291 | + * the other processing functions has to be called first so that the QPDF object is initialized | |
| 292 | + * with PDF data. | |
| 337 | 293 | */ |
| 338 | 294 | QPDF_DLL |
| 339 | 295 | QPDF_ERROR_CODE |
| ... | ... | @@ -344,18 +300,16 @@ extern "C" { |
| 344 | 300 | |
| 345 | 301 | /* READ FUNCTIONS */ |
| 346 | 302 | |
| 347 | - /* Read functions below must be called after qpdf_read or any of | |
| 348 | - * the other functions that process a PDF. */ | |
| 303 | + /* Read functions below must be called after qpdf_read or any of the other functions that | |
| 304 | + * process a PDF. */ | |
| 349 | 305 | |
| 350 | 306 | /* |
| 351 | - * NOTE: Functions that return char* are returning a pointer to an | |
| 352 | - * internal buffer that will be reused for each call to a function | |
| 353 | - * that returns a char*. You must use or copy the value before | |
| 354 | - * calling any other qpdf library functions. | |
| 307 | + * NOTE: Functions that return char* are returning a pointer to an internal buffer that will be | |
| 308 | + * reused for each call to a function that returns a char*. You must use or copy the value | |
| 309 | + * before calling any other qpdf library functions. | |
| 355 | 310 | */ |
| 356 | 311 | |
| 357 | - /* Return the version of the PDF file. See warning above about | |
| 358 | - * functions that return char*. */ | |
| 312 | + /* Return the version of the PDF file. See warning above about functions that return char*. */ | |
| 359 | 313 | QPDF_DLL |
| 360 | 314 | char const* qpdf_get_pdf_version(qpdf_data qpdf); |
| 361 | 315 | |
| ... | ... | @@ -363,30 +317,26 @@ extern "C" { |
| 363 | 317 | QPDF_DLL |
| 364 | 318 | int qpdf_get_pdf_extension_level(qpdf_data qpdf); |
| 365 | 319 | |
| 366 | - /* Return the user password. If the file is opened using the | |
| 367 | - * owner password, the user password may be retrieved using this | |
| 368 | - * function. If the file is opened using the user password, this | |
| 369 | - * function will return that user password. See warning above | |
| 370 | - * about functions that return char*. | |
| 320 | + /* Return the user password. If the file is opened using the owner password, the user password | |
| 321 | + * may be retrieved using this function. If the file is opened using the user password, this | |
| 322 | + * function will return that user password. See warning above about functions that return | |
| 323 | + * char*. | |
| 371 | 324 | */ |
| 372 | 325 | QPDF_DLL |
| 373 | 326 | char const* qpdf_get_user_password(qpdf_data qpdf); |
| 374 | 327 | |
| 375 | - /* Return the string value of a key in the document's Info | |
| 376 | - * dictionary. The key parameter should include the leading | |
| 377 | - * slash, e.g. "/Author". If the key is not present or has a | |
| 378 | - * non-string value, a null pointer is returned. Otherwise, a | |
| 379 | - * pointer to an internal buffer is returned. See warning above | |
| 380 | - * about functions that return char*. | |
| 328 | + /* Return the string value of a key in the document's Info dictionary. The key parameter should | |
| 329 | + * include the leading slash, e.g. "/Author". If the key is not present or has a non-string | |
| 330 | + * value, a null pointer is returned. Otherwise, a pointer to an internal buffer is returned. | |
| 331 | + * See warning above about functions that return char*. | |
| 381 | 332 | */ |
| 382 | 333 | QPDF_DLL |
| 383 | 334 | char const* qpdf_get_info_key(qpdf_data qpdf, char const* key); |
| 384 | 335 | |
| 385 | - /* Set a value in the info dictionary, possibly replacing an | |
| 386 | - * existing value. The key must include the leading slash | |
| 387 | - * (e.g. "/Author"). Passing a null pointer as a value will | |
| 388 | - * remove the key from the info dictionary. Otherwise, a copy | |
| 389 | - * will be made of the string that is passed in. | |
| 336 | + /* Set a value in the info dictionary, possibly replacing an existing value. The key must | |
| 337 | + * include the leading slash (e.g. "/Author"). Passing a null pointer as a value will remove | |
| 338 | + * the key from the info dictionary. Otherwise, a copy will be made of the string that is | |
| 339 | + * passed in. | |
| 390 | 340 | */ |
| 391 | 341 | QPDF_DLL |
| 392 | 342 | void qpdf_set_info_key(qpdf_data qpdf, char const* key, char const* value); |
| ... | ... | @@ -420,21 +370,16 @@ extern "C" { |
| 420 | 370 | |
| 421 | 371 | /* JSON WRITE FUNCTIONS */ |
| 422 | 372 | |
| 423 | - /* This function serializes the PDF to JSON. This calls writeJSON | |
| 424 | - * from the C++ API. | |
| 373 | + /* This function serializes the PDF to JSON. This calls writeJSON from the C++ API. | |
| 425 | 374 | * |
| 426 | 375 | * - version: the JSON version, currently must be 2 |
| 427 | - * - fn: a function that will be called with blocks of JSON data; | |
| 428 | - * will be called with data, a length, and the value of the | |
| 429 | - * udata parameter to this function | |
| 430 | - * - udata: will be passed as the third argument to fn with each | |
| 431 | - * call; use this for your own tracking or pass a null pointer | |
| 432 | - * if you don't need it | |
| 433 | - * - For decode_level, json_stream_data, file_prefix, and | |
| 434 | - * wanted_objects, see comments in QPDF.hh. For this API, | |
| 435 | - * wanted_objects should be a null-terminated array of | |
| 436 | - * null-terminated strings. Pass a null pointer if you want all | |
| 437 | - * objects. | |
| 376 | + * - fn: a function that will be called with blocks of JSON data; will be called with data, a | |
| 377 | + * length, and the value of the udata parameter to this function | |
| 378 | + * - udata: will be passed as the third argument to fn with each call; use this for your own | |
| 379 | + * tracking or pass a null pointer if you don't need it | |
| 380 | + * - For decode_level, json_stream_data, file_prefix, and wanted_objects, see comments in | |
| 381 | + * QPDF.hh. For this API, wanted_objects should be a null-terminated array of null-terminated | |
| 382 | + * strings. Pass a null pointer if you want all objects. | |
| 438 | 383 | */ |
| 439 | 384 | |
| 440 | 385 | /* Function should return 0 on success. */ |
| ... | ... | @@ -453,37 +398,29 @@ extern "C" { |
| 453 | 398 | |
| 454 | 399 | /* WRITE FUNCTIONS */ |
| 455 | 400 | |
| 456 | - /* Set up for writing. No writing is actually performed until the | |
| 457 | - * call to qpdf_write(). | |
| 401 | + /* Set up for writing. No writing is actually performed until the call to qpdf_write(). | |
| 458 | 402 | */ |
| 459 | 403 | |
| 460 | - /* Supply the name of the file to be written and initialize the | |
| 461 | - * qpdf_data object to handle writing operations. This function | |
| 462 | - * also attempts to create the file. The PDF data is not written | |
| 463 | - * until the call to qpdf_write. qpdf_init_write may be called | |
| 464 | - * multiple times for the same qpdf_data object. When | |
| 465 | - * qpdf_init_write is called, all information from previous calls | |
| 466 | - * to functions that set write parameters (qpdf_set_linearization, | |
| 467 | - * etc.) is lost, so any write parameter functions must be called | |
| 468 | - * again. | |
| 404 | + /* Supply the name of the file to be written and initialize the qpdf_data object to handle | |
| 405 | + * writing operations. This function also attempts to create the file. The PDF data is not | |
| 406 | + * written until the call to qpdf_write. qpdf_init_write may be called multiple times for the | |
| 407 | + * same qpdf_data object. When qpdf_init_write is called, all information from previous calls | |
| 408 | + * to functions that set write parameters (qpdf_set_linearization, etc.) is lost, so any write | |
| 409 | + * parameter functions must be called again. | |
| 469 | 410 | */ |
| 470 | 411 | QPDF_DLL |
| 471 | 412 | QPDF_ERROR_CODE qpdf_init_write(qpdf_data qpdf, char const* filename); |
| 472 | 413 | |
| 473 | - /* Initialize for writing but indicate that the PDF file should be | |
| 474 | - * written to memory. Call qpdf_get_buffer_length and | |
| 475 | - * qpdf_get_buffer to retrieve the resulting buffer. The memory | |
| 476 | - * containing the PDF file will be destroyed when qpdf_cleanup is | |
| 477 | - * called. | |
| 414 | + /* Initialize for writing but indicate that the PDF file should be written to memory. Call | |
| 415 | + * qpdf_get_buffer_length and qpdf_get_buffer to retrieve the resulting buffer. The memory | |
| 416 | + * containing the PDF file will be destroyed when qpdf_cleanup is called. | |
| 478 | 417 | */ |
| 479 | 418 | QPDF_DLL |
| 480 | 419 | QPDF_ERROR_CODE qpdf_init_write_memory(qpdf_data qpdf); |
| 481 | 420 | |
| 482 | - /* Retrieve the buffer used if the file was written to memory. | |
| 483 | - * qpdf_get_buffer returns a null pointer if data was not written | |
| 484 | - * to memory. The memory is freed when qpdf_cleanup is called or | |
| 485 | - * if a subsequent call to qpdf_init_write or | |
| 486 | - * qpdf_init_write_memory is called. */ | |
| 421 | + /* Retrieve the buffer used if the file was written to memory. qpdf_get_buffer returns a null | |
| 422 | + * pointer if data was not written to memory. The memory is freed when qpdf_cleanup is called | |
| 423 | + * or if a subsequent call to qpdf_init_write or qpdf_init_write_memory is called. */ | |
| 487 | 424 | QPDF_DLL |
| 488 | 425 | size_t qpdf_get_buffer_length(qpdf_data qpdf); |
| 489 | 426 | QPDF_DLL |
| ... | ... | @@ -516,14 +453,14 @@ extern "C" { |
| 516 | 453 | QPDF_DLL |
| 517 | 454 | void qpdf_set_deterministic_ID(qpdf_data qpdf, QPDF_BOOL value); |
| 518 | 455 | |
| 519 | - /* Never use qpdf_set_static_ID except in test suites to suppress | |
| 520 | - * generation of a random /ID. See also qpdf_set_deterministic_ID. | |
| 456 | + /* Never use qpdf_set_static_ID except in test suites to suppress generation of a random /ID. | |
| 457 | + * See also qpdf_set_deterministic_ID. | |
| 521 | 458 | */ |
| 522 | 459 | QPDF_DLL |
| 523 | 460 | void qpdf_set_static_ID(qpdf_data qpdf, QPDF_BOOL value); |
| 524 | 461 | |
| 525 | - /* Never use qpdf_set_static_aes_IV except in test suites to | |
| 526 | - * create predictable AES encrypted output. | |
| 462 | + /* Never use qpdf_set_static_aes_IV except in test suites to create predictable AES encrypted | |
| 463 | + * output. | |
| 527 | 464 | */ |
| 528 | 465 | QPDF_DLL |
| 529 | 466 | void qpdf_set_static_aes_IV(qpdf_data qpdf, QPDF_BOOL value); |
| ... | ... | @@ -534,9 +471,8 @@ extern "C" { |
| 534 | 471 | QPDF_DLL |
| 535 | 472 | void qpdf_set_preserve_encryption(qpdf_data qpdf, QPDF_BOOL value); |
| 536 | 473 | |
| 537 | - /* The *_insecure functions are identical to the old versions but | |
| 538 | - * have been renamed as a an alert to the caller that they are | |
| 539 | - * insecure. See "Weak Cryptographic" in the manual for | |
| 474 | + /* The *_insecure functions are identical to the old versions but have been renamed as a an | |
| 475 | + * alert to the caller that they are insecure. See "Weak Cryptographic" in the manual for | |
| 540 | 476 | * details. |
| 541 | 477 | */ |
| 542 | 478 | QPDF_DLL |
| ... | ... | @@ -622,15 +558,12 @@ extern "C" { |
| 622 | 558 | void |
| 623 | 559 | qpdf_force_pdf_version_and_extension(qpdf_data qpdf, char const* version, int extension_level); |
| 624 | 560 | |
| 625 | - /* During write, your report_progress function will be called with | |
| 626 | - * a value between 0 and 100 representing the approximate write | |
| 627 | - * progress. The data object you pass to | |
| 628 | - * qpdf_register_progress_reporter will be handed back to your | |
| 629 | - * function. This function must be called after qpdf_init_write | |
| 630 | - * (or qpdf_init_write_memory) and before qpdf_write. The | |
| 631 | - * registered progress reporter applies only to a single write, so | |
| 632 | - * you must call it again if you perform a subsequent write with a | |
| 633 | - * new writer. | |
| 561 | + /* During write, your report_progress function will be called with a value between 0 and 100 | |
| 562 | + * representing the approximate write progress. The data object you pass to | |
| 563 | + * qpdf_register_progress_reporter will be handed back to your function. This function must be | |
| 564 | + * called after qpdf_init_write (or qpdf_init_write_memory) and before qpdf_write. The | |
| 565 | + * registered progress reporter applies only to a single write, so you must call it again if you | |
| 566 | + * perform a subsequent write with a new writer. | |
| 634 | 567 | */ |
| 635 | 568 | QPDF_DLL |
| 636 | 569 | void qpdf_register_progress_reporter( |
| ... | ... | @@ -642,67 +575,51 @@ extern "C" { |
| 642 | 575 | |
| 643 | 576 | /* Object handling. |
| 644 | 577 | * |
| 645 | - * These functions take and return a qpdf_oh object handle, which | |
| 646 | - * is just an unsigned integer. The value 0 is never returned, which | |
| 647 | - * makes it usable as an uninitialized value. The handles returned by | |
| 648 | - * these functions are guaranteed to be unique, i.e. two calls to | |
| 649 | - * (the same of different) functions will return distinct handles | |
| 650 | - * even when they refer to the same object. | |
| 578 | + * These functions take and return a qpdf_oh object handle, which is just an unsigned integer. | |
| 579 | + * The value 0 is never returned, which makes it usable as an uninitialized value. The handles | |
| 580 | + * returned by these functions are guaranteed to be unique, i.e. two calls to (the same of | |
| 581 | + * different) functions will return distinct handles even when they refer to the same object. | |
| 651 | 582 | * |
| 652 | - * Each function below, starting with qpdf_oh, corresponds to a | |
| 653 | - * specific method of QPDFObjectHandler. For example, | |
| 654 | - * qpdf_oh_is_bool corresponds to QPDFObjectHandle::isBool. If the | |
| 655 | - * C++ method is overloaded, the C function's name will be | |
| 656 | - * disambiguated. If the C++ method takes optional arguments, the C | |
| 657 | - * function will have required arguments in those positions. For | |
| 658 | - * details about the method, please see comments in | |
| 659 | - * QPDFObjectHandle.hh. Comments here only explain things that are | |
| 660 | - * specific to the "C" API. | |
| 583 | + * Each function below, starting with qpdf_oh, corresponds to a specific method of | |
| 584 | + * QPDFObjectHandler. For example, qpdf_oh_is_bool corresponds to QPDFObjectHandle::isBool. If | |
| 585 | + * the C++ method is overloaded, the C function's name will be disambiguated. If the C++ method | |
| 586 | + * takes optional arguments, the C function will have required arguments in those positions. For | |
| 587 | + * details about the method, please see comments in QPDFObjectHandle.hh. Comments here only | |
| 588 | + * explain things that are specific to the "C" API. | |
| 661 | 589 | * |
| 662 | - * Only a fraction of the methods of QPDFObjectHandle are | |
| 663 | - * available here. Most of the basic methods for creating, | |
| 664 | - * accessing, and modifying most types of objects are present. | |
| 665 | - * Most of the higher-level functions are not implemented. | |
| 666 | - * Functions for dealing with content streams as well as objects | |
| 667 | - * that only exist in content streams (operators and inline | |
| 668 | - * images) are mostly not provided. | |
| 590 | + * Only a fraction of the methods of QPDFObjectHandle are available here. Most of the basic | |
| 591 | + * methods for creating, accessing, and modifying most types of objects are present. Most of the | |
| 592 | + * higher-level functions are not implemented. Functions for dealing with content streams as | |
| 593 | + * well as objects that only exist in content streams (operators and inline images) are mostly | |
| 594 | + * not provided. | |
| 669 | 595 | * |
| 670 | - * To refer to a specific QPDFObjectHandle, you need a pair | |
| 671 | - * consisting of a qpdf_data and a qpdf_oh, which is just an index | |
| 672 | - * into an internal table of objects. All memory allocated by any | |
| 673 | - * of these functions is returned when qpdf_cleanup is called. | |
| 596 | + * To refer to a specific QPDFObjectHandle, you need a pair consisting of a qpdf_data and a | |
| 597 | + * qpdf_oh, which is just an index into an internal table of objects. All memory allocated by | |
| 598 | + * any of these functions is returned when qpdf_cleanup is called. | |
| 674 | 599 | * |
| 675 | - * Regarding memory, the same rules apply as the above functions. | |
| 676 | - * Specifically, if a function returns a char*, the memory is | |
| 677 | - * managed by the library and, unless otherwise specified, is not | |
| 600 | + * Regarding memory, the same rules apply as the above functions. Specifically, if a function | |
| 601 | + * returns a char*, the memory is managed by the library and, unless otherwise specified, is not | |
| 678 | 602 | * expected to be valid after the next qpdf call. |
| 679 | 603 | * |
| 680 | - * The qpdf_data object keeps a cache of handles returned by these | |
| 681 | - * functions. Once you are finished referencing a handle, you can | |
| 682 | - * optionally release it. Releasing handles is optional since they | |
| 683 | - * will all get released by qpdf_cleanup, but it can help to | |
| 684 | - * reduce the memory footprint of the qpdf_data object to release | |
| 685 | - * them when you're done. Releasing a handle does not destroy the | |
| 686 | - * object. All QPDFObjectHandle objects are deleted when they are | |
| 687 | - * no longer referenced. Releasing an object handle simply | |
| 688 | - * invalidates it. For example, if you create an object, | |
| 689 | - * add it to an existing dictionary or array, and then release its | |
| 690 | - * handle, the object is safely part of the dictionary or array. | |
| 691 | - * Similarly, any other object handle refering to the object remains | |
| 692 | - * valid. Explicitly releasing an object handle is essentially the | |
| 693 | - * same as letting a QPDFObjectHandle go out of scope in the C++ | |
| 694 | - * API. | |
| 604 | + * The qpdf_data object keeps a cache of handles returned by these functions. Once you are | |
| 605 | + * finished referencing a handle, you can optionally release it. Releasing handles is optional | |
| 606 | + * since they will all get released by qpdf_cleanup, but it can help to reduce the memory | |
| 607 | + * footprint of the qpdf_data object to release them when you're done. Releasing a handle does | |
| 608 | + * not destroy the object. All QPDFObjectHandle objects are deleted when they are no longer | |
| 609 | + * referenced. Releasing an object handle simply invalidates it. For example, if you create an | |
| 610 | + * object, add it to an existing dictionary or array, and then release its handle, the object is | |
| 611 | + * safely part of the dictionary or array. Similarly, any other object handle refering to the | |
| 612 | + * object remains valid. Explicitly releasing an object handle is essentially the same as | |
| 613 | + * letting a QPDFObjectHandle go out of scope in the C++ API. | |
| 695 | 614 | * |
| 696 | - * Please see "ERROR HANDLING" above for details on how error | |
| 697 | - * conditions are handled. | |
| 615 | + * Please see "ERROR HANDLING" above for details on how error conditions are handled. | |
| 698 | 616 | */ |
| 699 | 617 | |
| 700 | 618 | /* For examples of using this API, see examples/pdf-c-objects.c */ |
| 701 | 619 | |
| 702 | 620 | typedef unsigned int qpdf_oh; |
| 703 | 621 | |
| 704 | - /* Releasing objects -- see comments above. These functions have no | |
| 705 | - * equivalent in the C++ API. | |
| 622 | + /* Releasing objects -- see comments above. These functions have no equivalent in the C++ API. | |
| 706 | 623 | */ |
| 707 | 624 | QPDF_DLL |
| 708 | 625 | void qpdf_oh_release(qpdf_data qpdf, qpdf_oh oh); |
| ... | ... | @@ -727,13 +644,11 @@ extern "C" { |
| 727 | 644 | QPDF_DLL |
| 728 | 645 | void qpdf_replace_object(qpdf_data qpdf, int objid, int generation, qpdf_oh oh); |
| 729 | 646 | |
| 730 | - /* Wrappers around QPDFObjectHandle methods. Be sure to read | |
| 731 | - * corresponding comments in QPDFObjectHandle.hh to understand | |
| 732 | - * what each function does and what kinds of objects it applies | |
| 733 | - * to. Note that names are to appear in a canonicalized form | |
| 734 | - * starting with a leading slash and with all PDF escaping | |
| 735 | - * resolved. See comments for getName() in QPDFObjectHandle.hh for | |
| 736 | - * details. | |
| 647 | + /* Wrappers around QPDFObjectHandle methods. Be sure to read corresponding comments in | |
| 648 | + * QPDFObjectHandle.hh to understand what each function does and what kinds of objects it | |
| 649 | + * applies to. Note that names are to appear in a canonicalized form starting with a leading | |
| 650 | + * slash and with all PDF escaping resolved. See comments for getName() in QPDFObjectHandle.hh | |
| 651 | + * for details. | |
| 737 | 652 | */ |
| 738 | 653 | |
| 739 | 654 | QPDF_DLL |
| ... | ... | @@ -829,18 +744,14 @@ extern "C" { |
| 829 | 744 | QPDF_BOOL |
| 830 | 745 | qpdf_oh_get_value_as_name(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length); |
| 831 | 746 | |
| 832 | - /* Return the length of the last string returned. This enables you | |
| 833 | - * to retrieve the entire string for cases in which a char* | |
| 834 | - * returned by one of the functions below points to a string with | |
| 835 | - * embedded null characters. The function | |
| 836 | - * qpdf_oh_get_binary_string_value takes a length pointer, which | |
| 837 | - * can be useful if you are retrieving the value of a string that | |
| 838 | - * is expected to contain binary data, such as a checksum or | |
| 839 | - * document ID. It is always valid to call | |
| 840 | - * qpdf_get_last_string_length, but it is usually not necessary as | |
| 841 | - * C strings returned by the library are only expected to be able | |
| 842 | - * to contain null characters if their values originate from PDF | |
| 843 | - * strings in the input. | |
| 747 | + /* Return the length of the last string returned. This enables you to retrieve the entire string | |
| 748 | + * for cases in which a char* returned by one of the functions below points to a string with | |
| 749 | + * embedded null characters. The function qpdf_oh_get_binary_string_value takes a length | |
| 750 | + * pointer, which can be useful if you are retrieving the value of a string that is expected to | |
| 751 | + * contain binary data, such as a checksum or document ID. It is always valid to call | |
| 752 | + * qpdf_get_last_string_length, but it is usually not necessary as C strings returned by the | |
| 753 | + * library are only expected to be able to contain null characters if their values originate | |
| 754 | + * from PDF strings in the input. | |
| 844 | 755 | */ |
| 845 | 756 | QPDF_DLL |
| 846 | 757 | size_t qpdf_get_last_string_length(qpdf_data qpdf); |
| ... | ... | @@ -865,10 +776,9 @@ extern "C" { |
| 865 | 776 | QPDF_DLL |
| 866 | 777 | qpdf_oh qpdf_oh_get_array_item(qpdf_data qpdf, qpdf_oh oh, int n); |
| 867 | 778 | |
| 868 | - /* In all dictionary APIs, keys are specified/represented as | |
| 869 | - * canonicalized name strings starting with / and with all PDF | |
| 870 | - * escaping resolved. See comments for getName() in | |
| 871 | - * QPDFObjectHandle for details. | |
| 779 | + /* In all dictionary APIs, keys are specified/represented as canonicalized name strings starting | |
| 780 | + * with / and with all PDF escaping resolved. See comments for getName() in QPDFObjectHandle for | |
| 781 | + * details. | |
| 872 | 782 | */ |
| 873 | 783 | |
| 874 | 784 | /* "C"-specific dictionary key iteration */ |
| ... | ... | @@ -878,11 +788,9 @@ extern "C" { |
| 878 | 788 | void qpdf_oh_begin_dict_key_iter(qpdf_data qpdf, qpdf_oh dict); |
| 879 | 789 | QPDF_DLL |
| 880 | 790 | QPDF_BOOL qpdf_oh_dict_more_keys(qpdf_data qpdf); |
| 881 | - /* The memory returned by qpdf_oh_dict_next_key is owned by | |
| 882 | - * qpdf_data. It is good until the next call to | |
| 883 | - * qpdf_oh_dict_next_key with the same qpdf_data object. Calling | |
| 884 | - * the function again, even with a different dict, invalidates | |
| 885 | - * previous return values. | |
| 791 | + /* The memory returned by qpdf_oh_dict_next_key is owned by qpdf_data. It is good until the next | |
| 792 | + * call to qpdf_oh_dict_next_key with the same qpdf_data object. Calling the function again, | |
| 793 | + * even with a different dict, invalidates previous return values. | |
| 886 | 794 | */ |
| 887 | 795 | QPDF_DLL |
| 888 | 796 | char const* qpdf_oh_dict_next_key(qpdf_data qpdf); |
| ... | ... | @@ -918,8 +826,8 @@ extern "C" { |
| 918 | 826 | qpdf_oh qpdf_oh_new_string(qpdf_data qpdf, char const* str); |
| 919 | 827 | QPDF_DLL |
| 920 | 828 | qpdf_oh qpdf_oh_new_unicode_string(qpdf_data qpdf, char const* utf8_str); |
| 921 | - /* Use qpdf_oh_new_binary_string for creating a string that may | |
| 922 | - * contain atrbitary binary data including embedded null characters. | |
| 829 | + /* Use qpdf_oh_new_binary_string for creating a string that may contain atrbitary binary data | |
| 830 | + * including embedded null characters. | |
| 923 | 831 | */ |
| 924 | 832 | QPDF_DLL |
| 925 | 833 | qpdf_oh qpdf_oh_new_binary_string(qpdf_data qpdf, char const* str, size_t length); |
| ... | ... | @@ -930,11 +838,10 @@ extern "C" { |
| 930 | 838 | QPDF_DLL |
| 931 | 839 | qpdf_oh qpdf_oh_new_dictionary(qpdf_data qpdf); |
| 932 | 840 | |
| 933 | - /* Create a new stream. Use qpdf_oh_get_dict to get (and | |
| 934 | - * subsequently modify) the stream dictionary if needed. See | |
| 935 | - * comments in QPDFObjectHandle.hh for newStream() for additional | |
| 936 | - * notes. You must call qpdf_oh_replace_stream_data to provide | |
| 937 | - * data for the stream. See STREAM FUNCTIONS below. | |
| 841 | + /* Create a new stream. Use qpdf_oh_get_dict to get (and subsequently modify) the stream | |
| 842 | + * dictionary if needed. See comments in QPDFObjectHandle.hh for newStream() for additional | |
| 843 | + * notes. You must call qpdf_oh_replace_stream_data to provide data for the stream. See STREAM | |
| 844 | + * FUNCTIONS below. | |
| 938 | 845 | */ |
| 939 | 846 | QPDF_DLL |
| 940 | 847 | qpdf_oh qpdf_oh_new_stream(qpdf_data qpdf); |
| ... | ... | @@ -973,40 +880,33 @@ extern "C" { |
| 973 | 880 | QPDF_DLL |
| 974 | 881 | char const* qpdf_oh_unparse_binary(qpdf_data qpdf, qpdf_oh oh); |
| 975 | 882 | |
| 976 | - /* Note about foreign objects: the C API does not have enough | |
| 977 | - * information in the value of a qpdf_oh to know what QPDF object | |
| 978 | - * it belongs to. To uniquely specify a qpdf object handle from a | |
| 979 | - * specific qpdf_data instance, you always pair the qpdf_oh with | |
| 980 | - * the correct qpdf_data. Otherwise, you are likely to get | |
| 981 | - * completely the wrong object if you are not lucky enough to get | |
| 982 | - * an error about the object being invalid. | |
| 883 | + /* Note about foreign objects: the C API does not have enough information in the value of a | |
| 884 | + * qpdf_oh to know what QPDF object it belongs to. To uniquely specify a qpdf object handle from | |
| 885 | + * a specific qpdf_data instance, you always pair the qpdf_oh with the correct qpdf_data. | |
| 886 | + * Otherwise, you are likely to get completely the wrong object if you are not lucky enough to | |
| 887 | + * get an error about the object being invalid. | |
| 983 | 888 | */ |
| 984 | 889 | |
| 985 | - /* Copy foreign object: the qpdf_oh returned belongs to `qpdf`, | |
| 986 | - * while `foreign_oh` belongs to `other_qpdf`. | |
| 890 | + /* Copy foreign object: the qpdf_oh returned belongs to `qpdf`, while `foreign_oh` belongs to | |
| 891 | + * `other_qpdf`. | |
| 987 | 892 | */ |
| 988 | 893 | QPDF_DLL |
| 989 | 894 | qpdf_oh qpdf_oh_copy_foreign_object(qpdf_data qpdf, qpdf_data other_qpdf, qpdf_oh foreign_oh); |
| 990 | 895 | |
| 991 | 896 | /* STREAM FUNCTIONS */ |
| 992 | 897 | |
| 993 | - /* These functions provide basic access to streams and stream | |
| 994 | - * data. They are not as comprehensive as what is in | |
| 995 | - * QPDFObjectHandle, but they do allow for working with streams | |
| 996 | - * and stream data as caller-managed memory. | |
| 898 | + /* These functions provide basic access to streams and stream data. They are not as | |
| 899 | + * comprehensive as what is in QPDFObjectHandle, but they do allow for working with streams and | |
| 900 | + * stream data as caller-managed memory. | |
| 997 | 901 | */ |
| 998 | 902 | |
| 999 | - /* Get stream data as a buffer. The buffer is allocated with | |
| 1000 | - * malloc and must be freed by the caller. The size of the buffer | |
| 1001 | - * is stored in *len. The arguments are similar to those in | |
| 1002 | - * QPDFObjectHandle::pipeStreamData. To get raw stream data, pass | |
| 1003 | - * qpdf_dl_none as decode_level. Otherwise, filtering is attempted | |
| 1004 | - * and *filtered is set to indicate whether it was successful. If | |
| 1005 | - * *filtered is QPDF_FALSE, then raw, unfiltered stream data was | |
| 1006 | - * returned. You may pass a null pointer as filtered if you don't | |
| 1007 | - * care about the result. If you pass a null pointer as bufp (and | |
| 1008 | - * len), the value of filtered will be set to whether the stream | |
| 1009 | - * can be filterable. | |
| 903 | + /* Get stream data as a buffer. The buffer is allocated with malloc and must be freed by the | |
| 904 | + * caller. The size of the buffer is stored in *len. The arguments are similar to those in | |
| 905 | + * QPDFObjectHandle::pipeStreamData. To get raw stream data, pass qpdf_dl_none as decode_level. | |
| 906 | + * Otherwise, filtering is attempted and *filtered is set to indicate whether it was successful. | |
| 907 | + * If *filtered is QPDF_FALSE, then raw, unfiltered stream data was returned. You may pass a | |
| 908 | + * null pointer as filtered if you don't care about the result. If you pass a null pointer as | |
| 909 | + * bufp (and len), the value of filtered will be set to whether the stream can be filterable. | |
| 1010 | 910 | */ |
| 1011 | 911 | QPDF_DLL |
| 1012 | 912 | QPDF_ERROR_CODE qpdf_oh_get_stream_data( |
| ... | ... | @@ -1017,17 +917,16 @@ extern "C" { |
| 1017 | 917 | unsigned char** bufp, |
| 1018 | 918 | size_t* len); |
| 1019 | 919 | |
| 1020 | - /* This function returns the concatenation of all of a page's | |
| 1021 | - * content streams as a single, dynamically allocated buffer. As | |
| 1022 | - * with qpdf_oh_get_stream_data, the buffer is allocated with | |
| 920 | + /* This function returns the concatenation of all of a page's content streams as a single, | |
| 921 | + * dynamically allocated buffer. As with qpdf_oh_get_stream_data, the buffer is allocated with | |
| 1023 | 922 | * malloc and must be freed by the caller. |
| 1024 | 923 | */ |
| 1025 | 924 | QPDF_DLL |
| 1026 | 925 | QPDF_ERROR_CODE qpdf_oh_get_page_content_data( |
| 1027 | 926 | qpdf_data qpdf, qpdf_oh page_oh, unsigned char** bufp, size_t* len); |
| 1028 | 927 | |
| 1029 | - /* The data pointed to by bufp will be copied by the library. It | |
| 1030 | - * does not need to remain valid after the call returns. | |
| 928 | + /* The data pointed to by bufp will be copied by the library. It does not need to remain valid | |
| 929 | + * after the call returns. | |
| 1031 | 930 | */ |
| 1032 | 931 | QPDF_DLL |
| 1033 | 932 | void qpdf_oh_replace_stream_data( |
| ... | ... | @@ -1040,21 +939,18 @@ extern "C" { |
| 1040 | 939 | |
| 1041 | 940 | /* PAGE FUNCTIONS */ |
| 1042 | 941 | |
| 1043 | - /* The first time a page function is called, qpdf will traverse | |
| 1044 | - * the /Pages tree. Subsequent calls to retrieve the number of | |
| 1045 | - * pages or a specific page run in constant time as they are | |
| 1046 | - * accessing the pages cache. If you manipulate the page tree | |
| 1047 | - * outside of these functions, you should call | |
| 1048 | - * qpdf_update_all_pages_cache. See comments for getAllPages() and | |
| 942 | + /* The first time a page function is called, qpdf will traverse the /Pages tree. Subsequent | |
| 943 | + * calls to retrieve the number of pages or a specific page run in constant time as they are | |
| 944 | + * accessing the pages cache. If you manipulate the page tree outside of these functions, you | |
| 945 | + * should call qpdf_update_all_pages_cache. See comments for getAllPages() and | |
| 1049 | 946 | * updateAllPagesCache() in QPDF.hh. |
| 1050 | 947 | */ |
| 1051 | 948 | |
| 1052 | - /* For each function, the corresponding method in QPDF.hh is | |
| 1053 | - * referenced. Please see comments in QPDF.hh for details. | |
| 949 | + /* For each function, the corresponding method in QPDF.hh is referenced. Please see comments in | |
| 950 | + * QPDF.hh for details. | |
| 1054 | 951 | */ |
| 1055 | 952 | |
| 1056 | - /* calls getAllPages(). On error, returns -1 and sets error for | |
| 1057 | - * qpdf_get_error. */ | |
| 953 | + /* calls getAllPages(). On error, returns -1 and sets error for qpdf_get_error. */ | |
| 1058 | 954 | QPDF_DLL |
| 1059 | 955 | int qpdf_get_num_pages(qpdf_data qpdf); |
| 1060 | 956 | /* returns uninitialized object if out of range */ |
| ... | ... | @@ -1065,9 +961,8 @@ extern "C" { |
| 1065 | 961 | QPDF_DLL |
| 1066 | 962 | QPDF_ERROR_CODE qpdf_update_all_pages_cache(qpdf_data qpdf); |
| 1067 | 963 | |
| 1068 | - /* findPage() -- return zero-based index. If page is not found, | |
| 1069 | - * return -1 and save the error to be retrieved with | |
| 1070 | - * qpdf_get_error. | |
| 964 | + /* findPage() -- return zero-based index. If page is not found, return -1 and save the error to | |
| 965 | + * be retrieved with qpdf_get_error. | |
| 1071 | 966 | */ |
| 1072 | 967 | QPDF_DLL |
| 1073 | 968 | int qpdf_find_page_by_id(qpdf_data qpdf, int objid, int generation); |
| ... | ... | @@ -1078,10 +973,9 @@ extern "C" { |
| 1078 | 973 | QPDF_DLL |
| 1079 | 974 | QPDF_ERROR_CODE qpdf_push_inherited_attributes_to_page(qpdf_data qpdf); |
| 1080 | 975 | |
| 1081 | - /* Functions that add pages may add pages from other files. If | |
| 1082 | - * adding a page from the same file, newpage_qpdf and qpdf are the | |
| 1083 | - * same. | |
| 1084 | - /*/ | |
| 976 | + /* Functions that add pages may add pages from other files. If adding a page from the same file, | |
| 977 | + newpage_qpdf and qpdf are the same. | |
| 978 | + */ | |
| 1085 | 979 | |
| 1086 | 980 | /* addPage() */ |
| 1087 | 981 | QPDF_DLL | ... | ... |
include/qpdf/qpdfjob-c.h
| ... | ... | @@ -2,33 +2,29 @@ |
| 2 | 2 | * |
| 3 | 3 | * This file is part of qpdf. |
| 4 | 4 | * |
| 5 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | - * you may not use this file except in compliance with the License. | |
| 7 | - * You may obtain a copy of the License at | |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | + * in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | * |
| 9 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | * |
| 11 | - * Unless required by applicable law or agreed to in writing, software | |
| 12 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | - * See the License for the specific language governing permissions and | |
| 15 | - * limitations under the License. | |
| 10 | + * Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | + * or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | + * the License. | |
| 16 | 14 | * |
| 17 | - * Versions of qpdf prior to version 7 were released under the terms | |
| 18 | - * of version 2.0 of the Artistic License. At your option, you may | |
| 19 | - * continue to consider qpdf to be licensed under those terms. Please | |
| 20 | - * see the manual for additional information. | |
| 15 | + * Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | + * License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | + * Please see the manual for additional information. | |
| 21 | 18 | */ |
| 22 | 19 | |
| 23 | 20 | #ifndef QPDFJOB_C_H |
| 24 | 21 | #define QPDFJOB_C_H |
| 25 | 22 | |
| 26 | 23 | /* |
| 27 | - * This file defines a basic "C" API for QPDFJob. See also qpdf-c.h, | |
| 28 | - * which defines an API that exposes more of the library's API. This | |
| 29 | - * API is primarily intended to make it simpler for programs in | |
| 30 | - * languages other than C++ to incorporate functionality that could be | |
| 31 | - * run directly from the command-line. | |
| 24 | + * This file defines a basic "C" API for QPDFJob. See also qpdf-c.h, which defines an API that | |
| 25 | + * exposes more of the library's API. This API is primarily intended to make it simpler for programs | |
| 26 | + * in languages other than C++ to incorporate functionality that could be run directly from the | |
| 27 | + * command-line. | |
| 32 | 28 | */ |
| 33 | 29 | |
| 34 | 30 | #include <qpdf/DLL.h> |
| ... | ... | @@ -40,52 +36,46 @@ |
| 40 | 36 | #endif |
| 41 | 37 | |
| 42 | 38 | /* |
| 43 | - * This file provides a minimal wrapper around QPDFJob. See | |
| 44 | - * examples/qpdfjob-c.c for an example of its use. | |
| 39 | + * This file provides a minimal wrapper around QPDFJob. See examples/qpdfjob-c.c for an example of | |
| 40 | + * its use. | |
| 45 | 41 | */ |
| 46 | 42 | |
| 47 | 43 | #ifdef __cplusplus |
| 48 | 44 | extern "C" { |
| 49 | 45 | #endif |
| 50 | - /* SHORT INTERFACE -- These functions are single calls that take | |
| 51 | - * care of the whole life cycle of QPDFJob. They can be used for | |
| 52 | - * one-shot operations where no additional configuration is | |
| 46 | + /* SHORT INTERFACE -- These functions are single calls that take care of the whole life cycle of | |
| 47 | + * QPDFJob. They can be used for one-shot operations where no additional configuration is | |
| 53 | 48 | * needed. See FULL INTERFACE below. */ |
| 54 | 49 | |
| 55 | - /* This function does the equivalent of running the qpdf | |
| 56 | - * command-line with the given arguments and returns the exit code | |
| 57 | - * that qpdf would use. argv must be a null-terminated array of | |
| 58 | - * null-terminated UTF8-encoded strings. If calling this from | |
| 59 | - * wmain on Windows, use qpdfjob_run_from_wide_argv instead. Exit | |
| 60 | - * code values are defined in Constants.h in the qpdf_exit_code_e | |
| 61 | - * type. | |
| 50 | + /* This function does the equivalent of running the qpdf command-line with the given arguments | |
| 51 | + * and returns the exit code that qpdf would use. argv must be a null-terminated array of | |
| 52 | + * null-terminated UTF8-encoded strings. If calling this from wmain on Windows, use | |
| 53 | + * qpdfjob_run_from_wide_argv instead. Exit code values are defined in Constants.h in the | |
| 54 | + * qpdf_exit_code_e type. | |
| 62 | 55 | */ |
| 63 | 56 | QPDF_DLL |
| 64 | 57 | int qpdfjob_run_from_argv(char const* const argv[]); |
| 65 | 58 | |
| 66 | 59 | #ifndef QPDF_NO_WCHAR_T |
| 67 | - /* This function is the same as qpdfjob_run_from_argv except argv | |
| 68 | - * is encoded with wide characters. This would be suitable for | |
| 69 | - * calling from a Windows wmain function. | |
| 60 | + /* This function is the same as qpdfjob_run_from_argv except argv is encoded with wide | |
| 61 | + * characters. This would be suitable for calling from a Windows wmain function. | |
| 70 | 62 | */ |
| 71 | 63 | QPDF_DLL |
| 72 | 64 | int qpdfjob_run_from_wide_argv(wchar_t const* const argv[]); |
| 73 | 65 | #endif /* QPDF_NO_WCHAR_T */ |
| 74 | 66 | |
| 75 | - /* This function runs QPDFJob from a job JSON file. See the "QPDF | |
| 76 | - * Job" section of the manual for details. The JSON string must be | |
| 77 | - * UTF8-encoded. It returns the error code that qpdf would return | |
| 78 | - * with the equivalent command-line invocation. Exit code values | |
| 79 | - * are defined in Constants.h in the qpdf_exit_code_e type. | |
| 67 | + /* This function runs QPDFJob from a job JSON file. See the "QPDF Job" section of the manual for | |
| 68 | + * details. The JSON string must be UTF8-encoded. It returns the error code that qpdf would | |
| 69 | + * return with the equivalent command-line invocation. Exit code values are defined in | |
| 70 | + * Constants.h in the qpdf_exit_code_e type. | |
| 80 | 71 | */ |
| 81 | 72 | QPDF_DLL |
| 82 | 73 | int qpdfjob_run_from_json(char const* json); |
| 83 | 74 | |
| 84 | - /* FULL INTERFACE -- new in qpdf11. Similar to the qpdf-c.h API, | |
| 85 | - * you must call qpdfjob_init to get a qpdfjob_handle and, when | |
| 86 | - * done, call qpdfjob_cleanup to free resources. Remaining methods | |
| 87 | - * take qpdfjob_handle as an argument. This interface requires | |
| 88 | - * more calls but also offers greater flexibility. | |
| 75 | + /* FULL INTERFACE -- new in qpdf11. Similar to the qpdf-c.h API, you must call qpdfjob_init to | |
| 76 | + * get a qpdfjob_handle and, when done, call qpdfjob_cleanup to free resources. Remaining | |
| 77 | + * methods take qpdfjob_handle as an argument. This interface requires more calls but also | |
| 78 | + * offers greater flexibility. | |
| 89 | 79 | */ |
| 90 | 80 | typedef struct _qpdfjob_handle* qpdfjob_handle; |
| 91 | 81 | QPDF_DLL |
| ... | ... | @@ -94,11 +84,9 @@ extern "C" { |
| 94 | 84 | QPDF_DLL |
| 95 | 85 | void qpdfjob_cleanup(qpdfjob_handle* j); |
| 96 | 86 | |
| 97 | - /* Set or get the current logger. You need to call | |
| 98 | - * qpdflogger_cleanup on the logger handles when you are done with | |
| 99 | - * the handles. The underlying logger is cleaned up automatically | |
| 100 | - * and persists if needed after the logger handle is destroyed. | |
| 101 | - * See comments in qpdflogger-c.h for details. | |
| 87 | + /* Set or get the current logger. You need to call qpdflogger_cleanup on the logger handles when | |
| 88 | + * you are done with the handles. The underlying logger is cleaned up automatically and persists | |
| 89 | + * if needed after the logger handle is destroyed. See comments in qpdflogger-c.h for details. | |
| 102 | 90 | */ |
| 103 | 91 | |
| 104 | 92 | QPDF_DLL |
| ... | ... | @@ -106,62 +94,55 @@ extern "C" { |
| 106 | 94 | QPDF_DLL |
| 107 | 95 | qpdflogger_handle qpdfjob_get_logger(qpdfjob_handle j); |
| 108 | 96 | |
| 109 | - /* This function wraps QPDFJob::initializeFromArgv. The return | |
| 110 | - * value is the same as qpdfjob_run. If this returns an error, it | |
| 111 | - * is invalid to call any other functions this job handle. | |
| 97 | + /* This function wraps QPDFJob::initializeFromArgv. The return value is the same as qpdfjob_run. | |
| 98 | + * If this returns an error, it is invalid to call any other functions this job handle. | |
| 112 | 99 | */ |
| 113 | 100 | QPDF_DLL |
| 114 | 101 | int qpdfjob_initialize_from_argv(qpdfjob_handle j, char const* const argv[]); |
| 115 | 102 | |
| 116 | 103 | #ifndef QPDF_NO_WCHAR_T |
| 117 | - /* This function is the same as qpdfjob_initialize_from_argv | |
| 118 | - * except argv is encoded with wide characters. This would be | |
| 119 | - * suitable for calling from a Windows wmain function. | |
| 104 | + /* This function is the same as qpdfjob_initialize_from_argv except argv is encoded with wide | |
| 105 | + * characters. This would be suitable for calling from a Windows wmain function. | |
| 120 | 106 | */ |
| 121 | 107 | QPDF_DLL |
| 122 | 108 | int qpdfjob_initialize_from_wide_argv(qpdfjob_handle j, wchar_t const* const argv[]); |
| 123 | 109 | #endif /* QPDF_NO_WCHAR_T */ |
| 124 | 110 | |
| 125 | - /* This function wraps QPDFJob::initializeFromJson. The return | |
| 126 | - * value is the same as qpdfjob_run. If this returns an error, it | |
| 127 | - * is invalid to call any other functions this job handle. | |
| 111 | + /* This function wraps QPDFJob::initializeFromJson. The return value is the same as qpdfjob_run. | |
| 112 | + * If this returns an error, it is invalid to call any other functions using this job handle. | |
| 128 | 113 | */ |
| 129 | 114 | QPDF_DLL |
| 130 | 115 | int qpdfjob_initialize_from_json(qpdfjob_handle j, char const* json); |
| 131 | 116 | |
| 132 | - /* This function wraps QPDFJob::run. It returns the error code | |
| 133 | - * that qpdf would return with the equivalent command-line | |
| 134 | - * invocation. Exit code values are defined in Constants.h in the | |
| 117 | + /* This function wraps QPDFJob::run. It returns the error code that qpdf would return with the | |
| 118 | + * equivalent command-line invocation. Exit code values are defined in Constants.h in the | |
| 135 | 119 | * qpdf_exit_code_e type. |
| 136 | 120 | */ |
| 137 | 121 | QPDF_DLL |
| 138 | 122 | int qpdfjob_run(qpdfjob_handle j); |
| 139 | 123 | |
| 140 | - /* The following two functions allow a job to be run in two stages - | |
| 141 | - * creation of a qpdf_data object and writing of the qpdf_data object. This | |
| 142 | - * allows the qpdf_data object to be modified prior to writing it out. See | |
| 143 | - * examples/qpdfjob-remove-annotations for a C++ illustration of its use. | |
| 124 | + /* The following two functions allow a job to be run in two stages - creation of a qpdf_data | |
| 125 | + * object and writing of the qpdf_data object. This allows the qpdf_data object to be modified | |
| 126 | + * prior to writing it out. See examples/qpdfjob-remove-annotations for a C++ illustration of | |
| 127 | + * its use. | |
| 144 | 128 | * |
| 145 | - * This function wraps QPDFJob::createQPDF. It runs the first stage of the | |
| 146 | - * job. A nullptr is returned if the job did not produce any pdf file to be | |
| 147 | - * written. | |
| 129 | + * This function wraps QPDFJob::createQPDF. It runs the first stage of the job. A nullptr is | |
| 130 | + * returned if the job did not produce any pdf file to be written. | |
| 148 | 131 | */ |
| 149 | 132 | QPDF_DLL |
| 150 | 133 | qpdf_data qpdfjob_create_qpdf(qpdfjob_handle j); |
| 151 | 134 | |
| 152 | - /* This function wraps QPDFJob::writeQPDF. It returns the error code that | |
| 153 | - * qpdf would return with the equivalent command-line invocation. Exit code | |
| 154 | - * values are defined in Constants.h in the qpdf_exit_code_e type. NOTE it | |
| 155 | - * is the callers responsibility to clean up the resources associated | |
| 156 | - * qpdf_data object by calling qpdf_cleanup after the call to | |
| 135 | + /* This function wraps QPDFJob::writeQPDF. It returns the error code that qpdf would return with | |
| 136 | + * the equivalent command-line invocation. Exit code values are defined in Constants.h in the | |
| 137 | + * qpdf_exit_code_e type. NOTE it is the callers responsibility to clean up the resources | |
| 138 | + * associated with the qpdf_data object by calling qpdf_cleanup after the call to | |
| 157 | 139 | * qpdfjob_write_qpdf. |
| 158 | 140 | */ |
| 159 | 141 | QPDF_DLL |
| 160 | 142 | int qpdfjob_write_qpdf(qpdfjob_handle j, qpdf_data qpdf); |
| 161 | 143 | |
| 162 | - /* Allow specification of a custom progress reporter. The progress | |
| 163 | - * reporter is only used if progress is otherwise requested (with | |
| 164 | - * the --progress option or "progress": "" in the JSON). | |
| 144 | + /* Allow specification of a custom progress reporter. The progress reporter is only used if | |
| 145 | + * progress is otherwise requested (with the --progress option or "progress": "" in the JSON). | |
| 165 | 146 | */ |
| 166 | 147 | QPDF_DLL |
| 167 | 148 | void qpdfjob_register_progress_reporter( | ... | ... |
include/qpdf/qpdflogger-c.h
| ... | ... | @@ -2,30 +2,26 @@ |
| 2 | 2 | * |
| 3 | 3 | * This file is part of qpdf. |
| 4 | 4 | * |
| 5 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | - * you may not use this file except in compliance with the License. | |
| 7 | - * You may obtain a copy of the License at | |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 6 | + * in compliance with the License. You may obtain a copy of the License at | |
| 8 | 7 | * |
| 9 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | 9 | * |
| 11 | - * Unless required by applicable law or agreed to in writing, software | |
| 12 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | - * See the License for the specific language governing permissions and | |
| 15 | - * limitations under the License. | |
| 10 | + * Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 11 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | + * or implied. See the License for the specific language governing permissions and limitations under | |
| 13 | + * the License. | |
| 16 | 14 | * |
| 17 | - * Versions of qpdf prior to version 7 were released under the terms | |
| 18 | - * of version 2.0 of the Artistic License. At your option, you may | |
| 19 | - * continue to consider qpdf to be licensed under those terms. Please | |
| 20 | - * see the manual for additional information. | |
| 15 | + * Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic | |
| 16 | + * License. At your option, you may continue to consider qpdf to be licensed under those terms. | |
| 17 | + * Please see the manual for additional information. | |
| 21 | 18 | */ |
| 22 | 19 | |
| 23 | 20 | #ifndef QPDFLOGGER_H |
| 24 | 21 | #define QPDFLOGGER_H |
| 25 | 22 | |
| 26 | 23 | /* |
| 27 | - * This file provides a C API for QPDFLogger. See QPDFLogger.hh for | |
| 28 | - * information about the logger and | |
| 24 | + * This file provides a C API for QPDFLogger. See QPDFLogger.hh for information about the logger and | |
| 29 | 25 | * examples/qpdfjob-c-save-attachment.c for an example. |
| 30 | 26 | */ |
| 31 | 27 | |
| ... | ... | @@ -36,26 +32,21 @@ |
| 36 | 32 | extern "C" { |
| 37 | 33 | #endif |
| 38 | 34 | |
| 39 | - /* To operate on a logger, you need a handle to it. call | |
| 40 | - * qpdflogger_default_logger to get a handle for the default | |
| 41 | - * logger. There are functions in qpdf-c.h and qpdfjob-c.h that | |
| 42 | - * also take or return logger handles. When you're done with the | |
| 43 | - * logger handler, call qpdflogger_cleanup. This cleans up the | |
| 44 | - * handle but leaves the underlying log object intact. (It uses a | |
| 45 | - * shared pointer and will be cleaned up automatically when it is | |
| 46 | - * no longer in use.) That means you can create a logger with | |
| 47 | - * qpdflogger_create(), pass the logger handle to a function in | |
| 48 | - * qpdf-c.h or qpdfjob-c.h, and then clean it up, subject to | |
| 49 | - * constraints imposed by the other function. | |
| 35 | + /* To operate on a logger, you need a handle to it. call qpdflogger_default_logger to get a | |
| 36 | + * handle for the default logger. There are functions in qpdf-c.h and qpdfjob-c.h that also take | |
| 37 | + * or return logger handles. When you're done with the logger handler, call qpdflogger_cleanup. | |
| 38 | + * This cleans up the handle but leaves the underlying log object intact. (It uses a shared | |
| 39 | + * pointer and will be cleaned up automatically when it is no longer in use.) That means you can | |
| 40 | + * create a logger with qpdflogger_create(), pass the logger handle to a function in qpdf-c.h or | |
| 41 | + * qpdfjob-c.h, and then clean it up, subject to constraints imposed by the other function. | |
| 50 | 42 | */ |
| 51 | 43 | |
| 52 | 44 | typedef struct _qpdflogger_handle* qpdflogger_handle; |
| 53 | 45 | QPDF_DLL |
| 54 | 46 | qpdflogger_handle qpdflogger_default_logger(); |
| 55 | 47 | |
| 56 | - /* Calling cleanup on the handle returned by qpdflogger_create | |
| 57 | - * destroys the handle but not the underlying logger. See comments | |
| 58 | - * above. | |
| 48 | + /* Calling cleanup on the handle returned by qpdflogger_create destroys the handle but not the | |
| 49 | + * underlying logger. See comments above. | |
| 59 | 50 | */ |
| 60 | 51 | QPDF_DLL |
| 61 | 52 | qpdflogger_handle qpdflogger_create(); |
| ... | ... | @@ -84,8 +75,8 @@ extern "C" { |
| 84 | 75 | void qpdflogger_set_error( |
| 85 | 76 | qpdflogger_handle l, enum qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata); |
| 86 | 77 | |
| 87 | - /* A non-zero value for only_if_not_set means that the save | |
| 88 | - * pipeline will only be changed if it is not already set. | |
| 78 | + /* A non-zero value for only_if_not_set means that the save pipeline will only be changed if it | |
| 79 | + * is not already set. | |
| 89 | 80 | */ |
| 90 | 81 | QPDF_DLL |
| 91 | 82 | void qpdflogger_set_save( | ... | ... |
libqpdf/ClosedFileInputSource.cc
| ... | ... | @@ -11,8 +11,7 @@ ClosedFileInputSource::ClosedFileInputSource(char const* filename) : |
| 11 | 11 | |
| 12 | 12 | ClosedFileInputSource::~ClosedFileInputSource() |
| 13 | 13 | { |
| 14 | - // Must be explicit and not inline -- see QPDF_DLL_CLASS in | |
| 15 | - // README-maintainer | |
| 14 | + // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer | |
| 16 | 15 | } |
| 17 | 16 | |
| 18 | 17 | void |
| ... | ... | @@ -91,8 +90,7 @@ ClosedFileInputSource::unreadCh(char ch) |
| 91 | 90 | { |
| 92 | 91 | before(); |
| 93 | 92 | this->fis->unreadCh(ch); |
| 94 | - // Don't call after -- the file has to stay open after this | |
| 95 | - // operation. | |
| 93 | + // Don't call after -- the file has to stay open after this operation. | |
| 96 | 94 | } |
| 97 | 95 | |
| 98 | 96 | void | ... | ... |
libqpdf/ContentNormalizer.cc
| ... | ... | @@ -41,9 +41,8 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token) |
| 41 | 41 | break; |
| 42 | 42 | |
| 43 | 43 | case QPDFTokenizer::tt_string: |
| 44 | - // Replacing string and name tokens in this way normalizes | |
| 45 | - // their representation as this will automatically handle | |
| 46 | - // quoting of unprintable characters, etc. | |
| 44 | + // Replacing string and name tokens in this way normalizes their representation as this will | |
| 45 | + // automatically handle quoting of unprintable characters, etc. | |
| 47 | 46 | writeToken(QPDFTokenizer::Token(QPDFTokenizer::tt_string, token.getValue())); |
| 48 | 47 | break; |
| 49 | 48 | ... | ... |
libqpdf/FileInputSource.cc
| ... | ... | @@ -27,8 +27,7 @@ FileInputSource::FileInputSource(char const* description, FILE* filep, bool clos |
| 27 | 27 | |
| 28 | 28 | FileInputSource::~FileInputSource() |
| 29 | 29 | { |
| 30 | - // Must be explicit and not inline -- see QPDF_DLL_CLASS in | |
| 31 | - // README-maintainer | |
| 30 | + // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer | |
| 32 | 31 | if (this->file && this->close_file) { |
| 33 | 32 | fclose(this->file); |
| 34 | 33 | } |
| ... | ... | @@ -68,8 +67,7 @@ FileInputSource::findAndSkipNextEOL() |
| 68 | 67 | char* p = (p1 && p2) ? std::min(p1, p2) : p1 ? p1 : p2; |
| 69 | 68 | if (p) { |
| 70 | 69 | result = cur_offset + (p - buf); |
| 71 | - // We found \r or \n. Keep reading until we get past | |
| 72 | - // \r and \n characters. | |
| 70 | + // We found \r or \n. Keep reading until we get past \r and \n characters. | |
| 73 | 71 | this->seek(result + 1, SEEK_SET); |
| 74 | 72 | char ch; |
| 75 | 73 | while (!done) { | ... | ... |
libqpdf/InputSource.cc
| ... | ... | @@ -20,12 +20,10 @@ InputSource::getLastOffset() const |
| 20 | 20 | std::string |
| 21 | 21 | InputSource::readLine(size_t max_line_length) |
| 22 | 22 | { |
| 23 | - // Return at most max_line_length characters from the next line. | |
| 24 | - // Lines are terminated by one or more \r or \n characters. | |
| 25 | - // Consume the trailing newline characters but don't return them. | |
| 26 | - // After this is called, the file will be positioned after a line | |
| 27 | - // terminator or at the end of the file, and last_offset will | |
| 28 | - // point to position the file had when this method was called. | |
| 23 | + // Return at most max_line_length characters from the next line. Lines are terminated by one or | |
| 24 | + // more \r or \n characters. Consume the trailing newline characters but don't return them. | |
| 25 | + // After this is called, the file will be positioned after a line terminator or at the end of | |
| 26 | + // the file, and last_offset will point to position the file had when this method was called. | |
| 29 | 27 | |
| 30 | 28 | qpdf_offset_t offset = this->tell(); |
| 31 | 29 | auto bp = std::make_unique<char[]>(max_line_length + 1); |
| ... | ... | @@ -45,22 +43,18 @@ InputSource::readLine(size_t max_line_length) |
| 45 | 43 | bool |
| 46 | 44 | InputSource::findFirst(char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder) |
| 47 | 45 | { |
| 48 | - // Basic approach: search for the first character of start_chars | |
| 49 | - // starting from offset but not going past len (if len != 0). Once | |
| 50 | - // the first character is found, see if it is the beginning of a | |
| 51 | - // sequence of characters matching start_chars. If so, call | |
| 52 | - // finder.check() to do caller-specific additional checks. If not, | |
| 53 | - // keep searching. | |
| 46 | + // Basic approach: search for the first character of start_chars starting from offset but not | |
| 47 | + // going past len (if len != 0). Once the first character is found, see if it is the beginning | |
| 48 | + // of a sequence of characters matching start_chars. If so, call finder.check() to do | |
| 49 | + // caller-specific additional checks. If not, keep searching. | |
| 54 | 50 | |
| 55 | - // This code is tricky and highly subject to off-by-one or other | |
| 56 | - // edge case logic errors. See comments throughout that explain | |
| 57 | - // how we're not missing any edge cases. There are also tests | |
| 58 | - // specifically constructed to make sure we caught the edge cases | |
| 59 | - // in testing. | |
| 51 | + // This code is tricky and highly subject to off-by-one or other edge case logic errors. See | |
| 52 | + // comments throughout that explain how we're not missing any edge cases. There are also tests | |
| 53 | + // specifically constructed to make sure we caught the edge cases in testing. | |
| 60 | 54 | |
| 61 | 55 | char buf[1025]; // size known to input_source.cc in libtests |
| 62 | - // To enable us to guarantee null-termination, save an extra byte | |
| 63 | - // so that buf[size] is valid memory. | |
| 56 | + // To enable us to guarantee null-termination, save an extra byte so that buf[size] is valid | |
| 57 | + // memory. | |
| 64 | 58 | size_t size = sizeof(buf) - 1; |
| 65 | 59 | if ((strlen(start_chars) < 1) || (strlen(start_chars) > size)) { |
| 66 | 60 | throw std::logic_error("InputSource::findSource called with" |
| ... | ... | @@ -71,19 +65,15 @@ InputSource::findFirst(char const* start_chars, qpdf_offset_t offset, size_t len |
| 71 | 65 | qpdf_offset_t buf_offset = offset; |
| 72 | 66 | size_t bytes_read = 0; |
| 73 | 67 | |
| 74 | - // Guarantee that we return from this loop. Each time through, we | |
| 75 | - // either return, advance p, or restart the loop with a condition | |
| 76 | - // that will cause return on the next pass. Eventually we will | |
| 77 | - // either be out of range or hit EOF, either of which forces us to | |
| 78 | - // return. | |
| 68 | + // Guarantee that we return from this loop. Each time through, we either return, advance p, or | |
| 69 | + // restart the loop with a condition that will cause return on the next pass. Eventually we will | |
| 70 | + // either be out of range or hit EOF, either of which forces us to return. | |
| 79 | 71 | while (true) { |
| 80 | - // Do we need to read more data? Pretend size = 5, buf starts | |
| 81 | - // at 0, and start_chars has 3 characters. buf[5] is valid and | |
| 82 | - // null. If p == 2, start_chars could be buf[2] through | |
| 83 | - // buf[4], so p + strlen(start_chars) == buf + size is okay. | |
| 84 | - // If p points to buf[size], since strlen(start_chars) is | |
| 85 | - // always >= 1, this overflow test will be correct for that | |
| 86 | - // case regardless of start_chars. | |
| 72 | + // Do we need to read more data? Pretend size = 5, buf starts at 0, and start_chars has 3 | |
| 73 | + // characters. buf[5] is valid and null. If p == 2, start_chars could be buf[2] through | |
| 74 | + // buf[4], so p + strlen(start_chars) == buf + size is okay. If p points to buf[size], since | |
| 75 | + // strlen(start_chars) is always >= 1, this overflow test will be correct for that case | |
| 76 | + // regardless of start_chars. | |
| 87 | 77 | if ((p == nullptr) || ((p + strlen(start_chars)) > (buf + bytes_read))) { |
| 88 | 78 | if (p) { |
| 89 | 79 | QTC::TC( |
| ... | ... | @@ -91,9 +81,8 @@ InputSource::findFirst(char const* start_chars, qpdf_offset_t offset, size_t len |
| 91 | 81 | buf_offset += (p - buf); |
| 92 | 82 | } |
| 93 | 83 | this->seek(buf_offset, SEEK_SET); |
| 94 | - // Read into buffer and zero out the rest of the buffer | |
| 95 | - // including buf[size]. We allocated an extra byte so that | |
| 96 | - // we could guarantee null termination as an extra | |
| 84 | + // Read into buffer and zero out the rest of the buffer including buf[size]. We | |
| 85 | + // allocated an extra byte so that we could guarantee null termination as an extra | |
| 97 | 86 | // protection against overrun when using string functions. |
| 98 | 87 | bytes_read = this->read(buf, size); |
| 99 | 88 | if (bytes_read < strlen(start_chars)) { |
| ... | ... | @@ -122,19 +111,16 @@ InputSource::findFirst(char const* start_chars, qpdf_offset_t offset, size_t len |
| 122 | 111 | } |
| 123 | 112 | } |
| 124 | 113 | if ((p + strlen(start_chars)) > (buf + bytes_read)) { |
| 125 | - // If there are not enough bytes left in the file for | |
| 126 | - // start_chars, we will detect this on the next pass | |
| 127 | - // as EOF and return. | |
| 114 | + // If there are not enough bytes left in the file for start_chars, we will detect | |
| 115 | + // this on the next pass as EOF and return. | |
| 128 | 116 | QTC::TC("libtests", "InputSource not enough bytes"); |
| 129 | 117 | continue; |
| 130 | 118 | } |
| 131 | 119 | |
| 132 | - // See if p points to a sequence matching start_chars. We | |
| 133 | - // already checked above to make sure we are not going to | |
| 134 | - // overrun memory. | |
| 120 | + // See if p points to a sequence matching start_chars. We already checked above to make | |
| 121 | + // sure we are not going to overrun memory. | |
| 135 | 122 | if (strncmp(p, start_chars, strlen(start_chars)) == 0) { |
| 136 | - // Call finder.check() with the input source | |
| 137 | - // positioned to the point of the match. | |
| 123 | + // Call finder.check() with the input source positioned to the point of the match. | |
| 138 | 124 | this->seek(buf_offset + (p - buf), SEEK_SET); |
| 139 | 125 | if (finder.check()) { |
| 140 | 126 | return true; |
| ... | ... | @@ -144,8 +130,8 @@ InputSource::findFirst(char const* start_chars, qpdf_offset_t offset, size_t len |
| 144 | 130 | } else { |
| 145 | 131 | QTC::TC("libtests", "InputSource first char matched but not string"); |
| 146 | 132 | } |
| 147 | - // This occurrence of the first character wasn't a match. | |
| 148 | - // Skip over it and keep searching. | |
| 133 | + // This occurrence of the first character wasn't a match. Skip over it and keep | |
| 134 | + // searching. | |
| 149 | 135 | ++p; |
| 150 | 136 | } else { |
| 151 | 137 | // Trigger reading the next block | ... | ... |
libqpdf/InsecureRandomDataProvider.cc
| ... | ... | @@ -21,9 +21,8 @@ long |
| 21 | 21 | InsecureRandomDataProvider::random() |
| 22 | 22 | { |
| 23 | 23 | if (!this->seeded_random) { |
| 24 | - // Seed the random number generator with something simple, but | |
| 25 | - // just to be interesting, don't use the unmodified current | |
| 26 | - // time. It would be better if this were a more secure seed. | |
| 24 | + // Seed the random number generator with something simple, but just to be interesting, don't | |
| 25 | + // use the unmodified current time. It would be better if this were a more secure seed. | |
| 27 | 26 | auto seed = static_cast<unsigned int>(QUtil::get_current_time() ^ 0xcccc); |
| 28 | 27 | #ifdef HAVE_RANDOM |
| 29 | 28 | ::srandom(seed); | ... | ... |
libqpdf/JSONHandler.cc
| ... | ... | @@ -133,12 +133,10 @@ JSONHandler::handle(std::string const& path, JSON j) |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | if (!handled) { |
| 136 | - // It would be nice to include information about what type the | |
| 137 | - // object was and what types were allowed, but we're relying | |
| 138 | - // on schema validation to make sure input is properly | |
| 139 | - // structured before calling the handlers. It would be | |
| 140 | - // different if this code were trying to be part of a | |
| 141 | - // general-purpose JSON package. | |
| 136 | + // It would be nice to include information about what type the object was and what types | |
| 137 | + // were allowed, but we're relying on schema validation to make sure input is properly | |
| 138 | + // structured before calling the handlers. It would be different if this code were trying to | |
| 139 | + // be part of a general-purpose JSON package. | |
| 142 | 140 | QTC::TC("libtests", "JSONHandler unhandled value"); |
| 143 | 141 | usage("JSON handler: value at " + path + " is not of expected type"); |
| 144 | 142 | } | ... | ... |
libqpdf/MD5.cc
| ... | ... | @@ -78,8 +78,7 @@ MD5::encodeFile(char const* filename, qpdf_offset_t up_to_offset) |
| 78 | 78 | } |
| 79 | 79 | } while (len > 0); |
| 80 | 80 | if (ferror(file)) { |
| 81 | - // Assume, perhaps incorrectly, that errno was set by the | |
| 82 | - // underlying call to read.... | |
| 81 | + // Assume, perhaps incorrectly, that errno was set by the underlying call to read.... | |
| 83 | 82 | (void)fclose(file); |
| 84 | 83 | QUtil::throw_system_error(std::string("MD5: read error on ") + filename); |
| 85 | 84 | } | ... | ... |
libqpdf/NNTree.cc
| ... | ... | @@ -36,23 +36,18 @@ NNTreeIterator::NNTreeIterator(NNTreeImpl& impl) : |
| 36 | 36 | void |
| 37 | 37 | NNTreeIterator::updateIValue(bool allow_invalid) |
| 38 | 38 | { |
| 39 | - // ivalue should never be used inside the class since we return a | |
| 40 | - // pointer/reference to it. Every bit of code that ever changes | |
| 41 | - // what object the iterator points to should take care to call | |
| 42 | - // updateIValue. Failure to do this means that any old references | |
| 43 | - // to *iter will point to incorrect objects, though the next | |
| 44 | - // dereference of the iterator will fix it. This isn't necessarily | |
| 45 | - // catastrophic, but it would be confusing. The test suite | |
| 46 | - // attempts to exercise various cases to ensure we don't introduce | |
| 47 | - // that bug in the future, but sadly it's tricky to verify by | |
| 48 | - // reasoning about the code that this constraint is always | |
| 49 | - // satisfied. Whenever we update what the iterator points to, we | |
| 50 | - // should call setItemNumber, which calls this. If we change what | |
| 51 | - // the iterator in some other way, such as replacing a value or | |
| 52 | - // removing an item and making the iterator point at a different | |
| 53 | - // item in potentially the same position, we must call | |
| 54 | - // updateIValue as well. These cases are handled, and for good | |
| 55 | - // measure, we also call updateIValue in operator* and operator->. | |
| 39 | + // ivalue should never be used inside the class since we return a pointer/reference to it. Every | |
| 40 | + // bit of code that ever changes what object the iterator points to should take care to call | |
| 41 | + // updateIValue. Failure to do this means that any old references to *iter will point to | |
| 42 | + // incorrect objects, though the next dereference of the iterator will fix it. This isn't | |
| 43 | + // necessarily catastrophic, but it would be confusing. The test suite attempts to exercise | |
| 44 | + // various cases to ensure we don't introduce that bug in the future, but sadly it's tricky to | |
| 45 | + // verify by reasoning about the code that this constraint is always satisfied. Whenever we | |
| 46 | + // update what the iterator points to, we should call setItemNumber, which calls this. If we | |
| 47 | + // change what the iterator points to in some other way, such as replacing a value or removing | |
| 48 | + // an item and making the iterator point at a different item in potentially the same position, | |
| 49 | + // we must call updateIValue as well. These cases are handled, and for good measure, we also | |
| 50 | + // call updateIValue in operator* and operator->. | |
| 56 | 51 | |
| 57 | 52 | bool okay = false; |
| 58 | 53 | if ((item_number >= 0) && this->node.isDictionary()) { |
| ... | ... | @@ -228,12 +223,11 @@ NNTreeIterator::resetLimits(QPDFObjectHandle node, std::list<PathElement>::itera |
| 228 | 223 | void |
| 229 | 224 | NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterator parent) |
| 230 | 225 | { |
| 231 | - // Split some node along the path to the item pointed to by this | |
| 232 | - // iterator, and adjust the iterator so it points to the same | |
| 233 | - // item. | |
| 226 | + // Split some node along the path to the item pointed to by this iterator, and adjust the | |
| 227 | + // iterator so it points to the same item. | |
| 234 | 228 | |
| 235 | - // In examples, for simplicity, /Nums is show to just contain | |
| 236 | - // numbers instead of pairs. Imagine this tree: | |
| 229 | + // In examples, for simplicity, /Nums is shown to just contain numbers instead of pairs. Imagine | |
| 230 | + // this tree: | |
| 237 | 231 | // |
| 238 | 232 | // root: << /Kids [ A B C D ] >> |
| 239 | 233 | // A: << /Nums [ 1 2 3 4 ] >> |
| ... | ... | @@ -260,8 +254,7 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterato |
| 260 | 254 | throw std::logic_error("NNTreeIterator::split called an invalid iterator"); |
| 261 | 255 | } |
| 262 | 256 | |
| 263 | - // Find the array we actually need to split, which is either this | |
| 264 | - // node's kids or items. | |
| 257 | + // Find the array we actually need to split, which is either this node's kids or items. | |
| 265 | 258 | auto kids = to_split.getKey("/Kids"); |
| 266 | 259 | int nkids = kids.isArray() ? kids.getArrayNItems() : 0; |
| 267 | 260 | auto items = to_split.getKey(impl.details.itemsKey()); |
| ... | ... | @@ -294,30 +287,22 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterato |
| 294 | 287 | bool is_root = (parent == this->path.end()); |
| 295 | 288 | bool is_leaf = (nitems > 0); |
| 296 | 289 | |
| 297 | - // CURRENT STATE: tree is in original state; iterator is valid and | |
| 298 | - // unchanged. | |
| 290 | + // CURRENT STATE: tree is in original state; iterator is valid and unchanged. | |
| 299 | 291 | |
| 300 | 292 | if (is_root) { |
| 301 | - // What we want to do is to create a new node for the second | |
| 302 | - // half of the items and put it in the parent's /Kids array | |
| 303 | - // right after the element that points to the current to_split | |
| 304 | - // node, but if we're splitting root, there is no parent, so | |
| 305 | - // handle that first. | |
| 306 | - | |
| 307 | - // In the non-root case, parent points to the path element | |
| 308 | - // whose /Kids contains the first half node, and the first | |
| 309 | - // half node is to_split. If we are splitting the root, we | |
| 310 | - // need to push everything down a level, but we want to keep | |
| 311 | - // the actual root object the same so that indirect references | |
| 312 | - // to it remain intact (and also in case it might be a direct | |
| 313 | - // object, which it shouldn't be but that case probably exists | |
| 314 | - // in the wild). To achieve this, we create a new node for the | |
| 315 | - // first half and then replace /Kids in the root to contain | |
| 316 | - // it. Then we adjust the path so that the first element is | |
| 317 | - // root and the second element, if any, is the new first half. | |
| 318 | - // In this way, we make the root case identical to the | |
| 319 | - // non-root case so remaining logic can handle them in the | |
| 320 | - // same way. | |
| 293 | + // What we want to do is to create a new node for the second half of the items and put it in | |
| 294 | + // the parent's /Kids array right after the element that points to the current to_split | |
| 295 | + // node, but if we're splitting root, there is no parent, so handle that first. | |
| 296 | + | |
| 297 | + // In the non-root case, parent points to the path element whose /Kids contains the first | |
| 298 | + // half node, and the first half node is to_split. If we are splitting the root, we need to | |
| 299 | + // push everything down a level, but we want to keep the actual root object the same so that | |
| 300 | + // indirect references to it remain intact (and also in case it might be a direct object, | |
| 301 | + // which it shouldn't be but that case probably exists in the wild). To achieve this, we | |
| 302 | + // create a new node for the first half and then replace /Kids in the root to contain it. | |
| 303 | + // Then we adjust the path so that the first element is root and the second element, if any, | |
| 304 | + // is the new first half. In this way, we make the root case identical to the non-root case | |
| 305 | + // so remaining logic can handle them in the same way. | |
| 321 | 306 | |
| 322 | 307 | auto first_node = impl.qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary()); |
| 323 | 308 | first_node.replaceKey(key, first_half); |
| ... | ... | @@ -339,12 +324,11 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterato |
| 339 | 324 | to_split = first_node; |
| 340 | 325 | } |
| 341 | 326 | |
| 342 | - // CURRENT STATE: parent is guaranteed to be defined, and we have | |
| 343 | - // the invariants that parent[/Kids][kid_number] == to_split and | |
| 344 | - // (++parent).node == to_split. | |
| 327 | + // CURRENT STATE: parent is guaranteed to be defined, and we have the invariants that | |
| 328 | + // parent[/Kids][kid_number] == to_split and (++parent).node == to_split. | |
| 345 | 329 | |
| 346 | - // Create a second half array, and transfer the second half of the | |
| 347 | - // items into the second half array. | |
| 330 | + // Create a second half array, and transfer the second half of the items into the second half | |
| 331 | + // array. | |
| 348 | 332 | QPDFObjectHandle second_half = QPDFObjectHandle::newArray(); |
| 349 | 333 | int start_idx = ((n / 2) & ~1); |
| 350 | 334 | while (first_half.getArrayNItems() > start_idx) { |
| ... | ... | @@ -358,15 +342,13 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterato |
| 358 | 342 | second_node.replaceKey(key, second_half); |
| 359 | 343 | resetLimits(second_node, parent); |
| 360 | 344 | |
| 361 | - // CURRENT STATE: half the items from the kids or items array in | |
| 362 | - // the node being split have been moved into a new node. The new | |
| 363 | - // node is not yet attached to the tree. The iterator may have a | |
| 345 | + // CURRENT STATE: half the items from the kids or items array in the node being split have been | |
| 346 | + // moved into a new node. The new node is not yet attached to the tree. The iterator may have a | |
| 364 | 347 | // path element or leaf node that is out of bounds. |
| 365 | 348 | |
| 366 | - // We need to adjust the parent to add the second node to /Kids | |
| 367 | - // and, if needed, update kid_number to traverse through it. We | |
| 368 | - // need to update to_split's path element, or the node if this is | |
| 369 | - // a leaf, so that the kid/item number points to the right place. | |
| 349 | + // We need to adjust the parent to add the second node to /Kids and, if needed, update | |
| 350 | + // kid_number to traverse through it. We need to update to_split's path element, or the node if | |
| 351 | + // this is a leaf, so that the kid/item number points to the right place. | |
| 370 | 352 | |
| 371 | 353 | auto parent_kids = parent->node.getKey("/Kids"); |
| 372 | 354 | parent_kids.insertItem(parent->kid_number + 1, second_node); |
| ... | ... | @@ -430,8 +412,7 @@ NNTreeIterator::insertAfter(QPDFObjectHandle key, QPDFObjectHandle value) |
| 430 | 412 | void |
| 431 | 413 | NNTreeIterator::remove() |
| 432 | 414 | { |
| 433 | - // Remove this item, leaving the tree valid and this iterator | |
| 434 | - // pointing to the next item. | |
| 415 | + // Remove this item, leaving the tree valid and this iterator pointing to the next item. | |
| 435 | 416 | |
| 436 | 417 | if (!valid()) { |
| 437 | 418 | throw std::logic_error("attempt made to remove an invalid iterator"); |
| ... | ... | @@ -450,34 +431,32 @@ NNTreeIterator::remove() |
| 450 | 431 | // There are still items left |
| 451 | 432 | |
| 452 | 433 | if ((this->item_number == 0) || (this->item_number == nitems)) { |
| 453 | - // We removed either the first or last item of an items array | |
| 454 | - // that remains non-empty, so we have to adjust limits. | |
| 434 | + // We removed either the first or last item of an items array that remains non-empty, so | |
| 435 | + // we have to adjust limits. | |
| 455 | 436 | QTC::TC("qpdf", "NNTree remove reset limits"); |
| 456 | 437 | resetLimits(this->node, lastPathElement()); |
| 457 | 438 | } |
| 458 | 439 | |
| 459 | 440 | if (this->item_number == nitems) { |
| 460 | - // We removed the last item of a non-empty items array, so | |
| 461 | - // advance to the successor of the previous item. | |
| 441 | + // We removed the last item of a non-empty items array, so advance to the successor of | |
| 442 | + // the previous item. | |
| 462 | 443 | QTC::TC("qpdf", "NNTree erased last item"); |
| 463 | 444 | this->item_number -= 2; |
| 464 | 445 | increment(false); |
| 465 | 446 | } else if (this->item_number < nitems) { |
| 466 | - // We don't have to do anything since the removed item's | |
| 467 | - // successor now occupies its former location. | |
| 447 | + // We don't have to do anything since the removed item's successor now occupies its | |
| 448 | + // former location. | |
| 468 | 449 | QTC::TC("qpdf", "NNTree erased non-last item"); |
| 469 | 450 | updateIValue(); |
| 470 | 451 | } else { |
| 471 | - // We already checked to ensure this condition would not | |
| 472 | - // happen. | |
| 452 | + // We already checked to ensure this condition would not happen. | |
| 473 | 453 | throw std::logic_error("NNTreeIterator::remove: item_number > nitems after erase"); |
| 474 | 454 | } |
| 475 | 455 | return; |
| 476 | 456 | } |
| 477 | 457 | |
| 478 | 458 | if (this->path.empty()) { |
| 479 | - // Special case: if this is the root node, we can leave it | |
| 480 | - // empty. | |
| 459 | + // Special case: if this is the root node, we can leave it empty. | |
| 481 | 460 | QTC::TC("qpdf", "NNTree erased all items on leaf/root"); |
| 482 | 461 | setItemNumber(impl.oh, -1); |
| 483 | 462 | return; |
| ... | ... | @@ -485,9 +464,8 @@ NNTreeIterator::remove() |
| 485 | 464 | |
| 486 | 465 | QTC::TC("qpdf", "NNTree items is empty after remove"); |
| 487 | 466 | |
| 488 | - // We removed the last item from this items array, so we need to | |
| 489 | - // remove this node from the parent on up the tree. Then we need | |
| 490 | - // to position ourselves at the removed item's successor. | |
| 467 | + // We removed the last item from this items array, so we need to remove this node from the | |
| 468 | + // parent on up the tree. Then we need to position ourselves at the removed item's successor. | |
| 491 | 469 | bool done = false; |
| 492 | 470 | while (!done) { |
| 493 | 471 | auto element = lastPathElement(); |
| ... | ... | @@ -503,8 +481,7 @@ NNTreeIterator::remove() |
| 503 | 481 | resetLimits(element->node, parent); |
| 504 | 482 | } |
| 505 | 483 | if (element->kid_number == nkids) { |
| 506 | - // Move to the successor of the last child of the | |
| 507 | - // previous kid. | |
| 484 | + // Move to the successor of the last child of the previous kid. | |
| 508 | 485 | setItemNumber(QPDFObjectHandle(), -1); |
| 509 | 486 | --element->kid_number; |
| 510 | 487 | deepen(kids.getArrayItem(element->kid_number), false, true); |
| ... | ... | @@ -523,8 +500,7 @@ NNTreeIterator::remove() |
| 523 | 500 | } |
| 524 | 501 | done = true; |
| 525 | 502 | } else if (parent == this->path.end()) { |
| 526 | - // We erased the very last item. Convert the root to an | |
| 527 | - // empty items array. | |
| 503 | + // We erased the very last item. Convert the root to an empty items array. | |
| 528 | 504 | QTC::TC("qpdf", "NNTree non-flat tree is empty after remove"); |
| 529 | 505 | element->node.removeKey("/Kids"); |
| 530 | 506 | element->node.replaceKey(impl.details.itemsKey(), QPDFObjectHandle::newArray()); |
| ... | ... | @@ -608,9 +584,8 @@ NNTreeIterator::addPathElement(QPDFObjectHandle const& node, int kid_number) |
| 608 | 584 | bool |
| 609 | 585 | NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) |
| 610 | 586 | { |
| 611 | - // Starting at this node, descend through the first or last kid | |
| 612 | - // until we reach a node with items. If we succeed, return true; | |
| 613 | - // otherwise return false and leave path alone. | |
| 587 | + // Starting at this node, descend through the first or last kid until we reach a node with | |
| 588 | + // items. If we succeed, return true; otherwise return false and leave path alone. | |
| 614 | 589 | |
| 615 | 590 | auto opath = this->path; |
| 616 | 591 | bool failed = false; | ... | ... |
libqpdf/Pl_AES_PDF.cc
| ... | ... | @@ -98,9 +98,8 @@ Pl_AES_PDF::finish() |
| 98 | 98 | flush(false); |
| 99 | 99 | } |
| 100 | 100 | if (!this->disable_padding) { |
| 101 | - // Pad as described in section 3.5.1 of version 1.7 of the PDF | |
| 102 | - // specification, including providing an entire block of padding | |
| 103 | - // if the input was a multiple of 16 bytes. | |
| 101 | + // Pad as described in section 3.5.1 of version 1.7 of the PDF specification, including | |
| 102 | + // providing an entire block of padding if the input was a multiple of 16 bytes. | |
| 104 | 103 | unsigned char pad = QIntC::to_uchar(this->buf_size - this->offset); |
| 105 | 104 | memset(this->inbuf + this->offset, pad, pad); |
| 106 | 105 | this->offset = this->buf_size; |
| ... | ... | @@ -108,11 +107,9 @@ Pl_AES_PDF::finish() |
| 108 | 107 | } |
| 109 | 108 | } else { |
| 110 | 109 | if (this->offset != this->buf_size) { |
| 111 | - // This is never supposed to happen as the output is | |
| 112 | - // always supposed to be padded. However, we have | |
| 113 | - // encountered files for which the output is not a | |
| 114 | - // multiple of the block size. In this case, pad with | |
| 115 | - // zeroes and hope for the best. | |
| 110 | + // This is never supposed to happen as the output is always supposed to be padded. | |
| 111 | + // However, we have encountered files for which the output is not a multiple of the | |
| 112 | + // block size. In this case, pad with zeroes and hope for the best. | |
| 116 | 113 | if (this->offset >= this->buf_size) { |
| 117 | 114 | throw std::logic_error("buffer overflow in AES encryption" |
| 118 | 115 | " pipeline"); |
| ... | ... | @@ -156,19 +153,19 @@ Pl_AES_PDF::flush(bool strip_padding) |
| 156 | 153 | bool return_after_init = false; |
| 157 | 154 | if (this->cbc_mode) { |
| 158 | 155 | if (encrypt) { |
| 159 | - // Set cbc_block to the initialization vector, and if | |
| 160 | - // not zero, write it to the output stream. | |
| 156 | + // Set cbc_block to the initialization vector, and if not zero, write it to the | |
| 157 | + // output stream. | |
| 161 | 158 | initializeVector(); |
| 162 | 159 | if (!(this->use_zero_iv || this->use_specified_iv)) { |
| 163 | 160 | getNext()->write(this->cbc_block, this->buf_size); |
| 164 | 161 | } |
| 165 | 162 | } else if (this->use_zero_iv || this->use_specified_iv) { |
| 166 | - // Initialize vector with zeroes; zero vector was not | |
| 167 | - // written to the beginning of the input file. | |
| 163 | + // Initialize vector with zeroes; zero vector was not written to the beginning of | |
| 164 | + // the input file. | |
| 168 | 165 | initializeVector(); |
| 169 | 166 | } else { |
| 170 | - // Take the first block of input as the initialization | |
| 171 | - // vector. There's nothing to write at this time. | |
| 167 | + // Take the first block of input as the initialization vector. There's nothing to | |
| 168 | + // write at this time. | |
| 172 | 169 | memcpy(this->cbc_block, this->inbuf, this->buf_size); |
| 173 | 170 | this->offset = 0; |
| 174 | 171 | return_after_init = true; | ... | ... |
libqpdf/Pl_ASCII85Decoder.cc
| ... | ... | @@ -91,8 +91,7 @@ Pl_ASCII85Decoder::flush() |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | QTC::TC("libtests", "Pl_ASCII85Decoder partial flush", (this->pos == 5) ? 0 : 1); |
| 94 | - // Reset before calling getNext()->write in case that throws an | |
| 95 | - // exception. | |
| 94 | + // Reset before calling getNext()->write in case that throws an exception. | |
| 96 | 95 | auto t = this->pos - 1; |
| 97 | 96 | this->pos = 0; |
| 98 | 97 | memset(this->inbuf, 117, 5); | ... | ... |
libqpdf/Pl_ASCIIHexDecoder.cc
| ... | ... | @@ -79,8 +79,7 @@ Pl_ASCIIHexDecoder::flush() |
| 79 | 79 | auto ch = static_cast<unsigned char>((b[0] << 4) + b[1]); |
| 80 | 80 | |
| 81 | 81 | QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush", (this->pos == 2) ? 0 : 1); |
| 82 | - // Reset before calling getNext()->write in case that throws an | |
| 83 | - // exception. | |
| 82 | + // Reset before calling getNext()->write in case that throws an exception. | |
| 84 | 83 | this->pos = 0; |
| 85 | 84 | this->inbuf[0] = '0'; |
| 86 | 85 | this->inbuf[1] = '0'; | ... | ... |
libqpdf/Pl_Concatenate.cc
| ... | ... | @@ -7,8 +7,7 @@ Pl_Concatenate::Pl_Concatenate(char const* identifier, Pipeline* next) : |
| 7 | 7 | |
| 8 | 8 | Pl_Concatenate::~Pl_Concatenate() |
| 9 | 9 | { |
| 10 | - // Must be explicit and not inline -- see QPDF_DLL_CLASS in | |
| 11 | - // README-maintainer | |
| 10 | + // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer | |
| 12 | 11 | } |
| 13 | 12 | |
| 14 | 13 | void | ... | ... |
libqpdf/Pl_Count.cc
| ... | ... | @@ -16,8 +16,7 @@ Pl_Count::Pl_Count(char const* identifier, Pipeline* next) : |
| 16 | 16 | |
| 17 | 17 | Pl_Count::~Pl_Count() |
| 18 | 18 | { |
| 19 | - // Must be explicit and not inline -- see QPDF_DLL_CLASS in | |
| 20 | - // README-maintainer | |
| 19 | + // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer | |
| 21 | 20 | } |
| 22 | 21 | |
| 23 | 22 | void | ... | ... |
libqpdf/Pl_DCT.cc
| ... | ... | @@ -77,8 +77,7 @@ Pl_DCT::Pl_DCT( |
| 77 | 77 | |
| 78 | 78 | Pl_DCT::~Pl_DCT() |
| 79 | 79 | { |
| 80 | - // Must be explicit and not inline -- see QPDF_DLL_CLASS in | |
| 81 | - // README-maintainer | |
| 80 | + // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer | |
| 82 | 81 | } |
| 83 | 82 | |
| 84 | 83 | void |
| ... | ... | @@ -92,14 +91,12 @@ Pl_DCT::finish() |
| 92 | 91 | { |
| 93 | 92 | m->buf.finish(); |
| 94 | 93 | |
| 95 | - // Using a std::shared_ptr<Buffer> here and passing it into compress | |
| 96 | - // and decompress causes a memory leak with setjmp/longjmp. Just | |
| 97 | - // use a pointer and delete it. | |
| 94 | + // Using a std::shared_ptr<Buffer> here and passing it into compress and decompress causes a | |
| 95 | + // memory leak with setjmp/longjmp. Just use a pointer and delete it. | |
| 98 | 96 | Buffer* b = m->buf.getBuffer(); |
| 99 | 97 | if (b->getSize() == 0) { |
| 100 | - // Special case: empty data will never succeed and probably | |
| 101 | - // means we're calling finish a second time from an exception | |
| 102 | - // handler. | |
| 98 | + // Special case: empty data will never succeed and probably means we're calling finish a | |
| 99 | + // second time from an exception handler. | |
| 103 | 100 | delete b; |
| 104 | 101 | this->getNext()->finish(); |
| 105 | 102 | return; |
| ... | ... | @@ -114,8 +111,7 @@ Pl_DCT::finish() |
| 114 | 111 | jerr.pub.error_exit = error_handler; |
| 115 | 112 | |
| 116 | 113 | bool error = false; |
| 117 | - // The jpeg library is a "C" library, so we use setjmp and longjmp | |
| 118 | - // for exception handling. | |
| 114 | + // The jpeg library is a "C" library, so we use setjmp and longjmp for exception handling. | |
| 119 | 115 | if (setjmp(jerr.jmpbuf) == 0) { |
| 120 | 116 | try { |
| 121 | 117 | if (m->action == a_compress) { |
| ... | ... | @@ -124,9 +120,8 @@ Pl_DCT::finish() |
| 124 | 120 | decompress(reinterpret_cast<void*>(&cinfo_decompress), b); |
| 125 | 121 | } |
| 126 | 122 | } catch (std::exception& e) { |
| 127 | - // Convert an exception back to a longjmp so we can ensure | |
| 128 | - // that the right cleanup happens. This will get converted | |
| 129 | - // back to an exception. | |
| 123 | + // Convert an exception back to a longjmp so we can ensure that the right cleanup | |
| 124 | + // happens. This will get converted back to an exception. | |
| 130 | 125 | jerr.msg = e.what(); |
| 131 | 126 | longjmp(jerr.jmpbuf, 1); |
| 132 | 127 | } |
| ... | ... | @@ -205,9 +200,8 @@ init_buffer_source(j_decompress_ptr) |
| 205 | 200 | static boolean |
| 206 | 201 | fill_buffer_input_buffer(j_decompress_ptr) |
| 207 | 202 | { |
| 208 | - // The whole JPEG data is expected to reside in the supplied memory | |
| 209 | - // buffer, so any request for more data beyond the given buffer size | |
| 210 | - // is treated as an error. | |
| 203 | + // The whole JPEG data is expected to reside in the supplied memory buffer, so any request for | |
| 204 | + // more data beyond the given buffer size is treated as an error. | |
| 211 | 205 | throw std::runtime_error("invalid jpeg data reading from buffer"); |
| 212 | 206 | return TRUE; |
| 213 | 207 | } |
| ... | ... | @@ -216,8 +210,8 @@ static void |
| 216 | 210 | skip_buffer_input_data(j_decompress_ptr cinfo, long num_bytes) |
| 217 | 211 | { |
| 218 | 212 | if (num_bytes < 0) { |
| 219 | - throw std::runtime_error("reading jpeg: jpeg library requested" | |
| 220 | - " skipping a negative number of bytes"); | |
| 213 | + throw std::runtime_error( | |
| 214 | + "reading jpeg: jpeg library requested skipping a negative number of bytes"); | |
| 221 | 215 | } |
| 222 | 216 | size_t to_skip = QIntC::to_size(num_bytes); |
| 223 | 217 | if ((to_skip > 0) && (to_skip <= cinfo->src->bytes_in_buffer)) { | ... | ... |
libqpdf/Pl_Discard.cc
| ... | ... | @@ -9,8 +9,7 @@ Pl_Discard::Pl_Discard() : |
| 9 | 9 | |
| 10 | 10 | Pl_Discard::~Pl_Discard() |
| 11 | 11 | { |
| 12 | - // Must be explicit and not inline -- see QPDF_DLL_CLASS in | |
| 13 | - // README-maintainer | |
| 12 | + // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer | |
| 14 | 13 | } |
| 15 | 14 | |
| 16 | 15 | void | ... | ... |
libqpdf/Pl_Flate.cc
| ... | ... | @@ -16,16 +16,14 @@ Pl_Flate::Members::Members(size_t out_bufsize, action_e action) : |
| 16 | 16 | zdata(nullptr) |
| 17 | 17 | { |
| 18 | 18 | this->outbuf = QUtil::make_shared_array<unsigned char>(out_bufsize); |
| 19 | - // Indirect through zdata to reach the z_stream so we don't have | |
| 20 | - // to include zlib.h in Pl_Flate.hh. This means people using | |
| 21 | - // shared library versions of qpdf don't have to have zlib | |
| 22 | - // development files available, which particularly helps in a | |
| 23 | - // Windows environment. | |
| 19 | + // Indirect through zdata to reach the z_stream so we don't have to include zlib.h in | |
| 20 | + // Pl_Flate.hh. This means people using shared library versions of qpdf don't have to have zlib | |
| 21 | + // development files available, which particularly helps in a Windows environment. | |
| 24 | 22 | this->zdata = new z_stream; |
| 25 | 23 | |
| 26 | 24 | if (out_bufsize > UINT_MAX) { |
| 27 | - throw std::runtime_error("Pl_Flate: zlib doesn't support buffer" | |
| 28 | - " sizes larger than unsigned int"); | |
| 25 | + throw std::runtime_error( | |
| 26 | + "Pl_Flate: zlib doesn't support buffer sizes larger than unsigned int"); | |
| 29 | 27 | } |
| 30 | 28 | |
| 31 | 29 | z_stream& zstream = *(static_cast<z_stream*>(this->zdata)); |
| ... | ... | @@ -62,8 +60,7 @@ Pl_Flate::Pl_Flate( |
| 62 | 60 | |
| 63 | 61 | Pl_Flate::~Pl_Flate() |
| 64 | 62 | { |
| 65 | - // Must be explicit and not inline -- see QPDF_DLL_CLASS in | |
| 66 | - // README-maintainer | |
| 63 | + // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer | |
| 67 | 64 | } |
| 68 | 65 | |
| 69 | 66 | void |
| ... | ... | @@ -88,8 +85,7 @@ Pl_Flate::write(unsigned char const* data, size_t len) |
| 88 | 85 | this->identifier + ": Pl_Flate: write() called after finish() called"); |
| 89 | 86 | } |
| 90 | 87 | |
| 91 | - // Write in chunks in case len is too big to fit in an int. | |
| 92 | - // Assume int is at least 32 bits. | |
| 88 | + // Write in chunks in case len is too big to fit in an int. Assume int is at least 32 bits. | |
| 93 | 89 | static size_t const max_bytes = 1 << 30; |
| 94 | 90 | size_t bytes_left = len; |
| 95 | 91 | unsigned char const* buf = data; |
| ... | ... | @@ -105,20 +101,18 @@ void |
| 105 | 101 | Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) |
| 106 | 102 | { |
| 107 | 103 | if (len > UINT_MAX) { |
| 108 | - throw std::runtime_error("Pl_Flate: zlib doesn't support data" | |
| 109 | - " blocks larger than int"); | |
| 104 | + throw std::runtime_error("Pl_Flate: zlib doesn't support data blocks larger than int"); | |
| 110 | 105 | } |
| 111 | 106 | z_stream& zstream = *(static_cast<z_stream*>(m->zdata)); |
| 112 | - // zlib is known not to modify the data pointed to by next_in but | |
| 113 | - // doesn't declare the field value const unless compiled to do so. | |
| 107 | + // zlib is known not to modify the data pointed to by next_in but doesn't declare the field | |
| 108 | + // value const unless compiled to do so. | |
| 114 | 109 | zstream.next_in = const_cast<unsigned char*>(data); |
| 115 | 110 | zstream.avail_in = QIntC::to_uint(len); |
| 116 | 111 | |
| 117 | 112 | if (!m->initialized) { |
| 118 | 113 | int err = Z_OK; |
| 119 | 114 | |
| 120 | - // deflateInit and inflateInit are macros that use old-style | |
| 121 | - // casts. | |
| 115 | + // deflateInit and inflateInit are macros that use old-style casts. | |
| 122 | 116 | #if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__)) |
| 123 | 117 | # pragma GCC diagnostic push |
| 124 | 118 | # pragma GCC diagnostic ignored "-Wold-style-cast" |
| ... | ... | @@ -147,21 +141,18 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) |
| 147 | 141 | } |
| 148 | 142 | if ((m->action == a_inflate) && (err != Z_OK) && zstream.msg && |
| 149 | 143 | (strcmp(zstream.msg, "incorrect data check") == 0)) { |
| 150 | - // Other PDF readers ignore this specific error. Combining | |
| 151 | - // this with Z_SYNC_FLUSH enables qpdf to handle some | |
| 152 | - // broken zlib streams without losing data. | |
| 144 | + // Other PDF readers ignore this specific error. Combining this with Z_SYNC_FLUSH | |
| 145 | + // enables qpdf to handle some broken zlib streams without losing data. | |
| 153 | 146 | err = Z_STREAM_END; |
| 154 | 147 | } |
| 155 | 148 | switch (err) { |
| 156 | 149 | case Z_BUF_ERROR: |
| 157 | - // Probably shouldn't be able to happen, but possible as a | |
| 158 | - // boundary condition: if the last call to inflate exactly | |
| 159 | - // filled the output buffer, it's possible that the next | |
| 160 | - // call to inflate could have nothing to do. There are PDF | |
| 161 | - // files in the wild that have this error (including at | |
| 162 | - // least one in qpdf's test suite). In some cases, we want | |
| 163 | - // to know about this, because it indicates incorrect | |
| 164 | - // compression, so call a callback if provided. | |
| 150 | + // Probably shouldn't be able to happen, but possible as a boundary condition: if the | |
| 151 | + // last call to inflate exactly filled the output buffer, it's possible that the next | |
| 152 | + // call to inflate could have nothing to do. There are PDF files in the wild that have | |
| 153 | + // this error (including at least one in qpdf's test suite). In some cases, we want to | |
| 154 | + // know about this, because it indicates incorrect compression, so call a callback if | |
| 155 | + // provided. | |
| 165 | 156 | this->warn("input stream is complete but output may still be valid", err); |
| 166 | 157 | done = true; |
| 167 | 158 | break; |
| ... | ... | @@ -173,9 +164,8 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) |
| 173 | 164 | case Z_OK: |
| 174 | 165 | { |
| 175 | 166 | if ((zstream.avail_in == 0) && (zstream.avail_out > 0)) { |
| 176 | - // There is nothing left to read, and there was | |
| 177 | - // sufficient buffer space to write everything we | |
| 178 | - // needed, so we're done for now. | |
| 167 | + // There is nothing left to read, and there was sufficient buffer space to write | |
| 168 | + // everything we needed, so we're done for now. | |
| 179 | 169 | done = true; |
| 180 | 170 | } |
| 181 | 171 | uLong ready = QIntC::to_ulong(m->out_bufsize - zstream.avail_out); | ... | ... |
libqpdf/Pl_Function.cc
| ... | ... | @@ -41,8 +41,7 @@ Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_c_char_t |
| 41 | 41 | |
| 42 | 42 | Pl_Function::~Pl_Function() |
| 43 | 43 | { |
| 44 | - // Must be explicit and not inline -- see QPDF_DLL_CLASS in | |
| 45 | - // README-maintainer | |
| 44 | + // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer | |
| 46 | 45 | } |
| 47 | 46 | |
| 48 | 47 | void | ... | ... |
libqpdf/Pl_LZWDecoder.cc
| ... | ... | @@ -149,9 +149,8 @@ Pl_LZWDecoder::handleCode(unsigned int code) |
| 149 | 149 | this->eod = true; |
| 150 | 150 | } else { |
| 151 | 151 | if (this->last_code != 256) { |
| 152 | - // Add to the table from last time. New table entry would | |
| 153 | - // be what we read last plus the first character of what | |
| 154 | - // we're reading now. | |
| 152 | + // Add to the table from last time. New table entry would be what we read last plus the | |
| 153 | + // first character of what we're reading now. | |
| 155 | 154 | unsigned char next = '\0'; |
| 156 | 155 | unsigned int table_size = QIntC::to_uint(table.size()); |
| 157 | 156 | if (code < 256) { |
| ... | ... | @@ -162,10 +161,8 @@ Pl_LZWDecoder::handleCode(unsigned int code) |
| 162 | 161 | if (idx > table_size) { |
| 163 | 162 | throw std::runtime_error("LZWDecoder: bad code received"); |
| 164 | 163 | } else if (idx == table_size) { |
| 165 | - // The encoder would have just created this entry, | |
| 166 | - // so the first character of this entry would have | |
| 167 | - // been the same as the first character of the | |
| 168 | - // last entry. | |
| 164 | + // The encoder would have just created this entry, so the first character of | |
| 165 | + // this entry would have been the same as the first character of the last entry. | |
| 169 | 166 | QTC::TC("libtests", "Pl_LZWDecoder last was table size"); |
| 170 | 167 | next = getFirstChar(this->last_code); |
| 171 | 168 | } else { | ... | ... |
libqpdf/Pl_MD5.cc
| ... | ... | @@ -19,8 +19,7 @@ Pl_MD5::write(unsigned char const* buf, size_t len) |
| 19 | 19 | this->in_progress = true; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - // Write in chunks in case len is too big to fit in an int. | |
| 23 | - // Assume int is at least 32 bits. | |
| 22 | + // Write in chunks in case len is too big to fit in an int. Assume int is at least 32 bits. | |
| 24 | 23 | static size_t const max_bytes = 1 << 30; |
| 25 | 24 | size_t bytes_left = len; |
| 26 | 25 | unsigned char const* data = buf; | ... | ... |
libqpdf/Pl_OStream.cc
| ... | ... | @@ -15,8 +15,7 @@ Pl_OStream::Pl_OStream(char const* identifier, std::ostream& os) : |
| 15 | 15 | |
| 16 | 16 | Pl_OStream::~Pl_OStream() |
| 17 | 17 | { |
| 18 | - // Must be explicit and not inline -- see QPDF_DLL_CLASS in | |
| 19 | - // README-maintainer | |
| 18 | + // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer | |
| 20 | 19 | } |
| 21 | 20 | |
| 22 | 21 | void | ... | ... |
libqpdf/Pl_PNGFilter.cc
| ... | ... | @@ -33,8 +33,8 @@ Pl_PNGFilter::Pl_PNGFilter( |
| 33 | 33 | } |
| 34 | 34 | if (!((bits_per_sample == 1) || (bits_per_sample == 2) || (bits_per_sample == 4) || |
| 35 | 35 | (bits_per_sample == 8) || (bits_per_sample == 16))) { |
| 36 | - throw std::runtime_error("PNGFilter created with invalid bits_per_sample not" | |
| 37 | - " 1, 2, 4, 8, or 16"); | |
| 36 | + throw std::runtime_error( | |
| 37 | + "PNGFilter created with invalid bits_per_sample not 1, 2, 4, 8, or 16"); | |
| 38 | 38 | } |
| 39 | 39 | this->bytes_per_pixel = ((bits_per_sample * samples_per_pixel) + 7) / 8; |
| 40 | 40 | unsigned long long bpr = ((columns * bits_per_sample * samples_per_pixel) + 7) / 8; | ... | ... |
libqpdf/Pl_QPDFTokenizer.cc
| ... | ... | @@ -23,8 +23,7 @@ Pl_QPDFTokenizer::Pl_QPDFTokenizer( |
| 23 | 23 | |
| 24 | 24 | Pl_QPDFTokenizer::~Pl_QPDFTokenizer() |
| 25 | 25 | { |
| 26 | - // Must be explicit and not inline -- see QPDF_DLL_CLASS in | |
| 27 | - // README-maintainer | |
| 26 | + // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer | |
| 28 | 27 | } |
| 29 | 28 | |
| 30 | 29 | void | ... | ... |
libqpdf/Pl_RunLength.cc
| ... | ... | @@ -18,8 +18,7 @@ Pl_RunLength::Pl_RunLength(char const* identifier, Pipeline* next, action_e acti |
| 18 | 18 | |
| 19 | 19 | Pl_RunLength::~Pl_RunLength() |
| 20 | 20 | { |
| 21 | - // Must be explicit and not inline -- see QPDF_DLL_CLASS in | |
| 22 | - // README-maintainer | |
| 21 | + // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer | |
| 23 | 22 | } |
| 24 | 23 | |
| 25 | 24 | void |
| ... | ... | @@ -135,10 +134,9 @@ Pl_RunLength::flush_encode() |
| 135 | 134 | void |
| 136 | 135 | Pl_RunLength::finish() |
| 137 | 136 | { |
| 138 | - // When decoding, we might have read a length byte not followed by | |
| 139 | - // data, which means the stream was terminated early, but we will | |
| 140 | - // just ignore this case since this is the only sensible thing to | |
| 141 | - // do. | |
| 137 | + // When decoding, we might have read a length byte not followed by data, which means the stream | |
| 138 | + // was terminated early, but we will just ignore this case since this is the only sensible thing | |
| 139 | + // to do. | |
| 142 | 140 | if (m->action == a_encode) { |
| 143 | 141 | flush_encode(); |
| 144 | 142 | unsigned char ch = 128; | ... | ... |
libqpdf/Pl_SHA2.cc
| ... | ... | @@ -20,8 +20,7 @@ Pl_SHA2::write(unsigned char const* buf, size_t len) |
| 20 | 20 | this->in_progress = true; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - // Write in chunks in case len is too big to fit in an int. | |
| 24 | - // Assume int is at least 32 bits. | |
| 23 | + // Write in chunks in case len is too big to fit in an int. Assume int is at least 32 bits. | |
| 25 | 24 | static size_t const max_bytes = 1 << 30; |
| 26 | 25 | size_t bytes_left = len; |
| 27 | 26 | unsigned char const* data = buf; | ... | ... |
libqpdf/Pl_StdioFile.cc
| ... | ... | @@ -19,8 +19,7 @@ Pl_StdioFile::Pl_StdioFile(char const* identifier, FILE* f) : |
| 19 | 19 | |
| 20 | 20 | Pl_StdioFile::~Pl_StdioFile() |
| 21 | 21 | { |
| 22 | - // Must be explicit and not inline -- see QPDF_DLL_CLASS in | |
| 23 | - // README-maintainer | |
| 22 | + // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer | |
| 24 | 23 | } |
| 25 | 24 | |
| 26 | 25 | void | ... | ... |
libqpdf/Pl_String.cc
| ... | ... | @@ -15,8 +15,7 @@ Pl_String::Pl_String(char const* identifier, Pipeline* next, std::string& s) : |
| 15 | 15 | |
| 16 | 16 | Pl_String::~Pl_String() |
| 17 | 17 | { |
| 18 | - // Must be explicit and not inline -- see QPDF_DLL_CLASS in | |
| 19 | - // README-maintainer | |
| 18 | + // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer | |
| 20 | 19 | } |
| 21 | 20 | |
| 22 | 21 | void | ... | ... |
libqpdf/QPDF.cc
| ... | ... | @@ -106,9 +106,8 @@ namespace |
| 106 | 106 | throwException() |
| 107 | 107 | { |
| 108 | 108 | throw std::logic_error("QPDF operation attempted on a QPDF object with no input " |
| 109 | - "source." | |
| 110 | - " QPDF operations are invalid before processFile (or another" | |
| 111 | - " process method) or after closeInputSource"); | |
| 109 | + "source. QPDF operations are invalid before processFile (or " | |
| 110 | + "another process method) or after closeInputSource"); | |
| 112 | 111 | } |
| 113 | 112 | }; |
| 114 | 113 | } // namespace | ... | ... |
libqpdf/QPDFAnnotationObjectHelper.cc
| ... | ... | @@ -54,13 +54,10 @@ QPDFAnnotationObjectHelper::getAppearanceStream(std::string const& which, std::s |
| 54 | 54 | if (ap.isDictionary()) { |
| 55 | 55 | QPDFObjectHandle ap_sub = ap.getKey(which); |
| 56 | 56 | if (ap_sub.isStream()) { |
| 57 | - // According to the spec, Appearance State is supposed to | |
| 58 | - // refer to a subkey of the appearance stream when /AP is | |
| 59 | - // a dictionary, but files have been seen in the wild | |
| 60 | - // where Appearance State is `/N` and `/AP` is a stream. | |
| 61 | - // Therefore, if `which` points to a stream, disregard | |
| 62 | - // state and just use the stream. See qpdf issue #949 for | |
| 63 | - // details. | |
| 57 | + // According to the spec, Appearance State is supposed to refer to a subkey of the | |
| 58 | + // appearance stream when /AP is a dictionary, but files have been seen in the wild | |
| 59 | + // where Appearance State is `/N` and `/AP` is a stream. Therefore, if `which` points to | |
| 60 | + // a stream, disregard state and just use the stream. See qpdf issue #949 for details. | |
| 64 | 61 | QTC::TC("qpdf", "QPDFAnnotationObjectHelper AP stream"); |
| 65 | 62 | return ap_sub; |
| 66 | 63 | } |
| ... | ... | @@ -85,84 +82,66 @@ QPDFAnnotationObjectHelper::getPageContentForAppearance( |
| 85 | 82 | return ""; |
| 86 | 83 | } |
| 87 | 84 | |
| 88 | - // The appearance matrix computed by this method is the | |
| 89 | - // transformation matrix that needs to be in effect when drawing | |
| 90 | - // this annotation's appearance stream on the page. The algorithm | |
| 91 | - // for computing the appearance matrix described in section 12.5.5 | |
| 92 | - // of the ISO-32000 PDF spec is similar but not identical to what | |
| 93 | - // we are doing here. | |
| 85 | + // The appearance matrix computed by this method is the transformation matrix that needs to be | |
| 86 | + // in effect when drawing this annotation's appearance stream on the page. The algorithm for | |
| 87 | + // computing the appearance matrix described in section 12.5.5 of the ISO-32000 PDF spec is | |
| 88 | + // similar but not identical to what we are doing here. | |
| 94 | 89 | |
| 95 | - // When rendering an appearance stream associated with an | |
| 96 | - // annotation, there are four relevant components: | |
| 90 | + // When rendering an appearance stream associated with an annotation, there are four relevant | |
| 91 | + // components: | |
| 97 | 92 | // |
| 98 | 93 | // * The appearance stream's bounding box (/BBox) |
| 99 | 94 | // * The appearance stream's matrix (/Matrix) |
| 100 | 95 | // * The annotation's rectangle (/Rect) |
| 101 | - // * In the case of form fields with the NoRotate flag, the | |
| 102 | - // page's rotation | |
| 96 | + // * In the case of form fields with the NoRotate flag, the page's rotation | |
| 103 | 97 | |
| 104 | - // When rendering a form xobject in isolation, just drawn with a | |
| 105 | - // /Do operator, there is no form field, so page rotation is not | |
| 106 | - // relevant, and there is no annotation, so /Rect is not relevant, | |
| 107 | - // so only /BBox and /Matrix are relevant. The effect of these are | |
| 108 | - // as follows: | |
| 98 | + // When rendering a form xobject in isolation, just drawn with a /Do operator, there is no form | |
| 99 | + // field, so page rotation is not relevant, and there is no annotation, so /Rect is not | |
| 100 | + // relevant, so only /BBox and /Matrix are relevant. The effect of these are as follows: | |
| 109 | 101 | |
| 110 | 102 | // * /BBox is treated as a clipping region |
| 111 | - // * /Matrix is applied as a transformation prior to rendering the | |
| 112 | - // appearance stream. | |
| 113 | - | |
| 114 | - // There is no relationship between /BBox and /Matrix in this | |
| 115 | - // case. | |
| 116 | - | |
| 117 | - // When rendering a form xobject in the context of an annotation, | |
| 118 | - // things are a little different. In particular, a matrix is | |
| 119 | - // established such that /BBox, when transformed by /Matrix, would | |
| 120 | - // fit completely inside of /Rect. /BBox is no longer a clipping | |
| 121 | - // region. To illustrate the difference, consider a /Matrix of | |
| 122 | - // [2 0 0 2 0 0], which is scaling by a factor of two along both | |
| 123 | - // axes. If the appearance stream drew a rectangle equal to /BBox, | |
| 124 | - // in the case of the form xobject in isolation, this matrix would | |
| 125 | - // cause only the lower-left quadrant of the rectangle to be | |
| 126 | - // visible since the scaling would cause the rest of it to fall | |
| 127 | - // outside of the clipping region. In the case of the form xobject | |
| 128 | - // displayed in the context of an annotation, such a matrix would | |
| 129 | - // have no effect at all because it would be applied to the | |
| 130 | - // bounding box first, and then when the resulting enclosing | |
| 131 | - // quadrilateral was transformed to fit into /Rect, the effect of | |
| 132 | - // the scaling would be undone. | |
| 133 | - | |
| 134 | - // Our job is to create a transformation matrix that compensates | |
| 135 | - // for these differences so that the appearance stream of an | |
| 136 | - // annotation can be drawn as a regular form xobject. | |
| 137 | - | |
| 138 | - // To do this, we perform the following steps, which overlap | |
| 139 | - // significantly with the algorithm in 12.5.5: | |
| 140 | - | |
| 141 | - // 1. Transform the four corners of /BBox by applying /Matrix to | |
| 142 | - // them, creating an arbitrarily transformed quadrilateral. | |
| 143 | - | |
| 144 | - // 2. Find the minimum upright rectangle that encompasses the | |
| 145 | - // resulting quadrilateral. This is the "transformed appearance | |
| 146 | - // box", T. | |
| 147 | - | |
| 148 | - // 3. Compute matrix A that maps the lower left and upper right | |
| 149 | - // corners of T to the annotation's /Rect. This can be done by | |
| 150 | - // scaling so that the sizes match and translating so that the | |
| 103 | + // * /Matrix is applied as a transformation prior to rendering the appearance stream. | |
| 104 | + | |
| 105 | + // There is no relationship between /BBox and /Matrix in this case. | |
| 106 | + | |
| 107 | + // When rendering a form xobject in the context of an annotation, things are a little different. | |
| 108 | + // In particular, a matrix is established such that /BBox, when transformed by /Matrix, would | |
| 109 | + // fit completely inside of /Rect. /BBox is no longer a clipping region. To illustrate the | |
| 110 | + // difference, consider a /Matrix of [2 0 0 2 0 0], which is scaling by a factor of two along | |
| 111 | + // both axes. If the appearance stream drew a rectangle equal to /BBox, in the case of the form | |
| 112 | + // xobject in isolation, this matrix would cause only the lower-left quadrant of the rectangle | |
| 113 | + // to be visible since the scaling would cause the rest of it to fall outside of the clipping | |
| 114 | + // region. In the case of the form xobject displayed in the context of an annotation, such a | |
| 115 | + // matrix would have no effect at all because it would be applied to the bounding box first, and | |
| 116 | + // then when the resulting enclosing quadrilateral was transformed to fit into /Rect, the effect | |
| 117 | + // of the scaling would be undone. | |
| 118 | + | |
| 119 | + // Our job is to create a transformation matrix that compensates for these differences so that | |
| 120 | + // the appearance stream of an annotation can be drawn as a regular form xobject. | |
| 121 | + | |
| 122 | + // To do this, we perform the following steps, which overlap significantly with the algorithm | |
| 123 | + // in 12.5.5: | |
| 124 | + | |
| 125 | + // 1. Transform the four corners of /BBox by applying /Matrix to them, creating an arbitrarily | |
| 126 | + // transformed quadrilateral. | |
| 127 | + | |
| 128 | + // 2. Find the minimum upright rectangle that encompasses the resulting quadrilateral. This is | |
| 129 | + // the "transformed appearance box", T. | |
| 130 | + | |
| 131 | + // 3. Compute matrix A that maps the lower left and upper right corners of T to the annotation's | |
| 132 | + // /Rect. This can be done by scaling so that the sizes match and translating so that the | |
| 151 | 133 | // scaled T exactly overlaps /Rect. |
| 152 | 134 | |
| 153 | - // If the annotation's /F flag has bit 4 set, this means that | |
| 154 | - // annotation is to be rotated about its upper left corner to | |
| 155 | - // counteract any rotation of the page so it remains upright. To | |
| 135 | + // If the annotation's /F flag has bit 4 set, this means that annotation is to be rotated about | |
| 136 | + // its upper left corner to counteract any rotation of the page so it remains upright. To | |
| 156 | 137 | // achieve this effect, we do the following extra steps: |
| 157 | 138 | |
| 158 | - // 1. Perform the rotation on /BBox box prior to transforming it | |
| 159 | - // with /Matrix (by replacing matrix with concatenation of | |
| 160 | - // matrix onto the rotation) | |
| 139 | + // 1. Perform the rotation on /BBox box prior to transforming it with /Matrix (by replacing | |
| 140 | + // matrix with concatenation of matrix onto the rotation) | |
| 161 | 141 | |
| 162 | 142 | // 2. Rotate the destination rectangle by the specified amount |
| 163 | 143 | |
| 164 | - // 3. Apply the rotation to A as computed above to get the final | |
| 165 | - // appearance matrix. | |
| 144 | + // 3. Apply the rotation to A as computed above to get the final appearance matrix. | |
| 166 | 145 | |
| 167 | 146 | QPDFObjectHandle rect_obj = this->oh.getKey("/Rect"); |
| 168 | 147 | QPDFObjectHandle as = getAppearanceStream("/N").getDict(); |
| ... | ... | @@ -192,14 +171,12 @@ QPDFAnnotationObjectHelper::getPageContentForAppearance( |
| 192 | 171 | QPDFObjectHandle::Rectangle rect = rect_obj.getArrayAsRectangle(); |
| 193 | 172 | bool do_rotate = (rotate && (flags & an_no_rotate)); |
| 194 | 173 | if (do_rotate) { |
| 195 | - // If the the annotation flags include the NoRotate bit and | |
| 196 | - // the page is rotated, we have to rotate the annotation about | |
| 197 | - // its upper left corner by the same amount in the opposite | |
| 198 | - // direction so that it will remain upright in absolute | |
| 199 | - // coordinates. Since the semantics of /Rotate for a page are | |
| 200 | - // to rotate the page, while the effect of rotating using a | |
| 201 | - // transformation matrix is to rotate the coordinate system, | |
| 202 | - // the opposite directionality is explicit in the code. | |
| 174 | + // If the the annotation flags include the NoRotate bit and the page is rotated, we have to | |
| 175 | + // rotate the annotation about its upper left corner by the same amount in the opposite | |
| 176 | + // direction so that it will remain upright in absolute coordinates. Since the semantics of | |
| 177 | + // /Rotate for a page are to rotate the page, while the effect of rotating using a | |
| 178 | + // transformation matrix is to rotate the coordinate system, the opposite directionality is | |
| 179 | + // explicit in the code. | |
| 203 | 180 | QPDFMatrix mr; |
| 204 | 181 | mr.rotatex90(rotate); |
| 205 | 182 | mr.concat(matrix); | ... | ... |
libqpdf/QPDFArgParser.cc
| ... | ... | @@ -139,8 +139,8 @@ QPDFArgParser::addInvalidChoiceHandler(std::string const& arg, param_arg_handler |
| 139 | 139 | auto i = m->option_table->find(arg); |
| 140 | 140 | if (i == m->option_table->end()) { |
| 141 | 141 | QTC::TC("libtests", "QPDFArgParser invalid choice handler to unknown"); |
| 142 | - throw std::logic_error("QPDFArgParser: attempt to add invalid choice handler" | |
| 143 | - " to unknown argument"); | |
| 142 | + throw std::logic_error( | |
| 143 | + "QPDFArgParser: attempt to add invalid choice handler to unknown argument"); | |
| 144 | 144 | } |
| 145 | 145 | auto& oe = i->second; |
| 146 | 146 | oe.invalid_choice_handler = handler; |
| ... | ... | @@ -231,9 +231,9 @@ QPDFArgParser::invalidHelpArg(std::string const& p) |
| 231 | 231 | void |
| 232 | 232 | QPDFArgParser::handleArgFileArguments() |
| 233 | 233 | { |
| 234 | - // Support reading arguments from files. Create a new argv. Ensure | |
| 235 | - // that argv itself as well as all its contents are automatically | |
| 236 | - // deleted by using shared pointers to back the pointers in argv. | |
| 234 | + // Support reading arguments from files. Create a new argv. Ensure that argv itself as well as | |
| 235 | + // all its contents are automatically deleted by using shared pointers back to the pointers in | |
| 236 | + // argv. | |
| 237 | 237 | m->new_argv.push_back(QUtil::make_shared_cstr(m->argv[0])); |
| 238 | 238 | for (int i = 1; i < m->argc; ++i) { |
| 239 | 239 | char const* argfile = nullptr; |
| ... | ... | @@ -264,12 +264,10 @@ QPDFArgParser::handleArgFileArguments() |
| 264 | 264 | void |
| 265 | 265 | QPDFArgParser::handleBashArguments() |
| 266 | 266 | { |
| 267 | - // Do a minimal job of parsing bash_line into arguments. This | |
| 268 | - // doesn't do everything the shell does (e.g. $(...), variable | |
| 269 | - // expansion, arithmetic, globs, etc.), but it should be good | |
| 270 | - // enough for purposes of handling completion. As we build up the | |
| 271 | - // new argv, we can't use m->new_argv because this code has to | |
| 272 | - // interoperate with @file arguments, so memory for both ways of | |
| 267 | + // Do a minimal job of parsing bash_line into arguments. This doesn't do everything the shell | |
| 268 | + // does (e.g. $(...), variable expansion, arithmetic, globs, etc.), but it should be good enough | |
| 269 | + // for purposes of handling completion. As we build up the new argv, we can't use m->new_argv | |
| 270 | + // because this code has to interoperate with @file arguments, so memory for both ways of | |
| 273 | 271 | // fabricating argv has to be protected. |
| 274 | 272 | |
| 275 | 273 | bool last_was_backslash = false; |
| ... | ... | @@ -321,12 +319,11 @@ QPDFArgParser::handleBashArguments() |
| 321 | 319 | } |
| 322 | 320 | } |
| 323 | 321 | if (m->bash_argv.empty()) { |
| 324 | - // This can't happen if properly invoked by bash, but ensure | |
| 325 | - // we have a valid argv[0] regardless. | |
| 322 | + // This can't happen if properly invoked by bash, but ensure we have a valid argv[0] | |
| 323 | + // regardless. | |
| 326 | 324 | m->bash_argv.push_back(QUtil::make_shared_cstr(m->argv[0])); |
| 327 | 325 | } |
| 328 | - // Explicitly discard any non-space-terminated word. The "current | |
| 329 | - // word" is handled specially. | |
| 326 | + // Explicitly discard any non-space-terminated word. The "current word" is handled specially. | |
| 330 | 327 | m->bash_argv_ph = QUtil::make_shared_array<char const*>(1 + m->bash_argv.size()); |
| 331 | 328 | for (size_t i = 0; i < m->bash_argv.size(); ++i) { |
| 332 | 329 | m->bash_argv_ph.get()[i] = m->bash_argv.at(i).get(); |
| ... | ... | @@ -367,12 +364,10 @@ QPDFArgParser::checkCompletion() |
| 367 | 364 | { |
| 368 | 365 | // See if we're being invoked from bash completion. |
| 369 | 366 | std::string bash_point_env; |
| 370 | - // On Windows with mingw, there have been times when there appears | |
| 371 | - // to be no way to distinguish between an empty environment | |
| 372 | - // variable and an unset variable. There are also conditions under | |
| 373 | - // which bash doesn't set COMP_LINE. Therefore, enter this logic | |
| 374 | - // if either COMP_LINE or COMP_POINT are set. They will both be | |
| 375 | - // set together under ordinary circumstances. | |
| 367 | + // On Windows with mingw, there have been times when there appears to be no way to distinguish | |
| 368 | + // between an empty environment variable and an unset variable. There are also conditions under | |
| 369 | + // which bash doesn't set COMP_LINE. Therefore, enter this logic if either COMP_LINE or | |
| 370 | + // COMP_POINT are set. They will both be set together under ordinary circumstances. | |
| 376 | 371 | bool got_line = QUtil::get_env("COMP_LINE", &m->bash_line); |
| 377 | 372 | bool got_point = QUtil::get_env("COMP_POINT", &bash_point_env); |
| 378 | 373 | if (got_line || got_point) { |
| ... | ... | @@ -385,15 +380,12 @@ QPDFArgParser::checkCompletion() |
| 385 | 380 | if (p > m->bash_line.length()) { |
| 386 | 381 | p = m->bash_line.length(); |
| 387 | 382 | } |
| 388 | - // Set bash_cur and bash_prev based on bash_line rather than | |
| 389 | - // relying on argv. This enables us to use bashcompinit to get | |
| 390 | - // completion in zsh too since bashcompinit sets COMP_LINE and | |
| 391 | - // COMP_POINT but doesn't invoke the command with options like | |
| 392 | - // bash does. | |
| 393 | - | |
| 394 | - // p is equal to length of the string. Walk backwards looking | |
| 395 | - // for the first separator. bash_cur is everything after the | |
| 396 | - // last separator, possibly empty. | |
| 383 | + // Set bash_cur and bash_prev based on bash_line rather than relying on argv. This enables | |
| 384 | + // us to use bashcompinit to get completion in zsh too since bashcompinit sets COMP_LINE and | |
| 385 | + // COMP_POINT but doesn't invoke the command with options like bash does. | |
| 386 | + | |
| 387 | + // p is equal to length of the string. Walk backwards looking for the first separator. | |
| 388 | + // bash_cur is everything after the last separator, possibly empty. | |
| 397 | 389 | char sep(0); |
| 398 | 390 | while (p > 0) { |
| 399 | 391 | --p; |
| ... | ... | @@ -407,10 +399,9 @@ QPDFArgParser::checkCompletion() |
| 407 | 399 | m->bash_cur = m->bash_line.substr(1 + p, std::string::npos); |
| 408 | 400 | } |
| 409 | 401 | if ((sep == ':') || (sep == '=')) { |
| 410 | - // Bash sets prev to the non-space separator if any. | |
| 411 | - // Actually, if there are multiple separators in a row, | |
| 412 | - // they are all included in prev, but that detail is not | |
| 413 | - // important to us and not worth coding. | |
| 402 | + // Bash sets prev to the non-space separator if any. Actually, if there are multiple | |
| 403 | + // separators in a row, they are all included in prev, but that detail is not important | |
| 404 | + // to us and not worth coding. | |
| 414 | 405 | m->bash_prev = m->bash_line.substr(p, 1); |
| 415 | 406 | } else { |
| 416 | 407 | // Go back to the last separator and set prev based on |
| ... | ... | @@ -429,8 +420,8 @@ QPDFArgParser::checkCompletion() |
| 429 | 420 | m->bash_prev = m->bash_line.substr(0, p); |
| 430 | 421 | } |
| 431 | 422 | if (m->argc == 1) { |
| 432 | - // This is probably zsh using bashcompinit. There are a | |
| 433 | - // few differences in the expected output. | |
| 423 | + // This is probably zsh using bashcompinit. There are a few differences in the expected | |
| 424 | + // output. | |
| 434 | 425 | m->zsh_completion = true; |
| 435 | 426 | } |
| 436 | 427 | handleBashArguments(); |
| ... | ... | @@ -454,8 +445,7 @@ QPDFArgParser::parseArgs() |
| 454 | 445 | std::string o_arg(arg); |
| 455 | 446 | std::string arg_s(arg); |
| 456 | 447 | if (strcmp(arg, "--") == 0) { |
| 457 | - // Special case for -- option, which is used to break out | |
| 458 | - // of subparsers. | |
| 448 | + // Special case for -- option, which is used to break out of subparsers. | |
| 459 | 449 | oep = m->option_table->find("--"); |
| 460 | 450 | end_option = true; |
| 461 | 451 | if (oep == m->option_table->end()) { |
| ... | ... | @@ -471,11 +461,9 @@ QPDFArgParser::parseArgs() |
| 471 | 461 | QTC::TC("libtests", "QPDFArgParser single dash"); |
| 472 | 462 | } |
| 473 | 463 | |
| 474 | - // Prevent --=something from being treated as an empty arg | |
| 475 | - // by searching for = from after the first character. We | |
| 476 | - // do this since the empty string in the option table is | |
| 477 | - // for positional arguments. Besides, it doesn't make | |
| 478 | - // sense to have an empty option. | |
| 464 | + // Prevent --=something from being treated as an empty arg by searching for = from after | |
| 465 | + // the first character. We do this since the empty string in the option table is for | |
| 466 | + // positional arguments. Besides, it doesn't make sense to have an empty option. | |
| 479 | 467 | arg_s = arg; |
| 480 | 468 | size_t equal_pos = std::string::npos; |
| 481 | 469 | if (arg_s.length() > 0) { |
| ... | ... | @@ -489,8 +477,7 @@ QPDFArgParser::parseArgs() |
| 489 | 477 | |
| 490 | 478 | if ((!m->bash_completion) && (m->argc == 2) && (m->cur_arg == 1) && |
| 491 | 479 | m->help_option_table.count(arg_s)) { |
| 492 | - // Handle help option, which is only valid as the sole | |
| 493 | - // option. | |
| 480 | + // Handle help option, which is only valid as the sole option. | |
| 494 | 481 | QTC::TC("libtests", "QPDFArgParser help option"); |
| 495 | 482 | oep = m->help_option_table.find(arg_s); |
| 496 | 483 | help_option = true; |
| ... | ... | @@ -500,8 +487,7 @@ QPDFArgParser::parseArgs() |
| 500 | 487 | oep = m->option_table->find(arg_s); |
| 501 | 488 | } |
| 502 | 489 | } else { |
| 503 | - // The empty string maps to the positional argument | |
| 504 | - // handler. | |
| 490 | + // The empty string maps to the positional argument handler. | |
| 505 | 491 | QTC::TC("libtests", "QPDFArgParser positional"); |
| 506 | 492 | oep = m->option_table->find(""); |
| 507 | 493 | parameter = arg; |
| ... | ... | @@ -522,8 +508,7 @@ QPDFArgParser::parseArgs() |
| 522 | 508 | std::string message = "--" + arg_s + " must be given as --" + arg_s + "="; |
| 523 | 509 | if (oe.invalid_choice_handler) { |
| 524 | 510 | oe.invalid_choice_handler(parameter); |
| 525 | - // Method should call usage() or exit. Just in case it | |
| 526 | - // doesn't... | |
| 511 | + // Method should call usage() or exit. Just in case it doesn't... | |
| 527 | 512 | message += "option"; |
| 528 | 513 | } else if (!oe.choices.empty()) { |
| 529 | 514 | QTC::TC("libtests", "QPDFArgParser required choices"); |
| ... | ... | @@ -609,8 +594,8 @@ QPDFArgParser::addOptionsToCompletions(option_table_t& option_table) |
| 609 | 594 | std::string base = "--" + arg; |
| 610 | 595 | if (oe.param_arg_handler) { |
| 611 | 596 | if (m->zsh_completion) { |
| 612 | - // zsh doesn't treat = as a word separator, so add all | |
| 613 | - // the options so we don't get a space after the =. | |
| 597 | + // zsh doesn't treat = as a word separator, so add all the options so we don't get a | |
| 598 | + // space after the =. | |
| 614 | 599 | addChoicesToCompletions(option_table, arg, base + "="); |
| 615 | 600 | } |
| 616 | 601 | m->completions.insert(base + "="); | ... | ... |
libqpdf/QPDFCryptoProvider.cc
| ... | ... | @@ -92,8 +92,7 @@ QPDFCryptoProvider::setDefaultProvider_internal(std::string const& name) |
| 92 | 92 | { |
| 93 | 93 | if (!m->providers.count(name)) { |
| 94 | 94 | throw std::logic_error( |
| 95 | - "QPDFCryptoProvider: request to set default" | |
| 96 | - " provider to unknown implementation \"" + | |
| 95 | + "QPDFCryptoProvider: request to set default provider to unknown implementation \"" + | |
| 97 | 96 | name + "\""); |
| 98 | 97 | } |
| 99 | 98 | m->default_provider = name; | ... | ... |
libqpdf/QPDFCrypto_gnutls.cc
| ... | ... | @@ -233,9 +233,8 @@ QPDFCrypto_gnutls::rijndael_process(unsigned char* in_data, unsigned char* out_d |
| 233 | 233 | this->cipher_ctx, in_data, rijndael_buf_size, out_data, rijndael_buf_size); |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - // Gnutls doesn't support AES in ECB (non-CBC) mode, but the | |
| 237 | - // result is the same as if you just reset the cbc block to all | |
| 238 | - // zeroes each time. We jump through a few hoops here to make this | |
| 236 | + // Gnutls doesn't support AES in ECB (non-CBC) mode, but the result is the same as if you just | |
| 237 | + // reset the cbc block to all zeroes each time. We jump through a few hoops here to make this | |
| 239 | 238 | // work. |
| 240 | 239 | if (!this->cbc_mode) { |
| 241 | 240 | static unsigned char zeroes[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | ... | ... |
libqpdf/QPDFCrypto_openssl.cc
| ... | ... | @@ -83,8 +83,8 @@ static void |
| 83 | 83 | check_openssl(int status) |
| 84 | 84 | { |
| 85 | 85 | if (status != 1) { |
| 86 | - // OpenSSL creates a "queue" of errors; copy the first (innermost) | |
| 87 | - // error to the exception message. | |
| 86 | + // OpenSSL creates a "queue" of errors; copy the first (innermost) error to the exception | |
| 87 | + // message. | |
| 88 | 88 | char buf[256] = ""; |
| 89 | 89 | ERR_error_string_n(ERR_get_error(), buf, sizeof(buf)); |
| 90 | 90 | std::string what = "OpenSSL error: "; | ... | ... |
libqpdf/QPDFDocumentHelper.cc
libqpdf/QPDFEFStreamObjectHelper.cc
| ... | ... | @@ -134,8 +134,8 @@ QPDFEFStreamObjectHelper::newFromStream(QPDFObjectHandle stream) |
| 134 | 134 | QPDFEFStreamObjectHelper result(stream); |
| 135 | 135 | stream.getDict().replaceKey("/Type", QPDFObjectHandle::newName("/EmbeddedFile")); |
| 136 | 136 | Pl_Discard discard; |
| 137 | - // The PDF spec specifies use of MD5 here and notes that it is not | |
| 138 | - // to be used for security. MD5 is known to be insecure. | |
| 137 | + // The PDF spec specifies use of MD5 here and notes that it is not to be used for security. MD5 | |
| 138 | + // is known to be insecure. | |
| 139 | 139 | Pl_MD5 md5("EF md5", &discard); |
| 140 | 140 | Pl_Count count("EF size", &md5); |
| 141 | 141 | if (!stream.pipeStreamData(&count, nullptr, 0, qpdf_dl_all)) { | ... | ... |