java.lang.Object
org.sejda.impl.sambox.util.FontUtils
Utility to map from Sejda font definition to PDFBox.
- Author:
- Andrea Vacondio
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final List<org.sejda.impl.sambox.component.font.FallbackFontsProvider>static org.sejda.sambox.pdmodel.font.PDFontstatic final Stringstatic final FontResource[] -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareEncodeDecodeSame(org.sejda.sambox.pdmodel.font.PDFont font, String text) static voidassertEncodeDecodeSame(org.sejda.sambox.pdmodel.font.PDFont font, String text) static doublecalculateBBoxHeight(String text, org.sejda.sambox.pdmodel.font.PDFont font) static booleancanDisplay(String text, org.sejda.sambox.pdmodel.font.PDFont font) static booleancanDisplaySpace(org.sejda.sambox.pdmodel.font.PDFont font) static voidstatic voidclearLoadedFontCache(org.sejda.sambox.pdmodel.PDDocument document) static Stringdecode(org.sejda.sambox.pdmodel.font.PDFont font, byte[] bytes) static org.sejda.sambox.pdmodel.font.PDFontfindFontFor(org.sejda.sambox.pdmodel.PDDocument document, String text) static org.sejda.sambox.pdmodel.font.PDFontfindFontFor(org.sejda.sambox.pdmodel.PDDocument document, String text, boolean bold, org.sejda.sambox.pdmodel.font.PDFont originalFont) static org.sejda.sambox.pdmodel.font.PDFontfontOrFallback(String text, org.sejda.sambox.pdmodel.font.PDFont font, org.sejda.sambox.pdmodel.PDDocument document) Checks the text can be written with the given font, find a fallback font otherwisestatic doublegetSimpleStringWidth(String text, org.sejda.sambox.pdmodel.font.PDFont font, double fontSize) Calculates the width of the string using the given font.static org.sejda.sambox.pdmodel.font.PDType1FontgetStandardType1Font(StandardType1Font st1Font) Mapping between Sejda and PDFBox standard type 1 fonts implementationstatic booleanisBold(org.sejda.sambox.pdmodel.font.PDFont font) static booleanisItalic(org.sejda.sambox.pdmodel.font.PDFont font) static booleanisOnlyWhitespace(String text) static org.sejda.sambox.pdmodel.font.PDFontloadFont(org.sejda.sambox.pdmodel.PDDocument document, FontResource font) static StringremoveUnsupportedCharacters(String text, org.sejda.sambox.pdmodel.PDDocument doc) static StringremoveWhitespace(String text) Removes all unicode whitespace characters from the input stringstatic StringreplaceUnsupportedCharacters(String text, org.sejda.sambox.pdmodel.PDDocument doc, String replacement) static List<TextWithFont>resolveFonts(String label, org.sejda.sambox.pdmodel.font.PDFont font, org.sejda.sambox.pdmodel.PDDocument document) Supports writing labels which require multiple fonts (eg: mixing thai and english words) Returns a list of text with associated font.resolveTextFragments(String input, org.sejda.sambox.pdmodel.font.PDFont font) Splits an input string into multiple fragments, when glyphs with 0 width are detectedwrapLines(String rawLabel, org.sejda.sambox.pdmodel.font.PDFont font, float fontSize, double maxWidth, org.sejda.sambox.pdmodel.PDDocument document) Wraps the given text on multiple lines, if it does not fit within the given maxWidth It will try to determine if all text can be written with given font and find a fallback for parts that are not supported.
-
Field Details
-
HELVETICA
public static org.sejda.sambox.pdmodel.font.PDFont HELVETICA -
TYPE0FONTS
-
FALLBACK_FONTS_PROVIDERS
public static final List<org.sejda.impl.sambox.component.font.FallbackFontsProvider> FALLBACK_FONTS_PROVIDERS -
REMARK_FROM_SEJDA_FONT_RESOURCE
- See Also:
-
-
Method Details
-
getStandardType1Font
public static org.sejda.sambox.pdmodel.font.PDType1Font getStandardType1Font(StandardType1Font st1Font) Mapping between Sejda and PDFBox standard type 1 fonts implementation- Parameters:
st1Font-- Returns:
- the PDFBox font.
-
fontOrFallback
public static org.sejda.sambox.pdmodel.font.PDFont fontOrFallback(String text, org.sejda.sambox.pdmodel.font.PDFont font, org.sejda.sambox.pdmodel.PDDocument document) Checks the text can be written with the given font, find a fallback font otherwise -
clearLoadedFontCache
public static void clearLoadedFontCache() -
clearLoadedFontCache
public static void clearLoadedFontCache(org.sejda.sambox.pdmodel.PDDocument document) -
loadFont
public static org.sejda.sambox.pdmodel.font.PDFont loadFont(org.sejda.sambox.pdmodel.PDDocument document, FontResource font) -
findFontFor
public static org.sejda.sambox.pdmodel.font.PDFont findFontFor(org.sejda.sambox.pdmodel.PDDocument document, String text) -
findFontFor
public static org.sejda.sambox.pdmodel.font.PDFont findFontFor(org.sejda.sambox.pdmodel.PDDocument document, String text, boolean bold, org.sejda.sambox.pdmodel.font.PDFont originalFont) - Parameters:
document-text-- Returns:
- a font capable of displaying the given string or null
-
isOnlyWhitespace
- Parameters:
text-- Returns:
- true if given text contains only unicode whitespace characters
-
removeWhitespace
Removes all unicode whitespace characters from the input string- Parameters:
text-- Returns:
- the resulting string
-
canDisplaySpace
public static boolean canDisplaySpace(org.sejda.sambox.pdmodel.font.PDFont font) -
canDisplay
- Returns:
- true if the given font can display the given text. IMPORTANT: Ignores all whitespace in text.
-
calculateBBoxHeight
-
isBold
public static boolean isBold(org.sejda.sambox.pdmodel.font.PDFont font) -
isItalic
public static boolean isItalic(org.sejda.sambox.pdmodel.font.PDFont font) -
wrapLines
public static List<String> wrapLines(String rawLabel, org.sejda.sambox.pdmodel.font.PDFont font, float fontSize, double maxWidth, org.sejda.sambox.pdmodel.PDDocument document) throws TaskIOException Wraps the given text on multiple lines, if it does not fit within the given maxWidth It will try to determine if all text can be written with given font and find a fallback for parts that are not supported.- Throws:
TaskIOException
-
getSimpleStringWidth
public static double getSimpleStringWidth(String text, org.sejda.sambox.pdmodel.font.PDFont font, double fontSize) throws IOException Calculates the width of the string using the given font. Does not try to find out if the text can actually be written with the given font and find fallback- Throws:
IOException
-
resolveFonts
public static List<TextWithFont> resolveFonts(String label, org.sejda.sambox.pdmodel.font.PDFont font, org.sejda.sambox.pdmodel.PDDocument document) Supports writing labels which require multiple fonts (eg: mixing thai and english words) Returns a list of text with associated font. -
resolveTextFragments
public static List<String> resolveTextFragments(String input, org.sejda.sambox.pdmodel.font.PDFont font) Splits an input string into multiple fragments, when glyphs with 0 width are detected -
removeUnsupportedCharacters
-
replaceUnsupportedCharacters
-
areEncodeDecodeSame
public static boolean areEncodeDecodeSame(org.sejda.sambox.pdmodel.font.PDFont font, String text) throws IOException - Throws:
IOException
-
assertEncodeDecodeSame
public static void assertEncodeDecodeSame(org.sejda.sambox.pdmodel.font.PDFont font, String text) throws IOException - Throws:
IOException
-
decode
public static String decode(org.sejda.sambox.pdmodel.font.PDFont font, byte[] bytes) throws IOException - Throws:
IOException
-