/***************************************************************************/
/* */
/* ttsbit0.c */
/* */
/* TrueType and OpenType embedded bitmap support (body). */
/* This is a heap-optimized version. */
/* */
/* Copyright 2005, 2006, 2007, 2008, 2009 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. */
/* */
/***************************************************************************/
/* This file is included by ttsbit.c */
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_TRUETYPE_TAGS_H
#include "ttsbit.h"
#include "sferrors.h"
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_ttsbit
FT_LOCAL_DEF( FT_Error )
tt_face_load_eblc( TT_Face face,
FT_Stream stream )
{
FT_Error error = SFNT_Err_Ok;
FT_Fixed version;
FT_ULong num_strikes, table_size;
FT_Byte* p;
FT_Byte* p_limit;
FT_UInt count;
face->sbit_num_strikes = 0;
/* this table is optional */
error = face->goto_table( face, TTAG_EBLC, stream, &table_size );
if ( error )
error = face->goto_table( face, TTAG_bloc, stream, &table_size );
if ( error )
goto Exit;
if ( table_size < 8 )
{
FT_ERROR(( "tt_face_load_sbit_strikes: table too short\n" ));
error = SFNT_Err_Invalid_File_Format;
goto Exit;
}
if ( FT_FRAME_EXTRACT( table_size, face->sbit_table ) )
goto Exit;
face->sbit_table_size = table_size;
p = face->sbit_table;
p_limit = p + table_size;
version = FT_NEXT_ULONG( p );
num_strikes = FT_NEXT_ULONG( p );
if ( version != 0x00020000UL || num_strikes >= 0x10000UL )
{
FT_ERROR(( "tt_face_load_sbit_strikes: invalid table version\n" ));
error = SFNT_Err_Invalid_File_Format;
goto Fail;
}
/*
* Count the number of strikes available in the table. We are a bit
* paranoid there and don't trust the data.
*/
count = (FT_UInt)num_strikes;
if ( 8 + 48UL * count > table_size )
count = (FT_UInt)( ( p_limit - p ) / 48 );
face->sbit_num_strikes = count;
FT_TRACE3(( "sbit_num_strikes: %u\n", count ));
Exit:
return error;
Fail:
FT_FRAME_RELEASE( face->sbit_table );
face->sbit_table_size = 0;
goto Exit;
}
FT_LOCAL_DEF( void )
tt_face_free_eblc( TT_Face face )
{
FT_Stream stream = face->root.stream;
FT_FRAME_RELEASE( face->sbit_table );
face->sbit_table_size = 0;
face->sbit_num_strikes = 0;
}
FT_LOCAL_DEF( FT_Error )
tt_face_set_sbit_strike( TT_Face face,
FT_Size_Request req,
FT_ULong* astrike_index )
{
return FT_Match_Size( (FT_Face)face, req, 0, astrike_index );
}
FT_LOCAL_DEF( FT_Error )
tt_face_load_strike_metrics( TT_Face face,
FT_ULong strike_index,
FT_Size_Metrics* metrics )
{
FT_Byte* strike;
if ( strike_index >= (FT_ULong)face->sbit_num_strikes )
return SFNT_Err_Invalid_Argument;
strike = face->sbit_table + 8 + strike_index * 48;
metrics->x_ppem = (FT_UShort)strike[44];
metrics->y_ppem = (FT_UShort)strike[45];
metrics->ascender = (FT_Char)strike[16] << 6; /* hori.ascender */
metrics->descender = (FT_Char)strike[17] << 6; /* hori.descender */
metrics->height = metrics->ascender - metrics->descender;
/* XXX: Is this correct? */
metrics->max_advance = ( (FT_Char)strike[22] + /* min_origin_SB */
strike[18] + /* max_width */
(FT_Char)strike[23] /* min_advance_SB */
) <<