From 7abf7e4194d30a716f24c6557e70891e29d0fee3 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Thu, 12 Nov 2020 22:24:02 +0100 Subject: pdf: Improve dict and array format when copying with PDFObjectCopier Change-Id: I4fcc4d912d4ce9d7800782b69811f877b85d9857 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105782 Tested-by: Jenkins CollaboraOffice Reviewed-by: Andras Timar --- vcl/source/gdi/pdfobjectcopier.cxx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/vcl/source/gdi/pdfobjectcopier.cxx b/vcl/source/gdi/pdfobjectcopier.cxx index 4e5575c25952..0d67fe735561 100644 --- a/vcl/source/gdi/pdfobjectcopier.cxx +++ b/vcl/source/gdi/pdfobjectcopier.cxx @@ -100,17 +100,21 @@ sal_Int32 PDFObjectCopier::copyExternalResource(SvMemoryStream& rDocBuffer, if (rObject.GetDictionary()) { aLine.append("<< "); - + bool bFirst = true; for (auto const& rPair : rObject.GetDictionaryItems()) { + if (bFirst) + bFirst = false; + else + aLine.append(" "); + aLine.append("/"); aLine.append(rPair.first); aLine.append(" "); copyRecursively(aLine, rPair.second, rDocBuffer, rCopiedResources); - aLine.append(" "); } - aLine.append(">>\n"); + aLine.append(" >>\n"); } if (filter::PDFStreamElement* pStream = rObject.GetStream()) @@ -127,10 +131,14 @@ sal_Int32 PDFObjectCopier::copyExternalResource(SvMemoryStream& rDocBuffer, const std::vector& rElements = pArray->GetElements(); + bool bFirst = true; for (auto const& pElement : rElements) { + if (bFirst) + bFirst = false; + else + aLine.append(" "); copyRecursively(aLine, pElement, rDocBuffer, rCopiedResources); - aLine.append(" "); } aLine.append("]\n"); } @@ -138,8 +146,7 @@ sal_Int32 PDFObjectCopier::copyExternalResource(SvMemoryStream& rDocBuffer, // If the object has a number element outside a dictionary or array, copy that. if (filter::PDFNumberElement* pNumber = rObject.GetNumberElement()) { - aLine.append(static_cast(pObjectStream->GetData()) + pNumber->GetLocation(), - pNumber->GetLength()); + pNumber->writeString(aLine); aLine.append("\n"); } -- cgit