/src/compiler/android-ndk/jni/freetype/src/base/ftpatent.c

http://ftk.googlecode.com/ · C · 286 lines · 199 code · 67 blank · 20 comment · 47 complexity · a8e9de75621e7386322735c39e120942 MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* ftpatent.c */
  4. /* */
  5. /* FreeType API for checking patented TrueType bytecode instructions */
  6. /* (body). */
  7. /* */
  8. /* Copyright 2007, 2008, 2010 by David Turner. */
  9. /* */
  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. */
  15. /* */
  16. /***************************************************************************/
  17. #include <ft2build.h>
  18. #include FT_FREETYPE_H
  19. #include FT_TRUETYPE_TAGS_H
  20. #include FT_INTERNAL_OBJECTS_H
  21. #include FT_INTERNAL_STREAM_H
  22. #include FT_SERVICE_SFNT_H
  23. #include FT_SERVICE_TRUETYPE_GLYF_H
  24. static FT_Bool
  25. _tt_check_patents_in_range( FT_Stream stream,
  26. FT_ULong size )
  27. {
  28. FT_Bool result = FALSE;
  29. FT_Error error;
  30. FT_Bytes p, end;
  31. if ( FT_FRAME_ENTER( size ) )
  32. return 0;
  33. p = stream->cursor;
  34. end = p + size;
  35. while ( p < end )
  36. {
  37. switch (p[0])
  38. {
  39. case 0x06: /* SPvTL // */
  40. case 0x07: /* SPvTL + */
  41. case 0x08: /* SFvTL // */
  42. case 0x09: /* SFvTL + */
  43. case 0x0A: /* SPvFS */
  44. case 0x0B: /* SFvFS */
  45. result = TRUE;
  46. goto Exit;
  47. case 0x40:
  48. if ( p + 1 >= end )
  49. goto Exit;
  50. p += p[1] + 2;
  51. break;
  52. case 0x41:
  53. if ( p + 1 >= end )
  54. goto Exit;
  55. p += p[1] * 2 + 2;
  56. break;
  57. case 0x71: /* DELTAP2 */
  58. case 0x72: /* DELTAP3 */
  59. case 0x73: /* DELTAC0 */
  60. case 0x74: /* DELTAC1 */
  61. case 0x75: /* DELTAC2 */
  62. result = TRUE;
  63. goto Exit;
  64. case 0xB0:
  65. case 0xB1:
  66. case 0xB2:
  67. case 0xB3:
  68. case 0xB4:
  69. case 0xB5:
  70. case 0xB6:
  71. case 0xB7:
  72. p += ( p[0] - 0xB0 ) + 2;
  73. break;
  74. case 0xB8:
  75. case 0xB9:
  76. case 0xBA:
  77. case 0xBB:
  78. case 0xBC:
  79. case 0xBD:
  80. case 0xBE:
  81. case 0xBF:
  82. p += ( p[0] - 0xB8 ) * 2 + 3;
  83. break;
  84. default:
  85. p += 1;
  86. break;
  87. }
  88. }
  89. Exit:
  90. FT_UNUSED( error );
  91. FT_FRAME_EXIT();
  92. return result;
  93. }
  94. static FT_Bool
  95. _tt_check_patents_in_table( FT_Face face,
  96. FT_ULong tag )
  97. {
  98. FT_Stream stream = face->stream;
  99. FT_Error error = FT_Err_Ok;
  100. FT_Service_SFNT_Table service;
  101. FT_Bool result = FALSE;
  102. FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
  103. if ( service )
  104. {
  105. FT_UInt i = 0;
  106. FT_ULong tag_i = 0, offset_i = 0, length_i = 0;
  107. for ( i = 0; !error && tag_i != tag ; i++ )
  108. error = service->table_info( face, i,
  109. &tag_i, &offset_i, &length_i );
  110. if ( error ||
  111. FT_STREAM_SEEK( offset_i ) )
  112. goto Exit;
  113. result = _tt_check_patents_in_range( stream, length_i );
  114. }
  115. Exit:
  116. return result;
  117. }
  118. static FT_Bool
  119. _tt_face_check_patents( FT_Face face )
  120. {
  121. FT_Stream stream = face->stream;
  122. FT_UInt gindex;
  123. FT_Error error;
  124. FT_Bool result;
  125. FT_Service_TTGlyf service;
  126. result = _tt_check_patents_in_table( face, TTAG_fpgm );
  127. if ( result )
  128. goto Exit;
  129. result = _tt_check_patents_in_table( face, TTAG_prep );
  130. if ( result )
  131. goto Exit;
  132. FT_FACE_FIND_SERVICE( face, service, TT_GLYF );
  133. if ( service == NULL )
  134. goto Exit;
  135. for ( gindex = 0; gindex < (FT_UInt)face->num_glyphs; gindex++ )
  136. {
  137. FT_ULong offset, num_ins, size;
  138. FT_Int num_contours;
  139. offset = service->get_location( face, gindex, &size );
  140. if ( size == 0 )
  141. continue;
  142. if ( FT_STREAM_SEEK( offset ) ||
  143. FT_READ_SHORT( num_contours ) )
  144. continue;
  145. if ( num_contours >= 0 ) /* simple glyph */
  146. {
  147. if ( FT_STREAM_SKIP( 8 + num_contours * 2 ) )
  148. continue;
  149. }
  150. else /* compound glyph */
  151. {
  152. FT_Bool has_instr = 0;
  153. if ( FT_STREAM_SKIP( 8 ) )
  154. continue;
  155. /* now read each component */
  156. for (;;)
  157. {
  158. FT_UInt flags, toskip;
  159. if( FT_READ_USHORT( flags ) )
  160. break;
  161. toskip = 2 + 1 + 1;
  162. if ( ( flags & ( 1 << 0 ) ) != 0 ) /* ARGS_ARE_WORDS */
  163. toskip += 2;
  164. if ( ( flags & ( 1 << 3 ) ) != 0 ) /* WE_HAVE_A_SCALE */
  165. toskip += 2;
  166. else if ( ( flags & ( 1 << 6 ) ) != 0 ) /* WE_HAVE_X_Y_SCALE */
  167. toskip += 4;
  168. else if ( ( flags & ( 1 << 7 ) ) != 0 ) /* WE_HAVE_A_2x2 */
  169. toskip += 8;
  170. if ( ( flags & ( 1 << 8 ) ) != 0 ) /* WE_HAVE_INSTRUCTIONS */
  171. has_instr = 1;
  172. if ( FT_STREAM_SKIP( toskip ) )
  173. goto NextGlyph;
  174. if ( ( flags & ( 1 << 5 ) ) == 0 ) /* MORE_COMPONENTS */
  175. break;
  176. }
  177. if ( !has_instr )
  178. goto NextGlyph;
  179. }
  180. if ( FT_READ_USHORT( num_ins ) )
  181. continue;
  182. result = _tt_check_patents_in_range( stream, num_ins );
  183. if ( result )
  184. goto Exit;
  185. NextGlyph:
  186. ;
  187. }
  188. Exit:
  189. return result;
  190. }
  191. /* documentation is in freetype.h */
  192. FT_EXPORT_DEF( FT_Bool )
  193. FT_Face_CheckTrueTypePatents( FT_Face face )
  194. {
  195. FT_Bool result = FALSE;
  196. if ( face && FT_IS_SFNT( face ) )
  197. result = _tt_face_check_patents( face );
  198. return result;
  199. }
  200. /* documentation is in freetype.h */
  201. FT_EXPORT_DEF( FT_Bool )
  202. FT_Face_SetUnpatentedHinting( FT_Face face,
  203. FT_Bool value )
  204. {
  205. FT_Bool result = FALSE;
  206. #if defined( TT_CONFIG_OPTION_UNPATENTED_HINTING ) && \
  207. !defined( TT_CONFIG_OPTION_BYTECODE_INTEPRETER )
  208. if ( face && FT_IS_SFNT( face ) )
  209. {
  210. result = !face->internal->ignore_unpatented_hinter;
  211. face->internal->ignore_unpatented_hinter = !value;
  212. }
  213. #else
  214. FT_UNUSED( face );
  215. FT_UNUSED( value );
  216. #endif
  217. return result;
  218. }
  219. /* END */