Package org.xhtmlrenderer.pdf
Class ITextFontResolver
java.lang.Object
org.xhtmlrenderer.pdf.ITextFontResolver
- All Implemented Interfaces:
FontResolver
- Direct Known Subclasses:
CJKFontResolver
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<String, FontDescription> private final Map<String, FontFamily> private static final Stringprivate static final org.slf4j.Loggerprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddCourier(Map<String, FontFamily> result) voidvoidAdd the font with encoding "CP1252" (don't ask me why :) )voidaddFont(String path, @Nullable String fontFamilyNameOverride, String encoding, boolean embedded, @Nullable String pathToPFB) voidvoidvoidaddFontDirectory(String dir, boolean embedded) Add all fonts from given directory with encoding "CP1252" (don't ask me why :) )voidaddFontDirectory(String dir, String encoding, boolean embedded) Add all fonts from given directory (all files with extension ".otf" and ".ttf")private voidaddFontFaceFont(@Nullable String fontFamilyNameOverride, @Nullable IdentValue fontWeightOverride, @Nullable IdentValue fontStyleOverride, String uri, String encoding, boolean embedded, byte[] ttfAfm, byte @Nullable [] pfb) private voidaddHelvetica(Map<String, FontFamily> result) private voidaddSymbol(Map<String, FontFamily> result) private voidaddTimes(Map<String, FontFamily> result) private voidaddZapfDingbats(Map<String, FontFamily> result) static intconvertWeightToInt(IdentValue weight) private com.lowagie.text.pdf.BaseFontcreateFont(String name) private com.lowagie.text.pdf.BaseFontcreateFont(String name, String encoding, boolean embedded) private File[]filesWithExtensions(File f, String... extensions) voidvoidprivate static FontDescriptionfontDescription(@Nullable IdentValue fontWeightOverride, @Nullable IdentValue fontStyleOverride, String uri, byte[] ttfAfm, com.lowagie.text.pdf.BaseFont font) private booleanfontSupported(String uri) getDistinctFontFamilyNames(String path, String encoding, boolean embedded) Utility method which uses iText libraries to determine the family name(s) for the font at the given path.private FontFamilygetFontFamily(String fontFamilyName) private static Collection<String> getFontFamilyNames(com.lowagie.text.pdf.BaseFont font, @Nullable String fontFamilyNameOverride) getFonts()private voidimportFontFace(FontFaceRule rule, UserAgentCallback userAgentCallback) voidimportFontFaces(List<FontFaceRule> fontFaces, UserAgentCallback userAgentCallback) protected Map<String, FontFamily> (package private) StringnormalizeFontFamily(String fontFamily) private byte[]private @Nullable FSFontresolveFont(String @Nullable [] families, float size, IdentValue weight, IdentValue style) private @Nullable FSFontresolveFont(String fontFamily, float size, IdentValue weight, IdentValue style) @Nullable FSFontresolveFont(SharedContext renderingContext, FontSpecification spec) private StringstripQuotes(String text) strip off the leading and trailing quote if they are there
-
Field Details
-
log
private static final org.slf4j.Logger log -
OTF
- See Also:
-
TTF
- See Also:
-
AFM
- See Also:
-
PFM
- See Also:
-
PFB
- See Also:
-
PFA
- See Also:
-
TTC
- See Also:
-
TTC_COMMA
- See Also:
-
_fontFamilies
-
_fontCache
-
-
Constructor Details
-
ITextFontResolver
public ITextFontResolver()
-
-
Method Details
-
getFonts
-
getDistinctFontFamilyNames
public static Set<String> getDistinctFontFamilyNames(String path, String encoding, boolean embedded) Utility method which uses iText libraries to determine the family name(s) for the font at the given path. The iText APIs seem to indicate there can be more than one name, but this method will return a set of them. Use a name from this list when referencing the font in CSS for PDF output. Note that family names as reported by iText may vary from those reported by the AWT Font class, e.g. "Arial Unicode MS" for iText and "ArialUnicodeMS" for AWT.- Parameters:
path- local path to the font fileencoding- same as what you would use foraddFont(String, String, boolean)embedded- same as what you would use foraddFont(String, String, boolean)- Returns:
- set of all family names for the font file, as reported by iText libraries
-
flushCache
public void flushCache()- Specified by:
flushCachein interfaceFontResolver
-
flushFontFaceFonts
public void flushFontFaceFonts() -
importFontFaces
-
importFontFace
-
addFontDirectory
public void addFontDirectory(String dir, boolean embedded) throws com.lowagie.text.DocumentException, IOException Add all fonts from given directory with encoding "CP1252" (don't ask me why :) )- Throws:
com.lowagie.text.DocumentExceptionIOException
-
addFontDirectory
public void addFontDirectory(String dir, String encoding, boolean embedded) throws com.lowagie.text.DocumentException, IOException Add all fonts from given directory (all files with extension ".otf" and ".ttf")- Throws:
com.lowagie.text.DocumentExceptionIOException
-
filesWithExtensions
-
addFont
public void addFont(String path, boolean embedded) throws com.lowagie.text.DocumentException, IOException Add the font with encoding "CP1252" (don't ask me why :) )- Throws:
com.lowagie.text.DocumentExceptionIOException
-
addFont
public void addFont(String path, String encoding, boolean embedded) throws com.lowagie.text.DocumentException, IOException - Throws:
com.lowagie.text.DocumentExceptionIOException
-
addFont
public void addFont(String path, String encoding, boolean embedded, @Nullable String pathToPFB) throws com.lowagie.text.DocumentException, IOException - Throws:
com.lowagie.text.DocumentExceptionIOException
-
addFont
public void addFont(String path, @Nullable String fontFamilyNameOverride, String encoding, boolean embedded, @Nullable String pathToPFB) throws com.lowagie.text.DocumentException, IOException - Throws:
com.lowagie.text.DocumentExceptionIOException
-
addFont
-
getFontFamilyNames
private static Collection<String> getFontFamilyNames(com.lowagie.text.pdf.BaseFont font, @Nullable String fontFamilyNameOverride) -
fontSupported
-
addFontFaceFont
private void addFontFaceFont(@Nullable String fontFamilyNameOverride, @Nullable IdentValue fontWeightOverride, @Nullable IdentValue fontStyleOverride, String uri, String encoding, boolean embedded, byte[] ttfAfm, byte @Nullable [] pfb) throws com.lowagie.text.DocumentException, IOException - Parameters:
ttfAfm- the font as a byte array, possibly null- Throws:
com.lowagie.text.DocumentExceptionIOException
-
fontDescription
private static FontDescription fontDescription(@Nullable IdentValue fontWeightOverride, @Nullable IdentValue fontStyleOverride, String uri, byte[] ttfAfm, com.lowagie.text.pdf.BaseFont font) -
readFile
- Throws:
IOException
-
getFontFamily
-
resolveFont
private @Nullable FSFont resolveFont(String @Nullable [] families, float size, IdentValue weight, IdentValue style) -
normalizeFontFamily
-
stripQuotes
strip off the leading and trailing quote if they are there -
resolveFont
private @Nullable FSFont resolveFont(String fontFamily, float size, IdentValue weight, IdentValue style) -
convertWeightToInt
-
loadFonts
-
createFont
-
createFont
-
addCourier
-
addTimes
-
addHelvetica
-
addSymbol
-
addZapfDingbats
-