ftglyph.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. /***************************************************************************/
  2. /* */
  3. /* ftglyph.h */
  4. /* */
  5. /* FreeType convenience functions to handle glyphs (specification). */
  6. /* */
  7. /* Copyright 1996-2001, 2002, 2003, 2006 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. /*************************************************************************/
  18. /* */
  19. /* This file contains the definition of several convenience functions */
  20. /* that can be used by client applications to easily retrieve glyph */
  21. /* bitmaps and outlines from a given face. */
  22. /* */
  23. /* These functions should be optional if you are writing a font server */
  24. /* or text layout engine on top of FreeType. However, they are pretty */
  25. /* handy for many other simple uses of the library. */
  26. /* */
  27. /*************************************************************************/
  28. #ifndef __FTGLYPH_H__
  29. #define __FTGLYPH_H__
  30. #include <ft2build.h>
  31. #include FT_FREETYPE_H
  32. #ifdef FREETYPE_H
  33. #error "freetype.h of FreeType 1 has been loaded!"
  34. #error "Please fix the directory search order for header files"
  35. #error "so that freetype.h of FreeType 2 is found first."
  36. #endif
  37. FT_BEGIN_HEADER
  38. /*************************************************************************/
  39. /* */
  40. /* <Section> */
  41. /* glyph_management */
  42. /* */
  43. /* <Title> */
  44. /* Glyph Management */
  45. /* */
  46. /* <Abstract> */
  47. /* Generic interface to manage individual glyph data. */
  48. /* */
  49. /* <Description> */
  50. /* This section contains definitions used to manage glyph data */
  51. /* through generic FT_Glyph objects. Each of them can contain a */
  52. /* bitmap, a vector outline, or even images in other formats. */
  53. /* */
  54. /*************************************************************************/
  55. /* forward declaration to a private type */
  56. typedef struct FT_Glyph_Class_ FT_Glyph_Class;
  57. /*************************************************************************/
  58. /* */
  59. /* <Type> */
  60. /* FT_Glyph */
  61. /* */
  62. /* <Description> */
  63. /* Handle to an object used to model generic glyph images. It is a */
  64. /* pointer to the @FT_GlyphRec structure and can contain a glyph */
  65. /* bitmap or pointer. */
  66. /* */
  67. /* <Note> */
  68. /* Glyph objects are not owned by the library. You must thus release */
  69. /* them manually (through @FT_Done_Glyph) _before_ calling */
  70. /* @FT_Done_FreeType. */
  71. /* */
  72. typedef struct FT_GlyphRec_* FT_Glyph;
  73. /*************************************************************************/
  74. /* */
  75. /* <Struct> */
  76. /* FT_GlyphRec */
  77. /* */
  78. /* <Description> */
  79. /* The root glyph structure contains a given glyph image plus its */
  80. /* advance width in 16.16 fixed float format. */
  81. /* */
  82. /* <Fields> */
  83. /* library :: A handle to the FreeType library object. */
  84. /* */
  85. /* clazz :: A pointer to the glyph's class. Private. */
  86. /* */
  87. /* format :: The format of the glyph's image. */
  88. /* */
  89. /* advance :: A 16.16 vector that gives the glyph's advance width. */
  90. /* */
  91. typedef struct FT_GlyphRec_
  92. {
  93. FT_Library library;
  94. const FT_Glyph_Class* clazz;
  95. FT_Glyph_Format format;
  96. FT_Vector advance;
  97. } FT_GlyphRec;
  98. /*************************************************************************/
  99. /* */
  100. /* <Type> */
  101. /* FT_BitmapGlyph */
  102. /* */
  103. /* <Description> */
  104. /* A handle to an object used to model a bitmap glyph image. This is */
  105. /* a sub-class of @FT_Glyph, and a pointer to @FT_BitmapGlyphRec. */
  106. /* */
  107. typedef struct FT_BitmapGlyphRec_* FT_BitmapGlyph;
  108. /*************************************************************************/
  109. /* */
  110. /* <Struct> */
  111. /* FT_BitmapGlyphRec */
  112. /* */
  113. /* <Description> */
  114. /* A structure used for bitmap glyph images. This really is a */
  115. /* `sub-class' of @FT_GlyphRec. */
  116. /* */
  117. /* <Fields> */
  118. /* root :: The root @FT_Glyph fields. */
  119. /* */
  120. /* left :: The left-side bearing, i.e., the horizontal distance */
  121. /* from the current pen position to the left border of the */
  122. /* glyph bitmap. */
  123. /* */
  124. /* top :: The top-side bearing, i.e., the vertical distance from */
  125. /* the current pen position to the top border of the glyph */
  126. /* bitmap. This distance is positive for upwards-y! */
  127. /* */
  128. /* bitmap :: A descriptor for the bitmap. */
  129. /* */
  130. /* <Note> */
  131. /* You can typecast an @FT_Glyph to @FT_BitmapGlyph if you have */
  132. /* `glyph->format == FT_GLYPH_FORMAT_BITMAP'. This lets you access */
  133. /* the bitmap's contents easily. */
  134. /* */
  135. /* The corresponding pixel buffer is always owned by @FT_BitmapGlyph */
  136. /* and is thus created and destroyed with it. */
  137. /* */
  138. typedef struct FT_BitmapGlyphRec_
  139. {
  140. FT_GlyphRec root;
  141. FT_Int left;
  142. FT_Int top;
  143. FT_Bitmap bitmap;
  144. } FT_BitmapGlyphRec;
  145. /*************************************************************************/
  146. /* */
  147. /* <Type> */
  148. /* FT_OutlineGlyph */
  149. /* */
  150. /* <Description> */
  151. /* A handle to an object used to model an outline glyph image. This */
  152. /* is a sub-class of @FT_Glyph, and a pointer to @FT_OutlineGlyphRec. */
  153. /* */
  154. typedef struct FT_OutlineGlyphRec_* FT_OutlineGlyph;
  155. /*************************************************************************/
  156. /* */
  157. /* <Struct> */
  158. /* FT_OutlineGlyphRec */
  159. /* */
  160. /* <Description> */
  161. /* A structure used for outline (vectorial) glyph images. This */
  162. /* really is a `sub-class' of @FT_GlyphRec. */
  163. /* */
  164. /* <Fields> */
  165. /* root :: The root @FT_Glyph fields. */
  166. /* */
  167. /* outline :: A descriptor for the outline. */
  168. /* */
  169. /* <Note> */
  170. /* You can typecast a @FT_Glyph to @FT_OutlineGlyph if you have */
  171. /* `glyph->format == FT_GLYPH_FORMAT_OUTLINE'. This lets you access */
  172. /* the outline's content easily. */
  173. /* */
  174. /* As the outline is extracted from a glyph slot, its coordinates are */
  175. /* expressed normally in 26.6 pixels, unless the flag */
  176. /* @FT_LOAD_NO_SCALE was used in @FT_Load_Glyph() or @FT_Load_Char(). */
  177. /* */
  178. /* The outline's tables are always owned by the object and are */
  179. /* destroyed with it. */
  180. /* */
  181. typedef struct FT_OutlineGlyphRec_
  182. {
  183. FT_GlyphRec root;
  184. FT_Outline outline;
  185. } FT_OutlineGlyphRec;
  186. /*************************************************************************/
  187. /* */
  188. /* <Function> */
  189. /* FT_Get_Glyph */
  190. /* */
  191. /* <Description> */
  192. /* A function used to extract a glyph image from a slot. */
  193. /* */
  194. /* <Input> */
  195. /* slot :: A handle to the source glyph slot. */
  196. /* */
  197. /* <Output> */
  198. /* aglyph :: A handle to the glyph object. */
  199. /* */
  200. /* <Return> */
  201. /* FreeType error code. 0 means success. */
  202. /* */
  203. FT_EXPORT( FT_Error )
  204. FT_Get_Glyph( FT_GlyphSlot slot,
  205. FT_Glyph *aglyph );
  206. /*************************************************************************/
  207. /* */
  208. /* <Function> */
  209. /* FT_Glyph_Copy */
  210. /* */
  211. /* <Description> */
  212. /* A function used to copy a glyph image. Note that the created */
  213. /* @FT_Glyph object must be released with @FT_Done_Glyph. */
  214. /* */
  215. /* <Input> */
  216. /* source :: A handle to the source glyph object. */
  217. /* */
  218. /* <Output> */
  219. /* target :: A handle to the target glyph object. 0 in case of */
  220. /* error. */
  221. /* */
  222. /* <Return> */
  223. /* FreeType error code. 0 means success. */
  224. /* */
  225. FT_EXPORT( FT_Error )
  226. FT_Glyph_Copy( FT_Glyph source,
  227. FT_Glyph *target );
  228. /*************************************************************************/
  229. /* */
  230. /* <Function> */
  231. /* FT_Glyph_Transform */
  232. /* */
  233. /* <Description> */
  234. /* Transforms a glyph image if its format is scalable. */
  235. /* */
  236. /* <InOut> */
  237. /* glyph :: A handle to the target glyph object. */
  238. /* */
  239. /* <Input> */
  240. /* matrix :: A pointer to a 2x2 matrix to apply. */
  241. /* */
  242. /* delta :: A pointer to a 2d vector to apply. Coordinates are */
  243. /* expressed in 1/64th of a pixel. */
  244. /* */
  245. /* <Return> */
  246. /* FreeType error code (if not 0, the glyph format is not scalable). */
  247. /* */
  248. /* <Note> */
  249. /* The 2x2 transformation matrix is also applied to the glyph's */
  250. /* advance vector. */
  251. /* */
  252. FT_EXPORT( FT_Error )
  253. FT_Glyph_Transform( FT_Glyph glyph,
  254. FT_Matrix* matrix,
  255. FT_Vector* delta );
  256. /*************************************************************************/
  257. /* */
  258. /* <Enum> */
  259. /* FT_Glyph_BBox_Mode */
  260. /* */
  261. /* <Description> */
  262. /* The mode how the values of @FT_Glyph_Get_CBox are returned. */
  263. /* */
  264. /* <Values> */
  265. /* FT_GLYPH_BBOX_UNSCALED :: */
  266. /* Return unscaled font units. */
  267. /* */
  268. /* FT_GLYPH_BBOX_SUBPIXELS :: */
  269. /* Return unfitted 26.6 coordinates. */
  270. /* */
  271. /* FT_GLYPH_BBOX_GRIDFIT :: */
  272. /* Return grid-fitted 26.6 coordinates. */
  273. /* */
  274. /* FT_GLYPH_BBOX_TRUNCATE :: */
  275. /* Return coordinates in integer pixels. */
  276. /* */
  277. /* FT_GLYPH_BBOX_PIXELS :: */
  278. /* Return grid-fitted pixel coordinates. */
  279. /* */
  280. typedef enum FT_Glyph_BBox_Mode_
  281. {
  282. FT_GLYPH_BBOX_UNSCALED = 0,
  283. FT_GLYPH_BBOX_SUBPIXELS = 0,
  284. FT_GLYPH_BBOX_GRIDFIT = 1,
  285. FT_GLYPH_BBOX_TRUNCATE = 2,
  286. FT_GLYPH_BBOX_PIXELS = 3
  287. } FT_Glyph_BBox_Mode;
  288. /*************************************************************************/
  289. /* */
  290. /* <Enum> */
  291. /* ft_glyph_bbox_xxx */
  292. /* */
  293. /* <Description> */
  294. /* These constants are deprecated. Use the corresponding */
  295. /* @FT_Glyph_BBox_Mode values instead. */
  296. /* */
  297. /* <Values> */
  298. /* ft_glyph_bbox_unscaled :: See @FT_GLYPH_BBOX_UNSCALED. */
  299. /* ft_glyph_bbox_subpixels :: See @FT_GLYPH_BBOX_SUBPIXELS. */
  300. /* ft_glyph_bbox_gridfit :: See @FT_GLYPH_BBOX_GRIDFIT. */
  301. /* ft_glyph_bbox_truncate :: See @FT_GLYPH_BBOX_TRUNCATE. */
  302. /* ft_glyph_bbox_pixels :: See @FT_GLYPH_BBOX_PIXELS. */
  303. /* */
  304. #define ft_glyph_bbox_unscaled FT_GLYPH_BBOX_UNSCALED
  305. #define ft_glyph_bbox_subpixels FT_GLYPH_BBOX_SUBPIXELS
  306. #define ft_glyph_bbox_gridfit FT_GLYPH_BBOX_GRIDFIT
  307. #define ft_glyph_bbox_truncate FT_GLYPH_BBOX_TRUNCATE
  308. #define ft_glyph_bbox_pixels FT_GLYPH_BBOX_PIXELS
  309. /*************************************************************************/
  310. /* */
  311. /* <Function> */
  312. /* FT_Glyph_Get_CBox */
  313. /* */
  314. /* <Description> */
  315. /* Return a glyph's `control box'. The control box encloses all the */
  316. /* outline's points, including Bézier control points. Though it */
  317. /* coincides with the exact bounding box for most glyphs, it can be */
  318. /* slightly larger in some situations (like when rotating an outline */
  319. /* which contains Bézier outside arcs). */
  320. /* */
  321. /* Computing the control box is very fast, while getting the bounding */
  322. /* box can take much more time as it needs to walk over all segments */
  323. /* and arcs in the outline. To get the latter, you can use the */
  324. /* `ftbbox' component which is dedicated to this single task. */
  325. /* */
  326. /* <Input> */
  327. /* glyph :: A handle to the source glyph object. */
  328. /* */
  329. /* mode :: The mode which indicates how to interpret the returned */
  330. /* bounding box values. */
  331. /* */
  332. /* <Output> */
  333. /* acbox :: The glyph coordinate bounding box. Coordinates are */
  334. /* expressed in 1/64th of pixels if it is grid-fitted. */
  335. /* */
  336. /* <Note> */
  337. /* Coordinates are relative to the glyph origin, using the Y-upwards */
  338. /* convention. */
  339. /* */
  340. /* If the glyph has been loaded with @FT_LOAD_NO_SCALE, `bbox_mode' */
  341. /* must be set to @FT_GLYPH_BBOX_UNSCALED to get unscaled font */
  342. /* units in 26.6 pixel format. The value @FT_GLYPH_BBOX_SUBPIXELS */
  343. /* is another name for this constant. */
  344. /* */
  345. /* Note that the maximum coordinates are exclusive, which means that */
  346. /* one can compute the width and height of the glyph image (be it in */
  347. /* integer or 26.6 pixels) as: */
  348. /* */
  349. /* { */
  350. /* width = bbox.xMax - bbox.xMin; */
  351. /* height = bbox.yMax - bbox.yMin; */
  352. /* } */
  353. /* */
  354. /* Note also that for 26.6 coordinates, if `bbox_mode' is set to */
  355. /* @FT_GLYPH_BBOX_GRIDFIT, the coordinates will also be grid-fitted, */
  356. /* which corresponds to: */
  357. /* */
  358. /* { */
  359. /* bbox.xMin = FLOOR(bbox.xMin); */
  360. /* bbox.yMin = FLOOR(bbox.yMin); */
  361. /* bbox.xMax = CEILING(bbox.xMax); */
  362. /* bbox.yMax = CEILING(bbox.yMax); */
  363. /* } */
  364. /* */
  365. /* To get the bbox in pixel coordinates, set `bbox_mode' to */
  366. /* @FT_GLYPH_BBOX_TRUNCATE. */
  367. /* */
  368. /* To get the bbox in grid-fitted pixel coordinates, set `bbox_mode' */
  369. /* to @FT_GLYPH_BBOX_PIXELS. */
  370. /* */
  371. FT_EXPORT( void )
  372. FT_Glyph_Get_CBox( FT_Glyph glyph,
  373. FT_UInt bbox_mode,
  374. FT_BBox *acbox );
  375. /*************************************************************************/
  376. /* */
  377. /* <Function> */
  378. /* FT_Glyph_To_Bitmap */
  379. /* */
  380. /* <Description> */
  381. /* Converts a given glyph object to a bitmap glyph object. */
  382. /* */
  383. /* <InOut> */
  384. /* the_glyph :: A pointer to a handle to the target glyph. */
  385. /* */
  386. /* <Input> */
  387. /* render_mode :: An enumeration that describe how the data is */
  388. /* rendered. */
  389. /* */
  390. /* origin :: A pointer to a vector used to translate the glyph */
  391. /* image before rendering. Can be 0 (if no */
  392. /* translation). The origin is expressed in */
  393. /* 26.6 pixels. */
  394. /* */
  395. /* destroy :: A boolean that indicates that the original glyph */
  396. /* image should be destroyed by this function. It is */
  397. /* never destroyed in case of error. */
  398. /* */
  399. /* <Return> */
  400. /* FreeType error code. 0 means success. */
  401. /* */
  402. /* <Note> */
  403. /* The glyph image is translated with the `origin' vector before */
  404. /* rendering. */
  405. /* */
  406. /* The first parameter is a pointer to an @FT_Glyph handle, that will */
  407. /* be replaced by this function. Typically, you would use (omitting */
  408. /* error handling): */
  409. /* */
  410. /* */
  411. /* { */
  412. /* FT_Glyph glyph; */
  413. /* FT_BitmapGlyph glyph_bitmap; */
  414. /* */
  415. /* */
  416. /* // load glyph */
  417. /* error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAUT ); */
  418. /* */
  419. /* // extract glyph image */
  420. /* error = FT_Get_Glyph( face->glyph, &glyph ); */
  421. /* */
  422. /* // convert to a bitmap (default render mode + destroy old) */
  423. /* if ( glyph->format != FT_GLYPH_FORMAT_BITMAP ) */
  424. /* { */
  425. /* error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_DEFAULT, */
  426. /* 0, 1 ); */
  427. /* if ( error ) // glyph unchanged */
  428. /* ... */
  429. /* } */
  430. /* */
  431. /* // access bitmap content by typecasting */
  432. /* glyph_bitmap = (FT_BitmapGlyph)glyph; */
  433. /* */
  434. /* // do funny stuff with it, like blitting/drawing */
  435. /* ... */
  436. /* */
  437. /* // discard glyph image (bitmap or not) */
  438. /* FT_Done_Glyph( glyph ); */
  439. /* } */
  440. /* */
  441. /* */
  442. /* This function does nothing if the glyph format isn't scalable. */
  443. /* */
  444. FT_EXPORT( FT_Error )
  445. FT_Glyph_To_Bitmap( FT_Glyph* the_glyph,
  446. FT_Render_Mode render_mode,
  447. FT_Vector* origin,
  448. FT_Bool destroy );
  449. /*************************************************************************/
  450. /* */
  451. /* <Function> */
  452. /* FT_Done_Glyph */
  453. /* */
  454. /* <Description> */
  455. /* Destroys a given glyph. */
  456. /* */
  457. /* <Input> */
  458. /* glyph :: A handle to the target glyph object. */
  459. /* */
  460. FT_EXPORT( void )
  461. FT_Done_Glyph( FT_Glyph glyph );
  462. /* */
  463. /* other helpful functions */
  464. /*************************************************************************/
  465. /* */
  466. /* <Section> */
  467. /* computations */
  468. /* */
  469. /*************************************************************************/
  470. /*************************************************************************/
  471. /* */
  472. /* <Function> */
  473. /* FT_Matrix_Multiply */
  474. /* */
  475. /* <Description> */
  476. /* Performs the matrix operation `b = a*b'. */
  477. /* */
  478. /* <Input> */
  479. /* a :: A pointer to matrix `a'. */
  480. /* */
  481. /* <InOut> */
  482. /* b :: A pointer to matrix `b'. */
  483. /* */
  484. /* <Note> */
  485. /* The result is undefined if either `a' or `b' is zero. */
  486. /* */
  487. FT_EXPORT( void )
  488. FT_Matrix_Multiply( const FT_Matrix* a,
  489. FT_Matrix* b );
  490. /*************************************************************************/
  491. /* */
  492. /* <Function> */
  493. /* FT_Matrix_Invert */
  494. /* */
  495. /* <Description> */
  496. /* Inverts a 2x2 matrix. Returns an error if it can't be inverted. */
  497. /* */
  498. /* <InOut> */
  499. /* matrix :: A pointer to the target matrix. Remains untouched in */
  500. /* case of error. */
  501. /* */
  502. /* <Return> */
  503. /* FreeType error code. 0 means success. */
  504. /* */
  505. FT_EXPORT( FT_Error )
  506. FT_Matrix_Invert( FT_Matrix* matrix );
  507. /* */
  508. FT_END_HEADER
  509. #endif /* __FTGLYPH_H__ */
  510. /* END */
  511. /* Local Variables: */
  512. /* coding: utf-8 */
  513. /* End: */