[Podofo-svn] SF.net SVN: podofo:[1773] podofo/trunk/src/doc/PdfPainter.cpp
A PDF parsing, modification and creation library.
Brought to you by:
domseichter
|
From: <aj...@us...> - 2016-07-16 18:10:23
|
Revision: 1773
http://sourceforge.net/p/podofo/code/1773
Author: aja_
Date: 2016-07-16 18:10:20 +0000 (Sat, 16 Jul 2016)
Log Message:
-----------
ADDED: Patch by Jaseem Ali K T: PdfPainter::DrawMultiLineText() improvements
Modified Paths:
--------------
podofo/trunk/src/doc/PdfPainter.cpp
Modified: podofo/trunk/src/doc/PdfPainter.cpp
===================================================================
--- podofo/trunk/src/doc/PdfPainter.cpp 2016-07-16 18:08:16 UTC (rev 1772)
+++ podofo/trunk/src/doc/PdfPainter.cpp 2016-07-16 18:10:20 UTC (rev 1773)
@@ -947,7 +947,7 @@
PdfString sString = this->ExpandTabs( rsText, rsText.GetCharacterLength() );
std::vector<PdfString> vecLines = GetMultiLineTextAsLines(dWidth, sString);
-
+ double dLineGap = m_pFont->GetFontMetrics()->GetLineSpacing() - m_pFont->GetFontMetrics()->GetAscent() + m_pFont->GetFontMetrics()->GetDescent();
// Do vertical alignment
switch( eVertical )
{
@@ -962,13 +962,14 @@
break;
}
+ dY -= (m_pFont->GetFontMetrics()->GetAscent() + dLineGap / (2.0));
+
std::vector<PdfString>::const_iterator it = vecLines.begin();
while( it != vecLines.end() )
{
if( (*it).GetCharacterLength() )
- this->DrawTextAligned( dX, dY - m_pFont->GetFontMetrics()->GetAscent(), dWidth, *it, eAlignment );
+ this->DrawTextAligned( dX, dY, dWidth, *it, eAlignment );
dY -= m_pFont->GetFontMetrics()->GetLineSpacing();
-
++it;
}
this->Restore();
@@ -1014,7 +1015,7 @@
{
vecLines.push_back( PdfString( pszLineBegin, pszCurrentCharacter - pszLineBegin ) );
- pszLineBegin = pszCurrentCharacter+1;// skip the line feed
+ pszLineBegin = pszCurrentCharacter + 1;// skip the line feed
startOfWord = true;
dCurWidthOfLine = 0.0;
}
@@ -1024,7 +1025,19 @@
{
// The previous word does not fit in the current line.
// -> Move it to the next one.
- vecLines.push_back( PdfString( pszLineBegin, pszStartOfCurrentWord - pszLineBegin ) );
+ if( pszStartOfCurrentWord > pszLineBegin )
+ {
+ vecLines.push_back( PdfString( pszLineBegin, pszStartOfCurrentWord - pszLineBegin ) );
+ }
+ else
+ {
+ vecLines.push_back( PdfString( pszLineBegin, pszCurrentCharacter - pszLineBegin ) );
+ // Skip all spaces at the end of the line
+ while (IsSpaceChar(*(pszCurrentCharacter + 1)))
+ pszCurrentCharacter++;
+
+ pszStartOfCurrentWord = pszCurrentCharacter + 1;
+ }
pszLineBegin = pszStartOfCurrentWord;
if (!startOfWord)
@@ -1059,10 +1072,20 @@
{
// This word takes up the whole line.
// Put as much as possible on this line.
- vecLines.push_back( PdfString( pszLineBegin, pszCurrentCharacter - pszLineBegin ) );
- pszLineBegin = pszCurrentCharacter;
- pszStartOfCurrentWord = pszCurrentCharacter;
- dCurWidthOfLine = m_pFont->GetFontMetrics()->UnicodeCharWidth( SwapCharBytesIfRequired( *pszCurrentCharacter ) );
+ if (pszLineBegin == pszCurrentCharacter)
+ {
+ vecLines.push_back( PdfString( pszCurrentCharacter, 1 ) );
+ pszLineBegin = pszCurrentCharacter + 1;
+ pszStartOfCurrentWord = pszCurrentCharacter + 1;
+ dCurWidthOfLine = 0;
+ }
+ else
+ {
+ vecLines.push_back(PdfString(pszLineBegin, pszCurrentCharacter - pszLineBegin));
+ pszLineBegin = pszCurrentCharacter;
+ pszStartOfCurrentWord = pszCurrentCharacter;
+ dCurWidthOfLine = m_pFont->GetFontMetrics()->UnicodeCharWidth( SwapCharBytesIfRequired( *pszCurrentCharacter ) );
+ }
}
else
{
@@ -1070,7 +1093,7 @@
// -> Move it to the next one.
vecLines.push_back( PdfString( pszLineBegin, pszStartOfCurrentWord - pszLineBegin ) );
pszLineBegin = pszStartOfCurrentWord;
- dCurWidthOfLine = m_pFont->GetFontMetrics()->StringWidth( pszStartOfCurrentWord, (pszCurrentCharacter-pszStartOfCurrentWord) + 1 );
+ dCurWidthOfLine = m_pFont->GetFontMetrics()->StringWidth( pszStartOfCurrentWord, (pszCurrentCharacter - pszStartOfCurrentWord) + 1);
}
}
else
@@ -1083,7 +1106,7 @@
if( (pszCurrentCharacter - pszLineBegin) > 0 )
{
- if( dCurWidthOfLine > dWidth )
+ if( dCurWidthOfLine > dWidth && pszStartOfCurrentWord > pszLineBegin )
{
// The previous word does not fit in the current line.
// -> Move it to the next one.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|