Package com.openhtmltopdf.pdfboxout
Class PdfBoxFontResolver
- java.lang.Object
-
- com.openhtmltopdf.pdfboxout.PdfBoxFontResolver
-
- All Implemented Interfaces:
FontResolver
public class PdfBoxFontResolver extends java.lang.Object implements FontResolver
This class handles all font resolving for the PDF generation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classPdfBoxFontResolver.FilePDFontSupplierLoads a Type0 font on demandstatic classPdfBoxFontResolver.FontDescriptionAFontDescriptioncan exist in multiple states.static classPdfBoxFontResolver.FontGroup
-
Field Summary
Fields Modifier and Type Field Description private AbstractFontStore_builtinFontsprivate org.apache.pdfbox.pdmodel.PDDocument_docprivate FallbackFontStore_finalFallbackFontsprivate FallbackFontStore_preBuiltinFallbackFontsprivate MainFontStore_suppliedFonts
-
Constructor Summary
Constructors Constructor Description PdfBoxFontResolver(SharedContext sharedContext, org.apache.pdfbox.pdmodel.PDDocument doc, FSCacheEx<java.lang.String,FSCacheValue> pdfMetricsCache, PdfRendererBuilder.PdfAConformance pdfAConformance, boolean pdfUaConform)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddFont(FSSupplier<java.io.InputStream> supplier, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset)voidaddFont(FSSupplier<java.io.InputStream> supplier, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup)Adds a font specified by an input stream (truetype) to a specific font group.voidaddFont(PDFontSupplier supplier, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset)voidaddFont(PDFontSupplier supplier, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup)Add a font specified by a PDFontSupplier to a specific font group.voidaddFont(java.io.File fontFile, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset)Deprecated.voidaddFont(java.io.File fontFile, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup)Add a font file (truetype) to a specific font group.voidaddFontCollection(FSSupplier<java.io.InputStream> supplier, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset)voidaddFontCollection(FSSupplier<java.io.InputStream> supplier, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup)Adds a font collection (.ttc in an input stream) to a specific font group.voidaddFontCollection(java.io.File file, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset)voidaddFontCollection(java.io.File file, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup)Adds a font collection (.ttc file) to a specific group.voidaddFontDirectory(java.lang.String dir, boolean embedded)Deprecated.voidaddFontDirectory(java.lang.String dir, boolean embedded, PdfBoxFontResolver.FontGroup fontGroup)Add all fonts in the given directoryvoidclose()Free all font resources (i.e.private FallbackFontStoregetFallbackFontStore(PdfBoxFontResolver.FontGroup fontGroup)voidimportFontFaces(java.util.List<FontFaceRule> fontFaces)private voidresolveFamilyFont(SharedContext ctx, java.lang.String[] families, float size, IdentValue weight, IdentValue style, IdentValue variant, java.util.List<PdfBoxFontResolver.FontDescription> fonts, AbstractFontStore store)FSFontresolveFont(SharedContext renderingContext, FontSpecification spec)private FSFontresolveFont(SharedContext ctx, java.lang.String[] families, float size, IdentValue weight, IdentValue style, IdentValue variant)
-
-
-
Field Detail
-
_doc
private final org.apache.pdfbox.pdmodel.PDDocument _doc
-
_suppliedFonts
private final MainFontStore _suppliedFonts
-
_preBuiltinFallbackFonts
private final FallbackFontStore _preBuiltinFallbackFonts
-
_builtinFonts
private final AbstractFontStore _builtinFonts
-
_finalFallbackFonts
private final FallbackFontStore _finalFallbackFonts
-
-
Constructor Detail
-
PdfBoxFontResolver
public PdfBoxFontResolver(SharedContext sharedContext, org.apache.pdfbox.pdmodel.PDDocument doc, FSCacheEx<java.lang.String,FSCacheValue> pdfMetricsCache, PdfRendererBuilder.PdfAConformance pdfAConformance, boolean pdfUaConform)
-
-
Method Detail
-
resolveFont
public FSFont resolveFont(SharedContext renderingContext, FontSpecification spec)
- Specified by:
resolveFontin interfaceFontResolver
-
close
public void close()
Free all font resources (i.e. open files), the document should already be closed.
-
importFontFaces
public void importFontFaces(java.util.List<FontFaceRule> fontFaces)
-
addFontDirectory
@Deprecated public void addFontDirectory(java.lang.String dir, boolean embedded) throws java.io.IOExceptionDeprecated.- Throws:
java.io.IOException
-
addFontDirectory
public void addFontDirectory(java.lang.String dir, boolean embedded, PdfBoxFontResolver.FontGroup fontGroup) throws java.io.IOExceptionAdd all fonts in the given directory- Throws:
java.io.IOException
-
addFontCollection
public void addFontCollection(FSSupplier<java.io.InputStream> supplier, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup) throws java.io.IOException
Adds a font collection (.ttc in an input stream) to a specific font group.- Throws:
java.io.IOException
-
addFontCollection
@Deprecated public void addFontCollection(FSSupplier<java.io.InputStream> supplier, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset) throws java.io.IOException
Add fonts using a .ttc TrueTypeCollection- Throws:
java.io.IOException
-
addFontCollection
public void addFontCollection(java.io.File file, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup) throws java.io.IOExceptionAdds a font collection (.ttc file) to a specific group.- Throws:
java.io.IOException
-
addFontCollection
@Deprecated public void addFontCollection(java.io.File file, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset) throws java.io.IOExceptionAdd fonts using a .ttc TrueTypeCollection- Throws:
java.io.IOException
-
addFont
public void addFont(java.io.File fontFile, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup) throws java.io.IOExceptionAdd a font file (truetype) to a specific font group.- Throws:
java.io.IOException
-
getFallbackFontStore
private FallbackFontStore getFallbackFontStore(PdfBoxFontResolver.FontGroup fontGroup)
-
addFont
@Deprecated public void addFont(java.io.File fontFile, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset) throws java.io.IOExceptionDeprecated.Add a font using a existing file. If the file is a TrueTypeCollection, it will be handled as such.- Throws:
java.io.IOException
-
addFont
public void addFont(FSSupplier<java.io.InputStream> supplier, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup)
Adds a font specified by an input stream (truetype) to a specific font group.
-
addFont
@Deprecated public void addFont(FSSupplier<java.io.InputStream> supplier, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset)
Add a font using a InputStream. The given file must be a TrueType Font (.ttf). If you know the underlying stream is a .ttc file you should useaddFontCollection(FSSupplier, String, Integer, IdentValue, boolean)
-
addFont
public void addFont(PDFontSupplier supplier, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup)
Add a font specified by a PDFontSupplier to a specific font group.
-
addFont
@Deprecated public void addFont(PDFontSupplier supplier, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset)
Add a font using a PDFontSupplier. Use this method if you need special rules for font-loading (like using a font-cache) and subclass thePDFontSupplier.
-
resolveFont
private FSFont resolveFont(SharedContext ctx, java.lang.String[] families, float size, IdentValue weight, IdentValue style, IdentValue variant)
-
resolveFamilyFont
private void resolveFamilyFont(SharedContext ctx, java.lang.String[] families, float size, IdentValue weight, IdentValue style, IdentValue variant, java.util.List<PdfBoxFontResolver.FontDescription> fonts, AbstractFontStore store)
-
-