首页 > 解决方案 > True Type 字体缩放

问题描述

MSDN 的 truetype 字体文章 ( https://docs.microsoft.com/en-us/typography/opentype/otspec160/ttch01 ) 给出了将 FUnits 转换为像素的以下内容:

em 正方形中的值通过将它们乘以比例转换为像素坐标系中的值。这个比例是:

pointSize * 分辨率 / (每英寸 72 点 * units_per_em )

其中 pointSize 是要显示字形的大小,而分辨率是输出设备的分辨率。分母中的 72 反映了每英寸的点数。

例如,假设字形特征在 18 点的 72 dpi 屏幕上的长度为 550 FUnits。每个 em 有 2048 个单位。以下计算表明该特征的长度为 4.83 像素。

550 * 18 * 72 / ( 72 * 2048 ) = 4.83

问题:

  1. 它说“pointSize 是要显示字形的大小。” 如何计算这个,它是什么单位?
  2. 它说“分辨率是输出设备的分辨率”。这是在 DPI 中吗?我从哪里得到这些信息?
  3. 它说“分母中的 72 反映了每英寸的点数。” 这与DPI有关吗?
  4. 在示例中,它显示“18 点”。这 18 是用于计算分辨率还是 pointSize?

不幸的是,Apple 的文档或多或少是相同的,除了阅读 stb_truetype 的源代码之外几乎没有任何资源。

标签: truetype

解决方案


它说“pointSize 是要显示字形的大小。” 如何计算这个,它是什么单位?

你不计算点大小,你设置它。这是您希望字体显示的标称大小(想想文本编辑器中的字体菜单)。“点大小”是一种传统的印刷测量系统,“点”大约是 1/72 英寸。这带来了另一个问题:

它说“分母中的 72 反映了每英寸的点数。” 这与DPI有关吗?

不。同样,这些是印刷点 - 与您设置点大小的单位相同。这就是为什么它首先是分母的一部分:点的大小以 72 点到一英寸的测量系统表示,并且必须以某种方式在等式中考虑到这一点。

Now, the typographical points are different from the output device’s dots or pixels. While in the early days of desktop publishing it was common to have a screen resolution of 72 pixels per inch that indeed corresponded to typographical system of 72 points per inch (no coincidence in that), these days the output resolution can, of course, vary quite dramatically, so it’s important to keep the point vs pixel distinction in mind.

In the example, it says '18 point'. Is this 18 used in computing the resolution or the pointSize?

Neither. It is the point size; see above. The entire example could be translated as follows. With a font based on 2048 units per em, if a particular glyph feature is 550 em units long and the glyph gets displayed at the size of 18 points (that is, 18/72 of an inch) on a device with screen resolution of 72 pixels per inch, the pixel size of that feature will be 4.84.

It says "resolution is the resolution of the output device". Is this in DPI? Where would I get this information?

It’s DPI/PPI, yes. You have to query some system API for that information or just hardcode the value if you’re targeting a specific device.


推荐阅读