1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
/*******************************************************************
*
* ftxwidth.c 1.0
*
* Glyph Widths (and Heights) fast retrieval extension
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
*
* This extension is used to parse the "glyf" table of a TrueType
* file in order to extract the bbox of a given range of glyphs.
*
* The bbox is then used to build font unit widths and height
* that are returned in two parallel arrays.
*
* This extension is needed by the FreeType/2 OS/2 Font Driver.
*
******************************************************************/
#include "ttconfig.h"
#include "ftxwidth.h"
#include "ttdebug.h"
#include "ttobjs.h"
#include "ttfile.h"
#include "tttags.h"
#include "ttload.h"
/* Required by the tracing mode */
#undef TT_COMPONENT
#define TT_COMPONENT trace_any
/******************************************************************/
/* */
/* Function: TT_Get_Face_Widths */
/* */
/* Description: Returns the widths and/or heights of a given */
/* range of glyphs for a face. */
/* */
/* Input: */
/* face :: face handle */
/* */
/* first_glyph :: first glyph in range */
/* */
/* last_glyph :: last glyph in range */
/* */
/* widths :: address of table receiving the widths */
/* expressed in font units (ushorts). Set */
/* this parameter to NULL if you're not */
/* interested by these values. */
/* */
/* heights :: address of table receiving the heights */
/* expressed in font units (ushorts). Set */
/* this parameter to NULL if you're not */
/* interested by these values. */
/* */
/* Returns: */
/* Error code */
/* */
/* */
/******************************************************************/
EXPORT_FUNC
TT_Error TT_Get_Face_Widths( TT_Face face,
TT_UShort first_glyph,
TT_UShort last_glyph,
TT_UShort* widths,
TT_UShort* heights )
{
DEFINE_ALL_LOCALS;
PFace faze = HANDLE_Face(face);
UShort n;
Long table;
ULong glyf_offset; /* offset of glyph table in file */
UShort zero_width = 0; /* width of glyph 0 */
UShort zero_height = 0; /* height of glyph 0 */
Bool zero_loaded = 0;
#ifndef TT_HUGE_PTR
PStorage locations;
#else
Storage TT_HUGE_PTR * locations;
#endif
TT_BBox bbox;
if ( !faze )
return TT_Err_Invalid_Face_Handle;
if ( last_glyph >= faze->numGlyphs ||
first_glyph > last_glyph )
return TT_Err_Invalid_Argument;
/* find "glyf" table */
table = TT_LookUp_Table( faze, TTAG_glyf );
if ( table < 0 )
{
PERROR(( "ERROR: there is no glyph table in this font file!\n" ));
return TT_Err_Glyf_Table_Missing;
}
glyf_offset = faze->dirTables[table].Offset;
/* now access stream */
if ( USE_Stream( faze->stream, stream ) )
return error;
locations = faze->glyphLocations + first_glyph;
/* loop to load each glyph in the range */
for ( n = first_glyph; n <= last_glyph; n++ )
{
if ( n + 1 < faze->numGlyphs &&
locations[0] == locations[1] )
{
/* Note : Glyph 0 is always used to indicate a missing glyph */
/* in a range. We must thus return its width and height */
/* where appropriate when we find an undefined glyph. */
if ( zero_loaded == 0 )
{
if ( FILE_Seek( glyf_offset + faze->glyphLocations[0] ) ||
ACCESS_Frame( 10L ) )
goto Fail;
(void)GET_Short(); /* skip number of contours */
bbox.xMin = GET_Short();
bbox.yMin = GET_Short();
bbox.xMax = GET_Short();
bbox.yMax = GET_Short();
FORGET_Frame();
zero_width = (UShort)(bbox.xMax - bbox.xMin);
zero_height = (UShort)(bbox.yMax - bbox.yMin);
zero_loaded = 1;
}
if ( widths )
*widths++ = zero_width;
if ( heights )
*heights++ = zero_height;
}
else
{
/* normal glyph, read header */
if ( FILE_Seek( glyf_offset + locations[0] ) ||
ACCESS_Frame( 10L ) )
goto Fail;
(void)GET_Short(); /* skip number of contours */
bbox.xMin = GET_Short();
bbox.yMin = GET_Short();
bbox.xMax = GET_Short();
bbox.yMax = GET_Short();
FORGET_Frame();
if ( widths )
*widths++ = (UShort)(bbox.xMax - bbox.xMin);
if ( heights )
*heights++ = (UShort)(bbox.yMax - bbox.yMin);
}
}
Fail:
DONE_Stream( stream );
return error;
}
/* END */
|