1 /***************************************************************************/
5 /* Type 1 Glyph Loader (body). */
7 /* Copyright 1996-2001 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. */
16 /***************************************************************************/
21 #include FT_INTERNAL_DEBUG_H
22 #include FT_INTERNAL_STREAM_H
24 #include FT_INTERNAL_POSTSCRIPT_AUX_H
28 #include <string.h> /* for strcmp() */
31 /*************************************************************************/
33 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
34 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
35 /* messages during execution. */
38 #define FT_COMPONENT trace_t1gload
41 /*************************************************************************/
42 /*************************************************************************/
43 /*************************************************************************/
44 /********** *********/
45 /********** COMPUTE THE MAXIMUM ADVANCE WIDTH *********/
46 /********** *********/
47 /********** The following code is in charge of computing *********/
48 /********** the maximum advance width of the font. It *********/
49 /********** quickly processes each glyph charstring to *********/
50 /********** extract the value from either a `sbw' or `seac' *********/
51 /********** operator. *********/
52 /********** *********/
53 /*************************************************************************/
54 /*************************************************************************/
55 /*************************************************************************/
58 FT_CALLBACK_DEF( FT_Error )
59 T1_Parse_Glyph( T1_Decoder* decoder,
62 T1_Face face = (T1_Face)decoder->builder.face;
63 T1_Font* type1 = &face->type1;
66 decoder->font_matrix = type1->font_matrix;
67 decoder->font_offset = type1->font_offset;
69 return decoder->funcs.parse_charstrings(
71 type1->charstrings [glyph_index],
72 type1->charstrings_len[glyph_index] );
77 T1_Compute_Max_Advance( T1_Face face,
83 T1_Font* type1 = &face->type1;
84 PSAux_Interface* psaux = (PSAux_Interface*)face->psaux;
89 /* initialize load decoder */
90 error = psaux->t1_decoder_funcs->init( &decoder,
94 (FT_Byte**)type1->glyph_names,
100 decoder.builder.metrics_only = 1;
101 decoder.builder.load_points = 0;
103 decoder.num_subrs = type1->num_subrs;
104 decoder.subrs = type1->subrs;
105 decoder.subrs_len = type1->subrs_len;
107 /* for each glyph, parse the glyph charstring and extract */
108 /* the advance width */
109 for ( glyph_index = 0; glyph_index < type1->num_glyphs; glyph_index++ )
111 /* now get load the unscaled outline */
112 error = T1_Parse_Glyph( &decoder, glyph_index );
113 /* ignore the error if one occured - skip to next glyph */
116 *max_advance = decoder.builder.advance.x;
121 /*************************************************************************/
122 /*************************************************************************/
123 /*************************************************************************/
124 /********** *********/
125 /********** UNHINTED GLYPH LOADER *********/
126 /********** *********/
127 /********** The following code is in charge of loading a *********/
128 /********** single outline. It completely ignores hinting *********/
129 /********** and is used when FT_LOAD_NO_HINTING is set. *********/
130 /********** *********/
131 /********** The Type 1 hinter is located in `t1hint.c' *********/
132 /********** *********/
133 /*************************************************************************/
134 /*************************************************************************/
135 /*************************************************************************/
138 FT_LOCAL_DEF FT_Error
139 T1_Load_Glyph( T1_GlyphSlot glyph,
146 T1_Face face = (T1_Face)glyph->root.face;
148 T1_Font* type1 = &face->type1;
149 PSAux_Interface* psaux = (PSAux_Interface*)face->psaux;
150 const T1_Decoder_Funcs* decoder_funcs = psaux->t1_decoder_funcs;
152 FT_Matrix font_matrix;
153 FT_Vector font_offset;
155 if ( load_flags & FT_LOAD_NO_RECURSE )
156 load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING;
158 glyph->x_scale = size->root.metrics.x_scale;
159 glyph->y_scale = size->root.metrics.y_scale;
161 glyph->root.outline.n_points = 0;
162 glyph->root.outline.n_contours = 0;
164 hinting = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE ) == 0 &&
165 ( load_flags & FT_LOAD_NO_HINTING ) == 0 );
167 glyph->root.format = ft_glyph_format_outline;
169 error = decoder_funcs->init( &decoder,
173 (FT_Byte**)type1->glyph_names,
179 decoder.builder.no_recurse = FT_BOOL(
180 ( load_flags & FT_LOAD_NO_RECURSE ) != 0 );
182 decoder.num_subrs = type1->num_subrs;
183 decoder.subrs = type1->subrs;
184 decoder.subrs_len = type1->subrs_len;
187 /* now load the unscaled outline */
188 error = T1_Parse_Glyph( &decoder, glyph_index );
192 font_matrix = decoder.font_matrix;
193 font_offset = decoder.font_offset;
195 /* save new glyph tables */
196 decoder_funcs->done( &decoder );
198 /* now, set the metrics -- this is rather simple, as */
199 /* the left side bearing is the xMin, and the top side */
200 /* bearing the yMax */
203 glyph->root.outline.flags &= ft_outline_owner;
204 glyph->root.outline.flags |= ft_outline_reverse_fill;
206 /* for composite glyphs, return only left side bearing and */
208 if ( load_flags & FT_LOAD_NO_RECURSE )
210 FT_Slot_Internal internal = glyph->root.internal;
213 glyph->root.metrics.horiBearingX = decoder.builder.left_bearing.x;
214 glyph->root.metrics.horiAdvance = decoder.builder.advance.x;
215 internal->glyph_matrix = font_matrix;
216 internal->glyph_delta = font_offset;
217 internal->glyph_transformed = 1;
222 FT_Glyph_Metrics* metrics = &glyph->root.metrics;
225 /* copy the _unscaled_ advance width */
226 metrics->horiAdvance = decoder.builder.advance.x;
227 glyph->root.linearHoriAdvance = decoder.builder.advance.x;
228 glyph->root.internal->glyph_transformed = 0;
230 /* make up vertical metrics */
231 metrics->vertBearingX = 0;
232 metrics->vertBearingY = 0;
233 metrics->vertAdvance = 0;
235 glyph->root.linearVertAdvance = 0;
237 glyph->root.format = ft_glyph_format_outline;
239 if ( size && size->root.metrics.y_ppem < 24 )
240 glyph->root.outline.flags |= ft_outline_high_precision;
242 /* apply the font matrix */
243 FT_Outline_Transform( &glyph->root.outline, &font_matrix );
245 FT_Outline_Translate( &glyph->root.outline,
251 glyph->root.outline.second_pass = TRUE;
252 glyph->root.outline.high_precision = size->root.metrics.y_ppem < 24;
253 glyph->root.outline.dropout_mode = 2;
257 if ( ( load_flags & FT_LOAD_NO_SCALE ) == 0 )
259 /* scale the outline and the metrics */
261 FT_Outline* cur = decoder.builder.base;
262 FT_Vector* vec = cur->points;
263 FT_Fixed x_scale = glyph->x_scale;
264 FT_Fixed y_scale = glyph->y_scale;
267 /* First of all, scale the points */
268 for ( n = cur->n_points; n > 0; n--, vec++ )
270 vec->x = FT_MulFix( vec->x, x_scale );
271 vec->y = FT_MulFix( vec->y, y_scale );
274 FT_Outline_Get_CBox( &glyph->root.outline, &cbox );
276 /* Then scale the metrics */
277 metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, x_scale );
278 metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, y_scale );
280 metrics->vertBearingX = FT_MulFix( metrics->vertBearingX, x_scale );
281 metrics->vertBearingY = FT_MulFix( metrics->vertBearingY, y_scale );
284 /* compute the other metrics */
285 FT_Outline_Get_CBox( &glyph->root.outline, &cbox );
287 /* grid fit the bounding box if necessary */
292 cbox.xMax = ( cbox.xMax+63 ) & -64;
293 cbox.yMax = ( cbox.yMax+63 ) & -64;
296 metrics->width = cbox.xMax - cbox.xMin;
297 metrics->height = cbox.yMax - cbox.yMin;
299 metrics->horiBearingX = cbox.xMin;
300 metrics->horiBearingY = cbox.yMax;
303 /* Set control data to the glyph charstrings. Note that this is */
304 /* _not_ zero-terminated. */
305 glyph->root.control_data = type1->charstrings [glyph_index];
306 glyph->root.control_len = type1->charstrings_len[glyph_index];