True Type 字体缩放

True Type Font Scaling

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

Values in the em square are converted to values in the pixel coordinate system by multiplying them by a scale. This scale is:

pointSize * resolution / ( 72 points per inch * units_per_em )

where pointSize is the size at which the glyph is to be displayed, and resolution is the resolution of the output device. The 72 in the denominator reflects the number of points per inch.

For example, assume that a glyph feature is 550 FUnits in length on a 72 dpi screen at 18 point. There are 2048 units per em. The following calculation reveals that the feature is 4.83 pixels long.

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

问题:

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

不幸的是,Apple 的文档或多或少是相同的,除此之外,除了阅读 stb_truetype.

的源代码外几乎没有任何资源。

It says "pointSize is the size at which the glyph is to be displayed." How does one compute this, and what units is it in?

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

It says "72 in the denominator reflects the number of points per inch." Is this related to DPI or no?

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

现在,印刷点与输出设备的点或像素不同。虽然在桌面出版的早期,屏幕分辨率通常为每英寸 72 像素,这确实对应于每英寸 72 点的排版系统(这并非巧合),但如今输出分辨率当然会有所不同非常引人注目,所以记住 pointpixel 的区别很重要。

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

都没有。 点的大小;看上面。整个示例可以翻译如下。对于基于每 em 2048 个单位的字体,如果特定字形特征的长度为 550 em 单位,并且该字形在屏幕分辨率为 72 的设备上以 18 点(即 18/72 英寸)的大小显示每英寸像素,则该特征的像素大小将为 4.84。

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

是DPI/PPI,是的。您必须查询某些系统 API 以获取该信息,或者如果您针对特定设备,则只需对值进行硬编码。