JDK-4727902 : PrinterJob prints incorrect colors on Windows NT with version 1.4
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2002-08-07
  • Updated: 2002-11-27
  • Resolved: 2002-11-27
Related Reports
Duplicate :  
Description

Name: jk109818			Date: 08/07/2002


FULL PRODUCT VERSION :
Microsoft<R> Windows NT(TM)
<C> Copyright 1985-1996 Microsoft Corp.

C:\>java -version
java version "1.4.0"
Java<TM> 2 Runtime Environment, Standard Edition <build 1.4.0-b92>
Java Hotspot<TM> Client VM <build 1.4.0-b92, mixed mode>

C;\>

FULL OPERATING SYSTEM VERSION :Windows NT Version 4.0


EXTRA RELEVANT SYSTEM CONFIGURATION :
Printer is HP 895 cse
Happens in Forte 4 or running jar file from desktop

A DESCRIPTION OF THE PROBLEM :
Code which prints using printer job, prints incorrect
colors on Windows NT with an HP 895cse printer.  It works
fine on Windows XP in version 1.4, and on Windows NT with
version 1.3.  Blue prints it should, black prints as white,
red prints as aqua and white prints as a very pale purple.



REGRESSION.  Last worked in version 1.3.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. use this code to print a JFrame in Windows NT with an HP
895 cse printer.
2.
3.

EXPECTED VERSUS ACTUAL BEHAVIOR :
I had expected this to print the same colors on the page as
I see on the screen as it did in version 1.3 with same
printer.  (This exact code prints fine on Windows XP in
version 1.4 with a different HP printer.)
Wrong colors:
  red = aqua
  white = pale purple
  black = white
  grey = blue
  blue = blue (this is okay)

ERROR MESSAGES/STACK TRACES THAT OCCUR :
There is no error, the colors are just wrong

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

package data;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.awt.print.*;
import java.awt.Paint;
import java.awt.event.*;
import javax.swing.event.*;


/**
 *
 * @author  shea
 * @version
 */
public class ShortGuiPrint extends Object {
 private JFrame printme;

     /** Creates new PrintGUI */
    public ShortGuiPrint(JFrame f) {
        printme = new JFrame();
        printme = f;
    
    }
    
     
public void PrintPage(){
        try{
               PrinterJob pjob = PrinterJob.getPrinterJob();
               pjob.setJobName("Table");
               pjob.setCopies(1);
               
     
     pjob.setPrintable(new Printable(){
     public int print(Graphics pg, PageFormat pf, int pageNum){
           pg.setColor(Color.black);
           int frWth = printme.getWidth();
           int frHt = printme.getHeight();
             if (frHt < frWth){
               pf.setOrientation(PageFormat.LANDSCAPE);}
             else{
               pf.setOrientation(PageFormat.PORTRAIT);}
                               
           double pageHt = pf.getImageableHeight() + 50;
           double pageWth = pf.getImageableWidth() + 100;
          
           double scale = 1;
           
             if (frWth/pageWth > 1 || frHt/pageHt > 1){  // either h or w >
page size
                if(frWth/pageWth > frHt/pageHt)
                      scale = pageWth/frWth;
                else
                      scale = pageHt/frHt;
                        
             }
                  if (pageNum>0)
                     return Printable.NO_SUCH_PAGE;
           
                   Graphics2D g2 = (Graphics2D) pg;
                   g2.setColor(Color.black);
                   g2.translate(pf.getImageableX(),pf.getImageableY());
                   g2.scale(scale,scale);
                   
                   g2.translate(0f,0f);
                   g2.setClip(0,0,(int)pageWth,(int)pageHt);
                
                   printme.paint(g2);
                   return Printable.PAGE_EXISTS;
       }
     });
 
           if (pjob.printDialog() == false)
                 return;
           pjob.print();
          } catch (PrinterException pe){
              JOptionPane.showMessageDialog(printme, "PrinterError" +
pe, "Printing Error", JOptionPane.ERROR_MESSAGE);
          }
    }
         
}



---------- END SOURCE ----------

CUSTOMER WORKAROUND :
I can print blue text on a white background to have a
legible output, but not happy with this solution
(Review ID: 160049) 
======================================================================

Comments
EVALUATION This may be a problem in the printer driver in the way that it handles images. We have seen bugs like this in HP printer drivers. However the user is not helping himself by using non-optimal API. The example uses "printme.paint(g)" to print a Swing UI. This will not turn off Swing's double-buffering, so Swing will print as a low-res image. The user would do better to call printme.printAll(g) and would likely 1) not see a problem because it will no longer print an image, 2) get smaller, higher quality output. ###@###.### 2002-08-07 =========================== happens only using 16-bit display setting. Marking as duplicate of 4733565. ###@###.### 2002-11-27 ====================================
07-08-2002