[Podofo-svn] SF.net SVN: podofo:[1771] podofo/trunk/src/doc/PdfPainter.cpp
A PDF parsing, modification and creation library.
Brought to you by:
domseichter
|
From: <dom...@us...> - 2016-07-03 15:49:24
|
Revision: 1771
http://sourceforge.net/p/podofo/code/1771
Author: domseichter
Date: 2016-07-03 15:49:21 +0000 (Sun, 03 Jul 2016)
Log Message:
-----------
FIXED: Patch by Ulrich Arnold to support more than 128 different glyphs per font in DrawGlyph
Modified Paths:
--------------
podofo/trunk/src/doc/PdfPainter.cpp
Modified: podofo/trunk/src/doc/PdfPainter.cpp
===================================================================
--- podofo/trunk/src/doc/PdfPainter.cpp 2016-07-03 15:02:00 UTC (rev 1770)
+++ podofo/trunk/src/doc/PdfPainter.cpp 2016-07-03 15:49:21 UTC (rev 1771)
@@ -1142,79 +1142,95 @@
PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
}
- // search for a copy of this font to enter difference-encoding, create a new one if not found
- PdfFont* pGlyphFont = pDocument->CreateDuplicateFontType1( m_pFont, "Glyph1" );
+ PdfFont* pGlyphFont = NULL;
+ int code = 32;
- // select identical sizes
- pGlyphFont->SetFontSize( m_pFont->GetFontSize() );
- pGlyphFont->SetFontCharSpace( m_pFont->GetFontCharSpace() );
- pGlyphFont->SetFontScale( m_pFont->GetFontScale() );
- PdfObject* pGlyphFontObj = pGlyphFont->GetObject();
+ for ( int num = 1; num <= 999; num++ )
+ {
+ // search for a copy of this font to enter difference-encoding, create a new one if not found
+ char suffix[256];
+ sprintf( suffix, "Glyph%i", num );
+ pGlyphFont = pDocument->CreateDuplicateFontType1( m_pFont, suffix );
- // get width of glyph
- int width = static_cast<int>(pGlyphFont->GetFontMetrics()->GetGlyphWidth( pszGlyphname ) );
+ PdfObject* pGlyphFontObj = pGlyphFont->GetObject();
+ PdfObject* pEncoding = pGlyphFontObj->GetDictionary().GetKey( "Encoding" );
- // change encoding to difference-encoding and adapt width
- PdfObject* pEncoding = pGlyphFontObj->GetDictionary().GetKey( "Encoding" );
-
- int code = 32;
- if ( pEncoding == NULL || pEncoding->IsReference() == false )
- {
// first time: create difference-encoding as reference, enter glyph
- pEncoding = pDocument->GetObjects().CreateObject( "Encoding" );
-
- code++;
-
- PdfArray diffs;
- diffs.push_back( PdfVariant( static_cast<pdf_int64>( code ) ) );
- diffs.push_back( PdfName( pszGlyphname ) );
-
- pEncoding->GetDictionary().AddKey( "Differences", diffs );
- pGlyphFontObj->GetDictionary().AddKey("Encoding", pEncoding->Reference() );
+ if ( pEncoding == NULL || pEncoding->IsReference() == false )
+ {
- // clear Widths-array and enter width of this glyph
- PdfObject* pWidthObj = pGlyphFontObj->GetIndirectKey( "Widths" );
- PdfArray & rWidthArr = pWidthObj->GetArray();
- for ( unsigned int i = 0; i < rWidthArr.size(); i++ )
- {
- rWidthArr[i] = PdfVariant( static_cast<pdf_int64>( 0 ) );
- }
- rWidthArr[code] = PdfVariant( static_cast<pdf_int64>( width ) );
- }
- else
- {
- // search glyph in existing Encoding/Difference, create if not found
- pEncoding = pDocument->GetObjects().GetObject( pEncoding->GetReference() );
-
- PODOFO_ASSERT( pEncoding != NULL ); // paranoia
+ // get width of glyph to enter in difference-encoding
+ int width = static_cast<int>(pGlyphFont->GetFontMetrics()->GetGlyphWidth( pszGlyphname ) );
+ pEncoding = pDocument->GetObjects().CreateObject( "Encoding" );
+
+ code++;
+
+ PdfArray diffs;
+ diffs.push_back( PdfVariant( static_cast<pdf_int64>( code ) ) );
+ diffs.push_back( PdfName( pszGlyphname ) );
+
+ pEncoding->GetDictionary().AddKey( "Differences", diffs );
+ pGlyphFontObj->GetDictionary().AddKey("Encoding", pEncoding->Reference() );
- PdfArray diffs;
- diffs = pEncoding->GetDictionary().GetKey( "Differences" )->GetArray();
+ // clear Widths-array and enter width of this glyph
+ PdfObject* pWidthObj = pGlyphFontObj->GetIndirectKey( "Widths" );
+ PdfArray & rWidthArr = pWidthObj->GetArray();
+ for ( unsigned int i = 0; i < rWidthArr.size(); i++ )
+ {
+ rWidthArr[i] = PdfVariant( static_cast<pdf_int64>( 0 ) );
+ }
+ rWidthArr[code] = PdfVariant( static_cast<pdf_int64>( width ) );
- bool foundIt = false;
+ break;
+ }
- TCIVariantList it = diffs.begin();
- while( it != diffs.end() )
+
+ // Existing font, search for glyph in existing difference-encoding
{
- if( (*it).GetDataType() == ePdfDataType_Name )
+ pEncoding = pDocument->GetObjects().GetObject( pEncoding->GetReference() );
+
+ PODOFO_ASSERT( pEncoding != NULL ); // paranoia
+
+ PdfArray diffs;
+ diffs = pEncoding->GetDictionary().GetKey( "Differences" )->GetArray();
+
+ bool foundIt = false;
+
+ TCIVariantList it = diffs.begin();
+ while( it != diffs.end() )
{
- code++;
- if ( (*it).GetName().GetName() == pszGlyphname )
+ if( (*it).GetDataType() == ePdfDataType_Name )
{
- foundIt = true;
- break;
+ code++;
+ if ( (*it).GetName().GetName() == pszGlyphname )
+ {
+ foundIt = true;
+ break;
+ }
}
+
+ ++it;
}
-
- ++it;
+ if ( foundIt ) // glyph fount, use it
+ break;
}
- // TODO: if code exceeds 255, create a new font-copy and start again with code 33
- PODOFO_ASSERT( code <= 255 );
+ // limit to codes <= 127, make new duplicate font if more
+ if ( code+1 >= 127 )
+ {
+ code = 32;
+ continue;
+ }
- if ( foundIt == false )
+ // add glyph to existing difference-encoding
{
+ // get width of glyph to enter in difference-encoding
+ int width = static_cast<int>(pGlyphFont->GetFontMetrics()->GetGlyphWidth( pszGlyphname ) );
+
code++;
+
+ PdfArray diffs;
+ diffs = pEncoding->GetDictionary().GetKey( "Differences" )->GetArray();
diffs.push_back( PdfName( pszGlyphname ) );
pEncoding->GetDictionary().AddKey( "Differences", diffs );
@@ -1223,10 +1239,21 @@
PdfObject* pWidthObj = pGlyphFontObj->GetIndirectKey( "Widths" );
PdfArray & rWidthArr = pWidthObj->GetArray();
rWidthArr[code] = PdfVariant( static_cast<pdf_int64>( width ) );
+
+ break;
}
}
- if( m_pFont->IsSubsetting() ) {
+ // select identical sizes
+ pGlyphFont->SetFontSize( m_pFont->GetFontSize() );
+ pGlyphFont->SetFontCharSpace( m_pFont->GetFontCharSpace() );
+ pGlyphFont->SetFontScale( m_pFont->GetFontScale() );
+ PdfObject* pGlyphFontObj = pGlyphFont->GetObject();
+
+ PODOFO_ASSERT( code > 32 && code <= 127 );
+
+ if( m_pFont->IsSubsetting() )
+ {
// mark glyph as used in basefont (needed for subsetting)
m_pFont->AddUsedGlyphname( pszGlyphname );
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|