mirror of
https://github.com/qpdf/qpdf.git
synced 2024-06-09 05:32:43 +00:00
implement methods to get dictionary and array contents as map and vector
This commit is contained in:
parent
d9ec2eb0f6
commit
655c55f848
|
@ -172,6 +172,8 @@ class QPDFObjectHandle
|
||||||
int getArrayNItems();
|
int getArrayNItems();
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
QPDFObjectHandle getArrayItem(int n);
|
QPDFObjectHandle getArrayItem(int n);
|
||||||
|
QPDF_DLL
|
||||||
|
std::vector<QPDFObjectHandle> getArrayAsVector();
|
||||||
|
|
||||||
// Methods for dictionary objects
|
// Methods for dictionary objects
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
|
@ -180,6 +182,8 @@ class QPDFObjectHandle
|
||||||
QPDFObjectHandle getKey(std::string const&);
|
QPDFObjectHandle getKey(std::string const&);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
std::set<std::string> getKeys();
|
std::set<std::string> getKeys();
|
||||||
|
QPDF_DLL
|
||||||
|
std::map<std::string, QPDFObjectHandle> getDictAsMap();
|
||||||
|
|
||||||
// Methods for name and array objects
|
// Methods for name and array objects
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
|
|
|
@ -246,6 +246,13 @@ QPDFObjectHandle::getArrayItem(int n)
|
||||||
return dynamic_cast<QPDF_Array*>(obj.getPointer())->getItem(n);
|
return dynamic_cast<QPDF_Array*>(obj.getPointer())->getItem(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<QPDFObjectHandle>
|
||||||
|
QPDFObjectHandle::getArrayAsVector()
|
||||||
|
{
|
||||||
|
assertType("Array", isArray());
|
||||||
|
return dynamic_cast<QPDF_Array*>(obj.getPointer())->getAsVector();
|
||||||
|
}
|
||||||
|
|
||||||
// Array mutators
|
// Array mutators
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -278,6 +285,13 @@ QPDFObjectHandle::getKeys()
|
||||||
return dynamic_cast<QPDF_Dictionary*>(obj.getPointer())->getKeys();
|
return dynamic_cast<QPDF_Dictionary*>(obj.getPointer())->getKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, QPDFObjectHandle>
|
||||||
|
QPDFObjectHandle::getDictAsMap()
|
||||||
|
{
|
||||||
|
assertType("Dictionary", isDictionary());
|
||||||
|
return dynamic_cast<QPDF_Dictionary*>(obj.getPointer())->getAsMap();
|
||||||
|
}
|
||||||
|
|
||||||
// Array and Name accessors
|
// Array and Name accessors
|
||||||
bool
|
bool
|
||||||
QPDFObjectHandle::isOrHasName(std::string const& value)
|
QPDFObjectHandle::isOrHasName(std::string const& value)
|
||||||
|
|
|
@ -51,6 +51,12 @@ QPDF_Array::getItem(int n) const
|
||||||
return this->items[n];
|
return this->items[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<QPDFObjectHandle> const&
|
||||||
|
QPDF_Array::getAsVector() const
|
||||||
|
{
|
||||||
|
return this->items;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QPDF_Array::setItem(int n, QPDFObjectHandle const& oh)
|
QPDF_Array::setItem(int n, QPDFObjectHandle const& oh)
|
||||||
{
|
{
|
||||||
|
|
|
@ -78,6 +78,13 @@ QPDF_Dictionary::getKeys()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, QPDFObjectHandle> const&
|
||||||
|
QPDF_Dictionary::getAsMap() const
|
||||||
|
{
|
||||||
|
|
||||||
|
return this->items;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QPDF_Dictionary::replaceKey(std::string const& key,
|
QPDF_Dictionary::replaceKey(std::string const& key,
|
||||||
QPDFObjectHandle const& value)
|
QPDFObjectHandle const& value)
|
||||||
|
|
|
@ -14,6 +14,7 @@ class QPDF_Array: public QPDFObject
|
||||||
virtual std::string unparse();
|
virtual std::string unparse();
|
||||||
int getNItems() const;
|
int getNItems() const;
|
||||||
QPDFObjectHandle getItem(int n) const;
|
QPDFObjectHandle getItem(int n) const;
|
||||||
|
std::vector<QPDFObjectHandle> const& getAsVector() const;
|
||||||
void setItem(int, QPDFObjectHandle const&);
|
void setItem(int, QPDFObjectHandle const&);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -21,6 +21,7 @@ class QPDF_Dictionary: public QPDFObject
|
||||||
bool hasKey(std::string const&);
|
bool hasKey(std::string const&);
|
||||||
QPDFObjectHandle getKey(std::string const&);
|
QPDFObjectHandle getKey(std::string const&);
|
||||||
std::set<std::string> getKeys();
|
std::set<std::string> getKeys();
|
||||||
|
std::map<std::string, QPDFObjectHandle> const& getAsMap() const;
|
||||||
|
|
||||||
// Replace value of key, adding it if it does not exist
|
// Replace value of key, adding it if it does not exist
|
||||||
void replaceKey(std::string const& key, QPDFObjectHandle const&);
|
void replaceKey(std::string const& key, QPDFObjectHandle const&);
|
||||||
|
|
|
@ -3,4 +3,5 @@ old dict: 1
|
||||||
old dict: 1
|
old dict: 1
|
||||||
new dict: 2
|
new dict: 2
|
||||||
swapped array: /Array
|
swapped array: /Array
|
||||||
|
array and dictionary contents are correct
|
||||||
test 14 done
|
test 14 done
|
||||||
|
|
|
@ -570,6 +570,20 @@ void runtest(int n, char const* filename)
|
||||||
std::cout << "swapped array: " << qdict.getArrayItem(0).getName()
|
std::cout << "swapped array: " << qdict.getArrayItem(0).getName()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
|
// Exercise getAsMap and getAsArray
|
||||||
|
std::vector<QPDFObjectHandle> array_elements =
|
||||||
|
qdict.getArrayAsVector();
|
||||||
|
std::map<std::string, QPDFObjectHandle> dict_items =
|
||||||
|
qarray.getDictAsMap();
|
||||||
|
if ((array_elements.size() == 1) &&
|
||||||
|
(array_elements[0].getName() == "/Array") &&
|
||||||
|
(dict_items.size() == 1) &&
|
||||||
|
(dict_items["/NewDict"].getIntValue() == 2))
|
||||||
|
{
|
||||||
|
std::cout << "array and dictionary contents are correct"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
QPDFWriter w(pdf, "a.pdf");
|
QPDFWriter w(pdf, "a.pdf");
|
||||||
w.setStaticID(true);
|
w.setStaticID(true);
|
||||||
w.setStreamDataMode(qpdf_s_preserve);
|
w.setStreamDataMode(qpdf_s_preserve);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user