org.foray.ps.encode
Class EncodingVector4a

java.lang.Object
  extended by org.foray.ps.encode.EncodingVector4a
All Implemented Interfaces:
Serializable, org.axsl.ps.Encoding, org.axsl.ps.PsEncoding
Direct Known Subclasses:
EncodingCE, EncodingCustom, EncodingExpert, EncodingExpertSubset, EncodingFOrayLatinExtra, EncodingISOLatin1, EncodingMacExpert, EncodingMacRoman, EncodingMacStandard, EncodingPDFDoc, EncodingStandard, EncodingSymbol, EncodingWinAnsi, EncodingZapfDingbats

public abstract class EncodingVector4a
extends Object
implements org.axsl.ps.PsEncoding, Serializable

Encoding instances provide some standard encoding resources for PostScript. When a PostScript file is parsed, the characters in a string are really indices into an array of glyph names, which are in turn the keys to entries in a glyph dictionary. Input to a PostScript interpreter is not really characters, but rather character indexes. (The two might be the same, especially for ASCII characters).

So the PostScript interpreter uses a two-step process, as follows: 1. It conceptually maps character codes (integer values) to name objects like /A or /Uacute. This map is known as an "encoding". There are several standard encoding schemes defined in the PostScript standard that each interpreter must know how to handle. Those are provided as Encoding subclasses. 2. The name objects created in step 1 are then used as the key into a dictionary (contained in the Font dictionary) whose values contain the PostScript instructions needed to actually paint the glyph.

Nowhere in the above scheme is Unicode encoding contemplated or supported. Applications that create PostScript output from Unicode input need a way to convert from that Unicode input to the indexes that are expected for by the selected encoding. The closest resource that we have for this purpose is the standard glyph lists supplied by Adobe.

The canonical method for mapping a Unicode code point to a PostScript encoding index would be:

  1. Use the Adobe Glyph List (or another glyph list) to obtain the glyph name for a given Unicode code point.
  2. Use an Encoding instance to obtain the index in that Encoding for the glyph name obtained above.

However, for efficiency, an Encoding combines the above two steps and provides a direct mapping from a Unicode code point to the encoded index. Two parallel arrays are used to make this process efficient. The first is a an array of all Unicode code points supported in the Encoding. This array is sorted for fast searching. The second array provides the encoded index for the Unicode code point in the first array. Methods are provided to encode and decode characters.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.axsl.ps.PsEncoding
org.axsl.ps.PsEncoding.Predefined
 
Field Summary
static String NOTDEF
          The name of the undefined glyph.
 
Fields inherited from interface org.axsl.ps.Encoding
INVALID_UNICODE_CHAR
 
Constructor Summary
EncodingVector4a(String name, List<org.axsl.ps.GlyphList> sourceGlyphLists, char[] codePoints, char[] codePointIndexes)
          Create a new Encoding instance.
 
Method Summary
 String asPostScript(org.axsl.ps.Encoding baseEncoding)
           
 org.axsl.ps.PsEncoding bestBaseEncodingPdf()
           
 boolean canEncode(int codePoint)
           
 int decodeCharacter(int encodedIndex)
           
 int encodeCharacter(int codePoint)
           
 int getFirstIndex()
           
 String[] getGlyphNames()
           
 int getLastIndex()
           
 String getName()
           
 boolean isPredefinedPdf()
           
 boolean isPredefinedPs()
           
abstract  boolean isStatic()
          Indicates whether the data in this encoding vector is static, that is, tied entirely to the class itself and not built dynamically.
 boolean isSubsetOf(org.axsl.ps.PsEncoding otherVector)
           
 String mapCodePointToGlyphName(int codePoint)
           
 String mapCodePointToGlyphName(List<org.axsl.ps.GlyphList> glyphLists, int codePoint)
          Finds the glyph name for a given Unicode code point by searching an array of GlyphList instances for it.
 char mapGlyphNameToCodePoint(List<org.axsl.ps.GlyphList> glyphLists, String glyphName)
          Finds the Unicode code for a glyphName by searching an array of GlyphList instances for it.
 int size()
          Returns the number of entries in this encoding.
 void sortCodePoints(char[] codePoints, char[] codePointIndexes)
          Sorts the codePoints array by its contents, and sorts the parallel codePointIndexes arrays in a parallel manner, keeping its elements synchronized with those in codePoints.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.axsl.ps.PsEncoding
getPredefinedType
 

Field Detail

NOTDEF

public static final String NOTDEF
The name of the undefined glyph.

See Also:
Constant Field Values
Constructor Detail

EncodingVector4a

public EncodingVector4a(String name,
                        List<org.axsl.ps.GlyphList> sourceGlyphLists,
                        char[] codePoints,
                        char[] codePointIndexes)
Create a new Encoding instance.

Parameters:
name - The name of this encoding. This name is not used by the system, but may be useful for debugging.
sourceGlyphLists - The GlyphList instances that were used to create this encoding.
codePoints - The array of Unicode code points supported by this encoding.
codePointIndexes - The array of encoded indexes that is parallel to codePoints. codePointIndexes[n] should contain the encoded index that corresponds to the Unicode code point at codePoints[n].
Method Detail

getName

public String getName()
Specified by:
getName in interface org.axsl.ps.Encoding

encodeCharacter

public int encodeCharacter(int codePoint)
Specified by:
encodeCharacter in interface org.axsl.ps.Encoding

decodeCharacter

public int decodeCharacter(int encodedIndex)
Specified by:
decodeCharacter in interface org.axsl.ps.Encoding

size

public int size()
Returns the number of entries in this encoding.

Returns:
The number of entries in this encoding.

getGlyphNames

public String[] getGlyphNames()
Specified by:
getGlyphNames in interface org.axsl.ps.PsEncoding

getFirstIndex

public int getFirstIndex()
Specified by:
getFirstIndex in interface org.axsl.ps.Encoding

getLastIndex

public int getLastIndex()
Specified by:
getLastIndex in interface org.axsl.ps.Encoding

sortCodePoints

public void sortCodePoints(char[] codePoints,
                           char[] codePointIndexes)
Sorts the codePoints array by its contents, and sorts the parallel codePointIndexes arrays in a parallel manner, keeping its elements synchronized with those in codePoints.

Parameters:
codePoints - The array of Unicode code points to be sorted.
codePointIndexes - The array of encoding indexes that whose elements correspond to elements in codePoints.

asPostScript

public String asPostScript(org.axsl.ps.Encoding baseEncoding)
Specified by:
asPostScript in interface org.axsl.ps.Encoding

mapCodePointToGlyphName

public String mapCodePointToGlyphName(int codePoint)
Specified by:
mapCodePointToGlyphName in interface org.axsl.ps.PsEncoding

bestBaseEncodingPdf

public org.axsl.ps.PsEncoding bestBaseEncodingPdf()
Specified by:
bestBaseEncodingPdf in interface org.axsl.ps.PsEncoding

isSubsetOf

public boolean isSubsetOf(org.axsl.ps.PsEncoding otherVector)
Specified by:
isSubsetOf in interface org.axsl.ps.PsEncoding

isStatic

public abstract boolean isStatic()
Indicates whether the data in this encoding vector is static, that is, tied entirely to the class itself and not built dynamically. This is used primarily to determine whether the instance should actually be serialized.

Returns:
True iff all data in this encoding vector is static and does not need to be serialized.

isPredefinedPs

public boolean isPredefinedPs()
Specified by:
isPredefinedPs in interface org.axsl.ps.Encoding

isPredefinedPdf

public boolean isPredefinedPdf()
Specified by:
isPredefinedPdf in interface org.axsl.ps.Encoding

canEncode

public boolean canEncode(int codePoint)
Specified by:
canEncode in interface org.axsl.ps.Encoding

mapCodePointToGlyphName

public String mapCodePointToGlyphName(List<org.axsl.ps.GlyphList> glyphLists,
                                      int codePoint)
Finds the glyph name for a given Unicode code point by searching an array of GlyphList instances for it.

Parameters:
glyphLists - An array of GlyphList instances which should be tried.
codePoint - The Unicode code point for which a glyph name is sought.
Returns:
The glyph name which corresponds to codePoint, or null if there is none.

mapGlyphNameToCodePoint

public char mapGlyphNameToCodePoint(List<org.axsl.ps.GlyphList> glyphLists,
                                    String glyphName)
Finds the Unicode code for a glyphName by searching an array of GlyphList instances for it.

Parameters:
glyphLists - An array of GlyphList instances which should be tried.
glyphName - The glyph name for which a Unicode code point is sought.
Returns:
The Unicode code point which corresponds to glyphName, or Encoding.INVALID_UNICODE_CHAR if there is none.


Copyright © 2017. All rights reserved.