http://opentypecookbook.com/foundation-concepts/
Foundation Concepts 基础概念
Before we start writing any code, let’s first look at what the code will actually do. If you are reading this cookbook just to find out how to do something simple like write a small caps feature, you may skip this section and jump ahead to the code snippets. But, if you want to develop complex, nuanced, amazing features, you really should read this section. Understanding the underlying mechanics of how features work will allow you to carry your vision all the way from how the glyphs look to how they behave.
在我们开始编写任何代码之前,让我们先看看代码实际上能做什么。如果你读这本书只是为了了解如何做一些简单的事情,比如写一个小型大写的特性,你可以跳过这一部分,直接跳到代码片段。但是,如果你想开发复杂的、细致入微的、令人惊叹的特性,你真的应该阅读这一部分。了解特征如何工作的基本机制将允许您将您的愿景从字形看起来如何到它们的行为如何一路推进。
Ready? Alright, let’s get into some heavy stuff.
准备好了吗? 好,让我们来看看重要的东西。
Structures 结构
In OpenType we can define behaviors that we want to happen upon request from users. For example, the user may decide that text should be displayed with small caps. You, the type designer, can define which glyphs should be changed when this request is made by the user. These behaviors are defined in features. Features can do two things: they can substitute glyphs and they can adjust the positions of glyphs.
在 OpenType 中,我们可以定义希望在用户请求时发生的行为。例如,用户可能决定文本应该用小型大写显示。您,字体设计师,可以定义当用户发出此请求时应该替换哪些字形。这些行为是在特性中定义的。OT特性可以做两件事情: 1、可以替换字形,2、可以调整字形的显示位置。
The actual behavior within the features are defined with rules. Following the small caps example above, you can define a rule that states that the a glyph should be replaced with A.sc.
特性中的实际行为是用规则(rules)定义的。按照上面的小型大写示例,您可以定义一个规则,规定 a 字形应该替换为 A.sc。
Within a feature, it is often necessary to group a set of rules together. This group of rules is called a lookup.
在一个特性(feature )中,通常需要将一组规则组合在一起。这样一组规则称为查找(lookup)。
Visually, you can think of features, lookups and rules like this:
在视觉上,你可以这样理解特性、查找和规则:
(Note: In these illustrations if you see a jagged line cutting something off, it means “There is a bunch of the same kind of stuff so we’ll cut it off to avoid too much repetition.”)
(注意: 在这些插图中,如果你看到一条锯齿状的线条把什么东西切掉了,这意味着“有一大堆同样的东西,所以我们会把它切掉,以避免太多的重复。”)
Processing 处理
When text is processed, the features that the user wants applied are gathered into two groups: substitution features and positioning features. The substitution features are processed first and then the positioning features are processed. The order in which you have defined the features, lookups and rules is the order in which they will be applied to the text. This order is very important.
当处理文本时,用户想要应用的特征被集中到两组: 替换特性和定位特性。首先处理替换特征,然后处理定位特征。定义特性、查找和规则的顺序是它们应用于文本的顺序。这个顺序很重要。
Features process sequences of glyphs. These glyph runs may represent a complete line of text or a sub-section of a line of text.
特性处理一个序列的字形。一个字形序列可以表示一行完整的文本或一行文本的子部分。
For example, let’s assume that you have the following features, lookups and rules:
例如,假设你有以下特性,查找和规则:
Let’s also assume that the user wants to apply small caps and ligatures to a glyph run that displays Hello.
我们还假设用户希望对显示 Hello 的字形运行应用小写和连字。
A glyph run is processed one feature at a time. So, here is what Hello will look like as it enters and exists each feature:
字形运行一次处理一个特征。下面是 Hello 进入和存在每个特性时的样子:
Within each feature, the glyph run is processed one lookup at a time. Here is what our example looks like as it moves through the small caps feature:
在每个特性中,每次处理一个字形运行查找。下面是我们的例子在小写字母功能中的运行情况:
Within each lookup, things are a little different. The glyph run is passed one glyph at a time from beginning to end over each rule within the lookup. If a rule replaces the current glyph, the following rules are skipped for the current glyph. The next glyph is then current through the lookup. That’s complex, so let’s look at it with our example:
在每个查找中,内容都有一点不同。字形运行每次从头到尾通过查找内的每个规则传递一个字形。如果规则替换当前字形,则跳过当前标志符号的下列规则。然后通过查找当前的下一个字形。这很复杂,所以让我们用我们的例子来看一下:
The process is the same for positioning features, except that instead of rule evaluation stopping when a glyph is replaced, the evaluation is stopped when a glyph’s position is changed.
对于定位特征,这个过程是相同的,除了当一个字形被替换时规则计算停止,而当一个字形的位置被改变时计算停止。
That’s how processing works and it is the most complex part of OpenType features that you will need to understand. Got it? Great!
这就是处理的工作原理,也是 OpenType 特性中您需要理解的最复杂的部分。都明白了吗?太棒了!
Next: Syntax Introduction 下一步: 语法介绍