org.apache.fop.complexscripts.util

## Class GlyphSequence

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

All Implemented Interfaces:
  Cloneable

    public class GlyphSequence
    extends Object
    implements 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
`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(IntBuffer characters, IntBuffer glyphs, List associations)` Instantiate a glyph sequence, reusing (i.e., not copying) the referenced character and glyph buffers and associations.
`GlyphSequence(IntBuffer characters, IntBuffer glyphs, 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
`Object` `clone()`
`int` `compareGlyphs(IntBuffer gb)` Compare glyphs.
`static List` `concatAssociations(CharAssociation[] baa, CharAssociation[] iaa, CharAssociation[] laa)` Concatenante association arrays.
`static IntBuffer` `concatGlyphs(int[] bga, int[] iga, int[] lga)` Concatenante glyph arrays.
`CharAssociation` `getAssociation(int index)` Obtain association at specified index.
`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.
`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.
`IntBuffer` `getGlyphs()` Obtain reference to underlying glyph buffer.
`int[]` `getGlyphs(int offset, int count)` Obtain count glyphs starting at offset.
`Object` `getPredication(int offset, 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, String key, Object value)` Set predication <KEY,VALUE> at glyph sequence OFFSET.
`void` `setPredications(boolean enable)` Enable or disable predications.
`void` `setUnprocessedGS(GlyphSequence glyphSequence)`
`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(IntBuffer characters,
                         IntBuffer glyphs,
                         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(IntBuffer characters,
                         IntBuffer glyphs,
                         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 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 IndexOutOfBoundsException

Obtain glyph id at specified index.

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

#### getUnprocessedGlyph

    public int getUnprocessedGlyph(int index)
                            throws IndexOutOfBoundsException

Throws:
  `IndexOutOfBoundsException`

#### setUnprocessedGS

    public void setUnprocessedGS(GlyphSequence glyphSequence)

#### setGlyph

    public void setGlyph(int index,
                         int gi)
                  throws IndexOutOfBoundsException

Set glyph id at specified index.

Parameters:
  `index` - to set glyph
  `gi` - glyph index
Throws:
  `IndexOutOfBoundsException` - if index is greater or equal to the limit of the underlying glyph buffer

#### getGlyphs

    public 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 IndexOutOfBoundsException

Obtain association at specified index.

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

#### getAssociations

    public 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,
                               String key,
                               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 Object getPredication(int offset,
                                 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(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 Object clone()

Overrides:
  `clone` in class `Object`

#### toString

    public String toString()

Overrides:
  `toString` in class `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 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 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)