Package org.apache.fop.render.ps
Class PSFontUtils
- java.lang.Object
-
- org.apache.xmlgraphics.ps.PSFontUtils
-
- org.apache.fop.render.ps.PSFontUtils
-
public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils
Utility code for font handling in PostScript.
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.apache.commons.logging.Log
log
logging instance
-
Constructor Summary
Constructors Constructor Description PSFontUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addFallbackFonts(FontInfo fontInfo, org.apache.xmlgraphics.java2d.GeneralGraphics2DImagePainter painter)
private static void
buildCharStrings(org.apache.xmlgraphics.ps.PSGenerator gen, boolean buildCharStrings, CMapSegment[] cmap, java.util.Set<java.lang.String> glyphNames, CustomFont font)
private static void
checkPostScriptLevel3(org.apache.xmlgraphics.ps.PSGenerator gen, PSEventProducer eventProducer, java.lang.String fontType)
private static void
composeType0Font(org.apache.xmlgraphics.ps.PSGenerator gen, MultiByteFont font)
private static void
createType42DictionaryEntries(org.apache.xmlgraphics.ps.PSGenerator gen, CustomFont font, CMapSegment[] cmap, TTFFile ttfFile)
static org.apache.xmlgraphics.ps.PSResource
defineDerivedFont(org.apache.xmlgraphics.ps.PSGenerator gen, java.lang.String baseFontName, java.lang.String fontName, java.lang.String encoding)
Derives a new font based on an existing font with a given encoding.private static org.apache.xmlgraphics.ps.PSResource
defineDerivedTrueTypeFont(org.apache.xmlgraphics.ps.PSGenerator gen, PSEventProducer eventProducer, java.lang.String baseFontName, java.lang.String fontName, SingleByteEncoding encoding, CMapSegment[] cmap)
static org.apache.xmlgraphics.ps.PSResource
defineEncoding(org.apache.xmlgraphics.ps.PSGenerator gen, SingleByteEncoding encoding)
Defines the single-byte encoding for use in PostScript files.static java.util.Map
determineSuppliedFonts(org.apache.xmlgraphics.ps.dsc.ResourceTracker resTracker, FontInfo fontInfo, java.util.Map<java.lang.String,Typeface> fonts)
Determines the set of fonts that will be supplied with the PS file and registers them with the resource tracker.private static PSFontResource
embedFont(org.apache.xmlgraphics.ps.PSGenerator gen, Typeface tf, PSEventProducer eventProducer)
private static void
embedTrueTypeFont(org.apache.xmlgraphics.ps.PSGenerator gen, SingleByteFont font, java.io.InputStream fontStream)
private static void
embedType1Font(org.apache.xmlgraphics.ps.PSGenerator gen, CustomFont font, java.io.InputStream fontStream)
private static void
embedType2CFF(org.apache.xmlgraphics.ps.PSGenerator gen, MultiByteFont font, java.io.InputStream fontStream)
private static org.apache.xmlgraphics.ps.PSResource
embedType2CIDFont(org.apache.xmlgraphics.ps.PSGenerator gen, MultiByteFont font, java.io.InputStream fontStream)
private static int
getGlyphIndex(char c, CMapSegment[] cmap)
private static java.util.List<java.io.InputStream>
getInputStreamOnFont(org.apache.xmlgraphics.ps.PSGenerator gen, CustomFont font)
private static Typeface
getTypeFace(FontInfo fontInfo, java.util.Map<java.lang.String,Typeface> fonts, java.lang.String key)
private static boolean
isEmbeddable(CustomFont font)
private static void
reencodeFonts(org.apache.xmlgraphics.ps.PSGenerator gen, java.util.Map<java.lang.String,Typeface> fonts)
private static void
writeEncoding(org.apache.xmlgraphics.ps.PSGenerator gen, SingleByteFont font)
private static void
writeFontBBox(org.apache.xmlgraphics.ps.PSGenerator gen, CustomFont font)
static java.util.Map
writeFontDict(org.apache.xmlgraphics.ps.PSGenerator gen, FontInfo fontInfo)
Generates the PostScript code for the font dictionary.private static java.util.Map
writeFontDict(org.apache.xmlgraphics.ps.PSGenerator gen, FontInfo fontInfo, java.util.Map<java.lang.String,Typeface> fonts, boolean encodeAllCharacters, PSEventProducer eventProducer)
Generates the PostScript code for the font dictionary.static java.util.Map
writeFontDict(org.apache.xmlgraphics.ps.PSGenerator gen, FontInfo fontInfo, java.util.Map<java.lang.String,Typeface> fonts, PSEventProducer eventProducer)
Generates the PostScript code for the font dictionary.static java.util.Map
writeFontDict(org.apache.xmlgraphics.ps.PSGenerator gen, FontInfo fontInfo, PSEventProducer eventProducer)
Generates the PostScript code for the font dictionary.private static void
writeGlyphDefs(org.apache.xmlgraphics.ps.PSGenerator gen, java.lang.String glyphName, int glyphIndex)
-
-
-
Method Detail
-
writeFontDict
public static java.util.Map writeFontDict(org.apache.xmlgraphics.ps.PSGenerator gen, FontInfo fontInfo) throws java.io.IOException
Generates the PostScript code for the font dictionary. This method should only be used if no "resource optimization" is performed, i.e. when the fonts are not embedded in a second pass.- Parameters:
gen
- PostScript generator to use for outputfontInfo
- available fonts- Returns:
- a Map of PSResource instances representing all defined fonts (key: font key)
- Throws:
java.io.IOException
- in case of an I/O problem
-
writeFontDict
public static java.util.Map writeFontDict(org.apache.xmlgraphics.ps.PSGenerator gen, FontInfo fontInfo, PSEventProducer eventProducer) throws java.io.IOException
Generates the PostScript code for the font dictionary. This method should only be used if no "resource optimization" is performed, i.e. when the fonts are not embedded in a second pass.- Parameters:
gen
- PostScript generator to use for outputfontInfo
- available fontseventProducer
- to report events- Returns:
- a Map of PSResource instances representing all defined fonts (key: font key)
- Throws:
java.io.IOException
- in case of an I/O problem
-
writeFontDict
public static java.util.Map writeFontDict(org.apache.xmlgraphics.ps.PSGenerator gen, FontInfo fontInfo, java.util.Map<java.lang.String,Typeface> fonts, PSEventProducer eventProducer) throws java.io.IOException
Generates the PostScript code for the font dictionary. This method assumes all used fonts and characters are known, i.e. when PostScript is generated with resource optimization turned on.- Parameters:
gen
- PostScript generator to use for outputfontInfo
- available fontsfonts
- the set of fonts to work witheventProducer
- the event producer- Returns:
- a Map of PSResource instances representing all defined fonts (key: font key)
- Throws:
java.io.IOException
- in case of an I/O problem
-
writeFontDict
private static java.util.Map writeFontDict(org.apache.xmlgraphics.ps.PSGenerator gen, FontInfo fontInfo, java.util.Map<java.lang.String,Typeface> fonts, boolean encodeAllCharacters, PSEventProducer eventProducer) throws java.io.IOException
Generates the PostScript code for the font dictionary.- Parameters:
gen
- PostScript generator to use for outputfontInfo
- available fontsfonts
- the set of fonts to work withencodeAllCharacters
- true if all characters shall be encoded using additional, generated encodings.- Returns:
- a Map of PSResource instances representing all defined fonts (key: font key)
- Throws:
java.io.IOException
- in case of an I/O problem
-
reencodeFonts
private static void reencodeFonts(org.apache.xmlgraphics.ps.PSGenerator gen, java.util.Map<java.lang.String,Typeface> fonts) throws java.io.IOException
- Throws:
java.io.IOException
-
getTypeFace
private static Typeface getTypeFace(FontInfo fontInfo, java.util.Map<java.lang.String,Typeface> fonts, java.lang.String key)
-
embedFont
private static PSFontResource embedFont(org.apache.xmlgraphics.ps.PSGenerator gen, Typeface tf, PSEventProducer eventProducer) throws java.io.IOException
- Throws:
java.io.IOException
-
checkPostScriptLevel3
private static void checkPostScriptLevel3(org.apache.xmlgraphics.ps.PSGenerator gen, PSEventProducer eventProducer, java.lang.String fontType)
-
embedType1Font
private static void embedType1Font(org.apache.xmlgraphics.ps.PSGenerator gen, CustomFont font, java.io.InputStream fontStream) throws java.io.IOException
- Throws:
java.io.IOException
-
writeEncoding
private static void writeEncoding(org.apache.xmlgraphics.ps.PSGenerator gen, SingleByteFont font) throws java.io.IOException
- Throws:
java.io.IOException
-
embedTrueTypeFont
private static void embedTrueTypeFont(org.apache.xmlgraphics.ps.PSGenerator gen, SingleByteFont font, java.io.InputStream fontStream) throws java.io.IOException
- Throws:
java.io.IOException
-
createType42DictionaryEntries
private static void createType42DictionaryEntries(org.apache.xmlgraphics.ps.PSGenerator gen, CustomFont font, CMapSegment[] cmap, TTFFile ttfFile) throws java.io.IOException
- Throws:
java.io.IOException
-
buildCharStrings
private static void buildCharStrings(org.apache.xmlgraphics.ps.PSGenerator gen, boolean buildCharStrings, CMapSegment[] cmap, java.util.Set<java.lang.String> glyphNames, CustomFont font) throws java.io.IOException
- Throws:
java.io.IOException
-
writeGlyphDefs
private static void writeGlyphDefs(org.apache.xmlgraphics.ps.PSGenerator gen, java.lang.String glyphName, int glyphIndex) throws java.io.IOException
- Throws:
java.io.IOException
-
getGlyphIndex
private static int getGlyphIndex(char c, CMapSegment[] cmap)
-
composeType0Font
private static void composeType0Font(org.apache.xmlgraphics.ps.PSGenerator gen, MultiByteFont font) throws java.io.IOException
- Throws:
java.io.IOException
-
embedType2CFF
private static void embedType2CFF(org.apache.xmlgraphics.ps.PSGenerator gen, MultiByteFont font, java.io.InputStream fontStream) throws java.io.IOException
- Throws:
java.io.IOException
-
embedType2CIDFont
private static org.apache.xmlgraphics.ps.PSResource embedType2CIDFont(org.apache.xmlgraphics.ps.PSGenerator gen, MultiByteFont font, java.io.InputStream fontStream) throws java.io.IOException
- Throws:
java.io.IOException
-
writeFontBBox
private static void writeFontBBox(org.apache.xmlgraphics.ps.PSGenerator gen, CustomFont font) throws java.io.IOException
- Throws:
java.io.IOException
-
isEmbeddable
private static boolean isEmbeddable(CustomFont font)
-
getInputStreamOnFont
private static java.util.List<java.io.InputStream> getInputStreamOnFont(org.apache.xmlgraphics.ps.PSGenerator gen, CustomFont font) throws java.io.IOException
- Throws:
java.io.IOException
-
determineSuppliedFonts
public static java.util.Map determineSuppliedFonts(org.apache.xmlgraphics.ps.dsc.ResourceTracker resTracker, FontInfo fontInfo, java.util.Map<java.lang.String,Typeface> fonts)
Determines the set of fonts that will be supplied with the PS file and registers them with the resource tracker. All the fonts that are being processed are returned as a Map.- Parameters:
resTracker
- the resource trackerfontInfo
- available fontsfonts
- the set of fonts to work with- Returns:
- a Map of PSResource instances representing all defined fonts (key: font key)
-
defineEncoding
public static org.apache.xmlgraphics.ps.PSResource defineEncoding(org.apache.xmlgraphics.ps.PSGenerator gen, SingleByteEncoding encoding) throws java.io.IOException
Defines the single-byte encoding for use in PostScript files.- Parameters:
gen
- the PostScript generatorencoding
- the single-byte encoding- Returns:
- the PSResource instance that represents the encoding
- Throws:
java.io.IOException
- In case of an I/O problem
-
defineDerivedFont
public static org.apache.xmlgraphics.ps.PSResource defineDerivedFont(org.apache.xmlgraphics.ps.PSGenerator gen, java.lang.String baseFontName, java.lang.String fontName, java.lang.String encoding) throws java.io.IOException
Derives a new font based on an existing font with a given encoding. The encoding must have been registered before.- Parameters:
gen
- the PostScript generatorbaseFontName
- the font name of the font to derive fromfontName
- the font name of the new font to be defineencoding
- the new encoding (must be predefined in the PS file)- Returns:
- the PSResource representing the derived font
- Throws:
java.io.IOException
- In case of an I/O problem
-
defineDerivedTrueTypeFont
private static org.apache.xmlgraphics.ps.PSResource defineDerivedTrueTypeFont(org.apache.xmlgraphics.ps.PSGenerator gen, PSEventProducer eventProducer, java.lang.String baseFontName, java.lang.String fontName, SingleByteEncoding encoding, CMapSegment[] cmap) throws java.io.IOException
- Throws:
java.io.IOException
-
addFallbackFonts
public static void addFallbackFonts(FontInfo fontInfo, org.apache.xmlgraphics.java2d.GeneralGraphics2DImagePainter painter) throws java.io.IOException
- Throws:
java.io.IOException
-
-