[Libreoffice-commits] core.git: Branch 'libreoffice-6-0' - vcl/qa vcl/source

2018-05-29 Thread Miklos Vajna
 vcl/qa/cppunit/pdfexport/data/tdf113143.odp |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx  |  173 +---
 vcl/source/gdi/pdfextoutdevdata.cxx |6 
 3 files changed, 114 insertions(+), 65 deletions(-)

New commits:
commit 257014ce03dee29506e8e70c204e912c4ed33172
Author: Miklos Vajna 
Date:   Thu May 24 17:29:13 2018 +0200

tdf#113143 PDF export: fix mis-scaled JPGs on Impress note pages

This is really similar to commit
4c2172a3e973bc6351107a3a1b554c77b40b75dd (tdf#106702 PDF export: fix
missing images from Writer headers/footers, 2018-05-22) just this one is
about the size of the output rectangle for JPG content, while the
previous problem was about the position of them.

Also extract PdfExportTest::exportAndParse() from the last two tests to
avoid duplication.

(cherry picked from commit 89dc667cebfec5315f0c0361e49d759e88458689)

Change-Id: I9812924d505e9fdaca2a95b4990e7aaa5e44fd7f
Reviewed-on: https://gerrit.libreoffice.org/54989
Tested-by: Jenkins 
Reviewed-by: Christian Lohmaier 

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf113143.odp 
b/vcl/qa/cppunit/pdfexport/data/tdf113143.odp
new file mode 100644
index ..5f8a1b10e2e5
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf113143.odp differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 9e6924f2e66a..da3da74fc63d 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -40,8 +40,13 @@ class PdfExportTest : public test::BootstrapFixture, public 
unotest::MacrosTest
 uno::Reference mxComponent;
 FPDF_PAGE mpPdfPage = nullptr;
 FPDF_DOCUMENT mpPdfDocument = nullptr;
+utl::TempFile maTempFile;
+SvMemoryStream maMemory;
+// Export the document as PDF, then parse it with PDFium.
+void exportAndParse(const OUString& rURL, const utl::MediaDescriptor& 
rDescriptor);
 
 public:
+PdfExportTest();
 virtual void setUp() override;
 virtual void tearDown() override;
 void load(const OUString& rFile, vcl::filter::PDFDocument& rDocument);
@@ -77,6 +82,7 @@ public:
 void testTdf109143();
 void testTdf105954();
 void testTdf106702();
+void testTdf113143();
 
 CPPUNIT_TEST_SUITE(PdfExportTest);
 CPPUNIT_TEST(testTdf106059);
@@ -102,9 +108,32 @@ public:
 CPPUNIT_TEST(testTdf109143);
 CPPUNIT_TEST(testTdf105954);
 CPPUNIT_TEST(testTdf106702);
+CPPUNIT_TEST(testTdf113143);
 CPPUNIT_TEST_SUITE_END();
 };
 
+PdfExportTest::PdfExportTest()
+{
+maTempFile.EnableKillingFile();
+}
+
+void PdfExportTest::exportAndParse(const OUString& rURL, const 
utl::MediaDescriptor& rDescriptor)
+{
+// Import the bugdoc and export as PDF.
+mxComponent = loadFromDesktop(rURL);
+CPPUNIT_ASSERT(mxComponent.is());
+
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+xStorable->storeToURL(maTempFile.GetURL(), 
rDescriptor.getAsConstPropertyValueList());
+
+// Parse the export result with pdfium.
+SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
+maMemory.WriteStream(aFile);
+mpPdfDocument
+= FPDF_LoadMemDocument(maMemory.GetData(), maMemory.GetSize(), 
/*password=*/nullptr);
+CPPUNIT_ASSERT(mpPdfDocument);
+}
+
 void PdfExportTest::setUp()
 {
 test::BootstrapFixture::setUp();
@@ -142,14 +171,12 @@ void PdfExportTest::load(const OUString& rFile, 
vcl::filter::PDFDocument& rDocum
 CPPUNIT_ASSERT(mxComponent.is());
 
 uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
-utl::TempFile aTempFile;
-aTempFile.EnableKillingFile();
 utl::MediaDescriptor aMediaDescriptor;
 aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
-xStorable->storeToURL(aTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
+xStorable->storeToURL(maTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
 
 // Parse the export result.
-SvFileStream aStream(aTempFile.GetURL(), StreamMode::READ);
+SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ);
 CPPUNIT_ASSERT(rDocument.Read(aStream));
 }
 
@@ -161,8 +188,6 @@ void PdfExportTest::testTdf106059()
 CPPUNIT_ASSERT(mxComponent.is());
 
 uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
-utl::TempFile aTempFile;
-aTempFile.EnableKillingFile();
 utl::MediaDescriptor aMediaDescriptor;
 aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
 // Explicitly enable the usage of the reference XObject markup.
@@ -170,11 +195,11 @@ void PdfExportTest::testTdf106059()
 {"UseReferenceXObject", uno::Any(true) }
 }));
 aMediaDescriptor["FilterData"] <<= aFilterData;
-xStorable->storeToURL(aTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
+xStorable->storeToURL(maTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
 
 

[Libreoffice-commits] core.git: Branch 'libreoffice-6-0' - vcl/qa vcl/source

2018-05-18 Thread Miklos Vajna
 vcl/qa/cppunit/pdfexport/data/tdf105954.odt |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx  |   47 
 vcl/source/gdi/pdfextoutdevdata.cxx |5 ++
 3 files changed, 52 insertions(+)

New commits:
commit efd59fd1d7fc9d955a2b924f247709201f2281c5
Author: Miklos Vajna 
Date:   Wed May 16 09:46:36 2018 +0200

tdf#105954 PDF export, ReduceImageResolution: fix re-compressing large 
images

Expensive re-compress is not pointless when the user opts in to reduce
resolution.

(cherry picked from commit 9fd6b6b1f5b83d923a47252b744358721761d9cf)

Conflicts:
vcl/qa/cppunit/pdfexport/pdfexport.cxx
vcl/source/gdi/pdfextoutdevdata.cxx

Change-Id: I1e04c6d4f0d95d41808ef885082239645401b2e2
Reviewed-on: https://gerrit.libreoffice.org/54470
Tested-by: Jenkins 
Reviewed-by: Caolán McNamara 
Tested-by: Caolán McNamara 

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf105954.odt 
b/vcl/qa/cppunit/pdfexport/data/tdf105954.odt
new file mode 100644
index ..ba5c96de68bd
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf105954.odt differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index c6de4b344503..b2ebb23cf6cd 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -79,6 +79,7 @@ public:
 /// Text extracting RTL text with ligatures.
 void testTdf115117_2a();
 #endif
+void testTdf105954();
 #endif
 void testTdf109143();
 
@@ -104,6 +105,7 @@ public:
 CPPUNIT_TEST(testTdf115117_2);
 CPPUNIT_TEST(testTdf115117_2a);
 #endif
+CPPUNIT_TEST(testTdf105954);
 #endif
 CPPUNIT_TEST(testTdf109143);
 CPPUNIT_TEST_SUITE_END();
@@ -1019,6 +1021,51 @@ void PdfExportTest::testTdf115117_2a()
 CPPUNIT_ASSERT_EQUAL(aExpectedText, aActualText);
 }
 #endif
+
+void PdfExportTest::testTdf105954()
+{
+// Import the bugdoc and export as PDF.
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"tdf105954.odt";
+mxComponent = loadFromDesktop(aURL);
+CPPUNIT_ASSERT(mxComponent.is());
+
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+utl::TempFile aTempFile;
+aTempFile.EnableKillingFile();
+utl::MediaDescriptor aMediaDescriptor;
+aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+uno::Sequence 
aFilterData(comphelper::InitPropertySequence(
+{ { "ReduceImageResolution", uno::Any(true) },
+  { "MaxImageResolution", uno::Any(static_cast(300)) } }));
+aMediaDescriptor["FilterData"] <<= aFilterData;
+xStorable->storeToURL(aTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
+
+// Parse the export result with pdfium.
+SvFileStream aFile(aTempFile.GetURL(), StreamMode::READ);
+SvMemoryStream aMemory;
+aMemory.WriteStream(aFile);
+mpPdfDocument
+= FPDF_LoadMemDocument(aMemory.GetData(), aMemory.GetSize(), 
/*password=*/nullptr);
+CPPUNIT_ASSERT(mpPdfDocument);
+
+// The document has one page.
+CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(mpPdfDocument));
+mpPdfPage = FPDF_LoadPage(mpPdfDocument, /*page_index=*/0);
+CPPUNIT_ASSERT(mpPdfPage);
+
+// There is a single image on the page.
+int nPageObjectCount = FPDFPage_CountObjects(mpPdfPage);
+CPPUNIT_ASSERT_EQUAL(1, nPageObjectCount);
+
+// Check width of the image.
+FPDF_PAGEOBJECT pPageObject = FPDFPage_GetObject(mpPdfPage, /*index=*/0);
+FPDF_IMAGEOBJ_METADATA aMeta;
+CPPUNIT_ASSERT(FPDFImageObj_GetImageMetadata(pPageObject, mpPdfPage, 
));
+// This was 2000, i.e. the 'reduce to 300 DPI' request was ignored.
+// This is now around 238 (228 on macOS).
+CPPUNIT_ASSERT_LESS(static_cast(250), aMeta.width);
+}
+
 #endif
 
 CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest);
diff --git a/vcl/source/gdi/pdfextoutdevdata.cxx 
b/vcl/source/gdi/pdfextoutdevdata.cxx
index 71ef583cda58..3c689c3ccce0 100644
--- a/vcl/source/gdi/pdfextoutdevdata.cxx
+++ b/vcl/source/gdi/pdfextoutdevdata.cxx
@@ -810,6 +810,11 @@ bool PDFExtOutDevData::HasAdequateCompression( const 
Graphic ,
 // rOutputRect is the crop rectangle, re-compress cropped image.
 return false;
 
+if (mbReduceImageResolution)
+// Reducing resolution was requested, implies that re-compressing is
+// wanted.
+return false;
+
 if (rGraphic.GetLink().GetDataSize() == 0)
 return false;
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits