Class PdfBoxFontResolver

java.lang.Object
com.openhtmltopdf.pdfboxout.PdfBoxFontResolver
All Implemented Interfaces:
com.openhtmltopdf.extend.FontResolver

public class PdfBoxFontResolver
extends Object
implements com.openhtmltopdf.extend.FontResolver
This class handles all font resolving for the PDF generation. Please note that at the moment only subsetting/embedding of fonts work. So you should always set embedded/subset=true for now.
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static class  PdfBoxFontResolver.FontDescription
    A FontDescription can exist in multiple states.
  • Constructor Summary

    Constructors
    Constructor Description
    PdfBoxFontResolver​(com.openhtmltopdf.layout.SharedContext sharedContext, org.apache.pdfbox.pdmodel.PDDocument doc, com.openhtmltopdf.extend.FSCacheEx<String,​com.openhtmltopdf.extend.FSCacheValue> pdfMetricsCache, PdfRendererBuilder.PdfAConformance pdfAConformance, boolean pdfUaConform)  
  • Method Summary

    Modifier and Type Method Description
    void addFont​(com.openhtmltopdf.extend.FSSupplier<InputStream> supplier, String fontFamilyNameOverride, Integer fontWeightOverride, com.openhtmltopdf.css.constants.IdentValue fontStyleOverride, boolean subset)
    Add a font using a InputStream.
    void addFont​(PDFontSupplier supplier, String fontFamilyNameOverride, Integer fontWeightOverride, com.openhtmltopdf.css.constants.IdentValue fontStyleOverride, boolean subset)
    Add a font using a PDFontSupplier.
    void addFont​(File fontFile, String fontFamilyNameOverride, Integer fontWeightOverride, com.openhtmltopdf.css.constants.IdentValue fontStyleOverride, boolean subset)
    Add a font using a existing file.
    void addFontCollection​(com.openhtmltopdf.extend.FSSupplier<InputStream> supplier, String fontFamilyNameOverride, Integer fontWeightOverride, com.openhtmltopdf.css.constants.IdentValue fontStyleOverride, boolean subset)
    Add fonts using a .ttc TrueTypeCollection
    void addFontCollection​(File file, String fontFamilyNameOverride, Integer fontWeightOverride, com.openhtmltopdf.css.constants.IdentValue fontStyleOverride, boolean subset)
    Add fonts using a .ttc TrueTypeCollection
    void addFontDirectory​(String dir, boolean embedded)
    Add all fonts in the given directory
    void close()
    Free all font resources (i.e.
    void flushCache()
    Deprecated.
    void flushFontFaceFonts()
    Deprecated.
    protected static String getHashName​(String name, com.openhtmltopdf.css.constants.IdentValue weight, com.openhtmltopdf.css.constants.IdentValue style)  
    void importFontFaces​(List<com.openhtmltopdf.css.sheet.FontFaceRule> fontFaces)  
    com.openhtmltopdf.render.FSFont resolveFont​(com.openhtmltopdf.layout.SharedContext renderingContext, com.openhtmltopdf.css.value.FontSpecification spec)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PdfBoxFontResolver

      public PdfBoxFontResolver​(com.openhtmltopdf.layout.SharedContext sharedContext, org.apache.pdfbox.pdmodel.PDDocument doc, com.openhtmltopdf.extend.FSCacheEx<String,​com.openhtmltopdf.extend.FSCacheValue> pdfMetricsCache, PdfRendererBuilder.PdfAConformance pdfAConformance, boolean pdfUaConform)
  • Method Details

    • resolveFont

      public com.openhtmltopdf.render.FSFont resolveFont​(com.openhtmltopdf.layout.SharedContext renderingContext, com.openhtmltopdf.css.value.FontSpecification spec)
      Specified by:
      resolveFont in interface com.openhtmltopdf.extend.FontResolver
    • close

      public void close()
      Free all font resources (i.e. open files), the document should already be closed.
    • flushCache

      @Deprecated public void flushCache()
      Deprecated.
      Specified by:
      flushCache in interface com.openhtmltopdf.extend.FontResolver
    • flushFontFaceFonts

      @Deprecated public void flushFontFaceFonts()
      Deprecated.
    • importFontFaces

      public void importFontFaces​(List<com.openhtmltopdf.css.sheet.FontFaceRule> fontFaces)
    • addFontDirectory

      public void addFontDirectory​(String dir, boolean embedded) throws IOException
      Add all fonts in the given directory
      Throws:
      IOException
    • addFontCollection

      public void addFontCollection​(com.openhtmltopdf.extend.FSSupplier<InputStream> supplier, String fontFamilyNameOverride, Integer fontWeightOverride, com.openhtmltopdf.css.constants.IdentValue fontStyleOverride, boolean subset) throws IOException
      Add fonts using a .ttc TrueTypeCollection
      Throws:
      IOException
    • addFontCollection

      public void addFontCollection​(File file, String fontFamilyNameOverride, Integer fontWeightOverride, com.openhtmltopdf.css.constants.IdentValue fontStyleOverride, boolean subset) throws IOException
      Add fonts using a .ttc TrueTypeCollection
      Throws:
      IOException
    • addFont

      public void addFont​(File fontFile, String fontFamilyNameOverride, Integer fontWeightOverride, com.openhtmltopdf.css.constants.IdentValue fontStyleOverride, boolean subset) throws IOException
      Add a font using a existing file. If the file is a TrueTypeCollection, it will be handled as such.
      Throws:
      IOException
    • addFont

      public void addFont​(com.openhtmltopdf.extend.FSSupplier<InputStream> supplier, String fontFamilyNameOverride, Integer fontWeightOverride, com.openhtmltopdf.css.constants.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)
    • addFont

      public void addFont​(PDFontSupplier supplier, String fontFamilyNameOverride, Integer fontWeightOverride, com.openhtmltopdf.css.constants.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.
    • getHashName

      protected static String getHashName​(String name, com.openhtmltopdf.css.constants.IdentValue weight, com.openhtmltopdf.css.constants.IdentValue style)