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 Details

    • log

      protected static final org.apache.commons.logging.Log log
      logging instance
  • Constructor Details

    • PSFontUtils

      public PSFontUtils()
  • Method Details

    • writeFontDict

      public static Map writeFontDict(org.apache.xmlgraphics.ps.PSGenerator gen, FontInfo fontInfo) throws 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 output
      fontInfo - available fonts
      Returns:
      a Map of PSResource instances representing all defined fonts (key: font key)
      Throws:
      IOException - in case of an I/O problem
    • writeFontDict

      public static Map writeFontDict(org.apache.xmlgraphics.ps.PSGenerator gen, FontInfo fontInfo, PSEventProducer eventProducer) throws 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 output
      fontInfo - available fonts
      eventProducer - to report events
      Returns:
      a Map of PSResource instances representing all defined fonts (key: font key)
      Throws:
      IOException - in case of an I/O problem
    • writeFontDict

      public static Map writeFontDict(org.apache.xmlgraphics.ps.PSGenerator gen, FontInfo fontInfo, Map<String,Typeface> fonts, PSEventProducer eventProducer) throws 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 output
      fontInfo - available fonts
      fonts - the set of fonts to work with
      eventProducer - the event producer
      Returns:
      a Map of PSResource instances representing all defined fonts (key: font key)
      Throws:
      IOException - in case of an I/O problem
    • writeFontDict

      private static Map writeFontDict(org.apache.xmlgraphics.ps.PSGenerator gen, FontInfo fontInfo, Map<String,Typeface> fonts, boolean encodeAllCharacters, PSEventProducer eventProducer) throws IOException
      Generates the PostScript code for the font dictionary.
      Parameters:
      gen - PostScript generator to use for output
      fontInfo - available fonts
      fonts - the set of fonts to work with
      encodeAllCharacters - 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:
      IOException - in case of an I/O problem
    • reencodeFonts

      private static void reencodeFonts(org.apache.xmlgraphics.ps.PSGenerator gen, Map<String,Typeface> fonts) throws IOException
      Throws:
      IOException
    • getTypeFace

      private static Typeface getTypeFace(FontInfo fontInfo, Map<String,Typeface> fonts, String key)
    • embedFont

      private static PSFontResource embedFont(org.apache.xmlgraphics.ps.PSGenerator gen, Typeface tf, PSEventProducer eventProducer) throws IOException
      Throws:
      IOException
    • checkPostScriptLevel3

      private static void checkPostScriptLevel3(org.apache.xmlgraphics.ps.PSGenerator gen, PSEventProducer eventProducer, String fontType)
    • embedType1Font

      private static void embedType1Font(org.apache.xmlgraphics.ps.PSGenerator gen, CustomFont font, InputStream fontStream) throws IOException
      Throws:
      IOException
    • writeEncoding

      private static void writeEncoding(org.apache.xmlgraphics.ps.PSGenerator gen, SingleByteFont font) throws IOException
      Throws:
      IOException
    • embedTrueTypeFont

      private static void embedTrueTypeFont(org.apache.xmlgraphics.ps.PSGenerator gen, SingleByteFont font, InputStream fontStream) throws IOException
      Throws:
      IOException
    • createType42DictionaryEntries

      private static void createType42DictionaryEntries(org.apache.xmlgraphics.ps.PSGenerator gen, CustomFont font, CMapSegment[] cmap, TTFFile ttfFile) throws IOException
      Throws:
      IOException
    • buildCharStrings

      private static void buildCharStrings(org.apache.xmlgraphics.ps.PSGenerator gen, boolean buildCharStrings, CMapSegment[] cmap, Set<String> glyphNames, CustomFont font) throws IOException
      Throws:
      IOException
    • writeGlyphDefs

      private static void writeGlyphDefs(org.apache.xmlgraphics.ps.PSGenerator gen, String glyphName, int glyphIndex) throws IOException
      Throws:
      IOException
    • getGlyphIndex

      private static int getGlyphIndex(char c, CMapSegment[] cmap)
    • composeType0Font

      private static void composeType0Font(org.apache.xmlgraphics.ps.PSGenerator gen, MultiByteFont font) throws IOException
      Throws:
      IOException
    • embedType2CFF

      private static void embedType2CFF(org.apache.xmlgraphics.ps.PSGenerator gen, MultiByteFont font, InputStream fontStream) throws IOException
      Throws:
      IOException
    • embedType2CIDFont

      private static org.apache.xmlgraphics.ps.PSResource embedType2CIDFont(org.apache.xmlgraphics.ps.PSGenerator gen, MultiByteFont font, InputStream fontStream) throws IOException
      Throws:
      IOException
    • writeFontBBox

      private static void writeFontBBox(org.apache.xmlgraphics.ps.PSGenerator gen, CustomFont font) throws IOException
      Throws:
      IOException
    • isEmbeddable

      private static boolean isEmbeddable(CustomFont font)
    • getInputStreamOnFont

      private static List<InputStream> getInputStreamOnFont(org.apache.xmlgraphics.ps.PSGenerator gen, CustomFont font) throws IOException
      Throws:
      IOException
    • determineSuppliedFonts

      public static Map determineSuppliedFonts(org.apache.xmlgraphics.ps.dsc.ResourceTracker resTracker, FontInfo fontInfo, Map<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 tracker
      fontInfo - available fonts
      fonts - 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 IOException
      Defines the single-byte encoding for use in PostScript files.
      Parameters:
      gen - the PostScript generator
      encoding - the single-byte encoding
      Returns:
      the PSResource instance that represents the encoding
      Throws:
      IOException - In case of an I/O problem
    • defineDerivedFont

      public static org.apache.xmlgraphics.ps.PSResource defineDerivedFont(org.apache.xmlgraphics.ps.PSGenerator gen, String baseFontName, String fontName, String encoding) throws 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 generator
      baseFontName - the font name of the font to derive from
      fontName - the font name of the new font to be define
      encoding - the new encoding (must be predefined in the PS file)
      Returns:
      the PSResource representing the derived font
      Throws:
      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, String baseFontName, String fontName, SingleByteEncoding encoding, CMapSegment[] cmap) throws IOException
      Throws:
      IOException
    • addFallbackFonts

      public static void addFallbackFonts(FontInfo fontInfo, org.apache.xmlgraphics.java2d.GeneralGraphics2DImagePainter painter) throws IOException
      Throws:
      IOException