freetype2/src/gxvalid/gxvopbd.c

206 lines
7.4 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
/***************************************************************************/
/* */
/* gxvopbd.c */
/* */
/* TrueTypeGX/AAT opbd table validation (body). */
/* */
/* Copyright 2004, 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. */
/* */
/***************************************************************************/
#include "gxvalid.h"
#include "gxvcommn.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_gxvopbd
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** Data and Types *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
typedef struct GXV_opbd_DataRec_
{
FT_UShort format;
FT_UShort valueOffset_min;
} GXV_opbd_DataRec, *GXV_opbd_Data;
#define GXV_OPBD_DATA(FIELD) GXV_TABLE_DATA( opbd, FIELD )
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** UTILITY FUNCTIONS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
static void
gxv_opbd_LookupValue_validate( FT_UShort glyph,
GXV_LookupValueDesc value,
GXV_Validator valid )
{
/* offset in LookupTable is measured from the head of opbd table */
FT_Bytes p = valid->root->base + value.u;
FT_Bytes limit = valid->root->limit;
FT_Short delta_value;
int i;
if ( value.u < GXV_OPBD_DATA( valueOffset_min ) )
GXV_OPBD_DATA( valueOffset_min ) = value.u;
for ( i = 0; i < 4; i++ )
{
GXV_LIMIT_CHECK( 2 );
delta_value = FT_NEXT_SHORT( p );
if ( GXV_OPBD_DATA( format ) ) /* format 1, value is ctrl pt. */
{
if ( delta_value == -1 )
continue;
gxv_ctlPoint_validate( glyph, delta_value, valid );
}
else /* format 0, value is distance */
continue;
}
}
/*
opbd ---------------------+
|
+===============+ |
| lookup header | |
+===============+ |
| BinSrchHeader | |
+===============+ |
| lastGlyph[0] | |
+---------------+ |
| firstGlyph[0] | | head of opbd sfnt table
+---------------+ | +
| offset[0] | -> | offset [byte]
+===============+ | +
| lastGlyph[1] | | (glyphID - firstGlyph) * 4 * sizeof(FT_Short) [byte]
+---------------+ |
| firstGlyph[1] | |
+---------------+ |
| offset[1] | |
+===============+ |
|
.... |
|
48bit value array |
+===============+ |
| value | <-------+
| |
| |
| |
+---------------+
.... */
static GXV_LookupValueDesc
gxv_opbd_LookupFmt4_transit( FT_UShort relative_gindex,
GXV_LookupValueDesc base_value,
FT_Bytes lookuptbl_limit,
GXV_Validator valid )
{
GXV_LookupValueDesc value;
value.u = base_value.u + ( relative_gindex * 4 * sizeof ( FT_Short ) );
return value;
}
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** opbd TABLE *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
FT_LOCAL_DEF( void )
gxv_opbd_validate( FT_Bytes table,
FT_Face face,
FT_Validator ftvalid )
{
GXV_ValidatorRec validrec;
GXV_Validator valid = &validrec;
GXV_opbd_DataRec opbdrec;
GXV_opbd_Data opbd = &opbdrec;
FT_Bytes p = table;
FT_Bytes limit = 0;
FT_ULong version;
valid->root = ftvalid;
valid->table_data = opbd;
valid->face = face;
FT_TRACE3(( "validation opbd table\n" ));
GXV_INIT;
GXV_OPBD_DATA( valueOffset_min ) = 0xFFFF;
GXV_LIMIT_CHECK( 4 + 2 );
version = FT_NEXT_ULONG( p );
GXV_OPBD_DATA( format ) = FT_NEXT_USHORT( p );
/* 0x00010000 is only defined (1996) */
GXV_TRACE(( "(version=0x%08x)\n", version ));
if ( 0x00010000UL != version )
FT_INVALID_FORMAT;
/* 0, 1 are only defined (1996) */
GXV_TRACE(( "(format=0x%04x)\n", GXV_OPBD_DATA( format ) ));
if ( 0x0001 < GXV_OPBD_DATA( format ) )
FT_INVALID_FORMAT;
valid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED;
valid->lookupval_func = gxv_opbd_LookupValue_validate;
valid->lookupfmt4_trans = gxv_opbd_LookupFmt4_transit;
gxv_LookupTable_validate( p, limit, valid );
p += valid->subtable_length;
if ( p > table + GXV_OPBD_DATA( valueOffset_min ) )
{
GXV_TRACE(( "found overlap between LookupTable and opbd_value array\n" ));
FT_INVALID_OFFSET;
}
FT_TRACE4(( "\n" ));
}
/* END */