diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-11-07 16:18:00 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-11-12 22:26:13 +0100 |
commit | fbf14b4e48c7677d5acf9a0ab91a3dc8d4ffc6fd (patch) | |
tree | 58456b840662e915478248f31fad7d2693eafd02 /include | |
parent | 5db34391ebf7a51d26196f3fe28f3d9327ea2eb6 (diff) |
pdf: add writeString for pdf elements for writing element content
This adds a writeString virtual method to PDFElement and
subclasses and implemnts them for each element. This is used to
write the PDF object hierarchy back to a string buffer.
Change-Id: I484c9cebd8ab9149029b925a47e68b6a4fdf9be1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105492
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/vcl/filter/pdfdocument.hxx | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/include/vcl/filter/pdfdocument.hxx b/include/vcl/filter/pdfdocument.hxx index 7e6d210255dd..4177e615516e 100644 --- a/include/vcl/filter/pdfdocument.hxx +++ b/include/vcl/filter/pdfdocument.hxx @@ -17,6 +17,7 @@ #include <tools/stream.hxx> #include <vcl/dllapi.h> +#include <rtl/strbuf.hxx> #include <vcl/filter/pdfobjectcontainer.hxx> @@ -59,6 +60,8 @@ public: bool alreadyVisiting() const { return m_bVisiting; } void setParsing(bool bParsing) { m_bParsing = bParsing; } bool alreadyParsing() const { return m_bParsing; } + + virtual void writeString(OStringBuffer& rBuffer) = 0; }; /// Indirect object: something with a unique ID. @@ -129,6 +132,8 @@ public: SvMemoryStream* GetStreamBuffer() const; void SetStreamBuffer(std::unique_ptr<SvMemoryStream>& pStreamBuffer); PDFDocument& GetDocument(); + + void writeString(OStringBuffer& /*rBuffer*/) override { assert(false && "not implemented"); } }; /// Array object: a list. @@ -143,6 +148,17 @@ public: bool Read(SvStream& rStream) override; void PushBack(PDFElement* pElement); const std::vector<PDFElement*>& GetElements() const; + + void writeString(OStringBuffer& rBuffer) override + { + rBuffer.append("[ "); + for (auto& rElement : m_aElements) + { + rElement->writeString(rBuffer); + rBuffer.append(" "); + } + rBuffer.append("]"); + } }; /// Reference object: something with a unique ID. @@ -168,6 +184,14 @@ public: int GetGenerationValue() const; sal_uInt64 GetOffset() const; PDFNumberElement& GetObjectElement() const; + + void writeString(OStringBuffer& rBuffer) override + { + rBuffer.append(sal_Int32(GetObjectValue())); + rBuffer.append(' '); + rBuffer.append(sal_Int32(GetGenerationValue())); + rBuffer.append(" R"); + } }; /// Stream object: a byte array with a known length. @@ -183,6 +207,13 @@ public: bool Read(SvStream& rStream) override; sal_uInt64 GetOffset() const; SvMemoryStream& GetMemory(); + + void writeString(OStringBuffer& rBuffer) override + { + rBuffer.append("stream\n"); + rBuffer.append(static_cast<const char*>(m_aMemory.GetData()), m_aMemory.GetSize()); + rBuffer.append("\nendstream\n"); + } }; /// Name object: a key string. @@ -198,6 +229,12 @@ public: const OString& GetValue() const; sal_uInt64 GetLocation() const; static sal_uInt64 GetLength() { return 0; } + + void writeString(OStringBuffer& rBuffer) override + { + rBuffer.append("/"); + rBuffer.append(m_aValue); + } }; /// Dictionary object: a set key-value pairs. @@ -229,6 +266,20 @@ public: PDFObjectElement* LookupObject(const OString& rDictionaryKey); /// Looks up an element which is contained in this dictionary. PDFElement* LookupElement(const OString& rDictionaryKey); + + void writeString(OStringBuffer& rBuffer) override + { + rBuffer.append("<< "); + for (auto& rPair : m_aItems) + { + rBuffer.append("/"); + rBuffer.append(rPair.first); + rBuffer.append(" "); + rPair.second->writeString(rBuffer); + rBuffer.append(" "); + } + rBuffer.append(">>"); + } }; enum class TokenizeMode @@ -292,6 +343,13 @@ class VCL_DLLPUBLIC PDFHexStringElement final : public PDFElement public: bool Read(SvStream& rStream) override; const OString& GetValue() const; + + void writeString(OStringBuffer& rBuffer) override + { + rBuffer.append("<"); + rBuffer.append(m_aValue); + rBuffer.append(">"); + } }; /// Literal string: in (asdf) form. @@ -302,6 +360,13 @@ class VCL_DLLPUBLIC PDFLiteralStringElement final : public PDFElement public: bool Read(SvStream& rStream) override; const OString& GetValue() const; + + void writeString(OStringBuffer& rBuffer) override + { + rBuffer.append("("); + rBuffer.append(m_aValue); + rBuffer.append(")"); + } }; /// Numbering object: an integer or a real. @@ -319,6 +384,8 @@ public: double GetValue() const; sal_uInt64 GetLocation() const; sal_uInt64 GetLength() const; + + void writeString(OStringBuffer& rBuffer) override { rBuffer.append(m_fValue); } }; /** |