Top Description Inners Fields Constructors Methods
com.openhtmltopdf.pdfboxout

public Class PdfBoxFontResolver

extends Object
implements FontResolver
Class Inheritance
All Implemented Interfaces
com.openhtmltopdf.extend.FontResolver
Imports
com.openhtmltopdf.css.constants.CSSName, .IdentValue, com.openhtmltopdf.css.sheet.FontFaceRule, com.openhtmltopdf.css.style.CalculatedStyle, .FSDerivedValue, com.openhtmltopdf.css.value.FontSpecification, com.openhtmltopdf.extend.FSCacheEx, .FSCacheValue, .FSSupplier, .FontResolver, com.openhtmltopdf.layout.SharedContext, com.openhtmltopdf.outputdevice.helper.MinimalFontDescription, com.openhtmltopdf.pdfboxout.PdfRendererBuilder.PdfAConformance, com.openhtmltopdf.pdfboxout.fontstore.AbstractFontStore, .FallbackFontStore, .FontUtil, .MainFontStore, com.openhtmltopdf.render.FSFont, com.openhtmltopdf.util.LogMessageId, .XRLog, org.apache.fontbox.ttf.TrueTypeCollection, org.apache.pdfbox.pdmodel.PDDocument, org.apache.pdfbox.pdmodel.font.PDFont, .PDFontDescriptor, .PDType0Font, java.io.File, .FilenameFilter, .IOException, .InputStream, java.util.*, java.util.logging.Level

This class handles all font resolving for the PDF generation.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
PdfBoxFontResolver.FilePDFontSupplier

Loads a Type0 font on demand

public static class
PdfBoxFontResolver.FontDescription

A FontDescription can exist in multiple states.

public static enum

Field Summary

Modifier and TypeField and Description
private final AbstractFontStore
private final PDDocument
private final FallbackFontStore
private final FallbackFontStore
private final MainFontStore

Constructor Summary

AccessConstructor and Description
public
PdfBoxFontResolver(SharedContext sharedContext, PDDocument doc, FSCacheEx<String, FSCacheValue> pdfMetricsCache, PdfRendererBuilder.PdfAConformance pdfAConformance, boolean pdfUaConform)

Method Summary

Modifier and TypeMethod and Description
public void
addFont(File fontFile, String fontFamilyNameOverride, Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup)

Add a font file (truetype) to a specific font group.

public void
addFont(File fontFile, final String fontFamilyNameOverride, final Integer fontWeightOverride, final IdentValue fontStyleOverride, final boolean subset)

Add a font using a existing file.

public void
addFont(FSSupplier<InputStream> supplier, String fontFamilyNameOverride, Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup)

Adds a font specified by an input stream (truetype) to a specific font group.

public void
addFont(FSSupplier<InputStream> supplier, String fontFamilyNameOverride, Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset)

Add a font using a InputStream.

public void
addFont(PDFontSupplier supplier, String fontFamilyNameOverride, Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup)

Add a font specified by a PDFontSupplier to a specific font group.

public void
addFont(PDFontSupplier supplier, String fontFamilyNameOverride, Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset)

Add a font using a PDFontSupplier.

public void
addFontCollection(FSSupplier<InputStream> supplier, String fontFamilyNameOverride, Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup)

Adds a font collection (.ttc in an input stream) to a specific font group.

public void
addFontCollection(FSSupplier<InputStream> supplier, final String fontFamilyNameOverride, final Integer fontWeightOverride, final IdentValue fontStyleOverride, final boolean subset)

Add fonts using a .ttc TrueTypeCollection

public void
addFontCollection(File file, String fontFamilyNameOverride, Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup)

Adds a font collection (.ttc file) to a specific group.

public void
addFontCollection(File file, final String fontFamilyNameOverride, final Integer fontWeightOverride, final IdentValue fontStyleOverride, final boolean subset)

Add fonts using a .ttc TrueTypeCollection

public void
public void
addFontDirectory(String dir, boolean embedded, PdfBoxFontResolver.FontGroup fontGroup)

Add all fonts in the given directory

public void
close()

Free all font resources (i.e. open files), the document should already be closed.

private FallbackFontStore
public void
private void
public FSFont
private FSFont
resolveFont(SharedContext ctx, String[] families, float size, IdentValue weight, IdentValue style, IdentValue variant)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_builtinFontsback to summary
private final AbstractFontStore _builtinFonts
_docback to summary
private final PDDocument _doc
_finalFallbackFontsback to summary
private final FallbackFontStore _finalFallbackFonts
_preBuiltinFallbackFontsback to summary
private final FallbackFontStore _preBuiltinFallbackFonts
_suppliedFontsback to summary
private final MainFontStore _suppliedFonts

Constructor Detail

PdfBoxFontResolverback to summary
public PdfBoxFontResolver(SharedContext sharedContext, PDDocument doc, FSCacheEx<String, FSCacheValue> pdfMetricsCache, PdfRendererBuilder.PdfAConformance pdfAConformance, boolean pdfUaConform)

Method Detail

addFontback to summary
public void addFont(File fontFile, String fontFamilyNameOverride, Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup) throws IOException

Add a font file (truetype) to a specific font group.

addFontback to summary
public void addFont(File fontFile, final String fontFamilyNameOverride, final Integer fontWeightOverride, final IdentValue fontStyleOverride, final boolean subset) throws IOException

Add a font using a existing file. If the file is a TrueTypeCollection, it will be handled as such.

Annotations
@Deprecated
addFontback to summary
public void addFont(FSSupplier<InputStream> supplier, String fontFamilyNameOverride, Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup)

Adds a font specified by an input stream (truetype) to a specific font group.

addFontback to summary
public void addFont(FSSupplier<InputStream> supplier, String fontFamilyNameOverride, 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 use addFontCollection(FSSupplier, String, Integer, IdentValue, boolean)

Annotations
@Deprecated
addFontback to summary
public void addFont(PDFontSupplier supplier, String fontFamilyNameOverride, Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup)

Add a font specified by a PDFontSupplier to a specific font group.

addFontback to summary
public void addFont(PDFontSupplier supplier, String fontFamilyNameOverride, 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 the PDFontSupplier.

Annotations
@Deprecated
addFontCollectionback to summary
public void addFontCollection(FSSupplier<InputStream> supplier, String fontFamilyNameOverride, Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup) throws IOException

Adds a font collection (.ttc in an input stream) to a specific font group.

addFontCollectionback to summary
public void addFontCollection(FSSupplier<InputStream> supplier, final String fontFamilyNameOverride, final Integer fontWeightOverride, final IdentValue fontStyleOverride, final boolean subset) throws IOException

Add fonts using a .ttc TrueTypeCollection

Annotations
@Deprecated
addFontCollectionback to summary
public void addFontCollection(File file, String fontFamilyNameOverride, Integer fontWeightOverride, IdentValue fontStyleOverride, boolean subset, PdfBoxFontResolver.FontGroup fontGroup) throws IOException

Adds a font collection (.ttc file) to a specific group.

addFontCollectionback to summary
public void addFontCollection(File file, final String fontFamilyNameOverride, final Integer fontWeightOverride, final IdentValue fontStyleOverride, final boolean subset) throws IOException

Add fonts using a .ttc TrueTypeCollection

Annotations
@Deprecated
addFontDirectoryback to summary
public void addFontDirectory(String dir, boolean embedded) throws IOException
Annotations
@Deprecated
addFontDirectoryback to summary
public void addFontDirectory(String dir, boolean embedded, PdfBoxFontResolver.FontGroup fontGroup) throws IOException

Add all fonts in the given directory

closeback to summary
public void close()

Free all font resources (i.e. open files), the document should already be closed.

getFallbackFontStoreback to summary
private FallbackFontStore getFallbackFontStore(PdfBoxFontResolver.FontGroup fontGroup)
importFontFacesback to summary
public void importFontFaces(List<FontFaceRule> fontFaces)
resolveFamilyFontback to summary
private void resolveFamilyFont(SharedContext ctx, String[] families, float size, IdentValue weight, IdentValue style, IdentValue variant, List<PdfBoxFontResolver.FontDescription> fonts, AbstractFontStore store)
resolveFontback to summary
public FSFont resolveFont(SharedContext renderingContext, FontSpecification spec)

Implements com.openhtmltopdf.extend.FontResolver.resolveFont.

Annotations
@Override
resolveFontback to summary
private FSFont resolveFont(SharedContext ctx, String[] families, float size, IdentValue weight, IdentValue style, IdentValue variant)
com.openhtmltopdf.pdfboxout back to summary

private Class PdfBoxFontResolver.FilePDFontSupplier

extends Object
implements FSSupplier<PDFont>
Class Inheritance
  • java.lang.Object
  • com.openhtmltopdf.pdfboxout.PdfBoxFontResolver.FilePDFontSupplier
All Implemented Interfaces
com.openhtmltopdf.extend.FSSupplier

Loads a Type0 font on demand

Field Summary

Modifier and TypeField and Description
private final PDDocument
private final File

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public PDFont
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_docback to summary
private final PDDocument _doc
_fontFileback to summary
private final File _fontFile

Constructor Detail

FilePDFontSupplierback to summary
pack-priv FilePDFontSupplier(File fontFile, PDDocument doc)

Method Detail

supplyback to summary
public PDFont supply()

Implements com.openhtmltopdf.extend.FSSupplier.supply.

Annotations
@Override
com.openhtmltopdf.pdfboxout back to summary

public Class PdfBoxFontResolver.FontDescription

extends Object
implements MinimalFontDescription
Class Inheritance
  • java.lang.Object
  • com.openhtmltopdf.pdfboxout.PdfBoxFontResolver.FontDescription
All Implemented Interfaces
com.openhtmltopdf.outputdevice.helper.MinimalFontDescription

A FontDescription can exist in multiple states. Firstly the font may or may not be realized. Fonts are automatically realized upon calling getFont() Secondly, the metrics may or may not be available. If not available, you can attempt to retrieve them by realizing the font.

Field Summary

Modifier and TypeField and Description
private final PDDocument
private final String
private PDFont
private FSSupplier<PDFont>
private final boolean
private final boolean
private PdfBoxRawPDFontMetrics
private final FSCacheEx<String, FSCacheValue>
private final IdentValue
private FSSupplier<InputStream>
private final int

Constructor Summary

AccessConstructor and Description
public
FontDescription(PDFont font, IdentValue style, int weight)

Create a font description from one of the PDF built-in fonts.

public
FontDescription(PDDocument doc, FSSupplier<InputStream> supplier, int weight, IdentValue style, String family, boolean isFromFontFace, boolean isSubset, FSCacheEx<String, FSCacheValue> metricsCache)

Create a font description from an input stream supplier.

private
FontDescription(PDDocument doc, PDFont font, IdentValue style, int weight)

Create a font description when a PDFont is definitely available to begin with.

public
FontDescription(PDDocument doc, FSSupplier<PDFont> fontSupplier, IdentValue style, int weight, String family, boolean isFromFontFace, boolean isSubset, FSCacheEx<String, FSCacheValue> metricsCache)

Creates a font description from a PDFont supplier.

Method Summary

Modifier and TypeMethod and Description
private String
createFontMetricsCacheKey(String family, int weight, IdentValue style)

public String
public PDFont

Returns:

the font or null if there was a problem.
getFont
()

Downloads and parses the font if required.

public PdfBoxRawPDFontMetrics

Returns:

the font metrics or null if there was a problem.
getFontMetrics
()

Downloads and parses the font if required (metrics were not available from cache).

private PdfBoxRawPDFontMetrics
getFontMetricsFromCache(String family, int weight, IdentValue style)

public IdentValue
public int
public boolean
isFontAvailable()

Returns whether the font is available yet.

public boolean
public boolean
isMetricsAvailable()

If the metrics are available yet.

private boolean
private void
putFontMetricsInCache(String family, int weight, IdentValue style, PdfBoxRawPDFontMetrics metrics)

public boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_docback to summary
private final PDDocument _doc
_familyback to summary
private final String _family
_fontback to summary
private PDFont _font
_fontSupplierback to summary
private FSSupplier<PDFont> _fontSupplier
_isFromFontFaceback to summary
private final boolean _isFromFontFace
_isSubsetback to summary
private final boolean _isSubset
_metricsback to summary
private PdfBoxRawPDFontMetrics _metrics
_metricsCacheback to summary
private final FSCacheEx<String, FSCacheValue> _metricsCache
_styleback to summary
private final IdentValue _style
_supplierback to summary
private FSSupplier<InputStream> _supplier
_weightback to summary
private final int _weight

Constructor Detail

FontDescriptionback to summary
public FontDescription(PDFont font, IdentValue style, int weight)

Create a font description from one of the PDF built-in fonts.

FontDescriptionback to summary
public FontDescription(PDDocument doc, FSSupplier<InputStream> supplier, int weight, IdentValue style, String family, boolean isFromFontFace, boolean isSubset, FSCacheEx<String, FSCacheValue> metricsCache)

Create a font description from an input stream supplier. The input stream will only be accessed if getFont() or getFontMetrics() (and the font metrics were not available from cache) are called.

FontDescriptionback to summary
private FontDescription(PDDocument doc, PDFont font, IdentValue style, int weight)

Create a font description when a PDFont is definitely available to begin with. Currently only used for PDF built-in fonts.

FontDescriptionback to summary
public FontDescription(PDDocument doc, FSSupplier<PDFont> fontSupplier, IdentValue style, int weight, String family, boolean isFromFontFace, boolean isSubset, FSCacheEx<String, FSCacheValue> metricsCache)

Creates a font description from a PDFont supplier. The supplier will only be called upon if getFont() or getFontMetrics() (and the font metrics were not available from cache) are called.

Method Detail

createFontMetricsCacheKeyback to summary
private String createFontMetricsCacheKey(String family, int weight, IdentValue style)
getFamilyback to summary
public String getFamily()
getFontback to summary
public PDFont getFont()

Downloads and parses the font if required. Should only be called when the font is definitely needed.

Returns:PDFont

the font or null if there was a problem.

getFontMetricsback to summary
public PdfBoxRawPDFontMetrics getFontMetrics()

Downloads and parses the font if required (metrics were not available from cache). Should only be called when the font metrics are definitely needed.

Returns:PdfBoxRawPDFontMetrics

the font metrics or null if there was a problem.

See Also
isMetricsAvailable()
getFontMetricsFromCacheback to summary
private PdfBoxRawPDFontMetrics getFontMetricsFromCache(String family, int weight, IdentValue style)
getStyleback to summary
public IdentValue getStyle()

Implements com.openhtmltopdf.outputdevice.helper.MinimalFontDescription.getStyle.

Annotations
@Override
getWeightback to summary
public int getWeight()

Implements com.openhtmltopdf.outputdevice.helper.MinimalFontDescription.getWeight.

Annotations
@Override
isFontAvailableback to summary
public boolean isFontAvailable()

Returns whether the font is available yet.

See Also
getFont()
isFromFontFaceback to summary
public boolean isFromFontFace()
isMetricsAvailableback to summary
public boolean isMetricsAvailable()

If the metrics are available yet.

See Also
getFontMetrics()
loadMetricsback to summary
private boolean loadMetrics()
putFontMetricsInCacheback to summary
private void putFontMetricsInCache(String family, int weight, IdentValue style, PdfBoxRawPDFontMetrics metrics)
realizeFontback to summary
public boolean realizeFont()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
com.openhtmltopdf.pdfboxout back to summary

public final Enum PdfBoxFontResolver.FontGroup

extends Enum<PdfBoxFontResolver.FontGroup>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final PdfBoxFontResolver.FontGroup
public static final PdfBoxFontResolver.FontGroup
public static final PdfBoxFontResolver.FontGroup

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static PdfBoxFontResolver.FontGroup
public static PdfBoxFontResolver.FontGroup[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

FINAL_FALLBACKback to summary
public static final PdfBoxFontResolver.FontGroup FINAL_FALLBACK
MAINback to summary
public static final PdfBoxFontResolver.FontGroup MAIN
PRE_BUILT_IN_FALLBACKback to summary
public static final PdfBoxFontResolver.FontGroup PRE_BUILT_IN_FALLBACK

Constructor Detail

FontGroupback to summary
private FontGroup()

Method Detail

valueOfback to summary
public static PdfBoxFontResolver.FontGroup valueOf(String name)
valuesback to summary
public static PdfBoxFontResolver.FontGroup[] values()