gpt4 book ai didi

ios - 检测何时无法正确显示 unicode 字符

转载 作者:搜寻专家 更新时间:2023-11-01 05:37:53 25 4
gpt4 key购买 nike

部分unicode字符在iOS上无法显示,但在macOS上可以正常显示。同样,iOS 可以显示的一些 unicode 字符在 watchOS 上无法显示。这是由于这些平台上安装了不同的内置字体。

当无法显示字符时,它显示为 ?在一个盒子里,像这样:
enter image description here

我还看到一些角色显示为外星人(不确定为什么不同):
enter image description here

有没有办法知道给定一个 unicode 字符字符串(例如 "ᄥ"),何时无法正确显示特定的 unicode 字符?

我需要一个适用于 iOS 和 watchOS 的解决方案。

最佳答案

您可以使用 CTFontGetGlyphsForCharacters() 来确定字体是否具有特定代码点的字形(请注意补充字符需要作为代理项对进行检查):

CTFontRef font = CTFontCreateWithName(CFSTR("Helvetica"), 12, NULL);
const UniChar code_point[] = { 0xD83C, 0xDCA1 }; // U+1F0A1
CGGlyph glyph[] = { 0, 0 };
bool has_glyph = CTFontGetGlyphsForCharacters(font, code_point, glyph, 2);

或者,在 Swift 中:

let font = CTFontCreateWithName("Helvetica", 12, nil)
var code_point: [UniChar] = [0xD83C, 0xDCA1]
var glyphs: [CGGlyph] = [0, 0]
let has_glyph = CTFontGetGlyphsForCharacters(font, &code_point, &glyph, 2)

如果您想检查系统将尝试从中加载字形的完整后备字体集,您将需要检查 CTFontCopyDefaultCascadeListForLanguages() 返回的所有字体。检查answer to this question有关如何创建后备字体列表的信息。

关于ios - 检测何时无法正确显示 unicode 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34731539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com