1 /***************************************************************************/
5 /* Quick computation of advance widths (body). */
7 /* Copyright 2008, 2009 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 /***************************************************************************/
20 #include FT_ADVANCES_H
21 #include FT_INTERNAL_OBJECTS_H
25 _ft_face_scale_advances( FT_Face face
,
34 if ( flags
& FT_LOAD_NO_SCALE
)
37 if ( face
->size
== NULL
)
38 return FT_Err_Invalid_Size_Handle
;
40 if ( flags
& FT_LOAD_VERTICAL_LAYOUT
)
41 scale
= face
->size
->metrics
.y_scale
;
43 scale
= face
->size
->metrics
.x_scale
;
45 /* this must be the same scaling as to get linear{Hori,Vert}Advance */
46 /* (see `FT_Load_Glyph' implementation in src/base/ftobjs.c) */
48 for ( nn
= 0; nn
< count
; nn
++ )
49 advances
[nn
] = FT_MulDiv( advances
[nn
], scale
, 64 );
55 /* at the moment, we can perform fast advance retrieval only in */
56 /* the following cases: */
60 /* - light-hinted load */
62 #define LOAD_ADVANCE_FAST_CHECK( flags ) \
63 ( flags & ( FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING ) || \
64 FT_LOAD_TARGET_MODE( flags ) == FT_RENDER_MODE_LIGHT )
67 /* documentation is in ftadvanc.h */
69 FT_EXPORT_DEF( FT_Error
)
70 FT_Get_Advance( FT_Face face
,
75 FT_Face_GetAdvancesFunc func
;
79 return FT_Err_Invalid_Face_Handle
;
81 if ( gindex
>= (FT_UInt
)face
->num_glyphs
)
82 return FT_Err_Invalid_Glyph_Index
;
84 func
= face
->driver
->clazz
->get_advances
;
85 if ( func
&& LOAD_ADVANCE_FAST_CHECK( flags
) )
90 error
= func( face
, gindex
, 1, flags
, padvance
);
92 return _ft_face_scale_advances( face
, padvance
, 1, flags
);
94 if ( error
!= FT_ERROR_BASE( FT_Err_Unimplemented_Feature
) )
98 return FT_Get_Advances( face
, gindex
, 1, flags
, padvance
);
102 /* documentation is in ftadvanc.h */
104 FT_EXPORT_DEF( FT_Error
)
105 FT_Get_Advances( FT_Face face
,
109 FT_Fixed
*padvances
)
111 FT_Face_GetAdvancesFunc func
;
112 FT_UInt num
, end
, nn
;
113 FT_Error error
= FT_Err_Ok
;
117 return FT_Err_Invalid_Face_Handle
;
119 num
= (FT_UInt
)face
->num_glyphs
;
121 if ( start
>= num
|| end
< start
|| end
> num
)
122 return FT_Err_Invalid_Glyph_Index
;
127 func
= face
->driver
->clazz
->get_advances
;
128 if ( func
&& LOAD_ADVANCE_FAST_CHECK( flags
) )
130 error
= func( face
, start
, count
, flags
, padvances
);
134 if ( error
!= FT_ERROR_BASE( FT_Err_Unimplemented_Feature
) )
140 if ( flags
& FT_ADVANCE_FLAG_FAST_ONLY
)
141 return FT_Err_Unimplemented_Feature
;
143 flags
|= (FT_UInt32
)FT_LOAD_ADVANCE_ONLY
;
144 for ( nn
= 0; nn
< count
; nn
++ )
146 error
= FT_Load_Glyph( face
, start
+ nn
, flags
);
150 padvances
[nn
] = ( flags
& FT_LOAD_VERTICAL_LAYOUT
)
151 ? face
->glyph
->advance
.y
152 : face
->glyph
->advance
.x
;
159 return _ft_face_scale_advances( face
, padvances
, count
, flags
);