mirror of
https://github.com/qpdf/qpdf.git
synced 2024-11-01 03:12:29 +00:00
Add private method QPDFObjectHandle::getObjGenAsStr
Also, use methods to access objid and generation.
This commit is contained in:
parent
97f737a562
commit
e9c1637353
@ -1581,6 +1581,7 @@ class QPDFObjectHandle
|
|||||||
bool stop_at_streams);
|
bool stop_at_streams);
|
||||||
void shallowCopyInternal(QPDFObjectHandle& oh, bool first_level_only);
|
void shallowCopyInternal(QPDFObjectHandle& oh, bool first_level_only);
|
||||||
void releaseResolved();
|
void releaseResolved();
|
||||||
|
std::string getObjGenAsStr() const;
|
||||||
static void setObjectDescriptionFromInput(
|
static void setObjectDescriptionFromInput(
|
||||||
QPDFObjectHandle,
|
QPDFObjectHandle,
|
||||||
QPDF*,
|
QPDF*,
|
||||||
|
@ -338,7 +338,7 @@ QPDFObjectHandle::isDirectNull() const
|
|||||||
// Don't call dereference() -- this is a const method, and we know
|
// Don't call dereference() -- this is a const method, and we know
|
||||||
// objid == 0, so there's nothing to resolve.
|
// objid == 0, so there's nothing to resolve.
|
||||||
return (
|
return (
|
||||||
this->initialized && (this->objid == 0) &&
|
this->initialized && (getObjectID() == 0) &&
|
||||||
QPDFObjectTypeAccessor<QPDF_Null>::check(obj.get()));
|
QPDFObjectTypeAccessor<QPDF_Null>::check(obj.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,7 +490,7 @@ QPDFObjectHandle::isIndirect()
|
|||||||
if (!this->initialized) {
|
if (!this->initialized) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (this->objid != 0);
|
return (getObjectID() != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@ -1549,6 +1549,13 @@ QPDFObjectHandle::getObjGen() const
|
|||||||
return QPDFObjGen(this->objid, this->generation);
|
return QPDFObjGen(this->objid, this->generation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
QPDFObjectHandle::getObjGenAsStr() const
|
||||||
|
{
|
||||||
|
return QUtil::int_to_string(this->objid) + " " +
|
||||||
|
QUtil::int_to_string(this->generation);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
QPDFObjectHandle::getObjectID() const
|
QPDFObjectHandle::getObjectID() const
|
||||||
{
|
{
|
||||||
@ -1608,14 +1615,12 @@ QPDFObjectHandle::arrayOrStreamToStreamArray(
|
|||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto const& item: result) {
|
for (auto const& item: result) {
|
||||||
std::string og = QUtil::int_to_string(item.getObjectID()) + " " +
|
|
||||||
QUtil::int_to_string(item.getGeneration());
|
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
all_description += ",";
|
all_description += ",";
|
||||||
}
|
}
|
||||||
all_description += " stream " + og;
|
all_description += " stream " + item.getObjGenAsStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -1624,9 +1629,7 @@ QPDFObjectHandle::arrayOrStreamToStreamArray(
|
|||||||
std::vector<QPDFObjectHandle>
|
std::vector<QPDFObjectHandle>
|
||||||
QPDFObjectHandle::getPageContents()
|
QPDFObjectHandle::getPageContents()
|
||||||
{
|
{
|
||||||
std::string description = "page object " +
|
std::string description = "page object " + getObjGenAsStr();
|
||||||
QUtil::int_to_string(this->objid) + " " +
|
|
||||||
QUtil::int_to_string(this->generation);
|
|
||||||
std::string all_description;
|
std::string all_description;
|
||||||
return this->getKey("/Contents")
|
return this->getKey("/Contents")
|
||||||
.arrayOrStreamToStreamArray(description, all_description);
|
.arrayOrStreamToStreamArray(description, all_description);
|
||||||
@ -1735,8 +1738,7 @@ QPDFObjectHandle::unparse()
|
|||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
if (this->isIndirect()) {
|
if (this->isIndirect()) {
|
||||||
result = QUtil::int_to_string(this->objid) + " " +
|
result = getObjGenAsStr() + " R";
|
||||||
QUtil::int_to_string(this->generation) + " R";
|
|
||||||
} else {
|
} else {
|
||||||
result = unparseResolved();
|
result = unparseResolved();
|
||||||
}
|
}
|
||||||
@ -1848,9 +1850,7 @@ QPDFObjectHandle::parse(
|
|||||||
void
|
void
|
||||||
QPDFObjectHandle::pipePageContents(Pipeline* p)
|
QPDFObjectHandle::pipePageContents(Pipeline* p)
|
||||||
{
|
{
|
||||||
std::string description = "page object " +
|
std::string description = "page object " + getObjGenAsStr();
|
||||||
QUtil::int_to_string(this->objid) + " " +
|
|
||||||
QUtil::int_to_string(this->generation);
|
|
||||||
std::string all_description;
|
std::string all_description;
|
||||||
this->getKey("/Contents")
|
this->getKey("/Contents")
|
||||||
.pipeContentStreams(p, description, all_description);
|
.pipeContentStreams(p, description, all_description);
|
||||||
@ -1869,15 +1869,12 @@ QPDFObjectHandle::pipeContentStreams(
|
|||||||
buf.writeCStr("\n");
|
buf.writeCStr("\n");
|
||||||
}
|
}
|
||||||
LastChar lc(&buf);
|
LastChar lc(&buf);
|
||||||
std::string og = QUtil::int_to_string(stream.getObjectID()) + " " +
|
|
||||||
QUtil::int_to_string(stream.getGeneration());
|
|
||||||
std::string w_description = "content stream object " + og;
|
|
||||||
if (!stream.pipeStreamData(&lc, 0, qpdf_dl_specialized)) {
|
if (!stream.pipeStreamData(&lc, 0, qpdf_dl_specialized)) {
|
||||||
QTC::TC("qpdf", "QPDFObjectHandle errors in parsecontent");
|
QTC::TC("qpdf", "QPDFObjectHandle errors in parsecontent");
|
||||||
throw QPDFExc(
|
throw QPDFExc(
|
||||||
qpdf_e_damaged_pdf,
|
qpdf_e_damaged_pdf,
|
||||||
"content stream",
|
"content stream",
|
||||||
w_description,
|
"content stream object " + stream.getObjGenAsStr(),
|
||||||
0,
|
0,
|
||||||
"errors while decoding content stream");
|
"errors while decoding content stream");
|
||||||
}
|
}
|
||||||
@ -1893,9 +1890,7 @@ QPDFObjectHandle::pipeContentStreams(
|
|||||||
void
|
void
|
||||||
QPDFObjectHandle::parsePageContents(ParserCallbacks* callbacks)
|
QPDFObjectHandle::parsePageContents(ParserCallbacks* callbacks)
|
||||||
{
|
{
|
||||||
std::string description = "page object " +
|
std::string description = "page object " + getObjGenAsStr();
|
||||||
QUtil::int_to_string(this->objid) + " " +
|
|
||||||
QUtil::int_to_string(this->generation);
|
|
||||||
this->getKey("/Contents")
|
this->getKey("/Contents")
|
||||||
.parseContentStream_internal(description, callbacks);
|
.parseContentStream_internal(description, callbacks);
|
||||||
}
|
}
|
||||||
@ -1903,17 +1898,14 @@ QPDFObjectHandle::parsePageContents(ParserCallbacks* callbacks)
|
|||||||
void
|
void
|
||||||
QPDFObjectHandle::parseAsContents(ParserCallbacks* callbacks)
|
QPDFObjectHandle::parseAsContents(ParserCallbacks* callbacks)
|
||||||
{
|
{
|
||||||
std::string description = "object " + QUtil::int_to_string(this->objid) +
|
std::string description = "object " + getObjGenAsStr();
|
||||||
" " + QUtil::int_to_string(this->generation);
|
|
||||||
this->parseContentStream_internal(description, callbacks);
|
this->parseContentStream_internal(description, callbacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QPDFObjectHandle::filterPageContents(TokenFilter* filter, Pipeline* next)
|
QPDFObjectHandle::filterPageContents(TokenFilter* filter, Pipeline* next)
|
||||||
{
|
{
|
||||||
std::string description = "token filter for page object " +
|
auto description = "token filter for page object " + getObjGenAsStr();
|
||||||
QUtil::int_to_string(this->objid) + " " +
|
|
||||||
QUtil::int_to_string(this->generation);
|
|
||||||
Pl_QPDFTokenizer token_pipeline(description.c_str(), filter, next);
|
Pl_QPDFTokenizer token_pipeline(description.c_str(), filter, next);
|
||||||
this->pipePageContents(&token_pipeline);
|
this->pipePageContents(&token_pipeline);
|
||||||
}
|
}
|
||||||
@ -1921,9 +1913,7 @@ QPDFObjectHandle::filterPageContents(TokenFilter* filter, Pipeline* next)
|
|||||||
void
|
void
|
||||||
QPDFObjectHandle::filterAsContents(TokenFilter* filter, Pipeline* next)
|
QPDFObjectHandle::filterAsContents(TokenFilter* filter, Pipeline* next)
|
||||||
{
|
{
|
||||||
std::string description = "token filter for object " +
|
auto description = "token filter for object " + getObjGenAsStr();
|
||||||
QUtil::int_to_string(this->objid) + " " +
|
|
||||||
QUtil::int_to_string(this->generation);
|
|
||||||
Pl_QPDFTokenizer token_pipeline(description.c_str(), filter, next);
|
Pl_QPDFTokenizer token_pipeline(description.c_str(), filter, next);
|
||||||
this->pipeStreamData(&token_pipeline, 0, qpdf_dl_specialized);
|
this->pipeStreamData(&token_pipeline, 0, qpdf_dl_specialized);
|
||||||
}
|
}
|
||||||
@ -2862,7 +2852,7 @@ QPDFObjectHandle::copyObject(
|
|||||||
"attempt to make a stream into a direct object");
|
"attempt to make a stream into a direct object");
|
||||||
}
|
}
|
||||||
|
|
||||||
QPDFObjGen cur_og(this->objid, this->generation);
|
auto cur_og = getObjGen();
|
||||||
if (cur_og.getObj() != 0) {
|
if (cur_og.getObj() != 0) {
|
||||||
if (visited.count(cur_og)) {
|
if (visited.count(cur_og)) {
|
||||||
QTC::TC("qpdf", "QPDFObjectHandle makeDirect loop");
|
QTC::TC("qpdf", "QPDFObjectHandle makeDirect loop");
|
||||||
@ -3204,14 +3194,13 @@ QPDFObjectHandle::dereference()
|
|||||||
throw std::logic_error(
|
throw std::logic_error(
|
||||||
"attempted to dereference an uninitialized QPDFObjectHandle");
|
"attempted to dereference an uninitialized QPDFObjectHandle");
|
||||||
}
|
}
|
||||||
if (this->obj.get() && this->objid &&
|
if (this->obj.get() && getObjectID() &&
|
||||||
QPDF::Resolver::objectChanged(
|
QPDF::Resolver::objectChanged(this->qpdf, getObjGen(), this->obj)) {
|
||||||
this->qpdf, QPDFObjGen(this->objid, this->generation), this->obj)) {
|
|
||||||
this->obj = nullptr;
|
this->obj = nullptr;
|
||||||
}
|
}
|
||||||
if (this->obj.get() == 0) {
|
if (this->obj.get() == 0) {
|
||||||
std::shared_ptr<QPDFObject> obj =
|
std::shared_ptr<QPDFObject> obj =
|
||||||
QPDF::Resolver::resolve(this->qpdf, this->objid, this->generation);
|
QPDF::Resolver::resolve(this->qpdf, getObjectID(), getGeneration());
|
||||||
if (obj.get() == 0) {
|
if (obj.get() == 0) {
|
||||||
// QPDF::resolve never returns an uninitialized object, but
|
// QPDF::resolve never returns an uninitialized object, but
|
||||||
// check just in case.
|
// check just in case.
|
||||||
|
Loading…
Reference in New Issue
Block a user