Class TextShapers

java.lang.Object
de.xima.fc.common.text.shape.TextShapers

public final class TextShapers extends Object
Main entry point for accessing ITextShaper features.
Since:
8.4.0
  • 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 by codePointFallbackFontFinderBuilder().
      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

      public static ICodePointFallbackFontFinderBuilder codePointFallbackFontFinderBuilder()
    • fallbackShaper

      public static ITextShaper fallbackShaper()
      Gets a fallback shaper that will never throw, no matter what the input text.
      Returns:
      A fallback shaper.
    • fontShaper

      public static FontTextShaperBuilder 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

      public static TextShaperType fontShaperTypeAwt()
      Gets the text shaper type for shaping text via AWT font metrics. Worse than fontShaperTypeHarfbuzz(), but may be useful as a simple fallback.
      Returns:
      The AWT text shaper type.
    • fontShaperTypeHarfbuzz

      public static TextShaperType 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

      public static IFallbackFontFinder listFallbackFontFinder(Iterable<FontSpecifier> fallbackFonts)
      Creates a fallback font finder that 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.