|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--gnu.java.awt.font.opentype.OpenTypeFont
A font that takes its data from OpenType or TrueType font tables.
OpenType is an extension of the TrueType font format. In addition to tables for names, kerning or layout, it also stores the shapes of individual glyphs. Three formats are recognized for glyphs: Quadratic splines (classic TrueType), cubic splines (PostScript), and bitmaps.
| Field Summary | |
(package private) java.nio.ByteBuffer |
buf
A buffer containing the font data. |
private CharGlyphMap |
cmap
A delegate object for mapping Unicode UCS-4 codepoints to glyph IDs. |
private float |
emsPerUnit
A factor to convert font units into ems. |
private GlyphNamer |
glyphNamer
A delegate object for providing a name for each glyph. |
private java.nio.ByteBuffer |
nameTable
The font’s name table, or null if this
table has not yet been accessed. |
(package private) int |
numGlyphs
The number of glyphs in this font. |
private Scaler |
scaler
The scaler to which the actual scaling work is delegated. |
(package private) int[] |
tableLength
|
(package private) int[] |
tableStart
|
(package private) int[] |
tableTag
|
(package private) static int |
TAG_OTTO
|
(package private) static int |
TAG_SFNT
|
(package private) static int |
TAG_TRUE
|
(package private) static int |
TAG_TTCF
|
(package private) static int |
TAG_ZAPF
|
private int |
unitsPerEm
The number of font units per em. |
private int |
version
The version of the font in 16.16 fixed-point encoding, for example 0x00010000 for version 1.0. |
| Constructor Summary | |
(package private) |
OpenTypeFont(java.nio.ByteBuffer buf,
int offsetTablePosition)
Constructs an OpenType or TrueType font. |
| Method Summary | |
java.awt.font.GlyphVector |
createGlyphVector(java.awt.Font font,
java.awt.font.FontRenderContext frc,
java.text.CharacterIterator ci)
Creates a GlyphVector by mapping each character in a CharacterIterator to the corresponding glyph. |
void |
getAdvance(int glyphIndex,
float pointSize,
java.awt.geom.AffineTransform transform,
boolean antialias,
boolean fractionalMetrics,
boolean horizontal,
java.awt.geom.Point2D advance)
Determines the advance width for a glyph. |
float |
getAscent(float pointSize,
java.awt.geom.AffineTransform transform,
boolean antialiased,
boolean fractionalMetrics,
boolean horizontal)
Determines the distance between the base line and the highest ascender. |
private CharGlyphMap |
getCharGlyphMap()
|
float |
getDescent(float pointSize,
java.awt.geom.AffineTransform transform,
boolean antialiased,
boolean fractionalMetrics,
boolean horizontal)
Determines the distance between the base line and the lowest descender. |
java.lang.String |
getFamilyName(java.util.Locale locale)
Returns the name of the family to which this font face belongs, for example “Univers”. |
java.nio.ByteBuffer |
getFontTable(int tag)
Creates a view buffer for an OpenType table. |
int |
getFontTableSize(int tag)
Returns the size of one of the tables in the font, or -1 if the table does not exist. |
java.lang.String |
getFullName(java.util.Locale locale)
Returns the full name of this font face, for example “Univers Light”. |
int |
getGlyph(int ucs4)
Looks up a glyph in the font’s cmap tables,
without performing any glyph substitution or reordering. |
java.lang.String |
getGlyphName(int glyphIndex)
Returns a name for the specified glyph. |
java.awt.geom.GeneralPath |
getGlyphOutline(int glyph,
float pointSize,
java.awt.geom.AffineTransform transform,
boolean antialias,
boolean fractionalMetrics)
Returns the shape of a glyph. |
int |
getMissingGlyphCode()
Returns the index of the glyph which gets displayed if the font cannot map a Unicode code point to a glyph. |
private java.lang.String |
getName(int name,
java.util.Locale locale)
Extracts a String from the font’s name table. |
int |
getNumGlyphs()
Returns the number of glyphs in this font face. |
java.lang.String |
getPostScriptName()
Returns the PostScript name of this font face, for example “Univers-Light”. |
java.lang.String |
getSubFamilyName(java.util.Locale locale)
Returns the name of this font face inside the family, for example “Light”. |
private int |
getTableIndex(int tag)
Determines the index of a table into the offset table. |
int |
getVersion()
Returns the version of the font. |
(package private) static java.lang.String |
tagToString(int tag)
Converts a four-byte tag identifier into a String that can be displayed when debugging this class. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
static final int TAG_OTTO
static final int TAG_SFNT
static final int TAG_TRUE
static final int TAG_TTCF
static final int TAG_ZAPF
java.nio.ByteBuffer buf
final int numGlyphs
int[] tableTag
int[] tableStart
int[] tableLength
private int version
private int unitsPerEm
private float emsPerUnit
1 /
unitsPerEm.
private Scaler scaler
private CharGlyphMap cmap
private GlyphNamer glyphNamer
private java.nio.ByteBuffer nameTable
null if this
table has not yet been accessed.
| Constructor Detail |
OpenTypeFont(java.nio.ByteBuffer buf,
int offsetTablePosition)
throws java.awt.FontFormatException
buf - a buffer with the contents of the font file. It is
recommended to use a MappedByteBuffer for very
large font files.offsetTablePosition - the position of the OpenType offset
table in the font file. The offset table of most OpenType and
TrueType fonts starts at position 0. However, so-called TrueType
Collections support multiple OpenType fonts in a single file,
which allows sharing some glyphs between fonts. If many glyphs
are shared (for example all the Kanji glyphs between multiple
Japanese fonts), the space savings can be considerable. In that
case, the offset table of each individual font would start at its
own position.
java.awt.FontFormatException - if the font data is
not in OpenType or TrueType format.| Method Detail |
private int getTableIndex(int tag)
tableStart[getTableIndex(TAG_NAME)].
tag - the table identifier, for instance
OpenType.TAG_NAME.
tag.public java.lang.String getFamilyName(java.util.Locale locale)
getFamilyName in interface FontDelegatelocale - the locale for which to localize the name.
public java.lang.String getSubFamilyName(java.util.Locale locale)
getSubFamilyName in interface FontDelegatelocale - the locale for which to localize the name.
public java.lang.String getFullName(java.util.Locale locale)
getFullName in interface FontDelegatelocale - the locale for which to localize the name.
public java.lang.String getPostScriptName()
getPostScriptName in interface FontDelegatenull if the font
does not provide a PostScript name.public int getNumGlyphs()
getNumGlyphs in interface FontDelegatepublic int getMissingGlyphCode()
getMissingGlyphCode in interface FontDelegate
private java.lang.String getName(int name,
java.util.Locale locale)
name - the numeric TrueType or OpenType name ID.locale - the locale for which names shall be localized, or
null if the locale does mot matter because the name
is known to be language-independent (for example, because it is
the PostScript name).public int getVersion()
OpenType.getVersion()public java.nio.ByteBuffer getFontTable(int tag)
tag - the table identifier, for example
OpenType.GLYF.
null if the font does not contain the requested
table.public int getFontTableSize(int tag)
private CharGlyphMap getCharGlyphMap()
public int getGlyph(int ucs4)
cmap tables,
without performing any glyph substitution or reordering. Because
of this limitation, this method cannot be used for script systems
that need advanced glyph mapping, such as Arabic, Korean, or even
Latin with exotic accents.
It is safe to call this method from any thread.
ucs4 - the Unicode codepoint in the 32-bit Unicode character
set UCS-4. Because UTF-16 surrogates do not correspond to a single
glyph, it does not make sense to pass them here.
public java.awt.font.GlyphVector createGlyphVector(java.awt.Font font,
java.awt.font.FontRenderContext frc,
java.text.CharacterIterator ci)
The mapping takes only the font’s cmap
tables into consideration. No other operations (such as glyph
re-ordering, composition, or ligature substitution) are
performed. This means that the resulting GlyphVector will not be
correct for text in languages that have complex
character-to-glyph mappings, such as Arabic, Hebrew, Hindi, or
Thai.
createGlyphVector in interface FontDelegatefont - the font object that the created GlyphVector
will return when it gets asked for its font. This argument is
needed because the public API works with java.awt.Font,
not with some private delegate like OpenTypeFont.frc - the font rendering parameters that are used for
measuring glyphs. The exact placement of text slightly depends on
device-specific characteristics, for instance the device
resolution or anti-aliasing. For this reason, any measurements
will only be accurate if the passed
FontRenderContext correctly reflects the relevant
parameters. Hence, frc should be obtained from the
same Graphics2D that will be used for drawing, and
any rendering hints should be set to the desired values before
obtaining frc.ci - a CharacterIterator for iterating over the
characters to be displayed.
public void getAdvance(int glyphIndex,
float pointSize,
java.awt.geom.AffineTransform transform,
boolean antialias,
boolean fractionalMetrics,
boolean horizontal,
java.awt.geom.Point2D advance)
getAdvance in interface FontDelegateglyphIndex - the glyph whose advance width is to be
determined.pointSize - the point size of the font.transform - a transform that is applied in addition to
scaling to the specified point size. This is often used for
scaling according to the device resolution. Those who lack any
aesthetic sense may also use the transform to slant or stretch
glyphs.antialias - true for anti-aliased rendering,
false for normal rendering. For hinted fonts,
this parameter may indeed affect the result.fractionalMetrics - true for fractional metrics,
false for rounding the result to a pixel boundary.horizontal - true for horizontal line layout,
false for vertical line layout.advance - a point whose x and y
fields will hold the advance in each direction. It is possible
that both values are non-zero, for example if
transform is a rotation, or in the case of Urdu
fonts.
public java.awt.geom.GeneralPath getGlyphOutline(int glyph,
float pointSize,
java.awt.geom.AffineTransform transform,
boolean antialias,
boolean fractionalMetrics)
getGlyphOutline in interface FontDelegatepointSize - the point size of the font.transform - a transform that is applied in addition to
scaling to the specified point size. This is often used for
scaling according to the device resolution. Those who lack any
aesthetic sense may also use the transform to slant or stretch
glyphs.antialias - true for anti-aliased rendering,
false for normal rendering. For hinted fonts, this
parameter may indeed affect the result.fractionalMetrics - true for fractional
metrics, false for rounding the result to a pixel
boundary.glyph - the glyph whose advance width is to be
determined.
null for bitmap fonts.public java.lang.String getGlyphName(int glyphIndex)
Names are not unique: Under some rare circumstances, the same name can be returned for different glyphs. It is therefore recommended that printer drivers check whether the same name has already been returned for antoher glyph, and make the name unique by adding the string ".alt" followed by the glyph index.
This situation would occur for an OpenType or TrueType font
that has a post table of format 3 and provides a
mapping from glyph IDs to Unicode sequences through a
Zapf table. If the same sequence of Unicode
codepoints leads to different glyphs (depending on contextual
position, for example, or on typographic sophistication level),
the same name would get synthesized for those glyphs.
getGlyphName in interface FontDelegateglyphIndex - the glyph whose name the caller wants to
retrieve.
public float getAscent(float pointSize,
java.awt.geom.AffineTransform transform,
boolean antialiased,
boolean fractionalMetrics,
boolean horizontal)
getAscent in interface FontDelegatepointSize - the point size of the font.transform - a transform that is applied in addition to
scaling to the specified point size. This is often used for
scaling according to the device resolution. Those who lack any
aesthetic sense may also use the transform to slant or stretch
glyphs.fractionalMetrics - true for fractional metrics,
false for rounding the result to a pixel boundary.horizontal - true for horizontal line layout,
false for vertical line layout.
public float getDescent(float pointSize,
java.awt.geom.AffineTransform transform,
boolean antialiased,
boolean fractionalMetrics,
boolean horizontal)
getDescent in interface FontDelegatepointSize - the point size of the font.transform - a transform that is applied in addition to
scaling to the specified point size. This is often used for
scaling according to the device resolution. Those who lack any
aesthetic sense may also use the transform to slant or stretch
glyphs.fractionalMetrics - true for fractional metrics,
false for rounding the result to a pixel boundary.horizontal - true for horizontal line layout,
false for vertical line layout.
static java.lang.String tagToString(int tag)
tag - the tag as an int.
name or glyf.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||