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.

493 lines
11 KiB

  1. /**
  2. ** Description:
  3. ** This is a module of the T1 to TT font converter. This is a
  4. ** sub-module of Hint module. This modules deals with the
  5. ** the font program fo the font.
  6. **
  7. ** Author: Michael Jansson
  8. **
  9. ** Created: 8/24/93
  10. **
  11. ***/
  12. #ifndef _ARGS
  13. # define IN const
  14. # define OUT
  15. # define INOUT
  16. # define _ARGS(arg) arg
  17. #endif
  18. #define HIBYTE(v) (UBYTE)((USHORT)(v)>>8)
  19. #define LOBYTE(v) (UBYTE)((USHORT)(v)&0xff)
  20. #define TWILIGHT 0
  21. #define GLYPHZONE 1
  22. #define TMPCVT 0L
  23. #define TMPPNT 0L
  24. #define TMPPNT1 1L
  25. #define STORAGE_DIAG 3
  26. #define ONEPIXEL 64L
  27. #define INFINITY (USHORT)SHRT_MAX
  28. #define MAXPTS 10 /* Max num of pts on a stem hint side. */
  29. /* IP bucket - Used for collecting points that should be
  30. interpolated within the zones defined by the stem hints. */
  31. typedef struct Extremas {
  32. short rp1;
  33. short rp2;
  34. short n;
  35. short pts[MAXPTS];
  36. } Extremas;
  37. enum aligntype {
  38. at_side1,
  39. at_side2,
  40. at_relative1,
  41. at_relative2,
  42. at_centered
  43. };
  44. /***
  45. **
  46. ** Description:
  47. ** This file contains op-codes for a sub-set of the
  48. ** TrueType instruction set.
  49. **
  50. ** Author: Michael Jansson
  51. **
  52. ** Created: 10/14/93
  53. **
  54. ***/
  55. /* TrueType sub-op codes. */
  56. #define SUBOP_Y 0x00
  57. #define SUBOP_X 0x01
  58. #define SUBOP_R 0x01
  59. #define SUBOP_MOVE 0x10
  60. #define SUBOP_MINDIST 0x08
  61. #define SUBOP_ROUND 0x04
  62. #define SUBOP_GRAY 0x00
  63. #define SUBOP_mMRGR SUBOP_MINDIST | SUBOP_ROUND | SUBOP_GRAY
  64. #define SUBOP_MmRGR SUBOP_MOVE | SUBOP_ROUND | SUBOP_GRAY
  65. /* TrueType op codes. */
  66. enum {
  67. op_mps = 0x4c,
  68. op_spvtl = 0x07,
  69. op_roll = 0x8a,
  70. op_gteq = 0x53,
  71. op_cindex = 0x25,
  72. op_rtdg = 0x3d,
  73. op_clear = 0x22,
  74. op_szp0 = 0x13,
  75. op_szp1 = 0x14,
  76. op_szp2 = 0x15,
  77. op_szps = 0x16,
  78. op_loopcall = 0x2a,
  79. op_shz = 0x36,
  80. op_smd = 0x1a,
  81. op_rutg = 0x7c,
  82. op_rdtg = 0x7d,
  83. op_pop = 0x21,
  84. op_abs = 0x64,
  85. op_scvtci = 0x1d,
  86. op_rs = 0x43,
  87. op_spvfs = 0x0a,
  88. op_shp = 0x33,
  89. op_roff = 0x7a,
  90. op_md = 0x49,
  91. op_ssw = 0x1f,
  92. op_mul = 0x63,
  93. op_odd = 0x56,
  94. op_gc = 0x46,
  95. op_dup = 0x20,
  96. op_min = 0x8c,
  97. op_max = 0x8b,
  98. op_neg = 0x65,
  99. op_sfvtl = 0x08,
  100. op_spvtca = 0x06,
  101. op_swap = 0x23,
  102. op_mdrp = 0xc0,
  103. op_mdap = 0x2e,
  104. op_miap = 0x3e,
  105. op_mirp = 0xe0,
  106. op_alignrp = 0x3c,
  107. op_iup = 0x30,
  108. op_svcta = 0x00,
  109. op_sloop = 0x17,
  110. op_npushb = 0x40,
  111. op_npushw = 0x41,
  112. op_mppem = 0x4b,
  113. op_lt = 0x50,
  114. op_gt = 0x52,
  115. op_if = 0x58,
  116. op_scfs = 0x48,
  117. op_else = 0x1b,
  118. op_wcvtf = 0x70,
  119. op_wcvtp = 0x44,
  120. op_pushw1 = 0xb8,
  121. op_pushb1 = 0xb0,
  122. op_eif = 0x59,
  123. op_shpix = 0x38,
  124. op_srp0 = 0x10,
  125. op_srp1 = 0x11,
  126. op_srp2 = 0x12,
  127. op_ip = 0x39,
  128. op_rcvt = 0x45,
  129. op_round = 0x68,
  130. op_rtg = 0x18,
  131. op_rthg = 0x19,
  132. op_add = 0x60,
  133. op_div = 0x62,
  134. op_scanctrl = 0x85,
  135. op_ws = 0x42,
  136. op_sswci = 0x1e,
  137. op_scantype = 0x8d,
  138. op_sub = 0x61,
  139. op_fdef = 0x2c,
  140. op_endf = 0x2d,
  141. op_call = 0x2b,
  142. op_getinfo = 0x88
  143. };
  144. /***
  145. ** Function: GetTopPos
  146. **
  147. ** Description:
  148. ** This function allocates a cvt entry for the
  149. ** top side of a horizontal stem;
  150. ***/
  151. short GetTopPos _ARGS((IN Blues *blues,
  152. INOUT AlignmentControl *align,
  153. IN funit pos));
  154. /***
  155. ** Function: GetBottomPos
  156. **
  157. ** Description:
  158. ** This function allocates a cvt entry for the
  159. ** top side of a horizontal stem;
  160. ***/
  161. short GetBottomPos _ARGS((IN Blues *blues,
  162. INOUT AlignmentControl *align,
  163. IN funit pos));
  164. /***
  165. ** Function: CutInSize
  166. **
  167. ** Description:
  168. ** This function computes the cut in size
  169. ** of a stem, given a master width and the
  170. ** width of the stem. This is done with the
  171. ** StdVW==2.0 pixel treshold and the thinn
  172. ** and wide cut in values.
  173. ***/
  174. USHORT CutInSize _ARGS((IN funit width,
  175. IN funit master,
  176. IN USHORT tresh,
  177. IN funit upem));
  178. /***
  179. ** Function: SnapStemArgs
  180. **
  181. ** Description:
  182. **
  183. ***/
  184. USHORT SnapStemArgs _ARGS((OUT short *args,
  185. INOUT USHORT ta,
  186. IN funit width,
  187. IN USHORT std_cvt,
  188. IN USHORT snap_cvt,
  189. IN USHORT std_ci,
  190. IN USHORT snap_ci,
  191. IN USHORT storage));
  192. /***
  193. ** Function: StdStemArgs
  194. **
  195. ** Description:
  196. **
  197. ***/
  198. USHORT StdStemArgs _ARGS((OUT short *args,
  199. INOUT USHORT ta,
  200. IN funit width,
  201. IN USHORT std_cvt,
  202. IN USHORT std_ci,
  203. IN USHORT storage));
  204. /***
  205. ** Function: CreateStdStems
  206. **
  207. ** Description:
  208. **
  209. ***/
  210. USHORT CreateStdStems _ARGS((INOUT UBYTE *prep,
  211. INOUT USHORT tp,
  212. IN short cnt));
  213. /***
  214. ** Function: CreateSnapStems
  215. **
  216. ** Description:
  217. **
  218. ***/
  219. USHORT CreateSnapStems _ARGS((INOUT UBYTE *prep,
  220. INOUT USHORT tp,
  221. IN short cnt));
  222. /***
  223. ** Function: tt_GetFontProg
  224. **
  225. ** Description:
  226. ** This function returns the static font
  227. ** font program.
  228. ***/
  229. const UBYTE *tt_GetFontProg _ARGS((void));
  230. /***
  231. ** Function: tt_GetNumFuns
  232. **
  233. ** Description:
  234. ** This function returns the number of functions
  235. ** defined in the static font program.
  236. ***/
  237. USHORT tt_GetNumFuns _ARGS((void));
  238. /***
  239. ** Function: tt_GetFontProgSize
  240. **
  241. ** Description:
  242. ** This function returns the size of the
  243. ** static font program.
  244. ***/
  245. USHORT tt_GetFontProgSize _ARGS((void));
  246. /***
  247. ** Function: SetZone
  248. **
  249. ** Description:
  250. ** This function initiate an alignment zone
  251. ** by creating an appropriate point in the
  252. ** twilight zone.
  253. ***/
  254. USHORT SetZone _ARGS((INOUT UBYTE *prep,
  255. INOUT USHORT tp,
  256. IN short cvt));
  257. /***
  258. ** Function: CopyZone
  259. **
  260. ** Description:
  261. ** This function copies a cvt entry, representing an
  262. ** alignment zone, to the cvt used for a particular hstem.
  263. ***/
  264. USHORT CopyZone _ARGS((INOUT UBYTE *prep,
  265. INOUT short tp,
  266. INOUT short *args,
  267. IN short ta));
  268. /***
  269. ** Function: CopyFamilyBlue
  270. **
  271. ** Description:
  272. ** This function copies a cvt entry, representing a
  273. ** family blue zone, to the cvt used for a particular hstem.
  274. ***/
  275. USHORT CopyFamilyBlue _ARGS((INOUT UBYTE *prep,
  276. INOUT short tp,
  277. INOUT short *args,
  278. IN short ta));
  279. /***
  280. ** Function: AlignFlat
  281. **
  282. ** Description:
  283. ** This function creates a cvt entry for
  284. ** a particular hstem.
  285. ***/
  286. USHORT AlignFlat _ARGS((INOUT UBYTE *prep,
  287. INOUT short tp,
  288. INOUT short *args,
  289. IN short ta));
  290. /***
  291. ** Function: AlignOvershoot
  292. **
  293. ** Description:
  294. ** This function creates a cvt entry for
  295. ** a particular hstem.
  296. ***/
  297. USHORT AlignOvershoot _ARGS((INOUT UBYTE *prep,
  298. INOUT short tp,
  299. INOUT short *args,
  300. IN short ta));
  301. /***
  302. ** Function: EmitFlex
  303. **
  304. ** Description:
  305. ** Convert a T1 flex hint into a TrueType IP[]
  306. ** intruction sequence that will reduce a flex
  307. ** that is flatter than a given height.
  308. ***/
  309. errcode EmitFlex _ARGS((INOUT short *args,
  310. INOUT short *pcd,
  311. IN funit height,
  312. IN short start,
  313. IN short mid,
  314. IN short last));
  315. /***
  316. ** Function: ReduceDiagonals
  317. **
  318. ** Description:
  319. ** This function generates the TT instructions
  320. ** that will shrink the outline, in order to
  321. ** control the width of diagonals. This implementation
  322. ** can probably be improved.
  323. ***/
  324. short ReduceDiagonals _ARGS((IN Outline *paths,
  325. INOUT UBYTE *pgm,
  326. INOUT short *pc,
  327. INOUT short *args,
  328. INOUT short *pcd));
  329. /***
  330. ** Function: ScaleDown3
  331. **
  332. ** Description:
  333. ** This function generates the TT instructions
  334. ** that will scale down points 3%.
  335. ***/
  336. void ScaleDown3 _ARGS((IN Extremas *extr,
  337. IN short xcnt,
  338. INOUT UBYTE *pgm,
  339. INOUT short *pc,
  340. INOUT short *args,
  341. INOUT short *pcd));
  342. /***
  343. ** Function: EmitIP
  344. **
  345. ** Description:
  346. ** This function generates the TT instructions
  347. ** that will interpolate points that are either
  348. ** within or between stem sides.
  349. ***/
  350. void EmitIP _ARGS((IN Extremas *extr,
  351. IN short xcnt,
  352. INOUT UBYTE *pgm,
  353. INOUT short *pc,
  354. INOUT short *args,
  355. INOUT short *pcd,
  356. IN short scale3offset));
  357. /***
  358. ** Function: EmitVerticalStem
  359. **
  360. ** Description:
  361. ** This function generates the code that
  362. ** will initiate the graphics state of the
  363. ** TrueType interpreter for the grid fitting
  364. ** of vertical stems.
  365. ***/
  366. void EmitVerticalStems _ARGS((INOUT UBYTE *pgm,
  367. INOUT short *pc,
  368. INOUT short *args,
  369. INOUT short *pcd));
  370. /***
  371. ** Function: EmitHorizontalStem
  372. **
  373. ** Description:
  374. ** This function generates the code that
  375. ** will initiate the graphics state of the
  376. ** TrueType interpreter for the grid fitting
  377. ** of vertical stems.
  378. ***/
  379. void EmitHorizontalStems _ARGS((INOUT UBYTE *pgm,
  380. INOUT short *pc,
  381. INOUT short *args,
  382. INOUT short *pcd));
  383. /***
  384. ** Function: EmitVStem
  385. **
  386. ** Description:
  387. ** This function generates the code that
  388. ** will create and grid fit points in the
  389. ** twilight zone, corresponding to a vstem.
  390. ***/
  391. errcode EmitVStem _ARGS((INOUT UBYTE *pgm,
  392. INOUT short *pc,
  393. INOUT short *args,
  394. INOUT short *pcd,
  395. INOUT struct T1Metrics *t1m,
  396. IN funit width,
  397. IN funit real_side1,
  398. IN funit real_side2,
  399. IN funit side1,
  400. IN funit side2,
  401. IN short rp,
  402. IN enum aligntype align,
  403. IN short ref));
  404. /***
  405. ** Function: EmitHStem
  406. **
  407. ** Description:
  408. ** This function generates the code that
  409. ** will create and grid fit points in the
  410. ** twilight zone, corresponding to a hstem.
  411. ***/
  412. errcode EmitHStem _ARGS((INOUT UBYTE *pgm,
  413. INOUT short *pc,
  414. INOUT short *args,
  415. INOUT short *pcd,
  416. INOUT struct T1Metrics *t1m,
  417. IN funit width,
  418. IN funit side1,
  419. IN funit side2,
  420. IN short rp,
  421. IN enum aligntype align,
  422. IN short ref));
  423. /***
  424. ** Function: FamilyCutIn
  425. **
  426. ** Description:
  427. ** This function generates a branch in the
  428. ** pre-program.
  429. ***/
  430. USHORT FamilyCutIn _ARGS((INOUT UBYTE *pgm,
  431. INOUT USHORT tp,
  432. IN short cis));
  433. /***
  434. ** Function: SetProjection
  435. **
  436. ** Description:
  437. ** This function generates the TrueType code that
  438. ** changes the projection vector in oblique typefaces.
  439. ***/
  440. void SetProjection _ARGS((INOUT UBYTE *pgm,
  441. INOUT short *pc,
  442. INOUT short *args,
  443. INOUT short *pcd,
  444. IN funit x,
  445. IN funit y));
  446. /***
  447. ** Function: AssembleArgs
  448. **
  449. ** Description:
  450. ** This function takes a sequence of arguments and
  451. ** assembles them into a sequence of PUSHB1[], PUSHW1[],
  452. ** NPUSHB[] and NPUSHW[] instructions.
  453. ***/
  454. void AssembleArgs _ARGS((INOUT short *args,
  455. IN short pcd,
  456. OUT UBYTE *is,
  457. INOUT short *cnt));