diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-01-03 12:40:16 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-01-04 17:36:35 +0100 |
commit | 197bbc5f17ac7f11cb07aefb935182eae1bc5ada (patch) | |
tree | 26694a4e3bdf11b42e8308e5e7e4c45dada5a60b /vcl | |
parent | be1474f51aa9a38b80f853b569493b20c01e6078 (diff) |
pdf: Only add role map when alias isn't the same as structure tag
It is not allowed in PDF/UA to override a structure tag. This
also true when you have an alias with the same name as a structure
tage. For example to define a "H1" that is an alias for the "H1"
structure tage. This is probably done in LO "just in case".
With this change, if the structure tag and alias are the same, it
will not get added to the role map, but this only happens when
PDF/UA is enabled.
Change-Id: Iff37c31ad31e5a01d7847ddb57f9b0e4c7b247db
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86212
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 16 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.hxx | 2 |
2 files changed, 15 insertions, 3 deletions
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index c5078143874c..31daa05a73bd 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -10080,6 +10080,16 @@ const char* PDFWriterImpl::getStructureTag( PDFWriter::StructElement eType ) return it != aTagStrings.end() ? it->second : "Div"; } +void PDFWriterImpl::addRoleMap(OString aAlias, PDFWriter::StructElement eType) +{ + OString aTag = getStructureTag(eType); + // For PDF/UA it's not allowed to map an alias with the same name. + // Not sure if this allowed, necessary or recommended otherwise, so + // only enable filtering when PDF/UA is enabled. + if (!m_bIsPDF_UA || aAlias != aTag) + m_aRoleMap[aAlias] = aTag; +} + void PDFWriterImpl::beginStructureElementMCSeq() { if( m_bEmitStructure && @@ -10209,7 +10219,7 @@ sal_Int32 PDFWriterImpl::beginStructureElement( PDFWriter::StructElement eType, appendName( rAlias, aNameBuf ); OString aAliasName( aNameBuf.makeStringAndClear() ); rEle.m_aAlias = aAliasName; - m_aRoleMap[ aAliasName ] = getStructureTag( eType ); + addRoleMap(aAliasName, eType); } if (g_bDebugDisableCompression) @@ -10331,8 +10341,8 @@ void PDFWriterImpl::addInternalStructureContainer( PDFStructureElement& rEle ) std::list< sal_Int32 > aNewChildren; // add Div in RoleMap, in case no one else did (TODO: is it needed? Is it dangerous?) - OString aAliasName( "Div" ); - m_aRoleMap[ aAliasName ] = getStructureTag( PDFWriter::Division ); + OString aAliasName("Div"); + addRoleMap(aAliasName, PDFWriter::Division); while( rEle.m_aKids.size() > ncMaxPDFArraySize ) { diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx index cccd38fe161f..82afd47e850e 100644 --- a/vcl/source/gdi/pdfwriter_impl.hxx +++ b/vcl/source/gdi/pdfwriter_impl.hxx @@ -759,6 +759,8 @@ i12626 /* the buffer where the data are encrypted, dynamically allocated */ std::vector<sal_uInt8> m_vEncryptionBuffer; + void addRoleMap(OString aAlias, PDFWriter::StructElement eType); + /* this function implements part of the PDF spec algorithm 3.1 in encryption, the rest (the actual encryption) is in PDFWriterImpl::writeBuffer */ void checkAndEnableStreamEncryption( sal_Int32 nObject ); |