org.apache.fop.complexscripts.util

## Class GlyphSequence

- java.lang.Object
- - org.apache.fop.complexscripts.util.GlyphSequence

- All Implemented Interfaces:
    java.lang.Cloneable

      public class GlyphSequence
      extends java.lang.Object
      implements java.lang.Cloneable

  A GlyphSequence encapsulates a sequence of character codes, a sequence of glyph codes, and a sequence of character associations, where, for each glyph in the sequence of glyph codes, there is a corresponding character association. Character associations server to relate the glyph codes in a glyph sequence to the specific characters in an original character code sequence with which the glyph codes are associated.

  This work was originally authored by Glenn Adams (gadams@apache.org).

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected GlyphSequence` | `unprocessedGS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `GlyphSequence(GlyphSequence gs)` Instantiate a glyph sequence using an existing glyph sequence, where the new glyph sequence shares the character array of the existing sequence (but not the buffer object), and creates new copies of glyphs buffer and association list.
    `GlyphSequence(GlyphSequence gs, int[] bga, int[] iga, int[] lga, CharAssociation[] bal, CharAssociation[] ial, CharAssociation[] lal)` Instantiate a glyph sequence using an existing glyph sequence, where the new glyph sequence shares the character array of the existing sequence (but not the buffer object), but uses the specified backtrack, input, and lookahead glyph arrays to populate the glyphs, and uses the specified of glyphs buffer and association list.
    `GlyphSequence(java.nio.IntBuffer characters, java.nio.IntBuffer glyphs, java.util.List associations)` Instantiate a glyph sequence, reusing (i.e., not copying) the referenced character and glyph buffers and associations.
    `GlyphSequence(java.nio.IntBuffer characters, java.nio.IntBuffer glyphs, java.util.List associations, boolean predications)` Instantiate a glyph sequence, reusing (i.e., not copying) the referenced character and glyph buffers and associations.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.Object` | `clone()`
    `int` | `compareGlyphs(java.nio.IntBuffer gb)` Compare glyphs.
    `static java.util.List` | `concatAssociations(CharAssociation[] baa, CharAssociation[] iaa, CharAssociation[] laa)` Concatenante association arrays.
    `static java.nio.IntBuffer` | `concatGlyphs(int[] bga, int[] iga, int[] lga)` Concatenante glyph arrays.
    `CharAssociation` | `getAssociation(int index)` Obtain association at specified index.
    `java.util.List` | `getAssociations()` Obtain reference to underlying associations list.
    `CharAssociation[]` | `getAssociations(int offset, int count)` Obtain count associations starting at offset.
    `int[]` | `getCharacterArray(boolean copy)` Obtain array of characters.
    `int` | `getCharacterCount()` Obtain the number of characters in character array, where each character constitutes a unicode scalar value.
    `java.nio.IntBuffer` | `getCharacters()` Obtain reference to underlying character buffer.
    `int` | `getGlyph(int index)` Obtain glyph id at specified index.
    `int[]` | `getGlyphArray(boolean copy)` Obtain array of glyphs.
    `int` | `getGlyphCount()` Obtain the number of glyphs in glyphs array, where each glyph constitutes a font specific glyph index.
    `java.nio.IntBuffer` | `getGlyphs()` Obtain reference to underlying glyph buffer.
    `int[]` | `getGlyphs(int offset, int count)` Obtain count glyphs starting at offset.
    `java.lang.Object` | `getPredication(int offset, java.lang.String key)` Get predication KEY at glyph sequence OFFSET.
    `boolean` | `getPredications()` Obtain predications state.
    `int` | `getUnprocessedGlyph(int index)`
    `int` | `getUTF16CharacterCount()` Obtain the number of characters in character array, where each character constitutes a UTF-16 character.
    `static GlyphSequence` | `join(GlyphSequence gs, GlyphSequence[] sa)` Join (concatenate) glyph sequences.
    `static GlyphSequence` | `reorder(GlyphSequence gs, int source, int count, int target)` Reorder sequence such that [SOURCE,SOURCE+COUNT) is moved just prior to TARGET.
    `static boolean` | `sameGlyphs(int[] ga1, int[] ga2)` Determine if two arrays of glyphs are identical.
    `void` | `setGlyph(int index, int gi)` Set glyph id at specified index.
    `void` | `setPredication(int offset, java.lang.String key, java.lang.Object value)` Set predication <KEY,VALUE> at glyph sequence OFFSET.
    `void` | `setPredications(boolean enable)` Enable or disable predications.
    `void` | `setUnprocessedGS(GlyphSequence glyphSequence)`
    `java.lang.String` | `toString()`

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

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

- - ### Field Detail

    - #### unprocessedGS

          protected GlyphSequence unprocessedGS

  - ### Constructor Detail

    - #### GlyphSequence

          public GlyphSequence(java.nio.IntBuffer characters,
                               java.nio.IntBuffer glyphs,
                               java.util.List associations,
                               boolean predications)

      Instantiate a glyph sequence, reusing (i.e., not copying) the referenced character and glyph buffers and associations. If characters is null, then an empty character buffer is created. If glyphs is null, then a glyph buffer is created whose capacity is that of the character buffer. If associations is null, then identity associations are created.
      Parameters:
        `characters` - a (possibly null) buffer of associated (originating) characters
        `glyphs` - a (possibly null) buffer of glyphs
        `associations` - a (possibly null) array of glyph to character associations
        `predications` - true if predications are enabled

    - #### GlyphSequence

          public GlyphSequence(java.nio.IntBuffer characters,
                               java.nio.IntBuffer glyphs,
                               java.util.List associations)

      Instantiate a glyph sequence, reusing (i.e., not copying) the referenced character and glyph buffers and associations. If characters is null, then an empty character buffer is created. If glyphs is null, then a glyph buffer is created whose capacity is that of the character buffer. If associations is null, then identity associations are created.
      Parameters:
        `characters` - a (possibly null) buffer of associated (originating) characters
        `glyphs` - a (possibly null) buffer of glyphs
        `associations` - a (possibly null) array of glyph to character associations

    - #### GlyphSequence

          public GlyphSequence(GlyphSequence gs)

      Instantiate a glyph sequence using an existing glyph sequence, where the new glyph sequence shares the character array of the existing sequence (but not the buffer object), and creates new copies of glyphs buffer and association list.
      Parameters:
        `gs` - an existing glyph sequence

    - #### GlyphSequence

          public GlyphSequence(GlyphSequence gs,
                               int[] bga,
                               int[] iga,
                               int[] lga,
                               CharAssociation[] bal,
                               CharAssociation[] ial,
                               CharAssociation[] lal)

      Instantiate a glyph sequence using an existing glyph sequence, where the new glyph sequence shares the character array of the existing sequence (but not the buffer object), but uses the specified backtrack, input, and lookahead glyph arrays to populate the glyphs, and uses the specified of glyphs buffer and association list. backtrack, input, and lookahead association arrays to populate the associations.
      Parameters:
        `gs` - an existing glyph sequence
        `bga` - backtrack glyph array
        `iga` - input glyph array
        `lga` - lookahead glyph array
        `bal` - backtrack association list
        `ial` - input association list
        `lal` - lookahead association list

  - ### Method Detail

    - #### getCharacters

          public java.nio.IntBuffer getCharacters()

      Obtain reference to underlying character buffer.
      Returns:
        character buffer reference

    - #### getCharacterArray

          public int[] getCharacterArray(boolean copy)

      Obtain array of characters. If `copy` is true, then a newly instantiated array is returned, otherwise a reference to the underlying buffer's array is returned. N.B. in case a reference to the undelying buffer's array is returned, the length of the array is not necessarily the number of characters in array. To determine the number of characters, use `getCharacterCount()`.
      Parameters:
        `copy` - true if to return a newly instantiated array of characters
      Returns:
        array of characters

    - #### getCharacterCount

          public int getCharacterCount()

      Obtain the number of characters in character array, where each character constitutes a unicode scalar value. NB: Supplementary characters (non-BMP code points) count as 1 character, not as two UTF-16 code units.
      Returns:
        number of characters available in character array

    - #### getUTF16CharacterCount

          public int getUTF16CharacterCount()

      Obtain the number of characters in character array, where each character constitutes a UTF-16 character. This means that every non-BMP character is counted as 2 characters.
      Returns:
        number of chars (UTF-16 code units) available in character array

    - #### getGlyph

          public int getGlyph(int index)
                       throws java.lang.IndexOutOfBoundsException

      Obtain glyph id at specified index.
      Parameters:
        `index` - to obtain glyph
      Returns:
        the glyph identifier of glyph at specified index
      Throws:
        `java.lang.IndexOutOfBoundsException` - if index is less than zero or exceeds last valid position

    - #### getUnprocessedGlyph

          public int getUnprocessedGlyph(int index)
                                  throws java.lang.IndexOutOfBoundsException

      Throws:
        `java.lang.IndexOutOfBoundsException`

    - #### setUnprocessedGS

          public void setUnprocessedGS(GlyphSequence glyphSequence)

    - #### setGlyph

          public void setGlyph(int index,
                               int gi)
                        throws java.lang.IndexOutOfBoundsException

      Set glyph id at specified index.
      Parameters:
        `index` - to set glyph
        `gi` - glyph index
      Throws:
        `java.lang.IndexOutOfBoundsException` - if index is greater or equal to the limit of the underlying glyph buffer

    - #### getGlyphs

          public java.nio.IntBuffer getGlyphs()

      Obtain reference to underlying glyph buffer.
      Returns:
        glyph buffer reference

    - #### getGlyphs

          public int[] getGlyphs(int offset,
                                 int count)

      Obtain count glyphs starting at offset. If `count` is negative, then it is treated as if the number of available glyphs were specified.
      Parameters:
        `offset` - into glyph sequence
        `count` - of glyphs to obtain starting at offset, or negative, indicating all avaialble glyphs starting at offset
      Returns:
        glyph array

    - #### getGlyphArray

          public int[] getGlyphArray(boolean copy)

      Obtain array of glyphs. If `copy` is true, then a newly instantiated array is returned, otherwise a reference to the underlying buffer's array is returned. N.B. in case a reference to the undelying buffer's array is returned, the length of the array is not necessarily the number of glyphs in array. To determine the number of glyphs, use `getGlyphCount()`.
      Parameters:
        `copy` - true if to return a newly instantiated array of glyphs
      Returns:
        array of glyphs

    - #### getGlyphCount

          public int getGlyphCount()

      Obtain the number of glyphs in glyphs array, where each glyph constitutes a font specific glyph index.
      Returns:
        number of glyphs available in character array

    - #### getAssociation

          public CharAssociation getAssociation(int index)
                                         throws java.lang.IndexOutOfBoundsException

      Obtain association at specified index.
      Parameters:
        `index` - into associations array
      Returns:
        glyph to character associations at specified index
      Throws:
        `java.lang.IndexOutOfBoundsException` - if index is less than zero or exceeds last valid position

    - #### getAssociations

          public java.util.List getAssociations()

      Obtain reference to underlying associations list.
      Returns:
        associations list

    - #### getAssociations

          public CharAssociation[] getAssociations(int offset,
                                                   int count)

      Obtain count associations starting at offset.
      Parameters:
        `offset` - into glyph sequence
        `count` - of associations to obtain starting at offset, or negative, indicating all avaialble associations starting at offset
      Returns:
        associations

    - #### setPredications

          public void setPredications(boolean enable)

      Enable or disable predications.
      Parameters:
        `enable` - true if predications are to be enabled; otherwise false to disable

    - #### getPredications

          public boolean getPredications()

      Obtain predications state.
      Returns:
        true if predications are enabled

    - #### setPredication

          public void setPredication(int offset,
                                     java.lang.String key,
                                     java.lang.Object value)

      Set predication <KEY,VALUE> at glyph sequence OFFSET.
      Parameters:
        `offset` - offset (index) into glyph sequence
        `key` - predication key
        `value` - predication value

    - #### getPredication

          public java.lang.Object getPredication(int offset,
                                                 java.lang.String key)

      Get predication KEY at glyph sequence OFFSET.
      Parameters:
        `offset` - offset (index) into glyph sequence
        `key` - predication key
      Returns:
        predication KEY at OFFSET or null if none exists

    - #### compareGlyphs

          public int compareGlyphs(java.nio.IntBuffer gb)

      Compare glyphs.
      Parameters:
        `gb` - buffer containing glyph indices with which this glyph sequence's glyphs are to be compared
      Returns:
        zero if glyphs are the same, otherwise returns 1 or -1 according to whether this glyph sequence's glyphs are lexicographically greater or lesser than the glyphs in the specified string buffer

    - #### clone

          public java.lang.Object clone()

      Overrides:
        `clone` in class `java.lang.Object`

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### sameGlyphs

          public static boolean sameGlyphs(int[] ga1,
                                           int[] ga2)

      Determine if two arrays of glyphs are identical.
      Parameters:
        `ga1` - first glyph array
        `ga2` - second glyph array
      Returns:
        true if arrays are botth null or both non-null and have identical elements

    - #### concatGlyphs

          public static java.nio.IntBuffer concatGlyphs(int[] bga,
                                                        int[] iga,
                                                        int[] lga)

      Concatenante glyph arrays.
      Parameters:
        `bga` - backtrack glyph array
        `iga` - input glyph array
        `lga` - lookahead glyph array
      Returns:
        new integer buffer containing concatenated glyphs

    - #### concatAssociations

          public static java.util.List concatAssociations(CharAssociation[] baa,
                                                          CharAssociation[] iaa,
                                                          CharAssociation[] laa)

      Concatenante association arrays.
      Parameters:
        `baa` - backtrack association array
        `iaa` - input association array
        `laa` - lookahead association array
      Returns:
        new list containing concatenated associations

    - #### join

          public static GlyphSequence join(GlyphSequence gs,
                                           GlyphSequence[] sa)

      Join (concatenate) glyph sequences.
      Parameters:
        `gs` - original glyph sequence from which to reuse character array reference
        `sa` - array of glyph sequences, whose glyph arrays and association lists are to be concatenated
      Returns:
        new glyph sequence referring to character array of GS and concatenated glyphs and associations of SA

    - #### reorder

          public static GlyphSequence reorder(GlyphSequence gs,
                                              int source,
                                              int count,
                                              int target)

      Reorder sequence such that [SOURCE,SOURCE+COUNT) is moved just prior to TARGET.
      Parameters:
        `gs` - input sequence
        `source` - index of sub-sequence to reorder
        `count` - length of sub-sequence to reorder
        `target` - index to which source sub-sequence is to be moved
      Returns:
        reordered sequence (or original if no reordering performed)

Copyright 1999-2021 The Apache Software Foundation. All Rights Reserved.