diff options
author | Rodrigo Tobar <rtobar@icrar.org> | 2022-11-25 16:34:06 +0800 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-12-10 10:49:03 +0100 |
commit | 17676705a5f9db8e3ff93b204bc9a347c78e378f (patch) | |
tree | 53f3dfbcfdab03ef9a48994c0415d021db5a02a2 /Userland/Libraries | |
parent | a63b93f7245c0876f7c307986a42304a7201e317 (diff) | |
download | serenity-17676705a5f9db8e3ff93b204bc9a347c78e378f.zip |
LibPDF: Add facility to obtain Vector<float> from ArrayObject
Arrays of float numbers are common in many PDF objects, and thus to
avoid code repetition I'm introducing a new method to ArrayObject that
will return exactly that.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibPDF/ObjectDerivatives.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibPDF/ObjectDerivatives.h | 1 |
2 files changed, 11 insertions, 0 deletions
diff --git a/Userland/Libraries/LibPDF/ObjectDerivatives.cpp b/Userland/Libraries/LibPDF/ObjectDerivatives.cpp index 9b1e0b834d..888e7d668b 100644 --- a/Userland/Libraries/LibPDF/ObjectDerivatives.cpp +++ b/Userland/Libraries/LibPDF/ObjectDerivatives.cpp @@ -50,6 +50,16 @@ DeprecatedString NameObject::to_deprecated_string(int) const return builder.to_deprecated_string(); } +Vector<float> ArrayObject::float_elements() const +{ + Vector<float> values; + values.ensure_capacity(m_elements.size()); + for (auto const& value : m_elements) { + values.append(value.to_float()); + } + return values; +} + DeprecatedString ArrayObject::to_deprecated_string(int indent) const { StringBuilder builder; diff --git a/Userland/Libraries/LibPDF/ObjectDerivatives.h b/Userland/Libraries/LibPDF/ObjectDerivatives.h index 7375d5f1d5..23cbd94b2b 100644 --- a/Userland/Libraries/LibPDF/ObjectDerivatives.h +++ b/Userland/Libraries/LibPDF/ObjectDerivatives.h @@ -74,6 +74,7 @@ public: [[nodiscard]] ALWAYS_INLINE size_t size() const { return m_elements.size(); } [[nodiscard]] ALWAYS_INLINE Vector<Value> elements() const { return m_elements; } + [[nodiscard]] Vector<float> float_elements() const; ALWAYS_INLINE auto begin() const { return m_elements.begin(); } ALWAYS_INLINE auto end() const { return m_elements.end(); } |