summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-12-16 16:44:51 +0900
committerMiklos Vajna <vmiklos@collabora.com>2024-12-17 11:44:43 +0100
commit4b071f537aa75c37137dd8f6674c57cbd3a86c0b (patch)
tree93cef79f31cdea7d8bd9b3dc2bd0ebf5ba8d7c38
parent30f83f2dff9f80db0b4a467fb30f9a9b2531fa3c (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>
-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 60b25f1c43c9..7ebc10e6ae58 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -149,57 +149,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 )
{
@@ -2413,7 +2362,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" );
@@ -2472,7 +2421,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" );
@@ -2585,7 +2534,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["
@@ -2900,7 +2849,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,
@@ -4745,7 +4694,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
@@ -4764,7 +4713,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
@@ -4833,7 +4782,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:
@@ -5177,7 +5126,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);
@@ -6194,7 +6143,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");
@@ -11012,7 +10961,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);
@@ -11803,7 +11752,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
@@ -11822,7 +11771,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: */