freetype2/src/gxvalid/gxvmorx5.c

198 lines
7.8 KiB
C
Raw Normal View History

Add gxvalid module to validate TrueType GX/AAT tables. Modifications on existing files: * Jamfile: Register gxvalid module. * src/base/Jamfile: Register ftgxval.c. * src/base/rule.mk: Register ftgxval.c. * docs/INSTALL.ANY: Register gxvalid/gxvalid.c. * include/freetype/config/ftheader.h: Add macro to include gxvalid header file, FT_GX_VALIDATE_H. * include/freetype/config/ftmodule.h: Register gxv_module_class. * include/freetype/ftchapters.h: Add comment about gx_validation. * include/freetype/ftotval.h: Change keyword FT_VALIDATE_XXX to FT_VALIDATE_OTXXX to co-exist gxvalid. * include/freetype/tttags.h: Add tag for TrueType GX/AAT tables. * include/freetype/internal/ftserv.h: Add macro to use gxvalid service, FT_SERVICE_GX_VALIDATE_H * include/freetype/internal/fttrace.h: Add trace facilities for gxvalid. New files on existing directories: * include/freetype/internal/services/svgxval.h: Registration of validation service for TrueType GX/AAT and classic kern table. * include/freetype/ftgxval.h: Public API definition to use gxvalid. * src/base/ftgxval.c: Public API of gxvalid. New files under src/gxvalid/: * src/gxvalid/Jamfile src/gxvalid/README src/gxvalid/module.mk src/gxvalid/rules.mk src/gxvalid/gxvalid.c src/gxvalid/gxvalid.h src/gxvalid/gxvbsln.c src/gxvalid/gxvcommn.c src/gxvalid/gxvcommn.h src/gxvalid/gxverror.h src/gxvalid/gxvfeat.c src/gxvalid/gxvfgen.c src/gxvalid/gxvjust.c src/gxvalid/gxvkern.c src/gxvalid/gxvlcar.c src/gxvalid/gxvmod.c src/gxvalid/gxvmod.h src/gxvalid/gxvmort.c src/gxvalid/gxvmort.h src/gxvalid/gxvmort0.c src/gxvalid/gxvmort1.c src/gxvalid/gxvmort2.c src/gxvalid/gxvmort4.c src/gxvalid/gxvmort5.c src/gxvalid/gxvmorx.c src/gxvalid/gxvmorx.h src/gxvalid/gxvmorx0.c src/gxvalid/gxvmorx1.c src/gxvalid/gxvmorx2.c src/gxvalid/gxvmorx4.c src/gxvalid/gxvmorx5.c src/gxvalid/gxvopbd.c src/gxvalid/gxvprop.c src/gxvalid/gxvtrak.c: New files, gxvalid body.
2005-08-24 06:31:31 +02:00
/***************************************************************************/
/* */
/* gxvmorx5.c */
/* */
/* TrueTypeGX/AAT morx table validation */
/* body for type5 (Contextual Glyph Insertion) subtable. */
/* */
/* Copyright 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
/* 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* gxvalid is derived from both gxlayout module and otvalid module. */
/* Development of gxlayout was support of Information-technology Promotion */
/* Agency(IPA), Japan. */
/***************************************************************************/
#include "gxvmorx.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_gxvmorx
/*
* morx subtable type5 (Contextual Glyph Insertion)
* has format of StateTable with insertion-glyph-list
* without name. however, 32bit offset from the head
* of subtable to the i-g-l is given after "entryTable",
* without variable name specification (the exist of
* offset to the table is different from mort type5).
*/
typedef struct GXV_morx_subtable_type5_StateOptRec_
{
FT_ULong insertionGlyphList;
FT_ULong insertionGlyphList_length;
} GXV_morx_subtable_type5_StateOptRec,
*GXV_morx_subtable_type5_StateOptRecData;
#define GXV_MORX_SUBTABLE_TYPE5_HEADER_SIZE ( GXV_STATETABLE_HEADER_SIZE + 4 )
static void
gxv_morx_subtable_type5_insertionGlyphList_load( FT_Bytes table,
FT_Bytes limit,
GXV_Validator valid )
{
FT_Bytes p = table;
GXV_morx_subtable_type5_StateOptRecData optdata = valid->xstatetable.optdata;
GXV_LIMIT_CHECK( 4 );
optdata->insertionGlyphList = FT_NEXT_ULONG( p );
}
static void
gxv_morx_subtable_type5_subtable_setup( FT_ULong table_size,
FT_ULong classTable,
FT_ULong stateArray,
FT_ULong entryTable,
FT_ULong* classTable_length_p,
FT_ULong* stateArray_length_p,
FT_ULong* entryTable_length_p,
GXV_Validator valid )
{
FT_ULong o[4];
FT_ULong* l[4];
FT_ULong buff[5];
GXV_morx_subtable_type5_StateOptRecData optdata = valid->xstatetable.optdata;
o[0] = classTable;
o[1] = stateArray;
o[2] = entryTable;
o[3] = optdata->insertionGlyphList;
l[0] = classTable_length_p;
l[1] = stateArray_length_p;
l[2] = entryTable_length_p;
l[3] = &(optdata->insertionGlyphList_length);
gxv_set_length_by_ulong_offset( o, l, buff, 4, table_size, valid );
}
static void
gxv_morx_subtable_type5_InsertList_validate( FT_UShort index,
FT_UShort count,
FT_Bytes table,
FT_Bytes limit,
GXV_Validator valid )
{
FT_Bytes p = table + ( index * 2 );
while ( p < table + ( count * 2 ) + ( index * 2 ) )
{
FT_UShort insert_glyphID;
GXV_LIMIT_CHECK( 2 );
insert_glyphID = FT_NEXT_USHORT( p );
GXV_TRACE(( " 0x%04x", insert_glyphID ));
}
GXV_TRACE(( "\n" ));
}
static void
gxv_morx_subtable_type5_entry_validate( FT_UShort state,
FT_UShort flags,
GXV_StateTable_GlyphOffsetDesc
glyphOffset,
FT_Bytes table,
FT_Bytes limit,
GXV_Validator valid )
{
FT_Bool setMark;
FT_Bool dontAdvance;
FT_Bool currentIsKashidaLike;
FT_Bool markedIsKashidaLike;
FT_Bool currentInsertBefore;
FT_Bool markedInsertBefore;
FT_Bool currentInsertCount;
FT_Byte markedInsertCount;
FT_Byte currentInsertList;
FT_UShort markedInsertList;
setMark = ( flags >> 15 ) & 1;
dontAdvance = ( flags >> 14 ) & 1;
currentIsKashidaLike = ( flags >> 13 ) & 1;
markedIsKashidaLike = ( flags >> 12 ) & 1;
currentInsertBefore = ( flags >> 11 ) & 1;
markedInsertBefore = ( flags >> 10 ) & 1;
currentInsertCount = ( flags & 0x03E0 ) / 0x20;
markedInsertCount = ( flags & 0x001F );
currentInsertList = glyphOffset.ul / 0x00010000;
markedInsertList = glyphOffset.ul & 0x0000FFFF;
if ( currentInsertList && 0 != currentInsertCount )
{
gxv_morx_subtable_type5_InsertList_validate( currentInsertList,
currentInsertCount,
table, limit,
valid );
}
if ( markedInsertList && 0 != markedInsertCount )
{
gxv_morx_subtable_type5_InsertList_validate( markedInsertList,
markedInsertCount,
table, limit,
valid );
}
}
static void
gxv_morx_subtable_type5_validate( FT_Bytes table,
FT_Bytes limit,
GXV_Validator valid )
{
FT_Bytes p = table;
GXV_morx_subtable_type5_StateOptRec et_rec;
GXV_morx_subtable_type5_StateOptRecData et = &et_rec;
GXV_NAME_ENTER( "morx chain subtable type5 (Glyph Insertion)" );
GXV_LIMIT_CHECK( GXV_MORX_SUBTABLE_TYPE5_HEADER_SIZE );
valid->xstatetable.optdata = et;
valid->xstatetable.optdata_load_func = gxv_morx_subtable_type5_insertionGlyphList_load;
valid->xstatetable.subtable_setup_func = gxv_morx_subtable_type5_subtable_setup;
valid->xstatetable.entry_glyphoffset_fmt = GXV_GLYPHOFFSET_ULONG;
valid->xstatetable.entry_validate_func = gxv_morx_subtable_type5_entry_validate;
gxv_XStateTable_validate( p, limit, valid );
GXV_EXIT;
}
/* END */