298 lines
8.5 KiB
C
298 lines
8.5 KiB
C
/***************************************************************************/
|
||
/* */
|
||
/* ftcsbits.c */
|
||
/* */
|
||
/* FreeType sbits manager (body). */
|
||
/* */
|
||
/* Copyright 2000-2001, 2002, 2003 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. */
|
||
/* */
|
||
/***************************************************************************/
|
||
|
||
|
||
#include <ft2build.h>
|
||
#include FT_CACHE_H
|
||
#include FT_CACHE_INTERNAL_SBITS_H
|
||
#include FT_INTERNAL_OBJECTS_H
|
||
#include FT_INTERNAL_DEBUG_H
|
||
#include FT_ERRORS_H
|
||
|
||
#include "ftcerror.h"
|
||
|
||
|
||
/*************************************************************************/
|
||
/*************************************************************************/
|
||
/***** *****/
|
||
/***** SBIT CACHE NODES *****/
|
||
/***** *****/
|
||
/*************************************************************************/
|
||
/*************************************************************************/
|
||
|
||
|
||
static FT_Error
|
||
ftc_sbit_copy_bitmap( FTC_SBit sbit,
|
||
FT_Bitmap* bitmap,
|
||
FT_Memory memory )
|
||
{
|
||
FT_Error error;
|
||
FT_Int pitch = bitmap->pitch;
|
||
FT_ULong size;
|
||
|
||
|
||
if ( pitch < 0 )
|
||
pitch = -pitch;
|
||
|
||
size = (FT_ULong)( pitch * bitmap->rows );
|
||
|
||
if ( !FT_ALLOC( sbit->buffer, size ) )
|
||
FT_MEM_COPY( sbit->buffer, bitmap->buffer, size );
|
||
|
||
return error;
|
||
}
|
||
|
||
|
||
FT_EXPORT_DEF( void )
|
||
FTC_SNode_Free( FTC_SNode snode,
|
||
FTC_Cache cache )
|
||
{
|
||
FTC_SBit sbit = snode->sbits;
|
||
FT_UInt count = snode->count;
|
||
FT_Memory memory = cache->memory;
|
||
|
||
|
||
for ( ; count > 0; sbit++, count-- )
|
||
FT_FREE( sbit->buffer );
|
||
|
||
FTC_GNode_Done( FTC_GNODE( snode ), cache );
|
||
|
||
FT_FREE( snode );
|
||
}
|
||
|
||
|
||
static FT_Error
|
||
ftc_snode_load( FTC_SNode snode,
|
||
FTC_Manager manager,
|
||
FT_UInt gindex,
|
||
FT_ULong *asize )
|
||
{
|
||
FT_Error error;
|
||
FTC_GNode gnode = FTC_GNODE( snode );
|
||
FTC_Family family = gnode->family;
|
||
FT_Memory memory = manager->memory;
|
||
FT_Face face;
|
||
FTC_SBit sbit;
|
||
FTC_SFamilyClass clazz;
|
||
|
||
|
||
if ( (FT_UInt)(gindex - gnode->gindex) >= snode->count )
|
||
{
|
||
FT_ERROR(( "ftc_snode_load: invalid glyph index" ));
|
||
return FTC_Err_Invalid_Argument;
|
||
}
|
||
|
||
sbit = snode->sbits + ( gindex - gnode->gindex );
|
||
clazz = (FTC_SFamilyClass)family->clazz;
|
||
|
||
sbit->buffer = 0;
|
||
|
||
error = clazz->family_load_glyph( family, gindex, manager, &face );
|
||
if ( error )
|
||
goto BadGlyph;
|
||
|
||
{
|
||
FT_Int temp;
|
||
FT_GlyphSlot slot = face->glyph;
|
||
FT_Bitmap* bitmap = &slot->bitmap;
|
||
FT_Int xadvance, yadvance;
|
||
|
||
|
||
if ( slot->format != FT_GLYPH_FORMAT_BITMAP )
|
||
{
|
||
FT_ERROR(( "%s: glyph loaded didn't return a bitmap!\n",
|
||
"ftc_snode_load" ));
|
||
goto BadGlyph;
|
||
}
|
||
|
||
/* |