}
/** {@inheritDoc} */
+ @Override
public void setContext(IFContext context) {
super.setContext(context);
this.pclUtil = new PCLRenderingUtil(context.getUserAgent());
}
/** {@inheritDoc} */
+ @Override
public void setDefaultFontInfo(FontInfo fontInfo) {
FontInfo fi = Java2DUtil.buildDefaultJava2DBasedFontInfo(fontInfo, getUserAgent());
setFontInfo(fi);
/** @return the target resolution */
protected int getResolution() {
- int resolution = (int)Math.round(getUserAgent().getTargetResolution());
+ int resolution = Math.round(getUserAgent().getTargetResolution());
if (resolution <= 300) {
return 300;
} else {
//----------------------------------------------------------------------------------------------
/** {@inheritDoc} */
+ @Override
public void startDocument() throws IFException {
super.startDocument();
try {
this.gen = new PCLGenerator(this.outputStream, getResolution());
+ this.gen.setDitheringQuality(pclUtil.getDitheringQuality());
if (!pclUtil.isPJLDisabled()) {
gen.universalEndOfLanguage();
}
/** {@inheritDoc} */
+ @Override
public void endDocumentHeader() throws IFException {
}
/** {@inheritDoc} */
+ @Override
public void endDocument() throws IFException {
try {
gen.separateJobs();
import org.apache.fop.util.bitmap.BitmapImageUtil;
import org.apache.fop.util.bitmap.DitherUtil;
-import org.apache.fop.util.bitmap.MonochromeBitmapConverter;
/**
* This class provides methods for generating PCL print files.
private boolean currentPatternTransparency = true;
private int maxBitmapResolution = PCL_RESOLUTIONS[PCL_RESOLUTIONS.length - 1];
+ private float ditheringQuality = 0.5f;
/**
* true: Standard PCL shades are used (poor quality). false: user-defined pattern are used
writeCommand("*v" + pattern + "T");
}
+ /**
+ * Sets the dithering quality used when encoding gray or color images. If not explicitely
+ * set a medium setting (0.5f) is used.
+ * @param quality a quality setting between 0.0f (worst/fastest) and 1.0f (best/slowest)
+ */
+ public void setDitheringQuality(float quality) {
+ quality = Math.min(Math.max(0f, quality), 1.0f);
+ this.ditheringQuality = quality;
+ }
+
+ /**
+ * Returns the dithering quality used when encoding gray or color images.
+ * @return the quality setting between 0.0f (worst/fastest) and 1.0f (best/slowest)
+ */
+ public float getDitheringQuality() {
+ return this.ditheringQuality;
+ }
+
/**
* Indicates whether an image is a monochrome (b/w) image.
* @param img the image
*/
public static boolean isMonochromeImage(RenderedImage img) {
return BitmapImageUtil.isMonochromeImage(img);
- }
+ }
/**
* Indicates whether an image is a grayscale image.
return resolution == calculatePCLResolution(resolution);
}
- private Dimension getAdjustedDimension(Dimension orgDim, double orgResolution,
- int pclResolution) {
- if (orgResolution == pclResolution) {
- return orgDim;
- } else {
- Dimension result = new Dimension();
- result.width = (int)Math.round((double)orgDim.width * pclResolution / orgResolution);
- result.height = (int)Math.round((double)orgDim.height * pclResolution / orgResolution);
- return result;
- }
- }
-
//Threshold table to convert an alpha channel (8-bit) into a clip mask (1-bit)
private static final byte[] THRESHOLD_TABLE = new byte[256];
static { // Initialize the arrays
popCursorPos();
}
- BufferedImage src = null;
- if (img instanceof BufferedImage && !scaled) {
- if (!isGrayscaleImage(img) || img.getColorModel().hasAlpha()) {
- /* Disabled as this doesn't work reliably, use the fallback below
- src = new BufferedImage(effDim.width, effDim.height,
- BufferedImage.TYPE_BYTE_GRAY);
- Graphics2D g2d = src.createGraphics();
- try {
- clearBackground(g2d, effDim);
- } finally {
- g2d.dispose();
- }
- ColorConvertOp op = new ColorConvertOp(
- ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
- op.filter((BufferedImage)img, src);
- */
- } else {
- src = (BufferedImage)img;
- }
- }
- if (src == null) {
- src = BitmapImageUtil.convertToGrayscale(img, effDim);
- }
- MonochromeBitmapConverter converter
- = BitmapImageUtil.createDefaultMonochromeBitmapConverter();
- converter.setHint("quality", "false");
-
- RenderedImage red = converter.convertToMonochrome(src);
+ RenderedImage red = BitmapImageUtil.convertToMonochrome(
+ img, effDim, this.ditheringQuality);
selectCurrentPattern(0, 0); //Solid black
setTransparencyMode(sourceTransparency || mask != null, true);
paintMonochromeBitmap(red, effResolution);
}
}
- private void clearBackground(Graphics2D g2d, Dimension effDim) {
- //white background
- g2d.setBackground(Color.WHITE);
- g2d.clearRect(0, 0, effDim.width, effDim.height);
- }
-
private int toGray(int rgb) {
// see http://www.jguru.com/faq/view.jsp?EID=221919
double greyVal = 0.072169d * (rgb & 0xff);
private static final long serialVersionUID = 6359884255324755026L;
/** "Quality" rendering (mixed native and bitmap for improved quality) */
- public static final PCLRenderingMode QUALITY = new PCLRenderingMode("quality");
+ public static final PCLRenderingMode QUALITY = new PCLRenderingMode("quality", 1.0f);
/** "Speed" rendering (maximum speed with native rendering, reduced visual quality) */
- public static final PCLRenderingMode SPEED = new PCLRenderingMode("speed");
+ public static final PCLRenderingMode SPEED = new PCLRenderingMode("speed", 0.25f);
/**
* "Bitmap" rendering (pages are painted entirely as bitmaps, maximum quality,
* reduced performance)
*/
- public static final PCLRenderingMode BITMAP = new PCLRenderingMode("bitmap");
+ public static final PCLRenderingMode BITMAP = new PCLRenderingMode("bitmap", 1.0f);
private String name;
+ private float defaultDitheringQuality;
/**
* Constructor to add a new named item.
* @param name Name of the item.
+ * @param defaultDitheringQuality the default dithering quality (0.0f..1.0f)
*/
- private PCLRenderingMode(String name) {
+ private PCLRenderingMode(String name, float defaultDitheringQuality) {
this.name = name;
+ this.defaultDitheringQuality = defaultDitheringQuality;
}
/** @return the name of the enum */
return this.name;
}
+ /**
+ * Returns the default dithering quality for this rendering mode.
+ * @return the default dithering quality (0.0f..1.0f)
+ */
+ public float getDefaultDitheringQuality() {
+ return this.defaultDitheringQuality;
+ }
+
/**
* Returns the enumeration/singleton object based on its name.
* @param name the name of the enumeration value
}
/** {@inheritDoc} */
+ @Override
public String toString() {
return "PCLRenderingMode:" + name;
}
*/
private PCLRenderingMode renderingMode = PCLRenderingMode.SPEED;
+ /** Controls the dithering quality when rendering gray or color images. */
+ private float ditheringQuality = 0.5f;
+
/**
* Controls whether all text should be painted as text. This is a fallback setting in case
* the mixture of native and bitmapped text does not provide the necessary quality.
*/
public void setRenderingMode(PCLRenderingMode mode) {
this.renderingMode = mode;
+ this.ditheringQuality = mode.getDefaultDitheringQuality();
}
/**
return this.renderingMode;
}
+ /**
+ * Returns the dithering quality to be used when encoding gray or color images.
+ * @return the quality (0.0f..1.0f)
+ */
+ public float getDitheringQuality() {
+ return this.ditheringQuality;
+ }
+
/**
* Controls whether PJL commands shall be generated by the PCL renderer.
* @param disable true to disable PJL commands