@Override public void createFont(final PdfObject pdfObject,final String fontID,final boolean renderPage,final ObjectStore objectStore,final Map<String,PdfJavaGlyphs> substitutedFonts) throws Exception {
  fontTypes=StandardFonts.TRUETYPE;
  this.fontsLoaded=substitutedFonts;
  init(fontID,renderPage);
  final PdfObject pdfFontDescriptor=pdfObject.getDictionary(PdfDictionary.FontDescriptor);
  setBoundsAndMatrix(pdfFontDescriptor);
  setName(pdfObject);
  setEncoding(pdfObject,pdfFontDescriptor);
  if (renderPage) {
    if (pdfFontDescriptor != null && substituteFont == null) {
      byte[] stream=null;
      PdfObject FontFile2=pdfFontDescriptor.getDictionary(PdfDictionary.FontFile2);
      if (FontFile2 == null) {
        FontFile2=pdfFontDescriptor.getDictionary(PdfDictionary.FontFile);
        if (FontFile2 == null) {
          FontFile2=pdfFontDescriptor.getDictionary(PdfDictionary.FontFile3);
        }
      }
      if (FontFile2 != null) {
        stream=currentPdfFile.readStream(FontFile2,true,true,false,false,false,FontFile2.getCacheName(currentPdfFile.getObjectReader()));
      }
      if (stream != null) {
        readEmbeddedFont(stream,null,hasEncoding);
      }
    }
    if (!isFontEmbedded && substituteFont != null) {
      subfontAlreadyLoaded=!isCIDFont && fontsLoaded.containsKey(substituteFont + '_' + glyphs.getBaseFontName());
      final File fontFile;
      FontData fontData=null;
      int objSize=0;
      if (!subfontAlreadyLoaded) {
        fontFile=new File(substituteFont);
        objSize=(int)fontFile.length();
      }
      if (FontData.maxSizeAllowedInMemory >= 0 && objSize > FontData.maxSizeAllowedInMemory) {
        if (!subfontAlreadyLoaded) {
          fontData=new FontData(substituteFont);
        }
        readEmbeddedFont(null,fontData,false);
      }
 else       if (subfontAlreadyLoaded) {
        readEmbeddedFont(null,null,false);
      }
 else {
        final BufferedInputStream from;
        InputStream jarFile=null;
        try {
          if (substituteFont.startsWith("jar:") || substituteFont.startsWith("http:")) {
            jarFile=loader.getResourceAsStream(substituteFont);
          }
 else {
            jarFile=loader.getResourceAsStream("file:///" + substituteFont);
          }
        }
 catch (        final Exception e) {
          LogWriter.writeLog("1.Unable to open " + substituteFont + ' '+ e);
        }
catch (        final Error err) {
          LogWriter.writeLog("1.Unable to open " + substituteFont + ' '+ err);
        }
        if (jarFile == null) {
          from=new BufferedInputStream(new FileInputStream(substituteFont));
        }
 else {
          from=new BufferedInputStream(jarFile);
        }
        final FastByteArrayOutputStream to=new FastByteArrayOutputStream();
        final byte[] buffer=new byte[65535];
        int bytes_read;
        while ((bytes_read=from.read(buffer)) != -1) {
          to.write(buffer,0,bytes_read);
        }
        from.close();
        readEmbeddedFont(to.toByteArray(),null,false);
      }
      isFontSubstituted=true;
    }
  }
  readWidths(pdfObject,true);
  if (renderPage) {
    setFont(glyphs.fontName,1);
  }
}

@ Override public void createFont ( final PdfObject pdfObject , final String fontID , final boolean renderPage , final ObjectStore objectStore , final Map < String , PdfJavaGlyphs > substitutedFonts ) throws Exception { fontTypes = StandardFonts . TRUETYPE ; this . fontsLoaded = substitutedFonts ; init ( fontID , renderPage ) ; final PdfObject pdfFontDescriptor = pdfObject . getDictionary ( PdfDictionary . FontDescriptor ) ; setBoundsAndMatrix ( pdfFontDescriptor ) ; setName ( pdfObject ) ; setEncoding ( pdfObject , pdfFontDescriptor ) ; if ( renderPage ) { if ( pdfFontDescriptor != null && substituteFont == null ) { byte [ ] stream = null ; PdfObject FontFile2 = pdfFontDescriptor . getDictionary ( PdfDictionary . FontFile2 ) ; if ( FontFile2 == null ) { FontFile2 = pdfFontDescriptor . getDictionary ( PdfDictionary . FontFile ) ; if ( FontFile2 == null ) { FontFile2 = pdfFontDescriptor . getDictionary ( PdfDictionary . FontFile3 ) ; } } if ( FontFile2 != null ) { stream = currentPdfFile . readStream ( FontFile2 , true , true , false , false , false , FontFile2 . getCacheName ( currentPdfFile . getObjectReader ( ) ) ) ; } if ( stream != null ) { readEmbeddedFont ( stream , null , hasEncoding ) ; } } if ( ! isFontEmbedded && substituteFont != null ) { subfontAlreadyLoaded = ! isCIDFont && fontsLoaded . containsKey ( substituteFont + '_' + glyphs . getBaseFontName ( ) ) ; final File fontFile ; FontData fontData = null ; int objSize = 0 ; if ( ! subfontAlreadyLoaded ) { fontFile = new File ( substituteFont ) ; objSize = ( int ) fontFile . length ( ) ; } if ( FontData . maxSizeAllowedInMemory >= 0 && objSize > FontData . maxSizeAllowedInMemory ) { if ( ! subfontAlreadyLoaded ) { fontData = new FontData ( substituteFont ) ; } readEmbeddedFont ( null , fontData , false ) ; } else if ( subfontAlreadyLoaded ) { readEmbeddedFont ( null , null , false ) ; } else { final BufferedInputStream from ; InputStream jarFile = null ; try { if ( substituteFont . startsWith ( "jar:" ) || substituteFont . startsWith ( "http:" ) ) { jarFile = loader . getResourceAsStream ( substituteFont ) ; } else { jarFile = loader . getResourceAsStream ( "file:///" + substituteFont ) ; } } catch ( final Exception e ) { LogWriter . writeLog ( "1.Unable to open " + substituteFont + ' ' + e ) ; } catch ( final Error err ) { LogWriter . writeLog ( "1.Unable to open " + substituteFont + ' ' + err ) ; } if ( jarFile == null ) { from = new BufferedInputStream ( new FileInputStream ( substituteFont ) ) ; } else { from = new BufferedInputStream ( jarFile ) ; } final FastByteArrayOutputStream to = new FastByteArrayOutputStream ( ) ; final byte [ ] buffer = new byte [ 65535 ] ; int bytes_read ; while ( ( bytes_read = from . read ( buffer ) ) != - 1 ) { to . write ( buffer , 0 , bytes_read ) ; } from . close ( ) ; readEmbeddedFont ( to . toByteArray ( ) , null , false ) ; } isFontSubstituted = true ; } } readWidths ( pdfObject , true ) ; if ( renderPage ) { setFont ( glyphs . fontName , 1 ) ; } }
read in a font and its details from the pdf file
