String retval = null;
if( isTypeFont() )
{
if( cmap == null )
{
COSBase toUnicode = font.getDictionaryObject( COSName.TO_UNICODE );
if( toUnicode instanceof COSStream )
{
hasToUnicode = true;
parseCmap( null, ((COSStream)toUnicode).getUnfilteredStream(), null );
}
else
{
COSBase encoding = getEncodingObject();
if( encoding instanceof COSStream )
{
COSStream encodingStream = (COSStream)encoding;
parseCmap( null, encodingStream.getUnfilteredStream(), null );
}
else if( isType0Font() && encoding instanceof COSName )
{
COSName encodingName = (COSName)encoding;
cmap = cmapObjects.get( encodingName );
if( cmap == null )
{
String cmapName = encodingName.getName();
if (encodingName.getName().equals( COSName.IDENTITY_H.getName() ))
{
COSArray descendantFontArray =
(COSArray)font.getDictionaryObject( COSName.DESCENDANT_FONTS );
if (descendantFontArray != null)
{
COSDictionary descendantFontDictionary =
(COSDictionary)descendantFontArray.getObject( 0 );
PDFont descendentFont = PDFontFactory.createFont( descendantFontDictionary );
COSDictionary cidsysteminfo =
(COSDictionary)descendentFont.font.getDictionaryObject(COSName.CIDSYSTEMINFO);
if (cidsysteminfo != null)
{
String ordering = cidsysteminfo.getString(COSName.ORDERING);
String registry = cidsysteminfo.getString(COSName.REGISTRY);
cmapName = registry + "-" + ordering+"-UCS2";
}
}
}
else
{
cmapName = CMapSubstitution.substituteCMap( cmapName );
}
String resourceRoot = "org/apache/pdfbox/resources/cmap/";
String resourceName = resourceRoot + cmapName;
parseCmap( resourceRoot, ResourceLoader.loadResource( resourceName ), encodingName );
if( cmap == null && !encodingName.getName().equals( COSName.IDENTITY_H.getName() ) )
{
throw new IOException( "Error: Could not find predefined " +
"CMAP file for '" + encodingName.getName() + "'" );
}
}
}
else if( encoding instanceof COSName ||
encoding instanceof COSDictionary )
{
Encoding currentFontEncoding = getEncoding();
if( currentFontEncoding != null )
{
retval = currentFontEncoding.getCharacter( getCodeFromArray( c, offset, length ) );
}
}
else
{
COSDictionary fontDescriptor =
(COSDictionary)font.getDictionaryObject( COSName.FONT_DESC );
if( isTrueTypeFont() && fontDescriptor != null &&
(fontDescriptor.getDictionaryObject( COSName.FONT_FILE )!= null ||
fontDescriptor.getDictionaryObject( COSName.FONT_FILE2 ) != null ||
fontDescriptor.getDictionaryObject( COSName.FONT_FILE3 ) != null ) )
{
//If we are using an embedded font then there is not much we can do besides
//return the same character codes.
//retval = new String( c,offset, length );
retval = getStringFromArray( c, offset, length );
}
else
{
//this case will be handled below after checking the cmap
}
}
}
}
}
if( retval == null && cmap != null )
{
retval = cmap.lookup( c, offset, length );
}
COSBase encodingCOS = getEncodingObject();
// The converter isn't needed if an unicode mapping is already given by the font dictionary
if ( !hasToUnicode && encodingCOS instanceof COSName )
{
EncodingConverter converter = EncodingConversionManager.getConverter(((COSName)encodingCOS).getName());
if ( converter != null )