Commit 21d6e3231f627470ee58b06df018f31de9eb3201

Authored by Jay Berkenbilt
1 parent f1c6bb97

Make use of the new Pipeline methods in some places

examples/pdf-create.cc
@@ -118,9 +118,7 @@ ImageProvider::provideStreamData(int objid, int generation, Pipeline* pipeline) @@ -118,9 +118,7 @@ ImageProvider::provideStreamData(int objid, int generation, Pipeline* pipeline)
118 118
119 for (size_t i = 0; i < n_stripes; ++i) { 119 for (size_t i = 0; i < n_stripes; ++i) {
120 for (size_t j = 0; j < width * stripe_height; ++j) { 120 for (size_t j = 0; j < width * stripe_height; ++j) {
121 - p->write(  
122 - QUtil::unsigned_char_pointer(stripes[i].c_str()),  
123 - stripes[i].length()); 121 + p->writeString(stripes[i]);
124 } 122 }
125 } 123 }
126 p->finish(); 124 p->finish();
libqpdf/Pl_DCT.cc
@@ -348,9 +348,7 @@ Pl_DCT::decompress(void* cinfo_p, Buffer* b) @@ -348,9 +348,7 @@ Pl_DCT::decompress(void* cinfo_p, Buffer* b)
348 (void)jpeg_start_decompress(cinfo); 348 (void)jpeg_start_decompress(cinfo);
349 while (cinfo->output_scanline < cinfo->output_height) { 349 while (cinfo->output_scanline < cinfo->output_height) {
350 (void)jpeg_read_scanlines(cinfo, buffer, 1); 350 (void)jpeg_read_scanlines(cinfo, buffer, 1);
351 - this->getNext()->write(  
352 - reinterpret_cast<unsigned char*>(buffer[0]),  
353 - width * sizeof(buffer[0][0])); 351 + this->getNext()->write(buffer[0], width * sizeof(buffer[0][0]));
354 } 352 }
355 (void)jpeg_finish_decompress(cinfo); 353 (void)jpeg_finish_decompress(cinfo);
356 this->getNext()->finish(); 354 this->getNext()->finish();
libqpdf/QPDF.cc
@@ -2739,7 +2739,7 @@ QPDF::pipeStreamData( @@ -2739,7 +2739,7 @@ QPDF::pipeStreamData(
2739 "unexpected EOF reading stream data"); 2739 "unexpected EOF reading stream data");
2740 } 2740 }
2741 length -= len; 2741 length -= len;
2742 - pipeline->write(QUtil::unsigned_char_pointer(buf), len); 2742 + pipeline->write(buf, len);
2743 } 2743 }
2744 pipeline->finish(); 2744 pipeline->finish();
2745 success = true; 2745 success = true;
libqpdf/QPDFFormFieldObjectHelper.cc
@@ -863,7 +863,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance( @@ -863,7 +863,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance(
863 863
864 TfFinder tff; 864 TfFinder tff;
865 Pl_QPDFTokenizer tok("tf", &tff); 865 Pl_QPDFTokenizer tok("tf", &tff);
866 - tok.write(QUtil::unsigned_char_pointer(DA.c_str()), DA.length()); 866 + tok.writeString(DA);
867 tok.finish(); 867 tok.finish();
868 double tf = tff.getTf(); 868 double tf = tff.getTf();
869 DA = tff.getDA(); 869 DA = tff.getDA();
libqpdf/QPDFObjectHandle.cc
@@ -127,7 +127,7 @@ QPDFObjectHandle::TokenFilter::write(char const* data, size_t len) @@ -127,7 +127,7 @@ QPDFObjectHandle::TokenFilter::write(char const* data, size_t len)
127 return; 127 return;
128 } 128 }
129 if (len) { 129 if (len) {
130 - this->pipeline->write(QUtil::unsigned_char_pointer(data), len); 130 + this->pipeline->write(data, len);
131 } 131 }
132 } 132 }
133 133
@@ -1857,7 +1857,7 @@ QPDFObjectHandle::pipeContentStreams( @@ -1857,7 +1857,7 @@ QPDFObjectHandle::pipeContentStreams(
1857 Pl_Buffer buf("concatenated content stream buffer"); 1857 Pl_Buffer buf("concatenated content stream buffer");
1858 for (auto stream: streams) { 1858 for (auto stream: streams) {
1859 if (need_newline) { 1859 if (need_newline) {
1860 - buf.write(QUtil::unsigned_char_pointer("\n"), 1); 1860 + buf.writeCStr("\n");
1861 } 1861 }
1862 LastChar lc(&buf); 1862 LastChar lc(&buf);
1863 std::string og = QUtil::int_to_string(stream.getObjectID()) + " " + 1863 std::string og = QUtil::int_to_string(stream.getObjectID()) + " " +
libqpdf/QPDFPageObjectHelper.cc
@@ -190,7 +190,7 @@ InlineImageTracker::handleToken(QPDFTokenizer::Token const&amp; token) @@ -190,7 +190,7 @@ InlineImageTracker::handleToken(QPDFTokenizer::Token const&amp; token)
190 QTC::TC( 190 QTC::TC(
191 "qpdf", "QPDFPageObjectHelper externalize inline image"); 191 "qpdf", "QPDFPageObjectHelper externalize inline image");
192 Pl_Buffer b("image_data"); 192 Pl_Buffer b("image_data");
193 - b.write(QUtil::unsigned_char_pointer(image_data), len); 193 + b.writeString(image_data);
194 b.finish(); 194 b.finish();
195 QPDFObjectHandle dict = 195 QPDFObjectHandle dict =
196 convertIIDict(QPDFObjectHandle::parse(dict_str)); 196 convertIIDict(QPDFObjectHandle::parse(dict_str));
libqpdf/QPDFWriter.cc
@@ -961,7 +961,7 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes) @@ -961,7 +961,7 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes)
961 void 961 void
962 QPDFWriter::writeString(std::string const& str) 962 QPDFWriter::writeString(std::string const& str)
963 { 963 {
964 - this->m->pipeline->write(QUtil::unsigned_char_pointer(str), str.length()); 964 + this->m->pipeline->writeString(str);
965 } 965 }
966 966
967 void 967 void
@@ -1736,7 +1736,7 @@ QPDFWriter::unparseObject( @@ -1736,7 +1736,7 @@ QPDFWriter::unparseObject(
1736 true, 1736 true,
1737 QUtil::unsigned_char_pointer(this->m->cur_data_key), 1737 QUtil::unsigned_char_pointer(this->m->cur_data_key),
1738 this->m->cur_data_key.length()); 1738 this->m->cur_data_key.length());
1739 - pl.write(QUtil::unsigned_char_pointer(val), val.length()); 1739 + pl.writeString(val);
1740 pl.finish(); 1740 pl.finish();
1741 auto buf = bufpl.getBufferSharedPointer(); 1741 auto buf = bufpl.getBufferSharedPointer();
1742 val = QPDF_String(std::string( 1742 val = QPDF_String(std::string(
libqpdf/QPDF_encryption.cc
@@ -235,7 +235,7 @@ process_with_aes( @@ -235,7 +235,7 @@ process_with_aes(
235 } 235 }
236 aes.disablePadding(); 236 aes.disablePadding();
237 for (unsigned int i = 0; i < repetitions; ++i) { 237 for (unsigned int i = 0; i < repetitions; ++i) {
238 - aes.write(QUtil::unsigned_char_pointer(data), data.length()); 238 + aes.writeString(data);
239 } 239 }
240 aes.finish(); 240 aes.finish();
241 auto bufp = buffer.getBufferSharedPointer(); 241 auto bufp = buffer.getBufferSharedPointer();
@@ -255,9 +255,9 @@ hash_V5( @@ -255,9 +255,9 @@ hash_V5(
255 QPDF::EncryptionData const& data) 255 QPDF::EncryptionData const& data)
256 { 256 {
257 Pl_SHA2 hash(256); 257 Pl_SHA2 hash(256);
258 - hash.write(QUtil::unsigned_char_pointer(password), password.length());  
259 - hash.write(QUtil::unsigned_char_pointer(salt), salt.length());  
260 - hash.write(QUtil::unsigned_char_pointer(udata), udata.length()); 258 + hash.writeString(password);
  259 + hash.writeString(salt);
  260 + hash.writeString(udata);
261 hash.finish(); 261 hash.finish();
262 std::string K = hash.getRawDigest(); 262 std::string K = hash.getRawDigest();
263 263
@@ -311,7 +311,7 @@ hash_V5( @@ -311,7 +311,7 @@ hash_V5(
311 E_mod_3 %= 3; 311 E_mod_3 %= 3;
312 int next_hash = ((E_mod_3 == 0) ? 256 : (E_mod_3 == 1) ? 384 : 512); 312 int next_hash = ((E_mod_3 == 0) ? 256 : (E_mod_3 == 1) ? 384 : 512);
313 Pl_SHA2 sha2(next_hash); 313 Pl_SHA2 sha2(next_hash);
314 - sha2.write(QUtil::unsigned_char_pointer(E), E.length()); 314 + sha2.writeString(E);
315 sha2.finish(); 315 sha2.finish();
316 K = sha2.getRawDigest(); 316 K = sha2.getRawDigest();
317 317
@@ -1151,7 +1151,7 @@ QPDF::decryptString(std::string&amp; str, int objid, int generation) @@ -1151,7 +1151,7 @@ QPDF::decryptString(std::string&amp; str, int objid, int generation)
1151 false, 1151 false,
1152 QUtil::unsigned_char_pointer(key), 1152 QUtil::unsigned_char_pointer(key),
1153 key.length()); 1153 key.length());
1154 - pl.write(QUtil::unsigned_char_pointer(str), str.length()); 1154 + pl.writeString(str);
1155 pl.finish(); 1155 pl.finish();
1156 auto buf = bufpl.getBufferSharedPointer(); 1156 auto buf = bufpl.getBufferSharedPointer();
1157 str = std::string( 1157 str = std::string(
qpdf/test_driver.cc
@@ -477,9 +477,7 @@ test_8(QPDF&amp; pdf, char const* arg2) @@ -477,9 +477,7 @@ test_8(QPDF&amp; pdf, char const* arg2)
477 } 477 }
478 Pl_Buffer p1("buffer"); 478 Pl_Buffer p1("buffer");
479 Pl_Flate p2("compress", &p1, Pl_Flate::a_deflate); 479 Pl_Flate p2("compress", &p1, Pl_Flate::a_deflate);
480 - p2.write(  
481 - QUtil::unsigned_char_pointer("new data for stream\n"),  
482 - 20); // no null! 480 + p2 << "new data for stream\n";
483 p2.finish(); 481 p2.finish();
484 auto b = p1.getBufferSharedPointer(); 482 auto b = p1.getBufferSharedPointer();
485 // This is a bogus way to use StreamDataProvider, but it does 483 // This is a bogus way to use StreamDataProvider, but it does
@@ -1021,9 +1019,7 @@ test_27(QPDF&amp; pdf, char const* arg2) @@ -1021,9 +1019,7 @@ test_27(QPDF&amp; pdf, char const* arg2)
1021 { 1019 {
1022 // Local scope 1020 // Local scope
1023 Pl_Buffer pl("buffer"); 1021 Pl_Buffer pl("buffer");
1024 - pl.write(  
1025 - QUtil::unsigned_char_pointer("new data for stream\n"),  
1026 - 20); // no null! 1022 + pl.writeCStr("new data for stream\n");
1027 pl.finish(); 1023 pl.finish();
1028 auto b = pl.getBufferSharedPointer(); 1024 auto b = pl.getBufferSharedPointer();
1029 Provider* provider = new Provider(b); 1025 Provider* provider = new Provider(b);
@@ -1050,9 +1046,7 @@ test_27(QPDF&amp; pdf, char const* arg2) @@ -1050,9 +1046,7 @@ test_27(QPDF&amp; pdf, char const* arg2)
1050 { 1046 {
1051 // Local scope 1047 // Local scope
1052 Pl_Buffer pl("buffer"); 1048 Pl_Buffer pl("buffer");
1053 - pl.write(  
1054 - QUtil::unsigned_char_pointer("more data for stream\n"),  
1055 - 21); // no null! 1049 + pl.writeCStr("more data for stream\n");
1056 pl.finish(); 1050 pl.finish();
1057 auto b = pl.getBufferSharedPointer(); 1051 auto b = pl.getBufferSharedPointer();
1058 Provider* provider = new Provider(b); 1052 Provider* provider = new Provider(b);
@@ -2648,7 +2642,8 @@ test_76(QPDF&amp; pdf, char const* arg2) @@ -2648,7 +2642,8 @@ test_76(QPDF&amp; pdf, char const* arg2)
2648 auto efs2 = QPDFEFStreamObjectHelper::createEFStream(pdf, "from string"); 2642 auto efs2 = QPDFEFStreamObjectHelper::createEFStream(pdf, "from string");
2649 efs2.setSubtype("text/plain"); 2643 efs2.setSubtype("text/plain");
2650 Pl_Buffer p("buffer"); 2644 Pl_Buffer p("buffer");
2651 - p.write(QUtil::unsigned_char_pointer("from buffer"), 11); 2645 + // exercise Pipeline::operator<<(std::string const&)
  2646 + p << std::string("from buffer");
2652 p.finish(); 2647 p.finish();
2653 auto efs3 = QPDFEFStreamObjectHelper::createEFStream( 2648 auto efs3 = QPDFEFStreamObjectHelper::createEFStream(
2654 pdf, p.getBufferSharedPointer()); 2649 pdf, p.getBufferSharedPointer());
@@ -2700,7 +2695,7 @@ test_78(QPDF&amp; pdf, char const* arg2) @@ -2700,7 +2695,7 @@ test_78(QPDF&amp; pdf, char const* arg2)
2700 // Test functional versions of replaceStreamData() 2695 // Test functional versions of replaceStreamData()
2701 2696
2702 auto f1 = [](Pipeline* p) { 2697 auto f1 = [](Pipeline* p) {
2703 - p->write(QUtil::unsigned_char_pointer("potato"), 6); 2698 + p->writeCStr("potato");
2704 p->finish(); 2699 p->finish();
2705 }; 2700 };
2706 auto f2 = [](Pipeline* p, bool suppress_warnings, bool will_retry) { 2701 auto f2 = [](Pipeline* p, bool suppress_warnings, bool will_retry) {
@@ -2712,7 +2707,7 @@ test_78(QPDF&amp; pdf, char const* arg2) @@ -2712,7 +2707,7 @@ test_78(QPDF&amp; pdf, char const* arg2)
2712 if (!suppress_warnings) { 2707 if (!suppress_warnings) {
2713 std::cerr << "warning" << std::endl; 2708 std::cerr << "warning" << std::endl;
2714 } 2709 }
2715 - p->write(QUtil::unsigned_char_pointer("salad"), 5); 2710 + p->writeCStr("salad");
2716 p->finish(); 2711 p->finish();
2717 std::cerr << "f2 done" << std::endl; 2712 std::cerr << "f2 done" << std::endl;
2718 return true; 2713 return true;
@@ -2767,7 +2762,7 @@ test_79(QPDF&amp; pdf, char const* arg2) @@ -2767,7 +2762,7 @@ test_79(QPDF&amp; pdf, char const* arg2)
2767 2762
2768 // Use a provider 2763 // Use a provider
2769 Pl_Buffer b("buffer"); 2764 Pl_Buffer b("buffer");
2770 - b.write(QUtil::unsigned_char_pointer("from buffer"), 11); 2765 + b.writeCStr("from buffer");
2771 b.finish(); 2766 b.finish();
2772 auto bp = b.getBufferSharedPointer(); 2767 auto bp = b.getBufferSharedPointer();
2773 auto s3 = QPDFObjectHandle::newStream(&pdf, bp); 2768 auto s3 = QPDFObjectHandle::newStream(&pdf, bp);