ttpload.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /***************************************************************************/
  2. /* */
  3. /* ttpload.c */
  4. /* */
  5. /* TrueType glyph data/program tables loader (body). */
  6. /* */
  7. /* Copyright 1996-2001, 2002 by */
  8. /* David Turner, Robert Wilhelm, and Werner Lemberg. */
  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_INTERNAL_DEBUG_H
  19. #include FT_INTERNAL_OBJECTS_H
  20. #include FT_INTERNAL_STREAM_H
  21. #include FT_TRUETYPE_TAGS_H
  22. #include "ttpload.h"
  23. #include "tterrors.h"
  24. /*************************************************************************/
  25. /* */
  26. /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
  27. /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
  28. /* messages during execution. */
  29. /* */
  30. #undef FT_COMPONENT
  31. #define FT_COMPONENT trace_ttpload
  32. /*************************************************************************/
  33. /* */
  34. /* <Function> */
  35. /* tt_face_load_loca */
  36. /* */
  37. /* <Description> */
  38. /* Loads the locations table. */
  39. /* */
  40. /* <InOut> */
  41. /* face :: A handle to the target face object. */
  42. /* */
  43. /* <Input> */
  44. /* stream :: The input stream. */
  45. /* */
  46. /* <Return> */
  47. /* FreeType error code. 0 means success. */
  48. /* */
  49. FT_LOCAL_DEF( FT_Error )
  50. tt_face_load_loca( TT_Face face,
  51. FT_Stream stream )
  52. {
  53. FT_Error error;
  54. FT_Memory memory = stream->memory;
  55. FT_Short LongOffsets;
  56. FT_ULong table_len;
  57. FT_TRACE2(( "Locations " ));
  58. LongOffsets = face->header.Index_To_Loc_Format;
  59. error = face->goto_table( face, TTAG_loca, stream, &table_len );
  60. if ( error )
  61. {
  62. error = TT_Err_Locations_Missing;
  63. goto Exit;
  64. }
  65. if ( LongOffsets != 0 )
  66. {
  67. face->num_locations = (FT_UShort)( table_len >> 2 );
  68. FT_TRACE2(( "(32bit offsets): %12d ", face->num_locations ));
  69. if ( FT_NEW_ARRAY( face->glyph_locations, face->num_locations ) )
  70. goto Exit;
  71. if ( FT_FRAME_ENTER( face->num_locations * 4L ) )
  72. goto Exit;
  73. {
  74. FT_Long* loc = face->glyph_locations;
  75. FT_Long* limit = loc + face->num_locations;
  76. for ( ; loc < limit; loc++ )
  77. *loc = FT_GET_LONG();
  78. }
  79. FT_FRAME_EXIT();
  80. }
  81. else
  82. {
  83. face->num_locations = (FT_UShort)( table_len >> 1 );
  84. FT_TRACE2(( "(16bit offsets): %12d ", face->num_locations ));
  85. if ( FT_NEW_ARRAY( face->glyph_locations, face->num_locations ) )
  86. goto Exit;
  87. if ( FT_FRAME_ENTER( face->num_locations * 2L ) )
  88. goto Exit;
  89. {
  90. FT_Long* loc = face->glyph_locations;
  91. FT_Long* limit = loc + face->num_locations;
  92. for ( ; loc < limit; loc++ )
  93. *loc = (FT_Long)( (FT_ULong)FT_GET_USHORT() * 2 );
  94. }
  95. FT_FRAME_EXIT();
  96. }
  97. FT_TRACE2(( "loaded\n" ));
  98. Exit:
  99. return error;
  100. }
  101. /*************************************************************************/
  102. /* */
  103. /* <Function> */
  104. /* tt_face_load_cvt */
  105. /* */
  106. /* <Description> */
  107. /* Loads the control value table into a face object. */
  108. /* */
  109. /* <InOut> */
  110. /* face :: A handle to the target face object. */
  111. /* */
  112. /* <Input> */
  113. /* stream :: A handle to the input stream. */
  114. /* */
  115. /* <Return> */
  116. /* FreeType error code. 0 means success. */
  117. /* */
  118. FT_LOCAL_DEF( FT_Error )
  119. tt_face_load_cvt( TT_Face face,
  120. FT_Stream stream )
  121. {
  122. FT_Error error;
  123. FT_Memory memory = stream->memory;
  124. FT_ULong table_len;
  125. FT_TRACE2(( "CVT " ));
  126. error = face->goto_table( face, TTAG_cvt, stream, &table_len );
  127. if ( error )
  128. {
  129. FT_TRACE2(( "is missing!\n" ));
  130. face->cvt_size = 0;
  131. face->cvt = NULL;
  132. error = TT_Err_Ok;
  133. goto Exit;
  134. }
  135. face->cvt_size = table_len / 2;
  136. if ( FT_NEW_ARRAY( face->cvt, face->cvt_size ) )
  137. goto Exit;
  138. if ( FT_FRAME_ENTER( face->cvt_size * 2L ) )
  139. goto Exit;
  140. {
  141. FT_Short* cur = face->cvt;
  142. FT_Short* limit = cur + face->cvt_size;
  143. for ( ; cur < limit; cur++ )
  144. *cur = FT_GET_SHORT();
  145. }
  146. FT_FRAME_EXIT();
  147. FT_TRACE2(( "loaded\n" ));
  148. Exit:
  149. return error;
  150. }
  151. /*************************************************************************/
  152. /* */
  153. /* <Function> */
  154. /* tt_face_load_fpgm */
  155. /* */
  156. /* <Description> */
  157. /* Loads the font program and the cvt program. */
  158. /* */
  159. /* <InOut> */
  160. /* face :: A handle to the target face object. */
  161. /* */
  162. /* <Input> */
  163. /* stream :: A handle to the input stream. */
  164. /* */
  165. /* <Return> */
  166. /* FreeType error code. 0 means success. */
  167. /* */
  168. FT_LOCAL_DEF( FT_Error )
  169. tt_face_load_fpgm( TT_Face face,
  170. FT_Stream stream )
  171. {
  172. FT_Error error;
  173. FT_ULong table_len;
  174. FT_TRACE2(( "Font program " ));
  175. /* The font program is optional */
  176. error = face->goto_table( face, TTAG_fpgm, stream, &table_len );
  177. if ( error )
  178. {
  179. face->font_program = NULL;
  180. face->font_program_size = 0;
  181. FT_TRACE2(( "is missing!\n" ));
  182. }
  183. else
  184. {
  185. face->font_program_size = table_len;
  186. if ( FT_FRAME_EXTRACT( table_len, face->font_program ) )
  187. goto Exit;
  188. FT_TRACE2(( "loaded, %12d bytes\n", face->font_program_size ));
  189. }
  190. FT_TRACE2(( "Prep program " ));
  191. error = face->goto_table( face, TTAG_prep, stream, &table_len );
  192. if ( error )
  193. {
  194. face->cvt_program = NULL;
  195. face->cvt_program_size = 0;
  196. error = TT_Err_Ok;
  197. FT_TRACE2(( "is missing!\n" ));
  198. }
  199. else
  200. {
  201. face->cvt_program_size = table_len;
  202. if ( FT_FRAME_EXTRACT( table_len, face->cvt_program ) )
  203. goto Exit;
  204. FT_TRACE2(( "loaded, %12d bytes\n", face->cvt_program_size ));
  205. }
  206. Exit:
  207. return error;
  208. }
  209. /* END */