summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-12-16 16:44:51 +0900
committerTomaž Vajngerl <quikee@gmail.com>2024-12-26 06:08:29 +0100
commit81b5ae3a5464189771b6953ae162847caa5a18dc (patch)
tree6d637c6d12801f329cda00451e84072223a8c2dc
parent5719a09bcbffa7ad0e1bedb19f4046aadfc38ce4 (diff)
pdf: move appendName implementations into COSWriter
Change-Id: I5c6b5bf685479643b32363159e047621473ad65a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178592 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178773 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--vcl/inc/pdf/COSWriter.hxx2
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx75
-rw-r--r--vcl/source/pdf/COSWriter.cxx47
3 files changed, 61 insertions, 63 deletions
diff --git a/vcl/inc/pdf/COSWriter.hxx b/vcl/inc/pdf/COSWriter.hxx
index d63a2198a2e7..277805e720fa 100644
--- a/vcl/inc/pdf/COSWriter.hxx
+++ b/vcl/inc/pdf/COSWriter.hxx
@@ -151,6 +151,8 @@ public:
}
static void appendUnicodeTextString(const OUString& rString, OStringBuffer& rBuffer);
+ static void appendName(std::u16string_view rString, OStringBuffer& rBuffer);
+ static void appendName(const char* pString, OStringBuffer& rBuffer);
};
}
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index cee972efb2fe..387edb5e2594 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -150,57 +150,6 @@ void appendHexArray(sal_uInt8* pArray, size_t nSize, OStringBuffer& rBuffer)
appendHex(pArray[i], rBuffer);
}
-void appendName( std::u16string_view rStr, OStringBuffer& rBuffer )
-{
-// FIXME i59651 add a check for max length of 127 chars? Per PDF spec 1.4, appendix C.1
-// I guess than when reading the #xx sequence it will count for a single character.
- OString aStr( OUStringToOString( rStr, RTL_TEXTENCODING_UTF8 ) );
- int nLen = aStr.getLength();
- for( int i = 0; i < nLen; i++ )
- {
- /* #i16920# PDF recommendation: output UTF8, any byte
- * outside the interval [33(=ASCII'!');126(=ASCII'~')]
- * should be escaped hexadecimal
- * for the sake of ghostscript which also reads PDF
- * but has a narrower acceptance rate we only pass
- * alphanumerics and '-' literally.
- */
- if( (aStr[i] >= 'A' && aStr[i] <= 'Z' ) ||
- (aStr[i] >= 'a' && aStr[i] <= 'z' ) ||
- (aStr[i] >= '0' && aStr[i] <= '9' ) ||
- aStr[i] == '-' )
- {
- rBuffer.append( aStr[i] );
- }
- else
- {
- rBuffer.append( '#' );
- appendHex( static_cast<sal_Int8>(aStr[i]), rBuffer );
- }
- }
-}
-
-void appendName( const char* pStr, OStringBuffer& rBuffer )
-{
- // FIXME i59651 see above
- while( pStr && *pStr )
- {
- if( (*pStr >= 'A' && *pStr <= 'Z' ) ||
- (*pStr >= 'a' && *pStr <= 'z' ) ||
- (*pStr >= '0' && *pStr <= '9' ) ||
- *pStr == '-' )
- {
- rBuffer.append( *pStr );
- }
- else
- {
- rBuffer.append( '#' );
- appendHex( static_cast<sal_Int8>(*pStr), rBuffer );
- }
- pStr++;
- }
-}
-
//used only to emit encoded passwords
void appendLiteralString( const char* pStr, sal_Int32 nLength, OStringBuffer& rBuffer )
{
@@ -2437,7 +2386,7 @@ sal_Int32 PDFWriterImpl::emitBuildinFont(const pdf::BuildinFontFace* pFD, sal_In
OString::number(nFontObject)
+ " 0 obj\n"
"<</Type/Font/Subtype/Type1/BaseFont/" );
- appendName( rBuildinFont.m_pPSName, aLine );
+ COSWriter::appendName( rBuildinFont.m_pPSName, aLine );
aLine.append( "\n" );
if( rBuildinFont.m_eCharSet == RTL_TEXTENCODING_MS_1252 )
aLine.append( "/Encoding/WinAnsiEncoding\n" );
@@ -2497,7 +2446,7 @@ std::map< sal_Int32, sal_Int32 > PDFWriterImpl::emitSystemFont( const vcl::font:
+ " 0 obj\n"
"<</Type/Font/Subtype/TrueType"
"/BaseFont/" );
- appendName( aInfo.m_aPSName, aLine );
+ COSWriter::appendName( aInfo.m_aPSName, aLine );
aLine.append( "\n" );
if (!pFace->IsMicrosoftSymbolEncoded())
aLine.append( "/Encoding/WinAnsiEncoding\n" );
@@ -2610,7 +2559,7 @@ bool PDFWriterImpl::emitType3Font(const vcl::font::PhysicalFontFace* pFace,
OString::number(nFontObject)
+ " 0 obj\n"
"<</Type/Font/Subtype/Type3/Name/");
- appendName(aSubsetInfo.m_aPSName, aLine);
+ COSWriter::appendName(aSubsetInfo.m_aPSName, aLine);
aLine.append(
"\n/FontBBox["
@@ -2926,7 +2875,7 @@ static void appendSubsetName( int nSubsetID, std::u16string_view rPSName, OStrin
}
rBuffer.append( '+' );
}
- appendName( rPSName, rBuffer );
+ COSWriter::appendName( rPSName, rBuffer );
}
sal_Int32 PDFWriterImpl::createToUnicodeCMap( sal_uInt8 const * pEncoding,
@@ -4794,7 +4743,7 @@ bool PDFWriterImpl::emitWidgetAnnotations()
SvMemoryStream* pStream = stream_it->second;
app_it->second.erase( stream_it );
OStringBuffer aBuf( rWidget.m_aOnValue.getLength()*2 );
- appendName( rWidget.m_aOnValue, aBuf );
+ COSWriter::appendName( rWidget.m_aOnValue, aBuf );
(app_it->second)[ aBuf.makeStringAndClear() ] = pStream;
}
else
@@ -4813,7 +4762,7 @@ bool PDFWriterImpl::emitWidgetAnnotations()
SvMemoryStream* pStream = stream_it->second;
app_it->second.erase( stream_it );
OStringBuffer aBuf( rWidget.m_aOffValue.getLength()*2 );
- appendName( rWidget.m_aOffValue, aBuf );
+ COSWriter::appendName( rWidget.m_aOffValue, aBuf );
(app_it->second)[ aBuf.makeStringAndClear() ] = pStream;
}
else
@@ -4882,7 +4831,7 @@ bool PDFWriterImpl::emitWidgetAnnotations()
if( rWidget.m_aValue.isEmpty() )
aValue.append( "Off" );
else
- appendName( rWidget.m_aValue, aValue );
+ COSWriter::appendName( rWidget.m_aValue, aValue );
}
[[fallthrough]];
case PDFWriter::PushButton:
@@ -5226,7 +5175,7 @@ bool PDFWriterImpl::emitEmbeddedFiles()
if (!rEmbeddedFile.m_aSubType.isEmpty())
{
aLine.append("/Subtype /");
- appendName(rEmbeddedFile.m_aSubType, aLine);
+ COSWriter::appendName(rEmbeddedFile.m_aSubType, aLine);
}
aLine.append(" /Length ");
appendObjectReference(nSizeObject, aLine);
@@ -6250,7 +6199,7 @@ bool PDFWriterImpl::emitTrailer()
for (auto const& rAttachedFile : m_aDocumentAttachedFiles)
{
aLine.append( "/" );
- appendName(rAttachedFile.maMimeType, aLine);
+ COSWriter::appendName(rAttachedFile.maMimeType, aLine);
aLine.append(" ");
appendObjectReference(rAttachedFile.mnEmbeddedFileObjectId, aLine);
aLine.append("\n");
@@ -11095,7 +11044,7 @@ void PDFWriterImpl::initStructureElement(sal_Int32 const id,
if( !rAlias.empty() && eType != PDFWriter::NonStructElement )
{
OStringBuffer aNameBuf( rAlias.size() );
- appendName( rAlias, aNameBuf );
+ COSWriter::appendName( rAlias, aNameBuf );
OString aAliasName( aNameBuf.makeStringAndClear() );
rEle.m_aAlias = aAliasName;
addRoleMap(aAliasName, eType);
@@ -11890,7 +11839,7 @@ void PDFWriterImpl::ensureUniqueRadioOnValues()
SvMemoryStream* pStream = stream_it->second;
app_it->second.erase( stream_it );
OStringBuffer aBuf( rKid.m_aOnValue.getLength()*2 );
- appendName( rKid.m_aOnValue, aBuf );
+ COSWriter::appendName( rKid.m_aOnValue, aBuf );
(app_it->second)[ aBuf.makeStringAndClear() ] = pStream;
}
else
@@ -11909,7 +11858,7 @@ void PDFWriterImpl::ensureUniqueRadioOnValues()
SvMemoryStream* pStream = stream_it->second;
app_it->second.erase( stream_it );
OStringBuffer aBuf( rKid.m_aOffValue.getLength()*2 );
- appendName( rKid.m_aOffValue, aBuf );
+ COSWriter::appendName( rKid.m_aOffValue, aBuf );
(app_it->second)[ aBuf.makeStringAndClear() ] = pStream;
}
else
diff --git a/vcl/source/pdf/COSWriter.cxx b/vcl/source/pdf/COSWriter.cxx
index 100da2e243aa..064bec546b3e 100644
--- a/vcl/source/pdf/COSWriter.cxx
+++ b/vcl/source/pdf/COSWriter.cxx
@@ -142,6 +142,53 @@ void COSWriter::appendUnicodeTextString(const OUString& rString, OStringBuffer&
}
}
+void COSWriter::appendName(std::u16string_view rStr, OStringBuffer& rBuffer)
+{
+ // FIXME i59651 add a check for max length of 127 chars? Per PDF spec 1.4, appendix C.1
+ // I guess than when reading the #xx sequence it will count for a single character.
+ OString aStr(OUStringToOString(rStr, RTL_TEXTENCODING_UTF8));
+ int nLen = aStr.getLength();
+ for (int i = 0; i < nLen; i++)
+ {
+ /* #i16920# PDF recommendation: output UTF8, any byte
+ * outside the interval [33(=ASCII'!');126(=ASCII'~')]
+ * should be escaped hexadecimal
+ * for the sake of ghostscript which also reads PDF
+ * but has a narrower acceptance rate we only pass
+ * alphanumerics and '-' literally.
+ */
+ if ((aStr[i] >= 'A' && aStr[i] <= 'Z') || (aStr[i] >= 'a' && aStr[i] <= 'z')
+ || (aStr[i] >= '0' && aStr[i] <= '9') || aStr[i] == '-')
+ {
+ rBuffer.append(aStr[i]);
+ }
+ else
+ {
+ rBuffer.append('#');
+ appendHex(static_cast<sal_Int8>(aStr[i]), rBuffer);
+ }
+ }
+}
+
+void COSWriter::appendName(const char* pStr, OStringBuffer& rBuffer)
+{
+ // FIXME i59651 see above
+ while (pStr && *pStr)
+ {
+ if ((*pStr >= 'A' && *pStr <= 'Z') || (*pStr >= 'a' && *pStr <= 'z')
+ || (*pStr >= '0' && *pStr <= '9') || *pStr == '-')
+ {
+ rBuffer.append(*pStr);
+ }
+ else
+ {
+ rBuffer.append('#');
+ appendHex(static_cast<sal_Int8>(*pStr), rBuffer);
+ }
+ pStr++;
+ }
+}
+
} //end vcl::pdf
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */