org.apache.fop.fonts

## Class Font

- java.lang.Object
- - org.apache.fop.fonts.Font

- All Implemented Interfaces:
    Positionable, Substitutable

      public class Font
      extends Object
      implements Substitutable, Positionable

  This class holds font state information and provides access to the font metrics.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static FontTriplet` | `DEFAULT_FONT` Default fallback key
    `static int` | `PRIORITY_DEFAULT` Default selection priority
    `static String` | `STYLE_INCLINED` Inclined font style
    `static String` | `STYLE_ITALIC` Italic font style
    `static String` | `STYLE_NORMAL` Normal font style
    `static String` | `STYLE_OBLIQUE` Oblique font style
    `static int` | `WEIGHT_BOLD` Bold font weight
    `static int` | `WEIGHT_EXTRA_BOLD` Extra Bold font weight
    `static int` | `WEIGHT_LIGHT` Light font weight
    `static int` | `WEIGHT_NORMAL` Normal font weight

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Font(String key, FontTriplet triplet, FontMetrics met, int fontSize)` Main constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getAscender()` Returns the font's ascender.
    `int` | `getCapHeight()` Returns the font's CapHeight.
    `int` | `getCharWidth(char c)` Helper method for getting the width of a unicode char from the current fontstate.
    `int` | `getCharWidth(int c)` Helper method for getting the width of a unicode char from the current fontstate.
    `int` | `getDescender()` Returns the font's Descender.
    `FontMetrics` | `getFontMetrics()` Returns the associated font metrics object.
    `String` | `getFontName()` Returns the font's name.
    `int` | `getFontSize()` Returns the font size
    `FontTriplet` | `getFontTriplet()`
    `Map<Integer,Map<Integer,Integer>>` | `getKerning()` Returns the font's kerning table
    `int` | `getKernValue(int ch1, int ch2)` Returns the amount of kerning between two characters.
    `int` | `getWidth(int charnum)` Returns the width of a character
    `int` | `getWordWidth(String word)` Calculates the word width.
    `int` | `getXHeight()` Returns the XHeight
    `boolean` | `hasChar(char c)` Determines whether this font contains a particular character/glyph.
    `boolean` | `hasCodePoint(int cp)` Determines whether this font contains a particular code point/glyph.
    `boolean` | `hasFeature(int tableType, String script, String language, String feature)`
    `boolean` | `hasKerning()`
    `boolean` | `isMultiByte()` Determines whether the font is a multibyte font.
    `char` | `mapChar(char c)` Map a java character (unicode) to a font character.
    `int` | `mapCodePoint(int cp)` Map a unicode code point to a font character.
    `int[][]` | `performPositioning(CharSequence cs, String script, String language)` Perform glyph positioning using an implied font size.
    `int[][]` | `performPositioning(CharSequence cs, String script, String language, int fontSize)` Perform glyph positioning.
    `boolean` | `performsPositioning()` Determines if font performs glyph positioning.
    `boolean` | `performsSubstitution()` Determines if font performs glyph substitution.
    `CharSequence` | `performSubstitution(CharSequence cs, String script, String language, List associations, boolean retainControls)` Perform substitutions on characters to effect glyph substitution.
    `CharSequence` | `reorderCombiningMarks(CharSequence cs, int[][] gpa, String script, String language, List associations)` Reorder combining marks in character sequence so that they precede (within the sequence) the base character to which they are applied.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### WEIGHT_EXTRA_BOLD

          public static final int WEIGHT_EXTRA_BOLD

      Extra Bold font weight
      See Also:
        Constant Field Values

    - #### WEIGHT_BOLD

          public static final int WEIGHT_BOLD

      Bold font weight
      See Also:
        Constant Field Values

    - #### WEIGHT_NORMAL

          public static final int WEIGHT_NORMAL

      Normal font weight
      See Also:
        Constant Field Values

    - #### WEIGHT_LIGHT

          public static final int WEIGHT_LIGHT

      Light font weight
      See Also:
        Constant Field Values

    - #### STYLE_NORMAL

          public static final String STYLE_NORMAL

      Normal font style
      See Also:
        Constant Field Values

    - #### STYLE_ITALIC

          public static final String STYLE_ITALIC

      Italic font style
      See Also:
        Constant Field Values

    - #### STYLE_OBLIQUE

          public static final String STYLE_OBLIQUE

      Oblique font style
      See Also:
        Constant Field Values

    - #### STYLE_INCLINED

          public static final String STYLE_INCLINED

      Inclined font style
      See Also:
        Constant Field Values

    - #### PRIORITY_DEFAULT

          public static final int PRIORITY_DEFAULT

      Default selection priority
      See Also:
        Constant Field Values

    - #### DEFAULT_FONT

          public static final FontTriplet DEFAULT_FONT

      Default fallback key

  - ### Constructor Detail

    - #### Font

          public Font(String key,
                      FontTriplet triplet,
                      FontMetrics met,
                      int fontSize)

      Main constructor
      Parameters:
        `key` - key of the font
        `triplet` - the font triplet that was used to lookup this font (may be null)
        `met` - font metrics
        `fontSize` - font size

  - ### Method Detail

    - #### getFontMetrics

          public FontMetrics getFontMetrics()

      Returns the associated font metrics object.
      Returns:
        the font metrics

    - #### isMultiByte

          public boolean isMultiByte()

      Determines whether the font is a multibyte font.
      Returns:
        True if it is multibyte

    - #### getAscender

          public int getAscender()

      Returns the font's ascender.
      Returns:
        the ascender

    - #### getCapHeight

          public int getCapHeight()

      Returns the font's CapHeight.
      Returns:
        the capital height

    - #### getDescender

          public int getDescender()

      Returns the font's Descender.
      Returns:
        the descender

    - #### getFontName

          public String getFontName()

      Returns the font's name.
      Returns:
        the font name

    - #### getFontTriplet

          public FontTriplet getFontTriplet()

      Returns:
        the font triplet that selected this font

    - #### getFontSize

          public int getFontSize()

      Returns the font size
      Returns:
        the font size

    - #### getXHeight

          public int getXHeight()

      Returns the XHeight
      Returns:
        the XHeight

    - #### hasKerning

          public boolean hasKerning()

      Returns:
        true if the font has kerning info

    - #### hasFeature

          public boolean hasFeature(int tableType,
                                    String script,
                                    String language,
                                    String feature)

      Returns:
        true if the font has feature (i.e., at least one lookup matches)

    - #### getKerning

          public Map<Integer,Map<Integer,Integer>> getKerning()

      Returns the font's kerning table
      Returns:
        the kerning table

    - #### getKernValue

          public int getKernValue(int ch1,
                                  int ch2)

      Returns the amount of kerning between two characters. The value returned measures in pt. So it is already adjusted for font size.
      Parameters:
        `ch1` - first character
        `ch2` - second character
      Returns:
        the distance to adjust for kerning, 0 if there's no kerning

    - #### getWidth

          public int getWidth(int charnum)

      Returns the width of a character
      Parameters:
        `charnum` - character to look up
      Returns:
        width of the character

    - #### mapChar

          public char mapChar(char c)

      Map a java character (unicode) to a font character. Default uses CodePointMapping.
      Parameters:
        `c` - character to map
      Returns:
        the mapped character

    - #### mapCodePoint

          public int mapCodePoint(int cp)

      Map a unicode code point to a font character. Default uses CodePointMapping.
      Parameters:
        `cp` - code point to map
      Returns:
        the mapped character

    - #### hasChar

          public boolean hasChar(char c)

      Determines whether this font contains a particular character/glyph.
      Parameters:
        `c` - character to check
      Returns:
        True if the character is supported, False otherwise

    - #### hasCodePoint

          public boolean hasCodePoint(int cp)

      Determines whether this font contains a particular code point/glyph.
      Parameters:
        `cp` - code point to check
      Returns:
        True if the code point is supported, False otherwise

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### getCharWidth

          public int getCharWidth(char c)

      Helper method for getting the width of a unicode char from the current fontstate. This also performs some guessing on widths on various versions of space that might not exists in the font.
      Parameters:
        `c` - character to inspect
      Returns:
        the width of the character or -1 if no width available

    - #### getCharWidth

          public int getCharWidth(int c)

      Helper method for getting the width of a unicode char from the current fontstate. This also performs some guessing on widths on various versions of space that might not exists in the font.
      Parameters:
        `c` - character to inspect
      Returns:
        the width of the character or -1 if no width available

    - #### getWordWidth

          public int getWordWidth(String word)

      Calculates the word width.
      Parameters:
        `word` - text to get width for
      Returns:
        the width of the text

    - #### performsSubstitution

          public boolean performsSubstitution()

      Determines if font performs glyph substitution.
      Specified by:
        `performsSubstitution` in interface `Substitutable`
      Returns:
        true if performs substitution.

    - #### performSubstitution

          public CharSequence performSubstitution(CharSequence cs,
                                                  String script,
                                                  String language,
                                                  List associations,
                                                  boolean retainControls)

      Perform substitutions on characters to effect glyph substitution. If some substitution is performed, it entails mapping from one or more input characters denoting textual character information to one or more output character codes denoting glyphs in this font, where the output character codes may make use of private character code values that have significance only for this font.
      Specified by:
        `performSubstitution` in interface `Substitutable`
      Parameters:
        `cs` - character sequence to map to output font encoding character sequence
        `script` - a script identifier
        `language` - a language identifier
        `associations` - optional list to receive list of character associations
        `retainControls` - if true, then retain control characters and their glyph mappings, otherwise remove
      Returns:
        output sequence (represented as a character sequence, where each character in the returned sequence denotes "font characters", i.e., character codes that map directly (1-1) to their associated glyphs

    - #### reorderCombiningMarks

          public CharSequence reorderCombiningMarks(CharSequence cs,
                                                    int[][] gpa,
                                                    String script,
                                                    String language,
                                                    List associations)

      Reorder combining marks in character sequence so that they precede (within the sequence) the base character to which they are applied. N.B. In the case of LTR segments, marks are not reordered by this, method since when the segment is reversed by BIDI processing, marks are automatically reordered to precede their base character.
      Specified by:
        `reorderCombiningMarks` in interface `Substitutable`
      Parameters:
        `cs` - character sequence within which combining marks to be reordered
        `gpa` - associated glyph position adjustments (also reordered)
        `script` - a script identifier
        `language` - a language identifier
        `associations` - optional list of associations to be reordered
      Returns:
        output sequence containing reordered "font characters"

    - #### performsPositioning

          public boolean performsPositioning()

      Determines if font performs glyph positioning.
      Specified by:
        `performsPositioning` in interface `Positionable`
      Returns:
        true if performs positioning

    - #### performPositioning

          public int[][] performPositioning(CharSequence cs,
                                            String script,
                                            String language,
                                            int fontSize)

      Perform glyph positioning.
      Specified by:
        `performPositioning` in interface `Positionable`
      Parameters:
        `cs` - character sequence to map to position offsets (advancement adjustments)
        `script` - a script identifier
        `language` - a language identifier
        `fontSize` - font size
      Returns:
        array (sequence) of 4-tuples of placement [PX,PY] and advance [AX,AY] adjustments, in that order, with one 4-tuple for each element of glyph sequence, or null if no non-zero adjustment applies

    - #### performPositioning

          public int[][] performPositioning(CharSequence cs,
                                            String script,
                                            String language)

      Perform glyph positioning using an implied font size.
      Specified by:
        `performPositioning` in interface `Positionable`
      Parameters:
        `cs` - character sequence to map to position offsets (advancement adjustments)
        `script` - a script identifier
        `language` - a language identifier
      Returns:
        array (sequence) of 4-tuples of placement [PX,PY] and advance [AX,AY] adjustments, in that order, with one 4-tuple for each element of glyph sequence, or null if no non-zero adjustment applies

Copyright © 2023 Apache Software Foundation. All rights reserved.