Class BasicFontProvider


  • public class BasicFontProvider
    extends FontProvider
    A basic FontProvider that allows configuring in the constructor which fonts are loaded by default.
    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • DEFAULT_FONT_FAMILY

        private static final java.lang.String DEFAULT_FONT_FAMILY
        See Also:
        Constant Field Values
      • FREE_FONT_RANGE

        private static final Range FREE_FONT_RANGE
      • HTML_TO_PDF_SHIPPED_FONT_RESOURCE_PATH

        private static final java.lang.String HTML_TO_PDF_SHIPPED_FONT_RESOURCE_PATH
        The path to the html2pdf shipped fonts.
        See Also:
        Constant Field Values
      • HTML_TO_PDF_SHIPPED_FONT_NAMES

        private static final java.lang.String[] HTML_TO_PDF_SHIPPED_FONT_NAMES
        The file names of the html2pdf shipped fonts.
      • calligraphyFontsTempList

        private final java.util.List<byte[]> calligraphyFontsTempList
      • shippedFontResourcePath

        protected java.lang.String shippedFontResourcePath
        The path to the shipped fonts.
      • shippedFontNames

        protected java.util.List<java.lang.String> shippedFontNames
        The file names of the shipped fonts.
    • Constructor Detail

      • BasicFontProvider

        public BasicFontProvider()
        Creates a new BasicFontProvider instance.
      • BasicFontProvider

        public BasicFontProvider​(boolean registerStandardPdfFonts,
                                 boolean registerSystemFonts)
        Creates a new BasicFontProvider instance.
        Parameters:
        registerStandardPdfFonts - use true if you want to register the standard Type 1 fonts (can't be embedded)
        registerSystemFonts - use true if you want to register the system fonts (can require quite some resources)
      • BasicFontProvider

        public BasicFontProvider​(boolean registerStandardPdfFonts,
                                 boolean registerShippedFonts,
                                 boolean registerSystemFonts)
        Creates a new BasicFontProvider instance.
        Parameters:
        registerStandardPdfFonts - use true if you want to register the standard Type 1 fonts (can't be embedded)
        registerShippedFonts - use true if you want to register the shipped fonts (can be embedded)
        registerSystemFonts - use true if you want to register the system fonts (can require quite some resources)
      • BasicFontProvider

        public BasicFontProvider​(boolean registerStandardPdfFonts,
                                 boolean registerSystemFonts,
                                 java.lang.String defaultFontFamily)
        Creates a new BasicFontProvider instance.
        Parameters:
        registerStandardPdfFonts - use true if you want to register the standard Type 1 fonts (can't be embedded)
        registerSystemFonts - use true if you want to register the system fonts (can require quite some resources)
        defaultFontFamily - default font family
      • BasicFontProvider

        public BasicFontProvider​(boolean registerStandardPdfFonts,
                                 boolean registerShippedFonts,
                                 boolean registerSystemFonts,
                                 java.lang.String defaultFontFamily)
        Creates a new BasicFontProvider instance.
        Parameters:
        registerStandardPdfFonts - use true if you want to register the standard Type 1 fonts (can't be embedded)
        registerShippedFonts - use true if you want to register the shipped fonts (can be embedded)
        registerSystemFonts - use true if you want to register the system fonts (can require quite some resources)
        defaultFontFamily - default font family
      • BasicFontProvider

        public BasicFontProvider​(FontSet fontSet,
                                 java.lang.String defaultFontFamily)
        Creates a new BasicFontProvider instance.
        Parameters:
        fontSet - predefined set of fonts, could be null.
        defaultFontFamily - default font family.
    • Method Detail

      • addCalligraphFonts

        protected Range addCalligraphFonts()
        This method loads a list of noto fonts from pdfCalligraph (if it is present in the classpath) into FontProvider. The list is the following (each font is represented in regular and bold types): NotoSansArabic, NotoSansGurmukhi, NotoSansOriya, NotoSerifBengali, NotoSerifDevanagari, NotoSerifGujarati, NotoSerifHebrew, NotoSerifKannada, NotoSerifKhmer, NotoSerifMalayalam, NotoSerifTamil, NotoSerifTelugu, NotoSerifThai. If it's needed to have a BasicFontProvider without typography fonts loaded, create an extension of BasicFontProvider and override this method, so it does nothing and only returns null.
        Returns:
        a unicode Range that excludes the loaded from pdfCalligraph fonts, i.e. the unicode range that is to be rendered with any other font contained in this FontProvider
      • addShippedFonts

        protected void addShippedFonts​(Range rangeToLoad)
        Adds fonts shipped with the font provider. For BasicFontProvider this method does nothing but can be overridden to load additional fonts.
        Parameters:
        rangeToLoad - a unicode Range to load characters
      • initShippedFontsResourcePath

        protected void initShippedFontsResourcePath()
        Initialize path to shipped fonts and list of font files.
      • isResourcePathAvailable

        private boolean isResourcePathAvailable()
      • addAllAvailableFonts

        private void addAllAvailableFonts​(Range rangeToLoad)