Package org.apache.fop.render.pcl
Class PCLGenerator
java.lang.Object
org.apache.fop.render.pcl.PCLGenerator
This class provides methods for generating PCL print files.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charThe ESC (escape) characterprotected Map<PCLSoftFontManager, Map<Typeface, Long>> protected Map<Typeface, PCLFontReader> static final int[]A list of all supported resolutions in PCL (values in dpi) -
Constructor Summary
ConstructorsConstructorDescriptionPCLGenerator(OutputStream out) Main constructor.PCLGenerator(OutputStream out, int maxResolution) Main constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFont(PCLSoftFontManager sfManager, Typeface font) voidchangePrintDirection(int rotate) Changes the current print direction while maintaining the current cursor position.voidClears the horizontal margins.final intconvertToGray(int r, int g, int b) Convert an RGB color value to a grayscale from 0 to 100.final intconvertToPCLShade(Color col) Convert a Color value to a PCL shade value (0-100).voiddefineGrayscalePattern(Color col, int patternID, int ditherMatrixSize) Generates a user-defined pattern for a dithering pattern matching the grayscale value of the color given.voidenterHPGL2Mode(boolean restorePreviousHPGL2Cursor) Enters the HP GL/2 mode.voidenterPCLMode(boolean restorePreviousPCLCursor) Enters the PCL mode.protected voidGenerate a filled rectangle at the current cursor position.final StringformatDouble2(double value) Formats a double value with two decimal positions for PCL output.final StringformatDouble4(double value) Formats a double value with four decimal positions for PCL output.voidformFeed()Sends the form feed character.floatReturns the dithering quality used when encoding gray or color images.intReturns the currently active text encoding.static booleanIndicates whether an image is a grayscale image.static booleanIndicates whether JAI is available.static booleanIndicates whether an image is a monochrome (b/w) image.voidpaintBitmap(RenderedImage img, Dimension targetDim, boolean sourceTransparency, PCLRenderingUtil pclUtil) Paint a bitmap at the current cursor position.voidpaintMonochromeBitmap(RenderedImage img, int resolution) Paint a bitmap at the current cursor position.voidPops the current cursor position from the stack.voidPushes the current cursor position on a stack (stack size: max 20 entries)voidResets the printer and restores the user default environment.voidselectColor(Color col) voidselectCurrentPattern(int patternID, int pattern) Select the current patternvoidselectDuplexMode(int selector) Selects the duplexing mode for the page.voidselectGrayscale(Color col) Selects the current grayscale color (the given color is converted to grayscales).voidselectOutputBin(int selector) Selects the output bin.voidselectPageSize(int selector) Selects the page size.voidselectPaperSource(int selector) Selects the paper source.voidSends the job separation command.voidsetCursorPos(double x, double y) Sets the cursor to a new absolute coordinate.voidsetDitheringQuality(float quality) Sets the dithering quality used when encoding gray or color images.voidsetPatternTransparencyMode(boolean transparent) Sets the pattern transparency mode.voidsetRasterGraphicsResolution(int value) Sets the raster graphics resolutionvoidsetSourceTransparencyMode(boolean transparent) Sets the source transparency mode.voidsetTextLength(int numberOfLines) The Text Length command can be used to define the bottom border.voidsetTopMargin(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.voidsetTransparencyMode(boolean source, boolean pattern) Sets the transparency modes.voidsetUnitOfMeasure(int value) Sets the unit of measure.voidsetVMI(double value) Sets the Vertical Motion Index (VMI).voidSends the universal end of language command (UEL).voidwriteBytes(byte[] bytes) Writes raw bytes to the output streamvoidwriteCommand(String cmd) Writes a PCL escape command to the output stream.voidWrites raw text (in ISO-8859-1 encoding) to the output stream.
-
Field Details
-
ESC
public static final char ESCThe ESC (escape) character- See Also:
-
PCL_RESOLUTIONS
public static final int[] PCL_RESOLUTIONSA list of all supported resolutions in PCL (values in dpi) -
fontReaderMap
-
fontManagerMap
-
-
Constructor Details
-
PCLGenerator
Main constructor.- Parameters:
out- the OutputStream to write the PCL stream to
-
PCLGenerator
Main constructor.- Parameters:
out- the OutputStream to write the PCL stream tomaxResolution- the maximum resolution to encode bitmap images at
-
-
Method Details
-
addFont
-
getOutputStream
- Returns:
- the OutputStream that this generator writes to
-
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
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
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
Writes raw bytes to the output stream- Parameters:
bytes- The bytes- Throws:
IOException- In case of an I/O error
-
formatDouble2
Formats a double value with two decimal positions for PCL output.- Parameters:
value- value to format- Returns:
- the formatted value
-
formatDouble4
Formats a double value with four decimal positions for PCL output.- Parameters:
value- value to format- Returns:
- the formatted value
-
universalEndOfLanguage
Sends the universal end of language command (UEL).- Throws:
IOException- In case of an I/O error
-
resetPrinter
Resets the printer and restores the user default environment.- Throws:
IOException- In case of an I/O error
-
separateJobs
Sends the job separation command.- Throws:
IOException- In case of an I/O error
-
formFeed
Sends the form feed character.- Throws:
IOException- In case of an I/O error
-
setUnitOfMeasure
Sets the unit of measure.- Parameters:
value- the resolution value (units per inch)- Throws:
IOException- In case of an I/O error
-
setRasterGraphicsResolution
Sets the raster graphics resolution- Parameters:
value- the resolution value (units per inch)- Throws:
IOException- In case of an I/O error
-
selectPageSize
Selects the page size.- Parameters:
selector- the integer representing the page size- Throws:
IOException- In case of an I/O error
-
selectPaperSource
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
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
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
Clears the horizontal margins.- Throws:
IOException- In case of an I/O error
-
setTopMargin
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
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
Sets the Vertical Motion Index (VMI).- Parameters:
value- the VMI value- Throws:
IOException- In case of an I/O error
-
setCursorPos
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
Pushes the current cursor position on a stack (stack size: max 20 entries)- Throws:
IOException- In case of an I/O error
-
popCursorPos
Pops the current cursor position from the stack.- Throws:
IOException- In case of an I/O error
-
changePrintDirection
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
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
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
Generate a filled rectangle at the current cursor position.- Parameters:
w- the width in millipointsh- the height in millipointscol- 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 forpatternID- the pattern ID to useditherMatrixSize- the size of the Bayer dither matrix to use (4 or 8 supported)- Throws:
IOException- In case of an I/O error
-
setSourceTransparencyMode
Sets the source transparency mode.- Parameters:
transparent- true if transparent, false for opaque- Throws:
IOException- In case of an I/O error
-
setPatternTransparencyMode
Sets the pattern transparency mode.- Parameters:
transparent- true if transparent, false for opaque- Throws:
IOException- In case of an I/O error
-
setTransparencyMode
Sets the transparency modes.- Parameters:
source- source transparency: true if transparent, false for opaquepattern- 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 componentg- the green componentb- the blue component- Returns:
- the gray value
-
convertToPCLShade
Convert a Color value to a PCL shade value (0-100).- Parameters:
col- the color- Returns:
- the PCL shade value (100=black)
-
selectGrayscale
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
- Throws:
IOException
-
selectCurrentPattern
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
Indicates whether an image is a monochrome (b/w) image.- Parameters:
img- the image- Returns:
- true if it's a monochrome image
-
isGrayscaleImage
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 imagetargetDim- the target Dimention (in mpt)sourceTransparency- true if the background should not be erased- Throws:
IOException- In case of an I/O error
-
paintMonochromeBitmap
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
-