Type1Font t1 = null;
boolean fontIsDamaged = false;
if (fd != null)
{
// a Type1 font may contain a Type1C font
PDStream fontFile3 = fd.getFontFile3();
if (fontFile3 != null)
{
throw new IllegalArgumentException("Use PDType1CFont for FontFile3");
}
// or it may contain a PFB
PDStream fontFile = fd.getFontFile();
if (fontFile != null)
{
try
{
COSStream stream = fontFile.getStream();
int length1 = stream.getInt(COSName.LENGTH1);
int length2 = stream.getInt(COSName.LENGTH2);
// repair Length1 if necessary
byte[] bytes = fontFile.getByteArray();
length1 = repairLength1(bytes, length1);
// the PFB embedded as two segments back-to-back
byte[] segment1 = Arrays.copyOfRange(bytes, 0, length1);
byte[] segment2 = Arrays.copyOfRange(bytes, length1, length1 + length2);