2000-10-31 23:13:54 +01:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ftcsbits.c */
|
|
|
|
/* */
|
|
|
|
/* FreeType sbits manager (body). */
|
|
|
|
/* */
|
2002-03-30 17:41:09 +01:00
|
|
|
/* Copyright 2000-2001, 2002 by */
|
2000-10-31 23:13:54 +01: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. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_CACHE_H
|
|
|
|
#include FT_CACHE_SMALL_BITMAPS_H
|
2001-12-05 16:59:33 +01:00
|
|
|
#include FT_CACHE_INTERNAL_GLYPH_H
|
2000-12-08 17:17:16 +01:00
|
|
|
#include FT_INTERNAL_OBJECTS_H
|
|
|
|
#include FT_INTERNAL_DEBUG_H
|
|
|
|
#include FT_ERRORS_H
|
2000-10-29 01:34:45 +02:00
|
|
|
|
Complete redesign of error codes. Please check ftmoderr.h for more
details.
* include/freetype/internal/cfferrs.h,
include/freetype/internal/tterrors.h,
include/freetype/internal/t1errors.h: Removed. Replaced with files
local to the module. All extra error codes have been moved to
`fterrors.h'.
* src/sfnt/ttpost.h: Move error codes to `fterrors.h'.
* src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h,
src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h,
src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h,
src/smooth/ftsmerrs.h, src/truetype/tterrors.h,
src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the
error names for the module it belongs to.
* include/freetype/ftmoderr.h: New file, defining the module error
offsets. Its structure is similar to `fterrors.h'.
* include/freetype/fterrors.h (FT_NOERRORDEF): New macro.
(FT_ERRORDEF): Redefined to use module error offsets.
All internal error codes are now public; unused error codes have
been removed, some are new.
* include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New
macro.
* include/freetype/config/ftoption.h
(FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro.
All other source files have been updated to use the new error codes;
some already existing (internal) error codes local to a module have
been renamed to give them the same name as in the base module.
All make files have been updated to include the local error files.
* src/cid/cidtokens.h: Replaced with...
* src/cid/cidtoken.h: This file for 8+3 consistency.
* src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
|
|
|
#include "ftcerror.h"
|
|
|
|
|
2000-10-31 23:13:54 +01:00
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
#define FTC_SBIT_ITEMS_PER_NODE 16
|
2000-10-29 01:34:45 +02:00
|
|
|
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
typedef struct FTC_SBitNodeRec_* FTC_SBitNode;
|
2001-10-26 18:58:27 +02:00
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
typedef struct FTC_SBitNodeRec_
|
2000-10-29 01:34:45 +02:00
|
|
|
{
|
2001-12-20 18:49:10 +01:00
|
|
|
FTC_GlyphNodeRec gnode;
|
|
|
|
FTC_SBitRec sbits[FTC_SBIT_ITEMS_PER_NODE];
|
2000-10-29 01:34:45 +02:00
|
|
|
|
2001-12-05 16:59:33 +01:00
|
|
|
} FTC_SBitNodeRec;
|
2000-10-29 01:34:45 +02:00
|
|
|
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
#define FTC_SBIT_NODE( x ) ( (FTC_SBitNode)( x ) )
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-10-29 01:34:45 +02:00
|
|
|
|
2001-12-05 02:22:05 +01:00
|
|
|
typedef struct FTC_SBitQueryRec_
|
2001-10-26 18:58:27 +02:00
|
|
|
{
|
2001-12-05 16:59:33 +01:00
|
|
|
FTC_GlyphQueryRec gquery;
|
|
|
|
FTC_ImageDesc desc;
|
2001-10-26 18:58:27 +02:00
|
|
|
|
|
|
|
} FTC_SBitQueryRec, *FTC_SBitQuery;
|
2000-10-29 01:34:45 +02:00
|
|
|
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
#define FTC_SBIT_QUERY( x ) ( (FTC_SBitQuery)( x ) )
|
2000-10-28 15:17:11 +02:00
|
|
|
|
|
|
|
|
2001-12-05 16:59:33 +01:00
|
|
|
typedef struct FTC_SBitFamilyRec_* FTC_SBitFamily;
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
/* sbit family structure */
|
2001-12-05 16:59:33 +01:00
|
|
|
typedef struct FTC_SBitFamilyRec_
|
2000-10-28 15:17:11 +02:00
|
|
|
{
|
2001-12-05 16:59:33 +01:00
|
|
|
FTC_GlyphFamilyRec gfam;
|
|
|
|
FTC_ImageDesc desc;
|
2000-10-31 23:13:54 +01:00
|
|
|
|
2001-12-05 16:59:33 +01:00
|
|
|
} FTC_SBitFamilyRec;
|
2002-06-07 22:07:44 +02:00
|
|
|
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
#define FTC_SBIT_FAMILY( x ) ( (FTC_SBitFamily)( x ) )
|
|
|
|
#define FTC_SBIT_FAMILY_MEMORY( x ) FTC_GLYPH_FAMILY_MEMORY( &( x )->cset )
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2001-12-05 16:59:33 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** SBIT CACHE NODES *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
2000-10-28 15:17:11 +02:00
|
|
|
|
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
static FT_Error
|
2001-12-05 16:59:33 +01:00
|
|
|
ftc_sbit_copy_bitmap( FTC_SBit sbit,
|
|
|
|
FT_Bitmap* bitmap,
|
|
|
|
FT_Memory memory )
|
2000-10-28 15:17:11 +02:00
|
|
|
{
|
|
|
|
FT_Error error;
|
2001-10-26 18:58:27 +02:00
|
|
|
FT_Int pitch = bitmap->pitch;
|
2000-10-28 15:17:11 +02:00
|
|
|
FT_ULong size;
|
|
|
|
|
2000-10-31 23:13:54 +01:00
|
|
|
|
2000-10-28 15:17:11 +02:00
|
|
|
if ( pitch < 0 )
|
|
|
|
pitch = -pitch;
|
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
size = (FT_ULong)( pitch * bitmap->rows );
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
if ( !FT_ALLOC( sbit->buffer, size ) )
|
|
|
|
FT_MEM_COPY( sbit->buffer, bitmap->buffer, size );
|
2000-10-28 15:17:11 +02:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-05 16:59:33 +01:00
|
|
|
FT_CALLBACK_DEF( void )
|
|
|
|
ftc_sbit_node_done( FTC_SBitNode snode,
|
|
|
|
FTC_Cache cache )
|
|
|
|
{
|
|
|
|
FTC_SBit sbit = snode->sbits;
|
2001-12-20 18:49:10 +01:00
|
|
|
FT_UInt count = FTC_GLYPH_NODE( snode )->item_count;
|
2001-12-05 16:59:33 +01:00
|
|
|
FT_Memory memory = cache->memory;
|
|
|
|
|
|
|
|
|
|
|
|
for ( ; count > 0; sbit++, count-- )
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( sbit->buffer );
|
2001-12-05 16:59:33 +01:00
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
ftc_glyph_node_done( FTC_GLYPH_NODE( snode ), cache );
|
2001-12-05 16:59:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
static FT_Error
|
2001-12-20 18:49:10 +01:00
|
|
|
ftc_sbit_node_load( FTC_SBitNode snode,
|
|
|
|
FTC_Manager manager,
|
|
|
|
FTC_SBitFamily sfam,
|
|
|
|
FT_UInt gindex,
|
|
|
|
FT_ULong *asize )
|
2000-10-28 15:17:11 +02:00
|
|
|
{
|
2001-12-20 18:49:10 +01:00
|
|
|
FT_Error error;
|
|
|
|
FTC_GlyphNode gnode = FTC_GLYPH_NODE( snode );
|
|
|
|
FT_Memory memory;
|
|
|
|
FT_Face face;
|
|
|
|
FT_Size size;
|
|
|
|
FTC_SBit sbit;
|
|
|
|
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2001-12-05 16:59:33 +01:00
|
|
|
if ( gindex < (FT_UInt)gnode->item_start ||
|
|
|
|
gindex >= (FT_UInt)gnode->item_start + gnode->item_count )
|
2001-10-26 18:58:27 +02:00
|
|
|
{
|
2001-12-20 18:49:10 +01:00
|
|
|
FT_ERROR(( "ftc_sbit_node_load: invalid glyph index" ));
|
2001-10-26 18:58:27 +02:00
|
|
|
return FTC_Err_Invalid_Argument;
|
|
|
|
}
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2001-12-05 16:59:33 +01:00
|
|
|
memory = manager->library->memory;
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
sbit = snode->sbits + ( gindex - gnode->item_start );
|
2001-12-05 16:59:33 +01:00
|
|
|
|
|
|
|
error = FTC_Manager_Lookup_Size( manager, &sfam->desc.font,
|
2000-10-28 15:17:11 +02:00
|
|
|
&face, &size );
|
|
|
|
if ( !error )
|
|
|
|
{
|
2001-12-20 18:49:10 +01:00
|
|
|
FT_UInt load_flags = FT_LOAD_DEFAULT;
|
|
|
|
FT_UInt type = sfam->desc.type;
|
2000-10-31 23:13:54 +01:00
|
|
|
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2000-10-29 01:34:45 +02:00
|
|
|
/* determine load flags, depending on the font description's */
|
2000-10-31 23:13:54 +01:00
|
|
|
/* image type */
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2001-12-05 16:59:33 +01:00
|
|
|
if ( FTC_IMAGE_FORMAT( type ) == ftc_image_format_bitmap )
|
2000-10-31 23:13:54 +01:00
|
|
|
{
|
2001-12-05 16:59:33 +01:00
|
|
|
if ( type & ftc_image_flag_monochrome )
|
2000-10-31 23:13:54 +01:00
|
|
|
load_flags |= FT_LOAD_MONOCHROME;
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2000-10-31 23:13:54 +01:00
|
|
|
/* disable embedded bitmaps loading if necessary */
|
2001-12-05 16:59:33 +01:00
|
|
|
if ( type & ftc_image_flag_no_sbits )
|
2000-10-31 23:13:54 +01:00
|
|
|
load_flags |= FT_LOAD_NO_BITMAP;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-12-05 02:22:05 +01:00
|
|
|
FT_ERROR((
|
2001-12-20 18:49:10 +01:00
|
|
|
"ftc_sbit_node_load: cannot load scalable glyphs in an"
|
2001-12-05 02:22:05 +01:00
|
|
|
" sbit cache, please check your arguments!\n" ));
|
Complete redesign of error codes. Please check ftmoderr.h for more
details.
* include/freetype/internal/cfferrs.h,
include/freetype/internal/tterrors.h,
include/freetype/internal/t1errors.h: Removed. Replaced with files
local to the module. All extra error codes have been moved to
`fterrors.h'.
* src/sfnt/ttpost.h: Move error codes to `fterrors.h'.
* src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h,
src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h,
src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h,
src/smooth/ftsmerrs.h, src/truetype/tterrors.h,
src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the
error names for the module it belongs to.
* include/freetype/ftmoderr.h: New file, defining the module error
offsets. Its structure is similar to `fterrors.h'.
* include/freetype/fterrors.h (FT_NOERRORDEF): New macro.
(FT_ERRORDEF): Redefined to use module error offsets.
All internal error codes are now public; unused error codes have
been removed, some are new.
* include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New
macro.
* include/freetype/config/ftoption.h
(FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro.
All other source files have been updated to use the new error codes;
some already existing (internal) error codes local to a module have
been renamed to give them the same name as in the base module.
All make files have been updated to include the local error files.
* src/cid/cidtokens.h: Replaced with...
* src/cid/cidtoken.h: This file for 8+3 consistency.
* src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
|
|
|
error = FTC_Err_Invalid_Argument;
|
2000-10-31 23:13:54 +01:00
|
|
|
goto Exit;
|
|
|
|
}
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-10-31 23:13:54 +01:00
|
|
|
/* always render glyphs to bitmaps */
|
|
|
|
load_flags |= FT_LOAD_RENDER;
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2001-12-05 16:59:33 +01:00
|
|
|
if ( type & ftc_image_flag_unhinted )
|
2000-10-31 23:13:54 +01:00
|
|
|
load_flags |= FT_LOAD_NO_HINTING;
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2001-12-05 16:59:33 +01:00
|
|
|
if ( type & ftc_image_flag_autohinted )
|
2000-10-31 23:13:54 +01:00
|
|
|
load_flags |= FT_LOAD_FORCE_AUTOHINT;
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
/* by default, indicates a `missing' glyph */
|
|
|
|
sbit->buffer = 0;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
error = FT_Load_Glyph( face, gindex, load_flags );
|
|
|
|
if ( !error )
|
|
|
|
{
|
|
|
|
FT_Int temp;
|
|
|
|
FT_GlyphSlot slot = face->glyph;
|
|
|
|
FT_Bitmap* bitmap = &slot->bitmap;
|
|
|
|
FT_Int xadvance, yadvance;
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
/* check that our values fit into 8-bit containers! */
|
|
|
|
/* If this is not the case, our bitmap is too large */
|
|
|
|
/* and we will leave it as `missing' with sbit.buffer = 0 */
|
2000-10-31 23:13:54 +01:00
|
|
|
|
|
|
|
#define CHECK_CHAR( d ) ( temp = (FT_Char)d, temp == d )
|
|
|
|
#define CHECK_BYTE( d ) ( temp = (FT_Byte)d, temp == d )
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
/* XXX: FIXME: add support for vertical layouts maybe */
|
2000-10-29 01:34:45 +02:00
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
/* horizontal advance in pixels */
|
|
|
|
xadvance = ( slot->metrics.horiAdvance + 32 ) >> 6;
|
|
|
|
yadvance = ( slot->metrics.vertAdvance + 32 ) >> 6;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
if ( CHECK_BYTE( bitmap->rows ) &&
|
|
|
|
CHECK_BYTE( bitmap->width ) &&
|
|
|
|
CHECK_CHAR( bitmap->pitch ) &&
|
|
|
|
CHECK_CHAR( slot->bitmap_left ) &&
|
|
|
|
CHECK_CHAR( slot->bitmap_top ) &&
|
|
|
|
CHECK_CHAR( xadvance ) &&
|
|
|
|
CHECK_CHAR( yadvance ) )
|
|
|
|
{
|
2002-05-21 16:13:01 +02:00
|
|
|
sbit->width = (FT_Byte)bitmap->width;
|
|
|
|
sbit->height = (FT_Byte)bitmap->rows;
|
|
|
|
sbit->pitch = (FT_Char)bitmap->pitch;
|
|
|
|
sbit->left = (FT_Char)slot->bitmap_left;
|
|
|
|
sbit->top = (FT_Char)slot->bitmap_top;
|
|
|
|
sbit->xadvance = (FT_Char)xadvance;
|
|
|
|
sbit->yadvance = (FT_Char)yadvance;
|
|
|
|
sbit->format = (FT_Byte)bitmap->pixel_mode;
|
|
|
|
/* XXX: Fixme: We don't handle the number of gray levels */
|
|
|
|
/* consistently -- we say num_grays == 1 for */
|
|
|
|
/* monochrome but num_grays == 256 for gray. It */
|
|
|
|
/* would be better to make this variable hold the */
|
|
|
|
/* highest possible value so that it fits into */
|
|
|
|
/* a single byte. */
|
|
|
|
sbit->num_grays = bitmap->num_grays;
|
|
|
|
|
|
|
|
/* grab the bitmap when possible - this is a hack! */
|
2002-02-24 03:39:08 +01:00
|
|
|
if ( slot->flags & FT_GLYPH_OWN_BITMAP )
|
2000-10-28 15:17:11 +02:00
|
|
|
{
|
2002-02-24 03:39:08 +01:00
|
|
|
slot->flags &= ~FT_GLYPH_OWN_BITMAP;
|
2001-10-26 18:58:27 +02:00
|
|
|
sbit->buffer = bitmap->buffer;
|
2000-10-28 15:17:11 +02:00
|
|
|
}
|
2001-10-26 18:58:27 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* copy the bitmap into a new buffer -- ignore error */
|
2001-12-05 16:59:33 +01:00
|
|
|
error = ftc_sbit_copy_bitmap( sbit, bitmap, memory );
|
2001-10-26 18:58:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* now, compute size */
|
|
|
|
if ( asize )
|
2001-12-20 18:49:10 +01:00
|
|
|
*asize = ABS( sbit->pitch ) * sbit->height;
|
2001-12-05 16:59:33 +01:00
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
} /* glyph dimensions ok */
|
|
|
|
|
|
|
|
} /* glyph loading successful */
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
/* ignore the errors that might have occurred -- */
|
|
|
|
/* we mark unloaded glyphs with `sbit.buffer == 0' */
|
|
|
|
/* and 'width == 255', 'height == 0' */
|
|
|
|
/* */
|
2001-10-26 18:58:27 +02:00
|
|
|
if ( error )
|
|
|
|
{
|
2001-12-05 02:22:05 +01:00
|
|
|
sbit->width = 255;
|
|
|
|
error = 0;
|
|
|
|
/* sbit->buffer == NULL too! */
|
2001-10-26 18:58:27 +02:00
|
|
|
}
|
2000-10-28 15:17:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
2001-10-26 18:58:27 +02:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_CALLBACK_DEF( FT_Error )
|
2001-12-05 16:59:33 +01:00
|
|
|
ftc_sbit_node_init( FTC_SBitNode snode,
|
|
|
|
FTC_GlyphQuery gquery,
|
|
|
|
FTC_Cache cache )
|
2001-10-26 18:58:27 +02:00
|
|
|
{
|
2001-12-05 02:22:05 +01:00
|
|
|
FT_Error error;
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
|
|
|
|
ftc_glyph_node_init( FTC_GLYPH_NODE( snode ),
|
2001-12-05 16:59:33 +01:00
|
|
|
gquery->gindex,
|
2001-12-20 18:49:10 +01:00
|
|
|
FTC_GLYPH_FAMILY( gquery->query.family ) );
|
2001-10-26 18:58:27 +02:00
|
|
|
|
2001-12-07 15:43:45 +01:00
|
|
|
error = ftc_sbit_node_load( snode,
|
|
|
|
cache->manager,
|
2001-12-20 18:49:10 +01:00
|
|
|
FTC_SBIT_FAMILY( FTC_QUERY( gquery )->family ),
|
2001-12-07 15:43:45 +01:00
|
|
|
gquery->gindex,
|
|
|
|
NULL );
|
2001-12-05 16:59:33 +01:00
|
|
|
if ( error )
|
2001-12-20 18:49:10 +01:00
|
|
|
ftc_glyph_node_done( FTC_GLYPH_NODE( snode ), cache );
|
2000-10-31 23:13:54 +01:00
|
|
|
|
2000-10-28 15:17:11 +02:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_CALLBACK_DEF( FT_ULong )
|
2001-12-05 16:59:33 +01:00
|
|
|
ftc_sbit_node_weight( FTC_SBitNode snode )
|
2000-10-28 15:17:11 +02:00
|
|
|
{
|
2001-12-20 18:49:10 +01:00
|
|
|
FTC_GlyphNode gnode = FTC_GLYPH_NODE( snode );
|
2001-12-05 16:59:33 +01:00
|
|
|
FT_UInt count = gnode->item_count;
|
|
|
|
FTC_SBit sbit = snode->sbits;
|
|
|
|
FT_Int pitch;
|
|
|
|
FT_ULong size;
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2000-10-31 23:13:54 +01:00
|
|
|
|
|
|
|
/* the node itself */
|
2001-12-20 18:49:10 +01:00
|
|
|
size = sizeof ( *snode );
|
2001-06-28 19:49:10 +02:00
|
|
|
|
2000-10-31 23:13:54 +01:00
|
|
|
/* the sbit records */
|
2001-12-20 18:49:10 +01:00
|
|
|
size += FTC_GLYPH_NODE( snode )->item_count * sizeof ( FTC_SBitRec );
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2000-10-29 01:34:45 +02:00
|
|
|
for ( ; count > 0; count--, sbit++ )
|
2000-10-28 15:17:11 +02:00
|
|
|
{
|
2000-10-31 23:13:54 +01:00
|
|
|
if ( sbit->buffer )
|
2000-10-28 15:17:11 +02:00
|
|
|
{
|
2000-10-29 01:34:45 +02:00
|
|
|
pitch = sbit->pitch;
|
2000-10-31 23:13:54 +01:00
|
|
|
if ( pitch < 0 )
|
2000-10-29 01:34:45 +02:00
|
|
|
pitch = -pitch;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-10-29 01:34:45 +02:00
|
|
|
/* add the size of a given glyph image */
|
|
|
|
size += pitch * sbit->height;
|
2000-10-28 15:17:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
FT_CALLBACK_DEF( FT_Bool )
|
2001-12-05 16:59:33 +01:00
|
|
|
ftc_sbit_node_compare( FTC_SBitNode snode,
|
|
|
|
FTC_SBitQuery squery,
|
2001-10-26 18:58:27 +02:00
|
|
|
FTC_Cache cache )
|
|
|
|
{
|
2001-12-20 18:49:10 +01:00
|
|
|
FTC_GlyphQuery gquery = FTC_GLYPH_QUERY( squery );
|
|
|
|
FTC_GlyphNode gnode = FTC_GLYPH_NODE( snode );
|
2001-10-26 18:58:27 +02:00
|
|
|
FT_Bool result;
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
|
2001-12-05 16:59:33 +01:00
|
|
|
result = ftc_glyph_node_compare( gnode, gquery );
|
2001-10-26 18:58:27 +02:00
|
|
|
if ( result )
|
|
|
|
{
|
|
|
|
/* check if we need to load the glyph bitmap now */
|
2001-12-05 16:59:33 +01:00
|
|
|
FT_UInt gindex = gquery->gindex;
|
2001-12-20 18:49:10 +01:00
|
|
|
FTC_SBit sbit = snode->sbits + ( gindex - gnode->item_start );
|
|
|
|
|
2001-12-05 02:22:05 +01:00
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
if ( sbit->buffer == NULL && sbit->width != 255 )
|
|
|
|
{
|
|
|
|
FT_ULong size;
|
2001-12-05 02:22:05 +01:00
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
|
2001-12-07 15:43:45 +01:00
|
|
|
/* yes, it's safe to ignore errors here */
|
|
|
|
ftc_sbit_node_load( snode,
|
|
|
|
cache->manager,
|
2001-12-20 18:49:10 +01:00
|
|
|
FTC_SBIT_FAMILY( FTC_QUERY( squery )->family ),
|
2001-12-07 15:43:45 +01:00
|
|
|
gindex,
|
|
|
|
&size );
|
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
cache->manager->cur_weight += size;
|
|
|
|
}
|
|
|
|
}
|
2001-12-05 02:22:05 +01:00
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-28 15:17:11 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
2001-12-05 16:59:33 +01:00
|
|
|
/***** SBITS FAMILIES *****/
|
2000-10-28 15:17:11 +02:00
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_CALLBACK_DEF( FT_Error )
|
2001-12-05 16:59:33 +01:00
|
|
|
ftc_sbit_family_init( FTC_SBitFamily sfam,
|
|
|
|
FTC_SBitQuery squery,
|
|
|
|
FTC_Cache cache )
|
2000-10-28 15:17:11 +02:00
|
|
|
{
|
2001-12-05 16:59:33 +01:00
|
|
|
FTC_Manager manager = cache->manager;
|
|
|
|
FT_Error error;
|
|
|
|
FT_Face face;
|
2001-12-05 02:22:05 +01:00
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
|
2001-12-05 16:59:33 +01:00
|
|
|
sfam->desc = squery->desc;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
/* we need to compute "cquery.item_total" now */
|
|
|
|
error = FTC_Manager_Lookup_Face( manager,
|
2001-12-05 16:59:33 +01:00
|
|
|
squery->desc.font.face_id,
|
2001-10-26 18:58:27 +02:00
|
|
|
&face );
|
2000-10-31 23:13:54 +01:00
|
|
|
if ( !error )
|
2001-10-26 18:58:27 +02:00
|
|
|
{
|
2001-12-20 18:49:10 +01:00
|
|
|
error = ftc_glyph_family_init( FTC_GLYPH_FAMILY( sfam ),
|
2001-12-05 16:59:33 +01:00
|
|
|
FTC_IMAGE_DESC_HASH( &sfam->desc ),
|
|
|
|
FTC_SBIT_ITEMS_PER_NODE,
|
|
|
|
face->num_glyphs,
|
2001-12-20 18:49:10 +01:00
|
|
|
FTC_GLYPH_QUERY( squery ),
|
2001-12-05 16:59:33 +01:00
|
|
|
cache );
|
2001-10-26 18:58:27 +02:00
|
|
|
}
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-10-29 01:34:45 +02:00
|
|
|
return error;
|
|
|
|
}
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-10-29 01:34:45 +02:00
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_CALLBACK_DEF( FT_Bool )
|
2001-12-20 18:49:10 +01:00
|
|
|
ftc_sbit_family_compare( FTC_SBitFamily sfam,
|
|
|
|
FTC_SBitQuery squery )
|
2000-10-28 15:17:11 +02:00
|
|
|
{
|
2001-10-26 18:58:27 +02:00
|
|
|
FT_Bool result;
|
|
|
|
|
2001-12-05 02:22:05 +01:00
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
/* we need to set the "cquery.cset" field or our query for */
|
2001-12-20 18:49:10 +01:00
|
|
|
/* faster glyph comparisons in ftc_sbit_node_compare */
|
|
|
|
/* */
|
2001-12-05 16:59:33 +01:00
|
|
|
result = FT_BOOL( FTC_IMAGE_DESC_COMPARE( &sfam->desc, &squery->desc ) );
|
2001-10-26 18:58:27 +02:00
|
|
|
if ( result )
|
2001-12-20 18:49:10 +01:00
|
|
|
FTC_GLYPH_FAMILY_FOUND( sfam, squery );
|
2001-10-26 18:58:27 +02:00
|
|
|
|
|
|
|
return result;
|
2000-10-28 15:17:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
2000-10-29 01:34:45 +02:00
|
|
|
/***** SBITS CACHE *****/
|
2000-10-28 15:17:11 +02:00
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_CALLBACK_TABLE_DEF
|
2001-10-26 18:58:27 +02:00
|
|
|
const FTC_Cache_ClassRec ftc_sbit_cache_class =
|
2000-10-28 15:17:11 +02:00
|
|
|
{
|
2001-12-20 18:49:10 +01:00
|
|
|
sizeof ( FTC_CacheRec ),
|
|
|
|
(FTC_Cache_InitFunc) ftc_cache_init,
|
|
|
|
(FTC_Cache_ClearFunc)ftc_cache_clear,
|
|
|
|
(FTC_Cache_DoneFunc) ftc_cache_done,
|
|
|
|
|
|
|
|
sizeof ( FTC_SBitFamilyRec ),
|
|
|
|
(FTC_Family_InitFunc) ftc_sbit_family_init,
|
|
|
|
(FTC_Family_CompareFunc)ftc_sbit_family_compare,
|
|
|
|
(FTC_Family_DoneFunc) ftc_glyph_family_done,
|
|
|
|
|
|
|
|
sizeof ( FTC_SBitNodeRec ),
|
|
|
|
(FTC_Node_InitFunc) ftc_sbit_node_init,
|
|
|
|
(FTC_Node_WeightFunc) ftc_sbit_node_weight,
|
|
|
|
(FTC_Node_CompareFunc)ftc_sbit_node_compare,
|
|
|
|
(FTC_Node_DoneFunc) ftc_sbit_node_done
|
2000-10-28 15:17:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-06-28 19:49:10 +02:00
|
|
|
/* documentation is in ftcsbits.h */
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_EXPORT_DEF( FT_Error )
|
2001-12-05 16:59:33 +01:00
|
|
|
FTC_SBitCache_New( FTC_Manager manager,
|
|
|
|
FTC_SBitCache *acache )
|
2000-10-28 15:17:11 +02:00
|
|
|
{
|
2001-12-05 02:22:05 +01:00
|
|
|
return FTC_Manager_Register_Cache( manager,
|
|
|
|
&ftc_sbit_cache_class,
|
|
|
|
(FTC_Cache*)acache );
|
2000-10-28 15:17:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 19:49:10 +02:00
|
|
|
/* documentation is in ftcsbits.h */
|
|
|
|
|
2002-06-07 22:07:44 +02:00
|
|
|
#ifdef FTC_CACHE_USE_INLINE
|
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
#define GEN_CACHE_FAMILY_COMPARE( f, q, c ) \
|
|
|
|
ftc_sbit_family_compare( (FTC_SBitFamily)(f), (FTC_SBitQuery)(q) )
|
2002-06-07 22:07:44 +02:00
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
#define GEN_CACHE_NODE_COMPARE( n, q, c ) \
|
|
|
|
ftc_sbit_node_compare( (FTC_SBitNode)(n), (FTC_SBitQuery)(q), c )
|
2002-06-07 22:07:44 +02:00
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
#define GEN_CACHE_LOOKUP ftc_sbit_cache_lookup
|
|
|
|
#include "ftccache.i"
|
2002-06-07 22:07:44 +02:00
|
|
|
|
|
|
|
#else /* !FTC_CACHE_USE_INLINE */
|
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
#define ftc_sbit_cache_lookup ftc_cache_lookup
|
2002-06-07 22:07:44 +02:00
|
|
|
|
|
|
|
#endif /* !FTC_CACHE_USE_INLINE */
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_EXPORT_DEF( FT_Error )
|
2001-12-05 16:59:33 +01:00
|
|
|
FTC_SBitCache_Lookup( FTC_SBitCache cache,
|
|
|
|
FTC_ImageDesc* desc,
|
|
|
|
FT_UInt gindex,
|
|
|
|
FTC_SBit *ansbit,
|
|
|
|
FTC_Node *anode )
|
2000-10-28 15:17:11 +02:00
|
|
|
{
|
2001-10-26 18:58:27 +02:00
|
|
|
FT_Error error;
|
2001-12-05 16:59:33 +01:00
|
|
|
FTC_SBitQueryRec squery;
|
|
|
|
FTC_SBitNode node;
|
2000-10-28 15:17:11 +02:00
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
|
|
|
|
/* other argument checks delayed to ftc_cache_lookup */
|
2000-11-10 23:43:37 +01:00
|
|
|
if ( !ansbit )
|
Complete redesign of error codes. Please check ftmoderr.h for more
details.
* include/freetype/internal/cfferrs.h,
include/freetype/internal/tterrors.h,
include/freetype/internal/t1errors.h: Removed. Replaced with files
local to the module. All extra error codes have been moved to
`fterrors.h'.
* src/sfnt/ttpost.h: Move error codes to `fterrors.h'.
* src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h,
src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h,
src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h,
src/smooth/ftsmerrs.h, src/truetype/tterrors.h,
src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the
error names for the module it belongs to.
* include/freetype/ftmoderr.h: New file, defining the module error
offsets. Its structure is similar to `fterrors.h'.
* include/freetype/fterrors.h (FT_NOERRORDEF): New macro.
(FT_ERRORDEF): Redefined to use module error offsets.
All internal error codes are now public; unused error codes have
been removed, some are new.
* include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New
macro.
* include/freetype/config/ftoption.h
(FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro.
All other source files have been updated to use the new error codes;
some already existing (internal) error codes local to a module have
been renamed to give them the same name as in the base module.
All make files have been updated to include the local error files.
* src/cid/cidtokens.h: Replaced with...
* src/cid/cidtoken.h: This file for 8+3 consistency.
* src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
|
|
|
return FTC_Err_Invalid_Argument;
|
2001-06-28 19:49:10 +02:00
|
|
|
|
2001-10-26 18:58:27 +02:00
|
|
|
*ansbit = NULL;
|
2001-06-28 19:49:10 +02:00
|
|
|
|
2001-12-05 16:59:33 +01:00
|
|
|
if ( anode )
|
|
|
|
*anode = NULL;
|
|
|
|
|
|
|
|
squery.gquery.gindex = gindex;
|
|
|
|
squery.desc = *desc;
|
|
|
|
|
2002-06-07 22:07:44 +02:00
|
|
|
error = ftc_sbit_cache_lookup( FTC_CACHE( cache ),
|
|
|
|
FTC_QUERY( &squery ),
|
|
|
|
(FTC_Node*)&node );
|
2001-10-26 18:58:27 +02:00
|
|
|
if ( !error )
|
|
|
|
{
|
2001-12-20 18:49:10 +01:00
|
|
|
*ansbit = node->sbits + ( gindex - FTC_GLYPH_NODE( node )->item_start );
|
2001-12-05 16:59:33 +01:00
|
|
|
|
|
|
|
if ( anode )
|
|
|
|
{
|
2001-12-20 18:49:10 +01:00
|
|
|
*anode = FTC_NODE( node );
|
|
|
|
FTC_NODE( node )->ref_count++;
|
2001-12-05 16:59:33 +01:00
|
|
|
}
|
2001-10-26 18:58:27 +02:00
|
|
|
}
|
2000-10-28 15:17:11 +02:00
|
|
|
return error;
|
|
|
|
}
|
2001-06-28 19:49:10 +02:00
|
|
|
|
2000-10-31 23:13:54 +01:00
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
/* backwards-compatibility functions */
|
2001-12-05 16:59:33 +01:00
|
|
|
|
|
|
|
FT_EXPORT_DEF( FT_Error )
|
|
|
|
FTC_SBit_Cache_New( FTC_Manager manager,
|
|
|
|
FTC_SBit_Cache *acache )
|
|
|
|
{
|
|
|
|
return FTC_SBitCache_New( manager, (FTC_SBitCache*)acache );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_EXPORT_DEF( FT_Error )
|
|
|
|
FTC_SBit_Cache_Lookup( FTC_SBit_Cache cache,
|
|
|
|
FTC_Image_Desc* desc,
|
|
|
|
FT_UInt gindex,
|
|
|
|
FTC_SBit *ansbit )
|
|
|
|
{
|
|
|
|
FTC_ImageDesc desc0;
|
2002-06-07 22:07:44 +02:00
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
|
2001-12-05 16:59:33 +01:00
|
|
|
if ( !desc )
|
2002-04-28 04:48:20 +02:00
|
|
|
return FTC_Err_Invalid_Argument;
|
2002-06-07 22:07:44 +02:00
|
|
|
|
2001-12-05 16:59:33 +01:00
|
|
|
desc0.font = desc->font;
|
2001-12-20 18:49:10 +01:00
|
|
|
desc0.type = (FT_UInt32)desc->image_type;
|
2001-12-05 16:59:33 +01:00
|
|
|
|
|
|
|
return FTC_SBitCache_Lookup( (FTC_SBitCache)cache,
|
|
|
|
&desc0,
|
|
|
|
gindex,
|
|
|
|
ansbit,
|
|
|
|
NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-31 23:13:54 +01:00
|
|
|
/* END */
|