From 17676705a5f9db8e3ff93b204bc9a347c78e378f Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Fri, 25 Nov 2022 16:34:06 +0800 Subject: [PATCH] LibPDF: Add facility to obtain Vector 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. --- Userland/Libraries/LibPDF/ObjectDerivatives.cpp | 10 ++++++++++ Userland/Libraries/LibPDF/ObjectDerivatives.h | 1 + 2 files changed, 11 insertions(+) diff --git a/Userland/Libraries/LibPDF/ObjectDerivatives.cpp b/Userland/Libraries/LibPDF/ObjectDerivatives.cpp index 9b1e0b834dd..888e7d668bc 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 ArrayObject::float_elements() const +{ + Vector 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 7375d5f1d50..23cbd94b2ba 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 elements() const { return m_elements; } + [[nodiscard]] Vector float_elements() const; ALWAYS_INLINE auto begin() const { return m_elements.begin(); } ALWAYS_INLINE auto end() const { return m_elements.end(); }