summaryrefslogtreecommitdiff
path: root/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx')
-rw-r--r--sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx53
1 files changed, 47 insertions, 6 deletions
diff --git a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx
index 1fa9ff32b530..5361330fd697 100644
--- a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx
+++ b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx
@@ -37,6 +37,8 @@
#include <math.h>
#include <vector>
+#include <boost/shared_array.hpp>
+
#if defined __SUNPRO_CC
#pragma disable_warn
#elif defined _MSC_VER
@@ -78,10 +80,44 @@ inline double normalize( double val )
return fabs(val) < 0.0000001 ? 0.0 : val;
}
-const char* escapeLineFeed( const char* pStr )
+namespace
+{
+
+/** Escapes line-ending characters (\n and \r) in input string.
+ */
+boost::shared_array<char> lcl_escapeLineFeeds(const char* const i_pStr)
{
- // TODO(Q3): Escape linefeeds
- return pStr;
+ size_t nLength(strlen(i_pStr));
+ char* pBuffer = new char[2*nLength+1];
+
+ const char* pRead = i_pStr;
+ char* pWrite = pBuffer;
+ while( nLength-- )
+ {
+ if( *pRead == '\r' )
+ {
+ *pWrite++ = '\\';
+ *pWrite++ = 'r';
+ }
+ else if( *pRead == '\n' )
+ {
+ *pWrite++ = '\\';
+ *pWrite++ = 'n';
+ }
+ else if( *pRead == '\\' )
+ {
+ *pWrite++ = '\\';
+ *pWrite++ = '\\';
+ }
+ else
+ *pWrite++ = *pRead;
+ pRead++;
+ }
+ *pWrite++ = 0;
+
+ return boost::shared_array<char>(pBuffer);
+}
+
}
/// for the temp char buffer the header gets snprintfed in
@@ -464,12 +500,14 @@ void PDFOutDev::processLink(Link* link, Catalog*)
{
const char* pURI = static_cast<LinkURI*>(pAction)->getURI()->getCString();
+ boost::shared_array<char> pEsc( lcl_escapeLineFeeds(pURI) );
+
printf( "drawLink %f %f %f %f %s\n",
normalize(x1),
normalize(y1),
normalize(x2),
normalize(y2),
- escapeLineFeed(pURI) );
+ pEsc.get() );
}
}
@@ -634,6 +672,8 @@ void PDFOutDev::updateFont(GfxState *state)
printf( " %lld", fontID );
aFont = it->second;
+
+ boost::shared_array<char> pEsc( lcl_escapeLineFeeds(aFont.familyName.getCString()) );
printf( " %d %d %d %d %f %d %s",
aFont.isEmbedded,
aFont.isBold,
@@ -641,7 +681,7 @@ void PDFOutDev::updateFont(GfxState *state)
aFont.isUnderline,
normalize(state->getTransformedFontSize()),
nEmbedSize,
- escapeLineFeed(aFont.familyName.getCString()) );
+ pEsc.get() );
}
printf( "\n" );
@@ -765,7 +805,8 @@ void PDFOutDev::drawChar(GfxState *state, double x, double y,
for( int i=0; i<uLen; ++i )
{
buf[ m_pUtf8Map->mapUnicode(u[i], buf, sizeof(buf)-1) ] = 0;
- printf( "%s", escapeLineFeed(buf) );
+ boost::shared_array<char> pEsc( lcl_escapeLineFeeds(buf) );
+ printf( "%s", pEsc.get() );
}
printf( "\n" );