private PDFont getFontAndUpdateResources(List<Object> tokens,
PDAppearanceStream appearanceStream) throws IOException
{
PDFont retval = null;
PDResources streamResources = appearanceStream.getResources();
PDResources formResources = acroForm.getDefaultResources();
if (formResources != null)
{
if (streamResources == null)
{
streamResources = new PDResources();
appearanceStream.setResources(streamResources);
}
COSString da = getDefaultAppearance();
if (da != null)
{
String data = da.getString();
PDFStreamParser streamParser = new PDFStreamParser(new ByteArrayInputStream(
data.getBytes("ISO-8859-1")));
streamParser.parse();
tokens = streamParser.getTokens();
}
int setFontIndex = tokens.indexOf(Operator.getOperator("Tf"));
COSName cosFontName = (COSName) tokens.get(setFontIndex - 2);
retval = streamResources.getFont(cosFontName);
if (retval == null)
{
retval = formResources.getFont(cosFontName);
streamResources.put(cosFontName, retval);
}
}
return retval;
}