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 class
PdfBoxFontResolver.FilePDFontSupplier
Loads a Type0 font on demandstatic class
PdfBoxFontResolver.FontDescription
AFontDescription
can exist in multiple states.static class
PdfBoxFontResolver.FontGroup
-
Field Summary
Fields Modifier and Type Field Description private AbstractFontStore
_builtinFonts
private org.apache.pdfbox.pdmodel.PDDocument
_doc
private FallbackFontStore
_finalFallbackFonts
private FallbackFontStore
_preBuiltinFallbackFonts
private 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 void
addFont(FSSupplier<java.io.InputStream> supplier, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset)
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.void
addFont(PDFontSupplier supplier, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset)
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.void
addFont(java.io.File fontFile, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset)
Deprecated.void
addFont(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.void
addFontCollection(FSSupplier<java.io.InputStream> supplier, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset)
void
addFontCollection(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.void
addFontCollection(java.io.File file, java.lang.String fontFamilyNameOverride, java.lang.Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset)
void
addFontCollection(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.void
addFontDirectory(java.lang.String dir, boolean embedded)
Deprecated.void
addFontDirectory(java.lang.String dir, boolean embedded, PdfBoxFontResolver.FontGroup fontGroup)
Add all fonts in the given directoryvoid
close()
Free all font resources (i.e.private FallbackFontStore
getFallbackFontStore(PdfBoxFontResolver.FontGroup fontGroup)
void
importFontFaces(java.util.List<FontFaceRule> fontFaces)
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)
FSFont
resolveFont(SharedContext renderingContext, FontSpecification spec)
private FSFont
resolveFont(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:
resolveFont
in 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.IOException
Deprecated.- Throws:
java.io.IOException
-
addFontDirectory
public void addFontDirectory(java.lang.String dir, boolean embedded, PdfBoxFontResolver.FontGroup fontGroup) throws java.io.IOException
Add 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.IOException
Adds 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.IOException
Add 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.IOException
Add 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.IOException
Deprecated.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)
-
-