Class LayoutProcessor


  • public class LayoutProcessor
    extends java.lang.Object
    Provides glyph layout e.g. for accented Latin letters.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.Map<BaseFont,​java.awt.Font> awtFontMap  
      private static int DEFAULT_FLAGS  
      private static boolean enabled  
      private static int flags  
      private static java.util.Map<java.awt.font.TextAttribute,​java.lang.Object> globalTextAttributes  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private LayoutProcessor()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.font.GlyphVector computeGlyphVector​(BaseFont baseFont, float fontSize, java.lang.String text)
      Computes glyph positioning
      static void disable()  
      static void enable()
      Enables the processor.
      static void enable​(int flags)
      Enables the processor with the provided flags.
      static void enableKernLiga()
      Enables the processor.
      static void enableKernLiga​(int flags)
      Enables the processor with the provided flags.
      static int getFlags()  
      private static boolean hasAdjustments​(java.awt.font.GlyphVector glyphVector)
      Checks if the glyphVector contains adjustments that make advanced layout necessary
      static boolean isEnabled()  
      static boolean isSet​(int queryFlags)  
      static void loadFont​(BaseFont baseFont, java.lang.String filename)
      Loads the AWT font needed for layout
      static void setKerning()
      Set kerning
      static void setKerning​(Font font)
      Set kerning for one font
      static void setLigatures()
      Add ligatures
      static void setLigatures​(Font font)
      Set ligatures for one font
      private static void setRunDirection​(Font font, java.lang.Boolean runDirection)
      Set run direction for one font
      static void setRunDirectionLtr​(Font font)
      Set run direction for one font to LTR
      static void setRunDirectionRtl​(Font font)
      Set run direction for one font to RTL
      private static void setTextAttributes​(Font font, java.util.Map<java.awt.font.TextAttribute,​java.lang.Object> textAttributes)
      Set text attributes to font The attributes are used only for glyph layout, and don't change the visual appearance of the font
      static java.awt.geom.Point2D showText​(PdfContentByte cb, BaseFont baseFont, float fontSize, java.lang.String text)
      Shows a text using glyph positioning (if needed)
      static boolean supportsFont​(BaseFont baseFont)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • awtFontMap

        private static final java.util.Map<BaseFont,​java.awt.Font> awtFontMap
      • globalTextAttributes

        private static final java.util.Map<java.awt.font.TextAttribute,​java.lang.Object> globalTextAttributes
      • enabled

        private static boolean enabled
      • flags

        private static int flags
    • Constructor Detail

      • LayoutProcessor

        private LayoutProcessor()
    • Method Detail

      • enable

        public static void enable()
        Enables the processor.

        Kerning and ligatures are switched off. This method can only be called once.

      • enable

        public static void enable​(int flags)
        Enables the processor with the provided flags.

        Kerning and ligatures are switched off. This method can only be called once.

        Parameters:
        flags - see java.awt.Font.layoutGlyphVector
      • enableKernLiga

        public static void enableKernLiga()
        Enables the processor.

        Kerning and ligatures are switched on. This method can only be called once.

      • enableKernLiga

        public static void enableKernLiga​(int flags)
        Enables the processor with the provided flags.

        Kerning and ligatures are switched on. This method can only be called once.

        Parameters:
        flags - see java.awt.Font.layoutGlyphVector
      • isEnabled

        public static boolean isEnabled()
      • setLigatures

        public static void setLigatures()
        Add ligatures
      • setLigatures

        public static void setLigatures​(Font font)
        Set ligatures for one font
        Parameters:
        font - The font for which ligatures are to be turned on
      • setRunDirectionRtl

        public static void setRunDirectionRtl​(Font font)
        Set run direction for one font to RTL
        Parameters:
        font - The font for which the run direction is set
      • setRunDirectionLtr

        public static void setRunDirectionLtr​(Font font)
        Set run direction for one font to LTR
        Parameters:
        font - The font for which the run direction is set
      • setRunDirection

        private static void setRunDirection​(Font font,
                                            java.lang.Boolean runDirection)
        Set run direction for one font
        Parameters:
        font - The font for which the run direction is set
      • setTextAttributes

        private static void setTextAttributes​(Font font,
                                              java.util.Map<java.awt.font.TextAttribute,​java.lang.Object> textAttributes)
        Set text attributes to font The attributes are used only for glyph layout, and don't change the visual appearance of the font
        Parameters:
        font - The font for which kerning is to be turned on
        textAttributes - Map of text attributes to be set
        See Also:
        Oracle: The Java™ Tutorials, Using Text Attributes to Style Text
      • getFlags

        public static int getFlags()
      • isSet

        public static boolean isSet​(int queryFlags)
      • supportsFont

        public static boolean supportsFont​(BaseFont baseFont)
      • loadFont

        public static void loadFont​(BaseFont baseFont,
                                    java.lang.String filename)
        Loads the AWT font needed for layout
        Parameters:
        baseFont - OpenPdf base font
        filename - of the font file
        Throws:
        java.lang.RuntimeException - if font can not be loaded
      • computeGlyphVector

        public static java.awt.font.GlyphVector computeGlyphVector​(BaseFont baseFont,
                                                                   float fontSize,
                                                                   java.lang.String text)
        Computes glyph positioning
        Parameters:
        baseFont - OpenPdf base font
        text - input text
        Returns:
        glyph vector containing reordered text, width and positioning info
      • hasAdjustments

        private static boolean hasAdjustments​(java.awt.font.GlyphVector glyphVector)
        Checks if the glyphVector contains adjustments that make advanced layout necessary
        Parameters:
        glyphVector - glyph vector containing the positions
        Returns:
        true, if the glyphVector contains adjustments
      • showText

        public static java.awt.geom.Point2D showText​(PdfContentByte cb,
                                                     BaseFont baseFont,
                                                     float fontSize,
                                                     java.lang.String text)
        Shows a text using glyph positioning (if needed)
        Parameters:
        cb - object containing the content of the page
        baseFont - base font to use
        fontSize - font size to apply
        text - text to show
        Returns:
        layout position correction to correct the start of the next line
      • disable

        public static void disable()