contrib/OWB: add correct SDL dependency, fix compilers used
[AROS-Contrib.git] / freetype1 / lib / extend / ftxwidth.c
blob5415f5aa8e185591a88790c1433b13b9392dff66
1 /*******************************************************************
3 * ftxwidth.c 1.0
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 ******************************************************************/
28 #include "ftxwidth.h"
29 #include "ttdebug.h"
30 #include "ttobjs.h"
31 #include "ttfile.h"
32 #include "tttags.h"
33 #include "ttload.h"
35 /* Required by the tracing mode */
37 #undef TT_COMPONENT
38 #define TT_COMPONENT trace_any
41 /******************************************************************/
42 /* */
43 /* Function: TT_Get_Face_Widths */
44 /* */
45 /* Description: Returns the widths and/or heights of a given */
46 /* range of glyphs for a face. */
47 /* */
48 /* Input: */
49 /* face :: face handle */
50 /* */
51 /* first_glyph :: first glyph in range */
52 /* */
53 /* last_glyph :: last glyph in range */
54 /* */
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. */
59 /* */
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. */
64 /* */
65 /* Returns: */
66 /* Error code */
67 /* */
68 /* */
69 /******************************************************************/
71 EXPORT_FUNC
72 TT_Error TT_Get_Face_Widths( TT_Face face,
73 TT_UShort first_glyph,
74 TT_UShort last_glyph,
75 TT_UShort* widths,
76 TT_UShort* heights )
78 DEFINE_ALL_LOCALS;
80 PFace faze = HANDLE_Face(face);
81 UShort n;
82 Long table;
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 */
88 Bool zero_loaded = 0;
90 #ifndef TT_HUGE_PTR
91 PStorage locations;
92 #else
93 Storage TT_HUGE_PTR * locations;
94 #endif
95 TT_BBox bbox;
98 if ( !faze )
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 );
107 if ( table < 0 )
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 ) )
116 return error;
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 ) )
133 goto Fail;
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();
142 FORGET_Frame();
144 zero_width = (UShort)(bbox.xMax - bbox.xMin);
145 zero_height = (UShort)(bbox.yMax - bbox.yMin);
146 zero_loaded = 1;
149 if ( widths )
150 *widths++ = zero_width;
152 if ( heights )
153 *heights++ = zero_height;
155 else
157 /* normal glyph, read header */
158 if ( FILE_Seek( glyf_offset + locations[0] ) ||
159 ACCESS_Frame( 10L ) )
160 goto Fail;
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();
169 FORGET_Frame();
171 if ( widths )
172 *widths++ = (UShort)(bbox.xMax - bbox.xMin);
174 if ( heights )
175 *heights++ = (UShort)(bbox.yMax - bbox.yMin);
179 Fail:
180 DONE_Stream( stream );
181 return error;
185 /* END */