Blame 1182011_JavaPrintApiDoesNotPrintUmlautCharsWithPostscriptOutputCorrectly.patch

9710a8e
9710a8e
# HG changeset patch
9710a8e
# User neugens
9710a8e
# Date 1421686672 -3600
9710a8e
# Node ID 868404fc8be0163f50c242f473ecfbe4eccfe519
9710a8e
# Parent  36c8318010acb190176744eb0a67a321ae23e711
9710a8e
8067364: Printing to Postscript doesn't support dieresis
9710a8e
Summary: Fix regression caused by fix for 8023990
9710a8e
Reviewed-by: bae, prr
9710a8e
Contributed-by: neugens@redhat.com, philip.race@oracle.com
9710a8e
9710a8e
diff -r 36c8318010ac -r 868404fc8be0 src/solaris/classes/sun/font/FcFontConfiguration.java
9710a8e
--- jdk8/jdk/src/solaris/classes/sun/font/FcFontConfiguration.java	Tue Dec 16 19:46:22 2014 +0000
9710a8e
+++ jdk8/jdk/src/solaris/classes/sun/font/FcFontConfiguration.java	Mon Jan 19 17:57:52 2015 +0100
9710a8e
@@ -180,7 +180,7 @@
9710a8e
         String[] componentFaceNames = cfi[idx].getComponentFaceNames();
9710a8e
         FontDescriptor[] ret = new FontDescriptor[componentFaceNames.length];
9710a8e
         for (int i = 0; i < componentFaceNames.length; i++) {
9710a8e
-            ret[i] = new FontDescriptor(componentFaceNames[i], StandardCharsets.UTF_8.newEncoder(), new int[0]);
9710a8e
+            ret[i] = new FontDescriptor(componentFaceNames[i], StandardCharsets.ISO_8859_1.newEncoder(), new int[0]);
9710a8e
         }
9710a8e
 
9710a8e
         return ret;
9710a8e
diff -r 36c8318010ac -r 868404fc8be0 test/javax/print/PrintSEUmlauts/PrintSEUmlauts.java
9710a8e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
9710a8e
+++ jdk8/jdk/test/javax/print/PrintSEUmlauts/PrintSEUmlauts.java	Mon Jan 19 17:57:52 2015 +0100
9710a8e
@@ -0,0 +1,120 @@
9710a8e
+/*
9710a8e
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
9710a8e
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9710a8e
+ *
9710a8e
+ * This code is free software; you can redistribute it and/or modify it
9710a8e
+ * under the terms of the GNU General Public License version 2 only, as
9710a8e
+ * published by the Free Software Foundation.  Oracle designates this
9710a8e
+ * particular file as subject to the "Classpath" exception as provided
9710a8e
+ * by Oracle in the LICENSE file that accompanied this code.
9710a8e
+ *
9710a8e
+ * This code is distributed in the hope that it will be useful, but WITHOUT
9710a8e
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9710a8e
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9710a8e
+ * version 2 for more details (a copy is included in the LICENSE file that
9710a8e
+ * accompanied this code).
9710a8e
+ *
9710a8e
+ * You should have received a copy of the GNU General Public License version
9710a8e
+ * 2 along with this work; if not, write to the Free Software Foundation,
9710a8e
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9710a8e
+ *
9710a8e
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9710a8e
+ * or visit www.oracle.com if you need additional information or have any
9710a8e
+ * questions.
9710a8e
+ */
9710a8e
+import java.awt.Graphics;
9710a8e
+import java.awt.GraphicsEnvironment;
9710a8e
+import java.awt.print.PageFormat;
9710a8e
+import java.awt.print.Printable;
9710a8e
+import java.io.File;
9710a8e
+import java.io.FileInputStream;
9710a8e
+import java.io.FileOutputStream;
9710a8e
+import java.io.IOException;
9710a8e
+import java.nio.charset.StandardCharsets;
9710a8e
+import javax.print.DocFlavor;
9710a8e
+import javax.print.DocPrintJob;
9710a8e
+import javax.print.SimpleDoc;
9710a8e
+import javax.print.StreamPrintService;
9710a8e
+import javax.print.StreamPrintServiceFactory;
9710a8e
+import javax.print.attribute.HashDocAttributeSet;
9710a8e
+import javax.print.attribute.HashPrintRequestAttributeSet;
9710a8e
+import javax.print.event.PrintJobAdapter;
9710a8e
+import javax.print.event.PrintJobEvent;
9710a8e
+
9710a8e
+/*
9710a8e
+ * @test
9710a8e
+ * @bug 8067364
9710a8e
+ * @summary Printing to Postscript doesn't support dieresis
9710a8e
+ * @build PrintSEUmlauts
9710a8e
+ * @run main/othervm PrintSEUmlauts
9710a8e
+ */
9710a8e
+public class PrintSEUmlauts implements Printable {
9710a8e
+
9710a8e
+    public static void main(String[] args) throws Exception {
9710a8e
+
9710a8e
+        GraphicsEnvironment.getLocalGraphicsEnvironment();
9710a8e
+
9710a8e
+        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
9710a8e
+        String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();
9710a8e
+
9710a8e
+        StreamPrintServiceFactory[] factories =
9710a8e
+                StreamPrintServiceFactory.
9710a8e
+                        lookupStreamPrintServiceFactories(flavor, mime);
9710a8e
+        if (factories.length == 0) {
9710a8e
+            System.out.println("No print service found.");
9710a8e
+            return;
9710a8e
+        }
9710a8e
+
9710a8e
+        FileOutputStream output = new FileOutputStream("out.ps");
9710a8e
+        StreamPrintService service = factories[0].getPrintService(output);
9710a8e
+
9710a8e
+        SimpleDoc doc =
9710a8e
+             new SimpleDoc(new PrintSEUmlauts(),
9710a8e
+                           DocFlavor.SERVICE_FORMATTED.PRINTABLE,
9710a8e
+                           new HashDocAttributeSet());
9710a8e
+        DocPrintJob job = service.createPrintJob();
9710a8e
+        job.addPrintJobListener(new PrintJobAdapter() {
9710a8e
+            @Override
9710a8e
+            public void printJobCompleted(PrintJobEvent pje) {
9710a8e
+                testPrintAndExit();
9710a8e
+            }
9710a8e
+        });
9710a8e
+
9710a8e
+        job.print(doc, new HashPrintRequestAttributeSet());
9710a8e
+    }
9710a8e
+
9710a8e
+    private static final boolean DEBUG = false;
9710a8e
+    private static void testPrintAndExit() {
9710a8e
+        String expected = "<e4> 7.44 100.0 100.0 S";
9710a8e
+        String content = "";
9710a8e
+
9710a8e
+        File file = new File("out.ps");
9710a8e
+        if (!DEBUG) {
9710a8e
+            file.deleteOnExit();
9710a8e
+        }
9710a8e
+
9710a8e
+        try (FileInputStream stream = new FileInputStream(file)) {
9710a8e
+            byte[] data = new byte[(int) file.length()];
9710a8e
+            stream.read(data);
9710a8e
+            content = new String(data, StandardCharsets.ISO_8859_1);
9710a8e
+        } catch (IOException ex) {
9710a8e
+            ex.printStackTrace();
9710a8e
+        }
9710a8e
+
9710a8e
+        if (!content.contains(expected)) {
9710a8e
+            System.err.println("FAIL");
9710a8e
+            if (DEBUG) {
9710a8e
+                System.err.println("printing content");
9710a8e
+                System.err.println(content);
9710a8e
+            }
9710a8e
+            throw new RuntimeException("Expected <e4> to represent 'ä' but not found!");
9710a8e
+        }
9710a8e
+        System.err.println("SUCCESS");
9710a8e
+    }
9710a8e
+
9710a8e
+    public int print(Graphics g, PageFormat pf, int pg) {
9710a8e
+       if (pg > 0) return NO_SUCH_PAGE;
9710a8e
+       g.drawString("ä", 100, 100);
9710a8e
+       return PAGE_EXISTS;
9710a8e
+   }
9710a8e
+}
9710a8e