gpt4 book ai didi

iphone - 断字库不适用于 iOS 5

转载 作者:行者123 更新时间:2023-11-29 13:43:59 24 4
gpt4 key购买 nike

我刚刚尝试了 Tupil 的连字符库。

这里提到了http://blog.tupil.com/adding-hyphenation-to-nsstring/ .

但是虽然它在 iOS 4.3 下工作得很好,但我没有让它在 iOS 5 上工作。

还有其他我可以使用的框架吗?我听说过 CoreText,但我不知道从哪里开始。

提前致谢马丁

最佳答案

我意识到已经有几年了,但我刚刚发现有一个 Core Foundation 函数建议连字点:CFStringGetHyphenationLocationBeforeIndex .它只适用于少数几种语言,但看起来它可能对窄标签问题很有帮助。

更新:

这是一些示例代码。这是一个 CLI 程序,显示在何处连接单词:

#include <Cocoa/Cocoa.h>


int main(int ac, char *av[])
{
@autoreleasepool {

if(ac < 2) {
fprintf(stderr, "usage: hyph word\n");
exit(1);
}
NSString *word = [NSString stringWithUTF8String: av[1]];
unsigned char hyspots[word.length];
memset(hyspots, 0, word.length);
CFRange range = CFRangeMake(0, word.length);
CFLocaleRef locale = CFLocaleCreate(NULL, CFSTR("en_US"));
for(int i = 0; i < word.length; i++) {
int x = CFStringGetHyphenationLocationBeforeIndex(
(CFStringRef) word, i, range,
0, locale, NULL);
if(x >= 0 && x < word.length)
hyspots[x] = 1;
}
for(int i = 0; i < word.length; i++) {
if(hyspots[i]) putchar('-');
printf("%s", [[word substringWithRange: NSMakeRange(i, 1)] UTF8String]);
}
putchar('\n');

}

exit(0);
}

这是构建和运行它时的样子:

$ cc -o hyph hyph.m -framework Cocoa
$ hyph accessibility
ac-ces-si-bil-i-ty
$ hyph hypothesis
hy-poth-e-sis

这些连字符与 OS X 词典完全一致。我将它用于 iOS 中的窄标签问题,它对我来说效果很好。

关于iphone - 断字库不适用于 iOS 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8203767/

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