JDK-8074259 : Wrong postscript output with german umlauts (????...) when printing JTextArea
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7u71
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2015-01-16
  • Updated: 2015-03-03
  • Resolved: 2015-03-03
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) Server VM (build 24.71-b01, mixed mode)

java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) Server VM (build 24.65-b04, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux pc123 3.7.10-1.16-desktop #1 SMP PREEMPT Fri May 31 20:21:23 UTC 2013 (97c14ba) i686 i686 i386 GNU/Linux (openSUSE 12.3 x86) 
Linux pc123 3.11.10-25-desktop #1 SMP PREEMPT Wed Dec 17 17:57:03 UTC 2014 (8210f77) i686 i686 i386 GNU/Linux (openSUSE 13.1 x86)
Linux pc123 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:08:14 UTC 2014 i686 i686 i686 GNU/Linux (Ubuntu 14.04 x86)

A DESCRIPTION OF THE PROBLEM :
Create a javax.swing.JTextArea with text containing german umlauts. Use a java.awt.PrinterJob object to print the contents of the JTextArea (to a postscript printer, or to a postscript file) using the native print dialog.
All german umlauts are displayed incorrectly, instead unrecognisable utf8-chars are printed (e.g. the symbol for "1/4").

REGRESSION.  Last worked in version 7u60

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) Server VM (build 24.60-b09, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- Start the example program (test case below in this bug report)
- Enter some Text with german umlauts in the JTextArea (e.g. "abc������������")
- Click the "Drucken" button at the bottom
- Click "OK" in the Print Dialog

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A page showing the correct text should be printed on the printer
ACTUAL -
Standard characters (abc) are printed correctly, german umlauts are printed as some unrecognisable other characters

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import javax.swing.*;

public class PrinterJob_Test extends JFrame implements Printable, ActionListener {

    private Component print_component;
	private JTextArea textArea;
	private JButton button;
	private JPanel panel;
    
	public PrinterJob_Test() {
		textArea = new JTextArea(6, 20);
		JScrollPane scrollPane = new JScrollPane(textArea);
		panel = new JPanel();
		panel.setLayout(new BorderLayout());
		panel.add(scrollPane, BorderLayout.CENTER);
		
		button = new JButton("Drucken");
		button.addActionListener(this);
		panel.add(button, BorderLayout.SOUTH);
		
		this.setContentPane(panel);
		this.setTitle("PrinterJob_Test");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.pack();
	}
    public static void printComponent(Component c) {
        new PrinterJob_Test(c).doPrint();
    }
 
    public PrinterJob_Test(Component comp) {
        this.print_component = comp;
    }
 
    public void doPrint() {
        PrinterJob printJob = PrinterJob.getPrinterJob();
        printJob.setPrintable(this);
        if (printJob.printDialog()) {
            try {
                printJob.print();
            } catch (PrinterException pe) {
                System.out.println("Error printing: " + pe);
            }
        }
    }
 
    @Override
    public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
        if (pageIndex > 0) {
            return (NO_SUCH_PAGE);
        } else {
            Graphics2D g2d = (Graphics2D) g;
            g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
            disableDoubleBuffering(print_component);
            print_component.paint(g2d);
            enableDoubleBuffering(print_component);
            return (PAGE_EXISTS);
        }
    }
 
    public static void disableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(false);
    }
 
    public static void enableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(true);
    }
    
    
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == button) {
			try {
				print();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
	}
	
	private void print() {
		PrinterJob_Test.printComponent(textArea);
	}
	
	public static void main(String args[]) {
		JFrame window = new PrinterJob_Test();
		window.setVisible(true);
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
We could narrow the bug down to the class "sun.font.FcFontConfiguration.class" contained in the file jre/lib/rt.jar.
In Java 7u60, this class contains a method "FontDescriptor[] getFontDescriptors(String, int)", which was replaced in Java 7u71 by the method "FontDescriptor[] buildFontDescriptors(int, int)".

Based on the file jre/lib/rt.jar in Java 7u71, unzip the file and replace the class sun/font/FcFontConfiguration.class with the same class file from the rt.jar in Java 7u60. Zip the complete directory structure into jre/lib/rt.jar again


Result: Using the modified version of rt.jar the program works correctly with Java 7u71.

This is not an applicable workaround to use in production systems, however it might help to narrow down the problem.


Comments
This issue describes the same problem as JDK-8068168.
16-01-2015