2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-05-29 00:10:54 +00:00

QPDFJob: convert PageSpec to used shared pointer

This commit is contained in:
Jay Berkenbilt 2022-01-22 18:43:05 -05:00
parent e4905983d2
commit e48bfce930
2 changed files with 19 additions and 12 deletions

View File

@ -123,16 +123,11 @@ class QPDFJob
{ {
PageSpec(std::string const& filename, PageSpec(std::string const& filename,
char const* password, char const* password,
char const* range) : std::string const& range);
filename(filename),
password(password),
range(range)
{
}
std::string filename; std::string filename;
char const* password; std::shared_ptr<char> password;
char const* range; std::string range;
}; };
struct RotationSpec struct RotationSpec

View File

@ -64,7 +64,7 @@ namespace
struct QPDFPageData struct QPDFPageData
{ {
QPDFPageData(std::string const& filename, QPDFPageData(std::string const& filename,
QPDF* qpdf, char const* range); QPDF* qpdf, std::string const& range);
QPDFPageData(QPDFPageData const& other, int page); QPDFPageData(QPDFPageData const& other, int page);
std::string filename; std::string filename;
@ -272,9 +272,21 @@ ImageOptimizer::provideStreamData(int, int, Pipeline* pipeline)
false, false); false, false);
} }
QPDFJob::PageSpec::PageSpec(std::string const& filename,
char const* password,
std::string const& range) :
filename(filename),
range(range)
{
if (password)
{
this->password = QUtil::make_shared_cstr(password);
}
}
QPDFPageData::QPDFPageData(std::string const& filename, QPDFPageData::QPDFPageData(std::string const& filename,
QPDF* qpdf, QPDF* qpdf,
char const* range) : std::string const& range) :
filename(filename), filename(filename),
qpdf(qpdf), qpdf(qpdf),
orig_pages(qpdf->getAllPages()) orig_pages(qpdf->getAllPages())
@ -282,7 +294,7 @@ QPDFPageData::QPDFPageData(std::string const& filename,
try try
{ {
this->selected_pages = this->selected_pages =
QUtil::parse_numrange(range, QUtil::parse_numrange(range.c_str(),
QIntC::to_int(this->orig_pages.size())); QIntC::to_int(this->orig_pages.size()));
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
@ -2599,7 +2611,7 @@ QPDFJob::handlePageSpecs(
// 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.
char const* password = page_spec.password; char const* password = page_spec.password.get();
if ((! o.encryption_file.empty()) && (password == 0) && if ((! o.encryption_file.empty()) && (password == 0) &&
(page_spec.filename == o.encryption_file)) (page_spec.filename == o.encryption_file))
{ {