Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

267 lines
7.2 KiB

  1. /***
  2. **
  3. ** Module: TItoTT
  4. **
  5. ** Description:
  6. ** This is the main module of the Postscript Type I to TrueType
  7. ** font converter.
  8. **
  9. ** Author: Michael Jansson
  10. ** Created: 5/26/93
  11. **
  12. ***/
  13. /***** INCLUDES */
  14. #include <string.h>
  15. #include "types.h"
  16. #include "safemem.h"
  17. #include "metrics.h"
  18. #include "titott.h"
  19. #include "t1parser.h"
  20. #include "builder.h"
  21. #include "trans.h"
  22. /***** LOCAL TYPES */
  23. /*-none-*/
  24. /***** CONSTANTS */
  25. #define NOTDEFNAME ".notdef"
  26. static const struct TTGlyph null = {
  27. NULL,
  28. 0, 0, 0, NULL,
  29. NULL,
  30. 0, 0
  31. };
  32. static Point mpo3[] = {
  33. {1150, 10}, {1150, 30}, {1160, 30}, {1170, 20}, {1180, 30}, {1190, 30},
  34. {1190, 10}, {1180, 10}, {1180, 20}, {1170, 10}, {1160, 20}, {1160, 10}
  35. };
  36. static Point mpo2[] = {
  37. {60, 40}, {60, 1560}, {1160, 1560}, {1160, 40}
  38. };
  39. static Point mpo1[] = {
  40. {20, 0}, {1200, 0}, {1200, 1600}, {20, 1600}
  41. };
  42. static ULONG onoff[1] = {0L};
  43. static Outline p1 = {
  44. NULL,
  45. sizeof(mpo3)/sizeof(mpo3[0]),
  46. &mpo3[0],
  47. &onoff[0]
  48. };
  49. static Outline p2 = {
  50. &p1,
  51. sizeof(mpo2)/sizeof(mpo2[0]),
  52. &mpo2[0],
  53. &onoff[0]
  54. };
  55. static Outline missingPath = {
  56. &p2,
  57. sizeof(mpo1)/sizeof(mpo1[0]),
  58. &mpo1[0],
  59. &onoff[0]
  60. };
  61. static struct TTGlyph missing = {
  62. NULL,
  63. MAXNOTDEFSIZE, 0, 0, NULL,
  64. &missingPath,
  65. 1500, 0
  66. };
  67. /***** MACROS */
  68. /*-none-*/
  69. /***** GLOBALS */
  70. /*-none-*/
  71. /***** STATIC FUNCTIONS */
  72. /*-none-*/
  73. /**** FUNCTIONS */
  74. /***
  75. ** Function: ConvertT1toTT
  76. **
  77. ** Description:
  78. ** Convert a T1 font into a TT font file.
  79. ***/
  80. errcode ConvertT1toTT(const struct TTArg *ttArg,
  81. const struct T1Arg *t1Arg,
  82. const short (*check)(const char *copyright,
  83. const char *notice,
  84. const char *facename),
  85. struct callProgress *cp)
  86. {
  87. /* Resources */
  88. struct T1Handle *t1 = NULL;
  89. struct TTHandle *tt = NULL;
  90. struct T1Metrics *t1m = NULL;
  91. /* Temporary variables. */
  92. struct T1Glyph glyph;
  93. struct TTGlyph *ttglyph;
  94. struct Composite *comp;
  95. struct TTComposite ttcomp;
  96. struct TTMetrics ttm;
  97. boolean fStdEncoding;
  98. boolean done;
  99. errcode status;
  100. /* Initiate variables. */
  101. ttglyph = NULL;
  102. memset(&glyph, '\0', sizeof(glyph));
  103. memset(&ttm, '\0', sizeof(ttm));
  104. /* Inititate input and output */
  105. if ((status = InitT1Input(t1Arg, &t1, &t1m, check))==SUCCESS &&
  106. (status = InitTTOutput(ttArg, &tt))==SUCCESS) {
  107. done = FALSE;
  108. fStdEncoding = (CurrentEncoding(t1m)==NULL);
  109. /* Create the missing and the null glyph. */
  110. if ((missing.hints = Malloc(MAXNOTDEFSIZE))==NULL) {
  111. status = NOMEM;
  112. done = TRUE;
  113. } else {
  114. memset(missing.hints, 0x22, MAXNOTDEFSIZE);
  115. (void)PutTTGlyph(tt, &missing, fStdEncoding);
  116. (void)PutTTGlyph(tt, &null, fStdEncoding);
  117. Free(missing.hints);
  118. }
  119. /* Convert the simple glyphs. */
  120. while(!done) {
  121. status = GetT1Glyph(t1, &glyph, t1Arg->filter);
  122. if (status == SUCCESS) {
  123. if ((status = ConvertGlyph(t1m,
  124. &glyph,
  125. &ttglyph,
  126. (int)ttArg->precision))!=SUCCESS ||
  127. (status = PutTTGlyph(tt, ttglyph, fStdEncoding))!=SUCCESS) {
  128. done = TRUE;
  129. } else {
  130. FreeTTGlyph(ttglyph);
  131. ttglyph=NULL;
  132. if (cp)
  133. cp->cb((short)0, &glyph, cp->arg);
  134. }
  135. } else if (status<=FAILURE || status==DONE) {
  136. done = TRUE;
  137. } else {
  138. /* Handle the missing glyph ".notdef" */
  139. if (!strcmp(glyph.name, NOTDEFNAME)) {
  140. if ((status = ConvertGlyph(t1m,
  141. &glyph,
  142. &ttglyph,
  143. (int)ttArg->precision))!=SUCCESS ||
  144. (status = PutTTNotDefGlyph(tt, ttglyph))!=SUCCESS) {
  145. done = TRUE;
  146. } else {
  147. FreeTTGlyph(ttglyph);
  148. ttglyph=NULL;
  149. if (cp)
  150. cp->cb((short)0, &glyph, cp->arg);
  151. }
  152. }
  153. }
  154. FreeT1Glyph(&glyph);
  155. }
  156. if (status==DONE) {
  157. /* Convert the composite glyphs. */
  158. while ((comp = GetT1Composite(t1))!=NULL) {
  159. /* Check if the base glyph is converted */
  160. if ((status = GetT1BaseGlyph(t1, comp, &glyph))==SUCCESS) {
  161. if ((status = ConvertGlyph(t1m,
  162. &glyph,
  163. &ttglyph,
  164. (int)ttArg->precision))!=SUCCESS ||
  165. (status = PutTTGlyph(tt, ttglyph, fStdEncoding))!=SUCCESS) {
  166. break;
  167. }
  168. FreeTTGlyph(ttglyph);
  169. ttglyph=NULL;
  170. if (cp)
  171. cp->cb((short)0, &glyph, cp->arg);
  172. } else if (status<=FAILURE)
  173. break;
  174. FreeT1Glyph(&glyph);
  175. /* Check if the base accent is converted */
  176. if ((status = GetT1AccentGlyph(t1, comp, &glyph))==SUCCESS) {
  177. if ((status = ConvertGlyph(t1m,
  178. &glyph,
  179. &ttglyph,
  180. (int)ttArg->precision))!=SUCCESS ||
  181. (status = PutTTGlyph(tt, ttglyph, fStdEncoding))!=SUCCESS) {
  182. break;
  183. }
  184. FreeTTGlyph(ttglyph);
  185. ttglyph=NULL;
  186. if (cp)
  187. cp->cb((short)0, &glyph, cp->arg);
  188. } else if (status<=FAILURE)
  189. break;
  190. FreeT1Glyph(&glyph);
  191. /* Convert and store accented glyph. */
  192. if (status>=SUCCESS &&
  193. ((status = ConvertComposite(t1m, comp, &ttcomp))!=SUCCESS ||
  194. (status = PutTTComposite(tt, &ttcomp))!=SUCCESS)) {
  195. break;
  196. }
  197. if (cp)
  198. cp->cb((short)1, &comp, cp->arg);
  199. }
  200. /* Flush out un-used work space. */
  201. FlushWorkspace(t1);
  202. /* Convert the metrics. */
  203. if (status==SUCCESS || status==DONE || status==SKIP) {
  204. if ((status = ReadOtherMetrics(t1m,
  205. t1Arg->metrics))==SUCCESS &&
  206. (status = ConvertMetrics(tt, t1m, &ttm,
  207. ttArg->tag))==SUCCESS) {
  208. if (cp)
  209. cp->cb((short)2, NULL, cp->arg);
  210. status = PutTTOther(tt, &ttm);
  211. }
  212. }
  213. }
  214. }
  215. /* More progress. */
  216. if (cp)
  217. cp->cb((short)3, NULL, cp->arg);
  218. FreeTTMetrics(&ttm);
  219. FreeTTGlyph(ttglyph);
  220. FreeT1Glyph(&glyph);
  221. if (CleanUpTT(tt, ttArg, status)!=SUCCESS && status==SUCCESS)
  222. status = BADINPUTFILE;
  223. if (CleanUpT1(t1)!=SUCCESS && status==SUCCESS)
  224. status = BADINPUTFILE;
  225. /* All done! */
  226. if (cp)
  227. cp->cb((short)4, NULL, cp->arg);
  228. return status;
  229. }