1 /***************************************************************************/
5 /* FreeType API for checking patented TrueType bytecode instructions */
8 /* Copyright 2007, 2008, 2010 by David Turner. */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
16 /***************************************************************************/
19 #include FT_FREETYPE_H
20 #include FT_TRUETYPE_TAGS_H
21 #include FT_INTERNAL_OBJECTS_H
22 #include FT_INTERNAL_STREAM_H
23 #include FT_SERVICE_SFNT_H
24 #include FT_SERVICE_TRUETYPE_GLYF_H
28 _tt_check_patents_in_range( FT_Stream stream
,
31 FT_Bool result
= FALSE
;
36 if ( FT_FRAME_ENTER( size
) )
46 case 0x06: /* SPvTL // */
47 case 0x07: /* SPvTL + */
48 case 0x08: /* SFvTL // */
49 case 0x09: /* SFvTL + */
50 case 0x0A: /* SPvFS */
51 case 0x0B: /* SFvFS */
69 case 0x71: /* DELTAP2 */
70 case 0x72: /* DELTAP3 */
71 case 0x73: /* DELTAC0 */
72 case 0x74: /* DELTAC1 */
73 case 0x75: /* DELTAC2 */
85 p
+= ( p
[0] - 0xB0 ) + 2;
96 p
+= ( p
[0] - 0xB8 ) * 2 + 3;
113 _tt_check_patents_in_table( FT_Face face
,
116 FT_Stream stream
= face
->stream
;
117 FT_Error error
= FT_Err_Ok
;
118 FT_Service_SFNT_Table service
;
119 FT_Bool result
= FALSE
;
122 FT_FACE_FIND_SERVICE( face
, service
, SFNT_TABLE
);
127 FT_ULong tag_i
= 0, offset_i
= 0, length_i
= 0;
130 for ( i
= 0; !error
&& tag_i
!= tag
; i
++ )
131 error
= service
->table_info( face
, i
,
132 &tag_i
, &offset_i
, &length_i
);
135 FT_STREAM_SEEK( offset_i
) )
138 result
= _tt_check_patents_in_range( stream
, length_i
);
147 _tt_face_check_patents( FT_Face face
)
149 FT_Stream stream
= face
->stream
;
154 FT_Service_TTGlyf service
;
157 result
= _tt_check_patents_in_table( face
, TTAG_fpgm
);
161 result
= _tt_check_patents_in_table( face
, TTAG_prep
);
165 FT_FACE_FIND_SERVICE( face
, service
, TT_GLYF
);
166 if ( service
== NULL
)
169 for ( gindex
= 0; gindex
< (FT_UInt
)face
->num_glyphs
; gindex
++ )
171 FT_ULong offset
, num_ins
, size
;
175 offset
= service
->get_location( face
, gindex
, &size
);
179 if ( FT_STREAM_SEEK( offset
) ||
180 FT_READ_SHORT( num_contours
) )
183 if ( num_contours
>= 0 ) /* simple glyph */
185 if ( FT_STREAM_SKIP( 8 + num_contours
* 2 ) )
188 else /* compound glyph */
190 FT_Bool has_instr
= 0;
193 if ( FT_STREAM_SKIP( 8 ) )
196 /* now read each component */
199 FT_UInt flags
, toskip
;
202 if( FT_READ_USHORT( flags
) )
207 if ( ( flags
& ( 1 << 0 ) ) != 0 ) /* ARGS_ARE_WORDS */
210 if ( ( flags
& ( 1 << 3 ) ) != 0 ) /* WE_HAVE_A_SCALE */
212 else if ( ( flags
& ( 1 << 6 ) ) != 0 ) /* WE_HAVE_X_Y_SCALE */
214 else if ( ( flags
& ( 1 << 7 ) ) != 0 ) /* WE_HAVE_A_2x2 */
217 if ( ( flags
& ( 1 << 8 ) ) != 0 ) /* WE_HAVE_INSTRUCTIONS */
220 if ( FT_STREAM_SKIP( toskip
) )
223 if ( ( flags
& ( 1 << 5 ) ) == 0 ) /* MORE_COMPONENTS */
231 if ( FT_READ_USHORT( num_ins
) )
234 result
= _tt_check_patents_in_range( stream
, num_ins
);
247 /* documentation is in freetype.h */
249 FT_EXPORT_DEF( FT_Bool
)
250 FT_Face_CheckTrueTypePatents( FT_Face face
)
252 FT_Bool result
= FALSE
;
255 if ( face
&& FT_IS_SFNT( face
) )
256 result
= _tt_face_check_patents( face
);
262 /* documentation is in freetype.h */
264 FT_EXPORT_DEF( FT_Bool
)
265 FT_Face_SetUnpatentedHinting( FT_Face face
,
268 FT_Bool result
= FALSE
;
271 #if defined( TT_CONFIG_OPTION_UNPATENTED_HINTING ) && \
272 !defined( TT_CONFIG_OPTION_BYTECODE_INTEPRETER )
273 if ( face
&& FT_IS_SFNT( face
) )
275 result
= !face
->internal
->ignore_unpatented_hinter
;
276 face
->internal
->ignore_unpatented_hinter
= !value
;