Al-Qurtas-Islamic-bank-The-.../src/base/ftadvanc.c

164 lines
5.0 KiB
C
Raw Normal View History

/***************************************************************************/
/* */
/* ftadvanc.c */
/* */
/* Quick computation of advance widths (body). */
/* */
/* Copyright 2008 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. */
/* */
/***************************************************************************/
2008-09-01 23:35:53 +02:00
#include <ft2build.h>
#include FT_ADVANCES_H
#include FT_INTERNAL_OBJECTS_H
2008-09-01 23:35:53 +02:00
static FT_Error
_ft_face_scale_advances( FT_Face face,
FT_Fixed* advances,
FT_UInt count,
FT_UInt flags )
{
FT_Fixed scale;
FT_UInt nn;
if ( flags & FT_LOAD_NO_SCALE )
2008-09-01 23:35:53 +02:00
return FT_Err_Ok;
if ( face->size == NULL )
return FT_Err_Invalid_Size_Handle;
if ( flags & FT_LOAD_VERTICAL_LAYOUT )
2008-09-01 23:35:53 +02:00
scale = face->size->metrics.y_scale;
else
scale = face->size->metrics.x_scale;
2008-09-01 23:35:53 +02:00
/* this must be the same computation as to get linearHori/VertAdvance */
/* (see `FT_Load_Glyph' implementation in src/base/ftobjs.c */
for ( nn = 0; nn < count; nn++ )
2008-09-01 23:35:53 +02:00
advances[nn] = FT_MulDiv( advances[nn], scale, 64 );
return FT_Err_Ok;
2008-09-01 23:35:53 +02:00
}
/* at the moment, we can perform fast advance retrieval only in */
/* the following cases: */
/* */
/* - unscaled load */
/* - unhinted load */
/* - light-hinted load */
#define LOAD_ADVANCE_FAST_CHECK( flags ) \
( flags & ( FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING ) || \
FT_LOAD_TARGET_MODE( flags ) == FT_RENDER_MODE_LIGHT )
2008-09-01 23:35:53 +02:00
/* documentation is in ftadvanc.h */
FT_EXPORT_DEF( FT_Error )
2008-09-01 23:35:53 +02:00
FT_Get_Advance( FT_Face face,
FT_UInt gindex,
FT_UInt flags,
FT_Fixed *padvance )
{
FT_Face_GetAdvancesFunc func;
2008-09-01 23:35:53 +02:00
if ( !face )
return FT_Err_Invalid_Face_Handle;
if ( gindex >= (FT_UInt)face->num_glyphs )
2008-09-01 23:35:53 +02:00
return FT_Err_Invalid_Glyph_Index;
func = face->driver->clazz->get_advances;
if ( func && LOAD_ADVANCE_FAST_CHECK( flags ) )
2008-09-01 23:35:53 +02:00
{
FT_Error error;
2008-09-01 23:35:53 +02:00
error = func( face, gindex, 1, flags, padvance );
if ( !error )
2008-09-01 23:35:53 +02:00
return _ft_face_scale_advances( face, padvance, 1, flags );
if ( error != FT_Err_Unimplemented_Feature )
2008-09-01 23:35:53 +02:00
return error;
}
return FT_Get_Advances( face, gindex, 1, flags, padvance );
}
/* documentation is in ftadvanc.h */
FT_EXPORT_DEF( FT_Error )
2008-09-01 23:35:53 +02:00
FT_Get_Advances( FT_Face face,
FT_UInt start,
FT_UInt count,
FT_UInt flags,
FT_Fixed *padvances )
{
FT_Face_GetAdvancesFunc func;
FT_UInt num, end, nn;
FT_Error error = FT_Err_Ok;
2008-09-01 23:35:53 +02:00
if ( !face )
return FT_Err_Invalid_Face_Handle;
num = (FT_UInt)face->num_glyphs;
2008-09-01 23:35:53 +02:00
end = start + count;
if ( start >= num || end < start || end > num )
2008-09-01 23:35:53 +02:00
return FT_Err_Invalid_Glyph_Index;
if ( count == 0 )
return FT_Err_Ok;
2008-09-01 23:35:53 +02:00
func = face->driver->clazz->get_advances;
if ( func && LOAD_ADVANCE_FAST_CHECK( flags ) )
2008-09-01 23:35:53 +02:00
{
error = func( face, start, count, flags, padvances );
if ( !error )
goto Exit;
2008-09-01 23:35:53 +02:00
if ( error != FT_Err_Unimplemented_Feature )
2008-09-01 23:35:53 +02:00
return error;
}
error = FT_Err_Ok;
2008-09-01 23:35:53 +02:00
if ( flags & FT_ADVANCE_FLAG_FAST_ONLY )
2008-09-01 23:35:53 +02:00
return FT_Err_Unimplemented_Feature;
flags |= FT_LOAD_ADVANCE_ONLY;
for ( nn = 0; nn < count; nn++ )
2008-09-01 23:35:53 +02:00
{
error = FT_Load_Glyph( face, start + nn, flags );
if ( error )
break;
2008-09-01 23:35:53 +02:00
padvances[nn] = ( flags & FT_LOAD_VERTICAL_LAYOUT )
? face->glyph->advance.x
: face->glyph->advance.y;
2008-09-01 23:35:53 +02:00
}
if ( error )
return error;
2008-09-01 23:35:53 +02:00
Exit:
return _ft_face_scale_advances( face, padvances, count, flags );
}
/* END */