Bug 43921 - gradient fill does not print its color properly
Summary: gradient fill does not print its color properly
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P1 normal (vote)
Target Milestone: ---   Edit
Assignee: Carolyn MacLeod CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-30 11:51 EDT by Karice McIntyre CLA
Modified: 2004-05-05 15:50 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karice McIntyre CLA 2003-09-30 11:51:44 EDT
When I try to print gradient foreground color as yellow, it
prints out turquoise.  If you change the fillGradient() call 
ti fillRectangle() the right color prints out.
I have seen this happen with other colors too.  

I altered the print example to demonstrate the problem.


package printing.tests;

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.printing.*;

public class BasicPrint {
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		FontDialog fontDialog = new FontDialog(shell, SWT.NULL);
		FontData displayFontData = fontDialog.open();
		PrintDialog dialog = new PrintDialog(shell, SWT.NULL);
		PrinterData data = dialog.open();
		shell.dispose();
		if (displayFontData == null || data == null) {
			System.out.println("Cancelled");
			return;
		}
		Printer printer = new Printer(data);
		Rectangle clientArea = printer.getClientArea();
		Font printerFont = new Font(printer, displayFontData.getName(), 
displayFontData.getHeight(), SWT.NORMAL);
		// this is the color that causes the problem
		Color foreground = new Color(printer, 255, 252, 194);	// 
yellow
		Color background = new Color(printer, 0xff, 0xff, 0xff);
		Image pageBuffer = new Image(printer, clientArea.width, 
clientArea.height);
		GC pageGC = new GC(pageBuffer);
		pageGC.setFont(printerFont);
		pageGC.setForeground(foreground);
		pageGC.setBackground(background);
		Rectangle rect = new Rectangle(20, 20, clientArea.width / 2, 
clientArea.height / 4);
		pageGC.drawRectangle(rect);
		pageGC.fillGradientRectangle(rect.x, rect.y, rect.width, 
rect.height, false);
		pageGC.drawString("Test", 222, 222);
		if (printer.startJob("Gradient Color Test")) {
			Rectangle trim = printer.computeTrim(0, 0, 0, 0);
			Point dpi = printer.getDPI();
			int leftMargin = dpi.x + trim.x; // one inch from left 
side of paper
			int topMargin = dpi.y / 2 + trim.y; // one-half inch 
from top edge of paper
			GC gc = new GC(printer);
			if (printer.startPage()) {
				gc.drawImage(pageBuffer, leftMargin, topMargin);
				gc.dispose();
				printer.endPage();
			}
			printer.endJob();
		}
		pageGC.dispose();
		pageBuffer.dispose();
	}		
}
Comment 1 Carolyn MacLeod CLA 2003-10-17 15:15:58 EDT
Tried it on eclipse 3.0 M4.
The colors are ok when printed from Windows XP, but they are wrong when 
printed from Windows 2000.
The printer is an IBM Infoprint Color 1220.

I also rewrote the snippet so that printing is done directly to the printer, 
instead of to a background image. Same problem (the color yellow is printed as 
turquoise).

Here is the rewritten snippet:

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.printing.*;

public class PrintColorGradient {
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		FontDialog fontDialog = new FontDialog(shell, SWT.NULL);
		FontData displayFontData = fontDialog.open();
		PrintDialog dialog = new PrintDialog(shell, SWT.NULL);
		PrinterData data = dialog.open();
		shell.dispose();
		if (displayFontData == null || data == null) {
			System.out.println("Cancelled");
			return;
		}
		Printer printer = new Printer(data);
		Rectangle clientArea = printer.getClientArea();
		Font printerFont = new Font(printer, displayFontData.getName
(), displayFontData.getHeight(), SWT.NORMAL);
		// this is the color that causes the problem
		Color foreground = new Color(printer, 255, 252, 194);	// 
yellow
		Color background = new Color(printer, 0xff, 0xff, 0xff);
		if (printer.startJob("Gradient Color Test")) {
			Rectangle trim = printer.computeTrim(0, 0, 0, 0);
			Point dpi = printer.getDPI();
			int leftMargin = dpi.x + trim.x; // one inch from left 
side of paper
			int topMargin = dpi.y / 2 + trim.y; // one-half inch 
from top edge of paper
			GC gc = new GC(printer);
			if (printer.startPage()) {
				gc.setFont(printerFont);
				gc.setForeground(foreground);
				gc.setBackground(background);
				Rectangle rect = new Rectangle(20, 20, 
clientArea.width / 2, clientArea.height / 4);
				gc.drawRectangle(rect);
				gc.fillGradientRectangle(rect.x, rect.y, 
rect.width, rect.height, false);
				gc.drawString("Test", 222, 222);
				gc.dispose();
				printer.endPage();
			}
			printer.endJob();
		}
	}		
}
Comment 2 Karice McIntyre CLA 2004-04-19 13:03:51 EDT
This still doesn't work in 3.0 M8 (Win2k).  We would really like this fixed for 
Eclipse 3.0
Comment 3 Carolyn MacLeod CLA 2004-04-19 13:41:39 EDT
I can't get to it right away, but I am marking it P1 so that it goes to the 
top of my pile (note that I do have several P1's).

If it turns out to be a platform limitation, I will try to come up with a 
suitable workaround, such as filling the gradient using fillRectangle instead, 
and doing a bit of math.

VI, do you have any experience with filling gradients without using the 
platform gradient method? Also, do you happen to have any experience with this 
bug (Printer uses a different color when you use GC.fillGradientRectangle)?
Comment 4 Carolyn MacLeod CLA 2004-05-05 15:50:20 EDT
Fixed > 20040505.

We emulate the gradient fill for printing now. It was failing on Win98 and 
Win2K.