Skip to content

Commit e89069b

Browse files
authored
Add variation selectors to emoji alt attributes (#700) (#920)
1 parent ce2ff44 commit e89069b

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

unicodetools/src/main/java/org/unicode/tools/emoji/GenerateEmoji.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.ibm.icu.lang.UCharacter;
1919
import com.ibm.icu.text.Collator;
2020
import com.ibm.icu.text.Transform;
21+
import com.ibm.icu.text.Transliterator;
2122
import com.ibm.icu.text.UTF16;
2223
import com.ibm.icu.text.UnicodeSet;
2324
import com.ibm.icu.text.UnicodeSet.EntryRange;
@@ -544,6 +545,8 @@ private static String getSvgImage(
544545
return null;
545546
}
546547

548+
static final Transliterator TO_HEX = Transliterator.getInstance("Any-Hex/XML");
549+
547550
/*
548551
* Note that Emoji.BESTOVERRIDE can override the source type for specific
549552
* characters.
@@ -597,8 +600,9 @@ public static String getImage(
597600
type, filename, doFlip)
598601
: "../images/" + filename;
599602
}
603+
String escaped = TO_HEX.transliterate(chars);
600604
return "<img alt='"
601-
+ chars
605+
+ escaped
602606
+ "'"
603607
+ " title='"
604608
+ getCodeCharsAndName(chars, " ")
@@ -1970,15 +1974,18 @@ private static void showVariationSequences() throws IOException {
19701974
+ "</td>");
19711975
if (EmojiData.EMOJI_DATA.getKeycapBases().contains(cp)) {
19721976
// keycaps, treat specially
1973-
String cp2 = cp + Emoji.KEYCAP_MARK;
1974-
out.println(GenerateEmoji.getCell(Emoji.Source.ref, cp2, "andr", false, null));
1975-
out.println(GenerateEmoji.getCell(null, cp2, "andr", false, null));
1977+
String cp1 = cp + Emoji.TEXT_VARIANT + Emoji.KEYCAP_MARK;
1978+
String cp2 = cp + Emoji.EMOJI_VARIANT + Emoji.KEYCAP_MARK;
1979+
out.println(getCell(Emoji.Source.ref, cp1, "andr", false, null));
1980+
out.println(getCell(null, cp2, "andr", false, null));
19761981
out.println("<td>" + version + "</td>");
19771982
out.println(
19781983
"<td>" + UCharacter.getName(cp.codePointAt(0)) + keycapIndicator + "</td>");
19791984
} else {
1980-
out.println(GenerateEmoji.getCell(Emoji.Source.ref, cp, "andr", false, null));
1981-
out.println(GenerateEmoji.getCell(null, cp, "andr", false, null));
1985+
String cp1 = cp + Emoji.TEXT_VARIANT;
1986+
String cp2 = cp + Emoji.EMOJI_VARIANT;
1987+
out.println(getCell(Emoji.Source.ref, cp1, "andr", false, null));
1988+
out.println(getCell(null, cp2, "andr", false, null));
19821989
out.println("<td>" + version + "</td>");
19831990
out.println("<td>" + UCharacter.getName(cp.codePointAt(0)) + "</td>");
19841991
}
@@ -3723,17 +3730,17 @@ public static String toSemiString(String chars2, int order, UnicodeSet level1) {
37233730
}
37243731

37253732
public static String getCell(
3726-
Emoji.Source type,
3727-
String core,
3728-
String cellClass,
3729-
boolean addLink,
3730-
Output<Boolean> found) {
3733+
Emoji.Source type, String s, String cellClass, boolean addLink, Output<Boolean> found) {
3734+
String core = s;
3735+
if (core.contains(Emoji.TEXT_VARIANT_STRING)) {
3736+
core = core.replace(Emoji.TEXT_VARIANT_STRING, "");
3737+
}
37313738
String linkPre = addLink ? getMoreInfoLink("full-emoji-list.html", core) : "";
37323739
String linkPost = addLink ? "</a>" : "";
37333740
if (type == null) {
37343741
return "<td class='andr'>"
37353742
+ linkPre
3736-
+ getBestImage(core, true, "", Emoji.Source.SAMPLE_SOURCE)
3743+
+ getBestImage(s, true, "", Emoji.Source.SAMPLE_SOURCE)
37373744
+ linkPost
37383745
+ "</td>\n";
37393746
}
@@ -3748,14 +3755,15 @@ public static String getCell(
37483755
fullName = EmojiImageData.getDataUrlFromFilename(type, filename);
37493756
}
37503757
if (fullName != null) {
3758+
String escaped = TO_HEX.transliterate(s);
37513759
String className = type.getClassAttribute(core);
37523760
androidCell =
37533761
"<td class='"
37543762
+ cellClass
37553763
+ "'>"
37563764
+ linkPre
37573765
+ "<img alt='"
3758-
+ core
3766+
+ escaped
37593767
+ "' class='"
37603768
+ className
37613769
+ "' src='"

0 commit comments

Comments
 (0)