0

我对skia和harfbuzz都是新手,我的项目依靠skia来呈现文本(Skia依靠harfbuzz来塑造文本。)。

因此,如果我尝试渲染文本“ff”或“fl”或“fi”(或者可能是其他一些组合 idk。),而不是渲染 2“f”,skia 将渲染一个由 2 个字符组成的字形(“ff " 或 "fl" 或 "fi"),如果我设置文本字母空间属性,它会变得更加明显。

通过跟踪断点,我跟踪并发现这都是 harfbuzz 整形结果的结果。如果文本是“ff”或“fl”或“fi”,Harfbuzz 将给出 1 个字形。

似乎通过对 harfbuzz 进行一些配置,我可以避免这种情况,但不知道如何,请给我一些提示。

PS:如果我使用不同的字体文件,形状结果会有所不同,所以这也与我使用的字体文件有关。

4

1 回答 1

1

What you are observing is the result of ligature glyph substitutions that occur during text layout.

Harfbuzz is performing advanced text layout using OpenType Layout features in a font. OpenType features are a mechanism for enabling different typographic capabilities that are supported in the font.

Some features are required for correct display of a script. For example, certain features are used to trigger word-contextual forms in Arabic script, or to trigger positioning of vowel marks in Bangla script or diacritic marks in Latin script. These are mandatory for correct display of these scripts.

Other features trigger optional typographic capabilities of a font—they're not essential for correct display of the script, but may be desired for high quality typography. Small caps or superscript forms are two examples of optional features. Many optional features are should not be used in applications by default. For instance, small caps should only be used when the content author explicitly wants them.

But in OpenType some optional features are recommended for use by default since they are intended to provide good quality typography for any body text. One such feature is "Standard Ligatures".

Your specific cases, "ff", "fi", etc., are considered standard ligatures. In any publication that has high quality typography, these will always be used in body text. Because the OpenType spec recommends that Standard Ligatures be applied by default, that's exactly what Harfbuzz is doing.

You can read the Harfbuzz documentation to find out more able how to enable or disable OpenType features. And you can find descriptions of all OpenType features in the OpenType Layout Tag Registry (part of the OpenType spec).

OpenType features use data contained directly in the fonts. Harfbuzz will enable the Standard Ligatures feature by default, but not all fonts necessarily have data that pertains to that feature. That's why you see the behaviour with some fonts but not others.

When a font does support features, the font data describe glyph-level actions to be performed. Harfbuzz (or any OpenType layout engine) will read the data and they perform the described actions. There are several types of actions that can be performed. One is a ligature substution—that is, substitute a sequence of glyphs with a single glyph, the ligature glyph. Ligature substitution actions could be used in fonts for a variety of purposes. Forming a "ff" ligature is one example. But a font might also substitute the default glyphs for a base letter and following combining mark with a single glyph that incorporates the base letter and the mark with the precise positioning of the mark for that combination. And that's something that would be essential for correct display of the script, but something that should be optional.

Thus, it would be a bad idea to disable all ligature substitutions. That's why OpenType has features as a trigger/control mechanism: features are organized around distinct typographic results, not the specific glyph-level actions used to achieve those results. So, you could disable a feature like Standard Ligatures without blocking ligature substitution actions that get used by the font for other typographic purposes.

于 2020-07-01T23:55:20.547 回答