Class OutputProfiler.AutoEmbeddingFontAction

  • All Implemented Interfaces:
    OutputProfiler.FontAction
    Enclosing class:
    OutputProfiler

    public static class OutputProfiler.AutoEmbeddingFontAction
    extends java.lang.Object
    implements OutputProfiler.FontAction

    The AutoEmbeddingFontAction class is an implementation of OutputProfiler.FontAction that will replace unembedded fonts with embedded ones via a "best fit" algorithm. When a new unembedded font is encountered, the action will replace it with the closest match of the fonts registered with it. The match is based on all attributes of the font, including name, properties and glyph metrics.

    Fonts can be added to this class with the add(org.faceless.pdf2.PDFFont) method as possible alternatives to the fonts in the PDF. There are also two fonts added by default for the ZapfDingbats and Symbol fonts, as copies of these fonts are distributed with the PDF library.

    • Constructor Summary

      Constructors 
      Constructor Description
      AutoEmbeddingFontAction()
      Create a new AutoEmbeddingFontAction
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(PDFFont font)
      Add a new PDFFont to the set of fonts that could be substituted into the PDF.
      java.util.List<PDFFont> getFont​(OutputProfiler profiler, java.lang.String name, boolean embedded, PDFFont font)
      Returns the font(s) to use instead of the specified font, or null to make no changes
      void setMultipleSubstitutions​(boolean multi)
      Set whether it is permissible to substitute multiple fonts for a single font.
      • Methods inherited from class java.lang.Object

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

      • AutoEmbeddingFontAction

        public AutoEmbeddingFontAction()
        Create a new AutoEmbeddingFontAction
    • Method Detail

      • add

        public void add​(PDFFont font)
        Add a new PDFFont to the set of fonts that could be substituted into the PDF.
        Parameters:
        font - the font
      • setMultipleSubstitutions

        public void setMultipleSubstitutions​(boolean multi)
        Set whether it is permissible to substitute multiple fonts for a single font. This is a last resort and as the alternative it usually rasterization it's best to leave this at the default of true. However as it may, theoretically cause text to change shape in the middle of a word, it may be set to false for compatibility with releases prior to 2.27
        Parameters:
        multi - whether to use multi-font substitutions or not.
        Since:
        2.27
      • getFont

        public java.util.List<PDFFont> getFont​(OutputProfiler profiler,
                                               java.lang.String name,
                                               boolean embedded,
                                               PDFFont font)
        Description copied from interface: OutputProfiler.FontAction
        Returns the font(s) to use instead of the specified font, or null to make no changes
        Specified by:
        getFont in interface OutputProfiler.FontAction
        Parameters:
        profiler - the OutputProfiler this action is being run on
        name - the font name
        embedded - whether the font is embedded in the PDF - typically embedded fonts should be left unchanged.
        font - the font that is being replaced. Note this structure is unlikely to support the full PDFFont API, and the object cannot be reused elsewhere.
        Returns:
        either null to make no changes, or a list of one or more fonts that can be used to substitute.