freetype/src/sfnt/ttcmap.c

1100 lines
39 KiB
C
Raw Normal View History

1999-12-17 00:11:37 +01:00
/***************************************************************************/
/* */
/* ttcmap.c */
/* */
/* TrueType character mapping table (cmap) support (body). */
/* */
/* Copyright 1996-2001 by */
1999-12-17 00:11:37 +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 */
1999-12-17 00:11:37 +01:00
/* 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_INTERNAL_DEBUG_H
#include "ttload.h"
#include "ttcmap.h"
1999-12-17 00:11:37 +01: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 "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. */
/* */
1999-12-17 00:11:37 +01:00
#undef FT_COMPONENT
#define FT_COMPONENT trace_ttcmap
1999-12-17 00:11:37 +01:00
2001-06-28 01:25:46 +02:00
FT_CALLBACK_DEF( FT_UInt )
code_to_index0( TT_CMapTable charmap,
2001-06-28 01:25:46 +02:00
FT_ULong char_code );
FT_CALLBACK_DEF( FT_ULong )
code_to_next0( TT_CMapTable charmap,
FT_ULong char_code );
2001-06-28 01:25:46 +02:00
FT_CALLBACK_DEF( FT_UInt )
code_to_index2( TT_CMapTable charmap,
2001-06-28 01:25:46 +02:00
FT_ULong char_code );
1999-12-17 00:11:37 +01:00
FT_CALLBACK_DEF( FT_ULong )
code_to_next2( TT_CMapTable charmap,
FT_ULong char_code );
2001-06-28 01:25:46 +02:00
FT_CALLBACK_DEF( FT_UInt )
code_to_index4( TT_CMapTable charmap,
2001-06-28 01:25:46 +02:00
FT_ULong char_code );
FT_CALLBACK_DEF( FT_ULong )
code_to_next4( TT_CMapTable charmap,
FT_ULong char_code );
2001-06-28 01:25:46 +02:00
FT_CALLBACK_DEF( FT_UInt )
code_to_index6( TT_CMapTable charmap,
2001-06-28 01:25:46 +02:00
FT_ULong char_code );
FT_CALLBACK_DEF( FT_ULong )
code_to_next6( TT_CMapTable charmap,
FT_ULong char_code );
FT_CALLBACK_DEF( FT_UInt )
code_to_index8_12( TT_CMapTable charmap,
FT_ULong char_code );
FT_CALLBACK_DEF( FT_ULong )
code_to_next8_12( TT_CMapTable charmap,
FT_ULong char_code );
FT_CALLBACK_DEF( FT_UInt )
code_to_index10( TT_CMapTable charmap,
FT_ULong char_code );
FT_CALLBACK_DEF( FT_ULong )
code_to_next10( TT_CMapTable charmap,
FT_ULong char_code );
1999-12-17 00:11:37 +01:00
/*************************************************************************/
/* */
/* <Function> */
/* TT_CharMap_Load */
/* */
/* <Description> */
/* Loads a given TrueType character map into memory. */
/* */
/* <Input> */
/* face :: A handle to the parent face object. */
/* stream :: A handle to the current stream object. */
/* */
/* <InOut> */
/* table :: A pointer to a cmap object. */
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
/* <Note> */
/* The function assumes that the stream is already in use (i.e., */
/* opened). In case of error, all partially allocated tables are */
/* released. */
/* */
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_CharMap_Load( TT_Face face,
TT_CMapTable cmap,
2001-06-28 01:25:46 +02:00
FT_Stream stream )
1999-12-17 00:11:37 +01:00
{
FT_Error error;
FT_Memory memory;
FT_UShort num_SH, num_Seg, i;
FT_ULong j, n;
1999-12-17 00:11:37 +01:00
FT_UShort u, l;
1999-12-17 00:11:37 +01:00
TT_CMap0 cmap0;
TT_CMap2 cmap2;
TT_CMap4 cmap4;
TT_CMap6 cmap6;
TT_CMap8_12 cmap8_12;
TT_CMap10 cmap10;
1999-12-17 00:11:37 +01:00
TT_CMap2SubHeader cmap2sub;
TT_CMap4Segment segments;
TT_CMapGroup groups;
1999-12-17 00:11:37 +01:00
if ( cmap->loaded )
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 SFNT_Err_Ok;
1999-12-17 00:11:37 +01:00
memory = stream->memory;
if ( FT_STREAM_SEEK( cmap->offset ) )
1999-12-17 00:11:37 +01:00
return error;
switch ( cmap->format )
{
case 0:
cmap0 = &cmap->c.cmap0;
if ( READ_UShort( cmap0->language ) ||
ALLOC( cmap0->glyphIdArray, 256L ) ||
FT_STREAM_READ( cmap0->glyphIdArray, 256L ) )
goto Fail;
1999-12-17 00:11:37 +01:00
cmap->get_index = code_to_index0;
cmap->get_next_char = code_to_next0;
1999-12-17 00:11:37 +01:00
break;
case 2:
num_SH = 0;
cmap2 = &cmap->c.cmap2;
/* allocate subheader keys */
if ( ALLOC_ARRAY( cmap2->subHeaderKeys, 256, FT_UShort ) ||
FT_FRAME_ENTER( 2L + 512L ) )
1999-12-17 00:11:37 +01:00
goto Fail;
cmap2->language = GET_UShort();
1999-12-17 00:11:37 +01:00
for ( i = 0; i < 256; i++ )
{
2001-06-20 01:03:41 +02:00
u = (FT_UShort)( GET_UShort() / 8 );
1999-12-17 00:11:37 +01:00
cmap2->subHeaderKeys[i] = u;
if ( num_SH < u )
num_SH = u;
}
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
/* load subheaders */
cmap2->numGlyphId = l = (FT_UShort)(
( ( cmap->length - 2L * ( 256 + 3 ) - num_SH * 8L ) & 0xFFFF ) / 2 );
1999-12-17 00:11:37 +01:00
if ( ALLOC_ARRAY( cmap2->subHeaders,
num_SH + 1,
TT_CMap2SubHeaderRec ) ||
FT_FRAME_ENTER( ( num_SH + 1 ) * 8L ) )
{
FREE( cmap2->subHeaderKeys );
1999-12-17 00:11:37 +01:00
goto Fail;
}
1999-12-17 00:11:37 +01:00
cmap2sub = cmap2->subHeaders;
for ( i = 0; i <= num_SH; i++ )
{
cmap2sub->firstCode = GET_UShort();
cmap2sub->entryCount = GET_UShort();
cmap2sub->idDelta = GET_Short();
/* we apply the location offset immediately */
2001-06-20 01:03:41 +02:00
cmap2sub->idRangeOffset = (FT_UShort)(
GET_UShort() - ( num_SH - i ) * 8 - 2 );
1999-12-17 00:11:37 +01:00
cmap2sub++;
}
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
/* load glyph IDs */
if ( ALLOC_ARRAY( cmap2->glyphIdArray, l, FT_UShort ) ||
FT_FRAME_ENTER( l * 2L ) )
{
FREE( cmap2->subHeaders );
FREE( cmap2->subHeaderKeys );
1999-12-17 00:11:37 +01:00
goto Fail;
}
1999-12-17 00:11:37 +01:00
for ( i = 0; i < l; i++ )
cmap2->glyphIdArray[i] = GET_UShort();
FT_FRAME_EXIT();
2000-05-17 01:44:38 +02:00
1999-12-17 00:11:37 +01:00
cmap->get_index = code_to_index2;
cmap->get_next_char = code_to_next2;
1999-12-17 00:11:37 +01:00
break;
case 4:
cmap4 = &cmap->c.cmap4;
/* load header */
if ( FT_FRAME_ENTER( 10L ) )
1999-12-17 00:11:37 +01:00
goto Fail;
cmap4->language = GET_UShort();
1999-12-17 00:11:37 +01:00
cmap4->segCountX2 = GET_UShort();
cmap4->searchRange = GET_UShort();
cmap4->entrySelector = GET_UShort();
cmap4->rangeShift = GET_UShort();
2001-06-20 01:03:41 +02:00
num_Seg = (FT_UShort)( cmap4->segCountX2 / 2 );
1999-12-17 00:11:37 +01:00
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
/* load segments */
if ( ALLOC_ARRAY( cmap4->segments,
num_Seg,
TT_CMap4SegmentRec ) ||
FT_FRAME_ENTER( ( num_Seg * 4 + 1 ) * 2L ) )
1999-12-17 00:11:37 +01:00
goto Fail;
segments = cmap4->segments;
for ( i = 0; i < num_Seg; i++ )
segments[i].endCount = GET_UShort();
(void)GET_UShort();
for ( i = 0; i < num_Seg; i++ )
segments[i].startCount = GET_UShort();
for ( i = 0; i < num_Seg; i++ )
segments[i].idDelta = GET_Short();
for ( i = 0; i < num_Seg; i++ )
segments[i].idRangeOffset = GET_UShort();
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
cmap4->numGlyphId = l = (FT_UShort)(
( ( cmap->length - ( 16L + 8L * num_Seg ) ) & 0xFFFF ) / 2 );
1999-12-17 00:11:37 +01:00
/* load IDs */
if ( ALLOC_ARRAY( cmap4->glyphIdArray, l, FT_UShort ) ||
FT_FRAME_ENTER( l * 2L ) )
{
FREE( cmap4->segments );
1999-12-17 00:11:37 +01:00
goto Fail;
}
1999-12-17 00:11:37 +01:00
for ( i = 0; i < l; i++ )
cmap4->glyphIdArray[i] = GET_UShort();
FT_FRAME_EXIT();
2000-05-17 01:44:38 +02:00
cmap4->last_segment = cmap4->segments;
cmap->get_index = code_to_index4;
cmap->get_next_char = code_to_next4;
1999-12-17 00:11:37 +01:00
break;
case 6:
cmap6 = &cmap->c.cmap6;
if ( FT_FRAME_ENTER( 6L ) )
1999-12-17 00:11:37 +01:00
goto Fail;
cmap6->language = GET_UShort();
1999-12-17 00:11:37 +01:00
cmap6->firstCode = GET_UShort();
cmap6->entryCount = GET_UShort();
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
l = cmap6->entryCount;
if ( ALLOC_ARRAY( cmap6->glyphIdArray, l, FT_Short ) ||
FT_FRAME_ENTER( l * 2L ) )
1999-12-17 00:11:37 +01:00
goto Fail;
for ( i = 0; i < l; i++ )
cmap6->glyphIdArray[i] = GET_UShort();
FT_FRAME_EXIT();
1999-12-17 00:11:37 +01:00
cmap->get_index = code_to_index6;
cmap->get_next_char = code_to_next6;
1999-12-17 00:11:37 +01:00
break;
case 8:
case 12:
cmap8_12 = &cmap->c.cmap8_12;
if ( FT_FRAME_ENTER( 8L ) )
goto Fail;
cmap->length = GET_ULong();
cmap8_12->language = GET_ULong();
FT_FRAME_EXIT();
if ( cmap->format == 8 )
if ( FT_STREAM_SKIP( 8192L ) )
goto Fail;
if ( READ_ULong( cmap8_12->nGroups ) )
goto Fail;
n = cmap8_12->nGroups;
if ( ALLOC_ARRAY( cmap8_12->groups, n, TT_CMapGroupRec ) ||
FT_FRAME_ENTER( n * 3 * 4L ) )
goto Fail;
groups = cmap8_12->groups;
for ( j = 0; j < n; j++ )
{
groups[j].startCharCode = GET_ULong();
groups[j].endCharCode = GET_ULong();
groups[j].startGlyphID = GET_ULong();
}
FT_FRAME_EXIT();
cmap8_12->last_group = cmap8_12->groups;
cmap->get_index = code_to_index8_12;
cmap->get_next_char = code_to_next8_12;
break;
case 10:
cmap10 = &cmap->c.cmap10;
if ( FT_FRAME_ENTER( 16L ) )
goto Fail;
cmap->length = GET_ULong();
cmap10->language = GET_ULong();
cmap10->startCharCode = GET_ULong();
cmap10->numChars = GET_ULong();
FT_FRAME_EXIT();
n = cmap10->numChars;
if ( ALLOC_ARRAY( cmap10->glyphs, n, FT_Short ) ||
FT_FRAME_ENTER( n * 2L ) )
goto Fail;
for ( j = 0; j < n; j++ )
cmap10->glyphs[j] = GET_UShort();
FT_FRAME_EXIT();
cmap->get_index = code_to_index10;
cmap->get_next_char = code_to_next10;
break;
1999-12-17 00:11:37 +01:00
default: /* corrupt character mapping table */
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 SFNT_Err_Invalid_CharMap_Format;
1999-12-17 00:11:37 +01: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
return SFNT_Err_Ok;
1999-12-17 00:11:37 +01:00
Fail:
TT_CharMap_Free( face, cmap );
return error;
}
/*************************************************************************/
/* */
/* <Function> */
/* TT_CharMap_Free */
/* */
/* <Description> */
/* Destroys a character mapping table. */
/* */
/* <Input> */
/* face :: A handle to the parent face object. */
/* cmap :: A handle to a cmap object. */
/* */
/* <Return> */
2000-06-25 08:47:11 +02:00
/* FreeType error code. 0 means success. */
1999-12-17 00:11:37 +01:00
/* */
FT_LOCAL_DEF( FT_Error )
2001-06-28 01:25:46 +02:00
TT_CharMap_Free( TT_Face face,
TT_CMapTable cmap )
1999-12-17 00:11:37 +01:00
{
FT_Memory memory;
if ( !cmap )
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 SFNT_Err_Ok;
1999-12-17 00:11:37 +01:00
- MAJOR INTERNAL REDESIGN: A lot of internal modifications have been performed lately on the source in order to provide the following enhancements: - more generic module support: The FT_Module type is now defined to represent a handle to a given module. The file <freetype/ftmodule.h> contains the FT_Module_Class definition, as well as the module-loading public API The FT_Driver type is still defined, and still represents a pointer to a font driver. Note that FT_Add_Driver is replaced by FT_Add_Module, FT_Get_Driver by FT_Get_Module, etc.. - support for generic glyph image types: The FT_Renderer type is a pointer to a module used to perform various operations on glyph image. Each renderer is capable of handling images in a single format (e.g. ft_glyph_format_outline). Its functions are used to: - transform an glyph image - render a glyph image into a bitmap - return the control box (dimensions) of a given glyph image The scan converters "ftraster.c" and "ftgrays.c" have been moved to the new directory "src/renderer", and are used to provide two default renderer modules. One corresponds to the "standard" scan-converter, the other to the "smooth" one. The current renderer can be set through the new function FT_Set_Renderer. The old raster-related function FT_Set_Raster, FT_Get_Raster and FT_Set_Raster_Mode have now disappeared, in favor of the new: FT_Get_Renderer FT_Set_Renderer see the file <freetype/ftrender.h> for more details.. These changes were necessary to properly support different scalable formats in the future, like bi-color glyphs, etc.. - glyph loader object: A new internal object, called a 'glyph loader' has been introduced in the base layer. It is used by all scalable format font drivers to load glyphs and composites. This object has been created to reduce the code size of each driver, as each one of them basically re-implemented its functionality. See <freetype/internal/ftobjs.h> and the FT_GlyphLoader type for more information.. - FT_GlyphSlot had new fields: In order to support extended features (see below), the FT_GlyphSlot structure has a few new fields: linearHoriAdvance: this field gives the linearly scaled (i.e. scaled but unhinted) advance width for the glyph, expressed as a 16.16 fixed pixel value. This is useful to perform WYSIWYG text. linearVertAdvance: this field gives the linearly scaled advance height for the glyph (relevant in vertical glyph layouts only). This is useful to perform WYSIWYG text. Note that the two above field replace the removed "metrics2" field in the glyph slot. advance: this field is a vector that gives the transformed advance for the glyph. By default, it corresponds to the advance width, unless FT_LOAD_VERTICAL_LAYOUT was specified when calling FT_Load_Glyph or FT_Load_Char bitmap_left: this field gives the distance in integer pixels from the current pen position to the left-most pixel of a glyph image WHEN IT IS A BITMAP. It is only valid when the "format" field is set to "ft_glyph_format_bitmap", for example, after calling the new function FT_Render_Glyph. bitmap_top: this field gives the distance in integer pixels from the current pen position (located on the baseline) to the top-most pixel of the glyph image WHEN IT IS A BITMAP. Positive values correspond to upwards Y. loader: this is a new private field for the glyph slot. Client applications should not touch it.. - support for transforms and direct rendering in FT_Load_Glyph: Most of the functionality found in <freetype/ftglyph.h> has been moved to the core library. Hence, the following: - a transform can be specified for a face through FT_Set_Transform. this transform is applied by FT_Load_Glyph to scalable glyph images (i.e. NOT TO BITMAPS) before the function returns, unless the bit flag FT_LOAD_IGNORE_TRANSFORM was set in the load flags.. - once a glyph image has been loaded, it can be directly converted to a bitmap by using the new FT_Render_Glyph function. Note that this function takes the glyph image from the glyph slot, and converts it to a bitmap whose properties are returned in "face.glyph.bitmap", "face.glyph.bitmap_left" and "face.glyph.bitmap_top". The original native image might be lost after the conversion. - when using the new bit flag FT_LOAD_RENDER, the FT_Load_Glyph and FT_Load_Char functions will call FT_Render_Glyph automatically when needed.
2000-06-22 02:17:42 +02:00
memory = face->root.driver->root.memory;
1999-12-17 00:11:37 +01:00
switch ( cmap->format )
{
case 0:
FREE( cmap->c.cmap0.glyphIdArray );
break;
case 2:
FREE( cmap->c.cmap2.subHeaderKeys );
FREE( cmap->c.cmap2.subHeaders );
FREE( cmap->c.cmap2.glyphIdArray );
break;
case 4:
FREE( cmap->c.cmap4.segments );
FREE( cmap->c.cmap4.glyphIdArray );
cmap->c.cmap4.segCountX2 = 0;
break;
case 6:
FREE( cmap->c.cmap6.glyphIdArray );
cmap->c.cmap6.entryCount = 0;
break;
case 8:
case 12:
FREE( cmap->c.cmap8_12.groups );
cmap->c.cmap8_12.nGroups = 0;
break;
case 10:
FREE( cmap->c.cmap10.glyphs );
cmap->c.cmap10.numChars = 0;
break;
1999-12-17 00:11:37 +01:00
default:
/* invalid table format, do nothing */
;
}
cmap->loaded = FALSE;
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 SFNT_Err_Ok;
1999-12-17 00:11:37 +01:00
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_index0 */
/* */
/* <Description> */
/* Converts the character code into a glyph index. Uses format 0. */
/* `charCode' must be in the range 0x00-0xFF (otherwise 0 is */
/* returned). */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* cmap0 :: A pointer to a cmap table in format 0. */
/* */
/* <Return> */
/* Glyph index into the glyphs array. 0 if the glyph does not exist. */
1999-12-17 00:11:37 +01:00
/* */
2001-06-28 01:25:46 +02:00
FT_CALLBACK_DEF( FT_UInt )
code_to_index0( TT_CMapTable cmap,
FT_ULong charCode )
1999-12-17 00:11:37 +01:00
{
TT_CMap0 cmap0 = &cmap->c.cmap0;
2000-05-17 01:44:38 +02:00
1999-12-17 00:11:37 +01:00
return ( charCode <= 0xFF ? cmap0->glyphIdArray[charCode] : 0 );
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_next0 */
/* */
/* <Description> */
/* Finds the next encoded character after the given one. Uses */
/* format 0. `charCode' must be in the range 0x00-0xFF (otherwise 0 */
/* is returned). */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* cmap0 :: A pointer to a cmap table in format 0. */
/* */
/* <Return> */
/* Next char code. 0 if no higher one is encoded. */
/* */
FT_CALLBACK_DEF( FT_ULong )
code_to_next0( TT_CMapTable cmap,
FT_ULong charCode )
{
TT_CMap0 cmap0 = &cmap->c.cmap0;
while ( ++charCode <= 0xFF )
if ( cmap0->glyphIdArray[charCode] )
return ( charCode );
return ( 0 );
}
1999-12-17 00:11:37 +01:00
/*************************************************************************/
/* */
/* <Function> */
/* code_to_index2 */
/* */
/* <Description> */
/* Converts the character code into a glyph index. Uses format 2. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* cmap2 :: A pointer to a cmap table in format 2. */
/* */
/* <Return> */
/* Glyph index into the glyphs array. 0 if the glyph does not exist. */
1999-12-17 00:11:37 +01:00
/* */
2001-06-28 01:25:46 +02:00
FT_CALLBACK_DEF( FT_UInt )
code_to_index2( TT_CMapTable cmap,
FT_ULong charCode )
1999-12-17 00:11:37 +01:00
{
FT_UInt result, index1, offset;
FT_UInt char_lo;
FT_ULong char_hi;
TT_CMap2SubHeader sh2;
TT_CMap2 cmap2;
1999-12-17 00:11:37 +01:00
cmap2 = &cmap->c.cmap2;
result = 0;
char_lo = (FT_UInt)( charCode & 0xFF );
1999-12-17 00:11:37 +01:00
char_hi = charCode >> 8;
if ( char_hi == 0 )
{
/* an 8-bit character code -- we use the subHeader 0 in this case */
/* to test whether the character code is in the charmap */
index1 = cmap2->subHeaderKeys[char_lo];
if ( index1 != 0 )
return 0;
1999-12-17 00:11:37 +01:00
}
else
{
/* a 16-bit character code */
index1 = cmap2->subHeaderKeys[char_hi & 0xFF];
if ( index1 == 0 )
return 0;
}
sh2 = cmap2->subHeaders + index1;
char_lo -= sh2->firstCode;
if ( char_lo < (FT_UInt)sh2->entryCount )
{
offset = sh2->idRangeOffset / 2 + char_lo;
if ( offset < (FT_UInt)cmap2->numGlyphId )
1999-12-17 00:11:37 +01:00
{
result = cmap2->glyphIdArray[offset];
if ( result )
result = ( result + sh2->idDelta ) & 0xFFFF;
1999-12-17 00:11:37 +01:00
}
}
1999-12-17 00:11:37 +01:00
return result;
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_next2 */
/* */
/* <Description> */
/* Find the next encoded character. Uses format 2. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* cmap2 :: A pointer to a cmap table in format 2. */
/* */
/* <Return> */
/* Next encoded character. 0 if none exists. */
/* */
FT_CALLBACK_DEF( FT_ULong )
code_to_next2( TT_CMapTable cmap,
FT_ULong charCode )
{
FT_UInt index1, offset;
FT_UInt char_lo;
FT_ULong char_hi;
TT_CMap2SubHeader sh2;
TT_CMap2 cmap2;
cmap2 = &cmap->c.cmap2;
charCode++;
/*
* This is relatively simplistic -- look for a subHeader containing
* glyphs and then walk to the first glyph in that subHeader.
*/
while ( charCode < 0x10000 )
{
char_lo = (FT_UInt)( charCode & 0xFF );
char_hi = charCode >> 8;
if ( char_hi == 0 )
{
/* an 8-bit character code -- we use the subHeader 0 in this case */
/* to test whether the character code is in the charmap */
index1 = cmap2->subHeaderKeys[char_lo];
if ( index1 != 0 )
{
charCode++;
continue;
}
}
else
{
/* a 16-bit character code */
index1 = cmap2->subHeaderKeys[char_hi & 0xFF];
if ( index1 == 0 )
{
charCode = ( char_hi + 1 ) << 8;
continue;
}
}
sh2 = cmap2->subHeaders + index1;
char_lo -= sh2->firstCode;
if ( char_lo > (FT_UInt)sh2->entryCount )
{
charCode = ( char_hi + 1 ) << 8;
continue;
}
offset = sh2->idRangeOffset / 2 + char_lo;
if ( offset >= (FT_UInt)cmap2->numGlyphId ||
cmap2->glyphIdArray[offset] == 0 )
{
charCode++;
continue;
}
return charCode;
}
return 0;
}
1999-12-17 00:11:37 +01:00
/*************************************************************************/
/* */
/* <Function> */
/* code_to_index4 */
/* */
/* <Description> */
/* Converts the character code into a glyph index. Uses format 4. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* cmap4 :: A pointer to a cmap table in format 4. */
/* */
/* <Return> */
/* Glyph index into the glyphs array. 0 if the glyph does not exist. */
1999-12-17 00:11:37 +01:00
/* */
2001-06-28 01:25:46 +02:00
FT_CALLBACK_DEF( FT_UInt )
code_to_index4( TT_CMapTable cmap,
FT_ULong charCode )
1999-12-17 00:11:37 +01:00
{
FT_UInt result, index1, segCount;
TT_CMap4 cmap4;
TT_CMap4SegmentRec *seg4, *limit;
1999-12-17 00:11:37 +01:00
1999-12-17 00:11:37 +01:00
cmap4 = &cmap->c.cmap4;
result = 0;
segCount = cmap4->segCountX2 / 2;
limit = cmap4->segments + segCount;
/* first, check against the last used segment */
1999-12-17 00:11:37 +01:00
seg4 = cmap4->last_segment;
/* the following is equivalent to performing two tests, as in */
/* */
/* if ( charCode >= seg4->startCount && charCode <= seg4->endCount ) */
/* */
/* This is a bit strange, but it is faster, and the idea behind the */
/* cache is to significantly speed up charcode to glyph index */
/* conversion. */
if ( (FT_ULong)( charCode - seg4->startCount ) <
(FT_ULong)( seg4->endCount - seg4->startCount ) )
goto Found1;
1999-12-17 00:11:37 +01:00
2000-06-07 22:06:18 +02:00
for ( seg4 = cmap4->segments; seg4 < limit; seg4++ )
{
/* the ranges are sorted in increasing order. If we are out of */
/* the range here, the char code isn't in the charmap, so exit. */
if ( charCode > (FT_UInt)seg4->endCount )
continue;
2000-06-05 16:32:32 +02:00
if ( charCode >= (FT_UInt)seg4->startCount )
goto Found;
1999-12-17 00:11:37 +01:00
}
return 0;
Found:
cmap4->last_segment = seg4;
2000-06-05 16:32:32 +02:00
Found1:
/* if the idRangeOffset is 0, we can compute the glyph index */
/* directly */
2000-06-05 16:32:32 +02:00
if ( seg4->idRangeOffset == 0 )
result = ( charCode + seg4->idDelta ) & 0xFFFF;
else
{
/* otherwise, we must use the glyphIdArray to do it */
index1 = (FT_UInt)( seg4->idRangeOffset / 2
+ ( charCode - seg4->startCount )
+ ( seg4 - cmap4->segments )
- segCount );
1999-12-17 00:11:37 +01:00
if ( index1 < (FT_UInt)cmap4->numGlyphId &&
cmap4->glyphIdArray[index1] != 0 )
result = ( cmap4->glyphIdArray[index1] + seg4->idDelta ) & 0xFFFF;
}
1999-12-17 00:11:37 +01:00
return result;
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_next4 */
/* */
/* <Description> */
/* Find the next encoded character. Uses format 4. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* cmap :: A pointer to a cmap table in format 4. */
/* */
/* <Return> */
/* Next encoded character. 0 if none exists. */
/* */
FT_CALLBACK_DEF( FT_ULong )
code_to_next4( TT_CMapTable cmap,
FT_ULong charCode )
{
FT_UInt index1, segCount;
TT_CMap4 cmap4;
TT_CMap4SegmentRec *seg4, *limit;
cmap4 = &cmap->c.cmap4;
segCount = cmap4->segCountX2 / 2;
limit = cmap4->segments + segCount;
charCode++;
for ( seg4 = cmap4->segments; seg4 < limit; seg4++ )
{
/* The ranges are sorted in increasing order. If we are out of */
/* the range here, the char code isn't in the charmap, so exit. */
if ( charCode <= (FT_UInt)seg4->endCount )
goto Found;
}
return 0;
Found:
2002-02-06 12:22:01 +01:00
if ( charCode < (FT_ULong) seg4->startCount )
charCode = seg4->startCount;
/* if the idRangeOffset is 0, all chars in the map exist */
if ( seg4->idRangeOffset == 0 )
return ( charCode );
while ( charCode <= (FT_UInt) seg4->endCount )
{
/* otherwise, we must use the glyphIdArray to do it */
index1 = (FT_UInt)( seg4->idRangeOffset / 2
+ ( charCode - seg4->startCount )
+ ( seg4 - cmap4->segments )
- segCount );
if ( index1 < (FT_UInt)cmap4->numGlyphId &&
cmap4->glyphIdArray[index1] != 0 )
return ( charCode );
charCode++;
}
return 0;
}
1999-12-17 00:11:37 +01:00
/*************************************************************************/
/* */
/* <Function> */
/* code_to_index6 */
/* */
/* <Description> */
/* Converts the character code into a glyph index. Uses format 6. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* cmap6 :: A pointer to a cmap table in format 6. */
/* */
/* <Return> */
/* Glyph index into the glyphs array. 0 if the glyph does not exist. */
1999-12-17 00:11:37 +01:00
/* */
2001-06-28 01:25:46 +02:00
FT_CALLBACK_DEF( FT_UInt )
code_to_index6( TT_CMapTable cmap,
FT_ULong charCode )
1999-12-17 00:11:37 +01:00
{
TT_CMap6 cmap6;
FT_UInt result = 0;
1999-12-17 00:11:37 +01:00
1999-12-17 00:11:37 +01:00
cmap6 = &cmap->c.cmap6;
charCode -= cmap6->firstCode;
if ( charCode < (FT_UInt)cmap6->entryCount )
result = cmap6->glyphIdArray[charCode];
return result;
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_next6 */
/* */
/* <Description> */
/* Find the next encoded character. Uses format 6. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* cmap :: A pointer to a cmap table in format 6. */
/* */
/* <Return> */
/* Next encoded character. 0 if none exists. */
/* */
FT_CALLBACK_DEF( FT_ULong )
code_to_next6( TT_CMapTable cmap,
FT_ULong charCode )
{
TT_CMap6 cmap6;
charCode++;
cmap6 = &cmap->c.cmap6;
2002-02-06 12:22:01 +01:00
if ( charCode < (FT_ULong) cmap6->firstCode )
charCode = cmap6->firstCode;
charCode -= cmap6->firstCode;
while ( charCode < (FT_UInt)cmap6->entryCount )
{
if ( cmap6->glyphIdArray[charCode] != 0 )
return charCode + cmap6->firstCode;
charCode++;
}
return 0;
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_index8_12 */
/* */
/* <Description> */
/* Converts the (possibly 32bit) character code into a glyph index. */
/* Uses format 8 or 12. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* cmap8_12 :: A pointer to a cmap table in format 8 or 12. */
/* */
/* <Return> */
/* Glyph index into the glyphs array. 0 if the glyph does not exist. */
/* */
FT_CALLBACK_DEF( FT_UInt )
code_to_index8_12( TT_CMapTable cmap,
FT_ULong charCode )
{
TT_CMap8_12 cmap8_12;
TT_CMapGroupRec *group, *limit;
cmap8_12 = &cmap->c.cmap8_12;
limit = cmap8_12->groups + cmap8_12->nGroups;
/* first, check against the last used group */
group = cmap8_12->last_group;
/* the following is equivalent to performing two tests, as in */
/* */
/* if ( charCode >= group->startCharCode && */
/* charCode <= group->endCharCode ) */
/* */
/* This is a bit strange, but it is faster, and the idea behind the */
/* cache is to significantly speed up charcode to glyph index */
/* conversion. */
if ( (FT_ULong)( charCode - group->startCharCode ) <
(FT_ULong)( group->endCharCode - group->startCharCode ) )
goto Found1;
for ( group = cmap8_12->groups; group < limit; group++ )
{
/* the ranges are sorted in increasing order. If we are out of */
/* the range here, the char code isn't in the charmap, so exit. */
if ( charCode > group->endCharCode )
continue;
if ( charCode >= group->startCharCode )
goto Found;
}
return 0;
Found:
cmap8_12->last_group = group;
Found1:
return group->startGlyphID + (FT_UInt)( charCode - group->startCharCode );
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_next8_12 */
/* */
/* <Description> */
/* Find the next encoded character. Uses format 8 or 12. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* cmap :: A pointer to a cmap table in format 8 or 12. */
/* */
/* <Return> */
/* Next encoded character. 0 if none exists. */
/* */
FT_CALLBACK_DEF( FT_ULong )
code_to_next8_12( TT_CMapTable cmap,
FT_ULong charCode )
{
TT_CMap8_12 cmap8_12;
TT_CMapGroupRec *group, *limit;
charCode++;
cmap8_12 = &cmap->c.cmap8_12;
limit = cmap8_12->groups + cmap8_12->nGroups;
for ( group = cmap8_12->groups; group < limit; group++ )
{
/* the ranges are sorted in increasing order. If we are out of */
/* the range here, the char code isn't in the charmap, so exit. */
if ( charCode <= group->endCharCode )
goto Found;
}
return 0;
Found:
if ( charCode < group->startCharCode )
charCode = group->startCharCode;
return charCode;
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_index10 */
/* */
/* <Description> */
/* Converts the (possibly 32bit) character code into a glyph index. */
/* Uses format 10. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* cmap10 :: A pointer to a cmap table in format 10. */
/* */
/* <Return> */
/* Glyph index into the glyphs array. 0 if the glyph does not exist. */
/* */
FT_CALLBACK_DEF( FT_UInt )
code_to_index10( TT_CMapTable cmap,
FT_ULong charCode )
{
TT_CMap10 cmap10;
FT_UInt result = 0;
cmap10 = &cmap->c.cmap10;
charCode -= cmap10->startCharCode;
/* the overflow trick for comparison works here also since the number */
/* of glyphs (even if numChars is specified as ULong in the specs) in */
/* an OpenType font is limited to 64k */
if ( charCode < cmap10->numChars )
result = cmap10->glyphs[charCode];
1999-12-17 00:11:37 +01:00
return result;
}
/*************************************************************************/
/* */
/* <Function> */
/* code_to_next10 */
/* */
/* <Description> */
/* Find the next encoded character. Uses format 10. */
/* */
/* <Input> */
/* charCode :: The wanted character code. */
/* cmap :: A pointer to a cmap table in format 10. */
/* */
/* <Return> */
/* Next encoded character. 0 if none exists. */
/* */
FT_CALLBACK_DEF( FT_ULong )
code_to_next10( TT_CMapTable cmap,
FT_ULong charCode )
{
TT_CMap10 cmap10;
charCode++;
cmap10 = &cmap->c.cmap10;
if ( charCode < cmap10->startCharCode )
charCode = cmap10->startCharCode;
charCode -= cmap10->startCharCode;
/* the overflow trick for comparison works here also since the number */
/* of glyphs (even if numChars is specified as ULong in the specs) in */
/* an OpenType font is limited to 64k */
while ( charCode < cmap10->numChars )
{
if ( cmap10->glyphs[charCode] )
return ( charCode + cmap10->startCharCode );
charCode++;
}
return 0;
}
1999-12-17 00:11:37 +01:00
/* END */