[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - vcl/qa vcl/source

2023-03-07 Thread Jaume Pujantell (via logerrit)
 vcl/qa/cppunit/filter/ipdf/data/array-mixed-numbers-and-elements.pdf |   55 
++
 vcl/qa/cppunit/filter/ipdf/ipdf.cxx  |   25 

 vcl/source/filter/ipdf/pdfdocument.cxx   |   45 

 3 files changed, 125 insertions(+)

New commits:
commit da1d2ef7bb9de291941f1048b4012a730e159b2f
Author: Jaume Pujantell 
AuthorDate: Fri Mar 3 19:25:11 2023 +0100
Commit: Andras Timar 
CommitDate: Tue Mar 7 20:52:23 2023 +

Fix a bug parsing pdf arrays

The parser ignored number elements in some situations, like before
a reference element. This manifested in creating an invalid pdf
file when exporting as pdf a document that contains a pdf.

Change-Id: I98625c8da8631056079814f7e824f36177cf41c7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148198
Tested-by: Jenkins
Reviewed-by: Andras Timar 
(cherry picked from commit 574e89ccda1b389faca9f3e44d909a71b5599473)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148333
Tested-by: Andras Timar 

diff --git 
a/vcl/qa/cppunit/filter/ipdf/data/array-mixed-numbers-and-elements.pdf 
b/vcl/qa/cppunit/filter/ipdf/data/array-mixed-numbers-and-elements.pdf
new file mode 100644
index ..01030ecf88bc
--- /dev/null
+++ b/vcl/qa/cppunit/filter/ipdf/data/array-mixed-numbers-and-elements.pdf
@@ -0,0 +1,55 @@
+%PDF-1.7
+%���
+1 0 obj <<
+  /Type /Catalog
+  /Pages 2 0 R
+>>
+endobj
+2 0 obj <<
+  /Type /Pages
+  /MediaBox [0 0 200 300]
+  /Count 1
+  /Kids [3 0 R]
+>>
+endobj
+3 0 obj <<
+  /Type /Page
+  /Parent 2 0 R
+  /Contents 4 0 R
+  /Test [1 4 0 R 3 false 5 (Lieral) 7 <90>]
+>>
+endobj
+4 0 obj <<
+  /Length 188
+>>
+stream
+q
+0 0 0 rg
+0 290 10 10 re B*
+10 150 50 30 re B*
+0 0 1 rg
+190 290 10 10 re B*
+70 232 50 30 re B*
+0 1 0 rg
+190 0 10 10 re B*
+130 150 50 30 re B*
+1 0 0 rg
+0 0 10 10 re B*
+70 67 50 30 re B*
+Q
+endstream
+endobj
+xref
+0 5
+00 65535 f 
+15 0 n 
+68 0 n 
+000157 0 n 
+000270 0 n 
+trailer <<
+  /Root 1 0 R
+  /Size 5
+>>
+startxref
+510
+%%EOF
diff --git a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx 
b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
index 93cc22360b56..32bd15643259 100644
--- a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
+++ b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
@@ -197,6 +197,31 @@ CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, testCommentEnd)
 CPPUNIT_ASSERT(aDocument.Read(aFile));
 }
 
+CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, testMixedArrayWithNumbers)
+{
+// Load a file that has markup like this:
+// 3 0 obj <<
+//  /Test [1 4 0 R 3 false 5 (Lieral) 7 <90>]
+// >>
+OUString aSourceURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"array-mixed-numbers-and-elements.pdf";
+SvFileStream aFile(aSourceURL, StreamMode::READ);
+vcl::filter::PDFDocument aDocument;
+CPPUNIT_ASSERT(aDocument.Read(aFile));
+std::vector aPages = aDocument.GetPages();
+CPPUNIT_ASSERT(!aPages.empty());
+vcl::filter::PDFObjectElement* pPage = aPages[0];
+auto pTest = 
dynamic_cast(pPage->Lookup("Test"));
+std::vector aElements = pTest->GetElements();
+
+// Without the accompanying fix in place, this test would have failed with
+// the array containing the wrong number of elements and in the incorrect 
order
+CPPUNIT_ASSERT_EQUAL(8, static_cast(aElements.size()));
+CPPUNIT_ASSERT(dynamic_cast(aElements[0]));
+CPPUNIT_ASSERT(dynamic_cast(aElements[2]));
+CPPUNIT_ASSERT(dynamic_cast(aElements[4]));
+CPPUNIT_ASSERT(dynamic_cast(aElements[6]));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/filter/ipdf/pdfdocument.cxx 
b/vcl/source/filter/ipdf/pdfdocument.cxx
index 7569deede0f5..8bc66d0c010d 100644
--- a/vcl/source/filter/ipdf/pdfdocument.cxx
+++ b/vcl/source/filter/ipdf/pdfdocument.cxx
@@ -3221,6 +3221,18 @@ size_t PDFObjectParser::parse(PDFElement* 
pParsingElement, size_t nStartIndex, i
 }
 else if (auto pReference = 
dynamic_cast(pCurrentElement))
 {
+// Handle previously stored number
+if (aNumbers.size() > 2)
+{
+aNumbers.resize(aNumbers.size() - 2);
+if (pParsingArray)
+{
+for (auto& pNumber : aNumbers)
+pParsingArray->PushBack(pNumber);
+}
+aNumbers.clear();
+}
+
 if (pParsingArray)
 {
 pParsingArray->PushBack(pReference);
@@ -3241,6 +3253,17 @@ size_t PDFObjectParser::parse(PDFElement* 
pParsingElement, size_t nStartIndex, i
 }
 else if (auto pLiteralString = 
dynamic_cast(pCurrentElement))
 {
+// Handle previously stored number
+if (!aNumbers.empty())
+{
+if (pParsingArray)
+{
+for (auto& pNumber : aNumbers

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - vcl/qa vcl/source

2022-03-10 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/pdfexport/data/pdf-image-annots.odg |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |   30 +
 vcl/source/gdi/pdfwriter_impl.cxx  |   16 +--
 3 files changed, 44 insertions(+), 2 deletions(-)

New commits:
commit 6dc55f8af3649a536e2c3c075a0b4b230094a9f5
Author: Miklos Vajna 
AuthorDate: Wed Mar 9 13:36:27 2022 +0100
Commit: Tomaž Vajngerl 
CommitDate: Fri Mar 11 01:56:04 2022 +0100

PDF export of PDF images: don't preserve annotations in general

Regression from 33c9bc0225a92f26770f9ef20b252af47853e7b9 (PDF export of
PDF images: preserve hyperlinks, 2022-01-07), the problem was that we
want to preserve hyperlinks, but annotations are added by the PDF export
explicitly, so it isn't a good idea to "preserve" them as well.

Fix the problem by going back to the old behavior, except when the
annotation sub-type is /Link.

This keeps hyperlinks working but doesn't lead to duplicated comments
when re-exporting an image + adding comments explicitly.

Conflicts:
vcl/qa/cppunit/pdfexport/pdfexport.cxx

Change-Id: I910990da59bdc1150cc346f1a5471cb6da55dd2c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131261
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/pdfexport/data/pdf-image-annots.odg 
b/vcl/qa/cppunit/pdfexport/data/pdf-image-annots.odg
new file mode 100644
index ..6dee0145c536
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/pdf-image-annots.odg 
differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 8c1c81162ace..2206bd25d58a 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -2645,6 +2645,36 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, 
testPdfImageHyperlink)
 CPPUNIT_ASSERT_EQUAL(0.0012626264, rtl::math::round(aScale.getY(), 10));
 #endif
 }
+
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfImageAnnots)
+{
+// Given a document with a PDF image that has 2 comments (popup, text) and 
a hyperlink:
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"pdf-image-annots.odg";
+mxComponent = loadFromDesktop(aURL);
+CPPUNIT_ASSERT(mxComponent.is());
+
+// When saving to PDF:
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+utl::MediaDescriptor aMediaDescriptor;
+aMediaDescriptor["FilterName"] <<= OUString("draw_pdf_Export");
+xStorable->storeToURL(maTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
+
+// Then make sure only the hyperlink is kept, since Draw itself has its 
own comments:
+SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
+maMemory.WriteStream(aFile);
+std::shared_ptr pPDFium = vcl::pdf::PDFiumLibrary::get();
+std::unique_ptr pPdfDocument
+= pPDFium->openDocument(maMemory.GetData(), maMemory.GetSize());
+CPPUNIT_ASSERT(pPdfDocument);
+CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
+std::unique_ptr pPdfPage = 
pPdfDocument->openPage(/*nIndex=*/0);
+CPPUNIT_ASSERT(pPdfPage);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 1
+// - Actual  : 3
+// i.e. not only the hyperlink but also the 2 comments were exported, 
leading to duplication.
+CPPUNIT_ASSERT_EQUAL(1, pPdfPage->getAnnotationCount());
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 6aefaf2edabe..3e934a19825d 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -8511,7 +8511,7 @@ void 
PDFWriterImpl::writeReferenceXObject(ReferenceXObjectEmit& rEmit)
 return;
 }
 
-// Merge page annotations (links, etc) from pPage to our page.
+// Merge link annotations from pPage to our page.
 std::vector aAnnots;
 if (auto pArray = 
dynamic_cast(pPage->Lookup("Annots")))
 {
@@ -8529,7 +8529,19 @@ void 
PDFWriterImpl::writeReferenceXObject(ReferenceXObjectEmit& rEmit)
 continue;
 }
 
-// Annotation refers to an object, remember it.
+auto pType = 
dynamic_cast(pObject->Lookup("Type"));
+if (!pType || pType->GetValue() != "Annot")
+{
+continue;
+}
+
+auto pSubtype = 
dynamic_cast(pObject->Lookup("Subtype"));
+if (!pSubtype || pSubtype->GetValue() != "Link")
+{
+continue;
+}
+
+// Reference to a link annotation object, remember it.
 aAnnots.push_back(pObject);
 }
 }


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - vcl/qa vcl/source

2022-02-03 Thread Luboš Luňák (via logerrit)
 vcl/qa/cppunit/BitmapTest.cxx |   65 +
 vcl/source/bitmap/bitmappaint.cxx |  140 +-
 2 files changed, 173 insertions(+), 32 deletions(-)

New commits:
commit f2ea6902b4f901b24e3f551c95280123cff662ab
Author: Luboš Luňák 
AuthorDate: Fri Feb 19 13:21:52 2021 +0100
Commit: Andras Timar 
CommitDate: Thu Feb 3 21:33:05 2022 +0100

optimize Bitmap::Mirror()

For the usual bitmap pixel formats it's much faster to just move
around pixel data rather than call the pixel-set/get functions.

Change-Id: Ie99b3ea1431d965b110ec08d269e163d9f108cf3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111213
Tested-by: Jenkins
Reviewed-by: Luboš Luňák 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129411
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Andras Timar 

diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx
index 490a2d3ce8c7..f2c61e67b770 100644
--- a/vcl/qa/cppunit/BitmapTest.cxx
+++ b/vcl/qa/cppunit/BitmapTest.cxx
@@ -49,6 +49,7 @@ class BitmapTest : public CppUnit::TestFixture
 void testBitmap32();
 void testOctree();
 void testEmptyAccess();
+void testMirror();
 
 CPPUNIT_TEST_SUITE(BitmapTest);
 CPPUNIT_TEST(testCreation);
@@ -64,6 +65,7 @@ class BitmapTest : public CppUnit::TestFixture
 CPPUNIT_TEST(testBitmap32);
 CPPUNIT_TEST(testOctree);
 CPPUNIT_TEST(testEmptyAccess);
+CPPUNIT_TEST(testMirror);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -661,6 +663,69 @@ void BitmapTest::testEmptyAccess()
 CPPUNIT_ASSERT_EQUAL(tools::Long(0), access.Height());
 }
 
+void BitmapTest::testMirror()
+{
+for (int bpp : { 4, 8, 24, 32 })
+{
+Bitmap bitmap(Size(11, 11), bpp);
+{
+bitmap.Erase(COL_MAGENTA);
+BitmapWriteAccess write(bitmap);
+if (write.HasPalette())
+{
+// Note that SetPixel() and GetColor() take arguments as Y,X.
+write.SetPixel(0, 0, 
BitmapColor(write.GetBestPaletteIndex(COL_BLACK)));
+write.SetPixel(10, 0, 
BitmapColor(write.GetBestPaletteIndex(COL_WHITE)));
+write.SetPixel(0, 10, 
BitmapColor(write.GetBestPaletteIndex(COL_RED)));
+write.SetPixel(10, 10, 
BitmapColor(write.GetBestPaletteIndex(COL_BLUE)));
+write.SetPixel(5, 0, 
BitmapColor(write.GetBestPaletteIndex(COL_GREEN)));
+write.SetPixel(0, 5, 
BitmapColor(write.GetBestPaletteIndex(COL_YELLOW)));
+}
+else
+{
+write.SetPixel(0, 0, COL_BLACK);
+write.SetPixel(10, 0, COL_WHITE);
+write.SetPixel(0, 10, COL_RED);
+write.SetPixel(10, 10, COL_BLUE);
+write.SetPixel(5, 0, COL_GREEN);
+write.SetPixel(0, 5, COL_YELLOW);
+}
+}
+bitmap.Mirror(BmpMirrorFlags::Horizontal);
+{
+BitmapReadAccess read(bitmap);
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLACK), read.GetColor(0, 10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_WHITE), read.GetColor(10, 
10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_RED), read.GetColor(0, 0));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLUE), read.GetColor(10, 0));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_GREEN), read.GetColor(5, 10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_YELLOW), read.GetColor(0, 5));
+}
+bitmap.Mirror(BmpMirrorFlags::Vertical);
+{
+BitmapReadAccess read(bitmap);
+// Now is effectively mirrored in both directions.
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLACK), read.GetColor(10, 
10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_WHITE), read.GetColor(0, 10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_RED), read.GetColor(10, 0));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLUE), read.GetColor(0, 0));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_GREEN), read.GetColor(5, 10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_YELLOW), read.GetColor(10, 
5));
+}
+bitmap.Mirror(BmpMirrorFlags::Vertical | BmpMirrorFlags::Horizontal);
+{
+BitmapReadAccess read(bitmap);
+// Now is back the original.
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLACK), read.GetColor(0, 0));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_WHITE), read.GetColor(10, 0));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_RED), read.GetColor(0, 10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLUE), read.GetColor(10, 10));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_GREEN), read.GetColor(5, 0));
+CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_YELLOW), read.GetColor(0, 5));
+}
+}
+}
+
 } // namespace
 
 CPPUNIT_TEST_SUITE_REGISTRATION(BitmapTest);
diff --git a/vcl/source/bitmap/bitmappaint.cxx 
b/v

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - vcl/qa vcl/source

2022-01-10 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/pdfexport/data/pdf-image-hyperlink.odg |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx|   30 +++
 vcl/source/gdi/pdfwriter_impl.cxx |   35 ++
 3 files changed, 65 insertions(+)

New commits:
commit 58e6fce28f7d3e1c1504f048be5766dc732af4e7
Author: Miklos Vajna 
AuthorDate: Fri Jan 7 12:23:34 2022 +0100
Commit: Tomaž Vajngerl 
CommitDate: Mon Jan 10 14:10:14 2022 +0100

PDF export of PDF images: preserve hyperlinks

The input file has a single page, with a full-page PDF image, which
contains a hyperlink. Similar to pdfcrop, we used to wrap this into a
form XObject, so page-level annotations like hyperlinks were lost.

Explicitly merge page-level annotations from the source page to the page
that contains the PDF image to preserve those annotations.

(cherry picked from commit 1984a5c140cc3c7c291047dacf3bddd7061d2047)

Conflicts:
vcl/qa/cppunit/pdfexport/pdfexport.cxx

Change-Id: I96e8bc9d33440b91f3514486d6a8bd75047546b2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128127
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/pdfexport/data/pdf-image-hyperlink.odg 
b/vcl/qa/cppunit/pdfexport/data/pdf-image-hyperlink.odg
new file mode 100644
index ..aa0f89300b2c
Binary files /dev/null and 
b/vcl/qa/cppunit/pdfexport/data/pdf-image-hyperlink.odg differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 3a5b11784f27..ba1468af5253 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -2552,6 +2552,36 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, 
testPdfImageRotate180)
 // flip).
 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, aScale.getX(), 0.01);
 }
+
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfImageHyperlink)
+{
+// Given a Draw file, containing a PDF image, which has a hyperlink in it:
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"pdf-image-hyperlink.odg";
+mxComponent = loadFromDesktop(aURL);
+CPPUNIT_ASSERT(mxComponent.is());
+
+// When saving to PDF:
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+utl::MediaDescriptor aMediaDescriptor;
+aMediaDescriptor["FilterName"] <<= OUString("draw_pdf_Export");
+xStorable->storeToURL(maTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
+
+// Then make sure that link is preserved:
+SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
+maMemory.WriteStream(aFile);
+std::shared_ptr pPDFium = vcl::pdf::PDFiumLibrary::get();
+std::unique_ptr pPdfDocument
+= pPDFium->openDocument(maMemory.GetData(), maMemory.GetSize());
+CPPUNIT_ASSERT(pPdfDocument);
+CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
+std::unique_ptr pPdfPage = 
pPdfDocument->openPage(/*nIndex=*/0);
+CPPUNIT_ASSERT(pPdfPage);
+int nStartPos = 0;
+FPDF_LINK pLinkAnnot = nullptr;
+// Without the accompanying fix in place, this test would have failed, the 
hyperlink of the PDF
+// image was lost.
+CPPUNIT_ASSERT(FPDFLink_Enumerate(pPdfPage->getPointer(), &nStartPos, 
&pLinkAnnot));
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 811fdeb14ce3..63f466a962d1 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -8511,6 +8511,41 @@ void 
PDFWriterImpl::writeReferenceXObject(ReferenceXObjectEmit& rEmit)
 return;
 }
 
+// Merge page annotations (links, etc) from pPage to our page.
+std::vector aAnnots;
+if (auto pArray = 
dynamic_cast(pPage->Lookup("Annots")))
+{
+for (const auto pElement : pArray->GetElements())
+{
+auto pReference = 
dynamic_cast(pElement);
+if (!pReference)
+{
+continue;
+}
+
+filter::PDFObjectElement* pObject = pReference->LookupObject();
+if (!pObject)
+{
+continue;
+}
+
+// Annotation refers to an object, remember it.
+aAnnots.push_back(pObject);
+}
+}
+if (!aAnnots.empty())
+{
+PDFObjectCopier aCopier(*this);
+SvMemoryStream& rDocBuffer = pPage->GetDocument().GetEditBuffer();
+std::map aMap;
+for (const auto& pAnnot : aAnnots)
+{
+// Copy over the annotation and refer to its new id.
+sal_Int32 nNewId = aCopier.copyExternalResource(rDocBuffer, 
*pAnnot, aMap);
+m_aPages.back().m_aAnnotations.push_back(nNewId);
+}
+}
+
 nWrappedFormObject = createObject();
 // Write the form X

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - vcl/qa vcl/source

2021-05-19 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/pdfexport/data/pdf-image-rotate-180.pdf |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |   67 +
 vcl/source/gdi/pdfwriter_impl.cxx  |   53 -
 3 files changed, 99 insertions(+), 21 deletions(-)

New commits:
commit 6c2d69c30303d2acac1e26fe8360b158c3b3f4cc
Author: Miklos Vajna 
AuthorDate: Mon May 17 13:51:31 2021 +0200
Commit: Miklos Vajna 
CommitDate: Wed May 19 09:16:43 2021 +0200

vcl PDF export: fix re-exporting PDF images with arbitrary page-level 
rotation

Building on top of commit bd520b177637d4b7d9d93733103cff17a3c91b0a (vcl
PDF export: fix re-exporting PDF images with page-level rotation,
2019-11-06), this was already working for 90 degrees, now generalize
this to work with 180 degrees as well.

(cherry picked from commit d7d43cf460d66354a40ffa3b34c0f9efcd42d0be)

Conflicts:
vcl/qa/cppunit/pdfexport/pdfexport.cxx

Change-Id: I5a5d51662399814d5554d7c2cb86a6c9a2974012
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115707
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/vcl/qa/cppunit/pdfexport/data/pdf-image-rotate-180.pdf 
b/vcl/qa/cppunit/pdfexport/data/pdf-image-rotate-180.pdf
new file mode 100644
index ..981ca32061cd
Binary files /dev/null and 
b/vcl/qa/cppunit/pdfexport/data/pdf-image-rotate-180.pdf differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 92d5bcb22bd0..3a5b11784f27 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -2485,6 +2485,73 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testReexportPDF)
 
 #endif
 }
+
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfImageRotate180)
+{
+// Create an empty document.
+mxComponent = loadFromDesktop("private:factory/swriter");
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xText = xTextDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+
+// Insert the PDF image.
+uno::Reference xFactory(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xGraphicObject(
+xFactory->createInstance("com.sun.star.text.TextGraphicObject"), 
uno::UNO_QUERY);
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"pdf-image-rotate-180.pdf";
+xGraphicObject->setPropertyValue("GraphicURL", uno::makeAny(aURL));
+uno::Reference xShape(xGraphicObject, uno::UNO_QUERY);
+xShape->setSize(awt::Size(1000, 1000));
+uno::Reference xTextContent(xGraphicObject, 
uno::UNO_QUERY);
+xText->insertTextContent(xCursor->getStart(), xTextContent, 
/*bAbsorb=*/false);
+
+// Save as PDF.
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+utl::MediaDescriptor aMediaDescriptor;
+aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+xStorable->storeToURL(maTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
+
+// Parse the export result.
+SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
+maMemory.WriteStream(aFile);
+std::shared_ptr pPDFium = vcl::pdf::PDFiumLibrary::get();
+std::unique_ptr pPdfDocument
+= pPDFium->openDocument(maMemory.GetData(), maMemory.GetSize());
+CPPUNIT_ASSERT(pPdfDocument);
+CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
+
+// Make sure that the page -> form -> form has a child image.
+std::unique_ptr pPdfPage = 
pPdfDocument->openPage(/*nIndex=*/0);
+CPPUNIT_ASSERT(pPdfPage);
+CPPUNIT_ASSERT_EQUAL(1, pPdfPage->getObjectCount());
+std::unique_ptr pPageObject = 
pPdfPage->getObject(0);
+CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Form, 
pPageObject->getType());
+// 2: white background and the actual object.
+CPPUNIT_ASSERT_EQUAL(2, pPageObject->getFormObjectCount());
+std::unique_ptr pFormObject = 
pPageObject->getFormObject(1);
+CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Form, 
pFormObject->getType());
+CPPUNIT_ASSERT_EQUAL(1, pFormObject->getFormObjectCount());
+
+// Check if the inner form object (original page object in the pdf image) 
has the correct
+// rotation.
+std::unique_ptr pInnerFormObject = 
pFormObject->getFormObject(0);
+CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Form, 
pInnerFormObject->getType());
+CPPUNIT_ASSERT_EQUAL(1, pInnerFormObject->getFormObjectCount());
+std::unique_ptr pImage = 
pInnerFormObject->getFormObject(0);
+CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFPageObjectType::Image, 
pImage->getType());
+basegfx::B2DHomMatrix aMat = pInnerFormObject->getMatrix();
+basegfx::B2DTuple aScale;
+basegfx::B2DTuple aTranslate;
+double fRotate = 0;
+double fShearX = 0;
+aMat.decompose(aScale, aTranslate, fRotate, fShearX);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: -1
+/

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - vcl/qa vcl/source

2021-05-13 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/filter/ipdf/data/comment-end.pdf |   69 
 vcl/qa/cppunit/filter/ipdf/ipdf.cxx |   19 ++
 vcl/source/filter/ipdf/pdfdocument.cxx  |7 ++
 3 files changed, 94 insertions(+), 1 deletion(-)

New commits:
commit 65cc6016ca56ec812cc29a892960dbb7af9e387f
Author: Miklos Vajna 
AuthorDate: Wed May 12 10:51:09 2021 +0200
Commit: Tomaž Vajngerl 
CommitDate: Fri May 14 05:53:05 2021 +0200

vcl PDF tokenizer: fix EOF position when \r is not followed by \n

Otherwise this would break partial tokenize when we only read a trailer
in the middle of the file: m_aEOFs.back() is one byte larger than
rStream.Tell(), so we reader past the end of the trailer, resulting in a
tokenize failure.

What's special about the bugdoc:

- it has 2 xrefs, the first is incomplete, and refers to a second which
is later in the file
- the object length is as indirect object, triggering an xref lookup
- the first EOF is followed by a \r, but then not with a \n

This results in reading past the end of the first trailer and then
triggering a lookup failure.

FWIW, pdfium does the same in

,
we're on in sync with it.

(cherry picked from commit 6b1d5bafdc722d07d3dc4980764275a6caa707ba)

Change-Id: Ia556a25e333b5e4f1418d92a98d74358862120e2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115485
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/filter/ipdf/data/comment-end.pdf 
b/vcl/qa/cppunit/filter/ipdf/data/comment-end.pdf
new file mode 100644
index ..6f1ad86f5c99
--- /dev/null
+++ b/vcl/qa/cppunit/filter/ipdf/data/comment-end.pdf
@@ -0,0 +1,69 @@
+%PDF-1.7
+%���
+1 0 obj <<
+  /Type /Catalog
+  /Pages 2 0 R
+>>
+endobj
+2 0 obj <<
+  /Type /Pages
+  /MediaBox [0 0 200 300]
+  /Count 1
+  /Kids [3 0 R]
+>>
+endobj
+3 0 obj <<
+  /Type /Page
+  /Parent 2 0 R
+  /Contents 4 0 R
+>>
+endobj
+4 0 obj <<
+  /Length 4
+>>
+stream
+q
+Q
+endstream
+endobj
+xref
+0 5
+00 65535 f 
+15 0 n 
+68 0 n 
+000157 0 n 
+000226 0 n 
+trailer <<
+  /Root 1 0 R
+  /Size 5
+  /Prev 541
+>>
+startxref
+280
+%%EOF
%%TEST
+4 0 obj <<
+  /Length 5 0 R
+>>
+stream
+q
+Q
+endstream
+endobj
+5 0 obj
+4
+endobj
+xref
+0 6
+00 65535 f 
+15 0 n 
+68 0 n 
+000157 0 n 
+000466 0 n 
+000524 0 n 
+trailer <<
+  /Root 1 0 R
+  /Size 6
+>>
+startxref
+280
+%%EOF
diff --git a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx 
b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
index d94eb76aa5b3..93cc22360b56 100644
--- a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
+++ b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
@@ -178,6 +178,25 @@ CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, testRealNumbers)
 CPPUNIT_ASSERT(!aPages.empty());
 }
 
+CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, testCommentEnd)
+{
+// Load the test document:
+// - it has two xrefs
+// - second xref has an updated page content object with an indirect length
+// - last startxref refers to the first xref
+// - first xref has a /Prev to the second xref
+// - first xref is terminated by a \r, which is not followed by a newline
+// this means that if reading doesn't stop at the end of the first xref, 
then we'll try to look
+// up the offset of the length object, which we don't yet have
+OUString aSourceURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"comment-end.pdf";
+SvFileStream aFile(aSourceURL, StreamMode::READ);
+vcl::filter::PDFDocument aDocument;
+
+// Without the accompanying fix in place, this test would have failed, 
because Tokenize() didn't
+// stop at the end of the first xref.
+CPPUNIT_ASSERT(aDocument.Read(aFile));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/filter/ipdf/pdfdocument.cxx 
b/vcl/source/filter/ipdf/pdfdocument.cxx
index 9c677e85e0f5..8a3ee8924d04 100644
--- a/vcl/source/filter/ipdf/pdfdocument.cxx
+++ b/vcl/source/filter/ipdf/pdfdocument.cxx
@@ -2077,9 +2077,14 @@ bool PDFCommentElement::Read(SvStream& rStream)
 sal_uInt64 nPos = rStream.Tell();
 if (ch == '\r')
 {
+rStream.ReadChar(ch);
+rStream.SeekRel(-1);
 // If the comment ends with a \r\n, count the \n as well 
to match Adobe Acrobat
 // behavior.
-nPos += 1;
+if (ch == '\n')
+{
+nPos += 1;
+}
 }
 m_rDoc.PushBackEOF(nPos);
 }
___
Libreoffice-commits mailing list
libreoffice-comm

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - vcl/qa vcl/source

2021-04-09 Thread Tomaž Vajngerl (via logerrit)
 vcl/qa/cppunit/GraphicTest.cxx |   10 ++
 vcl/source/gdi/impgraph.cxx|7 +++
 vcl/source/graphic/Manager.cxx |9 +
 3 files changed, 22 insertions(+), 4 deletions(-)

New commits:
commit cb0f00e14c76a820e796732275cd3863c393b21e
Author: Tomaž Vajngerl 
AuthorDate: Thu Nov 26 12:38:47 2020 +0900
Commit: Andras Timar 
CommitDate: Fri Apr 9 12:57:13 2021 +0200

pdf: workaround to disable swapping of PDF graphic files

This is needed so that swapping doesn't create excesive amount
of swap files, where each includes the original PDF file, which
would take a lot of temp disk space. This happens because each
graphic object swaps out the original PDF and we create one
graphic object per page.

In a problematic PDF this means it took 20MB (PDF file) * 700
(pages) ~ 14 GB ob disk space.

Change-Id: Id5f720946ce6b3f5aca92bc6d1af388fe8dbcc64
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106651
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Andras Timar 

diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index 50ff4a133f86..e6c114bf28f3 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -455,12 +455,14 @@ void GraphicTest::testSwappingPageNumber()
 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
 
 // Swapping out
-CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
-CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
-CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+// Following checks were commented out because of the PDF swap issues
+// with PDF graphic where a lot of swap files were created.
+//CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
+//CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
+//CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
 
 // Let's swap in
-CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+//CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 1d3e25418b5f..6b232d672c40 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1370,6 +1370,13 @@ bool ImpGraphic::swapOutContent(SvStream& rOStm)
 
 bool ImpGraphic::swapOut()
 {
+// Hack / Workaround - ignore swap out PDF files
+if (maVectorGraphicData &&
+maVectorGraphicData->getVectorGraphicDataType() == 
VectorGraphicDataType::Pdf)
+{
+return false;
+}
+
 if (isSwappedOut())
 return false;
 
diff --git a/vcl/source/graphic/Manager.cxx b/vcl/source/graphic/Manager.cxx
index 88e1f6e622df..6bbe3b5e7c7d 100644
--- a/vcl/source/graphic/Manager.cxx
+++ b/vcl/source/graphic/Manager.cxx
@@ -112,6 +112,15 @@ sal_Int64 Manager::getGraphicSizeBytes(const ImpGraphic* 
pImpGraphic)
 {
 if (!pImpGraphic->isAvailable())
 return 0;
+
+// Hack / Workaround - don't count PDF vector graphic to preven swapping
+if (pImpGraphic->getVectorGraphicData()
+&& pImpGraphic->getVectorGraphicData()->getVectorGraphicDataType()
+   == VectorGraphicDataType::Pdf)
+{
+return 0;
+}
+
 return pImpGraphic->ImplGetSizeBytes();
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits