Package org.apache.fop.afp.fonts
Class CharacterSetBuilder
java.lang.Object
org.apache.fop.afp.fonts.CharacterSetBuilder
- Direct Known Subclasses:
CharacterSetBuilder.DoubleByteLoader
,CharacterSetBuilder.SingleByteLoader
The CharacterSetBuilder is responsible building the a CharacterSet instance that holds
the font metric data. The data is either read from disk and passed to a CharacterSet (*)
or a FopCharacterSet is instantiated that is composed of a Typeface instance configured
with this data.
-*- For referenced fonts CharacterSetBuilder is responsible for reading the font attributes from binary code page files and the character set metric files. In IBM font structure, a code page maps each character of text to the characters in a character set. Each character is translated into a code point. When the character is printed, each code point is matched to a character ID on the code page specified. The character ID is then matched to the image (raster pattern or outline pattern) of the character in the character set specified. The image in the character set is the image that is printed in the document. To be a valid code page for a particular character set, all character IDs in the code page must be included in that character set.
This class will read the font information from the binary code page files and character set metric files in order to determine the correct metrics to use when rendering the formatted object.
-*- For referenced fonts CharacterSetBuilder is responsible for reading the font attributes from binary code page files and the character set metric files. In IBM font structure, a code page maps each character of text to the characters in a character set. Each character is translated into a code point. When the character is printed, each code point is matched to a character ID on the code page specified. The character ID is then matched to the image (raster pattern or outline pattern) of the character in the character set specified. The image in the character set is the image that is printed in the document. To be a valid code page for a particular character set, all character IDs in the code page must be included in that character set.
This class will read the font information from the binary code page files and character set metric files in order to determine the correct metrics to use when rendering the formatted object.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Double-byte (CID Keyed font (Type 0)) implementation of AFPFontReader.private class
private static class
private static final class
private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]
Character table MO:DCA structured field.private final org.apache.xmlgraphics.image.loader.util.SoftMapCache
Cache of charactersetsprivate static final byte[]
Codepage MO:DCA structured field.The collection of code pagesprivate static final CharacterSetOrientation[]
Template used to convert lists to arrays.private static final byte[]
Font control MO:DCA structured field.private static final byte[]
Font descriptor MO:DCA structured field.private static final byte[]
Font index MO:DCA structured field.private static final byte[]
Font orientation MO:DCA structured field.private static final byte[]
Font position MO:DCA structured field.protected static final org.apache.commons.logging.Log
Static logging instance -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild
(String characterSetName, String codePageName, String encoding, Typeface typeface, AFPEventProducer eventProducer) Load the font details and metrics into the CharacterSetMetric object, this will use the actual afp code page and character set files to load the object with the necessary metrics.build
(String characterSetName, String codePageName, String encoding, Typeface typeface, AFPResourceAccessor accessor, AFPEventProducer eventProducer) buildDBCS
(String characterSetName, String codePageName, String encoding, CharacterSetType charsetType, AFPResourceAccessor accessor, AFPEventProducer eventProducer) Load the font details and metrics into the CharacterSetMetric object, this will use the actual afp code page and character set files to load the object with the necessary metrics.buildSBCS
(String characterSetName, String codePageName, String encoding, AFPResourceAccessor accessor, AFPEventProducer eventProducer) Load the font details and metrics into the CharacterSetMetric object, this will use the actual afp code page and character set files to load the object with the necessary metrics.private void
closeInputStream
(InputStream inputStream) Closes the inputstreamprivate static int
determineOrientation
(byte orientation) static CharacterSetBuilder
Factory method for the double-byte (CID Keyed font (Type 0)) implementation of AFPFontReader.private static int
getSBIN
(byte[] data, int start) static CharacterSetBuilder
Factory method for the single-byte implementation of AFPFontReader.private static int
getUBIN
(byte[] data, int start) loadCodePage
(String codePage, String encoding, AFPResourceAccessor accessor, AFPEventProducer eventProducer) Load the code page information from the appropriate file.private InputStream
openInputStream
(AFPResourceAccessor accessor, String uriStr, AFPEventProducer eventProducer) Returns an InputStream to a given file path and filenameprivate CharacterSet
processFont
(String characterSetName, String codePageName, String encoding, CharacterSetType charsetType, AFPResourceAccessor accessor, AFPEventProducer eventProducer) private CharacterSetBuilder.FontControl
processFontControl
(StructuredFieldReader structuredFieldReader) Process the font control details using the structured field reader.private static CharacterSetBuilder.FontDescriptor
processFontDescriptor
(StructuredFieldReader structuredFieldReader) Process the font descriptor details using the structured field reader.private void
processFontIndex
(StructuredFieldReader structuredFieldReader, CharacterSetOrientation cso, Map<String, String> codepage, CharacterSetBuilder.ValueNormalizer normalizer) private CharacterSetOrientation[]
processFontOrientation
(StructuredFieldReader structuredFieldReader) Process the font orientation details from using the structured field reader.private void
processFontPosition
(StructuredFieldReader structuredFieldReader, CharacterSetOrientation[] characterSetOrientations, CharacterSetBuilder.ValueNormalizer normalizer) Populate the CharacterSetOrientation object in the suplied array with the font position details using the supplied structured field reader.
-
Field Details
-
LOG
protected static final org.apache.commons.logging.Log LOGStatic logging instance -
EMPTY_CSO_ARRAY
Template used to convert lists to arrays. -
CODEPAGE_SF
private static final byte[] CODEPAGE_SFCodepage MO:DCA structured field. -
CHARACTER_TABLE_SF
private static final byte[] CHARACTER_TABLE_SFCharacter table MO:DCA structured field. -
FONT_DESCRIPTOR_SF
private static final byte[] FONT_DESCRIPTOR_SFFont descriptor MO:DCA structured field. -
FONT_CONTROL_SF
private static final byte[] FONT_CONTROL_SFFont control MO:DCA structured field. -
FONT_ORIENTATION_SF
private static final byte[] FONT_ORIENTATION_SFFont orientation MO:DCA structured field. -
FONT_POSITION_SF
private static final byte[] FONT_POSITION_SFFont position MO:DCA structured field. -
FONT_INDEX_SF
private static final byte[] FONT_INDEX_SFFont index MO:DCA structured field. -
codePagesCache
The collection of code pages -
characterSetsCache
private final org.apache.xmlgraphics.image.loader.util.SoftMapCache characterSetsCacheCache of charactersets
-
-
Constructor Details
-
CharacterSetBuilder
private CharacterSetBuilder()Default constructor.
-
-
Method Details
-
getSingleByteInstance
Factory method for the single-byte implementation of AFPFontReader.- Returns:
- AFPFontReader
-
getDoubleByteInstance
Factory method for the double-byte (CID Keyed font (Type 0)) implementation of AFPFontReader.- Returns:
- AFPFontReader
-
openInputStream
private InputStream openInputStream(AFPResourceAccessor accessor, String uriStr, AFPEventProducer eventProducer) throws IOException Returns an InputStream to a given file path and filename- Parameters:
accessor
- the resource accessoruriStr
- the URIeventProducer
- for handling AFP related events- Returns:
- an inputStream
- Throws:
IOException
- in the event that an I/O exception of some sort has occurred
-
closeInputStream
Closes the inputstream- Parameters:
inputStream
- the inputstream to close
-
buildSBCS
public CharacterSet buildSBCS(String characterSetName, String codePageName, String encoding, AFPResourceAccessor accessor, AFPEventProducer eventProducer) throws IOException Load the font details and metrics into the CharacterSetMetric object, this will use the actual afp code page and character set files to load the object with the necessary metrics.- Parameters:
characterSetName
- name of the charactersetcodePageName
- name of the code page fileencoding
- encoding nameaccessor
- used to load codepage and characterseteventProducer
- for handling AFP related events- Returns:
- CharacterSet object
- Throws:
IOException
- if an I/O error occurs
-
buildDBCS
public CharacterSet buildDBCS(String characterSetName, String codePageName, String encoding, CharacterSetType charsetType, AFPResourceAccessor accessor, AFPEventProducer eventProducer) throws IOException Load the font details and metrics into the CharacterSetMetric object, this will use the actual afp code page and character set files to load the object with the necessary metrics. This method is to be used for double byte character sets (DBCS).- Parameters:
characterSetName
- name of the charactersetcodePageName
- name of the code page fileencoding
- encoding namecharsetType
- the characterset typeaccessor
- used to load codepage and characterseteventProducer
- for handling AFP related events- Returns:
- CharacterSet object
- Throws:
IOException
- if an I/O error occurs
-
build
public CharacterSet build(String characterSetName, String codePageName, String encoding, Typeface typeface, AFPEventProducer eventProducer) throws IOException Load the font details and metrics into the CharacterSetMetric object, this will use the actual afp code page and character set files to load the object with the necessary metrics.- Parameters:
characterSetName
- the CharacterSetMetric object to populatecodePageName
- the name of the code page to useencoding
- name of the encoding in usetypeface
- base14 font nameeventProducer
- for handling AFP related events- Returns:
- CharacterSet object
- Throws:
IOException
- if an I/O error occurs
-
build
public CharacterSet build(String characterSetName, String codePageName, String encoding, Typeface typeface, AFPResourceAccessor accessor, AFPEventProducer eventProducer) throws IOException - Throws:
IOException
-
processFont
private CharacterSet processFont(String characterSetName, String codePageName, String encoding, CharacterSetType charsetType, AFPResourceAccessor accessor, AFPEventProducer eventProducer) throws IOException - Throws:
IOException
-
loadCodePage
protected Map<String,String> loadCodePage(String codePage, String encoding, AFPResourceAccessor accessor, AFPEventProducer eventProducer) throws IOException Load the code page information from the appropriate file. The file name to load is determined by the code page name and the file extension 'CDP'.- Parameters:
codePage
- the code page identifierencoding
- the encoding to use for the character decodingaccessor
- the resource accessoreventProducer
- for handling AFP related events- Returns:
- a code page mapping (key: GCGID, value: Unicode character)
- Throws:
IOException
- if an I/O exception of some sort has occurred.
-
processFontDescriptor
private static CharacterSetBuilder.FontDescriptor processFontDescriptor(StructuredFieldReader structuredFieldReader) throws IOException Process the font descriptor details using the structured field reader.- Parameters:
structuredFieldReader
- the structured field reader- Returns:
- a class representing the font descriptor
- Throws:
IOException
- if an I/O exception of some sort has occurred.
-
processFontControl
private CharacterSetBuilder.FontControl processFontControl(StructuredFieldReader structuredFieldReader) throws IOException Process the font control details using the structured field reader.- Parameters:
structuredFieldReader
- the structured field reader- Returns:
- the FontControl
- Throws:
IOException
- if an I/O exception of some sort has occurred.
-
processFontOrientation
private CharacterSetOrientation[] processFontOrientation(StructuredFieldReader structuredFieldReader) throws IOException Process the font orientation details from using the structured field reader.- Parameters:
structuredFieldReader
- the structured field reader- Returns:
- CharacterSetOrientation array
- Throws:
IOException
- if an I/O exception of some sort has occurred.
-
processFontPosition
private void processFontPosition(StructuredFieldReader structuredFieldReader, CharacterSetOrientation[] characterSetOrientations, CharacterSetBuilder.ValueNormalizer normalizer) throws IOException Populate the CharacterSetOrientation object in the suplied array with the font position details using the supplied structured field reader.- Parameters:
structuredFieldReader
- the structured field readercharacterSetOrientations
- the array of CharacterSetOrientation objectsmetricNormalizationFactor
- factor to apply to the metrics to get normalized font metric values- Throws:
IOException
- if an I/O exception of some sort has occurred.
-
processFontIndex
private void processFontIndex(StructuredFieldReader structuredFieldReader, CharacterSetOrientation cso, Map<String, String> codepage, CharacterSetBuilder.ValueNormalizer normalizer) throws IOException- Throws:
IOException
-
getUBIN
private static int getUBIN(byte[] data, int start) -
getSBIN
private static int getSBIN(byte[] data, int start) -
determineOrientation
private static int determineOrientation(byte orientation)
-