if(cache.containsKey(reference))
return (Font)cache.get(reference);
}
PdfDictionary fontDictionary = (PdfDictionary)reference.getDataObject();
PdfName fontType = (PdfName)fontDictionary.get(PdfName.Subtype);
if(fontType == null)
throw new RuntimeException("Font type undefined (reference: " + reference + ")");
if(fontType.equals(PdfName.Type1)) // Type 1.
{
if(!fontDictionary.containsKey(PdfName.FontDescriptor)) // Standard Type 1.
return new StandardType1Font(reference);
else // Custom Type 1.
{
PdfDictionary fontDescriptor = (PdfDictionary)fontDictionary.resolve(PdfName.FontDescriptor);
if(fontDescriptor.containsKey(PdfName.FontFile3)
&& ((PdfName)((PdfStream)fontDescriptor.resolve(PdfName.FontFile3)).getHeader().resolve(PdfName.Subtype)).equals(PdfName.OpenType)) // OpenFont/CFF.
throw new NotImplementedException();
else // Non-OpenFont Type 1.
return new Type1Font(reference);
}
}
else if(fontType.equals(PdfName.TrueType)) // TrueType.
return new TrueTypeFont(reference);
else if(fontType.equals(PdfName.Type0)) // OpenFont.
{
PdfDictionary cidFontDictionary = (PdfDictionary)((PdfArray)fontDictionary.resolve(PdfName.DescendantFonts)).resolve(0);
PdfName cidFontType = (PdfName)cidFontDictionary.get(PdfName.Subtype);
if(cidFontType.equals(PdfName.CIDFontType0)) // OpenFont/CFF.
return new Type0Font(reference);
else if(cidFontType.equals(PdfName.CIDFontType2)) // OpenFont/TrueType.
return new Type2Font(reference);
else
throw new NotImplementedException("Type 0 subtype " + cidFontType + " not supported yet.");
}
else if(fontType.equals(PdfName.Type3)) // Type 3.