JDK-8068168 : cannot print special characteres using PrinterJob since patch JDK-8023990
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 7u71,8u11,8u20,8u40,9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-12-22
  • Updated: 2015-01-21
  • Resolved: 2015-01-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
va version "1.7.0_71"
OpenJDK Runtime Environment (IcedTea 2.5.3) (suse-1.1-x86_64)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
openSUSE 13.2 (x86_64)
VERSION = 13.2
CODENAME = Harlequin

EXTRA RELEVANT SYSTEM CONFIGURATION :
Linux linux-zr7s.site 3.16.7-7-desktop #1 SMP PREEMPT Wed Dec 17 18:00:44 UTC 2014 (762f27a) x86_64 x86_64 x86_64 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
The proposed application is used to print documents that includes special characters. Source code uses UTF-8, file.encoding property is set to UTF-8, however characters like ���������� fails to print and junk is printed instead. A further analysis in the problem, the output postscript file uses Latin1 while the text is printed in UTF-8, hence the failure.

This behaviour was seen after installing the patch JDK-8023990, before, special characters are correctly printed out.

REGRESSION.  Last worked in version 7u67

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Please use the attached application. It will show a printer dialog, print as a file and open It, the first three lines are right, the rest fails to print special characters.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
UTF-8 characters are printed out correctly
ACTUAL -
UTF-8 characters are printed as junk instead of correctly

ERROR MESSAGES/STACK TRACES THAT OCCUR :
None, instead, bad behaviour

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package es.eurohielo;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;

public class PrintTest implements Printable {

	@Override
	public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
			throws PrinterException {
		
		if (pageIndex > 1) {
			return Printable.NO_SUCH_PAGE;
		}
		
		Graphics2D g2d = (Graphics2D) graphics;
		
		RenderingHints rh =
	            new RenderingHints(RenderingHints.KEY_ANTIALIASING, 
	            RenderingHints.VALUE_ANTIALIAS_ON);

		rh.put(RenderingHints.KEY_RENDERING,
				RenderingHints.VALUE_RENDER_QUALITY);

		g2d.setRenderingHints(rh);

		g2d.setFont(new Font("Nimbus", Font.PLAIN, 8));

		g2d.drawString("Here's a little song I wrote", 20, 80);
		g2d.drawString("You might want to sing it note for note", 20, 100);
		g2d.drawString("Don't worry be happy", 20, 120);
		g2d.drawString("Now let's print some junk", 20, 140);
		g2d.drawString("������", 20, 160);
		g2d.drawString("Albar��n n�� ", 20, 180);

		return Printable.PAGE_EXISTS;
		
	}
	
	/**
	 * Method that does the magic of printing
	 * 
	 * Please run this program, after that select in the dialog to print as a file and check the output.
	 * Third first lines are printed with no issues, four and fifth print junk instead of special characters
	 * I have a similar code like this one running in PROD for more than 10 years and never show this behavior
	 * Until JDK-8023990 was installed 
	 * 
	 */
	public void print() {
		try {
			PrinterJob job = PrinterJob.getPrinterJob();

			if (job.printDialog()) {

				Book book = new Book();
				
				PageFormat pf = new PageFormat();
				Paper paper = pf.getPaper();
				paper.setSize(595, 842);
				paper.setImageableArea(20, 20, 555, 802);
				pf.setPaper(paper);
				book.append(this, pf);

				job.setPageable(book);

				job.print();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		PrintTest pt = new PrintTest();
		pt.print();
	}
	
}


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

CUSTOMER SUBMITTED WORKAROUND :
No workaround known


Comments
PrintSpecialCharactersTest.java is the test case provided in the description, I modified it to add java version. The java file uses UTF-8 encoding, to get the correct output you have to make sure javac treats it as UTF-8. The compiled class file is also attached. It was compiled with 7u51 and 7u51 produces the correct output. When the class file is run with 8u40-ea-b19, garbage is printed instead of the expected Unicode characters. See the resulting output PS files.
23-12-2014