📄 gsub.htm
字号:
<BR> <BR><FONT SIZE=5>LigatureSet table:<BR>All ligatures beginning with the same glyph</FONT>
<TABLE BGCOLOR="#F0F0F0" WIDTH=480 BORDER=0 CELLPADDING=3>
<THEAD>
<TR><TH BGCOLOR="#C0C0C0">Type</TH><TH BGCOLOR="#C0C0C0">Name</TH><TH BGCOLOR="#C0C0C0">Description</TH></TR>
</THEAD>
<TBODY>
<TR><TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>LigatureCount</TD><TD>Number of Ligature tables</TD></TR>
<TR><TD VALIGN=TOP>Offset</TD><TD VALIGN=TOP>Ligature<BR>[LigatureCount]</TD><TD>Array of offsets to Ligature tables-from beginning of LigatureSet table-ordered by preference</TD></TR>
</TABLE>
<P>For each ligature in the set, a Ligature table specifies the GlyphID of the output ligature glyph (LigGlyph); a count of the total number of component glyphs in the ligature, including the first component (CompCount); and an array of GlyphIDs for the components (Component). The array starts with the second component glyph (array index = 1) in the ligature because the first component glyph is specified in the Coverage table.
<BLOCKQUOTE>
<STRONG>Note:</STRONG> The Component array lists GlyphIDs according to the LookupFlag bit that specifies the writing direction of the text. For text written right to left, the right-most glyph will be first. Conversely, for text written left to right, the left-most glyph will be first.
</BLOCKQUOTE>
<A HREF="#EX6">Example 6</A> at the end of this chapter shows how to replace a string of glyphs with a single ligature.
<BR> <BR><FONT SIZE=5>Ligature table: Glyph components for one ligature</FONT>
<TABLE BGCOLOR="#F0F0F0" WIDTH=480 BORDER=0 CELLPADDING=3>
<THEAD>
<TR><TH BGCOLOR="#C0C0C0">Type</TH><TH BGCOLOR="#C0C0C0">Name</TH><TH BGCOLOR="#C0C0C0">Description</TH></TR>
</THEAD>
<TBODY>
<TR><TD VALIGN=TOP>GlyphID</TD><TD VALIGN=TOP>LigGlyph</TD><TD>GlyphID of ligature to substitute</TD></TR>
<TR><TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>CompCount</TD><TD>Number of components in the ligature</TD></TR>
<TR><TD VALIGN=TOP>GlyphID</TD><TD VALIGN=TOP NOWRAP=NOWRAP>Component<BR>[CompCount - 1]</TD><TD>Array of component GlyphIDs-start with the second component-ordered by LookupFlag direction bit</TD></TR>
</TABLE>
<H4>LookupType 5:<BR>
Contextual Substitution Subtable</H4>
<P>A Contextual Substitution (ContextSubst) subtable defines the most powerful type of glyph substitution lookup: it describes glyph substitutions in context that replace one or more glyphs within a certain pattern of glyphs.
<P>ContextSubst subtables can be any of three formats that define a context in terms of a specific sequence of glyphs, glyph classes, or glyph sets. Each format can describe one or more input glyph sequences and one or more substitutions for each sequence.
<P>All ContextSubst subtables specify the substitution data in a SubstLookupRecord. A description of that record follows the descriptions of the three formats available for ContextSubst subtables.
<A NAME=CSF1><H4>Context Substitution Format 1</H4></A>
<P>Format 1 defines the context for a glyph substitution as a particular sequence of glyphs. For example, a context could be <xyz>, <holiday>, <!?*#@>, or any other glyph sequence.
<P>Within a context sequence, Format 1 identifies particular glyph positions (not glyph indices) as the targets for specific substitutions. When a text-processing client locates a context in a string of text, it finds the lookup data for a targeted position and makes a substitution by applying the lookup data at that location.
<P>For example, to replace the glyph string <abc> with its reverse glyph string <cba>, the input context is defined as the glyph sequence, <abc>. On locating "abc" in the text, the client searches the ContextSubstFormat1 subtable for lookup data that applies to the first glyph in the sequence. When it finds the lookup data, the client applies the lookup and replaces the glyph in the first position (in this case, the "a") with a "c," producing the output glyph string <cac>.
<P>After completing the lookup for the first glyph position, the client searches the subtable for data applicable to the second glyph in the context sequence. Because the "b" does not need to be replaced, no data exists for this position.
<P>Finally, the client searches the subtable for data to apply to the third glyph in the sequence. The subtable specifies a substitution, so the client applies the lookup and replaces the "c" glyph with an "a." The contextual substitution ends, and the final output is the glyph string <cba>.
<P>To specify a context, a Coverage table lists the first glyph in the sequence, and a SubRule table identifies the remaining glyphs. To describe the >abc< context used in the previous example, the Coverage table lists the glyph index of the first component of the sequence-the "a" glyph. A SubRule table defines indices for the "b" and "c" glyphs.
<P>A single ContextSubstFormat1 subtable may define more than one context glyph sequence. If different context sequences begin with the same glyph, then the Coverage table should list the glyph only once because all glyphs in the table must be unique. For example, if three contexts each start with an "s" and two start with a "t," then the Coverage table will list one "s" and one "t."
<P>For each context, a SubRule table lists all the glyphs that follow the first glyph. The table also contains an array of SubstLookupRecords that specify the substitution lookup data for each glyph position (including the first glyph position) in the context.
<P>All of the SubRule tables defining contexts that begin with the same first glyph are grouped together and defined in a SubRuleSet table. For example, the SubRule tables that define the three contexts that begin with an "s" are grouped in one SubRuleSet table, and the SubRule tables that define the two contexts that begin with a "t" are grouped in a second SubRuleSet table. Each glyph listed in the Coverage table must have a SubRuleSet table defining all the SubRule tables that apply to a covered glyph.
<P>To locate a context glyph sequence, the text-processing client searches the Coverage table each time it encounters a new text glyph. If the glyph is covered, the client reads the corresponding SubRuleSet table and examines each SubRule table in the set to determine whether the rest of the context matches the subsequent glyphs in the text. If the context and text string match, the client finds the target glyph positions, applies the lookups for those positions, and completes the substitutions.
<P>A ContextSubstFormat1 subtable contains a format identifier (SubstFormat), an offset to a Coverage table (Coverage), a count of defined SubRuleSets (SubRuleSetCount), and an array of offsets to the SubRuleSet tables (SubRuleSet). As mentioned, one SubRuleSet table must be defined for each glyph listed in the Coverage table.
<P>In the SubRuleSet array, the SubRuleSet table offsets are ordered in the Coverage Index order. The first SubRuleSet in the array applies to the first GlyphID listed in the Coverage table, the second SubRuleSet in the array applies to the second GlyphID listed in the Coverage table, and so on.
<BR> <BR><FONT SIZE=5>ContextSubstFormat1 subtable:<BR> Simple context glyph substitution</FONT>
<TABLE BGCOLOR="#F0F0F0" WIDTH=480 BORDER=0 CELLPADDING=3>
<THEAD>
<TR><TH BGCOLOR="#C0C0C0">Type</TH><TH BGCOLOR="#C0C0C0">Name</TH><TH BGCOLOR="#C0C0C0">Description</TH></TR>
</THEAD>
<TBODY>
<TR><TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>SubstFormat</TD><TD>Format identifier-format = 1</TD></TR>
<TR><TD VALIGN=TOP>Offset</TD><TD VALIGN=TOP>Coverage</TD><TD>Offset to Coverage table-from beginning of Substitution table</TD></TR>
<TR><TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>SubRuleSetCount</TD><TD>Number of SubRuleSet tables-must equal GlyphCount in Coverage table</TD></TR>
<TR><TD VALIGN=TOP>Offset</TD><TD VALIGN=TOP>SubRuleSet<BR>[SubRuleSetCount]</TD><TD>Array of offsets to SubRuleSet tables-from beginning of Substitution table-ordered by Coverage Index</TD></TR>
</TABLE>
<P>A SubRuleSet table consists of an array of offsets to SubRule tables (SubRule), ordered by preference, and a count of the SubRule tables defined in the set (SubRuleCount).
The order in the SubRule array can be critical. Consider two contexts, <abc> and <abcd>. If <abc> is first in the SubRule array, all instances of <abc> in the text-including all instances of <abcd>-will be changed. If <abcd> comes first in the array, however, only <abcd> sequences will be changed, without affecting any instances of <abc>.
<BR> <BR><FONT SIZE=5>SubRuleSet table:<BR> All contexts beginning with the same glyph</FONT>
<TABLE BGCOLOR="#F0F0F0" WIDTH=480 BORDER=0 CELLPADDING=3>
<THEAD>
<TR><TH BGCOLOR="#C0C0C0">Type</TH><TH BGCOLOR="#C0C0C0">Name</TH><TH BGCOLOR="#C0C0C0">Description</TH></TR>
</THEAD>
<TBODY>
<TR><TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>SubRuleCount</TD><TD>Number of SubRule tables</TD></TR>
<TR><TD VALIGN=TOP>Offset</TD><TD VALIGN=TOP>SubRule<BR>[SubRuleCount]</TD><TD>Array of offsets to SubRule tables-from beginning of SubRuleSet table-ordered by preference</TD></TR>
</TABLE>
<P>A SubRule table consists of a count of the glyphs to be matched in the input context sequence (GlyphCount), including the first glyph in the sequence, and an array of glyph indices that describe the context (Input). The Coverage table specifies the index of the first glyph in the context, and the Input array begins with the second glyph (array index = 1) in the context sequence.
<BLOCKQUOTE>
<STRONG>Note:</STRONG> The Input array lists the indices in the order the corresponding glyphs appear in the text. For text written from right to left, the right-most glyph will be first; conversely, for text written from left to right, the left-most glyph will be first.
</BLOCKQUOTE>
<P>A SubRule table also contains a count of the substitutions to be performed on the input glyph sequence (SubstCount) and an array of SubstitutionLookupRecords (SubstLookupRecord). Each record specifies a position in the input glyph sequence and a LookupListIndex to the substitution lookup that is applied at that position. The array should list records in design order, or the order the lookups should be applied to the entire glyph sequence.
SubRule table: One simple context definition
<TABLE BGCOLOR="#F0F0F0" WIDTH=480 BORDER=0 CELLPADDING=3>
<THEAD>
<TR><TH BGCOLOR="#C0C0C0">Type</TH><TH BGCOLOR="#C0C0C0">Name</TH><TH BGCOLOR="#C0C0C0">Description</TH></TR>
</THEAD>
<TBODY>
<TR><TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>GlyphCount</TD><TD>Total number of glyphs in input glyph sequence-includes the first glyph</TD></TR>
<TR><TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>SubstCount</TD><TD>Number of SubstLookupRecords</TD></TR>
<TR><TD VALIGN=TOP>GlyphID</TD><TD VALIGN=TOP>Input<BR>[GlyphCount - 1]</TD><TD VALIGN=TOP>Array of input GlyphIDs-start with second glyph</TD></TR>
<TR><TD VALIGN=TOP>struct</TD><TD VALIGN=TOP>SubstLookupRecord<BR>[SubstCount]</TD><TD VALIGN=TOP>Array of SubstLookupRecords-in design order</TD></TR>
</TABLE>
<A HREF="#EX7"><P>Example 7</A> at the end of the chapter shows how to use the ContextSubstFormat1 subtable to replace three dashes with a sequence preferred for the French language system.
<A NAME=CSF2><H4>Context Substitution Format 2</H4></A>
<P>Format 2, a more flexible format than Format 1, describes class-based context substitution. For this format, a specific integer, called a class value, must be assigned to each glyph component in all context glyph sequences. Contexts are then defined as sequences of glyph class values. More than one context may be defined at a time.
<P>For example, suppose that a swash capital glyph should replace each uppercase letter glyph that is preceded by a space glyph and followed by a lowercase letter glyph (a glyph sequence of space - uppercase - lowercase). The set of uppercase glyphs would constitute one glyph class (Class 1), the set of lowercase glyphs would constitute a second class (Class 2), and the space glyph would constitute a third class (Class 3). The input context might be specified with a context rule (called a SubClassRule) that describes "the set of glyph strings that form a sequence of three glyph classes, one glyph from Class 3, followed by one glyph from Class 1, followed by one glyph from Class 2."
<P>Each ContextSubstFormat2 subtable contains an offset to a class definition table (ClassDef), which defines the glyph class values of all input contexts. Generally, a unique ClassDef table will be declared in each instance of the ContextSubstFormat2 table that is included in a font, even though several Format 2 tables could share ClassDef tables. Class assignments are fixed (the same for each position in the context), and classes are exclusive (a glyph cannot be in more than one class at a time). The output glyphs that replace the glyphs in the context sequences do not need class values because they are specified elsewhere by GlyphID.
<P>The ContextSubstFormat2 subtable also contains a format identifier (SubstFormat) and defines an offset to a Coverage table (Coverage). For this format, the Coverage table lists indices for the complete set of unique glyphs (not glyph classes) that may appear as the first glyph of any class-based context. In other words, the Coverage table contains the list of glyph indices for all the glyphs in all classes that may be first in any of the context class sequences. For example, if the contexts begin with a Class 1 or Class 2 glyph, then the Coverage table will list the indices of all Class 1 and Class 2 glyphs. This Coverage listing is redundant because the ClassDef table also identifies input glyphs, but it accelerates the lookup process.
<P>A ContextSubstFormat2 subtable also defines an array of offsets to the SubClassSet tables (SubClassSet) and a count of the SubClassSet tables (SubClassSetCnt). The array contains one offset for each class (including Class 0) in the ClassDef table. In the array, the class value defines an offset's index position, and the SubClassSet offsets are ordered by ascending class value (from 0 to SubClassSetCnt - 1).
<P>For example, the first SubClassSet listed in the array contains all contexts beginning with Class 0 glyphs, the second SubClassSet contains all contexts beginning with Class 1 glyphs, and so on. If no contexts begin with a particular class (that is, if a SubClassSet contains no SubClassRule tables), then the offset to that particular SubClassSet in the SubClassSet array will be set to NULL.
<BR> <BR><FONT SIZE=5>ContextSubstFormat2 subtable:<BR> Class-based context glyph substitution</FONT>
<TABLE BGCOLOR="#F0F0F0" WIDTH=480 BORDER=0 CELLPADDING=3>
<THEAD>
<TR><TH BGCOLOR="#C0C0C0">Type</TH><TH BGCOLOR="#C0C0C0">Name</TH><TH BGCOLOR="#C0C0C0">Description</TH></TR>
</THEAD>
<TBODY>
<TR><TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>SubstFormat</TD><TD>Format identifier-format = 2</TD></TR>
<TR><TD VALIGN=TOP>Offset</TD><TD VALIGN=TOP>Coverage</TD><TD>Offset to Coverage table-from beginning of Substitution table</TD></TR>
<TR><TD VALIGN=TOP>Offset</TD><TD VALIGN=TOP>ClassDef</TD><TD>Offset to glyph ClassDef table-from beginning of Substitution table</TD></TR>
<TR><TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>SubClassSetCnt</TD><TD>Number of SubClassSet tables</TD></TR>
<TR><TD VALIGN=TOP>Offset</TD><TD VALIGN=TOP>SubClassSet<BR>[SubClassSetCnt]</TD><TD>Array of offsets to SubClassSet tables-from beginning of Substitution table-ordered by class-may be NULL</TD></TR>
</TABLE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -