Package org.apache.fop.afp.fonts
Class CharacterSet
- java.lang.Object
-
- org.apache.fop.afp.fonts.CharacterSet
-
- Direct Known Subclasses:
FopCharacterSet
public class CharacterSet extends java.lang.Object
The IBM Font Object Content Architecture (FOCA) supports presentation of character shapes by defining their characteristics, which include font description information for identifying the characters, font metric information for positioning the characters, and character shape information for presenting the character images.
Presenting a graphic character on a presentation surface requires information on the rotation and position of character on the physical or logical page.
This class proivdes font metric information for a particular font as identified by the character set name. This information is obtained directly from the AFP font files which must be installed in the path specified in the afp-fonts xml definition file.
-
-
Field Summary
Fields Modifier and Type Field Description private AFPResourceAccessor
accessor
The path to the installed fontsprivate CharacterSetOrientation
characterSetOrientation
The collection of objects for each orientationprotected java.lang.String
codePage
The code page to which the character set relatesstatic java.lang.String
DEFAULT_CODEPAGE
default codepagestatic java.lang.String
DEFAULT_ENCODING
default encodingprivate CharactersetEncoder
encoder
The characterset encoder corresponding to this encodingprotected java.lang.String
encoding
The encoding used for the code pageprotected static org.apache.commons.logging.Log
LOG
Static logging instanceprivate static int
MAX_NAME_LEN
protected java.lang.String
name
The character set relating to the fontprivate int
nominalVerticalSize
The nominal vertical size (in millipoints) for bitmap fonts.static int
SUPPORTED_ORIENTATION
The current orientation (currently only 0 is supported by FOP)
-
Constructor Summary
Constructors Constructor Description CharacterSet(java.lang.String codePage, java.lang.String encoding, CharacterSetType charsetType, java.lang.String name, AFPResourceAccessor accessor, AFPEventProducer eventProducer)
Constructor for the CharacterSetMetric object, the character set is used to load the font information from the actual AFP font.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCharacterSetOrientation(CharacterSetOrientation cso)
Add character set metric information for the different orientationsCharactersetEncoder.EncodedChars
encodeChars(java.lang.CharSequence chars)
Encodes a character sequence to a byte array.int
getAscender()
Ascender height is the distance from the character baseline to the top of the character box.int
getCapHeight()
Cap height is the average height of the uppercase characters in a font.java.awt.Rectangle
getCharacterBox(char character, int size)
private CharacterSetOrientation
getCharacterSetOrientation()
Helper method to return the current CharacterSetOrientation, note that FOP does not yet implement the "reference-orientation" attribute therefore we always use the orientation zero degrees, Other orientation information is captured for use by a future implementation (whenever FOP implement the mechanism).java.lang.String
getCodePage()
Returns the AFP code page identifierint
getDescender()
Descender depth is the distance from the character baseline to the bottom of a character box.int
getEmSpaceIncrement()
Returns the increment for an em space.java.lang.String
getEncoding()
Returns the AFP code page encodingjava.lang.String
getName()
Returns the AFP character set identifierbyte[]
getNameBytes()
Returns the AFP character set identifier as a byte arrayint
getNominalCharIncrement()
Returns the nominal character increment.int
getNominalVerticalSize()
Returns the nominal vertical size of the font in the case of bitmap fonts.AFPResourceAccessor
getResourceAccessor()
Returns the resource accessor to load the font resources with.int
getSpaceIncrement()
Returns the increment for an space.int
getUnderscorePosition()
Return the position for an underscore (_) character.int
getUnderscoreWidth()
Return the width to use for an underscore (_) character.int
getWidth(char character, int size)
Get the width (in 1/1000ths of a point size) of the character identified by the parameter passed.int
getXHeight()
XHeight refers to the height of the lower case letters above the baseline.boolean
hasChar(char c)
Indicates whether the given char in the character set.char
mapChar(char c)
Map a Unicode character to a code point in the font.private java.lang.String
padName(java.lang.String name)
void
setNominalVerticalSize(int nominalVerticalSize)
Sets the nominal vertical size of the font in the case of bitmap fonts.
-
-
-
Field Detail
-
LOG
protected static final org.apache.commons.logging.Log LOG
Static logging instance
-
DEFAULT_CODEPAGE
public static final java.lang.String DEFAULT_CODEPAGE
default codepage- See Also:
- Constant Field Values
-
DEFAULT_ENCODING
public static final java.lang.String DEFAULT_ENCODING
default encoding- See Also:
- Constant Field Values
-
MAX_NAME_LEN
private static final int MAX_NAME_LEN
- See Also:
- Constant Field Values
-
SUPPORTED_ORIENTATION
public static final int SUPPORTED_ORIENTATION
The current orientation (currently only 0 is supported by FOP)- See Also:
- Constant Field Values
-
codePage
protected final java.lang.String codePage
The code page to which the character set relates
-
encoding
protected final java.lang.String encoding
The encoding used for the code page
-
encoder
private final CharactersetEncoder encoder
The characterset encoder corresponding to this encoding
-
name
protected final java.lang.String name
The character set relating to the font
-
accessor
private final AFPResourceAccessor accessor
The path to the installed fonts
-
characterSetOrientation
private CharacterSetOrientation characterSetOrientation
The collection of objects for each orientation
-
nominalVerticalSize
private int nominalVerticalSize
The nominal vertical size (in millipoints) for bitmap fonts. 0 for outline fonts.
-
-
Constructor Detail
-
CharacterSet
CharacterSet(java.lang.String codePage, java.lang.String encoding, CharacterSetType charsetType, java.lang.String name, AFPResourceAccessor accessor, AFPEventProducer eventProducer)
Constructor for the CharacterSetMetric object, the character set is used to load the font information from the actual AFP font.- Parameters:
codePage
- the code page identifierencoding
- the encoding of the fontcharsetType
- the type of the charactersetname
- the character set nameaccessor
- the resource accessor to load resource witheventProducer
- for handling AFP related events
-
-
Method Detail
-
padName
private java.lang.String padName(java.lang.String name)
-
addCharacterSetOrientation
public void addCharacterSetOrientation(CharacterSetOrientation cso)
Add character set metric information for the different orientations- Parameters:
cso
- the metrics for the orientation
-
setNominalVerticalSize
public void setNominalVerticalSize(int nominalVerticalSize)
Sets the nominal vertical size of the font in the case of bitmap fonts.- Parameters:
nominalVerticalSize
- the nominal vertical size (in millipoints)
-
getNominalVerticalSize
public int getNominalVerticalSize()
Returns the nominal vertical size of the font in the case of bitmap fonts. For outline fonts, zero is returned, because these are scalable fonts.- Returns:
- the nominal vertical size (in millipoints) for bitmap fonts, or 0 for outline fonts.
-
getAscender
public int getAscender()
Ascender height is the distance from the character baseline to the top of the character box. A negative ascender height signifies that all of the graphic character is below the character baseline. For a character rotation other than 0, ascender height loses its meaning when the character is lying on its side or is upside down with respect to normal viewing orientation. For the general case, Ascender Height is the characters most positive y-axis value. For bounded character boxes, for a given character having an ascender, ascender height and baseline offset are equal.- Returns:
- the ascender value in millipoints
-
getUnderscoreWidth
public int getUnderscoreWidth()
Return the width to use for an underscore (_) character.- Returns:
- the width of an underscore character
-
getUnderscorePosition
public int getUnderscorePosition()
Return the position for an underscore (_) character.- Returns:
- the position of an underscore character
-
getCapHeight
public int getCapHeight()
Cap height is the average height of the uppercase characters in a font. This value is specified by the designer of a font and is usually the height of the uppercase M.- Returns:
- the cap height value in millipoints
-
getDescender
public int getDescender()
Descender depth is the distance from the character baseline to the bottom of a character box. A negative descender depth signifies that all of the graphic character is above the character baseline.- Returns:
- the descender value in millipoints
-
getResourceAccessor
public AFPResourceAccessor getResourceAccessor()
Returns the resource accessor to load the font resources with.- Returns:
- the resource accessor to load the font resources with
-
getXHeight
public int getXHeight()
XHeight refers to the height of the lower case letters above the baseline.- Returns:
- the typical height of characters
-
getWidth
public int getWidth(char character, int size)
Get the width (in 1/1000ths of a point size) of the character identified by the parameter passed.- Parameters:
character
- the Unicode character from which the width will be calculatedsize
- the font size- Returns:
- the width of the character
-
getCharacterBox
public java.awt.Rectangle getCharacterBox(char character, int size)
-
getName
public java.lang.String getName()
Returns the AFP character set identifier- Returns:
- the AFP character set identifier
-
getNameBytes
public byte[] getNameBytes()
Returns the AFP character set identifier as a byte array- Returns:
- the AFP character set identifier as a byte array
-
getCodePage
public java.lang.String getCodePage()
Returns the AFP code page identifier- Returns:
- the AFP code page identifier
-
getEncoding
public java.lang.String getEncoding()
Returns the AFP code page encoding- Returns:
- the AFP code page encoding
-
getCharacterSetOrientation
private CharacterSetOrientation getCharacterSetOrientation()
Helper method to return the current CharacterSetOrientation, note that FOP does not yet implement the "reference-orientation" attribute therefore we always use the orientation zero degrees, Other orientation information is captured for use by a future implementation (whenever FOP implement the mechanism). This is also the case for landscape prints which use an orientation of 270 degrees, in 99.9% of cases the font metrics will be the same as the 0 degrees therefore the implementation currently will always use 0 degrees.- Returns:
- characterSetOrentation The current orientation metrics.
-
hasChar
public boolean hasChar(char c)
Indicates whether the given char in the character set.- Parameters:
c
- the character to check- Returns:
- true if the character is in the character set
-
encodeChars
public CharactersetEncoder.EncodedChars encodeChars(java.lang.CharSequence chars) throws java.nio.charset.CharacterCodingException
Encodes a character sequence to a byte array.- Parameters:
chars
- the characters- Returns:
- the encoded characters
- Throws:
java.nio.charset.CharacterCodingException
- if the encoding operation fails
-
mapChar
public char mapChar(char c)
Map a Unicode character to a code point in the font. The code tables are already converted to Unicode therefore we can use the identity mapping.- Parameters:
c
- the Unicode character to map- Returns:
- the mapped character
-
getSpaceIncrement
public int getSpaceIncrement()
Returns the increment for an space.- Returns:
- the space increment
-
getEmSpaceIncrement
public int getEmSpaceIncrement()
Returns the increment for an em space.- Returns:
- the em space increment
-
getNominalCharIncrement
public int getNominalCharIncrement()
Returns the nominal character increment.- Returns:
- the nominal character increment
-
-