mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-22 22:58:33 +00:00
Deprecate QPDFObjectHandle::isInitialized and remove from library
This commit is contained in:
parent
5a33c75b98
commit
0afaaea22a
@ -131,7 +131,7 @@ main(int argc, char* argv[])
|
||||
QPDFObjectHandle fileinfo;
|
||||
|
||||
for (auto const& it: Keys) {
|
||||
if (!fileinfo.isInitialized()) {
|
||||
if (!fileinfo) {
|
||||
if (filetrailer.hasKey("/Info")) {
|
||||
QTC::TC("examples", "pdf-mod-info has info");
|
||||
fileinfo = filetrailer.getKey("/Info");
|
||||
|
@ -300,8 +300,7 @@ class QPDFObjectHandle
|
||||
QPDF_DLL
|
||||
explicit inline operator bool() const noexcept;
|
||||
|
||||
QPDF_DLL
|
||||
inline bool isInitialized() const;
|
||||
[[deprecated("use operator bool()")]] QPDF_DLL inline bool isInitialized() const;
|
||||
|
||||
// This method returns true if the QPDFObjectHandle objects point to exactly the same underlying
|
||||
// object, meaning that changes to one are reflected in the other, or "if you paint one, the
|
||||
|
@ -300,8 +300,7 @@ class QPDFObjectHandle
|
||||
QPDF_DLL
|
||||
explicit inline operator bool() const noexcept;
|
||||
|
||||
QPDF_DLL
|
||||
inline bool isInitialized() const noexcept;
|
||||
[[deprecated("use operator bool()")]] QPDF_DLL inline bool isInitialized() const noexcept;
|
||||
|
||||
// This method returns true if the QPDFObjectHandle objects point to exactly the same underlying
|
||||
// object, meaning that changes to one are reflected in the other, or "if you paint one, the
|
||||
|
@ -188,7 +188,7 @@ NNTreeIterator::resetLimits(QPDFObjectHandle node, std::list<PathElement>::itera
|
||||
}
|
||||
}
|
||||
}
|
||||
if (first.isInitialized() && last.isInitialized()) {
|
||||
if (first && last) {
|
||||
auto limits = QPDFObjectHandle::newArray();
|
||||
limits.appendItem(first);
|
||||
limits.appendItem(last);
|
||||
|
@ -526,7 +526,7 @@ QPDF::warn(
|
||||
void
|
||||
QPDF::setTrailer(QPDFObjectHandle obj)
|
||||
{
|
||||
if (m->trailer.isInitialized()) {
|
||||
if (m->trailer) {
|
||||
return;
|
||||
}
|
||||
m->trailer = obj;
|
||||
@ -591,7 +591,7 @@ QPDF::reconstruct_xref(QPDFExc& e)
|
||||
}
|
||||
}
|
||||
m->file->seek(pos, SEEK_SET);
|
||||
} else if (!m->trailer.isInitialized() && t1.isWord("trailer")) {
|
||||
} else if (!m->trailer && t1.isWord("trailer")) {
|
||||
auto pos = m->file->tell();
|
||||
QPDFObjectHandle t = readTrailer();
|
||||
if (!t.isDictionary()) {
|
||||
@ -606,7 +606,7 @@ QPDF::reconstruct_xref(QPDFExc& e)
|
||||
}
|
||||
m->deleted_objects.clear();
|
||||
|
||||
if (!m->trailer.isInitialized()) {
|
||||
if (!m->trailer) {
|
||||
qpdf_offset_t max_offset{0};
|
||||
// If there are any xref streams, take the last one to appear.
|
||||
for (auto const& iter: m->xref_table) {
|
||||
@ -640,7 +640,7 @@ QPDF::reconstruct_xref(QPDFExc& e)
|
||||
}
|
||||
}
|
||||
|
||||
if (!m->trailer.isInitialized()) {
|
||||
if (!m->trailer) {
|
||||
// We could check the last encountered object to see if it was an xref stream. If so, we
|
||||
// could try to get the trailer from there. This may make it possible to recover files with
|
||||
// bad startxref pointers even when they have object streams.
|
||||
@ -730,7 +730,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset)
|
||||
}
|
||||
}
|
||||
|
||||
if (!m->trailer.isInitialized()) {
|
||||
if (!m->trailer) {
|
||||
throw damagedPDF("", 0, "unable to find trailer while reading xref");
|
||||
}
|
||||
int size = m->trailer.getKey("/Size").getIntValueAsInt();
|
||||
@ -1000,7 +1000,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset)
|
||||
throw damagedPDF("", "expected trailer dictionary");
|
||||
}
|
||||
|
||||
if (!m->trailer.isInitialized()) {
|
||||
if (!m->trailer) {
|
||||
setTrailer(cur_trailer);
|
||||
|
||||
if (!m->trailer.hasKey("/Size")) {
|
||||
@ -1258,7 +1258,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
|
||||
}
|
||||
}
|
||||
|
||||
if (!m->trailer.isInitialized()) {
|
||||
if (!m->trailer) {
|
||||
setTrailer(dict);
|
||||
}
|
||||
|
||||
@ -2052,7 +2052,7 @@ QPDF::makeIndirectFromQPDFObject(std::shared_ptr<QPDFObject> const& obj)
|
||||
QPDFObjectHandle
|
||||
QPDF::makeIndirectObject(QPDFObjectHandle oh)
|
||||
{
|
||||
if (!oh.isInitialized()) {
|
||||
if (!oh) {
|
||||
throw std::logic_error("attempted to make an uninitialized QPDFObjectHandle indirect");
|
||||
}
|
||||
return makeIndirectFromQPDFObject(oh.getObj());
|
||||
@ -2163,7 +2163,7 @@ QPDF::replaceObject(int objid, int generation, QPDFObjectHandle oh)
|
||||
void
|
||||
QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle oh)
|
||||
{
|
||||
if (!oh.isInitialized() || (oh.isIndirect() && !(oh.isStream() && oh.getObjGen() == og))) {
|
||||
if (!oh || (oh.isIndirect() && !(oh.isStream() && oh.getObjGen() == og))) {
|
||||
QTC::TC("qpdf", "QPDF replaceObject called with indirect object");
|
||||
throw std::logic_error("QPDF::replaceObject called with indirect object handle");
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name)
|
||||
} else {
|
||||
annot = kid;
|
||||
}
|
||||
if (!annot.isInitialized()) {
|
||||
if (!annot) {
|
||||
QTC::TC("qpdf", "QPDFObjectHandle broken radio button");
|
||||
this->oh.warnIfPossible("unable to set the value of this radio button");
|
||||
continue;
|
||||
@ -459,7 +459,7 @@ QPDFFormFieldObjectHelper::setCheckBoxValue(bool value)
|
||||
// Set /AS to the on value or /Off in addition to setting /V.
|
||||
QPDFObjectHandle name = QPDFObjectHandle::newName(value ? on_value : "/Off");
|
||||
setFieldAttribute("/V", name);
|
||||
if (!annot.isInitialized()) {
|
||||
if (!annot) {
|
||||
QTC::TC("qpdf", "QPDFObjectHandle broken checkbox");
|
||||
this->oh.warnIfPossible("unable to set the value of this checkbox");
|
||||
return;
|
||||
@ -815,7 +815,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& ao
|
||||
QPDFObjectHandle resources = AS.getDict().getKey("/Resources");
|
||||
QPDFObjectHandle font = getFontFromResource(resources, font_name);
|
||||
bool found_font_in_dr = false;
|
||||
if (!font.isInitialized()) {
|
||||
if (!font) {
|
||||
QPDFObjectHandle dr = getDefaultResources();
|
||||
font = getFontFromResource(dr, font_name);
|
||||
found_font_in_dr = font.isDictionary();
|
||||
|
@ -2165,7 +2165,7 @@ QPDFObjectHandle::parseContentStream_data(
|
||||
input->seek(offset, SEEK_SET);
|
||||
auto obj =
|
||||
QPDFParser(*input, "content", tokenizer, nullptr, context, false).parse(empty, true);
|
||||
if (!obj.isInitialized()) {
|
||||
if (!obj) {
|
||||
// EOF
|
||||
break;
|
||||
}
|
||||
@ -2520,7 +2520,7 @@ QPDFObjectHandle::makeDirect(bool allow_streams)
|
||||
void
|
||||
QPDFObjectHandle::assertInitialized() const
|
||||
{
|
||||
if (!isInitialized()) {
|
||||
if (!obj) {
|
||||
throw std::logic_error("operation attempted on uninitialized QPDFObjectHandle");
|
||||
}
|
||||
}
|
||||
@ -3018,34 +3018,30 @@ QPDFObjectHandle::QPDFArrayItems::end()
|
||||
QPDFObjGen
|
||||
QPDFObjectHandle::getObjGen() const
|
||||
{
|
||||
return isInitialized() ? obj->getObjGen() : QPDFObjGen();
|
||||
return obj ? obj->getObjGen() : QPDFObjGen();
|
||||
}
|
||||
|
||||
// Indirect object accessors
|
||||
QPDF*
|
||||
QPDFObjectHandle::getOwningQPDF() const
|
||||
{
|
||||
return isInitialized() ? this->obj->getQPDF() : nullptr;
|
||||
return obj ? obj->getQPDF() : nullptr;
|
||||
}
|
||||
|
||||
QPDF&
|
||||
QPDFObjectHandle::getQPDF(std::string const& error_msg) const
|
||||
{
|
||||
auto result = isInitialized() ? this->obj->getQPDF() : nullptr;
|
||||
if (result == nullptr) {
|
||||
throw std::runtime_error(
|
||||
error_msg.empty() ? "attempt to use a null qpdf object" : error_msg);
|
||||
if (auto result = obj ? obj->getQPDF() : nullptr) {
|
||||
return *result;
|
||||
}
|
||||
return *result;
|
||||
throw std::runtime_error(error_msg.empty() ? "attempt to use a null qpdf object" : error_msg);
|
||||
}
|
||||
|
||||
void
|
||||
QPDFObjectHandle::setParsedOffset(qpdf_offset_t offset)
|
||||
{
|
||||
// This is called during parsing on newly created direct objects,
|
||||
// so we can't call dereference() here.
|
||||
if (isInitialized()) {
|
||||
this->obj->setParsedOffset(offset);
|
||||
if (obj) {
|
||||
obj->setParsedOffset(offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ QPDFOutlineDocumentHelper::resolveNamedDest(QPDFObjectHandle name)
|
||||
{
|
||||
QPDFObjectHandle result;
|
||||
if (name.isName()) {
|
||||
if (!m->dest_dict.isInitialized()) {
|
||||
if (!m->dest_dict) {
|
||||
m->dest_dict = qpdf.getRoot().getKey("/Dests");
|
||||
}
|
||||
QTC::TC("qpdf", "QPDFOutlineDocumentHelper name named dest");
|
||||
@ -85,7 +85,7 @@ QPDFOutlineDocumentHelper::resolveNamedDest(QPDFObjectHandle name)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!result.isInitialized()) {
|
||||
if (!result) {
|
||||
return QPDFObjectHandle::newNull();
|
||||
}
|
||||
if (result.isDictionary()) {
|
||||
|
@ -59,8 +59,8 @@ QPDFOutlineObjectHelper::getDest()
|
||||
QTC::TC("qpdf", "QPDFOutlineObjectHelper action dest");
|
||||
dest = A.getKey("/D");
|
||||
}
|
||||
if (!dest.isInitialized()) {
|
||||
dest = QPDFObjectHandle::newNull();
|
||||
if (!dest) {
|
||||
return QPDFObjectHandle::newNull();
|
||||
}
|
||||
|
||||
if (dest.isName() || dest.isString()) {
|
||||
|
@ -1381,7 +1381,7 @@ QPDFWriter::unparseObject(
|
||||
}
|
||||
}
|
||||
|
||||
if (extensions.isInitialized()) {
|
||||
if (extensions) {
|
||||
std::set<std::string> keys = extensions.getKeys();
|
||||
if (keys.count("/ADBE") > 0) {
|
||||
have_extensions_adbe = true;
|
||||
@ -1412,7 +1412,7 @@ QPDFWriter::unparseObject(
|
||||
}
|
||||
}
|
||||
|
||||
if (extensions.isInitialized()) {
|
||||
if (extensions) {
|
||||
QTC::TC("qpdf", "QPDFWriter preserve Extensions");
|
||||
QPDFObjectHandle adbe = extensions.getKey("/ADBE");
|
||||
if (adbe.isDictionary() &&
|
||||
|
@ -661,18 +661,17 @@ void
|
||||
QPDF_Stream::replaceFilterData(
|
||||
QPDFObjectHandle const& filter, QPDFObjectHandle const& decode_parms, size_t length)
|
||||
{
|
||||
if (filter.isInitialized()) {
|
||||
this->stream_dict.replaceKey("/Filter", filter);
|
||||
if (filter) {
|
||||
stream_dict.replaceKey("/Filter", filter);
|
||||
}
|
||||
if (decode_parms.isInitialized()) {
|
||||
this->stream_dict.replaceKey("/DecodeParms", decode_parms);
|
||||
if (decode_parms) {
|
||||
stream_dict.replaceKey("/DecodeParms", decode_parms);
|
||||
}
|
||||
if (length == 0) {
|
||||
QTC::TC("qpdf", "QPDF_Stream unknown stream length");
|
||||
this->stream_dict.removeKey("/Length");
|
||||
stream_dict.removeKey("/Length");
|
||||
} else {
|
||||
this->stream_dict.replaceKey(
|
||||
"/Length", QPDFObjectHandle::newInteger(QIntC::to_longlong(length)));
|
||||
stream_dict.replaceKey("/Length", QPDFObjectHandle::newInteger(QIntC::to_longlong(length)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -325,7 +325,7 @@ QPDF::JSONReactor::anyErrors() const
|
||||
void
|
||||
QPDF::JSONReactor::containerStart()
|
||||
{
|
||||
if (next_obj.isInitialized()) {
|
||||
if (next_obj) {
|
||||
stack.emplace_back(next_state, std::move(next_obj));
|
||||
next_obj = QPDFObjectHandle();
|
||||
} else {
|
||||
@ -558,7 +558,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value)
|
||||
throw std::logic_error("stack empty in st_object_top");
|
||||
}
|
||||
auto& tos = stack.back();
|
||||
if (!tos.object.isInitialized()) {
|
||||
if (!tos.object) {
|
||||
throw std::logic_error("current object uninitialized in st_object_top");
|
||||
}
|
||||
if (key == "value") {
|
||||
@ -767,7 +767,7 @@ QPDF::JSONReactor::makeObject(JSON const& value)
|
||||
result = QPDFObjectHandle::newNull();
|
||||
}
|
||||
}
|
||||
if (!result.isInitialized()) {
|
||||
if (!result) {
|
||||
throw std::logic_error("JSONReactor::makeObject didn't initialize the object");
|
||||
}
|
||||
|
||||
|
@ -955,7 +955,7 @@ qpdf_oh_is_initialized(qpdf_data qpdf, qpdf_oh oh)
|
||||
{
|
||||
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_initialized");
|
||||
return do_with_oh<QPDF_BOOL>(
|
||||
qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isInitialized(); });
|
||||
qpdf, oh, return_false, [](QPDFObjectHandle& o) { return static_cast<bool>(o); });
|
||||
}
|
||||
|
||||
QPDF_BOOL
|
||||
|
@ -1428,7 +1428,7 @@ test_42(QPDF& pdf, char const* arg2)
|
||||
assert(i == ai.end());
|
||||
++i;
|
||||
assert(i == ai.end());
|
||||
assert(!i_value.isInitialized());
|
||||
assert(!i_value);
|
||||
--i;
|
||||
assert(i_value.getName() == "/Item2");
|
||||
assert(i->getName() == "/Item2");
|
||||
@ -1444,7 +1444,7 @@ test_42(QPDF& pdf, char const* arg2)
|
||||
++i;
|
||||
++i;
|
||||
assert(i == di.end());
|
||||
assert(!i_value.second.isInitialized());
|
||||
assert(!i_value.second);
|
||||
}
|
||||
assert("" == qtest.getStringValue());
|
||||
array.getArrayItem(-1).assertNull();
|
||||
@ -1542,7 +1542,7 @@ test_42(QPDF& pdf, char const* arg2)
|
||||
assert(m1.a == 0 && m1.b == 0 && m1.c == 0 && m1.d == 0 && m1.e == 0 && m1.f == 0);
|
||||
// Uninitialized
|
||||
QPDFObjectHandle uninitialized;
|
||||
assert(!uninitialized.isInitialized());
|
||||
assert(!uninitialized);
|
||||
assert(!uninitialized.isInteger());
|
||||
assert(!uninitialized.isDictionary());
|
||||
assert(!uninitialized.isScalar());
|
||||
@ -1692,7 +1692,7 @@ test_46(QPDF& pdf, char const* arg2)
|
||||
assert(iter1_val.first == 2);
|
||||
++iter1;
|
||||
assert(iter1 == new1.end());
|
||||
assert(!iter1_val.second.isInitialized());
|
||||
assert(!iter1_val.second);
|
||||
++iter1;
|
||||
assert(iter1->first == 1);
|
||||
--iter1;
|
||||
@ -1842,7 +1842,7 @@ test_48(QPDF& pdf, char const* arg2)
|
||||
assert(iter1_val.first == "2");
|
||||
++iter1;
|
||||
assert(iter1 == new1.end());
|
||||
assert(!iter1_val.second.isInitialized());
|
||||
assert(!iter1_val.second);
|
||||
++iter1;
|
||||
assert(iter1->first == "1");
|
||||
--iter1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user