Class TextShapers
java.lang.Object
de.xima.fc.common.text.shape.TextShapers
Main entry point for accessing
ITextShaper features.- Since:
- 8.4.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic IFallbackFontFindercodePointFallbackFontFinder(FontSpecifier[] fontSpecifiers, InputStream input, boolean validateInput) Creates a fallback font finder from the given pre-computed code point input data, as obtained bycodePointFallbackFontFinderBuilder().static ITextShaperGets a fallback shaper that will never throw, no matter what the input text.static FontTextShaperBuilderCreates a builder for an advanced shaper that uses font data to measure text.static TextShaperTypeGets the text shaper type for shaping text via AWT font metrics.static TextShaperTypeGets the text shaper type for shaping text via Harfbuzz.static IFallbackFontFinderlistFallbackFontFinder(Iterable<FontSpecifier> fallbackFonts) Creates afallback font finderthat always tries the given fonts in order, regardless of the text being shaped.static Rectangular2DDoublemeasureTextLine(ITextShaper shaper, String line, double fontSize, String script, EBidiTextDirection textDirection) Measures a single line of text, using the given shaper.
-
Method Details
-
codePointFallbackFontFinder
public static IFallbackFontFinder codePointFallbackFontFinder(FontSpecifier[] fontSpecifiers, InputStream input, boolean validateInput) throws IOException Creates a fallback font finder from the given pre-computed code point input data, as obtained bycodePointFallbackFontFinderBuilder().- Parameters:
fontSpecifiers- The font specifiers to use for the fallback font finder. Must not be null.input- The input stream containing the pre-computed code point data. Must not be null.validateInput- Whether to perform certain checks on the input data. May take slightly longer.- Returns:
- A fallback font finder that uses the given code point data to find fallback fonts for shaping text.
- Throws:
IOException- if an I/O error occurs while reading the input stream.
-
codePointFallbackFontFinderBuilder
-
fallbackShaper
Gets a fallback shaper that will never throw, no matter what the input text.- Returns:
- A fallback shaper.
-
fontShaper
Creates a builder for an advanced shaper that uses font data to measure text. Supports specifying fallback fonts for shaping text that needs multiple fonts for coverage.- Returns:
- A builder for a Harfbuzz shaper.
-
fontShaperTypeAwt
Gets the text shaper type for shaping text via AWT font metrics. Worse thanfontShaperTypeHarfbuzz(), but may be useful as a simple fallback.- Returns:
- The AWT text shaper type.
-
fontShaperTypeHarfbuzz
Gets the text shaper type for shaping text via Harfbuzz. This is the recommended way to shape text, as it is fast and supports a wide range of scripts and languages.- Returns:
- The Harfbuzz text shaper type.
-
listFallbackFontFinder
Creates afallback font finderthat always tries the given fonts in order, regardless of the text being shaped.- Parameters:
fallbackFonts- The fonts to use as fallbacks, in order of preference. May be empty, but not null.- Returns:
- A fallback font finder that will try the given fonts in order.
-
measureTextLine
public static Rectangular2DDouble measureTextLine(ITextShaper shaper, String line, double fontSize, String script, EBidiTextDirection textDirection) Measures a single line of text, using the given shaper. Assumes that there are no line breaks.- Parameters:
shaper- The text shaper to use for shaping the text.line- The text to measure.fontSize- The font size to use for measuring the text.script- The script to use for measuring the text. May affect the shaping of the text.textDirection- The default text direction.- Returns:
- The width and height of the text.
-