Class GlyphSequence
java.lang.Object
org.apache.fop.complexscripts.util.GlyphSequence
- All Implemented Interfaces:
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
-
Constructor Summary
ConstructorDescriptionGlyphSequence
(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.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. -
Method Summary
Modifier and TypeMethodDescriptionclone()
int
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.getAssociation
(int index) Obtain association at specified index.Obtain reference to underlying associations list.getAssociations
(int offset, int count) Obtain count associations starting at offset.int[]
getCharacterArray
(boolean copy) Obtain array of characters.int
Obtain the number of characters in character array, where each character constitutes a unicode scalar value.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
Obtain the number of glyphs in glyphs array, where each glyph constitutes a font specific glyph index.Obtain reference to underlying glyph buffer.int[]
getGlyphs
(int offset, int count) Obtain count glyphs starting at offset.getPredication
(int offset, String key) Get predication KEY at glyph sequence OFFSET.boolean
Obtain predications state.int
getUnprocessedGlyph
(int index) int
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) toString()
-
Field Details
-
unprocessedGS
-
-
Constructor Details
-
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) charactersglyphs
- a (possibly null) buffer of glyphsassociations
- a (possibly null) array of glyph to character associationspredications
- true if predications are enabled
-
GlyphSequence
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) charactersglyphs
- a (possibly null) buffer of glyphsassociations
- a (possibly null) array of glyph to character associations
-
GlyphSequence
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 sequencebga
- backtrack glyph arrayiga
- input glyph arraylga
- lookahead glyph arraybal
- backtrack association listial
- input association listlal
- lookahead association list
-
-
Method Details
-
getCharacters
Obtain reference to underlying character buffer.- Returns:
- character buffer reference
-
getCharacterArray
public int[] getCharacterArray(boolean copy) Obtain array of characters. Ifcopy
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, usegetCharacterCount()
.- 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
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
- Throws:
IndexOutOfBoundsException
-
setUnprocessedGS
-
setGlyph
Set glyph id at specified index.- Parameters:
index
- to set glyphgi
- glyph index- Throws:
IndexOutOfBoundsException
- if index is greater or equal to the limit of the underlying glyph buffer
-
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. Ifcount
is negative, then it is treated as if the number of available glyphs were specified.- Parameters:
offset
- into glyph sequencecount
- 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. Ifcopy
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, usegetGlyphCount()
.- 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
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
Obtain reference to underlying associations list.- Returns:
- associations list
-
getAssociations
Obtain count associations starting at offset.- Parameters:
offset
- into glyph sequencecount
- 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
Set predication <KEY,VALUE> at glyph sequence OFFSET.- Parameters:
offset
- offset (index) into glyph sequencekey
- predication keyvalue
- predication value
-
getPredication
Get predication KEY at glyph sequence OFFSET.- Parameters:
offset
- offset (index) into glyph sequencekey
- predication key- Returns:
- predication KEY at OFFSET or null if none exists
-
compareGlyphs
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
-
toString
-
sameGlyphs
public static boolean sameGlyphs(int[] ga1, int[] ga2) Determine if two arrays of glyphs are identical.- Parameters:
ga1
- first glyph arrayga2
- second glyph array- Returns:
- true if arrays are botth null or both non-null and have identical elements
-
concatGlyphs
Concatenante glyph arrays.- Parameters:
bga
- backtrack glyph arrayiga
- input glyph arraylga
- 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 arrayiaa
- input association arraylaa
- lookahead association array- Returns:
- new list containing concatenated associations
-
join
Join (concatenate) glyph sequences.- Parameters:
gs
- original glyph sequence from which to reuse character array referencesa
- 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
Reorder sequence such that [SOURCE,SOURCE+COUNT) is moved just prior to TARGET.- Parameters:
gs
- input sequencesource
- index of sub-sequence to reordercount
- length of sub-sequence to reordertarget
- index to which source sub-sequence is to be moved- Returns:
- reordered sequence (or original if no reordering performed)
-