changeset 16735:462934a5d8b1

8172967: [macosx] Exception while working with layout for text containing unmappable character Reviewed-by: serb, psadhukhan
author prr
date Fri, 10 Feb 2017 10:20:22 -0800
parents 6ead667074d4
children 68e4988e48e6
files src/java.desktop/share/classes/sun/font/CompositeStrike.java src/java.desktop/share/classes/sun/font/ExtendedTextSourceLabel.java src/java.desktop/share/native/libfontmanager/hb-jdk-font.cc test/java/awt/font/TextLayout/MissingCodePointLayoutTest.java
diffstat 4 files changed, 51 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/share/classes/sun/font/CompositeStrike.java	Fri Feb 10 08:57:42 2017 -0800
+++ b/src/java.desktop/share/classes/sun/font/CompositeStrike.java	Fri Feb 10 10:20:22 2017 -0800
@@ -71,7 +71,9 @@
     }
 
     PhysicalStrike getStrikeForSlot(int slot) {
-
+        if (slot >= strikes.length) {
+            slot = 0;
+        }
         PhysicalStrike strike = strikes[slot];
         if (strike == null) {
             strike =
--- a/src/java.desktop/share/classes/sun/font/ExtendedTextSourceLabel.java	Fri Feb 10 08:57:42 2017 -0800
+++ b/src/java.desktop/share/classes/sun/font/ExtendedTextSourceLabel.java	Fri Feb 10 10:20:22 2017 -0800
@@ -626,7 +626,11 @@
         glyphinfo = gv.getGlyphInfo();
     }
     catch (Exception e) {
-        System.out.println(source);
+        if (DEBUG) {
+            System.err.println(source);
+            e.printStackTrace();
+        }
+        glyphinfo = new float[gv.getNumGlyphs() * numvals];
     }
 
     int numGlyphs = gv.getNumGlyphs();
--- a/src/java.desktop/share/native/libfontmanager/hb-jdk-font.cc	Fri Feb 10 08:57:42 2017 -0800
+++ b/src/java.desktop/share/native/libfontmanager/hb-jdk-font.cc	Fri Feb 10 10:20:22 2017 -0800
@@ -52,6 +52,9 @@
 
     *glyph = (hb_codepoint_t)
           env->CallIntMethod(font2D, sunFontIDs.f2dCharToGlyphMID, u);
+    if ((int)*glyph < 0) {
+        *glyph = 0;
+    }
     return (*glyph != 0);
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/font/TextLayout/MissingCodePointLayoutTest.java	Fri Feb 10 10:20:22 2017 -0800
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ */
+
+/* @test
+ * @summary Verify no exception for unsupported code point.
+ * @bug 8172967
+ */
+import java.awt.Font;
+import java.awt.font.FontRenderContext;
+import java.awt.font.TextLayout;
+
+public class MissingCodePointLayoutTest {
+    public static void main(String[] args) {
+        Font font = new Font("Tahoma", Font.PLAIN, 12);
+        String text = "\ude00";
+        FontRenderContext frc = new FontRenderContext(null, false, false);
+        TextLayout layout = new TextLayout(text, font, frc);
+        layout.getCaretShapes(0);
+    }
+}
+