Package com.openhtmltopdf.pdfboxout
Class PdfBoxFontResolver.FontDescription
- java.lang.Object
-
- com.openhtmltopdf.pdfboxout.PdfBoxFontResolver.FontDescription
-
- All Implemented Interfaces:
MinimalFontDescription
- Enclosing class:
- PdfBoxFontResolver
public static class PdfBoxFontResolver.FontDescription extends java.lang.Object implements MinimalFontDescription
AFontDescription
can exist in multiple states. Firstly the font may or may not be realized. Fonts are automatically realized upon callinggetFont()
Secondly, the metrics may or may not be available. If not available, you can attempt to retrieve them by realizing the font.
-
-
Field Summary
Fields Modifier and Type Field Description private org.apache.pdfbox.pdmodel.PDDocument
_doc
private java.lang.String
_family
private org.apache.pdfbox.pdmodel.font.PDFont
_font
private FSSupplier<org.apache.pdfbox.pdmodel.font.PDFont>
_fontSupplier
private boolean
_isFromFontFace
private boolean
_isSubset
private PdfBoxRawPDFontMetrics
_metrics
private FSCacheEx<java.lang.String,FSCacheValue>
_metricsCache
private IdentValue
_style
private FSSupplier<java.io.InputStream>
_supplier
private int
_weight
-
Constructor Summary
Constructors Modifier Constructor Description FontDescription(org.apache.pdfbox.pdmodel.font.PDFont font, IdentValue style, int weight)
Create a font description from one of the PDF built-in fonts.FontDescription(org.apache.pdfbox.pdmodel.PDDocument doc, FSSupplier<java.io.InputStream> supplier, int weight, IdentValue style, java.lang.String family, boolean isFromFontFace, boolean isSubset, FSCacheEx<java.lang.String,FSCacheValue> metricsCache)
Create a font description from an input stream supplier.FontDescription(org.apache.pdfbox.pdmodel.PDDocument doc, FSSupplier<org.apache.pdfbox.pdmodel.font.PDFont> fontSupplier, IdentValue style, int weight, java.lang.String family, boolean isFromFontFace, boolean isSubset, FSCacheEx<java.lang.String,FSCacheValue> metricsCache)
Creates a font description from a PDFont supplier.private
FontDescription(org.apache.pdfbox.pdmodel.PDDocument doc, org.apache.pdfbox.pdmodel.font.PDFont font, IdentValue style, int weight)
Create a font description when a PDFont is definitely available to begin with.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.String
createFontMetricsCacheKey(java.lang.String family, int weight, IdentValue style)
java.lang.String
getFamily()
org.apache.pdfbox.pdmodel.font.PDFont
getFont()
Downloads and parses the font if required.PdfBoxRawPDFontMetrics
getFontMetrics()
Downloads and parses the font if required (metrics were not available from cache).private PdfBoxRawPDFontMetrics
getFontMetricsFromCache(java.lang.String family, int weight, IdentValue style)
IdentValue
getStyle()
int
getWeight()
boolean
isFontAvailable()
Returns whether the font is available yet.boolean
isFromFontFace()
boolean
isMetricsAvailable()
If the metrics are available yet.private boolean
loadMetrics()
private void
putFontMetricsInCache(java.lang.String family, int weight, IdentValue style, PdfBoxRawPDFontMetrics metrics)
boolean
realizeFont()
java.lang.String
toString()
-
-
-
Field Detail
-
_style
private final IdentValue _style
-
_weight
private final int _weight
-
_family
private final java.lang.String _family
-
_doc
private final org.apache.pdfbox.pdmodel.PDDocument _doc
-
_supplier
private FSSupplier<java.io.InputStream> _supplier
-
_fontSupplier
private FSSupplier<org.apache.pdfbox.pdmodel.font.PDFont> _fontSupplier
-
_font
private org.apache.pdfbox.pdmodel.font.PDFont _font
-
_isFromFontFace
private final boolean _isFromFontFace
-
_isSubset
private final boolean _isSubset
-
_metrics
private PdfBoxRawPDFontMetrics _metrics
-
_metricsCache
private final FSCacheEx<java.lang.String,FSCacheValue> _metricsCache
-
-
Constructor Detail
-
FontDescription
public FontDescription(org.apache.pdfbox.pdmodel.font.PDFont font, IdentValue style, int weight)
Create a font description from one of the PDF built-in fonts.
-
FontDescription
public FontDescription(org.apache.pdfbox.pdmodel.PDDocument doc, FSSupplier<java.io.InputStream> supplier, int weight, IdentValue style, java.lang.String family, boolean isFromFontFace, boolean isSubset, FSCacheEx<java.lang.String,FSCacheValue> metricsCache)
Create a font description from an input stream supplier. The input stream will only be accessed ifgetFont()
orgetFontMetrics()
(and the font metrics were not available from cache) are called.
-
FontDescription
private FontDescription(org.apache.pdfbox.pdmodel.PDDocument doc, org.apache.pdfbox.pdmodel.font.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.
-
FontDescription
public FontDescription(org.apache.pdfbox.pdmodel.PDDocument doc, FSSupplier<org.apache.pdfbox.pdmodel.font.PDFont> fontSupplier, IdentValue style, int weight, java.lang.String family, boolean isFromFontFace, boolean isSubset, FSCacheEx<java.lang.String,FSCacheValue> metricsCache)
Creates a font description from a PDFont supplier. The supplier will only be called upon ifgetFont()
orgetFontMetrics()
(and the font metrics were not available from cache) are called.
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getFamily
public java.lang.String getFamily()
-
createFontMetricsCacheKey
private java.lang.String createFontMetricsCacheKey(java.lang.String family, int weight, IdentValue style)
-
getFontMetricsFromCache
private PdfBoxRawPDFontMetrics getFontMetricsFromCache(java.lang.String family, int weight, IdentValue style)
-
putFontMetricsInCache
private void putFontMetricsInCache(java.lang.String family, int weight, IdentValue style, PdfBoxRawPDFontMetrics metrics)
-
loadMetrics
private boolean loadMetrics()
-
realizeFont
public boolean realizeFont()
-
isFontAvailable
public boolean isFontAvailable()
Returns whether the font is available yet.- See Also:
getFont()
-
getFont
public org.apache.pdfbox.pdmodel.font.PDFont getFont()
Downloads and parses the font if required. Should only be called when the font is definitely needed.- Returns:
- the font or null if there was a problem.
-
getWeight
public int getWeight()
- Specified by:
getWeight
in interfaceMinimalFontDescription
-
getStyle
public IdentValue getStyle()
- Specified by:
getStyle
in interfaceMinimalFontDescription
-
isFromFontFace
public boolean isFromFontFace()
-
isMetricsAvailable
public boolean isMetricsAvailable()
If the metrics are available yet.- See Also:
getFontMetrics()
-
getFontMetrics
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:
- the font metrics or null if there was a problem.
- See Also:
isMetricsAvailable()
-
-