简体   繁体   English

如何正确缩放字体字形轮廓?

[英]How to properly scale a font glyph outline?

How do I scale a font-glyph outline to match a certain point size? 如何缩放字体字形轮廓以匹配特定的点大小?

For example, I have the outline of the T-glyph (Arial) which looks like this: 例如,我具有T字形(Arial)的轮廓,如下所示:

在此处输入图片说明

The top two points of that glyph are at the Y-Coordinate 1466. According to this TrueType document from Microsoft: https://docs.microsoft.com/en-us/typography/opentype/spec/ttch01#scaling-a-glyph 该字形的最上面两点位于Y坐标1466。根据Microsoft的TrueType文档: https : //docs.microsoft.com/zh-cn/typography/opentype/spec/ttch01#scaling-a-glyph

I have to calculate it like this: 我必须这样计算:

pointSize * resolution / ( 72 points per inch * units_per_em ) pointSize *分辨率/(每英寸72点* units_per_em)

units_per_em for Arial is 2048, my target DPI is 72 and the font size I want is 12, so if I do this I get: Arial的units_per_em是2048,我的目标DPI是72,我想要的字体大小是12,所以如果这样做,我得到:

1466 * 12 * 72 / (72 * 2048) = 8.589 1466 * 12 * 72 /(72 * 2048)= 8.589

This results in the rasterized image to look like the one on the right in this picture: 这导致栅格化的图像看起来像这张图片中的右侧:

在此处输入图片说明

The left glyph here is a screenshot of the 12pt T in WordPad, the right one is my rasterized one. 左边的标志符号是写字板中12pt T的屏幕截图,右边的是我的栅格化图片。

As you can see mine is not only way smaller, but also blurry. 如您所见,我的不仅缩小了,而且模糊了。 This is due to it only being 8.589px tall and the top pixel being between two pixels. 这是因为它只有8.589像素高,顶部像素在两个像素之间。 And when I use 96 DPI as a target device DPI the result is 11.4531, which I guess is what WordPad does (pt vs px) but it's still blurry since 11.45 is still between two pixels. 当我将96 DPI用作目标设备DPI时,结果为11.4531,我猜这就是写字板的功能(pt与px),但由于11.45仍在两个像素之间,因此它仍然很模糊。

I am wondering, how do I scale the glyph outline to get an as crisp result as WordPad does? 我想知道,如何缩放字形轮廓以获得与写字板一样清晰的结果? Any ideas? 有任何想法吗?

Simply rounding the values to full pixels can't be the solution since that would not work for any glyph with diagonal lines (eg A). 简单地将值四舍五入为完整像素将不是解决方案,因为这不适用于带有对角线的任何字形(例如A)。 The colors that look like chromatic-abberations on the WordPad one are from Windows' ClearType feature which uses "subpixels" of the LCD for an even sharper result on diagonal glyph outlines. 看起来像写字板上的色差的颜色来自Windows的ClearType功能,该功能使用LCD的“子像素”在对角字形轮廓上获得更清晰的结果。 I don't worry about these for now. 我暂时不担心这些。

After reading more about it, I realized that TrueType has an interpreter language to grid fit the glyphs. 在阅读了更多有关它的内容之后,我意识到TrueType具有一种解释器语言,可以使字形适合网格。 So I'll have to implement that :) 所以我必须实现它:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM