--- old/src/java.desktop/share/classes/sun/font/CMap.java 2018-06-18 09:58:52.000000000 -0700 +++ new/src/java.desktop/share/classes/sun/font/CMap.java 2018-06-18 09:58:52.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,25 @@ } } + 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."); + } + } + try { + this.uvs = new UVS(buffer, offset); + } catch (Throwable t) { + t.printStackTrace(); + } + } + return; + } + /* final char charVal(byte[] cmap, int index) { return (char)(((0xff & cmap[index]) << 8)+(0xff & cmap[index+1])); @@ -1059,4 +1090,137 @@ } return -1; } + + static class UVS { + int numSelectors; + int[] selector; + + //for Default UVS Table + int[] numUnicodeValueRanges; + int[][] startUnicodeValue; + short[][] 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 short[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 if (tableOffset > 0) { + buffer.position(offset+tableOffset); + numUnicodeValueRanges[i] = buffer.getInt() & INTMASK; + + startUnicodeValue[i] = new int[numUnicodeValueRanges[i]]; + additionalCount[i] = new short[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] = (short)(buffer.get() & 0xff); + } + } + + //for Non-Default UVS Table + tableOffset = buffer.getInt(offset + 10 + i * 11 + 7); + if (tableOffset == 0) { + numUVSMapping[i] = 0; + } else if (tableOffset > 0) { + 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(); + } + } + } + } + + /* 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 + */ + static final int VS_NOGLYPH = 0; + static final int VS_DEFAULT_GLYPH = -1; + private int getGlyph(int charCode, int variationSelector) { + int targetSelector = -1; + for (int i = 0; i < numSelectors; i++) { + if (selector[i] == variationSelector) { + targetSelector = i; + break; + } + } + if (targetSelector == -1) { + return VS_NOGLYPH; + } + if (numUnicodeValueRanges[targetSelector] > 0) { + int index = java.util.Arrays.binarySearch( + startUnicodeValue[targetSelector], charCode); + if (index >= 0) { + return VS_DEFAULT_GLYPH; + } else { + index = -index - 2; + if (index >= 0 && + charCode >= startUnicodeValue[targetSelector][index] && + charCode <= startUnicodeValue[targetSelector][index] + +additionalCount[targetSelector][index]) { + return VS_DEFAULT_GLYPH; + } + } + } + if (numUVSMapping[targetSelector] > 0) { + int index = java.util.Arrays.binarySearch( + unicodeValue[targetSelector], charCode); + if (index >= 0) { + return glyphID[targetSelector][index]; + } + } + return VS_NOGLYPH; + } + } + + char getGlyph(int charCode, int variationSelector, boolean allowFallback) { + char glyph = 0; + if (uvs == null) { + if (allowFallback) { + glyph = getGlyph(charCode); + } + } else { + int result = uvs.getGlyph(charCode, variationSelector); + if (result > 0) { + glyph = (char)(result & 0xFFFF); + } else if (result == UVS.VS_DEFAULT_GLYPH || + allowFallback) { + glyph = getGlyph(charCode); + } + } + return glyph; + } } --- old/src/java.desktop/share/classes/sun/font/CharToGlyphMapper.java 2018-06-18 09:58:53.000000000 -0700 +++ new/src/java.desktop/share/classes/sun/font/CharToGlyphMapper.java 2018-06-18 09:58:53.000000000 -0700 @@ -36,6 +36,10 @@ public static final int HI_SURROGATE_END = 0xDBFF; public static final int LO_SURROGATE_START = 0xDC00; public static final int LO_SURROGATE_END = 0xDFFF; + public static final int VS_START = 0xFE00; + public static final int VS_END = 0xFE0F; + public static final int VSS_START = 0xE0100; + public static final int VSS_END = 0xE01FF; public static final int UNINITIALIZED_GLYPH = -1; public static final int INVISIBLE_GLYPH_ID = 0xffff; @@ -88,4 +92,34 @@ public abstract void charsToGlyphs(int count, int[] unicodes, int[] glyphs); + // Based on Unicode 10.0.0 chapter 23.4 + public static boolean isVSBaseChar(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 >= VSS_START && charCode <= VSS_END) || + (charCode >= VS_START && charCode <= VS_END)); + } + + public static boolean isVariationSelectorBMP(char charCode) { + return (charCode >= VS_START && charCode <= VS_END); + } + + public static boolean isVariationSelectorExt(char charCode1, + char charCode2) { + return (charCode1 == 0xDB40 && + (charCode2 >= 0xDD00 && charCode2 <= 0xDDEF)); + // VSS_START - VSS_END + } + } --- old/src/java.desktop/share/classes/sun/font/CompositeGlyphMapper.java 2018-06-18 09:58:54.000000000 -0700 +++ new/src/java.desktop/share/classes/sun/font/CompositeGlyphMapper.java 2018-06-18 09:58:54.000000000 -0700 @@ -133,6 +133,26 @@ 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); + if (mapper instanceof TrueTypeGlyphMapper) { + int glyphCode = ((TrueTypeGlyphMapper)mapper). + getGlyphOfVS(unicode, variationSelector); + 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 @@ -205,6 +225,9 @@ glyphs[i + 1] = INVISIBLE_GLYPH_ID; } } + if (isVariationSelector(code)) { + return charsToGlyphsNSVS(count, unicodes, glyphs); + } int gc = glyphs[i] = getCachedGlyphCode(code); if (gc == UNINITIALIZED_GLYPH) { @@ -226,6 +249,69 @@ return false; } + private boolean charsToGlyphsNSVS(int count, char[] unicodes, + int[] glyphs) { + + for (int i = 0; i < count; i++) { + int code = unicodes[i]; // char is unsigned. + int step = 1; + int variationSelector = 0; + + if (code >= HI_SURROGATE_START && + code <= HI_SURROGATE_END && i < count - 1) { + char low = unicodes[i + 1]; + + if (low >= LO_SURROGATE_START && + low <= LO_SURROGATE_END) { + code = (code - HI_SURROGATE_START) * + 0x400 + low - LO_SURROGATE_START + 0x10000; + glyphs[i + 1] = INVISIBLE_GLYPH_ID; + step = 2; + } + } + + if (i < count - step && + isVariationSelectorBMP(unicodes[i+step]) && + isVSBaseChar(code)) { + variationSelector = unicodes[i+step]; + glyphs[i] = convertToGlyph(code, variationSelector); + glyphs[i+step] = INVISIBLE_GLYPH_ID; + i += 1; + } else if (i < count - step -1 && + isVariationSelectorExt(unicodes[i+step], + unicodes[i+step+1]) && + isVSBaseChar(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) { + continue; + } + else if (FontUtilities.isComplexCharCode(code)) { + return true; + } + else if (code >= 0x10000) { + i += 1; // Empty glyph slot after surrogate + continue; + } + } + + return false; + } + /* The conversion is not very efficient - looping as it does, converting * one char at a time. However the cache should fill very rapidly. */ @@ -241,6 +327,10 @@ low <= LO_SURROGATE_END) { code = (code - HI_SURROGATE_START) * 0x400 + low - LO_SURROGATE_START + 0x10000; + if (isVariationSelector(code)) { + charsToGlyphsVS(count, unicodes, glyphs); + return; + } int gc = glyphs[i] = getCachedGlyphCode(code); if (gc == UNINITIALIZED_GLYPH) { @@ -250,6 +340,9 @@ glyphs[i] = INVISIBLE_GLYPH_ID; continue; } + } else if (isVariationSelectorBMP(unicodes[i])) { + charsToGlyphsVS(count, unicodes, glyphs); + return; } int gc = glyphs[i] = getCachedGlyphCode(code); @@ -259,9 +352,65 @@ } } + private void charsToGlyphsVS(int count, char[] unicodes, int[] glyphs) { + for (int i = 0; i < count; i++) { + int code = unicodes[i]; // char is unsigned. + int variationSelector = 0; + int step = 1; + + if (code >= HI_SURROGATE_START && + code <= HI_SURROGATE_END && i < count - 1) { + char low = unicodes[i + 1]; + + if (low >= LO_SURROGATE_START && + low <= LO_SURROGATE_END) { + code = (code - HI_SURROGATE_START) * + 0x400 + low - LO_SURROGATE_START + 0x10000; + + glyphs[i+1] = INVISIBLE_GLYPH_ID; + step = 2; + } + } + + if (i < count - step && + isVariationSelectorBMP(unicodes[i+step]) && + isVSBaseChar(code)) { + variationSelector = unicodes[i+step]; + glyphs[i] = convertToGlyph(code, variationSelector); + glyphs[i+step] = INVISIBLE_GLYPH_ID; + i += 1; + } else if (i < count - step -1 && + isVariationSelectorExt(unicodes[i+step], + unicodes[i+step+1]) && + isVSBaseChar(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++; + } + } + } + public void charsToGlyphs(int count, int[] unicodes, int[] glyphs) { 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.isVSBaseChar(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-06-18 09:58:57.000000000 -0700 +++ new/src/java.desktop/share/classes/sun/font/FontUtilities.java 2018-06-18 09:58:57.000000000 -0700 @@ -236,7 +236,9 @@ return isComplexCharCode(ch) || (ch >= CharToGlyphMapper.HI_SURROGATE_START && - ch <= CharToGlyphMapper.LO_SURROGATE_END); + ch <= CharToGlyphMapper.LO_SURROGATE_END) || + (ch >= CharToGlyphMapper.VS_START && + ch <= CharToGlyphMapper.VS_END); } /* If the character code falls into any of a number of unicode ranges --- old/src/java.desktop/share/classes/sun/font/TrueTypeGlyphMapper.java 2018-06-18 09:58:58.000000000 -0700 +++ new/src/java.desktop/share/classes/sun/font/TrueTypeGlyphMapper.java 2018-06-18 09:58:58.000000000 -0700 @@ -87,7 +87,32 @@ } return (char)missingGlyph; } - } catch(Exception e) { + } catch (Exception e) { + handleBadCMAP(); + return (char) missingGlyph; + } + } + + private char getGlyphFromCMAPVS(int charCode, int variationSelector) { + if (variationSelector == 0) { + return getGlyphFromCMAP(charCode); + } + try { + char glyphCode = cmap.getGlyph(charCode, variationSelector, true); + 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; } @@ -137,7 +162,11 @@ } public void charsToGlyphs(int count, int[] unicodes, int[] glyphs) { - for (int i=0;i= HI_SURROGATE_START && + code <= HI_SURROGATE_END && i < count - 1) { + char low = unicodes[i + 1]; + + if (low >= LO_SURROGATE_START && + low <= LO_SURROGATE_END) { + code = (code - HI_SURROGATE_START) * + 0x400 + low - LO_SURROGATE_START + 0x10000; + + glyphs[i + 1] = INVISIBLE_GLYPH_ID; + step = 2; + } + } + if (i < count - step && + isVariationSelectorBMP(unicodes[i + step]) && + isVSBaseChar(code)) { + variationSelector = unicodes[i + step]; + glyphs[i] = getGlyphFromCMAPVS(code, variationSelector); + glyphs[i+step] = INVISIBLE_GLYPH_ID; + i += 1; + } else if (i < count - step -1 && + isVariationSelectorExt(unicodes[i + step], + unicodes[i + step + 1]) && + isVSBaseChar(code)) { + variationSelector = (unicodes[i + step] - HI_SURROGATE_START) + * 0x400 + unicodes[i + step + 1] + - LO_SURROGATE_START + 0x10000; + glyphs[i] = getGlyphFromCMAPVS(code, variationSelector); + glyphs[i + step] = INVISIBLE_GLYPH_ID; + glyphs[i + step + 1] = INVISIBLE_GLYPH_ID; + i += 2; + } + if (variationSelector == 0) { + glyphs[i] = getGlyphFromCMAP(code); + + if (font.checkUseNatives() && + glyphs[i] < font.glyphToCharMap.length) { + font.glyphToCharMap[glyphs[i]] = (char)code; + } + } + if (code >= 0x10000) { + i++; + } + + } + } + /* This variant checks if shaping is needed and immediately * returns true if it does. A caller of this method should be expecting * to check the return type because it needs to know how to handle @@ -192,7 +314,7 @@ */ public boolean charsToGlyphsNS(int count, char[] unicodes, int[] glyphs) { - for (int i=0; i= HI_SURROGATE_START && + code <= HI_SURROGATE_END && i < count - 1) { + char low = unicodes[i + 1]; + + if (low >= LO_SURROGATE_START && + low <= LO_SURROGATE_END) { + code = (code - HI_SURROGATE_START) * + 0x400 + low - LO_SURROGATE_START + 0x10000; + glyphs[i + 1] = INVISIBLE_GLYPH_ID; + step = 2; + } + } + + if (i < count - step && + isVariationSelectorBMP(unicodes[i + step]) && + isVSBaseChar(code)) { + variationSelector = unicodes[i + step]; + glyphs[i] = getGlyphFromCMAPVS(code, variationSelector); + glyphs[i+step] = INVISIBLE_GLYPH_ID; + i += 1; + } else if (i < count - step - 1 && + isVariationSelectorExt(unicodes[i + step], + unicodes[i + step + 1]) && + isVSBaseChar(code)) { + variationSelector = (unicodes[i + step] - HI_SURROGATE_START) + * 0x400 + unicodes[i + step + 1] + - LO_SURROGATE_START + 0x10000; + glyphs[i] = getGlyphFromCMAPVS(code, variationSelector); + glyphs[i + step] = INVISIBLE_GLYPH_ID; + glyphs[i + step + 1] = INVISIBLE_GLYPH_ID; + i += 2; + } + if (variationSelector == 0) { + glyphs[i] = getGlyphFromCMAP(code); + if (font.checkUseNatives() && + glyphs[i] < font.glyphToCharMap.length) { + font.glyphToCharMap[glyphs[i]] = (char)code; + } + } + + if (code < FontUtilities.MIN_LAYOUT_CHARCODE) { + continue; + } + else if (FontUtilities.isComplexCharCode(code)) { + return true; + } + else if (code >= 0x10000) { + i += 1; // Empty glyph slot after surrogate + continue; + } + } + + return false; + } + /* A pretty good heuristic is that the cmap we are using * supports 32 bit character codes. */ @@ -242,4 +434,8 @@ cmap instanceof CMap.CMapFormat10 || cmap instanceof CMap.CMapFormat12; } + + int getGlyphOfVS(int charCode, int variationSelector) { + return cmap.getGlyph(charCode, variationSelector, false); + } } --- old/src/java.desktop/share/native/common/font/sunfontids.h 2018-06-18 09:58:59.000000000 -0700 +++ new/src/java.desktop/share/native/common/font/sunfontids.h 2018-06-18 09:58:58.000000000 -0700 @@ -39,6 +39,7 @@ jmethodID getTableBytesMID; jmethodID canDisplayMID; jmethodID f2dCharToGlyphMID; + jmethodID f2dCharsToGlyphsMID; /* sun/font/CharToGlyphMapper methods */ jmethodID charToGlyphMID; --- old/src/java.desktop/share/native/libfontmanager/hb-jdk-font.cc 2018-06-18 09:59:00.000000000 -0700 +++ new/src/java.desktop/share/native/libfontmanager/hb-jdk-font.cc 2018-06-18 09:58:59.000000000 -0700 @@ -48,10 +48,50 @@ JDKFontInfo *jdkFontInfo = (JDKFontInfo*)font_data; JNIEnv* env = jdkFontInfo->env; 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); + if (env->ExceptionOccurred()) + { + env->ExceptionClear(); + } + } else { + jintArray unicodes = NULL; + jintArray results = NULL; + jint vsPair[] = {(jint)unicode, + (jint)variation_selector}; - *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; + } + + env->SetIntArrayRegion(unicodes, 0, 2, vsPair); + env->CallVoidMethod(font2D, sunFontIDs.f2dCharsToGlyphsMID, 2, + unicodes, results); + if (env->ExceptionOccurred()) + { + goto cleanup; + } + env->GetIntArrayRegion(results, 0, 2, vsPair); + *glyph = vsPair[0]; +cleanup: + if (env->ExceptionOccurred()) + { + env->ExceptionClear(); + } + if (unicodes != NULL) { + env->DeleteLocalRef(unicodes); + } + if (results != NULL) { + env->DeleteLocalRef(results); + } + } if ((int)*glyph < 0) { *glyph = 0; } --- old/src/java.desktop/share/native/libfontmanager/sunFont.c 2018-06-18 09:59:01.000000000 -0700 +++ new/src/java.desktop/share/native/libfontmanager/sunFont.c 2018-06-18 09:59:00.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;")); Binary files /dev/null and new/test/jdk/java/awt/font/TextLayout/TestVS-expect.png differ --- /dev/null 2018-06-18 09:59:02.000000000 -0700 +++ new/test/jdk/java/awt/font/TextLayout/TestVS.java 2018-06-18 09:59:02.000000000 -0700 @@ -0,0 +1,92 @@ +/* + * 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 + * @summary Verify Variation Selector matches an expected image + * @bug 8187100 + * @ignore Requires a special font installed. + */ + +import javax.swing.SwingUtilities; +import javax.swing.border.LineBorder; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JFrame; +import javax.swing.JTextArea; +import javax.swing.ImageIcon; +import java.awt.Font; +import java.awt.Color; + +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); + final String actualFontName = ourFont.getFontName(); + if (!actualFontName.equals("IPAexMincho")) { + System.err.println("*** Warning: missing font IPAexMincho."); + System.err.println("*** Using font: " + actualFontName); + } + } 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-06-18 09:59:03.000000000 -0700 +++ new/test/jdk/java/awt/font/TextLayout/VariationSelectorTest.java 2018-06-18 09:59:03.000000000 -0700 @@ -0,0 +1,64 @@ +/* @test + * @summary Verify two identical 'a's are rendered + * @bug 8187100 + * @ignore Requires a special font installed. + */ +import javax.swing.JFrame; +import javax.swing.JComponent; +import javax.swing.SwingUtilities; +import javax.swing.WindowConstants; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.font.FontRenderContext; +import java.awt.font.GlyphVector; + +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) { + final String fontName = FONT.getFontName(); + if (!fontName.equals("DejaVuSans")) { + System.err.println("*** Warning: Font DejaVuSans not installed."); + System.err.println("*** Using font: " + fontName); + } + 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); + System.out.println("'a'=" + gv.getNumGlyphs()); + g2d.drawString("=" + gv.getNumGlyphs() + " ('a')", 100, 50); + 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); + System.out.println("'a'+VS=" + gv2.getNumGlyphs()); + g2d.drawString("=" + gv2.getNumGlyphs() + " ('a'+VS)", 100, 100); + if ((gv.getNumGlyphs() == 1) && (gv2.getNumGlyphs() == 1)) { + System.out.println("PASS"); + g2d.drawString("PASS", 10, 15); + } else { + System.err.println("FAIL"); + g2d.drawString("FAIL", 10, 15); + } + } + } +}