List of usage examples for com.itextpdf.awt FontMapper FontMapper
FontMapper
From source file:org.ganttproject.impex.htmlpdf.fonts.TTFontCache.java
License:Open Source License
public FontMapper getFontMapper(final FontSubstitutionModel substitutions, final String charset) { return new FontMapper() { private Map<Font, BaseFont> myFontCache = new HashMap<Font, BaseFont>(); @Override/* w w w . j ava 2 s . c o m*/ public BaseFont awtToPdf(Font awtFont) { if (myFontCache.containsKey(awtFont)) { return myFontCache.get(awtFont); } String family = awtFont.getFamily().toLowerCase(); Function<String, BaseFont> f = myMap_Family_ItextFont.get(family); if (f != null) { BaseFont result = f.apply(charset); myFontCache.put(awtFont, result); return result; } family = family.replace(' ', '_'); if (myProperties.containsKey("font." + family)) { family = String.valueOf(myProperties.get("font." + family)); } FontSubstitution substitution = substitutions.getSubstitution(family); if (substitution != null) { family = substitution.getSubstitutionFamily(); } f = myMap_Family_ItextFont.get(family); if (f != null) { BaseFont result = f.apply(charset); myFontCache.put(awtFont, result); return result; } BaseFont result = getFallbackFont(charset); if (result == null) { GPLogger.log(new RuntimeException("Font with family=" + awtFont.getFamily() + " not found. Also tried family=" + family + " and fallback font")); } return result; } @Override public Font pdfToAwt(BaseFont itextFont, int size) { return null; } }; }