[Libreoffice-commits] core.git: filter/source include/vcl officecfg/registry vcl/qa vcl/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Fri Apr 17 17:18:12 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 141e0449fdab89384564659191492b698e4b13d8
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Apr 17 17:28:58 2020 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Apr 17 19:17:36 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.
Change-Id: I9598dc46fe7db428bd2eff98bebff8b3c873b4ff
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92457
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
Tested-by: Jenkins
diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx
index 6e13beb96cd6..787bcab4398b 100644
--- a/filter/source/pdf/pdfexport.cxx
+++ b/filter/source/pdf/pdfexport.cxx
@@ -591,7 +591,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;
@@ -614,6 +614,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 1a7e6fda451d..b3b0f2c6e691 100644
--- a/include/vcl/pdfwriter.hxx
+++ b/include/vcl/pdfwriter.hxx
@@ -614,7 +614,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 ),
UniversalAccessibilityCompliance( false ),
Tagged( false ),
SubmitFormat( PDFWriter::FDF ),
diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index 1307269765fb..b405ea981d53 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -5328,7 +5328,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="16">
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index a2910b44fb81..c2aea35fb72f 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -144,6 +144,8 @@ public:
void testReduceImage();
void testLinkWrongPage();
void testLargePage();
+ void testVersion15();
+ void testDefaultVersion();
CPPUNIT_TEST_SUITE(PdfExportTest);
CPPUNIT_TEST(testTdf106059);
@@ -185,6 +187,8 @@ public:
CPPUNIT_TEST(testReduceImage);
CPPUNIT_TEST(testLinkWrongPage);
CPPUNIT_TEST(testLargePage);
+ CPPUNIT_TEST(testVersion15);
+ CPPUNIT_TEST(testDefaultVersion);
CPPUNIT_TEST_SUITE_END();
};
@@ -2101,6 +2105,55 @@ void PdfExportTest::testPdfImageResourceInlineXObjectRef()
CPPUNIT_ASSERT_EQUAL(-90, nRotateDeg);
}
+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 022fa502f986..1df96ad46e72 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -65,7 +65,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
@@ -81,7 +81,7 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream)
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;
@@ -103,8 +103,8 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream)
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 587b328307f5..9a8a93076d2e 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -548,6 +548,7 @@ PDFPage::PDFPage( PDFWriterImpl* pWriter, double nPageWidth, double nPageHeight,
m_pWriter( pWriter ),
m_nPageWidth( nPageWidth ),
m_nPageHeight( nPageHeight ),
+ m_nUserUnit( 1 ),
m_eOrientation( eOrientation ),
m_nPageObject( 0 ), // invalid object number
m_nStreamLengthObject( 0 ),
@@ -557,7 +558,16 @@ PDFPage::PDFPage( PDFWriterImpl* pWriter, double nPageWidth, double nPageHeight,
{
// 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;
+ }
}
void PDFPage::beginStream()
@@ -1228,8 +1238,8 @@ PDFWriterImpl::PDFWriterImpl( const PDFWriter::PDFWriterContext& rContext,
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