[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] printing gradient fill produces huge print spool file - printer often dies

Hi,

I make a modeling program that just got new improved graphical look on the models.
After a while reports started coming in from customers that couldn't print the models anymore. The cause were that printing produced too much data for the printers to cope with. The actual problem was that we used gradient fills in the models, and that the printing system sent huge bit maps for each gradient figure. Is this really necessary? If I draw a gradient fill in other programs the print data could be some kilobytes, so the printer knows how to generate gradients itself.


Here is a simple example that demonstrates the problem:

For a HP LaserJet 4200 printer, running with "... if (false) ..." (no gradient) produces 480bytes of print data. Running with "... if (true) ..." (gradient) produces 15.8MB print data!


To run the example just open an eclipse and paste the code below into the package explorer and a new project with the java class for the file is created. Then open the Java Build Path property dialog, click Add variable..., select ECLIPSE_HOME, click extend and select plugins/org.eclipse.swt_3.3.2.v3349d.jar and plugins/org.eclipse.swt.win32.win32.x86_3.3.3.v3349.jar and click all OKs.


Here is the example code:

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.printing.PrintDialog;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.printing.PrinterData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class SimplePrint {
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.pack();
		shell.open();
		PrintDialog dialog = new PrintDialog(shell);
		PrinterData printerData = dialog.open();
		if (printerData != null) {
			Printer printer = new Printer(printerData);
			if (printer.startJob("Text")) {
				GC gc = new GC(printer);
				if (printer.startPage()) {
					if (false) {
						gc.fillGradientRectangle(200, 500, 4000, 4000, true);
					} else {
						gc.setBackground(display
								.getSystemColor(SWT.COLOR_BLACK));
						gc.fillRectangle(200, 500, 4000, 4000);
					}
					printer.endPage();
				}
				gc.dispose();
				printer.endJob();
			}
			printer.dispose();
			System.out.println("Print job done.");
		}
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}
}