gnu.java.awt.font.opentype

Class OpenTypeFont

Implemented Interfaces:
FontDelegate

public final class OpenTypeFont
extends Object
implements FontDelegate

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.

See Also:
Adobe’s OpenType specification, Apple’s TrueType specification

Field Summary

int
unitsPerEm
The number of font units per em.

Fields inherited from interface gnu.java.awt.font.FontDelegate

FLAG_FITTED, FLAG_NO_HINT_EDGE_POINTS, FLAG_NO_HINT_HORIZONTAL, FLAG_NO_HINT_STRONG_POINTS, FLAG_NO_HINT_VERTICAL, FLAG_NO_HINT_WEAK_POINTS

Method Summary

GlyphVector
createGlyphVector(Font font, FontRenderContext frc, CharacterIterator ci)
Creates a GlyphVector by mapping each character in a CharacterIterator to the corresponding glyph.
void
getAdvance(int glyphIndex, float pointSize, AffineTransform transform, boolean antialias, boolean fractionalMetrics, boolean horizontal, Point2D advance)
Determines the advance width for a glyph.
float
getAscent(float pointSize, AffineTransform transform, boolean antialiased, boolean fractionalMetrics, boolean horizontal)
Determines the distance between the base line and the highest ascender.
float
getDescent(float pointSize, AffineTransform transform, boolean antialiased, boolean fractionalMetrics, boolean horizontal)
Determines the distance between the base line and the lowest descender.
String
getFamilyName(Locale locale)
Returns the name of the family to which this font face belongs, for example “Univers”.
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.
String
getFullName(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.
int
getGlyphIndex(int c)
Returns the glyph code for the specified character.
String
getGlyphName(int glyphIndex)
Returns a name for the specified glyph.
GeneralPath
getGlyphOutline(int glyph, float pointSize, AffineTransform transform, boolean antialias, boolean fractionalMetrics, int flags)
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.
int
getNumGlyphs()
Returns the number of glyphs in this font face.
String
getPostScriptName()
Returns the PostScript name of this font face, for example “Univers-Light”.
Zone
getRawGlyphOutline(int glyph, AffineTransform transform)
Fetches the raw glyph outline for the specified glyph index.
String
getSubFamilyName(Locale locale)
Returns the name of this font face inside the family, for example “Light”.
int
getVersion()
Returns the version of the font.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

unitsPerEm

public int unitsPerEm
The number of font units per em. For fonts with TrueType outlines, this is usually a power of two (such as 2048). For OpenType fonts with PostScript outlines, other values are acceptable (such as 1000).

Method Details

createGlyphVector

public GlyphVector createGlyphVector(Font font,
                                     FontRenderContext frc,
                                     CharacterIterator ci)
Creates a GlyphVector by mapping each character in a CharacterIterator to the corresponding glyph.

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.

Specified by:
createGlyphVector in interface FontDelegate
Parameters:
font - 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.

getAdvance

public void getAdvance(int glyphIndex,
                       float pointSize,
                       AffineTransform transform,
                       boolean antialias,
                       boolean fractionalMetrics,
                       boolean horizontal,
                       Point2D advance)
Determines the advance width for a glyph.
Specified by:
getAdvance in interface FontDelegate
Parameters:
glyphIndex - 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.

getAscent

public float getAscent(float pointSize,
                       AffineTransform transform,
                       boolean antialiased,
                       boolean fractionalMetrics,
                       boolean horizontal)
Determines the distance between the base line and the highest ascender.
Specified by:
getAscent in interface FontDelegate
Parameters:
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.
antialiased - 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.
Returns:
the ascent, which usually is a positive number.

getDescent

public float getDescent(float pointSize,
                        AffineTransform transform,
                        boolean antialiased,
                        boolean fractionalMetrics,
                        boolean horizontal)
Determines the distance between the base line and the lowest descender.
Specified by:
getDescent in interface FontDelegate
Parameters:
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.
antialiased - 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.
Returns:
the descent, which usually is a nagative number.

getFamilyName

public String getFamilyName(Locale locale)
Returns the name of the family to which this font face belongs, for example “Univers”.
Specified by:
getFamilyName in interface FontDelegate
Parameters:
locale - the locale for which to localize the name.
Returns:
the family name.

getFontTable

public ByteBuffer getFontTable(int tag)
Creates a view buffer for an OpenType table. The caller can access the returned buffer without needing to synchronize access from multiple threads.
Parameters:
tag - the table identifier, for example OpenType.GLYF.
Returns:
a slice of the underlying buffer containing the table, or null if the font does not contain the requested table.

getFontTableSize

public int getFontTableSize(int tag)
Returns the size of one of the tables in the font, or -1 if the table does not exist.

getFullName

public String getFullName(Locale locale)
Returns the full name of this font face, for example “Univers Light”.
Specified by:
getFullName in interface FontDelegate
Parameters:
locale - the locale for which to localize the name.
Returns:
the face name.

getGlyph

public int getGlyph(int ucs4)
Looks up a glyph in the font’s 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.

Parameters:
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.
Returns:
the glyph index, or zero if the font does not contain a glyph for the specified codepoint.

getGlyphIndex

public int getGlyphIndex(int c)
Returns the glyph code for the specified character.
Specified by:
getGlyphIndex in interface FontDelegate
Parameters:
c - the character to map
Returns:
the glyph code

getGlyphName

public String getGlyphName(int glyphIndex)
Returns a name for the specified glyph. This is useful for generating PostScript or PDF files that embed some glyphs of a font.

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.

Specified by:
getGlyphName in interface FontDelegate
Parameters:
glyphIndex - the glyph whose name the caller wants to retrieve.

getGlyphOutline

public GeneralPath getGlyphOutline(int glyph,
                                   float pointSize,
                                   AffineTransform transform,
                                   boolean antialias,
                                   boolean fractionalMetrics,
                                   int flags)
Returns the shape of a glyph.
Specified by:
getGlyphOutline in interface FontDelegate
Parameters:
glyph - 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.
Returns:
the scaled and grid-fitted outline of the specified glyph, or null for bitmap fonts.

getMissingGlyphCode

public int getMissingGlyphCode()
Returns the index of the glyph which gets displayed if the font cannot map a Unicode code point to a glyph. Many fonts show this glyph as an empty box.
Specified by:
getMissingGlyphCode in interface FontDelegate

getNumGlyphs

public int getNumGlyphs()
Returns the number of glyphs in this font face.
Specified by:
getNumGlyphs in interface FontDelegate

getPostScriptName

public String getPostScriptName()
Returns the PostScript name of this font face, for example “Univers-Light”.
Specified by:
getPostScriptName in interface FontDelegate
Returns:
the PostScript name, or null if the font does not provide a PostScript name.

getRawGlyphOutline

public Zone getRawGlyphOutline(int glyph,
                               AffineTransform transform)
Fetches the raw glyph outline for the specified glyph index. This is used for the autofitter only ATM and is otherwise not usable for outside code.
Parameters:
glyph - the glyph index to fetch
transform - the transform to apply
Returns:
the raw outline of that glyph

getSubFamilyName

public String getSubFamilyName(Locale locale)
Returns the name of this font face inside the family, for example “Light”.
Specified by:
getSubFamilyName in interface FontDelegate
Parameters:
locale - the locale for which to localize the name.
Returns:
the name of the face inside its family.

getVersion

public int getVersion()
Returns the version of the font.
Returns:
the version in 16.16 fixed-point encoding, for example 0x00010000 for version 1.0.

OpenTypeFont.java -- Manages OpenType and TrueType fonts. Copyright (C) 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.