cidobjs.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /***************************************************************************/
  2. /* */
  3. /* cidobjs.c */
  4. /* */
  5. /* CID objects manager (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_STREAM_H
  20. #include "cidgload.h"
  21. #include "cidload.h"
  22. #include FT_INTERNAL_POSTSCRIPT_NAMES_H
  23. #include FT_INTERNAL_POSTSCRIPT_AUX_H
  24. #include FT_INTERNAL_POSTSCRIPT_HINTS_H
  25. #include "ciderrs.h"
  26. /*************************************************************************/
  27. /* */
  28. /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
  29. /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
  30. /* messages during execution. */
  31. /* */
  32. #undef FT_COMPONENT
  33. #define FT_COMPONENT trace_cidobjs
  34. /*************************************************************************/
  35. /* */
  36. /* SLOT FUNCTIONS */
  37. /* */
  38. /*************************************************************************/
  39. FT_LOCAL_DEF( void )
  40. cid_slot_done( CID_GlyphSlot slot )
  41. {
  42. slot->root.internal->glyph_hints = 0;
  43. }
  44. FT_LOCAL_DEF( FT_Error )
  45. cid_slot_init( CID_GlyphSlot slot )
  46. {
  47. CID_Face face;
  48. PSHinter_Service pshinter;
  49. face = (CID_Face)slot->root.face;
  50. pshinter = (PSHinter_Service)face->pshinter;
  51. if ( pshinter )
  52. {
  53. FT_Module module;
  54. module = FT_Get_Module( slot->root.face->driver->root.library,
  55. "pshinter" );
  56. if ( module )
  57. {
  58. T1_Hints_Funcs funcs;
  59. funcs = pshinter->get_t1_funcs( module );
  60. slot->root.internal->glyph_hints = (void*)funcs;
  61. }
  62. }
  63. return 0;
  64. }
  65. /*************************************************************************/
  66. /* */
  67. /* SIZE FUNCTIONS */
  68. /* */
  69. /*************************************************************************/
  70. static PSH_Globals_Funcs
  71. cid_size_get_globals_funcs( CID_Size size )
  72. {
  73. CID_Face face = (CID_Face)size->root.face;
  74. PSHinter_Service pshinter = (PSHinter_Service)face->pshinter;
  75. FT_Module module;
  76. module = FT_Get_Module( size->root.face->driver->root.library,
  77. "pshinter" );
  78. return ( module && pshinter && pshinter->get_globals_funcs )
  79. ? pshinter->get_globals_funcs( module )
  80. : 0;
  81. }
  82. FT_LOCAL_DEF( void )
  83. cid_size_done( CID_Size size )
  84. {
  85. if ( size->root.internal )
  86. {
  87. PSH_Globals_Funcs funcs;
  88. funcs = cid_size_get_globals_funcs( size );
  89. if ( funcs )
  90. funcs->destroy( (PSH_Globals)size->root.internal );
  91. size->root.internal = 0;
  92. }
  93. }
  94. FT_LOCAL_DEF( FT_Error )
  95. cid_size_init( CID_Size size )
  96. {
  97. FT_Error error = 0;
  98. PSH_Globals_Funcs funcs = cid_size_get_globals_funcs( size );
  99. if ( funcs )
  100. {
  101. PSH_Globals globals;
  102. CID_Face face = (CID_Face)size->root.face;
  103. CID_FaceDict dict = face->cid.font_dicts + face->root.face_index;
  104. PS_Private priv = &dict->private_dict;
  105. error = funcs->create( size->root.face->memory, priv, &globals );
  106. if ( !error )
  107. size->root.internal = (FT_Size_Internal)(void*)globals;
  108. }
  109. return error;
  110. }
  111. FT_LOCAL_DEF( FT_Error )
  112. cid_size_reset( CID_Size size )
  113. {
  114. PSH_Globals_Funcs funcs = cid_size_get_globals_funcs( size );
  115. FT_Error error = 0;
  116. if ( funcs )
  117. error = funcs->set_scale( (PSH_Globals)size->root.internal,
  118. size->root.metrics.x_scale,
  119. size->root.metrics.y_scale,
  120. 0, 0 );
  121. return error;
  122. }
  123. /*************************************************************************/
  124. /* */
  125. /* FACE FUNCTIONS */
  126. /* */
  127. /*************************************************************************/
  128. /*************************************************************************/
  129. /* */
  130. /* <Function> */
  131. /* cid_face_done */
  132. /* */
  133. /* <Description> */
  134. /* Finalizes a given face object. */
  135. /* */
  136. /* <Input> */
  137. /* face :: A pointer to the face object to destroy. */
  138. /* */
  139. FT_LOCAL_DEF( void )
  140. cid_face_done( CID_Face face )
  141. {
  142. FT_Memory memory;
  143. if ( face )
  144. {
  145. CID_FaceInfo cid = &face->cid;
  146. PS_FontInfo info = &cid->font_info;
  147. memory = face->root.memory;
  148. /* release subrs */
  149. if ( face->subrs )
  150. {
  151. FT_Int n;
  152. for ( n = 0; n < cid->num_dicts; n++ )
  153. {
  154. CID_Subrs subr = face->subrs + n;
  155. if ( subr->code )
  156. {
  157. FT_FREE( subr->code[0] );
  158. FT_FREE( subr->code );
  159. }
  160. }
  161. FT_FREE( face->subrs );
  162. }
  163. /* release FontInfo strings */
  164. FT_FREE( info->version );
  165. FT_FREE( info->notice );
  166. FT_FREE( info->full_name );
  167. FT_FREE( info->family_name );
  168. FT_FREE( info->weight );
  169. /* release font dictionaries */
  170. FT_FREE( cid->font_dicts );
  171. cid->num_dicts = 0;
  172. /* release other strings */
  173. FT_FREE( cid->cid_font_name );
  174. FT_FREE( cid->registry );
  175. FT_FREE( cid->ordering );
  176. face->root.family_name = 0;
  177. face->root.style_name = 0;
  178. }
  179. }
  180. /*************************************************************************/
  181. /* */
  182. /* <Function> */
  183. /* cid_face_init */
  184. /* */
  185. /* <Description> */
  186. /* Initializes a given CID face object. */
  187. /* */
  188. /* <Input> */
  189. /* stream :: The source font stream. */
  190. /* */
  191. /* face_index :: The index of the font face in the resource. */
  192. /* */
  193. /* num_params :: Number of additional generic parameters. Ignored. */
  194. /* */
  195. /* params :: Additional generic parameters. Ignored. */
  196. /* */
  197. /* <InOut> */
  198. /* face :: The newly built face object. */
  199. /* */
  200. /* <Return> */
  201. /* FreeType error code. 0 means success. */
  202. /* */
  203. FT_LOCAL_DEF( FT_Error )
  204. cid_face_init( FT_Stream stream,
  205. CID_Face face,
  206. FT_Int face_index,
  207. FT_Int num_params,
  208. FT_Parameter* params )
  209. {
  210. FT_Error error;
  211. PSNames_Service psnames;
  212. PSAux_Service psaux;
  213. PSHinter_Service pshinter;
  214. FT_UNUSED( num_params );
  215. FT_UNUSED( params );
  216. FT_UNUSED( face_index );
  217. FT_UNUSED( stream );
  218. face->root.num_faces = 1;
  219. psnames = (PSNames_Service)face->psnames;
  220. if ( !psnames )
  221. {
  222. psnames = (PSNames_Service)FT_Get_Module_Interface(
  223. FT_FACE_LIBRARY( face ), "psnames" );
  224. face->psnames = psnames;
  225. }
  226. psaux = (PSAux_Service)face->psaux;
  227. if ( !psaux )
  228. {
  229. psaux = (PSAux_Service)FT_Get_Module_Interface(
  230. FT_FACE_LIBRARY( face ), "psaux" );
  231. face->psaux = psaux;
  232. }
  233. pshinter = (PSHinter_Service)face->pshinter;
  234. if ( !pshinter )
  235. {
  236. pshinter = (PSHinter_Service)FT_Get_Module_Interface(
  237. FT_FACE_LIBRARY( face ), "pshinter" );
  238. face->pshinter = pshinter;
  239. }
  240. /* open the tokenizer; this will also check the font format */
  241. if ( FT_STREAM_SEEK( 0 ) )
  242. goto Exit;
  243. error = cid_face_open( face );
  244. if ( error )
  245. goto Exit;
  246. /* if we just wanted to check the format, leave successfully now */
  247. if ( face_index < 0 )
  248. goto Exit;
  249. /* check the face index */
  250. if ( face_index != 0 )
  251. {
  252. FT_ERROR(( "cid_face_init: invalid face index\n" ));
  253. error = CID_Err_Invalid_Argument;
  254. goto Exit;
  255. }
  256. /* Now, load the font program into the face object */
  257. {
  258. /* Init the face object fields */
  259. /* Now set up root face fields */
  260. {
  261. FT_Face root = (FT_Face)&face->root;
  262. root->num_glyphs = face->cid.cid_count;
  263. root->num_charmaps = 0;
  264. root->face_index = face_index;
  265. root->face_flags = FT_FACE_FLAG_SCALABLE;
  266. root->face_flags |= FT_FACE_FLAG_HORIZONTAL;
  267. if ( face->cid.font_info.is_fixed_pitch )
  268. root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
  269. /* XXX: TODO: add kerning with .afm support */
  270. /* get style name -- be careful, some broken fonts only */
  271. /* have a /FontName dictionary entry! */
  272. root->family_name = face->cid.font_info.family_name;
  273. if ( root->family_name )
  274. {
  275. char* full = face->cid.font_info.full_name;
  276. char* family = root->family_name;
  277. while ( *family && *full == *family )
  278. {
  279. family++;
  280. full++;
  281. }
  282. root->style_name = ( *full == ' ' ) ? full + 1
  283. : (char *)"Regular";
  284. }
  285. else
  286. {
  287. /* do we have a `/FontName'? */
  288. if ( face->cid.cid_font_name )
  289. {
  290. root->family_name = face->cid.cid_font_name;
  291. root->style_name = (char *)"Regular";
  292. }
  293. }
  294. /* no embedded bitmap support */
  295. root->num_fixed_sizes = 0;
  296. root->available_sizes = 0;
  297. root->bbox.xMin = face->cid.font_bbox.xMin >> 16;
  298. root->bbox.yMin = face->cid.font_bbox.yMin >> 16;
  299. root->bbox.xMax = ( face->cid.font_bbox.xMax + 0xFFFFU ) >> 16;
  300. root->bbox.yMax = ( face->cid.font_bbox.yMax + 0xFFFFU ) >> 16;
  301. if ( !root->units_per_EM )
  302. root->units_per_EM = 1000;
  303. root->ascender = (FT_Short)( root->bbox.yMax );
  304. root->descender = (FT_Short)( root->bbox.yMin );
  305. root->height = (FT_Short)(
  306. ( ( root->ascender + root->descender ) * 12 ) / 10 );
  307. root->underline_position = face->cid.font_info.underline_position;
  308. root->underline_thickness = face->cid.font_info.underline_thickness;
  309. root->internal->max_points = 0;
  310. root->internal->max_contours = 0;
  311. }
  312. }
  313. Exit:
  314. return error;
  315. }
  316. /*************************************************************************/
  317. /* */
  318. /* <Function> */
  319. /* cid_driver_init */
  320. /* */
  321. /* <Description> */
  322. /* Initializes a given CID driver object. */
  323. /* */
  324. /* <Input> */
  325. /* driver :: A handle to the target driver object. */
  326. /* */
  327. /* <Return> */
  328. /* FreeType error code. 0 means success. */
  329. /* */
  330. FT_LOCAL_DEF( FT_Error )
  331. cid_driver_init( CID_Driver driver )
  332. {
  333. FT_UNUSED( driver );
  334. return CID_Err_Ok;
  335. }
  336. /*************************************************************************/
  337. /* */
  338. /* <Function> */
  339. /* cid_driver_done */
  340. /* */
  341. /* <Description> */
  342. /* Finalizes a given CID driver. */
  343. /* */
  344. /* <Input> */
  345. /* driver :: A handle to the target CID driver. */
  346. /* */
  347. FT_LOCAL_DEF( void )
  348. cid_driver_done( CID_Driver driver )
  349. {
  350. FT_UNUSED( driver );
  351. }
  352. /* END */