Class PdfGraphics2D.CompositeFontDrawer
- Enclosing class:
PdfGraphics2D
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 ClassesModifier and TypeClassDescriptionstatic interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
private static final String
private static final Method
private static final Class
<?> private static final String
Base fonts
that corresponds to the splitted part of the stringprivate static final Class
<?> private static final String
private static final Class
<?> private static final String
private static final Method
private static final String
private static final Method
private static final String
private static final String
private static final Method
private static final String
private static final Method
private static final String
private static final String
private final StringBuilder
Splitted parts of the string.private static final boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) 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.private static Class
<?> getClassForName
(String className) private static Method
(package private) boolean
isCompositeFont
(Font font) Check if the given font is a composite font.(package private) static boolean
private void
splitStringIntoDisplayableParts
(String s, Font compositeFont, Function<Font, BaseFont> fontConverter) Split string into visible and not visible parts.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.
-
Field Details
-
GET_MODULE_METHOD_NAME
- See Also:
-
IS_OPEN_METHOD_NAME
- See Also:
-
ADD_OPENS_METHOD_NAME
- See Also:
-
COMPOSITE_FONT_CLASS_NAME
- See Also:
-
COMPOSITE_FONT_CLASS
-
GET_NUM_SLOTS_METHOD_NAME
- See Also:
-
GET_NUM_SLOTS_METHOD
-
GET_SLOT_FONT_METHOD_NAME
- See Also:
-
GET_SLOT_FONT_METHOD
-
FONT_UTILITIES_CLASS_NAME
- See Also:
-
FONT_UTILITIES_CLASS
-
GET_FONT2D_METHOD_NAME
- See Also:
-
GET_FONT2D_METHOD
-
FONT2D_CLASS_NAME
- See Also:
-
FONT2D_CLASS
-
CAN_DISPLAY_METHOD_NAME
- See Also:
-
CAN_DYSPLAY_METHOD
-
GET_FONT_NAME_METHOD_NAME
- See Also:
-
GET_FONT_NAME_METHOD
-
SUPPORTED
private static final boolean SUPPORTED -
sb
-
stringParts
Splitted parts of the string. -
correspondingBaseFontsForParts
Base fonts
that corresponds to the splitted part of the string -
fontFamilyComposite
-
-
Constructor Details
-
CompositeFontDrawer
private CompositeFontDrawer()
-
-
Method Details
-
isSupported
static boolean isSupported() -
updateModuleToOpenPackage
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
-
getMethod
-
isCompositeFont
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 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(String s, Font compositeFont, Function<Font, BaseFont> fontConverter) throws IllegalAccessException, IllegalArgumentException, InvocationTargetExceptionSplit 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:
IllegalAccessException
IllegalArgumentException
InvocationTargetException
-