--- old/src/java.desktop/share/classes/javax/swing/text/DefaultEditorKit.java 2018-04-25 08:07:27.000000000 -0700 +++ new/src/java.desktop/share/classes/javax/swing/text/DefaultEditorKit.java 2018-04-25 08:07:27.000000000 -0700 @@ -34,6 +34,8 @@ import javax.swing.KeyStroke; import javax.swing.SwingConstants; import javax.swing.UIManager; +import static sun.font.CharToGlyphMapper.isVariationSelector; +import static sun.font.CharToGlyphMapper.isBaseChar; /** * This is the set of things needed by a text component @@ -1070,6 +1072,20 @@ c1 >= '\uDC00' && c1 <= '\uDFFF') { delChars = 2; } + + // Variation Selector and base char should be deleted. + if ((dot > 2 && isVariationSelector(c0, c1)) || + (isVariationSelector(c1))) { + String targetChars = doc.getText(0, dot); + int pre = targetChars.codePointBefore(dot - delChars); + if (isBaseChar(pre)){ + if (pre >= 0x10000){ + delChars += 2; + }else{ + delChars += 1; + } + } + } } doc.remove(dot - delChars, delChars); @@ -1118,10 +1134,28 @@ String dotChars = doc.getText(dot, 2); char c0 = dotChars.charAt(0); char c1 = dotChars.charAt(1); + int baseChar = (int)c0; if (c0 >= '\uD800' && c0 <= '\uDBFF' && c1 >= '\uDC00' && c1 <= '\uDFFF') { delChars = 2; + baseChar = (c0-0xD800)*0x400 + c1-0xDC00 + 0x10000; + } + + // Variation Selector and base char should be deleted. + if (isBaseChar(baseChar) && + dot < doc.getLength() - delChars) { + String nextChar = doc.getText(dot+delChars, 1); + char c2 = nextChar.charAt(0); + if (isVariationSelector(c2)) { + delChars += 1; + }else if (dot < doc.getLength() - delChars - 1) { + nextChar = doc.getText(dot + delChars + 1, 1); + char c3 = nextChar.charAt(0); + if (isVariationSelector(c2,c3)) { + delChars += 2; + } + } } } --- old/src/java.desktop/share/classes/sun/font/CMap.java 2018-04-25 08:07:29.000000000 -0700 +++ new/src/java.desktop/share/classes/sun/font/CMap.java 2018-04-25 08:07:29.000000000 -0700 @@ -140,6 +140,7 @@ * Using this saves running character coverters repeatedly. */ char[] xlat; + UVS uvs = null; static CMap initialize(TrueTypeFont font) { @@ -149,6 +150,7 @@ int three0=0, three1=0, three2=0, three3=0, three4=0, three5=0, three6=0, three10=0; + int zero5=0; // for Unicode Variation Sequences boolean threeStar = false; ByteBuffer cmapBuffer = font.getTableBuffer(TrueTypeFont.cmapTag); @@ -173,6 +175,12 @@ case 6: three6 = offset; break; // Johab case 10: three10 = offset; break; // MS Unicode surrogates } + } else if (platformID == 0) { + encodingID = cmapBuffer.getShort(); + offset = cmapBuffer.getInt(); + if (encodingID == 5) { + zero5 = offset; + } } } @@ -262,6 +270,10 @@ */ cmap = createCMap(cmapBuffer, cmapBuffer.getInt(8), null); } + // For Unicode Variation Sequences + if (cmap != null && zero5 != 0){ + cmap.createUVS(cmapBuffer, zero5); + } return cmap; } @@ -424,6 +436,20 @@ } } + private void createUVS(ByteBuffer buffer, int offset) { + int subtableFormat = buffer.getChar(offset); + if (subtableFormat == 14) { + long subtableLength = buffer.getInt(offset + 2) & INTMASK; + if (offset + subtableLength > buffer.capacity()) { + if (FontUtilities.isLogging()) { + FontUtilities.getLogger().warning("Cmap UVS subtable overflows buffer."); + } + } + this.uvs = new UVS(buffer, offset); + } + return; + } + /* final char charVal(byte[] cmap, int index) { return (char)(((0xff & cmap[index]) << 8)+(0xff & cmap[index+1])); @@ -1059,4 +1085,172 @@ } return -1; } + + static class UVS { + int numSelectors; + int[] selector; + + //for Default UVS Table + int[] numUnicodeValueRanges; + int[][] startUnicodeValue; + byte[][] additionalCount; + //for Non-Default UVS Table + int[] numUVSMapping; + int[][] unicodeValue; + char[][] glyphID; + + UVS(ByteBuffer buffer, int offset) { + numSelectors = buffer.getInt(offset+6); + selector = new int[numSelectors]; + numUnicodeValueRanges = new int[numSelectors]; + startUnicodeValue = new int[numSelectors][]; + additionalCount = new byte[numSelectors][]; + numUVSMapping = new int[numSelectors]; + unicodeValue = new int[numSelectors][]; + glyphID = new char[numSelectors][]; + + for (int i = 0; i < numSelectors; i++) { + buffer.position(offset + 10 + i * 11); + selector[i] = (buffer.get() & 0xff) << 16; //UINT24 + selector[i] += (buffer.get() & 0xff) << 8; + selector[i] += buffer.get() & 0xff; + + //for Default UVS Table + int tableOffset = buffer.getInt(offset + 10 + i * 11 + 3); + if (tableOffset == 0){ + numUnicodeValueRanges[i] = 0; + }else{ + buffer.position(offset+tableOffset); + numUnicodeValueRanges[i] = buffer.getInt() & INTMASK; + + startUnicodeValue[i] = new int[numUnicodeValueRanges[i]]; + additionalCount[i] = new byte[numUnicodeValueRanges[i]]; + + for (int j = 0; j < numUnicodeValueRanges[i]; j++) { + int temp = (buffer.get() & 0xff) << 16; //UINT24 + temp += (buffer.get() & 0xff) << 8; + temp += buffer.get() & 0xff; + startUnicodeValue[i][j] = temp; + additionalCount[i][j] = buffer.get(); + } + } + + //for Non-Default UVS Table + tableOffset = buffer.getInt(offset + 10 + i * 11 + 7); + if (tableOffset == 0){ + numUVSMapping[i] = 0; + } else { + buffer.position(offset+tableOffset); + numUVSMapping[i] = buffer.getInt() & INTMASK; + unicodeValue[i] = new int[numUVSMapping[i]]; + glyphID[i] = new char[numUVSMapping[i]]; + + for (int j = 0; j < numUVSMapping[i]; j++) { + int temp = (buffer.get() & 0xff) << 16; //UINT24 + temp += (buffer.get() & 0xff) << 8; + temp += buffer.get() & 0xff; + unicodeValue[i][j]= temp; + glyphID[i][j]= buffer.getChar(); + } + } + } + } + + private int cachedCode; + private int targetCachedCode; + private int targetCachedSelector = -1; + + /* getGlyph for Variation selector + return value: + 0: A special glyph for the variation selector is Not found + -1: Default glyph should be used + 0>: A special glyph is found + */ + int getGlyph(int charCode, int variationSelector) { + synchronized(this){ + if (charCode == targetCachedCode && variationSelector == targetCachedSelector) { + return cachedCode; + } + } + + int targetSelector = -1; + int result; + for (int i = 0; i < numSelectors; i++) { + if (selector[i] == variationSelector) { + targetSelector = i; + break; + } + } + if (targetSelector == -1){ + result = 0; + storeCache(charCode, variationSelector, result); + return result; + } + if (numUnicodeValueRanges[targetSelector] > 0) { + int index = java.util.Arrays.binarySearch( + startUnicodeValue[targetSelector], charCode); + if (index >= 0){ + result = -1; //pass through default table in actual CMAP + storeCache(charCode, variationSelector, result); + return result; + } else { + index = -index - 2; + if (index >=0 + && charCode >= startUnicodeValue[targetSelector][index] + && charCode <= startUnicodeValue[targetSelector][index] + +additionalCount[targetSelector][index]) { + result = -1; //pass through default table in actual CMAP + storeCache(charCode, variationSelector, result); + return result; + } + } + } + if (numUVSMapping[targetSelector] > 0){ + int index = java.util.Arrays.binarySearch( + unicodeValue[targetSelector], charCode); + if (index >= 0){ + result = glyphID[targetSelector][index]; + storeCache(charCode, variationSelector, result); + return result; + } + } + result = 0; + storeCache(charCode, variationSelector, result); + return result; + } + + private synchronized void storeCache(int charCode, int variationSelector, int glyph) { + cachedCode = glyph; + targetCachedCode = charCode; + targetCachedSelector = variationSelector; + } + + boolean hasVariationSelectorGlyph(int charCode, int variationSelector) { + int result= getGlyph(charCode, variationSelector); + if (result == 0) { + return false; + } else { + return true; + } + } + } + + public char getGlyph(int charCode, int variationSelector) { + if (uvs == null) { + return 0; + } + int result = uvs.getGlyph(charCode, variationSelector); + if (result == -1) { + result = this.getGlyph(charCode); + } + return (char)(result & 0xFFFF); + } + + public boolean hasVariationSelectorGlyph(int charCode, int variationSelector) { + if (uvs == null) { + return false; + } + return uvs.hasVariationSelectorGlyph(charCode, variationSelector); + } + } --- old/src/java.desktop/share/classes/sun/font/CharToGlyphMapper.java 2018-04-25 08:07:31.000000000 -0700 +++ new/src/java.desktop/share/classes/sun/font/CharToGlyphMapper.java 2018-04-25 08:07:31.000000000 -0700 @@ -88,4 +88,38 @@ public abstract void charsToGlyphs(int count, int[] unicodes, int[] glyphs); + protected boolean hasVariationSelectorGlyph(int charCode, int variationSelector) { + return false; + } + + public static boolean isBaseChar(int charCode){ + int type = Character.getType(charCode); + if (type == Character.UNASSIGNED || + type == Character.CONTROL || + type == Character.FORMAT || + type == Character.NON_SPACING_MARK) { + return false; + } + return java.text.Normalizer.isNormalized( + java.nio.CharBuffer.wrap(Character.toChars(charCode)), + java.text.Normalizer.Form.NFD); + } + + public static boolean isVariationSelector(int charCode) { + return ((charCode >= 0xE0100 && charCode <= 0xE01FF) || + (charCode >= 0xFE00 && charCode <= 0xFE0F) || + (charCode >= 0x180B && charCode <= 0x180D)); + } + + public static boolean isVariationSelector(char charCode) { + return ((charCode >= 0xFE00 && charCode <= 0xFE0F) || + (charCode >= 0x180B && charCode <= 0x180D)); + } + + public static boolean isVariationSelector(char charCode1, char charCode2) { + return (charCode1 == 0xDB40 && + charCode2 >= 0xDD00 && charCode2 <= 0xDDEF); + // 0xE0100 - 0xE01FF + } + } --- old/src/java.desktop/share/classes/sun/font/CompositeGlyphMapper.java 2018-04-25 08:07:34.000000000 -0700 +++ new/src/java.desktop/share/classes/sun/font/CompositeGlyphMapper.java 2018-04-25 08:07:33.000000000 -0700 @@ -133,6 +133,29 @@ return missingGlyph; } + private int convertToGlyph(int unicode, int variationSelector) { + if (variationSelector == 0) { + return convertToGlyph(unicode); + } + for (int slot = 0; slot < font.numSlots; slot++) { + if (!hasExcludes || !font.isExcludedChar(slot, unicode)) { + CharToGlyphMapper mapper = getSlotMapper(slot); + int glyphCode = missingGlyph; + if (mapper.hasVariationSelectorGlyph(unicode, variationSelector)) { + int glyphCodes[] = { 0, 0}; + int codes[] = {unicode, variationSelector}; + mapper.charsToGlyphs(2, codes, glyphCodes); + glyphCode = glyphCodes[0]; + if (glyphCode != mapper.getMissingGlyphCode()) { + glyphCode = compositeGlyphCode(slot, glyphCode); + return glyphCode; + } + } + } + } + return convertToGlyph(unicode); //retry without Variation Selector + } + public int getNumGlyphs() { int numGlyphs = 0; /* The number of glyphs in a composite is affected by @@ -193,6 +216,8 @@ for (int i=0; i= HI_SURROGATE_START && code <= HI_SURROGATE_END && i < count - 1) { @@ -203,12 +228,32 @@ code = (code - HI_SURROGATE_START) * 0x400 + low - LO_SURROGATE_START + 0x10000; glyphs[i + 1] = INVISIBLE_GLYPH_ID; + step = 2; } } - int gc = glyphs[i] = getCachedGlyphCode(code); - if (gc == UNINITIALIZED_GLYPH) { - glyphs[i] = convertToGlyph(code); + if (i < count - step && + isVariationSelector(unicodes[i+step]) && + isBaseChar(code)) { + variationSelector = unicodes[i+step]; + glyphs[i] = convertToGlyph(code, variationSelector); + glyphs[i+step] = INVISIBLE_GLYPH_ID; + i += 1; + } else if (i < count - step -1 && + isVariationSelector(unicodes[i+step], unicodes[i+step+1]) && + isBaseChar(code)) { + variationSelector = (unicodes[i+step] - HI_SURROGATE_START) * + 0x400 + unicodes[i+step+1] - LO_SURROGATE_START + 0x10000; + glyphs[i] = convertToGlyph(code, variationSelector); + glyphs[i+step] = INVISIBLE_GLYPH_ID; + glyphs[i+step+1] = INVISIBLE_GLYPH_ID; + i += 2; + } + if (variationSelector == 0) { + int gc = glyphs[i] = getCachedGlyphCode(code); + if (gc == UNINITIALIZED_GLYPH) { + glyphs[i] = convertToGlyph(code); + } } if (code < FontUtilities.MIN_LAYOUT_CHARCODE) { @@ -232,6 +277,8 @@ public void charsToGlyphs(int count, char[] unicodes, int[] glyphs) { for (int i=0; i= HI_SURROGATE_START && code <= HI_SURROGATE_END && i < count - 1) { @@ -242,19 +289,36 @@ code = (code - HI_SURROGATE_START) * 0x400 + low - LO_SURROGATE_START + 0x10000; - int gc = glyphs[i] = getCachedGlyphCode(code); - if (gc == UNINITIALIZED_GLYPH) { - glyphs[i] = convertToGlyph(code); - } - i += 1; // Empty glyph slot after surrogate - glyphs[i] = INVISIBLE_GLYPH_ID; - continue; + glyphs[i+1] = INVISIBLE_GLYPH_ID; + step = 2; } } - int gc = glyphs[i] = getCachedGlyphCode(code); - if (gc == UNINITIALIZED_GLYPH) { - glyphs[i] = convertToGlyph(code); + if (i < count - step && + isVariationSelector(unicodes[i+step]) && + isBaseChar(code)) { + variationSelector = unicodes[i+step]; + glyphs[i] = convertToGlyph(code, variationSelector); + glyphs[i+step] = INVISIBLE_GLYPH_ID; + i += 1; + } else if (i < count - step -1 && + isVariationSelector(unicodes[i+step], unicodes[i+step+1]) && + isBaseChar(code)) { + variationSelector = (unicodes[i+step] - HI_SURROGATE_START) * + 0x400 + unicodes[i+step+1] - LO_SURROGATE_START + 0x10000; + glyphs[i] = convertToGlyph(code, variationSelector); + glyphs[i+step] = INVISIBLE_GLYPH_ID; + glyphs[i+step+1] = INVISIBLE_GLYPH_ID; + i += 2; + } + if (variationSelector == 0) { + int gc = glyphs[i] = getCachedGlyphCode(code); + if (gc == UNINITIALIZED_GLYPH) { + glyphs[i] = convertToGlyph(code); + } + } + if (code >= 0x10000) { + i++; } } } @@ -263,9 +327,17 @@ for (int i=0; i>> 24; - while ((ch = nextCodePoint(lim)) != DONE && (mapper.charToGlyph(ch) & CompositeGlyphMapper.SLOTMASK) == sl); + while ((ch = nextCodePoint(lim)) != DONE ) { + if (CharToGlyphMapper.isVariationSelector(ch) + && CharToGlyphMapper.isBaseChar(preChar) + && consumed == false) { + consumed = true; + int[] chars = {preChar, ch}; + int[] glyphs = {0, 0}; + mapper.charsToGlyphs(2, chars, glyphs); + int vsSize = 1; + if (ch >= 0x10000) vsSize = 2; + if (secondPosition + vsSize == pos){ // Real slot + sl = glyphs[0] & CompositeGlyphMapper.SLOTMASK; + slot = sl >>> 24; + } + if ((glyphs[0] & CompositeGlyphMapper.SLOTMASK) != sl) { + pushback(ch); + pushback(preChar); + return true; + } + }else{ + consumed = false; + if ((mapper.charToGlyph(ch) & CompositeGlyphMapper.SLOTMASK) != sl) { + break; + } + } + preChar = ch; + } pushback(ch); return true; --- old/src/java.desktop/share/classes/sun/font/FontUtilities.java 2018-04-25 08:07:40.000000000 -0700 +++ new/src/java.desktop/share/classes/sun/font/FontUtilities.java 2018-04-25 08:07:39.000000000 -0700 @@ -236,7 +236,8 @@ return isComplexCharCode(ch) || (ch >= CharToGlyphMapper.HI_SURROGATE_START && - ch <= CharToGlyphMapper.LO_SURROGATE_END); + ch <= CharToGlyphMapper.LO_SURROGATE_END) || + CharToGlyphMapper.isVariationSelector(ch); } /* If the character code falls into any of a number of unicode ranges --- old/src/java.desktop/share/classes/sun/font/TrueTypeGlyphMapper.java 2018-04-25 08:07:42.000000000 -0700 +++ new/src/java.desktop/share/classes/sun/font/TrueTypeGlyphMapper.java 2018-04-25 08:07:42.000000000 -0700 @@ -93,6 +93,34 @@ } } + private char getGlyphFromCMAP(int charCode, int variationSelector) { + if (variationSelector == 0) { + return getGlyphFromCMAP(charCode); + } + try { + char glyphCode = cmap.getGlyph(charCode, variationSelector); + if (glyphCode == 0) { // retry without variation selector + return getGlyphFromCMAP(charCode); + } + if (glyphCode < numGlyphs || + glyphCode >= FileFontStrike.INVISIBLE_GLYPHS) { + return glyphCode; + } else { + if (FontUtilities.isLogging()) { + FontUtilities.getLogger().warning + (font + " out of range glyph id=" + + Integer.toHexString((int)glyphCode) + + " for char " + Integer.toHexString(charCode) + + " for vs " + Integer.toHexString(variationSelector)); + } + return (char)missingGlyph; + } + } catch(Exception e) { + handleBadCMAP(); + return (char) missingGlyph; + } + } + private void handleBadCMAP() { if (FontUtilities.isLogging()) { FontUtilities.getLogger().severe("Null Cmap for " + font + @@ -138,14 +166,27 @@ public void charsToGlyphs(int count, int[] unicodes, int[] glyphs) { for (int i=0;i= 0x10000) { + i++; } } @@ -194,6 +257,8 @@ for (int i=0; ienv; jobject font2D = jdkFontInfo->font2D; - hb_codepoint_t u = (variation_selector==0) ? unicode : variation_selector; + if (variation_selector==0){ + *glyph = (hb_codepoint_t) + env->CallIntMethod(font2D, sunFontIDs.f2dCharToGlyphMID, unicode); + }else{ + jintArray unicodes = NULL; + jintArray results = NULL; + jint* tmp = NULL; - *glyph = (hb_codepoint_t) - env->CallIntMethod(font2D, sunFontIDs.f2dCharToGlyphMID, u); + *glyph = 0; + unicodes = env->NewIntArray(2); + if (unicodes == NULL) goto cleanup; + results = env->NewIntArray(2); + if (results == NULL) goto cleanup; + + tmp = new jint[2]; + if (tmp == NULL) goto cleanup; + tmp[0] = unicode; + tmp[1] = variation_selector; + + env->SetIntArrayRegion(unicodes, 0, 2, tmp); + env->CallVoidMethod(font2D, sunFontIDs.f2dCharsToGlyphsMID, 2, unicodes, results); + env->GetIntArrayRegion(results, 0, 2, tmp); + *glyph = tmp[0]; +cleanup: + if (unicodes != NULL) env->DeleteLocalRef(unicodes); + if (results != NULL) env->DeleteLocalRef(results); + if (tmp != NULL) delete [] tmp; + } if ((int)*glyph < 0) { *glyph = 0; } --- old/src/java.desktop/share/native/libfontmanager/sunFont.c 2018-04-25 08:07:49.000000000 -0700 +++ new/src/java.desktop/share/native/libfontmanager/sunFont.c 2018-04-25 08:07:49.000000000 -0700 @@ -144,6 +144,8 @@ CHECK_NULL(tmpClass = (*env)->FindClass(env, "sun/font/Font2D")); CHECK_NULL(sunFontIDs.f2dCharToGlyphMID = (*env)->GetMethodID(env, tmpClass, "charToGlyph", "(I)I")); + CHECK_NULL(sunFontIDs.f2dCharsToGlyphsMID = + (*env)->GetMethodID(env, tmpClass, "charsToGlyphs", "(I[I[I)V")); CHECK_NULL(sunFontIDs.getMapperMID = (*env)->GetMethodID(env, tmpClass, "getMapper", "()Lsun/font/CharToGlyphMapper;")); @@ -155,6 +157,8 @@ CHECK_NULL(tmpClass = (*env)->FindClass(env, "sun/font/CharToGlyphMapper")); CHECK_NULL(sunFontIDs.charToGlyphMID = (*env)->GetMethodID(env, tmpClass, "charToGlyph", "(I)I")); + CHECK_NULL(sunFontIDs.charsToGlyphsMID = + (*env)->GetMethodID(env, tmpClass, "charsToGlyphs", "(I[I[I)V")); CHECK_NULL(tmpClass = (*env)->FindClass(env, "sun/font/PhysicalStrike")); CHECK_NULL(sunFontIDs.getGlyphMetricsMID = Binary files /dev/null and new/test/jdk/java/awt/font/TextLayout/TestVS-expect.png differ --- /dev/null 2018-04-25 08:07:54.000000000 -0700 +++ new/test/jdk/java/awt/font/TextLayout/TestVS.java 2018-04-25 08:07:53.000000000 -0700 @@ -0,0 +1,78 @@ +/* + * 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 + * questions. + * + */ + +/* @test @(#)TestVS.java + * @summary Verify Variation Selector matches an expected image + * @bug 8187100 + * @ignore Requires a special font installed. + */ + +import javax.swing.*; +import javax.swing.border.LineBorder; +import java.awt.*; +import java.awt.event.ActionEvent; + +public class TestVS { + public static void main(String[] args) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + new TestVS().run(); + } + }); + } + + private void run() { + Font ourFont = null; + final String fontName = "ipaexm.ttf"; // download from https://ipafont.ipa.go.jp/node26#en and place in {user.home}/fonts/ + try { + ourFont = Font.createFont(Font.TRUETYPE_FONT, new java.io.File(new java.io.File(System.getProperty("user.home"),"fonts"), fontName)); + ourFont = ourFont.deriveFont((float)48.0); + } catch(Throwable t) { + t.printStackTrace(); + System.err.println("Fail: " + t); + return; + } + JFrame frame = new JFrame(System.getProperty("java.version")); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + JPanel panel = new JPanel(); + final JTextArea label = new JTextArea("empty"); + label.setSize(400, 300); + label.setBorder(new LineBorder(Color.black)); + label.setFont(ourFont); + + final String str = "\u845b\udb40\udd00\u845b\udb40\udd01\n"; + + label.setText(str); + + panel.add(label); + panel.add(new JLabel(ourFont.getFamily())); + + // Show the expected result. + panel.add(new JLabel(new ImageIcon("TestVS-expect.png"))); + + frame.getContentPane().add(panel); + frame.pack(); + frame.setVisible(true); + } +} + --- /dev/null 2018-04-25 08:07:56.000000000 -0700 +++ new/test/jdk/java/awt/font/TextLayout/VariationSelectorTest.java 2018-04-25 08:07:56.000000000 -0700 @@ -0,0 +1,39 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.font.*; + +/* @test @(#)TestVS.java + * @summary Verify two identical 'a's are rendered + * @bug 8187100 + * @ignore Requires a special font installed. + */ +public class VariationSelectorTest { + // A font supporting Unicode variation selectors is required + private static final Font FONT = new Font("DejaVu Sans", Font.PLAIN, 12); + + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> { + JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + frame.add(new MyComponent()); + frame.setSize(200, 200); + frame.setVisible(true); + frame.setLocationRelativeTo(null); + }); + } + + private static class MyComponent extends JComponent { + @Override + protected void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + FontRenderContext frc = g2d.getFontRenderContext(); + String text = "a"; + GlyphVector gv = FONT.layoutGlyphVector(frc, text.toCharArray(), 0, text.length(), Font.LAYOUT_LEFT_TO_RIGHT); + g2d.drawGlyphVector(gv, 80, 50); + String text2 = "a\ufe00"; + GlyphVector gv2 = FONT.layoutGlyphVector(frc, text2.toCharArray(), 0, text2.length(), Font.LAYOUT_LEFT_TO_RIGHT); + g2d.drawGlyphVector(gv2, 80, 100); + } + } +} +