org.apache.fop.render.pcl

Class PCLGenerator


public class PCLGenerator
extends java.lang.Object

This class provides methods for generating PCL print files.

Field Summary

static int
DITHER_MATRIX_4X4
Selects a 4x4 Bayer dither matrix (17 grayscales)
static int
DITHER_MATRIX_8X8
Selects a 8x8 Bayer dither matrix (65 grayscales)
static char
ESC
The ESC (escape) character
static int[]
PCL_RESOLUTIONS
A list of all supported resolutions in PCL (values in dpi)

Constructor Summary

PCLGenerator(OutputStream out)
Main constructor.
PCLGenerator(OutputStream out, int maxResolution)
Main constructor.

Method Summary

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)
Generate a filled rectangle at the current cursor position.
void
formFeed()
Sends the form feed character.
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.
int
getMaximumBitmapResolution()
OutputStream
getOutputStream()
static boolean
isGrayscaleImage(RenderedImage img)
Indicates whether an image is a grayscale image.
static boolean
isMonochromeImage(RenderedImage img)
Indicates whether an image is a monochrome (b/w) image.
void
paintBitmap(RenderedImage img, Dimension targetDim, boolean sourceTransparency)
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
selectCurrentPattern(int patternID, int pattern)
Select the current pattern
void
selectGrayscale(Color col)
Selects the current grayscale color (the given color is converted to grayscales).
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
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
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.

Field Details

DITHER_MATRIX_4X4

public static final int DITHER_MATRIX_4X4
Selects a 4x4 Bayer dither matrix (17 grayscales)
Field Value:
4

DITHER_MATRIX_8X8

public static final int DITHER_MATRIX_8X8
Selects a 8x8 Bayer dither matrix (65 grayscales)
Field Value:
8

ESC

public static final char ESC
The ESC (escape) character
Field Value:
'\'

PCL_RESOLUTIONS

public static final int[] PCL_RESOLUTIONS
A list of all supported resolutions in PCL (values in dpi)

Constructor Details

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 Details

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.

clearHorizontalMargins

public void clearHorizontalMargins()
            throws IOException
Clears the horizontal margins.

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)

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)

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

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

fillRect

protected void fillRect(int w,
                        int h,
                        Color col)
            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

formFeed

public void formFeed()
            throws IOException
Sends the form feed character.

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

getMaximumBitmapResolution

public int getMaximumBitmapResolution()
Returns:
the maximum resolution to encode bitmap images at

getOutputStream

public OutputStream getOutputStream()
Returns:
the OutputStream that this generator writes to

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

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

paintBitmap

public void paintBitmap(RenderedImage img,
                        Dimension targetDim,
                        boolean sourceTransparency)
            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

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)

popCursorPos

public void popCursorPos()
            throws IOException
Pops the current cursor position from the stack.

pushCursorPos

public void pushCursorPos()
            throws IOException
Pushes the current cursor position on a stack (stack size: max 20 entries)

resetPrinter

public void resetPrinter()
            throws IOException
Resets the printer and restores the user default environment.

selectCurrentPattern

public void selectCurrentPattern(int patternID,
                                 int pattern)
            throws IOException
Select the current pattern
Parameters:
patternID - the pattern ID (*c#G command)
pattern - the pattern type (*v#T command)

selectGrayscale

public void selectGrayscale(Color col)
            throws IOException
Selects the current grayscale color (the given color is converted to grayscales).
Parameters:
col - the color

selectPageSize

public void selectPageSize(int selector)
            throws IOException
Selects the page size.
Parameters:
selector - the integer representing the page size

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

separateJobs

public void separateJobs()
            throws IOException
Sends the job separation command.

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)

setPatternTransparencyMode

public void setPatternTransparencyMode(boolean transparent)
            throws IOException
Sets the pattern transparency mode.
Parameters:
transparent - true if transparent, false for opaque

setRasterGraphicsResolution

public void setRasterGraphicsResolution(int value)
            throws IOException
Sets the raster graphics resolution
Parameters:
value - the resolution value (units per inch)

setSourceTransparencyMode

public void setSourceTransparencyMode(boolean transparent)
            throws IOException
Sets the source transparency mode.
Parameters:
transparent - true if transparent, false for opaque

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

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)

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

setUnitOfMeasure

public void setUnitOfMeasure(int value)
            throws IOException
Sets the unit of measure.
Parameters:
value - the resolution value (units per inch)

setVMI

public void setVMI(double value)
            throws IOException
Sets the Vertical Motion Index (VMI).
Parameters:
value - the VMI value

universalEndOfLanguage

public void universalEndOfLanguage()
            throws IOException
Sends the universal end of language command (UEL).

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)

writeText

public void writeText(String s)
            throws IOException
Writes raw text (in ISO-8859-1 encoding) to the output stream.
Parameters:
s - the text

Copyright 1999-2007 The Apache Software Foundation. All Rights Reserved.