filter/source/pdf/pdffilter.cxx                 |    2 
 vcl/qa/cppunit/pdfexport/data/reduce-image.fodt |   29 +++++++++++
 vcl/qa/cppunit/pdfexport/pdfexport.cxx          |   61 ++++++++++++++++++++++++
 3 files changed, 91 insertions(+), 1 deletion(-)

New commits:
commit 3b9797671ce49f53b2c583c9201c348b55b10c96
Author:     Miklos Vajna <[email protected]>
AuthorDate: Tue Jan 21 16:55:08 2020 +0100
Commit:     Miklos Vajna <[email protected]>
CommitDate: Tue Jan 21 17:51:04 2020 +0100

    PDF export: don't ignore FilterData specified by UNO clients
    
    The data was given to the PDF filter, but then we stopped iterating
    right after finding our output stream. Seems this was always like this,
    ever since commit 4111b430a0a7954416ff95794a8ffb8fbc4472e3 (#101570#:
    added pdf filter, 2002-08-13).
    
    Change-Id: If26661935c22a7b7959fda5f92b4d50b15f13a35
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87152
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Jenkins

diff --git a/filter/source/pdf/pdffilter.cxx b/filter/source/pdf/pdffilter.cxx
index 5a7e5fbaedf0..1bb919805b79 100644
--- a/filter/source/pdf/pdffilter.cxx
+++ b/filter/source/pdf/pdffilter.cxx
@@ -55,7 +55,7 @@ bool PDFFilter::implExport( const Sequence< PropertyValue >& 
rDescriptor )
     Reference< task::XStatusIndicator > xStatusIndicator;
     Reference< task::XInteractionHandler > xIH;
 
-    for (sal_Int32 i = 0 ; ( i < nLength ) && !xOStm.is(); ++i)
+    for (sal_Int32 i = 0; i < nLength; ++i)
     {
         if ( pValue[ i ].Name == "OutputStream" )
             pValue[ i ].Value >>= xOStm;
diff --git a/vcl/qa/cppunit/pdfexport/data/reduce-image.fodt 
b/vcl/qa/cppunit/pdfexport/data/reduce-image.fodt
new file mode 100644
index 000000000000..b5737ae27ec1
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/reduce-image.fodt
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:css3t="http://www.w3.org/TR/css3-text/"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.
 0" 
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
 xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:rpt="http://op
 enoffice.org/2005/report" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+  <office:styles>
+    <style:default-style style:family="graphic">
+    </style:default-style>
+    <style:style style:name="Graphics" style:family="graphic">
+    </style:style>
+  </office:styles>
+  <office:automatic-styles>
+    <style:style style:name="fr1" style:family="graphic" 
style:parent-style-name="Graphics">
+      <style:graphic-properties style:run-through="foreground" 
style:horizontal-pos="center" style:horizontal-rel="paragraph" 
style:mirror="none" fo:clip="rect(0cm, 0cm, 0cm, 0cm)" draw:luminance="0%" 
draw:contrast="0%" draw:red="0%" draw:green="0%" draw:blue="0%" 
draw:gamma="100%" draw:color-inversion="false" draw:image-opacity="100%" 
draw:color-mode="standard"/>
+    </style:style>
+  </office:automatic-styles>
+  <office:body>
+    <office:text>
+      <text:p text:style-name="Standard"><draw:frame draw:style-name="fr1" 
draw:name="Image1" text:anchor-type="char" svg:width="0.041cm" 
svg:height="0.041cm" draw:z-index="0"><draw:image 
loext:mime-type="image/png"><office:binary-data>iVBORw0KGgoAAAANSUhEUgAAAKAAAACgCAYAAACLz2ctAAAABmJLR0QA/wD/AP+gvaeTAAAA
+       CXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH5AEVDCUTfvEVdAAAAYhJREFUeNrt3bEJwzAQ
+       htFckjLreP8Bso5bc2lTpBDG4kfkvQUE5uNUGEnV3TdIufsECBABggARIAgQAYIAESAIEAGC
+       ABEgCBABggARIAgQAYIAESAIEAGCABEgCBABggARIHx7phZ+vF9D13Id217WXW9dExBbMAgQ
+       AYIAESAIEAGCABEgCBABIkAQIAIEASJAECAChKnq6hfTR88gsKarz46YgNiCESAIEAGCABEg
+       CBABwlSx27FStzHxW+oPlgmILRgBggARIAgQAYIAESAIEAGCABEgCBABggARIAgQAYIAESAI
+       EAGCABEgCBABggARIAgQAYIAESACBAEiQBAgAgQBIkAQIAIEASJAECACBAEiQBAgi4u9mJ56
+       oRsTEASIAEGACBABggARIAiQP1LdmR8So39Cjm0v6663rgmILRgEiABBgAgQBIgAQYAIEASI
+       ABEgCBABggARIAgQAcJUsTMhYAIiQAQIAkSAIEAECAJEgCBABAgCRIAgQAQIAkSAIEAECKd9
+       AEYENxB/sygQAAAAAElFTkSuQmCC
+      </office:binary-data></draw:image></draw:frame></text:p>
+    </office:text>
+  </office:body>
+</office:document>
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index d3cdcce90ea4..c13b2ab80c09 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -22,6 +22,9 @@
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/drawing/XShape.hpp>
 #include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/document/XFilter.hpp>
+#include <com/sun/star/document/XExporter.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
 
 #include <comphelper/processfactory.hxx>
 #include <comphelper/propertysequence.hxx>
@@ -37,6 +40,7 @@
 #include <fpdfview.h>
 #include <vcl/graphicfilter.hxx>
 #include <basegfx/matrix/b2dhommatrix.hxx>
+#include <unotools/streamwrap.hxx>
 
 using namespace ::com::sun::star;
 
@@ -138,6 +142,7 @@ public:
     void testTocLink();
     void testPdfImageResourceInlineXObjectRef();
     void testReduceSmallImage();
+    void testReduceImage();
 
     CPPUNIT_TEST_SUITE(PdfExportTest);
     CPPUNIT_TEST(testTdf106059);
@@ -176,6 +181,7 @@ public:
     CPPUNIT_TEST(testTocLink);
     CPPUNIT_TEST(testPdfImageResourceInlineXObjectRef);
     CPPUNIT_TEST(testReduceSmallImage);
+    CPPUNIT_TEST(testReduceImage);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -1899,6 +1905,61 @@ void PdfExportTest::testReduceSmallImage()
     CPPUNIT_ASSERT_EQUAL(16, nHeight);
 }
 
+void PdfExportTest::testReduceImage()
+{
+    // Load the Writer document.
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"reduce-image.fodt";
+    mxComponent = loadFromDesktop(aURL);
+
+    // Save as PDF.
+    uno::Reference<css::lang::XMultiServiceFactory> xFactory = 
getMultiServiceFactory();
+    uno::Reference<document::XFilter> xFilter(
+        xFactory->createInstance("com.sun.star.document.PDFFilter"), 
uno::UNO_QUERY);
+    uno::Reference<document::XExporter> xExporter(xFilter, uno::UNO_QUERY);
+    xExporter->setSourceDocument(mxComponent);
+
+    SvFileStream aOutputStream(maTempFile.GetURL(), StreamMode::WRITE);
+    uno::Reference<io::XOutputStream> xOutputStream(new 
utl::OStreamWrapper(aOutputStream));
+
+    uno::Sequence<beans::PropertyValue> aFilterData(
+        comphelper::InitPropertySequence({ { "ReduceImageResolution", 
uno::Any(false) } }));
+
+    // This is intentionally in an "unlucky" order, output stream comes before 
filter data.
+    uno::Sequence<beans::PropertyValue> 
aDescriptor(comphelper::InitPropertySequence({
+        { "FilterName", uno::Any(OUString("writer_pdf_Export")) },
+        { "OutputStream", uno::Any(xOutputStream) },
+        { "FilterData", uno::Any(aFilterData) },
+    }));
+    xFilter->filter(aDescriptor);
+    aOutputStream.Close();
+
+    // Parse the PDF: get the image.
+    SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
+    maMemory.WriteStream(aFile);
+    DocumentHolder pPdfDocument(
+        FPDF_LoadMemDocument(maMemory.GetData(), maMemory.GetSize(), 
/*password=*/nullptr));
+    CPPUNIT_ASSERT(pPdfDocument.get());
+    CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(pPdfDocument.get()));
+    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_IMAGE, FPDFPageObj_GetType(pPageObject));
+
+    // Make sure we don't scale down a bitmap.
+    FPDF_BITMAP pBitmap = FPDFImageObj_GetBitmap(pPageObject);
+    CPPUNIT_ASSERT(pBitmap);
+    int nWidth = FPDFBitmap_GetWidth(pBitmap);
+    int nHeight = FPDFBitmap_GetHeight(pBitmap);
+    FPDFBitmap_Destroy(pBitmap);
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 160
+    // - Actual  : 6
+    // i.e. the image was scaled down even with ReduceImageResolution=false.
+    CPPUNIT_ASSERT_EQUAL(160, nWidth);
+    CPPUNIT_ASSERT_EQUAL(160, nHeight);
+}
+
 void PdfExportTest::testPdfImageResourceInlineXObjectRef()
 {
     // Create an empty document.
_______________________________________________
Libreoffice-commits mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to