📄 chapter2.htm
字号:
</UL>
<P>In a Coverage table, a format code (CoverageFormat) specifies the format as an integer: 1 = lists, and 2 = ranges.
<P>A Coverage table defines a unique index value (Coverage Index) for each covered glyph. This unique value specifies the position of the covered glyph in the Coverage table. The client uses the Coverage Index to look up values in the subtable for each glyph.
<H3>Coverage Format 1</H3>
<P>Coverage Format 1 consists of a format code (CoverageFormat) and a count of covered glyphs (GlyphCount), followed by an array of glyph indices (GlyphArray). The glyph indices must be in numerical order for binary searching of the list. When a glyph is found in the Coverage table, its position in the GlyphArray determines the Coverage Index that is returned-the first glyph has a Coverage Index = 0, and the last glyph has a Coverage Index = GlyphCount -1.
<P>Example 5 at the end of this chapter shows a Coverage table that uses Format 1 to list the GlyphIDs of all lowercase descender glyphs in a font.
<BR> <BR><FONT SIZE=5>CoverageFormat1 table: Individual glyph indices</FONT>
<TABLE BGCOLOR="#F0F0F0" WIDTH=530 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>CoverageFormat</TD><TD VALIGN=TOP>Format identifier-format = 1</TD></TR>
<TR>
<TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>GlyphCount</TD><TD VALIGN=TOP>Number of glyphs in the GlyphArray</TD></TR>
<TR>
<TD VALIGN=TOP>GlyphID</TD><TD VALIGN=TOP>GlyphArray[GlyphCount]</TD><TD VALIGN=TOP>Array of GlyphIDs-in numerical order</TD></TR>
</TABLE>
<H3>Coverage Format 2</H3>
Format 2 consists of a format code (CoverageFormat) and a count of glyph index ranges (RangeCount), followed by an array of records (RangeRecords). Each RangeRecord consists of a start glyph index (Start), an end glyph index (End), and the Coverage Index associated with the range's Start glyph. Ranges must be in GlyphID order, and they must be distinct, with no overlapping.
The Coverage Indexes for the first range begin with zero (0), and the Start Coverage Indexes for each succeeding range are determined by adding the length of the preceding range
(End GlyphID - Start GlyphID + 1) to the array Index. This allows for a quick calculation of the Coverage Index for any glyph in any range using the formula:
Coverage Index (GlyphID) = StartCoverageIndex + GlyphID - Start GlyphID.
Example 6 at the end of this chapter shows a Coverage table that uses Format 2 to identify a range of numeral glyphs in a font.
<BR> <BR><FONT SIZE=5>CoverageFormat2 table: Range of glyphs</FONT>
<TABLE BGCOLOR="#F0F0F0" WIDTH=530 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>CoverageFormat</TD><TD VALIGN=TOP>Format identifier-format = 2</TD></TR>
<TR>
<TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>RangeCount</TD><TD VALIGN=TOP>Number of RangeRecords</TD></TR>
<TR>
<TD VALIGN=TOP>struct</TD><TD VALIGN=TOP>RangeRecord<BR>[RangeCount]</TD><TD VALIGN=TOP>Array of glyph ranges-ordered by Start GlyphID</TD></TR>
</TABLE>
<BR> <BR><FONT SIZE=5>RangeRecord</FONT>
<TABLE BGCOLOR="#F0F0F0" WIDTH=530 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>Start</TD><TD VALIGN=TOP>First GlyphID in the range</TD></TR>
<TR>
<TD VALIGN=TOP>GlyphID</TD><TD VALIGN=TOP>End</TD><TD VALIGN=TOP>Last GlyphID in the range</TD></TR>
<TR>
<TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>StartCoverageIndex</TD><TD VALIGN=TOP>Coverage Index of first GlyphID in range</TD></TR>
</TABLE>
<H2>Class Definition Table</H2>
<P>In TrueType Open, index values identify glyphs. For efficiency and ease of representation, a font developer can group glyph indices to form glyph classes. Class assignments vary in meaning from one lookup subtable to another. For example, in the GSUB and GPOS tables, classes are used to describe glyph contexts. GDEF tables also use the idea of glyph classes.
<P>Consider a substitution action that replaces only the lowercase ascender glyphs in a glyph string. To more easily describe the appropriate context for the substitution, the font developer might divide the font's lowercase glyphs into two classes, one that contains the ascenders and one that contains the glyphs without ascenders.
<P>A font developer can assign any glyph to any class, each identified with an integer called a class value. A Class Definition table (ClassDef) groups glyph indices by class, beginning with Class 1, then Class 2, and so on. All glyphs not assigned to a class fall into Class 0. Within a given class definition table, each glyph in the font belongs to exactly one class.
<P>The ClassDef table can have either of two formats: one that assigns a range of consecutive glyph indices to different classes, or one that puts groups of consecutive glyph indices into the same class.
<H3>Class Definition Table Format 1</H3>
<P>The first class definition format (ClassDefFormat1) specifies a range of consecutive glyph indices and a list of corresponding glyph class values. This table is useful for assigning each glyph to a different class because the glyph indices in each class are not grouped together.
<P>A ClassDef Format 1 table begins with a format identifier (ClassFormat). The range of glyph indices (GlyphIDs) covered by the table is identified by two values: the GlyphID of the first glyph (StartGlyph), and the number of consecutive GlyphIDs (including the first one) that will be assigned class values (GlyphCount). The ClassValueArray lists the class value assigned to each GlyphID, starting with the class value for StartGlyph and following the same order as the GlyphIDs. Any glyph not included in the range of covered GlyphIDs automatically belongs to Class 0.
<P>Example 7 at the end of this chapter uses Format 1 to assign class values to the lowercase, x-height, ascender, and descender glyphs in a font.
<BR> <BR><FONT SIZE=5>ClassDefFormat1 table: Class array</FONT>
<TABLE BGCOLOR="#F0F0F0" WIDTH=530 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>ClassFormat</TD><TD VALIGN=TOP>Format identifier-format = 1</TD></TR>
<TR>
<TD VALIGN=TOP>GlyphID</TD><TD VALIGN=TOP>StartGlyph</TD><TD VALIGN=TOP>First GlyphID of the ClassValueArray</TD></TR>
<TR>
<TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>GlyphCount</TD><TD VALIGN=TOP>Size of the ClassValueArray</TD></TR>
<TR>
<TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>ClassValueArray[GlyphCount]</TD><TD VALIGN=TOP>Array of Class Values-one per GlyphID</TD></TR>
</TABLE>
<H3>Class Definition Table Format 2</H3>
<P>The second class definition format (ClassDefFormat2) defines multiple groups of glyph indices that belong to the same class. Each group consists of a discrete range of glyph indices in consecutive order (ranges cannot overlap).
<P>The ClassDef Format 2 table contains a format identifier (ClassFormat), a count of ClassRangeRecords that define the groups and assign class values (ClassRangeCount), and an array of ClassRangeRecords ordered by the GlyphID of the first glyph in each record (ClassRangeRecord).
<P>Each ClassRangeRecord consists of a Start glyph index, an End glyph index, and a Class value. All GlyphIDs in a range, from Start to End inclusive, constitute the class identified by the Class value. Any glyph not covered by a ClassRangeRecord is assumed to belong to Class 0.
<P>Example 8 at the end of this chapter uses Format 2 to assign class values to four types of glyphs in the Arabic script.
<BR> <BR><FONT SIZE=5>ClassDefFormat2 table: Class ranges</FONT>
<TABLE BGCOLOR="#F0F0F0" WIDTH=530 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>ClassFormat</TD><TD VALIGN=TOP>Format identifier-format = 2</TD></TR>
<TR>
<TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>ClassRangeCount</TD><TD VALIGN=TOP>Number of ClassRangeRecords</TD></TR>
<TR>
<TD VALIGN=TOP>struct</TD><TD VALIGN=TOP>ClassRangeRecord<BR>[ClassRangeCount]</TD><TD VALIGN=TOP>Array of ClassRangeRecords-ordered by Start GlyphID</TD></TR>
</TABLE>
<BR> <BR><FONT SIZE=5>ClassRangeRecord</FONT>
<TABLE BGCOLOR="#F0F0F0" WIDTH=530 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>Start</TD><TD VALIGN=TOP>First GlyphID in the range</TD></TR>
<TR>
<TD VALIGN=TOP>GlyphID</TD><TD VALIGN=TOP>End</TD><TD VALIGN=TOP>Last GlyphID in the range</TD></TR>
<TR>
<TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>Class</TD><TD VALIGN=TOP>Applied to all glyphs in the range</TD></TR>
</TABLE>
<H2>Device Tables</H2>
<P>Glyphs in a font are defined in design units specified by the font developer. Font scaling increases or decreases a glyph's size and rounds it to the nearest whole pixel. However, precise glyph positioning often requires adjustment of these scaled and rounded values. Hinting, applied to points in the glyph outline, is an effective solution to this problem, but it may require the font developer to redesign or re-hint glyphs.
<P>Another solution-used by the GPOS, BASE, JSTF, and GDEF tables-is to use a Device table to specify correction values to adjust the scaled design units. A Device table applies the correction values to the range of sizes identified by StartSize and EndSize, which specify the smallest and largest pixel-per-em (ppem) sizes needing adjustment.
<P>Because the adjustments often are very small (a pixel or two), the correction can be compressed into a 2-, 4-, or 8-bit representation per size. Two bits can represent a number in the range {-2, -1, 0, or 1}, four bits can represent a number in the range {-8 to 7}, and eight bits can represent a number in the range {-128 to 127}. The Device table identifies one of three data formats-signed 2-, 4,- or 8-bit values-for the adjustment values (DeltaFormat). A single Device table provides delta information for one coordinate at a range of sizes.
<TABLE BGCOLOR="#F0F0F0" WIDTH=530 BORDER=0 CELLPADDING=3>
<THEAD>
<TR>
<TH BGCOLOR="#C0C0C0">Format</TH><TH BGCOLOR="#C0C0C0">Bits</TH><TH BGCOLOR="#C0C0C0">Description</TH></TR>
</THEAD><TBODY>
<TR>
<TD VALIGN=TOP>1</TD><TD VALIGN=TOP>2</TD><TD VALIGN=TOP>Signed 2-bit value, 8 values per uint16</TD></TR>
<TR>
<TD VALIGN=TOP>2</TD><TD VALIGN=TOP>4</TD><TD VALIGN=TOP>Signed 4-bit value, 4 values per uint16</TD></TR>
<TR>
<TD VALIGN=TOP>3</TD><TD VALIGN=TOP>8</TD><TD VALIGN=TOP>Signed 8-bit value, 2 values per uint16</TD></TR>
</TABLE>
<P>The 2-, 4-, or 8-bit signed values are packed into uint16's most significant bits first. For example, using a DeltaFormat of 2 (4-bit values), an array of values equal to {1, 2, 3, -1} would be represented by the DeltaValue 0x123F.
<P>The DeltaValue array lists the number of pixels to adjust specified points on the glyph, or the entire glyph, at each ppem size in the targeted range. In the array, the first index position specifies the number of pixels to add or subtract from the coordinate at the smallest ppem size that needs correction, the second index position specifies the number of pixels to add or subtract from the coordinate at the next ppem size, and so on for each ppem size in the range.
<P>Example 9 at the end of this chapter uses a Device table to define the minimum extent value for a math script.
<BR> <BR><FONT SIZE=5>Device table</FONT>
<TABLE BGCOLOR="#F0F0F0" WIDTH=530 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>StartSize</TD><TD VALIGN=TOP>Smallest size to correct-in ppem</TD></TR>
<TR>
<TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>EndSize</TD><TD VALIGN=TOP>Largest size to correct-in ppem</TD></TR>
<TR>
<TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>DeltaFormat</TD><TD VALIGN=TOP>Format of DeltaValue array data: 1, 2, or 3</TD></TR>
<TR>
<TD VALIGN=TOP>uint16</TD><TD VALIGN=TOP>DeltaValue[ ]</TD><TD VALIGN=TOP>Array of compressed data</TD></TR>
</TABLE>
<H2>Common Table Examples</H2>
<P>The rest of this chapter describes and illustrates examples of all the common table formats. All the examples reflect unique parameters, but the samples provide a useful reference for building tables specific to other situations.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -