aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2018-06-19 17:00:15 +0200
committerJay Berkenbilt <ejb@ql.org>2018-06-21 21:57:13 +0200
commit4cded10821e3bd523cf96eb628d7364820a07b84 (patch)
treeb3509d6b845450f2712a0e4a09331f1f91849159 /libqpdf
parent078cf9bf90ec22ba141ebf379e6993b491c2995d (diff)
downloadqpdf-4cded10821e3bd523cf96eb628d7364820a07b84.tar.zst
Add QPDFObjectHandle::Rectangle type
Provide a convenient way of accessing rectangles.
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDFObjectHandle.cc64
1 files changed, 62 insertions, 2 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index 149668eb..5c111cc8 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -554,6 +554,42 @@ QPDFObjectHandle::getArrayItem(int n)
return result;
}
+bool
+QPDFObjectHandle::isRectangle()
+{
+ if (! isArray())
+ {
+ return false;
+ }
+ if (getArrayNItems() != 4)
+ {
+ return false;
+ }
+ for (size_t i = 0; i < 4; ++i)
+ {
+ if (! getArrayItem(i).isNumber())
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+
+QPDFObjectHandle::Rectangle
+QPDFObjectHandle::getArrayAsRectangle()
+{
+ Rectangle result;
+ if (isRectangle())
+ {
+ result = Rectangle(getArrayItem(0).getNumericValue(),
+ getArrayItem(1).getNumericValue(),
+ getArrayItem(2).getNumericValue(),
+ getArrayItem(3).getNumericValue());
+ }
+ return result;
+}
+
std::vector<QPDFObjectHandle>
QPDFObjectHandle::getArrayAsVector()
{
@@ -1834,6 +1870,23 @@ QPDFObjectHandle::newArray(std::vector<QPDFObjectHandle> const& items)
}
QPDFObjectHandle
+QPDFObjectHandle::newArray(Rectangle const& rect)
+{
+ std::vector<QPDFObjectHandle> items;
+ items.push_back(newReal(rect.llx));
+ items.push_back(newReal(rect.lly));
+ items.push_back(newReal(rect.urx));
+ items.push_back(newReal(rect.ury));
+ return newArray(items);
+}
+
+QPDFObjectHandle
+QPDFObjectHandle::newFromRectangle(Rectangle const& rect)
+{
+ return newArray(rect);
+}
+
+QPDFObjectHandle
QPDFObjectHandle::newDictionary()
{
return newDictionary(std::map<std::string, QPDFObjectHandle>());
@@ -2103,7 +2156,8 @@ QPDFObjectHandle::typeWarning(char const* expected_type,
}
void
-QPDFObjectHandle::objectWarning(std::string const& warning)
+QPDFObjectHandle::warnIfPossible(std::string const& warning,
+ bool throw_if_no_description)
{
QPDF* context = 0;
std::string description;
@@ -2115,13 +2169,19 @@ QPDFObjectHandle::objectWarning(std::string const& warning)
"", description, 0,
warning));
}
- else
+ else if (throw_if_no_description)
{
throw std::logic_error(warning);
}
}
void
+QPDFObjectHandle::objectWarning(std::string const& warning)
+{
+ warnIfPossible(warning, true);
+}
+
+void
QPDFObjectHandle::assertType(char const* type_name, bool istype)
{
if (! istype)