2018-06-03 09:01:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* ftadvanc.c
|
|
|
|
*
|
|
|
|
* Quick computation of advance widths (body).
|
|
|
|
*
|
2022-01-11 10:54:10 +01:00
|
|
|
* Copyright (C) 2008-2022 by
|
2018-06-03 09:01:17 +02:00
|
|
|
* 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-12 18:27:48 +02:00
|
|
|
|
|
|
|
|
2020-06-08 13:31:55 +02:00
|
|
|
#include <freetype/internal/ftdebug.h>
|
2013-03-14 10:27:35 +01:00
|
|
|
|
2020-06-08 13:31:55 +02:00
|
|
|
#include <freetype/ftadvanc.h>
|
|
|
|
#include <freetype/internal/ftobjs.h>
|
2008-09-01 23:35:53 +02:00
|
|
|
|
2008-09-12 18:27:48 +02:00
|
|
|
|
2008-09-01 23:35:53 +02:00
|
|
|
static FT_Error
|
|
|
|
_ft_face_scale_advances( FT_Face face,
|
|
|
|
FT_Fixed* advances,
|
|
|
|
FT_UInt count,
|
2009-01-09 12:11:53 +01:00
|
|
|
FT_Int32 flags )
|
2008-09-01 23:35:53 +02:00
|
|
|
{
|
|
|
|
FT_Fixed scale;
|
|
|
|
FT_UInt nn;
|
|
|
|
|
2008-09-12 18:27:48 +02:00
|
|
|
|
|
|
|
if ( flags & FT_LOAD_NO_SCALE )
|
2008-09-01 23:35:53 +02:00
|
|
|
return FT_Err_Ok;
|
|
|
|
|
2016-12-26 17:08:17 +01:00
|
|
|
if ( !face->size )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_Size_Handle );
|
2008-09-01 23:35:53 +02:00
|
|
|
|
2008-09-12 18:27:48 +02:00
|
|
|
if ( flags & FT_LOAD_VERTICAL_LAYOUT )
|
2008-09-01 23:35:53 +02:00
|
|
|
scale = face->size->metrics.y_scale;
|
2008-09-12 18:27:48 +02:00
|
|
|
else
|
|
|
|
scale = face->size->metrics.x_scale;
|
2008-09-01 23:35:53 +02:00
|
|
|
|
2009-02-24 22:34:51 +01:00
|
|
|
/* this must be the same scaling as to get linear{Hori,Vert}Advance */
|
|
|
|
/* (see `FT_Load_Glyph' implementation in src/base/ftobjs.c) */
|
2008-09-12 18:27:48 +02:00
|
|
|
|
|
|
|
for ( nn = 0; nn < count; nn++ )
|
2008-09-01 23:35:53 +02:00
|
|
|
advances[nn] = FT_MulDiv( advances[nn], scale, 64 );
|
|
|
|
|
2008-09-12 18:27:48 +02:00
|
|
|
return FT_Err_Ok;
|
2008-09-01 23:35:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-12 18:27:48 +02:00
|
|
|
/* at the moment, we can perform fast advance retrieval only in */
|
|
|
|
/* the following cases: */
|
|
|
|
/* */
|
|
|
|
/* - unscaled load */
|
|
|
|
/* - unhinted load */
|
2017-05-02 12:32:19 +02:00
|
|
|
/* - light-hinted load */
|
2016-12-20 10:52:26 +01:00
|
|
|
/* - if a variations font, it must have an `HVAR' or `VVAR' */
|
|
|
|
/* table (thus the old MM or GX fonts don't qualify; this */
|
|
|
|
/* gets checked by the driver-specific functions) */
|
2008-09-12 18:27:48 +02:00
|
|
|
|
2017-05-02 12:32:19 +02:00
|
|
|
#define LOAD_ADVANCE_FAST_CHECK( face, 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
|
|
|
|
|
|
|
|
2008-09-12 18:27:48 +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,
|
2009-01-09 12:11:53 +01:00
|
|
|
FT_Int32 flags,
|
2008-09-01 23:35:53 +02:00
|
|
|
FT_Fixed *padvance )
|
|
|
|
{
|
|
|
|
FT_Face_GetAdvancesFunc func;
|
|
|
|
|
2008-09-12 18:27:48 +02:00
|
|
|
|
2008-09-01 23:35:53 +02:00
|
|
|
if ( !face )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_Face_Handle );
|
2008-09-01 23:35:53 +02:00
|
|
|
|
2014-11-25 10:21:13 +01:00
|
|
|
if ( !padvance )
|
|
|
|
return FT_THROW( Invalid_Argument );
|
|
|
|
|
2008-09-12 18:27:48 +02:00
|
|
|
if ( gindex >= (FT_UInt)face->num_glyphs )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_Glyph_Index );
|
2008-09-01 23:35:53 +02:00
|
|
|
|
|
|
|
func = face->driver->clazz->get_advances;
|
2016-02-05 12:47:29 +01:00
|
|
|
if ( func && LOAD_ADVANCE_FAST_CHECK( face, flags ) )
|
2008-09-01 23:35:53 +02:00
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
|
2008-09-12 18:27:48 +02:00
|
|
|
|
2008-09-01 23:35:53 +02:00
|
|
|
error = func( face, gindex, 1, flags, padvance );
|
2008-09-12 18:27:48 +02:00
|
|
|
if ( !error )
|
2008-09-01 23:35:53 +02:00
|
|
|
return _ft_face_scale_advances( face, padvance, 1, flags );
|
|
|
|
|
2013-03-14 17:50:49 +01:00
|
|
|
if ( FT_ERR_NEQ( error, Unimplemented_Feature ) )
|
2008-09-01 23:35:53 +02:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FT_Get_Advances( face, gindex, 1, flags, padvance );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-12 18:27:48 +02:00
|
|
|
/* 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,
|
2009-01-09 12:11:53 +01:00
|
|
|
FT_Int32 flags,
|
2008-09-01 23:35:53 +02:00
|
|
|
FT_Fixed *padvances )
|
|
|
|
{
|
2017-12-17 08:19:51 +01:00
|
|
|
FT_Error error = FT_Err_Ok;
|
|
|
|
|
2008-09-01 23:35:53 +02:00
|
|
|
FT_Face_GetAdvancesFunc func;
|
2017-12-17 08:19:51 +01:00
|
|
|
|
|
|
|
FT_UInt num, end, nn;
|
|
|
|
FT_Int factor;
|
2008-09-12 18:27:48 +02:00
|
|
|
|
2008-09-01 23:35:53 +02:00
|
|
|
|
|
|
|
if ( !face )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_Face_Handle );
|
2008-09-01 23:35:53 +02:00
|
|
|
|
2014-11-25 10:21:13 +01:00
|
|
|
if ( !padvances )
|
|
|
|
return FT_THROW( Invalid_Argument );
|
|
|
|
|
2008-09-12 18:27:48 +02:00
|
|
|
num = (FT_UInt)face->num_glyphs;
|
2008-09-01 23:35:53 +02:00
|
|
|
end = start + count;
|
2008-09-12 18:27:48 +02:00
|
|
|
if ( start >= num || end < start || end > num )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_Glyph_Index );
|
2008-09-01 23:35:53 +02:00
|
|
|
|
2008-09-12 18:27:48 +02:00
|
|
|
if ( count == 0 )
|
|
|
|
return FT_Err_Ok;
|
2008-09-01 23:35:53 +02:00
|
|
|
|
|
|
|
func = face->driver->clazz->get_advances;
|
2016-02-05 12:47:29 +01:00
|
|
|
if ( func && LOAD_ADVANCE_FAST_CHECK( face, flags ) )
|
2008-09-01 23:35:53 +02:00
|
|
|
{
|
|
|
|
error = func( face, start, count, flags, padvances );
|
2008-09-12 18:27:48 +02:00
|
|
|
if ( !error )
|
2011-12-08 11:55:06 +01:00
|
|
|
return _ft_face_scale_advances( face, padvances, count, flags );
|
2008-09-01 23:35:53 +02:00
|
|
|
|
2013-03-14 17:50:49 +01:00
|
|
|
if ( FT_ERR_NEQ( error, Unimplemented_Feature ) )
|
2008-09-01 23:35:53 +02:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2008-09-12 18:27:48 +02:00
|
|
|
error = FT_Err_Ok;
|
2008-09-01 23:35:53 +02:00
|
|
|
|
2008-09-12 18:27:48 +02:00
|
|
|
if ( flags & FT_ADVANCE_FLAG_FAST_ONLY )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Unimplemented_Feature );
|
2008-09-01 23:35:53 +02:00
|
|
|
|
2009-07-31 17:30:24 +02:00
|
|
|
flags |= (FT_UInt32)FT_LOAD_ADVANCE_ONLY;
|
2017-12-17 08:19:51 +01:00
|
|
|
factor = ( flags & FT_LOAD_NO_SCALE ) ? 1 : 1024;
|
2008-09-12 18:27:48 +02:00
|
|
|
for ( nn = 0; nn < count; nn++ )
|
2008-09-01 23:35:53 +02:00
|
|
|
{
|
2008-09-12 18:27:48 +02:00
|
|
|
error = FT_Load_Glyph( face, start + nn, flags );
|
|
|
|
if ( error )
|
|
|
|
break;
|
2008-09-01 23:35:53 +02:00
|
|
|
|
2017-12-17 08:19:51 +01:00
|
|
|
/* scale from 26.6 to 16.16, unless NO_SCALE was requested */
|
2008-09-12 18:27:48 +02:00
|
|
|
padvances[nn] = ( flags & FT_LOAD_VERTICAL_LAYOUT )
|
2017-12-17 08:19:51 +01:00
|
|
|
? face->glyph->advance.y * factor
|
|
|
|
: face->glyph->advance.x * factor;
|
2008-09-01 23:35:53 +02:00
|
|
|
}
|
2008-09-12 18:27:48 +02:00
|
|
|
|
2011-12-08 11:55:06 +01:00
|
|
|
return error;
|
2008-09-01 23:35:53 +02:00
|
|
|
}
|
2008-09-12 18:27:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* END */
|