mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 19:08:59 +00:00
Refactor qpdf processing
Push calls to processFile and processInputSource into separate functions in preparation for password recovery changes
This commit is contained in:
parent
e87d149918
commit
e4fa5a3c2a
63
qpdf/qpdf.cc
63
qpdf/qpdf.cc
@ -3670,6 +3670,39 @@ ImageOptimizer::provideStreamData(int, int, Pipeline* pipeline)
|
|||||||
false, false);
|
false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static PointerHolder<QPDF> do_process(
|
||||||
|
void (QPDF::*fn)(T, char const*),
|
||||||
|
T item, char const* password,
|
||||||
|
Options& o, bool empty)
|
||||||
|
{
|
||||||
|
PointerHolder<QPDF> pdf = new QPDF;
|
||||||
|
set_qpdf_options(*pdf, o);
|
||||||
|
if (empty)
|
||||||
|
{
|
||||||
|
pdf->emptyPDF();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
((*pdf).*fn)(item, password);
|
||||||
|
}
|
||||||
|
return pdf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PointerHolder<QPDF> process_file(char const* filename,
|
||||||
|
char const* password,
|
||||||
|
Options& o)
|
||||||
|
{
|
||||||
|
return do_process(&QPDF::processFile, filename, password, o,
|
||||||
|
strcmp(filename, "") == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PointerHolder<QPDF> process_input_source(
|
||||||
|
PointerHolder<InputSource> is, char const* password, Options& o)
|
||||||
|
{
|
||||||
|
return do_process(&QPDF::processInputSource, is, password, o, false);
|
||||||
|
}
|
||||||
|
|
||||||
static void handle_transformations(QPDF& pdf, Options& o)
|
static void handle_transformations(QPDF& pdf, Options& o)
|
||||||
{
|
{
|
||||||
QPDFPageDocumentHelper dh(pdf);
|
QPDFPageDocumentHelper dh(pdf);
|
||||||
@ -3807,9 +3840,6 @@ static void handle_page_specs(QPDF& pdf, Options& o)
|
|||||||
// the API, you can just create two different QPDF objects
|
// the API, you can just create two different QPDF objects
|
||||||
// to the same underlying file with the same path to
|
// to the same underlying file with the same path to
|
||||||
// achieve the same affect.
|
// achieve the same affect.
|
||||||
PointerHolder<QPDF> qpdf_ph = new QPDF();
|
|
||||||
page_heap.push_back(qpdf_ph);
|
|
||||||
QPDF* qpdf = qpdf_ph.getPointer();
|
|
||||||
char const* password = page_spec.password;
|
char const* password = page_spec.password;
|
||||||
if (o.encryption_file && (password == 0) &&
|
if (o.encryption_file && (password == 0) &&
|
||||||
(page_spec.filename == o.encryption_file))
|
(page_spec.filename == o.encryption_file))
|
||||||
@ -3838,8 +3868,9 @@ static void handle_page_specs(QPDF& pdf, Options& o)
|
|||||||
is = fis;
|
is = fis;
|
||||||
fis->setFilename(page_spec.filename.c_str());
|
fis->setFilename(page_spec.filename.c_str());
|
||||||
}
|
}
|
||||||
qpdf->processInputSource(is, password);
|
PointerHolder<QPDF> qpdf_ph = process_input_source(is, password, o);
|
||||||
page_spec_qpdfs[page_spec.filename] = qpdf;
|
page_heap.push_back(qpdf_ph);
|
||||||
|
page_spec_qpdfs[page_spec.filename] = qpdf_ph.getPointer();
|
||||||
if (cis)
|
if (cis)
|
||||||
{
|
{
|
||||||
cis->stayOpen(false);
|
cis->stayOpen(false);
|
||||||
@ -4176,10 +4207,10 @@ static void set_writer_options(QPDF& pdf, Options& o, QPDFWriter& w)
|
|||||||
}
|
}
|
||||||
if (o.copy_encryption)
|
if (o.copy_encryption)
|
||||||
{
|
{
|
||||||
QPDF encryption_pdf;
|
PointerHolder<QPDF> encryption_pdf =
|
||||||
encryption_pdf.processFile(
|
process_file(
|
||||||
o.encryption_file, o.encryption_file_password);
|
o.encryption_file, o.encryption_file_password, o);
|
||||||
w.copyEncryptionParameters(encryption_pdf);
|
w.copyEncryptionParameters(*encryption_pdf);
|
||||||
}
|
}
|
||||||
if (o.encrypt)
|
if (o.encrypt)
|
||||||
{
|
{
|
||||||
@ -4355,17 +4386,9 @@ int realmain(int argc, char* argv[])
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QPDF pdf;
|
PointerHolder<QPDF> pdf_ph =
|
||||||
set_qpdf_options(pdf, o);
|
process_file(o.infilename, o.password, o);
|
||||||
if (strcmp(o.infilename, "") == 0)
|
QPDF& pdf = *pdf_ph;
|
||||||
{
|
|
||||||
pdf.emptyPDF();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pdf.processFile(o.infilename, o.password);
|
|
||||||
}
|
|
||||||
|
|
||||||
handle_transformations(pdf, o);
|
handle_transformations(pdf, o);
|
||||||
if (! o.page_specs.empty())
|
if (! o.page_specs.empty())
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user