org.apache.fop.render.pcl

## Class PCLGenerator

- java.lang.Object
- - org.apache.fop.render.pcl.PCLGenerator

-     public class PCLGenerator
      extends Object

  This class provides methods for generating PCL print files.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static char` | `ESC` The ESC (escape) character
    `protected Map<PCLSoftFontManager,Map<Typeface,Long>>` | `fontManagerMap`
    `protected Map<Typeface,PCLFontReader>` | `fontReaderMap`
    `static int[]` | `PCL_RESOLUTIONS` A list of all supported resolutions in PCL (values in dpi)

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PCLGenerator(OutputStream out)` Main constructor.
    `PCLGenerator(OutputStream out, int maxResolution)` Main constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addFont(PCLSoftFontManager sfManager, Typeface font)`
    `void` | `changePrintDirection(int rotate)` Changes the current print direction while maintaining the current cursor position.
    `void` | `clearHorizontalMargins()` Clears the horizontal margins.
    `int` | `convertToGray(int r, int g, int b)` Convert an RGB color value to a grayscale from 0 to 100.
    `int` | `convertToPCLShade(Color col)` Convert a Color value to a PCL shade value (0-100).
    `void` | `defineGrayscalePattern(Color col, int patternID, int ditherMatrixSize)` Generates a user-defined pattern for a dithering pattern matching the grayscale value of the color given.
    `void` | `enterHPGL2Mode(boolean restorePreviousHPGL2Cursor)` Enters the HP GL/2 mode.
    `void` | `enterPCLMode(boolean restorePreviousPCLCursor)` Enters the PCL mode.
    `protected void` | `fillRect(int w, int h, Color col, boolean colorEnabled)` Generate a filled rectangle at the current cursor position.
    `String` | `formatDouble2(double value)` Formats a double value with two decimal positions for PCL output.
    `String` | `formatDouble4(double value)` Formats a double value with four decimal positions for PCL output.
    `void` | `formFeed()` Sends the form feed character.
    `float` | `getDitheringQuality()` Returns the dithering quality used when encoding gray or color images.
    `int` | `getMaximumBitmapResolution()`
    `OutputStream` | `getOutputStream()`
    `String` | `getTextEncoding()` Returns the currently active text encoding.
    `static boolean` | `isGrayscaleImage(RenderedImage img)` Indicates whether an image is a grayscale image.
    `static boolean` | `isJAIAvailable()` Indicates whether JAI is available.
    `static boolean` | `isMonochromeImage(RenderedImage img)` Indicates whether an image is a monochrome (b/w) image.
    `void` | `paintBitmap(RenderedImage img, Dimension targetDim, boolean sourceTransparency, PCLRenderingUtil pclUtil)` Paint a bitmap at the current cursor position.
    `void` | `paintMonochromeBitmap(RenderedImage img, int resolution)` Paint a bitmap at the current cursor position.
    `void` | `popCursorPos()` Pops the current cursor position from the stack.
    `void` | `pushCursorPos()` Pushes the current cursor position on a stack (stack size: max 20 entries)
    `void` | `resetPrinter()` Resets the printer and restores the user default environment.
    `void` | `selectColor(Color col)`
    `void` | `selectCurrentPattern(int patternID, int pattern)` Select the current pattern
    `void` | `selectDuplexMode(int selector)` Selects the duplexing mode for the page.
    `void` | `selectGrayscale(Color col)` Selects the current grayscale color (the given color is converted to grayscales).
    `void` | `selectOutputBin(int selector)` Selects the output bin.
    `void` | `selectPageSize(int selector)` Selects the page size.
    `void` | `selectPaperSource(int selector)` Selects the paper source.
    `void` | `separateJobs()` Sends the job separation command.
    `void` | `setCursorPos(double x, double y)` Sets the cursor to a new absolute coordinate.
    `void` | `setDitheringQuality(float quality)` Sets the dithering quality used when encoding gray or color images.
    `void` | `setPatternTransparencyMode(boolean transparent)` Sets the pattern transparency mode.
    `void` | `setRasterGraphicsResolution(int value)` Sets the raster graphics resolution
    `void` | `setSourceTransparencyMode(boolean transparent)` Sets the source transparency mode.
    `void` | `setTextLength(int numberOfLines)` The Text Length command can be used to define the bottom border.
    `void` | `setTopMargin(int numberOfLines)` The Top Margin command designates the number of lines between the top of the logical page and the top of the text area.
    `void` | `setTransparencyMode(boolean source, boolean pattern)` Sets the transparency modes.
    `void` | `setUnitOfMeasure(int value)` Sets the unit of measure.
    `void` | `setVMI(double value)` Sets the Vertical Motion Index (VMI).
    `void` | `universalEndOfLanguage()` Sends the universal end of language command (UEL).
    `void` | `writeBytes(byte[] bytes)` Writes raw bytes to the output stream
    `void` | `writeCommand(String cmd)` Writes a PCL escape command to the output stream.
    `void` | `writeText(String s)` Writes raw text (in ISO-8859-1 encoding) to the output stream.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### ESC

          public static final char ESC

      The ESC (escape) character
      See Also:
        Constant Field Values

    - #### PCL_RESOLUTIONS

          public static final int[] PCL_RESOLUTIONS

      A list of all supported resolutions in PCL (values in dpi)

    - #### fontReaderMap

          protected Map<Typeface,PCLFontReader> fontReaderMap

    - #### fontManagerMap

          protected Map<PCLSoftFontManager,Map<Typeface,Long>> fontManagerMap

  - ### Constructor Detail

    - #### PCLGenerator

          public PCLGenerator(OutputStream out)

      Main constructor.
      Parameters:
        `out` - the OutputStream to write the PCL stream to

    - #### PCLGenerator

          public PCLGenerator(OutputStream out,
                              int maxResolution)

      Main constructor.
      Parameters:
        `out` - the OutputStream to write the PCL stream to
        `maxResolution` - the maximum resolution to encode bitmap images at

  - ### Method Detail

    - #### addFont

          public void addFont(PCLSoftFontManager sfManager,
                              Typeface font)

    - #### getOutputStream

          public OutputStream getOutputStream()

      Returns:
        the OutputStream that this generator writes to

    - #### getTextEncoding

          public String getTextEncoding()

      Returns the currently active text encoding.
      Returns:
        the text encoding

    - #### getMaximumBitmapResolution

          public int getMaximumBitmapResolution()

      Returns:
        the maximum resolution to encode bitmap images at

    - #### writeCommand

          public void writeCommand(String cmd)
                            throws IOException

      Writes a PCL escape command to the output stream.
      Parameters:
        `cmd` - the command (without the ESCAPE character)
      Throws:
        `IOException` - In case of an I/O error

    - #### writeText

          public void writeText(String s)
                         throws IOException

      Writes raw text (in ISO-8859-1 encoding) to the output stream.
      Parameters:
        `s` - the text
      Throws:
        `IOException` - In case of an I/O error

    - #### writeBytes

          public void writeBytes(byte[] bytes)
                          throws IOException

      Writes raw bytes to the output stream
      Parameters:
        `bytes` - The bytes
      Throws:
        `IOException` - In case of an I/O error

    - #### formatDouble2

          public final String formatDouble2(double value)

      Formats a double value with two decimal positions for PCL output.
      Parameters:
        `value` - value to format
      Returns:
        the formatted value

    - #### formatDouble4

          public final String formatDouble4(double value)

      Formats a double value with four decimal positions for PCL output.
      Parameters:
        `value` - value to format
      Returns:
        the formatted value

    - #### universalEndOfLanguage

          public void universalEndOfLanguage()
                                      throws IOException

      Sends the universal end of language command (UEL).
      Throws:
        `IOException` - In case of an I/O error

    - #### resetPrinter

          public void resetPrinter()
                            throws IOException

      Resets the printer and restores the user default environment.
      Throws:
        `IOException` - In case of an I/O error

    - #### separateJobs

          public void separateJobs()
                            throws IOException

      Sends the job separation command.
      Throws:
        `IOException` - In case of an I/O error

    - #### formFeed

          public void formFeed()
                        throws IOException

      Sends the form feed character.
      Throws:
        `IOException` - In case of an I/O error

    - #### setUnitOfMeasure

          public void setUnitOfMeasure(int value)
                                throws IOException

      Sets the unit of measure.
      Parameters:
        `value` - the resolution value (units per inch)
      Throws:
        `IOException` - In case of an I/O error

    - #### setRasterGraphicsResolution

          public void setRasterGraphicsResolution(int value)
                                           throws IOException

      Sets the raster graphics resolution
      Parameters:
        `value` - the resolution value (units per inch)
      Throws:
        `IOException` - In case of an I/O error

    - #### selectPageSize

          public void selectPageSize(int selector)
                              throws IOException

      Selects the page size.
      Parameters:
        `selector` - the integer representing the page size
      Throws:
        `IOException` - In case of an I/O error

    - #### selectPaperSource

          public void selectPaperSource(int selector)
                                 throws IOException

      Selects the paper source. The parameter is usually printer-specific. Usually, "1" is the default tray, "2" is the manual paper feed, "3" is the manual envelope feed, "4" is the "lower" tray and "7" is "auto-select". Consult the technical reference for your printer for all available values.
      Parameters:
        `selector` - the integer representing the paper source/tray
      Throws:
        `IOException` - In case of an I/O error

    - #### selectOutputBin

          public void selectOutputBin(int selector)
                               throws IOException

      Selects the output bin. The parameter is usually printer-specific. Usually, "1" is the default output bin (upper bin) and "2" is the lower (rear) output bin. Some printers may support additional output bins. Consult the technical reference for your printer for all available values.
      Parameters:
        `selector` - the integer representing the output bin
      Throws:
        `IOException` - In case of an I/O error

    - #### selectDuplexMode

          public void selectDuplexMode(int selector)
                                throws IOException

      Selects the duplexing mode for the page. The parameter is usually printer-specific. "0" means Simplex, "1" means Duplex, Long-Edge Binding, "2" means Duplex, Short-Edge Binding.
      Parameters:
        `selector` - the integer representing the duplexing mode of the page
      Throws:
        `IOException` - In case of an I/O error

    - #### clearHorizontalMargins

          public void clearHorizontalMargins()
                                      throws IOException

      Clears the horizontal margins.
      Throws:
        `IOException` - In case of an I/O error

    - #### setTopMargin

          public void setTopMargin(int numberOfLines)
                            throws IOException

      The Top Margin command designates the number of lines between the top of the logical page and the top of the text area.
      Parameters:
        `numberOfLines` - the number of lines (See PCL specification for details)
      Throws:
        `IOException` - In case of an I/O error

    - #### setTextLength

          public void setTextLength(int numberOfLines)
                             throws IOException

      The Text Length command can be used to define the bottom border. See the PCL specification for details.
      Parameters:
        `numberOfLines` - the number of lines
      Throws:
        `IOException` - In case of an I/O error

    - #### setVMI

          public void setVMI(double value)
                      throws IOException

      Sets the Vertical Motion Index (VMI).
      Parameters:
        `value` - the VMI value
      Throws:
        `IOException` - In case of an I/O error

    - #### setCursorPos

          public void setCursorPos(double x,
                                   double y)
                            throws IOException

      Sets the cursor to a new absolute coordinate.
      Parameters:
        `x` - the X coordinate (in millipoints)
        `y` - the Y coordinate (in millipoints)
      Throws:
        `IOException` - In case of an I/O error

    - #### pushCursorPos

          public void pushCursorPos()
                             throws IOException

      Pushes the current cursor position on a stack (stack size: max 20 entries)
      Throws:
        `IOException` - In case of an I/O error

    - #### popCursorPos

          public void popCursorPos()
                            throws IOException

      Pops the current cursor position from the stack.
      Throws:
        `IOException` - In case of an I/O error

    - #### changePrintDirection

          public void changePrintDirection(int rotate)
                                    throws IOException

      Changes the current print direction while maintaining the current cursor position.
      Parameters:
        `rotate` - the rotation angle (counterclockwise), one of 0, 90, 180 and 270.
      Throws:
        `IOException` - In case of an I/O error

    - #### enterHPGL2Mode

          public void enterHPGL2Mode(boolean restorePreviousHPGL2Cursor)
                              throws IOException

      Enters the HP GL/2 mode.
      Parameters:
        `restorePreviousHPGL2Cursor` - true if the previous HP GL/2 pen position should be restored, false if the current position is maintained
      Throws:
        `IOException` - In case of an I/O error

    - #### enterPCLMode

          public void enterPCLMode(boolean restorePreviousPCLCursor)
                            throws IOException

      Enters the PCL mode.
      Parameters:
        `restorePreviousPCLCursor` - true if the previous PCL cursor position should be restored, false if the current position is maintained
      Throws:
        `IOException` - In case of an I/O error

    - #### fillRect

          protected void fillRect(int w,
                                  int h,
                                  Color col,
                                  boolean colorEnabled)
                           throws IOException

      Generate a filled rectangle at the current cursor position.
      Parameters:
        `w` - the width in millipoints
        `h` - the height in millipoints
        `col` - the fill color
      Throws:
        `IOException` - In case of an I/O error

    - #### defineGrayscalePattern

          public void defineGrayscalePattern(Color col,
                                             int patternID,
                                             int ditherMatrixSize)
                                      throws IOException

      Generates a user-defined pattern for a dithering pattern matching the grayscale value of the color given.
      Parameters:
        `col` - the color to create the pattern for
        `patternID` - the pattern ID to use
        `ditherMatrixSize` - the size of the Bayer dither matrix to use (4 or 8 supported)
      Throws:
        `IOException` - In case of an I/O error

    - #### setSourceTransparencyMode

          public void setSourceTransparencyMode(boolean transparent)
                                         throws IOException

      Sets the source transparency mode.
      Parameters:
        `transparent` - true if transparent, false for opaque
      Throws:
        `IOException` - In case of an I/O error

    - #### setPatternTransparencyMode

          public void setPatternTransparencyMode(boolean transparent)
                                          throws IOException

      Sets the pattern transparency mode.
      Parameters:
        `transparent` - true if transparent, false for opaque
      Throws:
        `IOException` - In case of an I/O error

    - #### setTransparencyMode

          public void setTransparencyMode(boolean source,
                                          boolean pattern)
                                   throws IOException

      Sets the transparency modes.
      Parameters:
        `source` - source transparency: true if transparent, false for opaque
        `pattern` - pattern transparency: true if transparent, false for opaque
      Throws:
        `IOException` - In case of an I/O error

    - #### convertToGray

          public final int convertToGray(int r,
                                         int g,
                                         int b)

      Convert an RGB color value to a grayscale from 0 to 100.
      Parameters:
        `r` - the red component
        `g` - the green component
        `b` - the blue component
      Returns:
        the gray value

    - #### convertToPCLShade

          public final int convertToPCLShade(Color col)

      Convert a Color value to a PCL shade value (0-100).
      Parameters:
        `col` - the color
      Returns:
        the PCL shade value (100=black)

    - #### selectGrayscale

          public void selectGrayscale(Color col)
                               throws IOException

      Selects the current grayscale color (the given color is converted to grayscales).
      Parameters:
        `col` - the color
      Throws:
        `IOException` - In case of an I/O error

    - #### selectColor

          public void selectColor(Color col)
                           throws IOException

      Throws:
        `IOException`

    - #### selectCurrentPattern

          public void selectCurrentPattern(int patternID,
                                           int pattern)
                                    throws IOException

      Select the current pattern
      Parameters:
        `patternID` - the pattern ID (<ESC>*c#G command)
        `pattern` - the pattern type (<ESC>*v#T command)
      Throws:
        `IOException` - In case of an I/O error

    - #### setDitheringQuality

          public void setDitheringQuality(float quality)

      Sets the dithering quality used when encoding gray or color images. If not explicitely set a medium setting (0.5f) is used.
      Parameters:
        `quality` - a quality setting between 0.0f (worst/fastest) and 1.0f (best/slowest)

    - #### getDitheringQuality

          public float getDitheringQuality()

      Returns the dithering quality used when encoding gray or color images.
      Returns:
        the quality setting between 0.0f (worst/fastest) and 1.0f (best/slowest)

    - #### isMonochromeImage

          public static boolean isMonochromeImage(RenderedImage img)

      Indicates whether an image is a monochrome (b/w) image.
      Parameters:
        `img` - the image
      Returns:
        true if it's a monochrome image

    - #### isGrayscaleImage

          public static boolean isGrayscaleImage(RenderedImage img)

      Indicates whether an image is a grayscale image.
      Parameters:
        `img` - the image
      Returns:
        true if it's a grayscale image

    - #### isJAIAvailable

          public static boolean isJAIAvailable()

      Indicates whether JAI is available. JAI has shown to be reliable when dithering a grayscale or color image to monochrome bitmaps (1-bit).
      Returns:
        true if JAI is available

    - #### paintBitmap

          public void paintBitmap(RenderedImage img,
                                  Dimension targetDim,
                                  boolean sourceTransparency,
                                  PCLRenderingUtil pclUtil)
                           throws IOException

      Paint a bitmap at the current cursor position. The bitmap is converted to a monochrome (1-bit) bitmap image.
      Parameters:
        `img` - the bitmap image
        `targetDim` - the target Dimention (in mpt)
        `sourceTransparency` - true if the background should not be erased
      Throws:
        `IOException` - In case of an I/O error

    - #### paintMonochromeBitmap

          public void paintMonochromeBitmap(RenderedImage img,
                                            int resolution)
                                     throws IOException

      Paint a bitmap at the current cursor position. The bitmap must be a monochrome (1-bit) bitmap image.
      Parameters:
        `img` - the bitmap image (must be 1-bit b/w)
        `resolution` - the resolution of the image (must be a PCL resolution)
      Throws:
        `IOException` - In case of an I/O error

Copyright © 2023 Apache Software Foundation. All rights reserved.