下面列出了android.graphics.Paint#hasGlyph ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static boolean canShowFlagEmoji() {
Paint paint = new Paint();
String switzerland = "\uD83C\uDDE8\uD83C\uDDED"; // U+1F1E8 U+1F1ED Flag for Switzerland
try {
return paint.hasGlyph(switzerland);
} catch (NoSuchMethodError e) {
// Compare display width of single-codepoint emoji to width of flag emoji to determine
// whether flag is rendered as single glyph or two adjacent regional indicator symbols.
float flagWidth = paint.measureText(switzerland);
float standardWidth = paint.measureText("\uD83D\uDC27"); // U+1F427 Penguin
return flagWidth < standardWidth * 1.25;
// This assumes that a valid glyph for the flag emoji must be less than 1.25 times
// the width of the penguin.
}
}
private static boolean canShowUnicodeEightEmoji() {
Paint paint = new Paint();
String cheese = "\uD83E\uDDC0"; // U+1F9C0 Cheese wedge
try {
return paint.hasGlyph(cheese);
} catch (NoSuchMethodError e) {
float cheeseWidth = paint.measureText(cheese);
float tofuWidth = paint.measureText("\uFFFE");
return cheeseWidth > tofuWidth;
// This assumes that a valid glyph for the cheese wedge must be greater than the width
// of the noncharacter.
}
}
private static boolean canShowFlagEmoji() {
Paint paint = new Paint();
String switzerland = "\uD83C\uDDE8\uD83C\uDDED"; // U+1F1E8 U+1F1ED Flag for Switzerland
try {
return paint.hasGlyph(switzerland);
} catch (NoSuchMethodError e) {
// Compare display width of single-codepoint emoji to width of flag emoji to determine
// whether flag is rendered as single glyph or two adjacent regional indicator symbols.
float flagWidth = paint.measureText(switzerland);
float standardWidth = paint.measureText("\uD83D\uDC27"); // U+1F427 Penguin
return flagWidth < standardWidth * 1.25;
// This assumes that a valid glyph for the flag emoji must be less than 1.25 times
// the width of the penguin.
}
}
private static boolean canShowUnicodeEightEmoji() {
Paint paint = new Paint();
String cheese = "\uD83E\uDDC0"; // U+1F9C0 Cheese wedge
try {
return paint.hasGlyph(cheese);
} catch (NoSuchMethodError e) {
float cheeseWidth = paint.measureText(cheese);
float tofuWidth = paint.measureText("\uFFFE");
return cheeseWidth > tofuWidth;
// This assumes that a valid glyph for the cheese wedge must be greater than the width
// of the noncharacter.
}
}
private static boolean canShowFlagEmoji() {
Paint paint = new Paint();
String switzerland = "\uD83C\uDDE8\uD83C\uDDED"; // U+1F1E8 U+1F1ED Flag for Switzerland
try {
return paint.hasGlyph(switzerland);
} catch (NoSuchMethodError e) {
// Compare display width of single-codepoint emoji to width of flag emoji to determine
// whether flag is rendered as single glyph or two adjacent regional indicator symbols.
float flagWidth = paint.measureText(switzerland);
float standardWidth = paint.measureText("\uD83D\uDC27"); // U+1F427 Penguin
return flagWidth < standardWidth * 1.25;
// This assumes that a valid glyph for the flag emoji must be less than 1.25 times
// the width of the penguin.
}
}
private static boolean canShowUnicodeEightEmoji() {
Paint paint = new Paint();
String cheese = "\uD83E\uDDC0"; // U+1F9C0 Cheese wedge
try {
return paint.hasGlyph(cheese);
} catch (NoSuchMethodError e) {
float cheeseWidth = paint.measureText(cheese);
float tofuWidth = paint.measureText("\uFFFE");
return cheeseWidth > tofuWidth;
// This assumes that a valid glyph for the cheese wedge must be greater than the width
// of the noncharacter.
}
}