[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - filter/source include/vcl officecfg/registry vcl/qa vcl/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Wed May 6 16:03:51 UTC 2020
filter/source/pdf/pdfexport.cxx | 5 -
include/vcl/pdfwriter.hxx | 2
officecfg/registry/schema/org/openoffice/Office/Common.xcs | 7 +
vcl/qa/cppunit/pdfexport/pdfexport.cxx | 53 +++++++++++++
vcl/source/filter/ipdf/pdfread.cxx | 8 -
vcl/source/gdi/pdfwriter_impl.cxx | 14 ++-
6 files changed, 80 insertions(+), 9 deletions(-)
New commits:
commit e2e76c1f8cdfa844aa660c52870573e739d3710c
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Apr 17 17:28:58 2020 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed May 6 18:03:19 2020 +0200
Change default PDF version to 1.6 (released in 2004)
We already write markup which is newer than 1.5, but the PDF version was
not changed. Fix the one violation I'm aware of.
Printing is left unchanged, similar to how commit
99ac4ee05b039166eedfe361fb985682fd92dd13 (Change default PDF version to
1.5, 2018-04-24) updated the default last time.
(cherry picked from commit 141e0449fdab89384564659191492b698e4b13d8)
Conflicts:
filter/source/pdf/pdfexport.cxx
include/vcl/pdfwriter.hxx
vcl/qa/cppunit/pdfexport/pdfexport.cxx
Change-Id: I9598dc46fe7db428bd2eff98bebff8b3c873b4ff
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93503
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx
index e9941c49147a..0ed63f99599e 100644
--- a/filter/source/pdf/pdfexport.cxx
+++ b/filter/source/pdf/pdfexport.cxx
@@ -597,7 +597,7 @@ bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >&
{
default:
case 0:
- aContext.Version = vcl::PDFWriter::PDFVersion::PDF_1_5;
+ aContext.Version = vcl::PDFWriter::PDFVersion::PDF_1_6;
break;
case 1:
aContext.Version = vcl::PDFWriter::PDFVersion::PDF_A_1;
@@ -607,6 +607,9 @@ bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >&
mbEncrypt = false; // no encryption
xEnc.clear();
break;
+ case 15:
+ aContext.Version = vcl::PDFWriter::PDFVersion::PDF_1_5;
+ break;
case 16:
aContext.Version = vcl::PDFWriter::PDFVersion::PDF_1_6;
break;
diff --git a/include/vcl/pdfwriter.hxx b/include/vcl/pdfwriter.hxx
index 751f698892f1..21d5c69dfbb3 100644
--- a/include/vcl/pdfwriter.hxx
+++ b/include/vcl/pdfwriter.hxx
@@ -620,7 +620,7 @@ The following structure describes the permissions used in PDF security
DefaultLinkAction( PDFWriter::URIAction ),
ConvertOOoTargetToPDFTarget( false ),
ForcePDFAction( false ),
- Version( PDFWriter::PDFVersion::PDF_1_5 ),
+ Version( PDFWriter::PDFVersion::PDF_1_6 ),
Tagged( false ),
SubmitFormat( PDFWriter::FDF ),
AllowDuplicateFieldNames( false ),
diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index bb285d61585c..3c161adcb1b4 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -5249,7 +5249,12 @@
<constraints>
<enumeration oor:value="0">
<info>
- <desc>PDF 1.5 (default selection).</desc>
+ <desc>PDF 1.6 (default selection).</desc>
+ </info>
+ </enumeration>
+ <enumeration oor:value="15">
+ <info>
+ <desc>PDF 1.5</desc>
</info>
</enumeration>
<enumeration oor:value="1">
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index fbc1f9be4160..8186d3857ba3 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -130,6 +130,8 @@ public:
void testTdf121962();
void testTdf121615();
void testLargePage();
+ void testVersion15();
+ void testDefaultVersion();
CPPUNIT_TEST_SUITE(PdfExportTest);
CPPUNIT_TEST(testTdf106059);
@@ -166,6 +168,8 @@ public:
CPPUNIT_TEST(testTdf121962);
CPPUNIT_TEST(testTdf121615);
CPPUNIT_TEST(testLargePage);
+ CPPUNIT_TEST(testVersion15);
+ CPPUNIT_TEST(testDefaultVersion);
CPPUNIT_TEST_SUITE_END();
};
@@ -1752,6 +1756,55 @@ void PdfExportTest::testLargePage()
CPPUNIT_ASSERT_DOUBLES_EQUAL(8503.94, fWidth, 0.01);
}
+void PdfExportTest::testDefaultVersion()
+{
+ // Create an empty document.
+ mxComponent = loadFromDesktop("private:factory/swriter");
+ CPPUNIT_ASSERT(mxComponent.is());
+
+ // Save as PDF.
+ uno::Reference<frame::XStorable> 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);
+ DocumentHolder pPdfDocument(
+ FPDF_LoadMemDocument(maMemory.GetData(), maMemory.GetSize(), /*password=*/nullptr));
+ CPPUNIT_ASSERT(pPdfDocument.get());
+ int nFileVersion = 0;
+ FPDF_GetFileVersion(pPdfDocument.get(), &nFileVersion);
+ CPPUNIT_ASSERT_EQUAL(16, nFileVersion);
+}
+
+void PdfExportTest::testVersion15()
+{
+ // Create an empty document.
+ mxComponent = loadFromDesktop("private:factory/swriter");
+ CPPUNIT_ASSERT(mxComponent.is());
+
+ // Save as PDF.
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aFilterData(comphelper::InitPropertySequence(
+ { { "SelectPdfVersion", uno::makeAny(static_cast<sal_Int32>(15)) } }));
+ utl::MediaDescriptor aMediaDescriptor;
+ aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+ aMediaDescriptor["FilterData"] <<= aFilterData;
+ xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+
+ // Parse the export result.
+ SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
+ maMemory.WriteStream(aFile);
+ DocumentHolder pPdfDocument(
+ FPDF_LoadMemDocument(maMemory.GetData(), maMemory.GetSize(), /*password=*/nullptr));
+ CPPUNIT_ASSERT(pPdfDocument.get());
+ int nFileVersion = 0;
+ FPDF_GetFileVersion(pPdfDocument.get(), &nFileVersion);
+ CPPUNIT_ASSERT_EQUAL(15, nFileVersion);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest);
}
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index ebe6d0db0c03..f9104152fbe8 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -67,7 +67,7 @@ bool isCompatible(SvStream& rInStream, sal_uInt64 nPos, sal_uInt64 nSize)
sal_Int32 nMajor = OString(aFirstBytes[5]).toInt32();
sal_Int32 nMinor = OString(aFirstBytes[7]).toInt32();
- return !(nMajor > 1 || (nMajor == 1 && nMinor > 5));
+ return !(nMajor > 1 || (nMajor == 1 && nMinor > 6));
}
/// Takes care of transparently downgrading the version of the PDF stream in
@@ -82,7 +82,7 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream, sal_uInt64 n
rOutStream.WriteStream(rInStream, nSize);
else
{
- // Downconvert to PDF-1.5.
+ // Downconvert to PDF-1.6.
FPDF_LIBRARY_CONFIG aConfig;
aConfig.version = 2;
aConfig.m_pUserFontPaths = nullptr;
@@ -104,8 +104,8 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream, sal_uInt64 n
aWriter.version = 1;
aWriter.WriteBlock = &CompatibleWriterCallback;
- // 15 means PDF-1.5.
- if (!FPDF_SaveWithVersion(pPdfDocument, &aWriter, 0, 15))
+ // 16 means PDF-1.6.
+ if (!FPDF_SaveWithVersion(pPdfDocument, &aWriter, 0, 16))
return false;
FPDF_CloseDocument(pPdfDocument);
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index bf44533afcb2..60be24294217 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -1123,6 +1123,7 @@ PDFWriterImpl::PDFPage::PDFPage( PDFWriterImpl* pWriter, double nPageWidth, doub
m_pWriter( pWriter ),
m_nPageWidth( nPageWidth ),
m_nPageHeight( nPageHeight ),
+ m_nUserUnit( 1 ),
m_eOrientation( eOrientation ),
m_nPageObject( 0 ), // invalid object number
m_nStreamLengthObject( 0 ),
@@ -1132,7 +1133,16 @@ PDFWriterImpl::PDFPage::PDFPage( PDFWriterImpl* pWriter, double nPageWidth, doub
{
// object ref must be only ever updated in emit()
m_nPageObject = m_pWriter->createObject();
- m_nUserUnit = std::ceil(std::max(nPageWidth, nPageHeight) / 14400.0);
+
+ switch (m_pWriter->m_aContext.Version)
+ {
+ case PDFWriter::PDFVersion::PDF_1_6:
+ m_nUserUnit = std::ceil(std::max(nPageWidth, nPageHeight) / 14400.0);
+ break;
+ default:
+ // 1.2 -> 1.5
+ break;
+ }
}
PDFWriterImpl::PDFPage::~PDFPage()
@@ -1798,8 +1808,8 @@ double PDFWriterImpl::PDFPage::getHeight() const
case PDFWriter::PDFVersion::PDF_1_3: aBuffer.append( "1.3" );break;
case PDFWriter::PDFVersion::PDF_A_1:
case PDFWriter::PDFVersion::PDF_1_4: aBuffer.append( "1.4" );break;
- default:
case PDFWriter::PDFVersion::PDF_1_5: aBuffer.append( "1.5" );break;
+ default:
case PDFWriter::PDFVersion::PDF_1_6: aBuffer.append( "1.6" );break;
}
// append something binary as comment (suggested in PDF Reference)
More information about the Libreoffice-commits
mailing list