1 /*******************************************************************
5 * Glyph Widths (and Heights) fast retrieval extension
7 * Copyright 1996-1999 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
10 * This file is part of the FreeType project, and may only be used
11 * modified and distributed under the terms of the FreeType project
12 * license, LICENSE.TXT. By continuing to use, modify, or distribute
13 * this file you indicate that you have read the license and
14 * understand and accept it fully.
17 * This extension is used to parse the "glyf" table of a TrueType
18 * file in order to extract the bbox of a given range of glyphs.
20 * The bbox is then used to build font unit widths and height
21 * that are returned in two parallel arrays.
23 * This extension is needed by the FreeType/2 OS/2 Font Driver.
25 ******************************************************************/
35 /* Required by the tracing mode */
38 #define TT_COMPONENT trace_any
41 /******************************************************************/
43 /* Function: TT_Get_Face_Widths */
45 /* Description: Returns the widths and/or heights of a given */
46 /* range of glyphs for a face. */
49 /* face :: face handle */
51 /* first_glyph :: first glyph in range */
53 /* last_glyph :: last glyph in range */
55 /* widths :: address of table receiving the widths */
56 /* expressed in font units (ushorts). Set */
57 /* this parameter to NULL if you're not */
58 /* interested by these values. */
60 /* heights :: address of table receiving the heights */
61 /* expressed in font units (ushorts). Set */
62 /* this parameter to NULL if you're not */
63 /* interested by these values. */
69 /******************************************************************/
72 TT_Error
TT_Get_Face_Widths( TT_Face face
,
73 TT_UShort first_glyph
,
80 PFace faze
= HANDLE_Face(face
);
84 ULong glyf_offset
; /* offset of glyph table in file */
85 UShort zero_width
= 0; /* width of glyph 0 */
86 UShort zero_height
= 0; /* height of glyph 0 */
93 Storage TT_HUGE_PTR
* locations
;
99 return TT_Err_Invalid_Face_Handle
;
101 if ( last_glyph
>= faze
->numGlyphs
||
102 first_glyph
> last_glyph
)
103 return TT_Err_Invalid_Argument
;
105 /* find "glyf" table */
106 table
= TT_LookUp_Table( faze
, TTAG_glyf
);
109 PERROR(( "ERROR: there is no glyph table in this font file!\n" ));
110 return TT_Err_Glyf_Table_Missing
;
112 glyf_offset
= faze
->dirTables
[table
].Offset
;
114 /* now access stream */
115 if ( USE_Stream( faze
->stream
, stream
) )
118 locations
= faze
->glyphLocations
+ first_glyph
;
120 /* loop to load each glyph in the range */
121 for ( n
= first_glyph
; n
<= last_glyph
; n
++ )
123 if ( n
+ 1 < faze
->numGlyphs
&&
124 locations
[0] == locations
[1] )
126 /* Note : Glyph 0 is always used to indicate a missing glyph */
127 /* in a range. We must thus return its width and height */
128 /* where appropriate when we find an undefined glyph. */
129 if ( zero_loaded
== 0 )
131 if ( FILE_Seek( glyf_offset
+ faze
->glyphLocations
[0] ) ||
132 ACCESS_Frame( 10L ) )
135 (void)GET_Short(); /* skip number of contours */
137 bbox
.xMin
= GET_Short();
138 bbox
.yMin
= GET_Short();
139 bbox
.xMax
= GET_Short();
140 bbox
.yMax
= GET_Short();
144 zero_width
= (UShort
)(bbox
.xMax
- bbox
.xMin
);
145 zero_height
= (UShort
)(bbox
.yMax
- bbox
.yMin
);
150 *widths
++ = zero_width
;
153 *heights
++ = zero_height
;
157 /* normal glyph, read header */
158 if ( FILE_Seek( glyf_offset
+ locations
[0] ) ||
159 ACCESS_Frame( 10L ) )
162 (void)GET_Short(); /* skip number of contours */
164 bbox
.xMin
= GET_Short();
165 bbox
.yMin
= GET_Short();
166 bbox
.xMax
= GET_Short();
167 bbox
.yMax
= GET_Short();
172 *widths
++ = (UShort
)(bbox
.xMax
- bbox
.xMin
);
175 *heights
++ = (UShort
)(bbox
.yMax
- bbox
.yMin
);
180 DONE_Stream( stream
);