(i.e. when ToUnicode stream is available).
*/
Map<Integer,Integer> unicodeGlyphIndexes = new Hashtable<Integer,Integer>();
for(Map.Entry<Integer,Integer> glyphIndexEntry : glyphIndexes.entrySet())
{
Integer code = codes.get(new ByteArray(new byte[]{(byte)(int)glyphIndexEntry.getKey()}));
if(code == null)
continue;
unicodeGlyphIndexes.put(code,glyphIndexEntry.getValue());
}
glyphIndexes = unicodeGlyphIndexes;
}
}
PdfDataObject encodingObject = getBaseDataObject().resolve(PdfName.Encoding);
EnumSet<FlagsEnum> flags = getFlags();
if(flags.contains(FlagsEnum.Symbolic)
|| (!flags.contains(FlagsEnum.Nonsymbolic) && encodingObject == null)) // Symbolic.
{
symbolic = true;
if(glyphIndexes == null)
{
/*
NOTE: In case no font file is available, we have to synthesize its metrics
from existing entries.
*/
glyphIndexes = new Hashtable<Integer,Integer>();
PdfArray glyphWidthObjects = (PdfArray)getBaseDataObject().resolve(PdfName.Widths);
if(glyphWidthObjects != null)
{
int code = ((PdfInteger)getBaseDataObject().get(PdfName.FirstChar)).getRawValue();
for(PdfDirectObject glyphWidthObject : glyphWidthObjects)
{
if(((PdfInteger)glyphWidthObject).getRawValue() > 0)
{glyphIndexes.put(code,code);}
code++;
}
}
}
if(codes == null)
{
Map<ByteArray,Integer> codes = new HashMap<ByteArray,Integer>();
for(Map.Entry<Integer,Integer> glyphIndexEntry : glyphIndexes.entrySet())
{
if(glyphIndexEntry.getValue() > 0)
{
int glyphCharCode = glyphIndexEntry.getKey();
byte[] charCode = new byte[]{(byte)glyphCharCode};
codes.put(new ByteArray(charCode),glyphCharCode);
}
}
this.codes = new BiMap<ByteArray,Integer>(codes);
}
}
else // Nonsymbolic.
{
symbolic = false;
if(codes == null)
{
Map<ByteArray,Integer> codes;
if(encodingObject == null) // Default encoding.
{codes = Encoding.get(PdfName.StandardEncoding).getCodes();}
else if(encodingObject instanceof PdfName) // Predefined encoding.
{codes = Encoding.get((PdfName)encodingObject).getCodes();}
else // Custom encoding.
{
PdfDictionary encodingDictionary = (PdfDictionary)encodingObject;
// 1. Base encoding.
PdfName baseEncodingName = (PdfName)encodingDictionary.get(PdfName.BaseEncoding);
if(baseEncodingName == null) // Default base encoding.
{codes = Encoding.get(PdfName.StandardEncoding).getCodes();}
else // Predefined base encoding.
{codes = Encoding.get(baseEncodingName).getCodes();}
// 2. Differences.
loadEncodingDifferences(encodingDictionary, codes);
}
this.codes = new BiMap<ByteArray,Integer>(codes);
}
if(glyphIndexes == null)
{
/*
NOTE: In case no font file is available, we have to synthesize its metrics
from existing entries.
*/
glyphIndexes = new Hashtable<Integer,Integer>();
PdfArray glyphWidthObjects = (PdfArray)getBaseDataObject().resolve(PdfName.Widths);
if(glyphWidthObjects != null)
{
ByteArray charCode = new ByteArray(
new byte[]
{(byte)(int)((PdfInteger)getBaseDataObject().get(PdfName.FirstChar)).getRawValue()}
);
for(PdfDirectObject glyphWidthObject : glyphWidthObjects)
{