public ITextFontMetricsFactory( final ITextFontRegistry registry ) { this.baseFontSupport = new BaseFontSupport( registry ); }
public void close() { this.baseFontSupport.close(); }
/** * Returns a BaseFont which can be used to represent the given AWT Font * * @param font the font to be converted * @return a BaseFont which has similar properties to the provided Font */ public BaseFont awtToPdf( final Font font ) { // this has to be defined in the element, an has to set as a default... final boolean embed = isEmbedFonts(); final String encoding = getDefaultEncoding(); try { return createBaseFont( font.getName(), font.isBold(), font.isItalic(), encoding, embed ); } catch ( Exception e ) { // unable to handle font creation exceptions properly, all we can // do is throw a runtime exception and hope the best .. throw new BaseFontCreateException( "Unable to create font: " + font, e ); } }
encoding = getDefaultEncoding(); final BaseFontRecord fontRecord = createFontFromTTF ( registryFontRecord, bold, italic, encoding, stringEncoding, embeddedOverride ); if ( fontRecord != null ) { BaseFontRecord fontRecord = getFromCache( fontName, encoding, embedded ); if ( fontRecord != null ) { return fontRecord; fontRecord = getFromCache( fontName, stringEncoding, embedded ); if ( fontRecord != null ) { return fontRecord; if ( f != null ) { fontRecord = new BaseFontRecord( fontName, false, embedded, f, bold, italic ); putToCache( fontRecord ); return fontRecord; BaseFontRecord fontRecord = getFromCache( BaseFont.HELVETICA, stringEncoding, embedded ); if ( fontRecord != null ) { putToCache( new BaseFontRecordKey( fontKey, encoding, embedded ), fontRecord ); return fontRecord; fontRecord = new BaseFontRecord ( BaseFont.HELVETICA, false, embedded, f, bold, italic ); putToCache( fontRecord ); putToCache( new BaseFontRecordKey( fontKey, encoding, embedded ), fontRecord );
final BaseFontRecord fontRec = getFromCache( filename, encoding, embedded ); if ( fontRec != null ) { return fontRec; putToCache( record ); return record;
/** * Stores a record in the cache. * * @param record the record. */ private void putToCache( final BaseFontRecord record ) { final BaseFontRecordKey key = record.createKey(); putToCache( key, record ); }
/** * Creates a iText-BaseFont for an font. If no basefont could be created, an BaseFontCreateException is thrown. * * @param logicalName the name of the font (null not permitted). * @param bold a flag indicating whether the font is rendered as bold font. * @param italic a flag indicating whether the font is rendered as italic or cursive font. * @param encoding the encoding. * @param embedded a flag indicating whether to embed the font glyphs in the generated documents. * @return the base font record. * @throws BaseFontCreateException if there was a problem setting the font for the target. */ public BaseFont createBaseFont( final String logicalName, final boolean bold, final boolean italic, final String encoding, final boolean embedded ) throws BaseFontCreateException { return createBaseFontRecord( logicalName, bold, italic, encoding, embedded ).getBaseFont(); }
/** * Returns an AWT Font which can be used to represent the given BaseFont * * @param font the font to be converted * @param size the desired point size of the resulting font * @return a Font which has similar properties to the provided BaseFont */ public Font pdfToAwt( final BaseFont font, final int size ) { final String logicalName = getFontName( font ); boolean bold = false; boolean italic = false; if ( StringUtils.endsWithIgnoreCase( logicalName, "bolditalic" ) ) { bold = true; italic = true; } else if ( StringUtils.endsWithIgnoreCase( logicalName, "bold" ) ) { bold = true; } else if ( StringUtils.endsWithIgnoreCase( logicalName, "italic" ) ) { italic = true; } int style = Font.PLAIN; if ( bold ) { style |= Font.BOLD; } if ( italic ) { style |= Font.ITALIC; } return new Font( logicalName, style, size ); }
final BaseFont baseFont = baseFontSupport.createBaseFont ( fontName, bold, italic, context.getEncoding(), context.isEmbedded() );