Class Cmap
- java.lang.Object
-
- com.adobe.fontengine.font.opentype.Table
-
- com.adobe.fontengine.font.opentype.Cmap
-
public final class Cmap extends Table
Gives access to a 'cmap' table.Encoding forms support
A number of subtable formats are designed to combine the decoding of a character stream and the computation of the glyph ID. For example, format 8 is geared to support encoding forms with one or two 16 bits code units (such as UTF-16) and has a 64K bit array to indicate those code units which represent a code point on their own and those code units which are the first of a pair. The idea is that the details of the encoding form can be captured in the font.
Our point of view is that encoding forms are not the business of fonts, so we ignore those parts of those formats.
Version handling
'cmap' tables have only a minor version number. This implementation:
- fully supports version 0 tables
- interprets version x > 0 tables as version 0 tables
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Cmap.CmapSelector
Class used to receive the list of recognized subtables in this cmap table.static class
Cmap.MacEncodingID
static class
Cmap.MS_EncodingID
static class
Cmap.PlatformID
Enum classes for the various platformIDs and encodingIDs.static class
Cmap.UnicodeEncodingID
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
char2glyph(int ch, int index)
int
coolTypeUnicodeChar2glyph(int usv)
Approximates CoolType's interpretation of cmaps.void
enumerateCmaps(Cmap.CmapSelector selector)
Enumerate the cmaps contained in the cmap table.int
getCmapSubtableIndex(int platformId, int encodingId)
int
getHighestMappedCode(int stOffset, boolean max2bytes)
Get the character code that is the highest that is mapped by the cmap found at stOffset.int
getLowestMappedCode(int stOffset)
Get the character code that is the lowest that is mapped by the cmap found at stOffset.int
getMapping(int stOffset, int charCode)
Get the glyphID for charCode using the subtable at stOffset.int
getOffset(int subtableIndex)
int[]
glyph2char(int numGlyphs, int index)
Get the inverted mapping from glyphs to characters for one subtable.boolean
isSymbolic()
Tell whether the font is symbolic.int
probe(int platformID, int encodingID)
Return the offset of a give cmap subtable if present, -1 otherwise.void
stream(Map tables)
void
streamForSWF(Map tables, int numGlyphs)
void
subsetAndStream(Subset subset, SubsetSimpleTrueType ttSubset, Map tables)
In the SubsetSimpleTrueType case, the client will have provided a cmap and a set of codepoints to map against it.void
subsetAndStreamForSWF(TreeSet codePoints, Subset subset, Map tables, boolean includeVariationCmap)
int
unicodeChar2glyph(int usv)
Get the glyph mapped from a given character.
-
-
-
Method Detail
-
probe
public int probe(int platformID, int encodingID) throws InvalidFontException, UnsupportedFontException
Return the offset of a give cmap subtable if present, -1 otherwise.
-
isSymbolic
public boolean isSymbolic() throws UnsupportedFontException, InvalidFontException
Tell whether the font is symbolic.
-
enumerateCmaps
public void enumerateCmaps(Cmap.CmapSelector selector) throws UnsupportedFontException, InvalidFontException
Enumerate the cmaps contained in the cmap table. Call the selector's cmapFound method for each recognized platform id/encoding id combination.- Parameters:
selector
-- Throws:
UnsupportedFontException
InvalidFontException
-
getCmapSubtableIndex
public int getCmapSubtableIndex(int platformId, int encodingId) throws InvalidFontException
- Throws:
InvalidFontException
-
unicodeChar2glyph
public int unicodeChar2glyph(int usv) throws UnsupportedFontException, InvalidFontException
Get the glyph mapped from a given character.- Parameters:
usv
- the Unicode scalar value to look up- Returns:
- the gid of the glyph mapped from
usv
, 0 if not mapped. Note that this is the true OpenType gid, even in the case of cid cff otf. It is NOT the cid. - Throws:
UnsupportedFontException
InvalidFontException
-
coolTypeUnicodeChar2glyph
public int coolTypeUnicodeChar2glyph(int usv) throws UnsupportedFontException, InvalidFontException
Approximates CoolType's interpretation of cmaps. This approximation is fairly incomplete: for example, CoolType has some heuristics to interpret the cmaps of Win 3.1 ME fonts (which have an MS/Symbol cmap that follows some conventions and are marked with high order bits in OS/2.fsSelection).
-
char2glyph
public int char2glyph(int ch, int index) throws UnsupportedFontException, InvalidFontException
-
getLowestMappedCode
public int getLowestMappedCode(int stOffset) throws UnsupportedFontException, InvalidFontException
Get the character code that is the lowest that is mapped by the cmap found at stOffset.
-
getHighestMappedCode
public int getHighestMappedCode(int stOffset, boolean max2bytes) throws UnsupportedFontException, InvalidFontException
Get the character code that is the highest that is mapped by the cmap found at stOffset. If max2bytes is true, the highest code that is at most 2 bytes is returned.
-
getMapping
public int getMapping(int stOffset, int charCode) throws UnsupportedFontException, InvalidFontException
Get the glyphID for charCode using the subtable at stOffset.- Parameters:
stOffset
- the offset (in the cmap table) of the subtable to usecharCode
- the character code to map- Returns:
- the glyphID for
charCode
- Throws:
UnsupportedFontException
InvalidFontException
-
getOffset
public int getOffset(int subtableIndex) throws InvalidFontException, UnsupportedFontException
-
glyph2char
public int[] glyph2char(int numGlyphs, int index) throws UnsupportedFontException, InvalidFontException
Get the inverted mapping from glyphs to characters for one subtable. The subtable, identified byindex
must be present.- Parameters:
numGlyphs
- the number of glyphs in the fontindex
- the index of the cmap to invert- Returns:
- array of
numGlyphs
integers, mapping glyphIDs to characters; if a glyphs is not mapped by the subtable, the value in this array is -1.
- Throws:
UnsupportedFontException
InvalidFontException
-
subsetAndStream
public void subsetAndStream(Subset subset, SubsetSimpleTrueType ttSubset, Map tables) throws UnsupportedFontException, InvalidFontException
In the SubsetSimpleTrueType case, the client will have provided a cmap and a set of codepoints to map against it. We will convert these to relate to the new subset GlyphIDs stored in the OTSubset. We don't bother to emit cmaps in any other case than the SubsetSimpleTrueType case.
-
subsetAndStreamForSWF
public void subsetAndStreamForSWF(TreeSet codePoints, Subset subset, Map tables, boolean includeVariationCmap) throws UnsupportedFontException, InvalidFontException
-
stream
public void stream(Map tables)
-
streamForSWF
public void streamForSWF(Map tables, int numGlyphs) throws UnsupportedFontException, InvalidFontException
-
-