mirror of https://github.com/qpdf/qpdf.git
Merge 24741420e1
into e9166457fa
This commit is contained in:
commit
f024d674e3
|
@ -759,6 +759,10 @@ class QPDFObjectHandle
|
|||
QPDF_DLL
|
||||
QPDFDictItems ditems();
|
||||
|
||||
class DictItems;
|
||||
QPDF_DLL
|
||||
DictItems dItems();
|
||||
|
||||
// Return true if key is present. Keys with null values are treated as if they are not present.
|
||||
// This is as per the PDF spec.
|
||||
QPDF_DLL
|
||||
|
@ -1418,6 +1422,41 @@ QPDFObjectHandle operator ""_qpdf(char const* v, size_t len);
|
|||
|
||||
#endif // QPDF_NO_QPDF_STRING
|
||||
|
||||
class QPDFObjectHandle::DictItems
|
||||
{
|
||||
friend class QPDFObjectHandle;
|
||||
|
||||
public:
|
||||
class iterator: public std::map<std::string, QPDFObjectHandle>::iterator
|
||||
{
|
||||
public:
|
||||
iterator(std::map<std::string, QPDFObjectHandle>::iterator it) :
|
||||
std::map<std::string, QPDFObjectHandle>::iterator(it)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
return dict.begin();
|
||||
}
|
||||
|
||||
iterator end()
|
||||
{
|
||||
return dict.end();
|
||||
}
|
||||
|
||||
private:
|
||||
DictItems(QPDFObjectHandle& oh, std::map<std::string, QPDFObjectHandle>& dict) :
|
||||
oh(oh),
|
||||
dict(dict)
|
||||
{
|
||||
}
|
||||
|
||||
QPDFObjectHandle oh;
|
||||
std::map<std::string, QPDFObjectHandle>& dict;
|
||||
};
|
||||
|
||||
class QPDFObjectHandle::QPDFDictItems
|
||||
{
|
||||
// This class allows C++-style iteration, including range-for iteration, around dictionaries.
|
||||
|
|
|
@ -962,6 +962,19 @@ QPDFObjectHandle::ditems()
|
|||
return {*this};
|
||||
}
|
||||
|
||||
QPDFObjectHandle::DictItems
|
||||
QPDFObjectHandle::dItems()
|
||||
{
|
||||
static std::map<std::string, QPDFObjectHandle> empty;
|
||||
if (auto dict = asDictionary()) {
|
||||
return {*this, dict->getAsMap()};
|
||||
} else {
|
||||
typeWarning("dictionary", "treating as empty");
|
||||
// QTC::TC("qpdf", "QPDFObjectHandle dictionary empty map for dItems");
|
||||
return {*this, empty};
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFObjectHandle::hasKey(std::string const& key)
|
||||
{
|
||||
|
|
|
@ -1129,7 +1129,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object)
|
|||
enqueueObject(item);
|
||||
}
|
||||
} else if (object.isDictionary()) {
|
||||
for (auto& item: object.getDictAsMap()) {
|
||||
for (auto& item: object.dItems()) {
|
||||
if (!item.second.isNull()) {
|
||||
enqueueObject(item.second);
|
||||
}
|
||||
|
@ -1487,7 +1487,7 @@ QPDFWriter::unparseObject(
|
|||
|
||||
writeString("<<");
|
||||
|
||||
for (auto& item: object.getDictAsMap()) {
|
||||
for (auto& item: object.dItems()) {
|
||||
if (!item.second.isNull()) {
|
||||
auto const& key = item.first;
|
||||
writeString(indent);
|
||||
|
|
|
@ -126,8 +126,8 @@ QPDF_Dictionary::getKeys()
|
|||
return result;
|
||||
}
|
||||
|
||||
std::map<std::string, QPDFObjectHandle> const&
|
||||
QPDF_Dictionary::getAsMap() const
|
||||
std::map<std::string, QPDFObjectHandle>&
|
||||
QPDF_Dictionary::getAsMap()
|
||||
{
|
||||
return this->items;
|
||||
}
|
||||
|
@ -152,3 +152,5 @@ QPDF_Dictionary::removeKey(std::string const& key)
|
|||
// no-op if key does not exist
|
||||
this->items.erase(key);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,8 +24,7 @@ class QPDF_Dictionary: public QPDFValue
|
|||
bool hasKey(std::string const&);
|
||||
QPDFObjectHandle getKey(std::string const&);
|
||||
std::set<std::string> getKeys();
|
||||
std::map<std::string, QPDFObjectHandle> const& getAsMap() const;
|
||||
|
||||
std::map<std::string, QPDFObjectHandle>& getAsMap();
|
||||
// If value is null, remove key; otherwise, replace the value of key, adding it if it does not
|
||||
// exist.
|
||||
void replaceKey(std::string const& key, QPDFObjectHandle value);
|
||||
|
|
Loading…
Reference in New Issue