2007-06-11 06:55:58 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ftpatent.c */
|
|
|
|
/* */
|
|
|
|
/* FreeType API for checking patented TrueType bytecode instructions */
|
|
|
|
/* (body). */
|
|
|
|
/* */
|
2010-01-05 20:00:35 +01:00
|
|
|
/* Copyright 2007, 2008, 2010 by David Turner. */
|
2007-06-11 06:55:58 +02:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2007-06-11 02:26:25 +02:00
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_FREETYPE_H
|
|
|
|
#include FT_TRUETYPE_TAGS_H
|
|
|
|
#include FT_INTERNAL_OBJECTS_H
|
|
|
|
#include FT_INTERNAL_STREAM_H
|
|
|
|
#include FT_SERVICE_SFNT_H
|
|
|
|
#include FT_SERVICE_TRUETYPE_GLYF_H
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
|
2007-06-11 02:26:25 +02:00
|
|
|
static FT_Bool
|
|
|
|
_tt_check_patents_in_range( FT_Stream stream,
|
|
|
|
FT_ULong size )
|
|
|
|
{
|
2007-06-11 06:55:58 +02:00
|
|
|
FT_Bool result = FALSE;
|
2007-06-11 02:26:25 +02:00
|
|
|
FT_Error error;
|
|
|
|
FT_Bytes p, end;
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
|
|
|
|
if ( FT_FRAME_ENTER( size ) )
|
2007-06-11 02:26:25 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
p = stream->cursor;
|
|
|
|
end = p + size;
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
while ( p < end )
|
2007-06-11 02:26:25 +02:00
|
|
|
{
|
|
|
|
switch (p[0])
|
|
|
|
{
|
|
|
|
case 0x06: /* SPvTL // */
|
|
|
|
case 0x07: /* SPvTL + */
|
|
|
|
case 0x08: /* SFvTL // */
|
|
|
|
case 0x09: /* SFvTL + */
|
2007-06-11 06:55:58 +02:00
|
|
|
case 0x0A: /* SPvFS */
|
|
|
|
case 0x0B: /* SFvFS */
|
|
|
|
result = TRUE;
|
2007-06-11 02:26:25 +02:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
case 0x40:
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( p + 1 >= end )
|
2007-06-11 02:26:25 +02:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
p += p[1] + 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x41:
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( p + 1 >= end )
|
2007-06-11 02:26:25 +02:00
|
|
|
goto Exit;
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
p += p[1] * 2 + 2;
|
2007-06-11 02:26:25 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x71: /* DELTAP2 */
|
|
|
|
case 0x72: /* DELTAP3 */
|
|
|
|
case 0x73: /* DELTAC0 */
|
|
|
|
case 0x74: /* DELTAC1 */
|
|
|
|
case 0x75: /* DELTAC2 */
|
2007-06-11 06:55:58 +02:00
|
|
|
result = TRUE;
|
2007-06-11 02:26:25 +02:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
case 0xB0:
|
|
|
|
case 0xB1:
|
|
|
|
case 0xB2:
|
|
|
|
case 0xB3:
|
|
|
|
case 0xB4:
|
|
|
|
case 0xB5:
|
|
|
|
case 0xB6:
|
|
|
|
case 0xB7:
|
2007-06-11 06:55:58 +02:00
|
|
|
p += ( p[0] - 0xB0 ) + 2;
|
2007-06-11 02:26:25 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xB8:
|
|
|
|
case 0xB9:
|
|
|
|
case 0xBA:
|
|
|
|
case 0xBB:
|
|
|
|
case 0xBC:
|
|
|
|
case 0xBD:
|
|
|
|
case 0xBE:
|
|
|
|
case 0xBF:
|
2007-06-11 06:55:58 +02:00
|
|
|
p += ( p[0] - 0xB8 ) * 2 + 3;
|
2007-06-11 02:26:25 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
p += 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
2009-07-31 17:30:12 +02:00
|
|
|
FT_UNUSED( error );
|
2007-06-11 02:26:25 +02:00
|
|
|
FT_FRAME_EXIT();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static FT_Bool
|
|
|
|
_tt_check_patents_in_table( FT_Face face,
|
|
|
|
FT_ULong tag )
|
|
|
|
{
|
|
|
|
FT_Stream stream = face->stream;
|
2010-01-05 20:00:35 +01:00
|
|
|
FT_Error error = FT_Err_Ok;
|
2007-06-11 02:26:25 +02:00
|
|
|
FT_Service_SFNT_Table service;
|
2007-06-11 06:55:58 +02:00
|
|
|
FT_Bool result = FALSE;
|
|
|
|
|
2007-06-11 02:26:25 +02:00
|
|
|
|
|
|
|
FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( service )
|
2007-06-11 02:26:25 +02:00
|
|
|
{
|
2009-06-28 20:09:17 +02:00
|
|
|
FT_UInt i = 0;
|
2010-01-05 20:48:57 +01:00
|
|
|
FT_ULong tag_i = 0, offset_i = 0, length_i = 0;
|
2010-01-05 20:00:35 +01:00
|
|
|
|
2007-06-11 02:26:25 +02:00
|
|
|
|
2009-06-28 20:09:17 +02:00
|
|
|
for ( i = 0; !error && tag_i != tag ; i++ )
|
|
|
|
error = service->table_info( face, i,
|
|
|
|
&tag_i, &offset_i, &length_i );
|
2007-06-11 06:55:58 +02:00
|
|
|
|
2010-01-05 20:00:35 +01:00
|
|
|
if ( error ||
|
2009-06-28 20:09:17 +02:00
|
|
|
FT_STREAM_SEEK( offset_i ) )
|
2007-06-11 02:26:25 +02:00
|
|
|
goto Exit;
|
|
|
|
|
2009-06-28 20:09:17 +02:00
|
|
|
result = _tt_check_patents_in_range( stream, length_i );
|
2007-06-11 02:26:25 +02:00
|
|
|
}
|
2007-06-11 06:55:58 +02:00
|
|
|
|
2007-06-11 02:26:25 +02:00
|
|
|
Exit:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static FT_Bool
|
|
|
|
_tt_face_check_patents( FT_Face face )
|
|
|
|
{
|
|
|
|
FT_Stream stream = face->stream;
|
|
|
|
FT_UInt gindex;
|
|
|
|
FT_Error error;
|
|
|
|
FT_Bool result;
|
|
|
|
|
|
|
|
FT_Service_TTGlyf service;
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
|
2007-06-11 02:26:25 +02:00
|
|
|
result = _tt_check_patents_in_table( face, TTAG_fpgm );
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( result )
|
2007-06-11 02:26:25 +02:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
result = _tt_check_patents_in_table( face, TTAG_prep );
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( result )
|
2007-06-11 02:26:25 +02:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
FT_FACE_FIND_SERVICE( face, service, TT_GLYF );
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( service == NULL )
|
2007-06-11 02:26:25 +02:00
|
|
|
goto Exit;
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
for ( gindex = 0; gindex < (FT_UInt)face->num_glyphs; gindex++ )
|
2007-06-11 02:26:25 +02:00
|
|
|
{
|
|
|
|
FT_ULong offset, num_ins, size;
|
|
|
|
FT_Int num_contours;
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
|
2007-06-11 02:26:25 +02:00
|
|
|
offset = service->get_location( face, gindex, &size );
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( size == 0 )
|
2007-06-11 02:26:25 +02:00
|
|
|
continue;
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( FT_STREAM_SEEK( offset ) ||
|
|
|
|
FT_READ_SHORT( num_contours ) )
|
2007-06-11 02:26:25 +02:00
|
|
|
continue;
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( num_contours >= 0 ) /* simple glyph */
|
2007-06-11 02:26:25 +02:00
|
|
|
{
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( FT_STREAM_SKIP( 8 + num_contours * 2 ) )
|
2007-06-11 02:26:25 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else /* compound glyph */
|
|
|
|
{
|
|
|
|
FT_Bool has_instr = 0;
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
|
2007-06-11 02:26:25 +02:00
|
|
|
if ( FT_STREAM_SKIP( 8 ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* now read each component */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
FT_UInt flags, toskip;
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
|
|
|
|
if( FT_READ_USHORT( flags ) )
|
2007-06-11 02:26:25 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
toskip = 2 + 1 + 1;
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( ( flags & ( 1 << 0 ) ) != 0 ) /* ARGS_ARE_WORDS */
|
2007-06-11 02:26:25 +02:00
|
|
|
toskip += 2;
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( ( flags & ( 1 << 3 ) ) != 0 ) /* WE_HAVE_A_SCALE */
|
2007-06-11 02:26:25 +02:00
|
|
|
toskip += 2;
|
2007-06-11 06:55:58 +02:00
|
|
|
else if ( ( flags & ( 1 << 6 ) ) != 0 ) /* WE_HAVE_X_Y_SCALE */
|
2007-06-11 02:26:25 +02:00
|
|
|
toskip += 4;
|
2007-06-11 06:55:58 +02:00
|
|
|
else if ( ( flags & ( 1 << 7 ) ) != 0 ) /* WE_HAVE_A_2x2 */
|
2007-06-11 02:26:25 +02:00
|
|
|
toskip += 8;
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( ( flags & ( 1 << 8 ) ) != 0 ) /* WE_HAVE_INSTRUCTIONS */
|
2007-06-11 02:26:25 +02:00
|
|
|
has_instr = 1;
|
|
|
|
|
|
|
|
if ( FT_STREAM_SKIP( toskip ) )
|
|
|
|
goto NextGlyph;
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( ( flags & ( 1 << 5 ) ) == 0 ) /* MORE_COMPONENTS */
|
2007-06-11 02:26:25 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-06-11 06:55:58 +02:00
|
|
|
|
|
|
|
if ( !has_instr )
|
2007-06-11 02:26:25 +02:00
|
|
|
goto NextGlyph;
|
|
|
|
}
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( FT_READ_USHORT( num_ins ) )
|
2007-06-11 02:26:25 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
result = _tt_check_patents_in_range( stream, num_ins );
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( result )
|
2007-06-11 02:26:25 +02:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
NextGlyph:
|
|
|
|
;
|
|
|
|
}
|
2007-06-11 06:55:58 +02:00
|
|
|
|
2007-06-11 02:26:25 +02:00
|
|
|
Exit:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
|
|
|
|
/* documentation is in freetype.h */
|
|
|
|
|
2007-06-11 02:26:25 +02:00
|
|
|
FT_EXPORT_DEF( FT_Bool )
|
2007-06-11 06:55:58 +02:00
|
|
|
FT_Face_CheckTrueTypePatents( FT_Face face )
|
2007-06-11 02:26:25 +02:00
|
|
|
{
|
2007-06-11 06:55:58 +02:00
|
|
|
FT_Bool result = FALSE;
|
2007-06-11 02:26:25 +02:00
|
|
|
|
2007-07-01 11:51:15 +02:00
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
if ( face && FT_IS_SFNT( face ) )
|
2007-06-11 02:26:25 +02:00
|
|
|
result = _tt_face_check_patents( face );
|
2007-06-11 06:55:58 +02:00
|
|
|
|
|
|
|
return result;
|
2007-06-11 02:26:25 +02:00
|
|
|
}
|
2007-06-11 06:55:58 +02:00
|
|
|
|
|
|
|
|
2007-07-02 16:58:58 +02:00
|
|
|
/* documentation is in freetype.h */
|
|
|
|
|
2007-07-01 11:51:15 +02:00
|
|
|
FT_EXPORT_DEF( FT_Bool )
|
2007-07-02 16:58:58 +02:00
|
|
|
FT_Face_SetUnpatentedHinting( FT_Face face,
|
|
|
|
FT_Bool value )
|
2007-07-01 11:51:15 +02:00
|
|
|
{
|
2008-12-11 09:55:48 +01:00
|
|
|
FT_Bool result = FALSE;
|
2007-07-01 11:51:15 +02:00
|
|
|
|
2007-07-02 16:58:58 +02:00
|
|
|
|
|
|
|
#if defined( TT_CONFIG_OPTION_UNPATENTED_HINTING ) && \
|
2011-07-20 06:30:20 +02:00
|
|
|
!defined( TT_CONFIG_OPTION_BYTECODE_INTERPRETER )
|
2007-07-02 16:58:58 +02:00
|
|
|
if ( face && FT_IS_SFNT( face ) )
|
2007-07-01 11:51:15 +02:00
|
|
|
{
|
|
|
|
result = !face->internal->ignore_unpatented_hinter;
|
|
|
|
face->internal->ignore_unpatented_hinter = !value;
|
|
|
|
}
|
|
|
|
#else
|
2007-07-02 16:58:58 +02:00
|
|
|
FT_UNUSED( face );
|
|
|
|
FT_UNUSED( value );
|
2007-07-01 11:51:15 +02:00
|
|
|
#endif
|
|
|
|
|
2007-07-02 16:58:58 +02:00
|
|
|
return result;
|
2007-07-01 11:51:15 +02:00
|
|
|
}
|
|
|
|
|
2007-06-11 06:55:58 +02:00
|
|
|
/* END */
|