pshints.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. /***************************************************************************/
  2. /* */
  3. /* pshints.h */
  4. /* */
  5. /* Interface to Postscript-specific (Type 1 and Type 2) hints */
  6. /* recorders (specification only). These are used to support native */
  7. /* T1/T2 hints in the `type1', `cid', and `cff' font drivers. */
  8. /* */
  9. /* Copyright 2001-2003, 2005-2007, 2009, 2012 by */
  10. /* David Turner, Robert Wilhelm, and Werner Lemberg. */
  11. /* */
  12. /* This file is part of the FreeType project, and may only be used, */
  13. /* modified, and distributed under the terms of the FreeType project */
  14. /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
  15. /* this file you indicate that you have read the license and */
  16. /* understand and accept it fully. */
  17. /* */
  18. /***************************************************************************/
  19. #ifndef __PSHINTS_H__
  20. #define __PSHINTS_H__
  21. #include <ft2build.h>
  22. #include FT_FREETYPE_H
  23. #include FT_TYPE1_TABLES_H
  24. FT_BEGIN_HEADER
  25. /*************************************************************************/
  26. /*************************************************************************/
  27. /***** *****/
  28. /***** INTERNAL REPRESENTATION OF GLOBALS *****/
  29. /***** *****/
  30. /*************************************************************************/
  31. /*************************************************************************/
  32. typedef struct PSH_GlobalsRec_* PSH_Globals;
  33. typedef FT_Error
  34. (*PSH_Globals_NewFunc)( FT_Memory memory,
  35. T1_Private* private_dict,
  36. PSH_Globals* aglobals );
  37. typedef FT_Error
  38. (*PSH_Globals_SetScaleFunc)( PSH_Globals globals,
  39. FT_Fixed x_scale,
  40. FT_Fixed y_scale,
  41. FT_Fixed x_delta,
  42. FT_Fixed y_delta );
  43. typedef void
  44. (*PSH_Globals_DestroyFunc)( PSH_Globals globals );
  45. typedef struct PSH_Globals_FuncsRec_
  46. {
  47. PSH_Globals_NewFunc create;
  48. PSH_Globals_SetScaleFunc set_scale;
  49. PSH_Globals_DestroyFunc destroy;
  50. } PSH_Globals_FuncsRec, *PSH_Globals_Funcs;
  51. /*************************************************************************/
  52. /*************************************************************************/
  53. /***** *****/
  54. /***** PUBLIC TYPE 1 HINTS RECORDER *****/
  55. /***** *****/
  56. /*************************************************************************/
  57. /*************************************************************************/
  58. /*************************************************************************
  59. *
  60. * @type:
  61. * T1_Hints
  62. *
  63. * @description:
  64. * This is a handle to an opaque structure used to record glyph hints
  65. * from a Type 1 character glyph character string.
  66. *
  67. * The methods used to operate on this object are defined by the
  68. * @T1_Hints_FuncsRec structure. Recording glyph hints is normally
  69. * achieved through the following scheme:
  70. *
  71. * - Open a new hint recording session by calling the `open' method.
  72. * This rewinds the recorder and prepare it for new input.
  73. *
  74. * - For each hint found in the glyph charstring, call the corresponding
  75. * method (`stem', `stem3', or `reset'). Note that these functions do
  76. * not return an error code.
  77. *
  78. * - Close the recording session by calling the `close' method. It
  79. * returns an error code if the hints were invalid or something
  80. * strange happened (e.g., memory shortage).
  81. *
  82. * The hints accumulated in the object can later be used by the
  83. * PostScript hinter.
  84. *
  85. */
  86. typedef struct T1_HintsRec_* T1_Hints;
  87. /*************************************************************************
  88. *
  89. * @type:
  90. * T1_Hints_Funcs
  91. *
  92. * @description:
  93. * A pointer to the @T1_Hints_FuncsRec structure that defines the API of
  94. * a given @T1_Hints object.
  95. *
  96. */
  97. typedef const struct T1_Hints_FuncsRec_* T1_Hints_Funcs;
  98. /*************************************************************************
  99. *
  100. * @functype:
  101. * T1_Hints_OpenFunc
  102. *
  103. * @description:
  104. * A method of the @T1_Hints class used to prepare it for a new Type 1
  105. * hints recording session.
  106. *
  107. * @input:
  108. * hints ::
  109. * A handle to the Type 1 hints recorder.
  110. *
  111. * @note:
  112. * You should always call the @T1_Hints_CloseFunc method in order to
  113. * close an opened recording session.
  114. *
  115. */
  116. typedef void
  117. (*T1_Hints_OpenFunc)( T1_Hints hints );
  118. /*************************************************************************
  119. *
  120. * @functype:
  121. * T1_Hints_SetStemFunc
  122. *
  123. * @description:
  124. * A method of the @T1_Hints class used to record a new horizontal or
  125. * vertical stem. This corresponds to the Type 1 `hstem' and `vstem'
  126. * operators.
  127. *
  128. * @input:
  129. * hints ::
  130. * A handle to the Type 1 hints recorder.
  131. *
  132. * dimension ::
  133. * 0 for horizontal stems (hstem), 1 for vertical ones (vstem).
  134. *
  135. * coords ::
  136. * Array of 2 coordinates in 16.16 format, used as (position,length)
  137. * stem descriptor.
  138. *
  139. * @note:
  140. * Use vertical coordinates (y) for horizontal stems (dim=0). Use
  141. * horizontal coordinates (x) for vertical stems (dim=1).
  142. *
  143. * `coords[0]' is the absolute stem position (lowest coordinate);
  144. * `coords[1]' is the length.
  145. *
  146. * The length can be negative, in which case it must be either -20 or
  147. * -21. It is interpreted as a `ghost' stem, according to the Type 1
  148. * specification.
  149. *
  150. * If the length is -21 (corresponding to a bottom ghost stem), then
  151. * the real stem position is `coords[0]+coords[1]'.
  152. *
  153. */
  154. typedef void
  155. (*T1_Hints_SetStemFunc)( T1_Hints hints,
  156. FT_UInt dimension,
  157. FT_Fixed* coords );
  158. /*************************************************************************
  159. *
  160. * @functype:
  161. * T1_Hints_SetStem3Func
  162. *
  163. * @description:
  164. * A method of the @T1_Hints class used to record three
  165. * counter-controlled horizontal or vertical stems at once.
  166. *
  167. * @input:
  168. * hints ::
  169. * A handle to the Type 1 hints recorder.
  170. *
  171. * dimension ::
  172. * 0 for horizontal stems, 1 for vertical ones.
  173. *
  174. * coords ::
  175. * An array of 6 values in 16.16 format, holding 3 (position,length)
  176. * pairs for the counter-controlled stems.
  177. *
  178. * @note:
  179. * Use vertical coordinates (y) for horizontal stems (dim=0). Use
  180. * horizontal coordinates (x) for vertical stems (dim=1).
  181. *
  182. * The lengths cannot be negative (ghost stems are never
  183. * counter-controlled).
  184. *
  185. */
  186. typedef void
  187. (*T1_Hints_SetStem3Func)( T1_Hints hints,
  188. FT_UInt dimension,
  189. FT_Fixed* coords );
  190. /*************************************************************************
  191. *
  192. * @functype:
  193. * T1_Hints_ResetFunc
  194. *
  195. * @description:
  196. * A method of the @T1_Hints class used to reset the stems hints in a
  197. * recording session.
  198. *
  199. * @input:
  200. * hints ::
  201. * A handle to the Type 1 hints recorder.
  202. *
  203. * end_point ::
  204. * The index of the last point in the input glyph in which the
  205. * previously defined hints apply.
  206. *
  207. */
  208. typedef void
  209. (*T1_Hints_ResetFunc)( T1_Hints hints,
  210. FT_UInt end_point );
  211. /*************************************************************************
  212. *
  213. * @functype:
  214. * T1_Hints_CloseFunc
  215. *
  216. * @description:
  217. * A method of the @T1_Hints class used to close a hint recording
  218. * session.
  219. *
  220. * @input:
  221. * hints ::
  222. * A handle to the Type 1 hints recorder.
  223. *
  224. * end_point ::
  225. * The index of the last point in the input glyph.
  226. *
  227. * @return:
  228. * FreeType error code. 0 means success.
  229. *
  230. * @note:
  231. * The error code is set to indicate that an error occurred during the
  232. * recording session.
  233. *
  234. */
  235. typedef FT_Error
  236. (*T1_Hints_CloseFunc)( T1_Hints hints,
  237. FT_UInt end_point );
  238. /*************************************************************************
  239. *
  240. * @functype:
  241. * T1_Hints_ApplyFunc
  242. *
  243. * @description:
  244. * A method of the @T1_Hints class used to apply hints to the
  245. * corresponding glyph outline. Must be called once all hints have been
  246. * recorded.
  247. *
  248. * @input:
  249. * hints ::
  250. * A handle to the Type 1 hints recorder.
  251. *
  252. * outline ::
  253. * A pointer to the target outline descriptor.
  254. *
  255. * globals ::
  256. * The hinter globals for this font.
  257. *
  258. * hint_mode ::
  259. * Hinting information.
  260. *
  261. * @return:
  262. * FreeType error code. 0 means success.
  263. *
  264. * @note:
  265. * On input, all points within the outline are in font coordinates. On
  266. * output, they are in 1/64th of pixels.
  267. *
  268. * The scaling transformation is taken from the `globals' object which
  269. * must correspond to the same font as the glyph.
  270. *
  271. */
  272. typedef FT_Error
  273. (*T1_Hints_ApplyFunc)( T1_Hints hints,
  274. FT_Outline* outline,
  275. PSH_Globals globals,
  276. FT_Render_Mode hint_mode );
  277. /*************************************************************************
  278. *
  279. * @struct:
  280. * T1_Hints_FuncsRec
  281. *
  282. * @description:
  283. * The structure used to provide the API to @T1_Hints objects.
  284. *
  285. * @fields:
  286. * hints ::
  287. * A handle to the T1 Hints recorder.
  288. *
  289. * open ::
  290. * The function to open a recording session.
  291. *
  292. * close ::
  293. * The function to close a recording session.
  294. *
  295. * stem ::
  296. * The function to set a simple stem.
  297. *
  298. * stem3 ::
  299. * The function to set counter-controlled stems.
  300. *
  301. * reset ::
  302. * The function to reset stem hints.
  303. *
  304. * apply ::
  305. * The function to apply the hints to the corresponding glyph outline.
  306. *
  307. */
  308. typedef struct T1_Hints_FuncsRec_
  309. {
  310. T1_Hints hints;
  311. T1_Hints_OpenFunc open;
  312. T1_Hints_CloseFunc close;
  313. T1_Hints_SetStemFunc stem;
  314. T1_Hints_SetStem3Func stem3;
  315. T1_Hints_ResetFunc reset;
  316. T1_Hints_ApplyFunc apply;
  317. } T1_Hints_FuncsRec;
  318. /*************************************************************************/
  319. /*************************************************************************/
  320. /***** *****/
  321. /***** PUBLIC TYPE 2 HINTS RECORDER *****/
  322. /***** *****/
  323. /*************************************************************************/
  324. /*************************************************************************/
  325. /*************************************************************************
  326. *
  327. * @type:
  328. * T2_Hints
  329. *
  330. * @description:
  331. * This is a handle to an opaque structure used to record glyph hints
  332. * from a Type 2 character glyph character string.
  333. *
  334. * The methods used to operate on this object are defined by the
  335. * @T2_Hints_FuncsRec structure. Recording glyph hints is normally
  336. * achieved through the following scheme:
  337. *
  338. * - Open a new hint recording session by calling the `open' method.
  339. * This rewinds the recorder and prepare it for new input.
  340. *
  341. * - For each hint found in the glyph charstring, call the corresponding
  342. * method (`stems', `hintmask', `counters'). Note that these
  343. * functions do not return an error code.
  344. *
  345. * - Close the recording session by calling the `close' method. It
  346. * returns an error code if the hints were invalid or something
  347. * strange happened (e.g., memory shortage).
  348. *
  349. * The hints accumulated in the object can later be used by the
  350. * Postscript hinter.
  351. *
  352. */
  353. typedef struct T2_HintsRec_* T2_Hints;
  354. /*************************************************************************
  355. *
  356. * @type:
  357. * T2_Hints_Funcs
  358. *
  359. * @description:
  360. * A pointer to the @T2_Hints_FuncsRec structure that defines the API of
  361. * a given @T2_Hints object.
  362. *
  363. */
  364. typedef const struct T2_Hints_FuncsRec_* T2_Hints_Funcs;
  365. /*************************************************************************
  366. *
  367. * @functype:
  368. * T2_Hints_OpenFunc
  369. *
  370. * @description:
  371. * A method of the @T2_Hints class used to prepare it for a new Type 2
  372. * hints recording session.
  373. *
  374. * @input:
  375. * hints ::
  376. * A handle to the Type 2 hints recorder.
  377. *
  378. * @note:
  379. * You should always call the @T2_Hints_CloseFunc method in order to
  380. * close an opened recording session.
  381. *
  382. */
  383. typedef void
  384. (*T2_Hints_OpenFunc)( T2_Hints hints );
  385. /*************************************************************************
  386. *
  387. * @functype:
  388. * T2_Hints_StemsFunc
  389. *
  390. * @description:
  391. * A method of the @T2_Hints class used to set the table of stems in
  392. * either the vertical or horizontal dimension. Equivalent to the
  393. * `hstem', `vstem', `hstemhm', and `vstemhm' Type 2 operators.
  394. *
  395. * @input:
  396. * hints ::
  397. * A handle to the Type 2 hints recorder.
  398. *
  399. * dimension ::
  400. * 0 for horizontal stems (hstem), 1 for vertical ones (vstem).
  401. *
  402. * count ::
  403. * The number of stems.
  404. *
  405. * coords ::
  406. * An array of `count' (position,length) pairs in 16.16 format.
  407. *
  408. * @note:
  409. * Use vertical coordinates (y) for horizontal stems (dim=0). Use
  410. * horizontal coordinates (x) for vertical stems (dim=1).
  411. *
  412. * There are `2*count' elements in the `coords' array. Each even
  413. * element is an absolute position in font units, each odd element is a
  414. * length in font units.
  415. *
  416. * A length can be negative, in which case it must be either -20 or
  417. * -21. It is interpreted as a `ghost' stem, according to the Type 1
  418. * specification.
  419. *
  420. */
  421. typedef void
  422. (*T2_Hints_StemsFunc)( T2_Hints hints,
  423. FT_UInt dimension,
  424. FT_UInt count,
  425. FT_Fixed* coordinates );
  426. /*************************************************************************
  427. *
  428. * @functype:
  429. * T2_Hints_MaskFunc
  430. *
  431. * @description:
  432. * A method of the @T2_Hints class used to set a given hintmask (this
  433. * corresponds to the `hintmask' Type 2 operator).
  434. *
  435. * @input:
  436. * hints ::
  437. * A handle to the Type 2 hints recorder.
  438. *
  439. * end_point ::
  440. * The glyph index of the last point to which the previously defined
  441. * or activated hints apply.
  442. *
  443. * bit_count ::
  444. * The number of bits in the hint mask.
  445. *
  446. * bytes ::
  447. * An array of bytes modelling the hint mask.
  448. *
  449. * @note:
  450. * If the hintmask starts the charstring (before any glyph point
  451. * definition), the value of `end_point' should be 0.
  452. *
  453. * `bit_count' is the number of meaningful bits in the `bytes' array; it
  454. * must be equal to the total number of hints defined so far (i.e.,
  455. * horizontal+verticals).
  456. *
  457. * The `bytes' array can come directly from the Type 2 charstring and
  458. * respects the same format.
  459. *
  460. */
  461. typedef void
  462. (*T2_Hints_MaskFunc)( T2_Hints hints,
  463. FT_UInt end_point,
  464. FT_UInt bit_count,
  465. const FT_Byte* bytes );
  466. /*************************************************************************
  467. *
  468. * @functype:
  469. * T2_Hints_CounterFunc
  470. *
  471. * @description:
  472. * A method of the @T2_Hints class used to set a given counter mask
  473. * (this corresponds to the `hintmask' Type 2 operator).
  474. *
  475. * @input:
  476. * hints ::
  477. * A handle to the Type 2 hints recorder.
  478. *
  479. * end_point ::
  480. * A glyph index of the last point to which the previously defined or
  481. * active hints apply.
  482. *
  483. * bit_count ::
  484. * The number of bits in the hint mask.
  485. *
  486. * bytes ::
  487. * An array of bytes modelling the hint mask.
  488. *
  489. * @note:
  490. * If the hintmask starts the charstring (before any glyph point
  491. * definition), the value of `end_point' should be 0.
  492. *
  493. * `bit_count' is the number of meaningful bits in the `bytes' array; it
  494. * must be equal to the total number of hints defined so far (i.e.,
  495. * horizontal+verticals).
  496. *
  497. * The `bytes' array can come directly from the Type 2 charstring and
  498. * respects the same format.
  499. *
  500. */
  501. typedef void
  502. (*T2_Hints_CounterFunc)( T2_Hints hints,
  503. FT_UInt bit_count,
  504. const FT_Byte* bytes );
  505. /*************************************************************************
  506. *
  507. * @functype:
  508. * T2_Hints_CloseFunc
  509. *
  510. * @description:
  511. * A method of the @T2_Hints class used to close a hint recording
  512. * session.
  513. *
  514. * @input:
  515. * hints ::
  516. * A handle to the Type 2 hints recorder.
  517. *
  518. * end_point ::
  519. * The index of the last point in the input glyph.
  520. *
  521. * @return:
  522. * FreeType error code. 0 means success.
  523. *
  524. * @note:
  525. * The error code is set to indicate that an error occurred during the
  526. * recording session.
  527. *
  528. */
  529. typedef FT_Error
  530. (*T2_Hints_CloseFunc)( T2_Hints hints,
  531. FT_UInt end_point );
  532. /*************************************************************************
  533. *
  534. * @functype:
  535. * T2_Hints_ApplyFunc
  536. *
  537. * @description:
  538. * A method of the @T2_Hints class used to apply hints to the
  539. * corresponding glyph outline. Must be called after the `close'
  540. * method.
  541. *
  542. * @input:
  543. * hints ::
  544. * A handle to the Type 2 hints recorder.
  545. *
  546. * outline ::
  547. * A pointer to the target outline descriptor.
  548. *
  549. * globals ::
  550. * The hinter globals for this font.
  551. *
  552. * hint_mode ::
  553. * Hinting information.
  554. *
  555. * @return:
  556. * FreeType error code. 0 means success.
  557. *
  558. * @note:
  559. * On input, all points within the outline are in font coordinates. On
  560. * output, they are in 1/64th of pixels.
  561. *
  562. * The scaling transformation is taken from the `globals' object which
  563. * must correspond to the same font than the glyph.
  564. *
  565. */
  566. typedef FT_Error
  567. (*T2_Hints_ApplyFunc)( T2_Hints hints,
  568. FT_Outline* outline,
  569. PSH_Globals globals,
  570. FT_Render_Mode hint_mode );
  571. /*************************************************************************
  572. *
  573. * @struct:
  574. * T2_Hints_FuncsRec
  575. *
  576. * @description:
  577. * The structure used to provide the API to @T2_Hints objects.
  578. *
  579. * @fields:
  580. * hints ::
  581. * A handle to the T2 hints recorder object.
  582. *
  583. * open ::
  584. * The function to open a recording session.
  585. *
  586. * close ::
  587. * The function to close a recording session.
  588. *
  589. * stems ::
  590. * The function to set the dimension's stems table.
  591. *
  592. * hintmask ::
  593. * The function to set hint masks.
  594. *
  595. * counter ::
  596. * The function to set counter masks.
  597. *
  598. * apply ::
  599. * The function to apply the hints on the corresponding glyph outline.
  600. *
  601. */
  602. typedef struct T2_Hints_FuncsRec_
  603. {
  604. T2_Hints hints;
  605. T2_Hints_OpenFunc open;
  606. T2_Hints_CloseFunc close;
  607. T2_Hints_StemsFunc stems;
  608. T2_Hints_MaskFunc hintmask;
  609. T2_Hints_CounterFunc counter;
  610. T2_Hints_ApplyFunc apply;
  611. } T2_Hints_FuncsRec;
  612. /* */
  613. typedef struct PSHinter_Interface_
  614. {
  615. PSH_Globals_Funcs (*get_globals_funcs)( FT_Module module );
  616. T1_Hints_Funcs (*get_t1_funcs) ( FT_Module module );
  617. T2_Hints_Funcs (*get_t2_funcs) ( FT_Module module );
  618. } PSHinter_Interface;
  619. typedef PSHinter_Interface* PSHinter_Service;
  620. #ifndef FT_CONFIG_OPTION_PIC
  621. #define FT_DEFINE_PSHINTER_INTERFACE( \
  622. class_, \
  623. get_globals_funcs_, \
  624. get_t1_funcs_, \
  625. get_t2_funcs_ ) \
  626. static const PSHinter_Interface class_ = \
  627. { \
  628. get_globals_funcs_, \
  629. get_t1_funcs_, \
  630. get_t2_funcs_ \
  631. };
  632. #else /* FT_CONFIG_OPTION_PIC */
  633. #define FT_DEFINE_PSHINTER_INTERFACE( \
  634. class_, \
  635. get_globals_funcs_, \
  636. get_t1_funcs_, \
  637. get_t2_funcs_ ) \
  638. void \
  639. FT_Init_Class_ ## class_( FT_Library library, \
  640. PSHinter_Interface* clazz ) \
  641. { \
  642. FT_UNUSED( library ); \
  643. \
  644. clazz->get_globals_funcs = get_globals_funcs_; \
  645. clazz->get_t1_funcs = get_t1_funcs_; \
  646. clazz->get_t2_funcs = get_t2_funcs_; \
  647. }
  648. #endif /* FT_CONFIG_OPTION_PIC */
  649. FT_END_HEADER
  650. #endif /* __PSHINTS_H__ */
  651. /* END */