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

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

New commits:
commit 4ccafbc96b9cf30963060acd443cfc9435b7d5e8
Author: Miklos Vajna 
AuthorDate: Wed Mar 9 13:36:27 2022 +0100
Commit: Andras Timar 
CommitDate: Wed Mar 9 16:58:20 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/+/131262
Tested-by: Aron Budea 
Reviewed-by: Andras Timar 

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 ea67d5530539..fc7103fede47 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -149,6 +149,7 @@ public:
 void testMultiPagePDF();
 void testPdfImageRotate180();
 void testPdfImageHyperlink();
+void testPdfImageAnnots();
 
 
 CPPUNIT_TEST_SUITE(PdfExportTest);
@@ -194,6 +195,7 @@ public:
 CPPUNIT_TEST(testMultiPagePDF);
 CPPUNIT_TEST(testPdfImageRotate180);
 CPPUNIT_TEST(testPdfImageHyperlink);
+CPPUNIT_TEST(testPdfImageAnnots);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -2332,6 +2334,35 @@ void PdfExportTest::testPdfImageHyperlink()
 #endif
 }
 
+void 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_TEST_SUITE_REGISTRATION(PdfExportTest);
 
 }
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 896a910eae51..1d10f377c0d0 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -8738,7 +8738,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")))
 {
@@ -8756,7 +8756,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")
+{
+   

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

2022-02-07 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |   48 +
 vcl/source/gdi/pdfwriter_impl.cxx  |4 +-
 2 files changed, 50 insertions(+), 2 deletions(-)

New commits:
commit ad0d65badf2d496e342d6f6da7b169bb507c203b
Author: Miklos Vajna 
AuthorDate: Fri Feb 4 10:55:28 2022 +0100
Commit: Miklos Vajna 
CommitDate: Mon Feb 7 16:04:34 2022 +0100

PDF export: improve precision of pdf image sizes

This helps exporting full-page PDF images from Draw more accurately. In
case the page size was A4, then the page height is 841.8897637795276
i.e. 842 points. Full-page PDF images are scaled to this size, so the
referred PDF form XObject has the reciprocal of that scaling.  We used
to just write 0.00118, doubling the precision leads to
0.0011878840.

In practice the old precision resulted in e.g. hyperlink rectangles to
get out of sync with link text after 2 roundtrips, while the new
precision doesn't result in any noticeable modification to the link text
position after a roundtrip.

(cherry picked from commit 50682cea4196819980c8e2d4018f80384097ce6f)

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

Change-Id: I72cc68696b9b9bcc1cbfde8df331c2b9c5f9eb29
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129498
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Tomaž Vajngerl 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129592
Reviewed-by: Miklos Vajna 

diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 94248572c887..ea67d5530539 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -38,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -2282,6 +2283,53 @@ void PdfExportTest::testPdfImageHyperlink()
 // 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(), , 
));
+
+// Also test the precision of the form XObject.
+// Given a full-page form XObject, page height is 27.94 cm (792 points):
+// When writing the reciprocal of the object height to PDF:
+std::unique_ptr pFormObject;
+for (int i = 0; i < pPdfPage->getObjectCount(); ++i)
+{
+std::unique_ptr pObject = 
pPdfPage->getObject(i);
+if (FPDFPageObj_GetType(pObject->getPointer()) == FPDF_PAGEOBJ_FORM)
+{
+pFormObject = std::move(pObject);
+break;
+}
+}
+CPPUNIT_ASSERT(pFormObject);
+std::unique_ptr pInnerFormObject;
+for (int i = 0; i < pFormObject->getFormObjectCount(); ++i)
+{
+std::unique_ptr pObject = 
pFormObject->getFormObject(i);
+if (FPDFPageObj_GetType(pObject->getPointer()) == FPDF_PAGEOBJ_FORM)
+{
+pInnerFormObject = std::move(pObject);
+break;
+}
+}
+CPPUNIT_ASSERT(pInnerFormObject);
+// Then make sure that enough digits are used, so the point size is 
unchanged:
+basegfx::B2DHomMatrix aMatrix;
+FS_MATRIX matrix;
+if (FPDFFormObj_GetMatrix(pInnerFormObject->getPointer(), ))
+{
+aMatrix = basegfx::B2DHomMatrix::abcdef(matrix.a, matrix.b, matrix.c, 
matrix.d, matrix.e,
+matrix.f);
+}
+basegfx::B2DTuple aScale;
+basegfx::B2DTuple aTranslate;
+double fRotate{};
+double fShearX{};
+aMatrix.decompose(aScale, aTranslate, fRotate, fShearX);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 0.0012626264
+// - Actual  : 0.00126
+// i.e. the rounded reciprocal was 794 points, not the original 792.
+// FIXME macOS actual value is 0.0001578282, for unknown reasons.
+#if !defined MACOSX
+CPPUNIT_ASSERT_EQUAL(0.0012626264, rtl::math::round(aScale.getY(), 10));
+#endif
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest);
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index b78ae731e8bd..896a910eae51 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -8870,9 +8870,9 @@ void 
PDFWriterImpl::writeReferenceXObject(ReferenceXObjectEmit& rEmit)
 
 aLine.append(">> >>");
 aLine.append(" /Matrix [ ");
-appendDouble(fScaleX, aLine);
+appendDouble(fScaleX, aLine, /*nPrecision=*/10);
 aLine.append(" 0 0 ");
-appendDouble(fScaleY, aLine);
+appendDouble(fScaleY, aLine, /*nPrecision=*/10);
 aLine.append(" 0 0 ]");
 aLine.append(" /BBox [ 0 0 ");
 aLine.append(aSize.Width());


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

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

New commits:
commit 33c9bc0225a92f26770f9ef20b252af47853e7b9
Author: Miklos Vajna 
AuthorDate: Fri Jan 7 12:23:34 2022 +0100
Commit: Miklos Vajna 
CommitDate: Tue Jan 11 10:10:26 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

Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128127
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Tomaž Vajngerl 
(cherry picked from commit 58e6fce28f7d3e1c1504f048be5766dc732af4e7)

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

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 aa96ee8a0f99..94248572c887 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -147,6 +147,7 @@ public:
 void testDefaultVersion();
 void testMultiPagePDF();
 void testPdfImageRotate180();
+void testPdfImageHyperlink();
 
 
 CPPUNIT_TEST_SUITE(PdfExportTest);
@@ -191,6 +192,7 @@ public:
 CPPUNIT_TEST(testDefaultVersion);
 CPPUNIT_TEST(testMultiPagePDF);
 CPPUNIT_TEST(testPdfImageRotate180);
+CPPUNIT_TEST(testPdfImageHyperlink);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -2252,6 +2254,36 @@ void PdfExportTest::testPdfImageRotate180()
 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, aScale.getX(), 0.01);
 }
 
+void 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(), , 
));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest);
 
 }
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 8b435678f93d..b78ae731e8bd 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -8738,6 +8738,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);
+}
+ 

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

2022-01-05 Thread Andras Timar (via logerrit)
 vcl/source/gdi/dibtools.cxx |5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

New commits:
commit 4aedf0956fb6849781bfb5139b04d8ca0708acdc
Author: Andras Timar 
AuthorDate: Mon Jan 3 22:12:01 2022 +0100
Commit: Andras Timar 
CommitDate: Wed Jan 5 13:56:48 2022 +0100

tdf#73523 do not seek backwards, the color mask info is not there

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

diff --git a/vcl/qa/cppunit/graphicfilter/data/bmp/fail/crash-1.bmp 
b/vcl/qa/cppunit/graphicfilter/data/bmp/pass/crash-1.bmp
similarity index 100%
rename from vcl/qa/cppunit/graphicfilter/data/bmp/fail/crash-1.bmp
rename to vcl/qa/cppunit/graphicfilter/data/bmp/pass/crash-1.bmp
diff --git a/vcl/source/gdi/dibtools.cxx b/vcl/source/gdi/dibtools.cxx
index ce1df4a68a65..949423a1f255 100644
--- a/vcl/source/gdi/dibtools.cxx
+++ b/vcl/source/gdi/dibtools.cxx
@@ -533,10 +533,9 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& 
rHeader, BitmapWriteAccess& r
 }
 else
 {
-// Read color mask
-if(bTCMask && BITFIELDS == rHeader.nCompression)
+// Read color mask. An additional 12 bytes of color bitfields follow 
the info header (WinBMPv3-NT)
+if(bTCMask && BITFIELDS == rHeader.nCompression && DIBINFOHEADERSIZE 
== rHeader.nSize)
 {
-rIStm.SeekRel( -12 );
 rIStm.ReadUInt32( nRMask );
 rIStm.ReadUInt32( nGMask );
 rIStm.ReadUInt32( nBMask );


[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - 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 |   72 +
 vcl/source/gdi/pdfwriter_impl.cxx  |   53 +++-
 3 files changed, 104 insertions(+), 21 deletions(-)

New commits:
commit 52add3bae28b1e7cda0234110341f3c6e0b06fdc
Author: Miklos Vajna 
AuthorDate: Mon May 17 13:51:31 2021 +0200
Commit: Miklos Vajna 
CommitDate: Wed May 19 09:16:57 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
vcl/source/gdi/pdfwriter_impl.cxx

Change-Id: I5a5d51662399814d5554d7c2cb86a6c9a2974012
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115712
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Ashod Nakashian 

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 5f50661b013e..aa96ee8a0f99 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -146,6 +146,7 @@ public:
 void testVersion15();
 void testDefaultVersion();
 void testMultiPagePDF();
+void testPdfImageRotate180();
 
 
 CPPUNIT_TEST_SUITE(PdfExportTest);
@@ -189,6 +190,7 @@ public:
 CPPUNIT_TEST(testVersion15);
 CPPUNIT_TEST(testDefaultVersion);
 CPPUNIT_TEST(testMultiPagePDF);
+CPPUNIT_TEST(testPdfImageRotate180);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -2180,6 +2182,76 @@ void PdfExportTest::testMultiPagePDF()
 #endif
 }
 
+void PdfExportTest::testPdfImageRotate180()
+{
+// Create an empty document.
+uno::Reference xComponent = 
loadFromDesktop("private:factory/swriter");
+uno::Reference xTextDocument(xComponent, 
uno::UNO_QUERY);
+uno::Reference xText = xTextDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+
+// Insert the PDF image.
+uno::Reference xFactory(xComponent, 
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(xComponent, uno::UNO_QUERY);
+utl::MediaDescriptor aMediaDescriptor;
+aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+utl::TempFile aTempFile;
+aTempFile.EnableKillingFile();
+xStorable->storeToURL(aTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
+xComponent->dispose();
+
+// Parse the export result.
+SvFileStream aFile(aTempFile.GetURL(), StreamMode::READ);
+SvMemoryStream aMemory;
+aMemory.WriteStream(aFile);
+DocumentHolder pPdfDocument(FPDF_LoadMemDocument(aMemory.GetData(), 
aMemory.GetSize(), /*password=*/nullptr));
+CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(pPdfDocument.get()));
+
+// Make sure that the page -> form -> form has a child image.
+PageHolder pPdfPage(FPDF_LoadPage(pPdfDocument.get(), /*page_index=*/0));
+CPPUNIT_ASSERT(pPdfPage.get());
+CPPUNIT_ASSERT_EQUAL(1, FPDFPage_CountObjects(pPdfPage.get()));
+FPDF_PAGEOBJECT pPageObject = FPDFPage_GetObject(pPdfPage.get(), 0);
+CPPUNIT_ASSERT_EQUAL(FPDF_PAGEOBJ_FORM, FPDFPageObj_GetType(pPageObject));
+// 2: white background and the actual object.
+CPPUNIT_ASSERT_EQUAL(2, FPDFFormObj_CountObjects(pPageObject));
+FPDF_PAGEOBJECT pFormObject = FPDFFormObj_GetObject(pPageObject, 1);
+CPPUNIT_ASSERT_EQUAL(FPDF_PAGEOBJ_FORM, FPDFPageObj_GetType(pFormObject));
+CPPUNIT_ASSERT_EQUAL(1, FPDFFormObj_CountObjects(pFormObject));
+
+// Check if the inner form object (original page object in the pdf image) 
has the correct
+// rotation.
+FPDF_PAGEOBJECT pInnerFormObject = FPDFFormObj_GetObject(pFormObject, 0);
+CPPUNIT_ASSERT_EQUAL(FPDF_PAGEOBJ_FORM, 
FPDFPageObj_GetType(pInnerFormObject));
+CPPUNIT_ASSERT_EQUAL(1, 

[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - 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 1e0ee8141207a425b56592c136ac5e94fc821173
Author: Miklos Vajna 
AuthorDate: Wed May 12 10:51:09 2021 +0200
Commit: Tomaž Vajngerl 
CommitDate: Fri May 14 05:53:16 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)

Conflicts:
vcl/qa/cppunit/filter/ipdf/ipdf.cxx

Change-Id: Ia556a25e333b5e4f1418d92a98d74358862120e2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115537
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 5055e36a922e..3307db5c9743 100644
--- a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
+++ b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
@@ -168,6 +168,25 @@ CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, testDictArrayDict)
 CPPUNIT_ASSERT(pKey);
 }
 
+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 64cf9dc4ef90..8715000f1627 100644
--- a/vcl/source/filter/ipdf/pdfdocument.cxx
+++ b/vcl/source/filter/ipdf/pdfdocument.cxx
@@ -2145,9 +2145,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] core.git: Branch 'distro/collabora/cp-6.4' - vcl/qa vcl/source

2021-05-06 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/PDFiumLibraryTest.cxx |   39 ++
 vcl/qa/cppunit/data/form-fields.pdf  |   95 +++
 vcl/source/filter/ipdf/pdfread.cxx   |   11 
 3 files changed, 145 insertions(+)

New commits:
commit d1aea7e642471393732c57bf29dcf67690099d76
Author: Miklos Vajna 
AuthorDate: Wed May 5 11:18:30 2021 +0200
Commit: Tomaž Vajngerl 
CommitDate: Fri May 7 06:40:47 2021 +0200

vcl pdfium render: handle widget annotations for form fields

Note that we render the bitmaps without FPDF_ANNOT, so comments are not
rendered into the bitmaps, rather we create them on top of the bitmaps
in Draw, explicitly.

FPDF_FFLDraw() draws content which is already an annotation, but not yet
interactive content; so this just fixes "missing text", as far as the
user is concerned.

Verified that e.g. vcl/qa/cppunit/data/PangramAcrobatAnnotations.pdf
indeed still doesn't render comments into bitmaps after this.

(cherry picked from commit 92cba30d5ce45e4f4a9516a80c9fe9915add6905)

Conflicts:
include/vcl/filter/PDFiumLibrary.hxx
vcl/qa/cppunit/PDFiumLibraryTest.cxx
vcl/source/filter/ipdf/pdfread.cxx
vcl/source/pdf/PDFiumLibrary.cxx

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

diff --git a/vcl/qa/cppunit/PDFiumLibraryTest.cxx 
b/vcl/qa/cppunit/PDFiumLibraryTest.cxx
index f18681c0adda..54f5e70e00d3 100644
--- a/vcl/qa/cppunit/PDFiumLibraryTest.cxx
+++ b/vcl/qa/cppunit/PDFiumLibraryTest.cxx
@@ -25,6 +25,8 @@
 #include 
 
 #include 
+#include 
+#include 
 
 class PDFiumLibraryTest : public test::BootstrapFixtureBase
 {
@@ -39,6 +41,7 @@ class PDFiumLibraryTest : public test::BootstrapFixtureBase
 void testAnnotationsMadeInEvince();
 void testAnnotationsMadeInAcrobat();
 void testTools();
+void testFormFields();
 
 CPPUNIT_TEST_SUITE(PDFiumLibraryTest);
 CPPUNIT_TEST(testDocument);
@@ -47,6 +50,7 @@ class PDFiumLibraryTest : public test::BootstrapFixtureBase
 CPPUNIT_TEST(testAnnotationsMadeInEvince);
 CPPUNIT_TEST(testAnnotationsMadeInAcrobat);
 CPPUNIT_TEST(testTools);
+CPPUNIT_TEST(testFormFields);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -287,6 +291,41 @@ void PDFiumLibraryTest::testAnnotationsMadeInAcrobat()
 }
 }
 
+void PDFiumLibraryTest::testFormFields()
+{
+// Given a document with a form field that looks like plain text:
+OUString aURL = getFullUrl(u"form-fields.pdf");
+SvFileStream aFileStream(aURL, StreamMode::READ);
+SvMemoryStream aMemory;
+aMemory.WriteStream(aFileStream);
+aMemory.Seek(0);
+
+// When rendering its first (and only) page to a bitmap:
+std::vector aBitmaps;
+int nRet = vcl::RenderPDFBitmaps(aMemory.GetData(), aMemory.GetSize(), 
aBitmaps);
+CPPUNIT_ASSERT(nRet);
+CPPUNIT_ASSERT_EQUAL(static_cast(1), aBitmaps.size());
+
+// Then make sure the bitmap contains that text:
+Bitmap aBitmap = aBitmaps[0];
+BitmapReadAccess aAccess(aBitmap);
+Size aSize = aBitmap.GetSizePixel();
+std::set aColors;
+for (long y = 0; y < aSize.Height(); ++y)
+{
+for (long x = 0; x < aSize.Width(); ++x)
+{
+aColors.insert(static_cast(aAccess.GetPixel(y, x)));
+}
+}
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected greater than: 1
+// - Actual  : 1
+// i.e. at least black text and white background is expected (possibly 
more, due to
+// anti-aliasing), but nothing was rendered.
+CPPUNIT_ASSERT_GREATER(static_cast(1), aColors.size());
+}
+
 void PDFiumLibraryTest::testTools()
 {
 OUString sConverted = 
vcl::pdf::convertPdfDateToISO8601("D:20200612201322+02'00");
diff --git a/vcl/qa/cppunit/data/form-fields.pdf 
b/vcl/qa/cppunit/data/form-fields.pdf
new file mode 100644
index ..a014b36c9821
--- /dev/null
+++ b/vcl/qa/cppunit/data/form-fields.pdf
@@ -0,0 +1,95 @@
+%PDF-1.7
+%���
+1 0 obj <<
+  /Type /Catalog
+  /Pages 5 0 R
+>>
+endobj
+
+2 0 obj <<
+  /Length 0
+>>
+stream
+endstream 
+endobj
+
+3 0 obj <<
+  /Font <<
+/TT1 4 0 R
+  >>
+>>
+endobj
+
+4 0 obj <<
+ /Type /Font
+ /Subtype /Type1
+ /Name /TT1
+ /BaseFont/Helvetica
+>>
+endobj
+
+5 0 obj <<
+  /Type /Pages
+  /Kids [6 0 R]
+  /Count 1
+  /MediaBox [ 0 0 612 446 ]
+>>
+endobj
+
+6 0 obj <<
+  /Type /Page
+  /Parent 5 0 R
+  /Resources 3 0 R
+  /Contents 2 0 R
+  /Annots [7 0 R]
+>>
+endobj
+
+7 0 obj <<
+  /Type /Annot
+  /Subtype /Widget
+  /T (T)
+  /V (V)
+  /DA (/Helv 0 Tf 0 g)
+  /Rect [ 0 0 612 446 ]
+  /FT /Tx
+  /AP <<
+/N 8 0 R
+  >>
+>>
+endobj
+
+8 0 obj <<
+  /Type /XObject
+  /Subtype /Form
+  /Matrix [1.0 0.0 0.0 1.0 0.0 0.0]
+  /Resources 3 0 R
+  /BBox [ 0 0 612 446 ]
+  /Length 55
+>>
+stream
+  BT
+  /TT1 24 

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

2020-11-26 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 e2dfc4e3d1c5913c8686f2c80f78514b0eb37a03
Author: Tomaž Vajngerl 
AuthorDate: Thu Nov 26 12:38:47 2020 +0900
Commit: Andras Timar 
CommitDate: Thu Nov 26 10:33:59 2020 +0100

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 a2629902241f..98533c972f15 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -438,12 +438,14 @@ void GraphicTest::testSwappingPageNumber()
 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->ImplIsSwapOut());
 
 // Swapping out
-CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->ImplSwapOut());
-CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->ImplIsSwapOut());
-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()->ImplSwapOut());
+//CPPUNIT_ASSERT_EQUAL(true, 
aGraphic.ImplGetImpGraphic()->ImplIsSwapOut());
+//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()->ImplIsSwapOut());
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index dc0122de050d..de3cbefc4d79 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1349,6 +1349,13 @@ bool ImpGraphic::ImplSwapOut()
 {
 bool bRet = false;
 
+// Hack / Workaround - ignore swap out PDF files
+if (maVectorGraphicData &&
+maVectorGraphicData->getVectorGraphicDataType() == 
VectorGraphicDataType::Pdf)
+{
+return false;
+}
+
 if( !ImplIsSwapOut() )
 {
 ::utl::TempFile aTempFile;
diff --git a/vcl/source/graphic/Manager.cxx b/vcl/source/graphic/Manager.cxx
index 5942b5cb8784..1be52a7e987c 100644
--- a/vcl/source/graphic/Manager.cxx
+++ b/vcl/source/graphic/Manager.cxx
@@ -109,6 +109,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


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

2020-11-12 Thread Miklos Vajna (via logerrit)
 vcl/qa/cppunit/filter/ipdf/data/dict-array-dict.pdf |   55 
 vcl/qa/cppunit/filter/ipdf/ipdf.cxx |   21 +++
 vcl/source/filter/ipdf/pdfdocument.cxx  |   13 
 3 files changed, 87 insertions(+), 2 deletions(-)

New commits:
commit c10a3586f10a9129135275c3c33cf3c7cfe8b42d
Author: Miklos Vajna 
AuthorDate: Fri Oct 16 18:15:21 2020 +0200
Commit: Miklos Vajna 
CommitDate: Thu Nov 12 12:35:50 2020 +0100

vcl pdf tokenizer: fix handling of dict -> array -> dict tokens

Needed to be able to parse the /Reference key of signatures.

Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104443
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins
(cherry picked from commit 056c1284d6a68525002c54bef10834cc135385db)

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

diff --git a/vcl/qa/cppunit/filter/ipdf/data/dict-array-dict.pdf 
b/vcl/qa/cppunit/filter/ipdf/data/dict-array-dict.pdf
new file mode 100644
index ..73de3117b9a6
--- /dev/null
+++ b/vcl/qa/cppunit/filter/ipdf/data/dict-array-dict.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
+  /Key[<>]
+>>
+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 
+000251 0 n 
+trailer <<
+  /Root 1 0 R
+  /Size 5
+>>
+startxref
+491
+%%EOF
diff --git a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx 
b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
index 362aa9b8ec4c..5055e36a922e 100644
--- a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
+++ b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 
 using namespace ::com::sun::star;
 
@@ -147,6 +148,26 @@ CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, 
testPDFAddVisibleSignatureLastPage)
 CPPUNIT_ASSERT_EQUAL(4, FPDFAnnot_GetObjectCount(pAnnot.get()));
 }
 
+CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, testDictArrayDict)
+{
+// Load a file that has markup like this:
+// 3 0 obj <<
+//   /Key[<>]
+// >>
+OUString aSourceURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"dict-array-dict.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 pKey = 
dynamic_cast(pPage->Lookup("Key"));
+
+// Without the accompanying fix in place, this test would have failed, 
because the value of Key
+// was a dictionary element, not an array element.
+CPPUNIT_ASSERT(pKey);
+}
+
 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 7d1305fa364c..690e2daf1263 100644
--- a/vcl/source/filter/ipdf/pdfdocument.cxx
+++ b/vcl/source/filter/ipdf/pdfdocument.cxx
@@ -2401,8 +2401,17 @@ size_t PDFDictionaryElement::Parse(const 
std::vector
 if (nexti >= i) // ensure we go forwards and not endlessly loop
 {
 i = nexti;
-rDictionary[aName] = pDictionary;
-aName.clear();
+if (pArray)
+{
+// Dictionary value inside an array.
+pArray->PushBack(pDictionary);
+}
+else
+{
+// Dictionary toplevel value.
+rDictionary[aName] = pDictionary;
+aName.clear();
+}
 }
 }
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - vcl/qa

2020-08-19 Thread Tomaž Vajngerl (via logerrit)
 vcl/qa/cppunit/GraphicTest.cxx |   42 +
 1 file changed, 42 insertions(+)

New commits:
commit 574a5433417efe38e683506a24167b767fc69610
Author: Tomaž Vajngerl 
AuthorDate: Mon Aug 17 07:44:57 2020 +0200
Commit: Tomaž Vajngerl 
CommitDate: Wed Aug 19 10:37:15 2020 +0200

Add test for preserving page number when suapping

Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100838
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 
(cherry picked from commit bda18edf18f30cabb1c6589c59afc77f38541220)

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

diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index 7038ae4c6a11..a2629902241f 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -38,6 +38,7 @@ class GraphicTest : public CppUnit::TestFixture
 void testUnloadedGraphicSizeUnit();
 void testSwapping();
 void testSwappingVectorGraphic();
+void testSwappingPageNumber();
 
 CPPUNIT_TEST_SUITE(GraphicTest);
 CPPUNIT_TEST(testUnloadedGraphic);
@@ -47,6 +48,7 @@ class GraphicTest : public CppUnit::TestFixture
 CPPUNIT_TEST(testUnloadedGraphicSizeUnit);
 CPPUNIT_TEST(testSwapping);
 CPPUNIT_TEST(testSwappingVectorGraphic);
+CPPUNIT_TEST(testSwappingPageNumber);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -157,6 +159,7 @@ bool checkBitmap(Graphic& rGraphic)
 }
 
 char const DATA_DIRECTORY[] = "/vcl/qa/cppunit/data/";
+char const PDFEXPORT_DATA_DIRECTORY[] = "/vcl/qa/cppunit/pdfexport/data/";
 
 void GraphicTest::testUnloadedGraphic()
 {
@@ -409,6 +412,45 @@ void GraphicTest::testSwappingVectorGraphic()
 CPPUNIT_ASSERT_EQUAL(false, 
comphelper::DirectoryHelper::fileExists(rSwapFileURL));
 }
 
+void GraphicTest::testSwappingPageNumber()
+{
+test::Directories aDirectories;
+OUString aURL = aDirectories.getURLFromSrc(PDFEXPORT_DATA_DIRECTORY) + 
"SimpleMultiPagePDF.pdf";
+SvFileStream aStream(aURL, StreamMode::READ);
+GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
+Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
+
+CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
+CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+
+// Load the vector graphic
+CPPUNIT_ASSERT_EQUAL(true, bool(aGraphic.getVectorGraphicData()));
+// Set the page index
+aGraphic.getVectorGraphicData()->setPageIndex(1);
+
+CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf,
+ 
aGraphic.getVectorGraphicData()->getVectorGraphicDataType());
+CPPUNIT_ASSERT_EQUAL(sal_uInt32(17693),
+ 
aGraphic.getVectorGraphicData()->getVectorGraphicDataArrayLength());
+CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
+CPPUNIT_ASSERT_EQUAL(sal_Int32(1), 
aGraphic.getVectorGraphicData()->getPageIndex());
+
+CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->ImplIsSwapOut());
+
+// Swapping out
+CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->ImplSwapOut());
+CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->ImplIsSwapOut());
+CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+
+// Let's swap in
+CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
+CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
+CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->ImplIsSwapOut());
+
+CPPUNIT_ASSERT_EQUAL(sal_Int32(1), 
aGraphic.getVectorGraphicData()->getPageIndex());
+}
+
 } // namespace
 
 CPPUNIT_TEST_SUITE_REGISTRATION(GraphicTest);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - vcl/qa

2020-08-19 Thread Luboš Luňák (via logerrit)
 vcl/qa/cppunit/GraphicTest.cxx |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

New commits:
commit b5ee39024198f4a820b5680152757c83bdb8f3bf
Author: Luboš Luňák 
AuthorDate: Thu May 14 16:02:31 2020 +0200
Commit: Tomaž Vajngerl 
CommitDate: Wed Aug 19 10:35:28 2020 +0200

do not hardcode a BitmapChecksum in a test

The checksum depends on this like RGB vs BGR and changing the VCL
backend to e.g. Skia breaks this.

Change-Id: I5bb3f4c009327c92683bfa575bd1510e3a1ea826
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94224
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 
(cherry picked from commit 88aeadd97e3aa8146e88912fa06d65743a36ead3)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100882
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Luboš Luňák 

diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx
index 583d7ce2ae3d..1630a599f7fd 100644
--- a/vcl/qa/cppunit/GraphicTest.cxx
+++ b/vcl/qa/cppunit/GraphicTest.cxx
@@ -289,7 +289,8 @@ void GraphicTest::testSwapping()
 
 CPPUNIT_ASSERT_EQUAL(120L, aGraphic.GetSizePixel().Width());
 CPPUNIT_ASSERT_EQUAL(100L, aGraphic.GetSizePixel().Height());
-CPPUNIT_ASSERT_EQUAL(BitmapChecksum(0xF5331397837B58EB), 
aGraphic.GetChecksum());
+
+BitmapChecksum aChecksumBeforeSwapping = aGraphic.GetChecksum();
 
 CPPUNIT_ASSERT_EQUAL(sal_uInt32(319), aGraphic.GetGfxLink().GetDataSize());
 
@@ -330,7 +331,7 @@ void GraphicTest::testSwapping()
 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->ImplIsSwapOut());
 
-CPPUNIT_ASSERT_EQUAL(BitmapChecksum(0xF5331397837B58EB), 
aGraphic.GetChecksum());
+CPPUNIT_ASSERT_EQUAL(aChecksumBeforeSwapping, aGraphic.GetChecksum());
 
 // File shouldn't be available anymore
 CPPUNIT_ASSERT_EQUAL(false, 
comphelper::DirectoryHelper::fileExists(rSwapFileURL));
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - vcl/qa

2020-06-07 Thread Tomaž Vajngerl (via logerrit)
 vcl/qa/cppunit/pdfexport/data/SimpleMultiPagePDF.pdf |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx   |  137 +++
 2 files changed, 137 insertions(+)

New commits:
commit 9a66b4fb9b3c408c3ea61cd89817d14f3c8d9a50
Author: Tomaž Vajngerl 
AuthorDate: Thu Apr 30 07:54:46 2020 +0200
Commit: Tomaž Vajngerl 
CommitDate: Sun Jun 7 21:18:41 2020 +0200

test import and export of multi-page PDF with PDFium filter

The test checks that the exported PDFs contain embedded PDF for
different pages.

Change-Id: I4e5cd108d8597851d86aa774efbde0d4f2b9d2ac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93322
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95701
Tested-by: Tomaž Vajngerl 

diff --git a/vcl/qa/cppunit/pdfexport/data/SimpleMultiPagePDF.pdf 
b/vcl/qa/cppunit/pdfexport/data/SimpleMultiPagePDF.pdf
new file mode 100644
index ..af665fcba8a0
Binary files /dev/null and 
b/vcl/qa/cppunit/pdfexport/data/SimpleMultiPagePDF.pdf differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 898e7188ed8c..be40e202306d 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -23,6 +23,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -141,6 +142,8 @@ public:
 void testLargePage();
 void testVersion15();
 void testDefaultVersion();
+void testMultiPagePDF();
+
 
 CPPUNIT_TEST_SUITE(PdfExportTest);
 CPPUNIT_TEST(testTdf106059);
@@ -182,6 +185,7 @@ public:
 CPPUNIT_TEST(testLargePage);
 CPPUNIT_TEST(testVersion15);
 CPPUNIT_TEST(testDefaultVersion);
+CPPUNIT_TEST(testMultiPagePDF);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -2060,6 +2064,139 @@ void PdfExportTest::testVersion15()
 CPPUNIT_ASSERT_EQUAL(15, nFileVersion);
 }
 
+// Check round-trip of importing and exporting the PDF with PDFium filter,
+// which imports the PDF document as multiple PDFs as graphic object.
+// Each page in the document has one PDF graphic object which content is
+// the correcponding page in the PDF. When such a document is exported,
+// the PDF graphic gets embedded into the exported PDF document (as a
+// Form XObject).
+void PdfExportTest::testMultiPagePDF()
+{
+// setenv only works on unix based systems
+#ifndef _WIN32
+// We need to enable PDFium import (and make sure to disable after the 
test)
+bool bResetEnvVar = false;
+if (getenv("LO_IMPORT_USE_PDFIUM") == nullptr)
+{
+bResetEnvVar = true;
+setenv("LO_IMPORT_USE_PDFIUM", "1", false);
+}
+comphelper::ScopeGuard aPDFiumEnvVarGuard([&]() {
+if (bResetEnvVar)
+unsetenv("LO_IMPORT_USE_PDFIUM");
+});
+
+// Load the PDF and save as PDF
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"SimpleMultiPagePDF.pdf";
+mxComponent = loadFromDesktop(aURL);
+CPPUNIT_ASSERT(mxComponent.is());
+
+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.
+vcl::filter::PDFDocument aDocument;
+SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ);
+CPPUNIT_ASSERT(aDocument.Read(aStream));
+
+std::vector aPages = aDocument.GetPages();
+CPPUNIT_ASSERT_EQUAL(static_cast(3), aPages.size());
+
+vcl::filter::PDFObjectElement* pResources = 
aPages[0]->LookupObject("Resources");
+CPPUNIT_ASSERT(pResources);
+
+auto pXObjects = 
dynamic_cast(pResources->Lookup("XObject"));
+CPPUNIT_ASSERT(pXObjects);
+
+CPPUNIT_ASSERT_EQUAL(static_cast(3), 
pXObjects->GetItems().size()); // 3 PDFs as Form XObjects
+
+std::vector rIDs;
+for (auto const & rPair : pXObjects->GetItems()) {
+rIDs.push_back(rPair.first);
+}
+
+// Let's check the embedded PDF pages - just make sure the size differs,
+// which should indicate we don't have 3 times the same page.
+
+{   // embedded PDF page 1
+vcl::filter::PDFObjectElement* pXObject1 = 
pXObjects->LookupObject(rIDs[0]);
+CPPUNIT_ASSERT(pXObject1);
+CPPUNIT_ASSERT_EQUAL(OString("Im19"), rIDs[0]);
+
+auto pSubtype1 = 
dynamic_cast(pXObject1->Lookup("Subtype"));
+CPPUNIT_ASSERT(pSubtype1);
+CPPUNIT_ASSERT_EQUAL(OString("Form"), pSubtype1->GetValue());
+
+auto pXObjectResources = 
dynamic_cast(pXObject1->Lookup("Resources"));
+CPPUNIT_ASSERT(pXObjectResources);
+auto pXObjectForms = 
dynamic_cast(pXObjectResources->LookupElement("XObject"));
+CPPUNIT_ASSERT(pXObjectForms);
+vcl::filter::PDFObjectElement* pForm = 
pXObjectForms->LookupObject(pXObjectForms->GetItems().begin()->first);
+