private PDFont getFontAndUpdateResources( List 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") ), null );
streamParser.parse();
tokens = streamParser.getTokens();
}
int setFontIndex = tokens.indexOf( PDFOperator.getOperator( "Tf" ));
COSName cosFontName = (COSName)tokens.get( setFontIndex-2 );
String fontName = cosFontName.getName();
retval = (PDFont)streamResources.getFonts().get( fontName );
if( retval == null )
{
retval = (PDFont)formResources.getFonts().get( fontName );
streamResources.getFonts().put( fontName, retval );
}
}
return retval;
}