org.apache.fop.fonts

## Class CustomFont

- java.lang.Object
- - org.apache.fop.fonts.Typeface
  - - org.apache.fop.fonts.CustomFont

All Implemented Interfaces:
  FontDescriptor, FontMetrics, MutableFont

Direct Known Subclasses:
  CIDFont, SingleByteFont

    public abstract class CustomFont
    extends Typeface
    implements FontDescriptor, MutableFont

Abstract base class for custom fonts loaded from files, for example.

### Field Summary

Fields
`protected List<SimpleSingleByteEncoding>` `additionalEncodings`
`protected List<CMapSegment>` `cmap` the character map, mapping Unicode ranges to glyph indices.
`protected Map<Integer,SVGGlyphData>` `svgs`
`protected Map<Character,SingleByteFont.UnencodedCharacter>` `unencodedCharacters`

### Fields inherited from class org.apache.fop.fonts.Typeface

`eventListener, NOT_FOUND`

### Constructor Summary

Constructors
Constructor and Description
`CustomFont(InternalResourceResolver resourceResolver)`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`void` `addUnencodedCharacter(NamedCharacter ch, int width, Rectangle bbox)` Adds an unencoded character (one that is not supported by the primary encoding).
`SimpleSingleByteEncoding` `getAdditionalEncoding(int index)` Returns an additional encoding.
`int` `getAdditionalEncodingCount()` Returns the number of additional encodings this single-byte font maintains.
`int` `getAscender()` Returns the ascender value of the font.
`int` `getAscender(int size)` Returns the ascent of the font described by this FontMetrics object.
`int` `getCapHeight()` Returns the capital height of the font.
`int` `getCapHeight(int size)` Returns the size of a capital letter measured from the font's baseline.
`CMapSegment[]` `getCMap()` Returns the character map for this font.
`int` `getDescender()` Returns the descender value of the font.
`int` `getDescender(int size)` Returns the descent of the font described by this FontMetrics object.
`EmbeddingMode` `getEmbeddingMode()` Returns the embedding mode for this font.
`URI` `getEmbedFileURI()` Returns an URI representing an embeddable font file.
`String` `getEmbedFontName()` Returns the font name for font embedding (may include a prefix, Example: "1E28bcArialMT").
`String` `getEmbedResourceName()` Returns the lookup name to an embeddable font file available as a resource.
`Set<String>` `getFamilyNames()` Returns the font family names.
`int` `getFirstChar()` Returns the index of the first character defined in this font.
`int` `getFlags()` Returns the flags for the font.
`int[]` `getFontBBox()` Returns the font's bounding box.
`String` `getFontName()` Returns the "PostScript" font name (Example: "Helvetica-BoldOblique").
`String` `getFontSubName()` Returns font's subfamily name.
`FontType` `getFontType()` Returns the type of the font.
`URI` `getFontURI()` Returns the URI of the font file from which these metrics were loaded.
`String` `getFullName()` Returns the font's full name (Example: "Helvetica Bold Oblique").
`InputStream` `getInputStream()` Returns an `InputStream` representing an embeddable font file.
`int` `getItalicAngle()` Returns the italic angle for the font.
`Map<Integer,Map<Integer,Integer>>` `getKerningInfo()` Returns the kerning map for the font.
`int` `getLastChar()` Returns the index of the last character defined in this font.
`int` `getMissingWidth()` Returns the width to be used when no width is available.
`boolean` `getSimulateStyle()`
`int` `getStemV()` Returns the vertical stem width for the font.
`int` `getStrikeoutPosition(int size)` Returns the distance from the baseline to the center of the strikeout line (negative value indicates below baseline).
`int` `getStrikeoutThickness(int size)` Returns the thickness of the strikeout line.
`String` `getStrippedFontName()` Returns the font family name stripped of whitespace.
`int` `getUnderlinePosition(int size)` Returns the distance from the baseline to the center of the underline (negative value indicates below baseline).
`int` `getUnderlineThickness(int size)` Returns the thickness of the underline.
`abstract char` `getUnicodeFromGID(int glyphIndex)` Returns the character from it's original glyph index in the font
`abstract Map<Integer,Integer>` `getUsedGlyphs()` Returns a Map of used Glyphs.
`int` `getWeight()` Returns the font weight (100, 200...800, 900).
`int` `getXHeight(int size)` Determines the typical font height of this FontMetrics object
`boolean` `hasAdditionalEncodings()` Indicates whether the encoding has additional encodings besides the primary encoding.
`boolean` `hasKerningInfo()` Indicates if the font has kerning information.
`boolean` `hasSVG()`
`boolean` `isAdvancedEnabled()` Used to determine if advanced typographic features are enabled.
`boolean` `isKerningEnabled()` Used to determine if kerning is enabled.
`boolean` `isSymbolicFont()` Indicates whether the font is a symbolic font.
`protected char` `mapUnencodedChar(char ch)` Adds a character to additional encodings
`void` `putKerningEntry(Integer key, Map<Integer,Integer> value)` Adds an entry to the kerning table.
`void` `replaceKerningMap(Map<Integer,Map<Integer,Integer>> kerningMap)` Replaces the existing kerning map with a new one.
`void` `setAdvancedEnabled(boolean enabled)` Enables/disabled advanced typographic features.
`void` `setAscender(int ascender)` Sets the ascent value.
`void` `setCapHeight(int capHeight)` Sets the capital height value.
`void` `setCMap(CMapSegment[] cmap)` Sets the character map for this font.
`void` `setDescender(int descender)` Sets the descent value.
`void` `setEmbeddingMode(EmbeddingMode embeddingMode)` Sets the embedding mode.
`void` `setEmbedResourceName(String name)` Sets the resource name of the embeddable font file.
`void` `setEmbedURI(URI path)` Sets the URI to the embeddable font.
`void` `setFamilyNames(Set<String> names)` Sets the font's family names (Example: "Helvetica").
`void` `setFirstChar(int index)` Sets the index of the first character in the character table.
`void` `setFlags(int flags)` Sets the font's flags
`void` `setFontBBox(int[] bbox)` Sets the font's bounding box
`void` `setFontName(String name)` Sets the "PostScript" font name (Example: "Helvetica-BoldOblique").
`void` `setFontSubFamilyName(String subFamilyName)` Sets the font's subfamily name.
`void` `setFontType(FontType fontType)` Sets the font type.
`void` `setFontURI(URI uri)` Sets the URI from which this font is or will be loaded.
`void` `setFullName(String name)` Sets the font's full name (usually the one that the operating system displays).
`void` `setItalicAngle(int italicAngle)` Sets the font's italic angle.
`void` `setKerningEnabled(boolean enabled)` Enables/disabled kerning.
`void` `setLastChar(int index)` Sets the index of the last character in the character table.
`void` `setMissingWidth(int width)` Sets the font's default width
`void` `setSimulateStyle(boolean enabled)`
`void` `setStemV(int stemV)` Sets the font's StemV value.
`void` `setStrikeoutPosition(int strikeoutPosition)`
`void` `setStrikeoutThickness(int strikeoutThickness)`
`void` `setSVG(Map<Integer,SVGGlyphData> svgs)`
`void` `setUnderlinePosition(int underlinePosition)`
`void` `setUnderlineThickness(int underlineThickness)`
`void` `setWeight(int weight)` Sets the font weight.
`void` `setXHeight(int xHeight)` Returns the XHeight value of the font.

### Methods inherited from class org.apache.fop.fonts.Typeface

`getEncodingName, getMaxAscent, hadMappingOperations, hasChar, hasFeature, isCID, isMultiByte, mapChar, notifyMapOperation, setEventListener, toString, warnMissingGlyph`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.apache.fop.fonts.FontDescriptor

`isEmbeddable, isSubsetEmbedded`

### Methods inherited from interface org.apache.fop.fonts.FontMetrics

`getBoundingBox, getMaxAscent, getWidth, getWidths, hasFeature, isMultiByte`

### Field Detail

#### cmap

    protected List<CMapSegment> cmap

the character map, mapping Unicode ranges to glyph indices.

#### svgs

    protected Map<Integer,SVGGlyphData> svgs

#### additionalEncodings

    protected List<SimpleSingleByteEncoding> additionalEncodings

#### unencodedCharacters

    protected Map<Character,SingleByteFont.UnencodedCharacter> unencodedCharacters

### Constructor Detail

#### CustomFont

    public CustomFont(InternalResourceResolver resourceResolver)

Parameters:
  `resourceResolver` - the URI resource resolver for controlling file access

### Method Detail

#### getFontURI

    public URI getFontURI()

Returns the URI of the font file from which these metrics were loaded.

Specified by:
  `getFontURI` in interface `FontMetrics`
Returns:
  the font file's URI

#### getFontName

    public String getFontName()

Returns the "PostScript" font name (Example: "Helvetica-BoldOblique").

Specified by:
  `getFontName` in interface `FontMetrics`
Returns:
  the font name

#### getEmbedFontName

    public String getEmbedFontName()

Returns the font name for font embedding (may include a prefix, Example: "1E28bcArialMT").

Specified by:
  `getEmbedFontName` in interface `FontMetrics`
Returns:
  the name for font embedding

#### getFullName

    public String getFullName()

Returns the font's full name (Example: "Helvetica Bold Oblique").

Specified by:
  `getFullName` in interface `FontMetrics`
Returns:
  the font's full name

#### getFamilyNames

    public Set<String> getFamilyNames()

Returns the font family names.

Specified by:
  `getFamilyNames` in interface `FontMetrics`
Returns:
  the font family names (a Set of Strings)

#### getStrippedFontName

    public String getStrippedFontName()

Returns the font family name stripped of whitespace.

Returns:
  the stripped font family
See Also:
  `FontUtil.stripWhiteSpace(String)`

#### getFontSubName

    public String getFontSubName()

Returns font's subfamily name.

Returns:
  the font's subfamily name

#### getEmbedFileURI

    public URI getEmbedFileURI()

Returns an URI representing an embeddable font file.

Returns:
  URI to an embeddable font file or null if not available.

#### getEmbeddingMode

    public EmbeddingMode getEmbeddingMode()

Returns the embedding mode for this font.

Returns:
  embedding mode

#### getInputStream

    public InputStream getInputStream()
                               throws IOException

Returns an `InputStream` representing an embeddable font file.

Returns:
  `InputStream` for an embeddable font file
Throws:
  `IOException` - if embedFileName is not null but Source is not found

#### getEmbedResourceName

    public String getEmbedResourceName()

Returns the lookup name to an embeddable font file available as a resource. (todo) Remove this method, this should be done using a resource: URI.

Returns:
  the lookup name

#### getAscender

    public int getAscender()

Returns the ascender value of the font. (Ascent in pdf spec)

Specified by:
  `getAscender` in interface `FontDescriptor`
Returns:
  the ascender

#### getDescender

    public int getDescender()

Returns the descender value of the font. (Descent in pdf spec)

Specified by:
  `getDescender` in interface `FontDescriptor`
Returns:
  the descender value

#### getCapHeight

    public int getCapHeight()

Returns the capital height of the font.

Specified by:
  `getCapHeight` in interface `FontDescriptor`
Returns:
  the capital height

#### getAscender

    public int getAscender(int size)

Returns the ascent of the font described by this FontMetrics object. It returns the nominal ascent within the em box.

Specified by:
  `getAscender` in interface `FontMetrics`
Parameters:
  `size` - font size
Returns:
  ascent in milliponts

#### getDescender

    public int getDescender(int size)

Returns the descent of the font described by this FontMetrics object.

Specified by:
  `getDescender` in interface `FontMetrics`
Parameters:
  `size` - font size
Returns:
  descent in milliponts

#### getCapHeight

    public int getCapHeight(int size)

Returns the size of a capital letter measured from the font's baseline.

Specified by:
  `getCapHeight` in interface `FontMetrics`
Parameters:
  `size` - font size
Returns:
  height of capital characters

#### getXHeight

    public int getXHeight(int size)

Determines the typical font height of this FontMetrics object

Specified by:
  `getXHeight` in interface `FontMetrics`
Parameters:
  `size` - font size
Returns:
  font height in millipoints

#### getFontBBox

    public int[] getFontBBox()

Returns the font's bounding box.

Specified by:
  `getFontBBox` in interface `FontDescriptor`
Returns:
  the bounding box

#### getFlags

    public int getFlags()

Returns the flags for the font. (See pdf spec)

Specified by:
  `getFlags` in interface `FontDescriptor`
Returns:
  the flags

#### isSymbolicFont

    public boolean isSymbolicFont()

Indicates whether the font is a symbolic font.

Specified by:
  `isSymbolicFont` in interface `FontDescriptor`
Returns:
  true if the font is a symbolic font (i.e. Symbol or ZapfDingbats)

#### getWeight

    public int getWeight()

Returns the font weight (100, 200...800, 900). This value may be different from the one that was actually used to register the font.

Returns:
  the font weight (or 0 if the font weight is unknown)

#### getStemV

    public int getStemV()

Returns the vertical stem width for the font.

Specified by:
  `getStemV` in interface `FontDescriptor`
Returns:
  the vertical stem width

#### getItalicAngle

    public int getItalicAngle()

Returns the italic angle for the font.

Specified by:
  `getItalicAngle` in interface `FontDescriptor`
Returns:
  the italic angle

#### getMissingWidth

    public int getMissingWidth()

Returns the width to be used when no width is available.

Returns:
  a character width

#### getFontType

    public FontType getFontType()

Returns the type of the font.

Specified by:
  `getFontType` in interface `FontMetrics`
Returns:
  the font type

#### getFirstChar

    public int getFirstChar()

Returns the index of the first character defined in this font.

Returns:
  the index of the first character

#### getLastChar

    public int getLastChar()

Returns the index of the last character defined in this font.

Returns:
  the index of the last character

#### isKerningEnabled

    public boolean isKerningEnabled()

Used to determine if kerning is enabled.

Returns:
  True if kerning is enabled.

#### hasKerningInfo

    public final boolean hasKerningInfo()

Indicates if the font has kerning information.

Specified by:
  `hasKerningInfo` in interface `FontMetrics`
Returns:
  true if kerning is available.

#### getKerningInfo

    public final Map<Integer,Map<Integer,Integer>> getKerningInfo()

Returns the kerning map for the font.

Specified by:
  `getKerningInfo` in interface `FontMetrics`
Returns:
  the kerning map

#### isAdvancedEnabled

    public boolean isAdvancedEnabled()

Used to determine if advanced typographic features are enabled. By default, this is false, but may be overridden by subclasses.

Returns:
  true if enabled.

#### setFontURI

    public void setFontURI(URI uri)

Sets the URI from which this font is or will be loaded.

Specified by:
  `setFontURI` in interface `MutableFont`
Parameters:
  `uri` - URI from which font is or will be loaded

#### setFontName

    public void setFontName(String name)

Sets the "PostScript" font name (Example: "Helvetica-BoldOblique").

Specified by:
  `setFontName` in interface `MutableFont`
Parameters:
  `name` - font name

#### setFullName

    public void setFullName(String name)

Sets the font's full name (usually the one that the operating system displays). Example: "Helvetica Bold Oblique".

Specified by:
  `setFullName` in interface `MutableFont`
Parameters:
  `name` - font' full name

#### setFamilyNames

    public void setFamilyNames(Set<String> names)

Sets the font's family names (Example: "Helvetica").

Specified by:
  `setFamilyNames` in interface `MutableFont`
Parameters:
  `names` - the font's family names (a Set of Strings)

#### setFontSubFamilyName

    public void setFontSubFamilyName(String subFamilyName)

Sets the font's subfamily name.

Parameters:
  `subFamilyName` - the subfamily name of the font

#### setEmbedURI

    public void setEmbedURI(URI path)

Sets the URI to the embeddable font.

Specified by:
  `setEmbedURI` in interface `MutableFont`
Parameters:
  `path` - URI to the font

#### setEmbedResourceName

    public void setEmbedResourceName(String name)

Sets the resource name of the embeddable font file.

Specified by:
  `setEmbedResourceName` in interface `MutableFont`
Parameters:
  `name` - resource name

#### setEmbeddingMode

    public void setEmbeddingMode(EmbeddingMode embeddingMode)

Sets the embedding mode.

Specified by:
  `setEmbeddingMode` in interface `MutableFont`
Parameters:
  `embeddingMode` - the embedding mode

#### setCapHeight

    public void setCapHeight(int capHeight)

Sets the capital height value.

Specified by:
  `setCapHeight` in interface `MutableFont`
Parameters:
  `capHeight` - capital height

#### setXHeight

    public void setXHeight(int xHeight)

Returns the XHeight value of the font.

Parameters:
  `xHeight` - the XHeight value

#### setAscender

    public void setAscender(int ascender)

Sets the ascent value.

Specified by:
  `setAscender` in interface `MutableFont`
Parameters:
  `ascender` - ascent height

#### setDescender

    public void setDescender(int descender)

Sets the descent value.

Specified by:
  `setDescender` in interface `MutableFont`
Parameters:
  `descender` - descent value

#### setFontBBox

    public void setFontBBox(int[] bbox)

Sets the font's bounding box

Specified by:
  `setFontBBox` in interface `MutableFont`
Parameters:
  `bbox` - bounding box

#### setFlags

    public void setFlags(int flags)

Sets the font's flags

Specified by:
  `setFlags` in interface `MutableFont`
Parameters:
  `flags` - flags

#### setWeight

    public void setWeight(int weight)

Sets the font weight. Valid values are 100, 200...800, 900.

Parameters:
  `weight` - the font weight

#### setStemV

    public void setStemV(int stemV)

Sets the font's StemV value.

Specified by:
  `setStemV` in interface `MutableFont`
Parameters:
  `stemV` - StemV

#### setItalicAngle

    public void setItalicAngle(int italicAngle)

Sets the font's italic angle.

Specified by:
  `setItalicAngle` in interface `MutableFont`
Parameters:
  `italicAngle` - italic angle

#### setMissingWidth

    public void setMissingWidth(int width)

Sets the font's default width

Specified by:
  `setMissingWidth` in interface `MutableFont`
Parameters:
  `width` - default width

#### setFontType

    public void setFontType(FontType fontType)

Sets the font type.

Specified by:
  `setFontType` in interface `MutableFont`
Parameters:
  `fontType` - font type

#### setFirstChar

    public void setFirstChar(int index)

Sets the index of the first character in the character table.

Specified by:
  `setFirstChar` in interface `MutableFont`
Parameters:
  `index` - index of first character

#### setLastChar

    public void setLastChar(int index)

Sets the index of the last character in the character table.

Specified by:
  `setLastChar` in interface `MutableFont`
Parameters:
  `index` - index of the last character

#### setKerningEnabled

    public void setKerningEnabled(boolean enabled)

Enables/disabled kerning.

Specified by:
  `setKerningEnabled` in interface `MutableFont`
Parameters:
  `enabled` - True if kerning should be enabled if available

#### setAdvancedEnabled

    public void setAdvancedEnabled(boolean enabled)

Enables/disabled advanced typographic features.

Specified by:
  `setAdvancedEnabled` in interface `MutableFont`
Parameters:
  `enabled` - true if advanced typographic features should be enabled if available

#### setSimulateStyle

    public void setSimulateStyle(boolean enabled)

#### getSimulateStyle

    public boolean getSimulateStyle()

#### putKerningEntry

    public void putKerningEntry(Integer key,
                                Map<Integer,Integer> value)

Adds an entry to the kerning table.

Specified by:
  `putKerningEntry` in interface `MutableFont`
Parameters:
  `key` - Kerning key
  `value` - Kerning value

#### replaceKerningMap

    public void replaceKerningMap(Map<Integer,Map<Integer,Integer>> kerningMap)

Replaces the existing kerning map with a new one.

Parameters:
  `kerningMap` - the kerning map (the integers are character codes)

#### setCMap

    public void setCMap(CMapSegment[] cmap)

Sets the character map for this font. It maps all available Unicode characters to their glyph indices inside the font.

Parameters:
  `cmap` - the character map

#### getCMap

    public CMapSegment[] getCMap()

Returns the character map for this font. It maps all available Unicode characters to their glyph indices inside the font.

Returns:
  the character map

#### getUnderlinePosition

    public int getUnderlinePosition(int size)

Description copied from interface: `FontMetrics`
Returns the distance from the baseline to the center of the underline (negative value indicates below baseline).

Specified by:
  `getUnderlinePosition` in interface `FontMetrics`
Parameters:
  `size` - font size
Returns:
  the position in 1/1000ths of the font size

#### setUnderlinePosition

    public void setUnderlinePosition(int underlinePosition)

#### getUnderlineThickness

    public int getUnderlineThickness(int size)

Description copied from interface: `FontMetrics`
Returns the thickness of the underline.

Specified by:
  `getUnderlineThickness` in interface `FontMetrics`
Parameters:
  `size` - font size
Returns:
  the thickness in 1/1000ths of the font size

#### setUnderlineThickness

    public void setUnderlineThickness(int underlineThickness)

#### getStrikeoutPosition

    public int getStrikeoutPosition(int size)

Description copied from interface: `FontMetrics`
Returns the distance from the baseline to the center of the strikeout line (negative value indicates below baseline).

Specified by:
  `getStrikeoutPosition` in interface `FontMetrics`
Parameters:
  `size` - font size
Returns:
  the position in 1/1000ths of the font size

#### setStrikeoutPosition

    public void setStrikeoutPosition(int strikeoutPosition)

#### getStrikeoutThickness

    public int getStrikeoutThickness(int size)

Description copied from interface: `FontMetrics`
Returns the thickness of the strikeout line.

Specified by:
  `getStrikeoutThickness` in interface `FontMetrics`
Parameters:
  `size` - font size
Returns:
  the thickness in 1/1000ths of the font size

#### setStrikeoutThickness

    public void setStrikeoutThickness(int strikeoutThickness)

#### getUsedGlyphs

    public abstract Map<Integer,Integer> getUsedGlyphs()

Returns a Map of used Glyphs.

Returns:
  Map Map of used Glyphs

#### getUnicodeFromGID

    public abstract char getUnicodeFromGID(int glyphIndex)

Returns the character from it's original glyph index in the font

Parameters:
  `glyphIndex` - The original index of the character
Returns:
  The character

#### hasAdditionalEncodings

    public boolean hasAdditionalEncodings()

Indicates whether the encoding has additional encodings besides the primary encoding.

Returns:
  true if there are additional encodings.

#### getAdditionalEncodingCount

    public int getAdditionalEncodingCount()

Returns the number of additional encodings this single-byte font maintains.

Returns:
  the number of additional encodings

#### getAdditionalEncoding

    public SimpleSingleByteEncoding getAdditionalEncoding(int index)
                                                   throws IndexOutOfBoundsException

Returns an additional encoding.

Parameters:
  `index` - the index of the additional encoding
Returns:
  the additional encoding
Throws:
  `IndexOutOfBoundsException` - if the index is out of bounds

#### addUnencodedCharacter

    public void addUnencodedCharacter(NamedCharacter ch,
                                      int width,
                                      Rectangle bbox)

Adds an unencoded character (one that is not supported by the primary encoding).

Parameters:
  `ch` - the named character
  `width` - the width of the character

#### mapUnencodedChar

    protected char mapUnencodedChar(char ch)

Adds a character to additional encodings

Parameters:
  `ch` - character to map

#### hasSVG

    public boolean hasSVG()

#### setSVG

    public void setSVG(Map<Integer,SVGGlyphData> svgs)