Class PdfBoxGraphics2DFontTextDrawerDefaultFonts

java.lang.Object
de.rototor.pdfbox.graphics2d.PdfBoxGraphics2DFontTextDrawer
de.rototor.pdfbox.graphics2d.PdfBoxGraphics2DFontTextDrawerDefaultFonts
All Implemented Interfaces:
IPdfBoxGraphics2DFontTextDrawer, Closeable, AutoCloseable
Direct Known Subclasses:
PdfBoxGraphics2DFontTextForcedDrawer

public class PdfBoxGraphics2DFontTextDrawerDefaultFonts extends PdfBoxGraphics2DFontTextDrawer
Like PdfBoxGraphics2DFontTextDrawer, but tries to use default fonts whenever possible. Default fonts are not embedded. You can register additional font files. If no font mapping is found, Helvetica is used. This will fallback to vectorized text if any kind of RTL text is rendered and/or any other not supported feature is used.
  • Constructor Details

    • PdfBoxGraphics2DFontTextDrawerDefaultFonts

      public PdfBoxGraphics2DFontTextDrawerDefaultFonts()
  • Method Details

    • mapFont

      protected org.apache.pdfbox.pdmodel.font.PDFont mapFont(Font font, IPdfBoxGraphics2DFontTextDrawer.IFontTextDrawerEnv env) throws IOException, FontFormatException
      Description copied from class: PdfBoxGraphics2DFontTextDrawer
      Try to map the java.awt.Font to a PDFont.
      Overrides:
      mapFont in class PdfBoxGraphics2DFontTextDrawer
      Parameters:
      font - the java.awt.Font for which a mapping should be found
      env - environment of the font mapper
      Returns:
      the PDFont or null if none can be found.
      Throws:
      IOException - when the font can not be loaded
      FontFormatException - when the font file can not be loaded
    • mapDefaultFonts

      public static org.apache.pdfbox.pdmodel.font.PDFont mapDefaultFonts(Font font)
      Find a PDFont for the given font object, which does not need to be embedded.
      Parameters:
      font - font for which to find a suitable default font
      Returns:
      null if no default font is found or a default font which does not need to be embedded.
    • fontNameEqualsAnyOf

      private static boolean fontNameEqualsAnyOf(Font font, String... names)
    • chooseMatchingTimes

      public static org.apache.pdfbox.pdmodel.font.PDFont chooseMatchingTimes(Font font)
      Get a PDType1Font.TIMES-variant, which matches the given font
      Parameters:
      font - Font to get the styles from
      Returns:
      a PDFont Times variant which matches the style in the given Font object.
    • chooseMatchingCourier

      public static org.apache.pdfbox.pdmodel.font.PDFont chooseMatchingCourier(Font font)
      Get a PDType1Font.COURIER-variant, which matches the given font
      Parameters:
      font - Font to get the styles from
      Returns:
      a PDFont Courier variant which matches the style in the given Font object.
    • chooseMatchingHelvetica

      public static org.apache.pdfbox.pdmodel.font.PDFont chooseMatchingHelvetica(Font font)
      Get a PDType1Font.HELVETICA-variant, which matches the given font
      Parameters:
      font - Font to get the styles from
      Returns:
      a PDFont Helvetica variant which matches the style in the given Font object.