Class PdfGraphics2D.CompositeFontDrawer

java.lang.Object
com.lowagie.text.pdf.PdfGraphics2D.CompositeFontDrawer
Enclosing class:
PdfGraphics2D

private static class PdfGraphics2D.CompositeFontDrawer extends Object
Wrapper class that helps to draw string with sun.font.CompositeFont (Windows logical fonts).

If the given font is a sun.font.CompositeFont than try to find some font (an implementation of sun.font.Font2D) that will display current text. For some symbols that cannot be displayed with the font from the first slot of the composite font all other font will be checked.

This processing is not necessary only for Mac OS - there isn't used "sun.font.CompositeFont", but "sun.font.CFont".

Since the sun.* packages are not part of the supported, public interface the reflection will be used.

  • Field Details

    • GET_MODULE_METHOD_NAME

      private static final String GET_MODULE_METHOD_NAME
      See Also:
    • IS_OPEN_METHOD_NAME

      private static final String IS_OPEN_METHOD_NAME
      See Also:
    • ADD_OPENS_METHOD_NAME

      private static final String ADD_OPENS_METHOD_NAME
      See Also:
    • COMPOSITE_FONT_CLASS_NAME

      private static final String COMPOSITE_FONT_CLASS_NAME
      See Also:
    • COMPOSITE_FONT_CLASS

      private static final Class<?> COMPOSITE_FONT_CLASS
    • GET_NUM_SLOTS_METHOD_NAME

      private static final String GET_NUM_SLOTS_METHOD_NAME
      See Also:
    • GET_NUM_SLOTS_METHOD

      private static final Method GET_NUM_SLOTS_METHOD
    • GET_SLOT_FONT_METHOD_NAME

      private static final String GET_SLOT_FONT_METHOD_NAME
      See Also:
    • GET_SLOT_FONT_METHOD

      private static final Method GET_SLOT_FONT_METHOD
    • FONT_UTILITIES_CLASS_NAME

      private static final String FONT_UTILITIES_CLASS_NAME
      See Also:
    • FONT_UTILITIES_CLASS

      private static final Class<?> FONT_UTILITIES_CLASS
    • GET_FONT2D_METHOD_NAME

      private static final String GET_FONT2D_METHOD_NAME
      See Also:
    • GET_FONT2D_METHOD

      private static final Method GET_FONT2D_METHOD
    • FONT2D_CLASS_NAME

      private static final String FONT2D_CLASS_NAME
      See Also:
    • FONT2D_CLASS

      private static final Class<?> FONT2D_CLASS
    • CAN_DISPLAY_METHOD_NAME

      private static final String CAN_DISPLAY_METHOD_NAME
      See Also:
    • CAN_DYSPLAY_METHOD

      private static final Method CAN_DYSPLAY_METHOD
    • GET_FONT_NAME_METHOD_NAME

      private static final String GET_FONT_NAME_METHOD_NAME
      See Also:
    • GET_FONT_NAME_METHOD

      private static final Method GET_FONT_NAME_METHOD
    • SUPPORTED

      private static final boolean SUPPORTED
    • sb

      private final transient StringBuilder sb
    • stringParts

      private final transient List<String> stringParts
      Splitted parts of the string.
    • correspondingBaseFontsForParts

      private final transient List<BaseFont> correspondingBaseFontsForParts
      Base fonts that corresponds to the splitted part of the string
    • fontFamilyComposite

      private final transient Map<String,Boolean> fontFamilyComposite
  • Constructor Details

    • CompositeFontDrawer

      private CompositeFontDrawer()
  • Method Details

    • isSupported

      static boolean isSupported()
    • updateModuleToOpenPackage

      private static void updateModuleToOpenPackage(Class<?> classInModule, String packageName)
      Update module of the given class to open the given package to the target module if the target module is opened for the current module.

      This helps to avoid warnings for the --illegal-access=permit. Actually (java 9-13) "permit" is default mode, but in the future java releases the default mode will be "deny". It's also important to add --add-opens for the given package if it's need.

    • getClassForName

      private static Class<?> getClassForName(String className)
    • getMethod

      private static Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes)
    • isCompositeFont

      boolean isCompositeFont(Font font)
      Check if the given font is a composite font.
      Parameters:
      font - given font
      Returns:
      true if the given font is sun.font.CompositeFont. False otherwise.
    • drawString

      double drawString(String s, Font compositeFont, double x, double y, Function<Font,BaseFont> fontConverter, PdfGraphics2D.CompositeFontDrawer.DrawStringFunction defaultDrawingFunction)
      Draw text with the given font at the specified position.

      This method splits the string into parts so that it can be displayed with a matching (font that can display all symbols of this part of string) slot font.

      If some class/method cannot be found or throw exception the default drawing string function will be used for a drawing string.

      Parameters:
      s - given string that should be drawn
      compositeFont - composite font. This font should be an instance of composite font, otherwise the default drawing function will be called.
      x - the x coordinate of the location
      y - the y coordinate of the location
      fontConverter - function that convert font to the needed base font
      defaultDrawingFunction - default drawing function that will be used for drawing string.
      Returns:
      width of the drawn string.
    • splitStringIntoDisplayableParts

      private void splitStringIntoDisplayableParts(String s, Font compositeFont, Function<Font,BaseFont> fontConverter) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
      Split string into visible and not visible parts.

      This method split string into substring parts. For each splitted part correspond found base font from the slots of the composite font witch can display all characters of the part of string. If no font found the base font from the own composite font will be used.

      Parameters:
      s -
      compositeFont -
      fontConverter -
      Throws:
      IllegalAccessException
      IllegalArgumentException
      InvocationTargetException