* docs/CHANGES: Document FT_Face_CheckTrueTypePatents).

Formatting, reformulations.
This commit is contained in:
Werner Lemberg 2007-06-11 04:55:58 +00:00
parent 7fa30ee879
commit f6c120f826
13 changed files with 175 additions and 98 deletions

View File

@ -1,16 +1,34 @@
2007-06-11 Werner Lemberg <wl@gnu.org>
* docs/CHANGES: Document FT_Face_CheckTrueTypePatents).
2007-06-10 David Turner <david@freetype.org>
* src/truetype/ttgload.c: slight speed-up to the TrueType glyph loader
* src/truetype/ttgload.c (TT_Load_Simple_Glyph): Slight speed-up to
the TrueType glyph loader.
* include/freetype/config/ftoption.h: clarify documentation regarding
unpatented hinting
* include/freetype/config/ftoption.h: Clarify documentation
regarding unpatented hinting.
* include/freetype/freetype.h, src/base/ftpatent.c, src/truetype/ttdriver.c,
include/freetype/internal/services/svttglyf.h, modules.cfg,:
include/freetype/internal/ftserv.h,:
Fonts without a cmap must be handled correctly by FreeType (anything
Adding the FT_Face_CheckTrueTypePatents API to FT_FREETYPE_H, it is
implemented by the optional src/base/ftpatent.c
Add new `FT_Face_CheckTrueTypePatents' API.
* include/freetype/freetype.h (FT_Face_CheckTrueTypePatents): New
declaration.
* include/freetype/internal/services/svttglyf.h,
src/base/ftpatent.c: New files.
* include/freetype/internal/ftserv.h (FT_SERVICE_TRUETYPE_GLYF_H):
New macro.
* src/truetype/ttdriver.c: Include FT_SERVICE_TRUETYPE_GLYF_H and
`ttpload.h'.
(tt_service_truetype_glyf): New service structure.
(tt_services): Register it.
* modules.cfg (BASE_EXTENSIONS), src/base/Jamfile (_sources): Add
`ftpatent.c'.
2007-06-08 Werner Lemberg <wl@gnu.org>

View File

@ -28,6 +28,10 @@ CHANGES BETWEEN 2.3.5 and 2.3.4
hinting module as the default instead of the Latin one. Thanks
to Rahul Bhalerao for this suggestion.
- A new API `FT_Face_CheckTrueTypePatents' has been added to find
out whether a given TrueType font uses patented bytecode
instructions.
III. MISCELLANEOUS

View File

@ -463,26 +463,47 @@ FT_BEGIN_HEADER
/*************************************************************************/
/* */
/* The TT_CONFIG_OPTION_UNPATENTED_HINTING macro is *ignored* if you */
/* have defined TT_CONFIG_OPTION_BYTECODE_INTERPRETER. If not, it will */
/* compile a special work-around TrueType bytecode interpreter that */
/* doesn't implement any of the patented opcodes/algorithms. */
/* If you define TT_CONFIG_OPTION_UNPATENTED_HINTING, a special version */
/* of the TrueType bytecode interpreter is used that doesn't implement */
/* any of the patented opcodes and algorithms. Note that the */
/* the TT_CONFIG_OPTION_UNPATENTED_HINTING macro is *ignored* if you */
/* define TT_CONFIG_OPTION_BYTECODE_INTERPRETER; with other words, */
/* either define TT_CONFIG_OPTION_BYTECODE_INTERPRETER or */
/* TT_CONFIG_OPTION_UNPATENTED_HINTING but not both at the same time. */
/* */
/* this is only useful for a small number of font files (mostly Asian) */
/* that require bytecode interpretation to properly load glyphs. For all */
/* other fonts, this will produce unpleasant results. */
/* This macro is only useful for a small number of font files (mostly */
/* for Asian scripts) that require bytecode interpretation to properly */
/* load glyphs. For all other fonts, this produces unpleasant results, */
/* thus the unpatented interpreter is never used to load glyphs from */
/* TrueType fonts unless one of the following two options is used. */
/* */
/* for this reason, the unpatented interpreter is never used by to load */
/* glyphs from TrueType fonts, unless one of the following happens: */
/* */
/* - the unpatented interpreter is explicitely activated by the */
/* user through the FT_PARAM_TAG_UNPATENTED_HINTING parameter tag */
/* when opening the FT_Face */
/* - The unpatented interpreter is explicitly activated by the user */
/* through the FT_PARAM_TAG_UNPATENTED_HINTING parameter tag */
/* when opening the FT_Face. */
/* */
/* - FreeType detects that the FT_Face corresponds to one of the */
/* 'trick' fonts (e.g. Mingliu) it knows about. The font engine */
/* `trick' fonts (e.g., `Mingliu') it knows about. The font engine */
/* contains a hard-coded list of font names and other matching */
/* parameters. */
/* parameters (see function `tt_face_init' in file */
/* `src/truetype/ttobjs.c'). */
/* */
/* Here a sample code snippet for using FT_PARAM_TAG_UNPATENTED_HINTING. */
/* */
/* { */
/* FT_Parameter parameter; */
/* FT_Open_Args open_args; */
/* */
/* */
/* parameter.tag = FT_PARAM_TAG_UNPATENTED_HINTING; */
/* */
/* open_args.flags = FT_OPEN_PATHNAME | FT_OPEN_PARAMS; */
/* open_args.pathname = my_font_pathname; */
/* open_args.num_params = 1; */
/* open_args.params = &parameter; */
/* */
/* error = FT_Open_Face( library, &open_args, index, &face ); */
/* ... */
/* } */
/* */
#define TT_CONFIG_OPTION_UNPATENTED_HINTING

View File

@ -2738,8 +2738,7 @@ FT_BEGIN_HEADER
/* */
/* <Description> */
/* Retrieve the ASCII name of a given glyph in a face. This only */
/* works for those faces where @FT_HAS_GLYPH_NAMES(face) returns */
/* TRUE. */
/* works for those faces where @FT_HAS_GLYPH_NAMES(face) returns 1. */
/* */
/* <Input> */
/* face :: A handle to a source face object. */
@ -3375,23 +3374,23 @@ FT_BEGIN_HEADER
/* FT_Face_CheckTrueTypePatents */
/* */
/* <Description> */
/* Parses the whole content of a TrueType font file and returns */
/* true if it uses any of the patented opcodes. this is only useful */
/* Parse all bytecode instructions of a TrueType font file to check */
/* whether any of the patented opcodes are used. This is only useful */
/* if you want to be able to use the unpatented hinter with */
/* fonts that do *not* use these opcodes. */
/* */
/* note that this function parses *all* glyph instructions in the */
/* font file, and may be *slow* */
/* Note that this function parses *all* glyph instructions in the */
/* font file, which may be slow. */
/* */
/* <Input> */
/* face :: a face handle */
/* face :: A face handle. */
/* */
/* <Return> */
/* TRUE if this is a TrueType font that uses one of the patented */
/* opcodes. FALSE otherwise */
/* 1 if this is a TrueType font that uses one of the patented */
/* opcodes, 0 otherwise. */
/* */
FT_EXPORT( FT_Bool )
FT_Face_CheckTrueTypePatents( FT_Face face );
FT_Face_CheckTrueTypePatents( FT_Face face );
/* */

View File

@ -411,14 +411,14 @@ FT_BEGIN_HEADER
/* */
/* height :: The character height. */
/* */
/* pixel :: A Boolean. If TRUE, the `width' and `height' fields */
/* are interpreted as integer pixel character sizes. */
/* pixel :: A Boolean. If 1, the `width' and `height' fields are */
/* interpreted as integer pixel character sizes. */
/* Otherwise, they are expressed as 1/64th of points. */
/* */
/* x_res :: Only used when `pixel' is FALSE to indicate the */
/* x_res :: Only used when `pixel' is value 0 to indicate the */
/* horizontal resolution in dpi. */
/* */
/* y_res :: Only used when `pixel' is FALSE to indicate the */
/* y_res :: Only used when `pixel' is value 0 to indicate the */
/* vertical resolution in dpi. */
/* */
/* <Note> */

View File

@ -297,8 +297,8 @@ FT_BEGIN_HEADER
* The source outline.
*
* opened ::
* A boolean. If TRUE, the outline is treated as an open path
* instead of a closed one.
* A boolean. If 1, the outline is treated as an open path instead
* of a closed one.
*
* @return:
* FreeType error code. 0 means success.
@ -334,7 +334,7 @@ FT_BEGIN_HEADER
* A pointer to the start vector.
*
* open ::
* A boolean. If TRUE, the sub-path is treated as an open one.
* A boolean. If 1, the sub-path is treated as an open one.
*
* @return:
* FreeType error code. 0 means success.
@ -649,7 +649,7 @@ FT_BEGIN_HEADER
* A stroker handle.
*
* destroy ::
* A Boolean. If TRUE, the source glyph object is destroyed
* A Boolean. If 1, the source glyph object is destroyed
* on success.
*
* @return:
@ -682,11 +682,11 @@ FT_BEGIN_HEADER
* A stroker handle.
*
* inside ::
* A Boolean. If TRUE, return the inside border, otherwise
* A Boolean. If 1, return the inside border, otherwise
* the outside border.
*
* destroy ::
* A Boolean. If TRUE, the source glyph object is destroyed
* A Boolean. If 1, the source glyph object is destroyed
* on success.
*
* @return:

View File

@ -4,7 +4,7 @@
/* */
/* FreeType simple types definitions (specification only). */
/* */
/* Copyright 1996-2001, 2002, 2004, 2006 by */
/* Copyright 1996-2001, 2002, 2004, 2006, 2007 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -94,7 +94,8 @@ FT_BEGIN_HEADER
/* FT_Bool */
/* */
/* <Description> */
/* A typedef of unsigned char, used for simple booleans. */
/* A typedef of unsigned char, used for simple booleans. As usual, */
/* values 1 and 0 represent true and false, respectively. */
/* */
typedef unsigned char FT_Bool;

View File

@ -4,7 +4,7 @@
/* */
/* The FreeType services (specification only). */
/* */
/* Copyright 2003, 2004, 2005, 2006 by */
/* Copyright 2003, 2004, 2005, 2006, 2007 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */

View File

@ -1,6 +1,6 @@
/***************************************************************************/
/* */
/* svsttglyf.h */
/* svttglyf.h */
/* */
/* The FreeType TrueType glyph service. */
/* */
@ -42,7 +42,7 @@ FT_BEGIN_HEADER
FT_END_HEADER
#endif /* __SVTTCMAP_H__ */
#endif /* __SVTTGLYF_H__ */
/* END */

View File

@ -220,7 +220,7 @@ BASE_EXTENSIONS += ftlcdfil.c
# See include/freetype/ftgasp.h for the API.
BASE_EXTENSIONS += ftgasp.c
# Support for FT_Face_CheckTrueTypePatents
# Support for FT_Face_CheckTrueTypePatents.
#
# See include/freetype.h for the API.
BASE_EXTENSIONS += ftpatent.c

View File

@ -1,3 +1,20 @@
/***************************************************************************/
/* */
/* ftpatent.c */
/* */
/* FreeType API for checking patented TrueType bytecode instructions */
/* (body). */
/* */
/* Copyright 2007 by David Turner. */
/* */
/* 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 <ft2build.h>
#include FT_FREETYPE_H
#include FT_TRUETYPE_TAGS_H
@ -6,21 +23,23 @@
#include FT_SERVICE_SFNT_H
#include FT_SERVICE_TRUETYPE_GLYF_H
static FT_Bool
_tt_check_patents_in_range( FT_Stream stream,
FT_ULong size )
{
FT_Bool result = 0;
FT_Bool result = FALSE;
FT_Error error;
FT_Bytes p, end;
if ( FT_FRAME_ENTER(size) )
if ( FT_FRAME_ENTER( size ) )
return 0;
p = stream->cursor;
end = p + size;
while (p < end)
while ( p < end )
{
switch (p[0])
{
@ -28,23 +47,23 @@
case 0x07: /* SPvTL + */
case 0x08: /* SFvTL // */
case 0x09: /* SFvTL + */
case 0x0A: /* SPvFS */
case 0x0B: /* SFvFS */
result = 1;
case 0x0A: /* SPvFS */
case 0x0B: /* SFvFS */
result = TRUE;
goto Exit;
case 0x40:
if ( p+1 >= end )
if ( p + 1 >= end )
goto Exit;
p += p[1] + 2;
break;
case 0x41:
if ( p+1 >= end )
if ( p + 1 >= end )
goto Exit;
p += p[1]*2 + 2;
p += p[1] * 2 + 2;
break;
case 0x71: /* DELTAP2 */
@ -52,7 +71,7 @@
case 0x73: /* DELTAC0 */
case 0x74: /* DELTAC1 */
case 0x75: /* DELTAC2 */
result = 1;
result = TRUE;
goto Exit;
case 0xB0:
@ -63,7 +82,7 @@
case 0xB5:
case 0xB6:
case 0xB7:
p += (p[0] - 0xB0) + 2;
p += ( p[0] - 0xB0 ) + 2;
break;
case 0xB8:
@ -74,7 +93,7 @@
case 0xBD:
case 0xBE:
case 0xBF:
p += (p[0] - 0xB8) * 2 + 3;
p += ( p[0] - 0xB8 ) * 2 + 3;
break;
default:
@ -96,14 +115,16 @@
FT_Stream stream = face->stream;
FT_Error error;
FT_Service_SFNT_Table service;
FT_Bool result = 0;
FT_Bool result = FALSE;
FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
if (service)
if ( service )
{
FT_ULong offset, size;
error = service->table_info( face, tag, &offset, &size );
if ( error ||
FT_STREAM_SEEK( offset ) )
@ -111,6 +132,7 @@
result = _tt_check_patents_in_range( stream, size );
}
Exit:
return result;
}
@ -126,40 +148,43 @@
FT_Service_TTGlyf service;
result = _tt_check_patents_in_table( face, TTAG_fpgm );
if (result)
if ( result )
goto Exit;
result = _tt_check_patents_in_table( face, TTAG_prep );
if (result)
if ( result )
goto Exit;
FT_FACE_FIND_SERVICE( face, service, TT_GLYF );
if (service == NULL)
if ( service == NULL )
goto Exit;
for (gindex = 0; gindex < (FT_UInt)face->num_glyphs; gindex++)
for ( gindex = 0; gindex < (FT_UInt)face->num_glyphs; gindex++ )
{
FT_ULong offset, num_ins, size;
FT_Int num_contours;
offset = service->get_location( face, gindex, &size );
if (size == 0)
if ( size == 0 )
continue;
if ( FT_STREAM_SEEK(offset) ||
FT_READ_SHORT(num_contours) )
if ( FT_STREAM_SEEK( offset ) ||
FT_READ_SHORT( num_contours ) )
continue;
if (num_contours >= 0) /* simple glyph */
if ( num_contours >= 0 ) /* simple glyph */
{
if ( FT_STREAM_SKIP( 8 + num_contours*2 ) )
if ( FT_STREAM_SKIP( 8 + num_contours * 2 ) )
continue;
}
else /* compound glyph */
{
FT_Bool has_instr = 0;
if ( FT_STREAM_SKIP( 8 ) )
continue;
@ -168,56 +193,65 @@
{
FT_UInt flags, toskip;
if( FT_READ_USHORT(flags) )
if( FT_READ_USHORT( flags ) )
break;
toskip = 2 + 1 + 1;
if ((flags & (1 << 0)) != 0) /* ARGS_ARE_WORDS */
if ( ( flags & ( 1 << 0 ) ) != 0 ) /* ARGS_ARE_WORDS */
toskip += 2;
if ((flags & (1 << 3)) != 0) /* WE_HAVE_A_SCALE */
if ( ( flags & ( 1 << 3 ) ) != 0 ) /* WE_HAVE_A_SCALE */
toskip += 2;
else if ((flags & (1 << 6)) != 0) /* WE_HAVE_X_Y_SCALE */
else if ( ( flags & ( 1 << 6 ) ) != 0 ) /* WE_HAVE_X_Y_SCALE */
toskip += 4;
else if ((flags & (1 << 7)) != 0) /* WE_HAVE_A_2x2 */
else if ( ( flags & ( 1 << 7 ) ) != 0 ) /* WE_HAVE_A_2x2 */
toskip += 8;
if ((flags & (1 << 8)) != 0) /* WE_HAVE_INSTRUCTIONS */
if ( ( flags & ( 1 << 8 ) ) != 0 ) /* WE_HAVE_INSTRUCTIONS */
has_instr = 1;
if ( FT_STREAM_SKIP( toskip ) )
goto NextGlyph;
if ((flags & (1 << 5)) == 0) /* MORE_COMPONENTS */
if ( ( flags & ( 1 << 5 ) ) == 0 ) /* MORE_COMPONENTS */
break;
}
if (!has_instr)
if ( !has_instr )
goto NextGlyph;
}
if ( FT_READ_USHORT(num_ins) )
if ( FT_READ_USHORT( num_ins ) )
continue;
result = _tt_check_patents_in_range( stream, num_ins );
if (result)
if ( result )
goto Exit;
NextGlyph:
;
}
Exit:
return result;
}
FT_EXPORT_DEF( FT_Bool )
FT_Face_CheckTrueTypePatents( FT_Face face )
{
FT_Bool result = 0;
if ( face && FT_IS_SFNT(face) )
{
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Bool )
FT_Face_CheckTrueTypePatents( FT_Face face )
{
FT_Bool result = FALSE;
if ( face && FT_IS_SFNT( face ) )
result = _tt_face_check_patents( face );
}
return result;
return result;
}
/* END */

View File

@ -317,7 +317,7 @@
static const FT_Service_TTGlyfRec tt_service_truetype_glyf =
{
(TT_Glyf_GetLocationFunc) tt_face_get_location
(TT_Glyf_GetLocationFunc)tt_face_get_location
};
static const FT_ServiceDescRec tt_services[] =

View File

@ -374,7 +374,7 @@
if ( f & 2 )
{
if (p + 1 > limit)
if ( p + 1 > limit )
goto Invalid_Outline;
y = (FT_Pos)FT_NEXT_BYTE( p );
@ -383,7 +383,7 @@
}
else if ( ( f & 16 ) == 0 )
{
if (p + 2 > limit)
if ( p + 2 > limit )
goto Invalid_Outline;
y = (FT_Pos)FT_NEXT_SHORT( p );
@ -391,7 +391,7 @@
x += y;
vec->x = x;
*flag = f & ~(2|16);
*flag = f & ~( 2 | 16 );
}
/* reading the Y coordinates */
@ -409,7 +409,7 @@
if ( f & 4 )
{
if (p + 1 > limit)
if ( p + 1 > limit )
goto Invalid_Outline;
y = (FT_Pos)FT_NEXT_BYTE( p );
@ -418,7 +418,7 @@
}
else if ( ( f & 32 ) == 0 )
{
if (p + 2 > limit)
if ( p + 2 > limit )
goto Invalid_Outline;
y = (FT_Pos)FT_NEXT_SHORT( p );
@ -426,7 +426,7 @@
x += y;
vec->y = x;
*flag = f & ~(4|32);
*flag = f & ~( 4 | 32 );
}
outline->n_points = (FT_UShort)n_points;