自定义UIFont基线已移位 [英] Custom UIFont baseline shifted

查看:369
本文介绍了自定义UIFont基线已移位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到自定义UIFonts的问题。我加载了其中的6个(常规/粗体/ regularItalic / boldItalic中的字体A,浓缩/浓缩变量中的字体B)。

I'm having a problem with custom UIFonts. I load 6 of them (font A in regular/bold/regularItalic/boldItalic, font B in condensed/condensedSlanted variants).

但是,这是渲染时的内容:

However, here is what it gives when rendered:

两个第一行都没问题,但最后一行表现出基线问题。

The two first rows are OK, but the last one exhibits a baseline problem.

我试过改变字体的UPM,ascender,descender,x-height FontLab使它匹配第一个字体的值(正确渲染),但无济于事。我试过将字体格式从OTF转换为TTF,没有运气。无论我尝试什么,它总是以这种方式呈现。

I've tried changing the UPM, ascender, descender, x-height of the font in FontLab so that it matches the first font's values (which render correctly), but to no avail. I've tried converting the font format from OTF to TTF, no luck. Whatever I try, it always renders this way.

有没有人有这方面的经验?

Does anyone have experience with this?

推荐答案

此处或甚至此处,您可以找到适合您的解决方案。
这完全与基线有关。

Here or even here you can find the solutions for you. It's all about baseline.

注意
在El Capitan上安装Apple Fonts Utility时出现问题。请参阅 https://apple.stackexchange.com / questions / 211138 / apple-font-tools-can-install-in-macbook-pro-el-capitan 获取解决方法。


要以字体编辑这些内容,您需要下载Apple Font
工具套件。安装完成后,需要打开终端,
导航到包含字体的目录。之后输入
以下命令:

To edit these in the font you will need to download the Apple Font Tool Suite. Once you’ve installed this you need to open Terminal and navigate to the directory that contains your font. After that enter the following command:


  1. ftxdumperfuser -t hhea -A d font.ttf这将创建一个文件
    名为font.hhea.xml,将此新文件打开到文本编辑器中,并调整
    ascender和descender的值。一般来说,如果你的字体太低了b $ b,你想减少上升并增加下降。
    编辑和保存后,在终端输入以下命令到
    重建你的字体文件:

  1. ftxdumperfuser -t hhea -A d font.ttf This will create a file called font.hhea.xml, open this new file into a text editor and adjust the values for ascender and descender. Generally if you font sits too low you want to decrease ascender and increase descender. After editing and saving enter the following command into terminal to reconstruct your Font file:

ftxdumperfuser -t hhea -A f font .ttf您现在可以在应用程序中使用font.ttf
文件。如果字体仍然不对,只需重复
上述程序,直到您满意为止。

ftxdumperfuser -t hhea -A f font.ttf You can now use the font.ttf file in your application. If the font still isn’t right just repeat the above procedure until you are happy.


或者您可以按如下方式轻松更改NSBaselineAttributeName:

OR you can easily change NSBaselineAttributeName as follows:

NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:@"a string"
                              attributes:@{ NSBaselineOffsetAttributeName : @-13 }];

这篇关于自定义UIFont基线已移位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆