Class PdfGraphics2D.CompositeFontDrawer
- java.lang.Object
-
- com.lowagie.text.pdf.PdfGraphics2D.CompositeFontDrawer
-
- Enclosing class:
- PdfGraphics2D
private static class PdfGraphics2D.CompositeFontDrawer extends java.lang.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
PdfGraphics2D.CompositeFontDrawer.DrawStringFunction
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
ADD_OPENS_METHOD_NAME
private static java.lang.String
CAN_DISPLAY_METHOD_NAME
private static java.lang.reflect.Method
CAN_DYSPLAY_METHOD
private static java.lang.Class<?>
COMPOSITE_FONT_CLASS
private static java.lang.String
COMPOSITE_FONT_CLASS_NAME
private java.util.List<BaseFont>
correspondingBaseFontsForParts
Base fonts
that corresponds to the splitted part of the stringprivate static java.lang.Class<?>
FONT_UTILITIES_CLASS
private static java.lang.String
FONT_UTILITIES_CLASS_NAME
private static java.lang.Class<?>
FONT2D_CLASS
private static java.lang.String
FONT2D_CLASS_NAME
private java.util.Map<java.lang.String,java.lang.Boolean>
fontFamilyComposite
private static java.lang.reflect.Method
GET_FONT_NAME_METHOD
private static java.lang.String
GET_FONT_NAME_METHOD_NAME
private static java.lang.reflect.Method
GET_FONT2D_METHOD
private static java.lang.String
GET_FONT2D_METHOD_NAME
private static java.lang.String
GET_MODULE_METHOD_NAME
private static java.lang.reflect.Method
GET_NUM_SLOTS_METHOD
private static java.lang.String
GET_NUM_SLOTS_METHOD_NAME
private static java.lang.reflect.Method
GET_SLOT_FONT_METHOD
private static java.lang.String
GET_SLOT_FONT_METHOD_NAME
private static java.lang.String
IS_OPEN_METHOD_NAME
private java.lang.StringBuilder
sb
private java.util.List<java.lang.String>
stringParts
Splitted parts of the string.private static boolean
SUPPORTED
-
Constructor Summary
Constructors Modifier Constructor Description private
CompositeFontDrawer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) double
drawString(java.lang.String s, java.awt.Font compositeFont, double x, double y, java.util.function.Function<java.awt.Font,BaseFont> fontConverter, PdfGraphics2D.CompositeFontDrawer.DrawStringFunction defaultDrawingFunction)
Draw text with the given font at the specified position.private static java.lang.Class<?>
getClassForName(java.lang.String className)
private static java.lang.reflect.Method
getMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
(package private) boolean
isCompositeFont(java.awt.Font font)
Check if the given font is a composite font.(package private) static boolean
isSupported()
private void
splitStringIntoDisplayableParts(java.lang.String s, java.awt.Font compositeFont, java.util.function.Function<java.awt.Font,BaseFont> fontConverter)
Split string into visible and not visible parts.private static void
updateModuleToOpenPackage(java.lang.Class<?> classInModule, java.lang.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.
-
-
-
Field Detail
-
GET_MODULE_METHOD_NAME
private static final java.lang.String GET_MODULE_METHOD_NAME
- See Also:
- Constant Field Values
-
IS_OPEN_METHOD_NAME
private static final java.lang.String IS_OPEN_METHOD_NAME
- See Also:
- Constant Field Values
-
ADD_OPENS_METHOD_NAME
private static final java.lang.String ADD_OPENS_METHOD_NAME
- See Also:
- Constant Field Values
-
COMPOSITE_FONT_CLASS_NAME
private static final java.lang.String COMPOSITE_FONT_CLASS_NAME
- See Also:
- Constant Field Values
-
COMPOSITE_FONT_CLASS
private static final java.lang.Class<?> COMPOSITE_FONT_CLASS
-
GET_NUM_SLOTS_METHOD_NAME
private static final java.lang.String GET_NUM_SLOTS_METHOD_NAME
- See Also:
- Constant Field Values
-
GET_NUM_SLOTS_METHOD
private static final java.lang.reflect.Method GET_NUM_SLOTS_METHOD
-
GET_SLOT_FONT_METHOD_NAME
private static final java.lang.String GET_SLOT_FONT_METHOD_NAME
- See Also:
- Constant Field Values
-
GET_SLOT_FONT_METHOD
private static final java.lang.reflect.Method GET_SLOT_FONT_METHOD
-
FONT_UTILITIES_CLASS_NAME
private static final java.lang.String FONT_UTILITIES_CLASS_NAME
- See Also:
- Constant Field Values
-
FONT_UTILITIES_CLASS
private static final java.lang.Class<?> FONT_UTILITIES_CLASS
-
GET_FONT2D_METHOD_NAME
private static final java.lang.String GET_FONT2D_METHOD_NAME
- See Also:
- Constant Field Values
-
GET_FONT2D_METHOD
private static final java.lang.reflect.Method GET_FONT2D_METHOD
-
FONT2D_CLASS_NAME
private static final java.lang.String FONT2D_CLASS_NAME
- See Also:
- Constant Field Values
-
FONT2D_CLASS
private static final java.lang.Class<?> FONT2D_CLASS
-
CAN_DISPLAY_METHOD_NAME
private static final java.lang.String CAN_DISPLAY_METHOD_NAME
- See Also:
- Constant Field Values
-
CAN_DYSPLAY_METHOD
private static final java.lang.reflect.Method CAN_DYSPLAY_METHOD
-
GET_FONT_NAME_METHOD_NAME
private static final java.lang.String GET_FONT_NAME_METHOD_NAME
- See Also:
- Constant Field Values
-
GET_FONT_NAME_METHOD
private static final java.lang.reflect.Method GET_FONT_NAME_METHOD
-
SUPPORTED
private static final boolean SUPPORTED
-
sb
private final transient java.lang.StringBuilder sb
-
stringParts
private final transient java.util.List<java.lang.String> stringParts
Splitted parts of the string.
-
correspondingBaseFontsForParts
private final transient java.util.List<BaseFont> correspondingBaseFontsForParts
Base fonts
that corresponds to the splitted part of the string
-
fontFamilyComposite
private final transient java.util.Map<java.lang.String,java.lang.Boolean> fontFamilyComposite
-
-
Method Detail
-
isSupported
static boolean isSupported()
-
updateModuleToOpenPackage
private static void updateModuleToOpenPackage(java.lang.Class<?> classInModule, java.lang.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 java.lang.Class<?> getClassForName(java.lang.String className)
-
getMethod
private static java.lang.reflect.Method getMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
-
isCompositeFont
boolean isCompositeFont(java.awt.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(java.lang.String s, java.awt.Font compositeFont, double x, double y, java.util.function.Function<java.awt.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 drawncompositeFont
- 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 locationy
- the y coordinate of the locationfontConverter
- function that convertfont
to the neededbase font
defaultDrawingFunction
- default drawing function that will be used for drawing string.- Returns:
- width of the drawn string.
-
splitStringIntoDisplayableParts
private void splitStringIntoDisplayableParts(java.lang.String s, java.awt.Font compositeFont, java.util.function.Function<java.awt.Font,BaseFont> fontConverter) throws java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.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 thebase font
from the own composite font will be used.- Parameters:
s
-compositeFont
-fontConverter
-- Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
-
-