ftimage.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. /****************************************************************************
  2. *
  3. * ftimage.h
  4. *
  5. * FreeType glyph image formats and default raster interface
  6. * (specification).
  7. *
  8. * Copyright (C) 1996-2023 by
  9. * David Turner, Robert Wilhelm, and Werner Lemberg.
  10. *
  11. * This file is part of the FreeType project, and may only be used,
  12. * modified, and distributed under the terms of the FreeType project
  13. * license, LICENSE.TXT. By continuing to use, modify, or distribute
  14. * this file you indicate that you have read the license and
  15. * understand and accept it fully.
  16. *
  17. */
  18. /**************************************************************************
  19. *
  20. * Note: A 'raster' is simply a scan-line converter, used to render
  21. * FT_Outlines into FT_Bitmaps.
  22. *
  23. */
  24. #ifndef FTIMAGE_H_
  25. #define FTIMAGE_H_
  26. FT_BEGIN_HEADER
  27. /**************************************************************************
  28. *
  29. * @section:
  30. * basic_types
  31. *
  32. */
  33. /**************************************************************************
  34. *
  35. * @type:
  36. * FT_Pos
  37. *
  38. * @description:
  39. * The type FT_Pos is used to store vectorial coordinates. Depending on
  40. * the context, these can represent distances in integer font units, or
  41. * 16.16, or 26.6 fixed-point pixel coordinates.
  42. */
  43. typedef signed long FT_Pos;
  44. /**************************************************************************
  45. *
  46. * @struct:
  47. * FT_Vector
  48. *
  49. * @description:
  50. * A simple structure used to store a 2D vector; coordinates are of the
  51. * FT_Pos type.
  52. *
  53. * @fields:
  54. * x ::
  55. * The horizontal coordinate.
  56. * y ::
  57. * The vertical coordinate.
  58. */
  59. typedef struct FT_Vector_
  60. {
  61. FT_Pos x;
  62. FT_Pos y;
  63. } FT_Vector;
  64. /**************************************************************************
  65. *
  66. * @struct:
  67. * FT_BBox
  68. *
  69. * @description:
  70. * A structure used to hold an outline's bounding box, i.e., the
  71. * coordinates of its extrema in the horizontal and vertical directions.
  72. *
  73. * @fields:
  74. * xMin ::
  75. * The horizontal minimum (left-most).
  76. *
  77. * yMin ::
  78. * The vertical minimum (bottom-most).
  79. *
  80. * xMax ::
  81. * The horizontal maximum (right-most).
  82. *
  83. * yMax ::
  84. * The vertical maximum (top-most).
  85. *
  86. * @note:
  87. * The bounding box is specified with the coordinates of the lower left
  88. * and the upper right corner. In PostScript, those values are often
  89. * called (llx,lly) and (urx,ury), respectively.
  90. *
  91. * If `yMin` is negative, this value gives the glyph's descender.
  92. * Otherwise, the glyph doesn't descend below the baseline. Similarly,
  93. * if `ymax` is positive, this value gives the glyph's ascender.
  94. *
  95. * `xMin` gives the horizontal distance from the glyph's origin to the
  96. * left edge of the glyph's bounding box. If `xMin` is negative, the
  97. * glyph extends to the left of the origin.
  98. */
  99. typedef struct FT_BBox_
  100. {
  101. FT_Pos xMin, yMin;
  102. FT_Pos xMax, yMax;
  103. } FT_BBox;
  104. /**************************************************************************
  105. *
  106. * @enum:
  107. * FT_Pixel_Mode
  108. *
  109. * @description:
  110. * An enumeration type used to describe the format of pixels in a given
  111. * bitmap. Note that additional formats may be added in the future.
  112. *
  113. * @values:
  114. * FT_PIXEL_MODE_NONE ::
  115. * Value~0 is reserved.
  116. *
  117. * FT_PIXEL_MODE_MONO ::
  118. * A monochrome bitmap, using 1~bit per pixel. Note that pixels are
  119. * stored in most-significant order (MSB), which means that the
  120. * left-most pixel in a byte has value 128.
  121. *
  122. * FT_PIXEL_MODE_GRAY ::
  123. * An 8-bit bitmap, generally used to represent anti-aliased glyph
  124. * images. Each pixel is stored in one byte. Note that the number of
  125. * 'gray' levels is stored in the `num_grays` field of the @FT_Bitmap
  126. * structure (it generally is 256).
  127. *
  128. * FT_PIXEL_MODE_GRAY2 ::
  129. * A 2-bit per pixel bitmap, used to represent embedded anti-aliased
  130. * bitmaps in font files according to the OpenType specification. We
  131. * haven't found a single font using this format, however.
  132. *
  133. * FT_PIXEL_MODE_GRAY4 ::
  134. * A 4-bit per pixel bitmap, representing embedded anti-aliased bitmaps
  135. * in font files according to the OpenType specification. We haven't
  136. * found a single font using this format, however.
  137. *
  138. * FT_PIXEL_MODE_LCD ::
  139. * An 8-bit bitmap, representing RGB or BGR decimated glyph images used
  140. * for display on LCD displays; the bitmap is three times wider than
  141. * the original glyph image. See also @FT_RENDER_MODE_LCD.
  142. *
  143. * FT_PIXEL_MODE_LCD_V ::
  144. * An 8-bit bitmap, representing RGB or BGR decimated glyph images used
  145. * for display on rotated LCD displays; the bitmap is three times
  146. * taller than the original glyph image. See also
  147. * @FT_RENDER_MODE_LCD_V.
  148. *
  149. * FT_PIXEL_MODE_BGRA ::
  150. * [Since 2.5] An image with four 8-bit channels per pixel,
  151. * representing a color image (such as emoticons) with alpha channel.
  152. * For each pixel, the format is BGRA, which means, the blue channel
  153. * comes first in memory. The color channels are pre-multiplied and in
  154. * the sRGB colorspace. For example, full red at half-translucent
  155. * opacity will be represented as '00,00,80,80', not '00,00,FF,80'.
  156. * See also @FT_LOAD_COLOR.
  157. */
  158. typedef enum FT_Pixel_Mode_
  159. {
  160. FT_PIXEL_MODE_NONE = 0,
  161. FT_PIXEL_MODE_MONO,
  162. FT_PIXEL_MODE_GRAY,
  163. FT_PIXEL_MODE_GRAY2,
  164. FT_PIXEL_MODE_GRAY4,
  165. FT_PIXEL_MODE_LCD,
  166. FT_PIXEL_MODE_LCD_V,
  167. FT_PIXEL_MODE_BGRA,
  168. FT_PIXEL_MODE_MAX /* do not remove */
  169. } FT_Pixel_Mode;
  170. /* these constants are deprecated; use the corresponding `FT_Pixel_Mode` */
  171. /* values instead. */
  172. #define ft_pixel_mode_none FT_PIXEL_MODE_NONE
  173. #define ft_pixel_mode_mono FT_PIXEL_MODE_MONO
  174. #define ft_pixel_mode_grays FT_PIXEL_MODE_GRAY
  175. #define ft_pixel_mode_pal2 FT_PIXEL_MODE_GRAY2
  176. #define ft_pixel_mode_pal4 FT_PIXEL_MODE_GRAY4
  177. /* */
  178. /* For debugging, the @FT_Pixel_Mode enumeration must stay in sync */
  179. /* with the `pixel_modes` array in file `ftobjs.c`. */
  180. /**************************************************************************
  181. *
  182. * @struct:
  183. * FT_Bitmap
  184. *
  185. * @description:
  186. * A structure used to describe a bitmap or pixmap to the raster. Note
  187. * that we now manage pixmaps of various depths through the `pixel_mode`
  188. * field.
  189. *
  190. * @fields:
  191. * rows ::
  192. * The number of bitmap rows.
  193. *
  194. * width ::
  195. * The number of pixels in bitmap row.
  196. *
  197. * pitch ::
  198. * The pitch's absolute value is the number of bytes taken by one
  199. * bitmap row, including padding. However, the pitch is positive when
  200. * the bitmap has a 'down' flow, and negative when it has an 'up' flow.
  201. * In all cases, the pitch is an offset to add to a bitmap pointer in
  202. * order to go down one row.
  203. *
  204. * Note that 'padding' means the alignment of a bitmap to a byte
  205. * border, and FreeType functions normally align to the smallest
  206. * possible integer value.
  207. *
  208. * For the B/W rasterizer, `pitch` is always an even number.
  209. *
  210. * To change the pitch of a bitmap (say, to make it a multiple of 4),
  211. * use @FT_Bitmap_Convert. Alternatively, you might use callback
  212. * functions to directly render to the application's surface; see the
  213. * file `example2.cpp` in the tutorial for a demonstration.
  214. *
  215. * buffer ::
  216. * A typeless pointer to the bitmap buffer. This value should be
  217. * aligned on 32-bit boundaries in most cases.
  218. *
  219. * num_grays ::
  220. * This field is only used with @FT_PIXEL_MODE_GRAY; it gives the
  221. * number of gray levels used in the bitmap.
  222. *
  223. * pixel_mode ::
  224. * The pixel mode, i.e., how pixel bits are stored. See @FT_Pixel_Mode
  225. * for possible values.
  226. *
  227. * palette_mode ::
  228. * This field is intended for paletted pixel modes; it indicates how
  229. * the palette is stored. Not used currently.
  230. *
  231. * palette ::
  232. * A typeless pointer to the bitmap palette; this field is intended for
  233. * paletted pixel modes. Not used currently.
  234. */
  235. typedef struct FT_Bitmap_
  236. {
  237. unsigned int rows;
  238. unsigned int width;
  239. int pitch;
  240. unsigned char* buffer;
  241. unsigned short num_grays;
  242. unsigned char pixel_mode;
  243. unsigned char palette_mode;
  244. void* palette;
  245. } FT_Bitmap;
  246. /**************************************************************************
  247. *
  248. * @section:
  249. * outline_processing
  250. *
  251. */
  252. /**************************************************************************
  253. *
  254. * @struct:
  255. * FT_Outline
  256. *
  257. * @description:
  258. * This structure is used to describe an outline to the scan-line
  259. * converter.
  260. *
  261. * @fields:
  262. * n_contours ::
  263. * The number of contours in the outline.
  264. *
  265. * n_points ::
  266. * The number of points in the outline.
  267. *
  268. * points ::
  269. * A pointer to an array of `n_points` @FT_Vector elements, giving the
  270. * outline's point coordinates.
  271. *
  272. * tags ::
  273. * A pointer to an array of `n_points` chars, giving each outline
  274. * point's type.
  275. *
  276. * If bit~0 is unset, the point is 'off' the curve, i.e., a Bezier
  277. * control point, while it is 'on' if set.
  278. *
  279. * Bit~1 is meaningful for 'off' points only. If set, it indicates a
  280. * third-order Bezier arc control point; and a second-order control
  281. * point if unset.
  282. *
  283. * If bit~2 is set, bits 5-7 contain the drop-out mode (as defined in
  284. * the OpenType specification; the value is the same as the argument to
  285. * the 'SCANMODE' instruction).
  286. *
  287. * Bits 3 and~4 are reserved for internal purposes.
  288. *
  289. * contours ::
  290. * An array of `n_contours` shorts, giving the end point of each
  291. * contour within the outline. For example, the first contour is
  292. * defined by the points '0' to `contours[0]`, the second one is
  293. * defined by the points `contours[0]+1` to `contours[1]`, etc.
  294. *
  295. * flags ::
  296. * A set of bit flags used to characterize the outline and give hints
  297. * to the scan-converter and hinter on how to convert/grid-fit it. See
  298. * @FT_OUTLINE_XXX.
  299. *
  300. * @note:
  301. * The B/W rasterizer only checks bit~2 in the `tags` array for the first
  302. * point of each contour. The drop-out mode as given with
  303. * @FT_OUTLINE_IGNORE_DROPOUTS, @FT_OUTLINE_SMART_DROPOUTS, and
  304. * @FT_OUTLINE_INCLUDE_STUBS in `flags` is then overridden.
  305. */
  306. typedef struct FT_Outline_
  307. {
  308. short n_contours; /* number of contours in glyph */
  309. short n_points; /* number of points in the glyph */
  310. FT_Vector* points; /* the outline's points */
  311. char* tags; /* the points flags */
  312. short* contours; /* the contour end points */
  313. int flags; /* outline masks */
  314. } FT_Outline;
  315. /* */
  316. /* Following limits must be consistent with */
  317. /* FT_Outline.{n_contours,n_points} */
  318. #define FT_OUTLINE_CONTOURS_MAX SHRT_MAX
  319. #define FT_OUTLINE_POINTS_MAX SHRT_MAX
  320. /**************************************************************************
  321. *
  322. * @enum:
  323. * FT_OUTLINE_XXX
  324. *
  325. * @description:
  326. * A list of bit-field constants used for the flags in an outline's
  327. * `flags` field.
  328. *
  329. * @values:
  330. * FT_OUTLINE_NONE ::
  331. * Value~0 is reserved.
  332. *
  333. * FT_OUTLINE_OWNER ::
  334. * If set, this flag indicates that the outline's field arrays (i.e.,
  335. * `points`, `flags`, and `contours`) are 'owned' by the outline
  336. * object, and should thus be freed when it is destroyed.
  337. *
  338. * FT_OUTLINE_EVEN_ODD_FILL ::
  339. * By default, outlines are filled using the non-zero winding rule. If
  340. * set to 1, the outline will be filled using the even-odd fill rule
  341. * (only works with the smooth rasterizer).
  342. *
  343. * FT_OUTLINE_REVERSE_FILL ::
  344. * By default, outside contours of an outline are oriented in
  345. * clock-wise direction, as defined in the TrueType specification.
  346. * This flag is set if the outline uses the opposite direction
  347. * (typically for Type~1 fonts). This flag is ignored by the scan
  348. * converter.
  349. *
  350. * FT_OUTLINE_IGNORE_DROPOUTS ::
  351. * By default, the scan converter will try to detect drop-outs in an
  352. * outline and correct the glyph bitmap to ensure consistent shape
  353. * continuity. If set, this flag hints the scan-line converter to
  354. * ignore such cases. See below for more information.
  355. *
  356. * FT_OUTLINE_SMART_DROPOUTS ::
  357. * Select smart dropout control. If unset, use simple dropout control.
  358. * Ignored if @FT_OUTLINE_IGNORE_DROPOUTS is set. See below for more
  359. * information.
  360. *
  361. * FT_OUTLINE_INCLUDE_STUBS ::
  362. * If set, turn pixels on for 'stubs', otherwise exclude them. Ignored
  363. * if @FT_OUTLINE_IGNORE_DROPOUTS is set. See below for more
  364. * information.
  365. *
  366. * FT_OUTLINE_OVERLAP ::
  367. * [Since 2.10.3] This flag indicates that this outline contains
  368. * overlapping contours and the anti-aliased renderer should perform
  369. * oversampling to mitigate possible artifacts. This flag should _not_
  370. * be set for well designed glyphs without overlaps because it quadruples
  371. * the rendering time.
  372. *
  373. * FT_OUTLINE_HIGH_PRECISION ::
  374. * This flag indicates that the scan-line converter should try to
  375. * convert this outline to bitmaps with the highest possible quality.
  376. * It is typically set for small character sizes. Note that this is
  377. * only a hint that might be completely ignored by a given
  378. * scan-converter.
  379. *
  380. * FT_OUTLINE_SINGLE_PASS ::
  381. * This flag is set to force a given scan-converter to only use a
  382. * single pass over the outline to render a bitmap glyph image.
  383. * Normally, it is set for very large character sizes. It is only a
  384. * hint that might be completely ignored by a given scan-converter.
  385. *
  386. * @note:
  387. * The flags @FT_OUTLINE_IGNORE_DROPOUTS, @FT_OUTLINE_SMART_DROPOUTS, and
  388. * @FT_OUTLINE_INCLUDE_STUBS are ignored by the smooth rasterizer.
  389. *
  390. * There exists a second mechanism to pass the drop-out mode to the B/W
  391. * rasterizer; see the `tags` field in @FT_Outline.
  392. *
  393. * Please refer to the description of the 'SCANTYPE' instruction in the
  394. * OpenType specification (in file `ttinst1.doc`) how simple drop-outs,
  395. * smart drop-outs, and stubs are defined.
  396. */
  397. #define FT_OUTLINE_NONE 0x0
  398. #define FT_OUTLINE_OWNER 0x1
  399. #define FT_OUTLINE_EVEN_ODD_FILL 0x2
  400. #define FT_OUTLINE_REVERSE_FILL 0x4
  401. #define FT_OUTLINE_IGNORE_DROPOUTS 0x8
  402. #define FT_OUTLINE_SMART_DROPOUTS 0x10
  403. #define FT_OUTLINE_INCLUDE_STUBS 0x20
  404. #define FT_OUTLINE_OVERLAP 0x40
  405. #define FT_OUTLINE_HIGH_PRECISION 0x100
  406. #define FT_OUTLINE_SINGLE_PASS 0x200
  407. /* these constants are deprecated; use the corresponding */
  408. /* `FT_OUTLINE_XXX` values instead */
  409. #define ft_outline_none FT_OUTLINE_NONE
  410. #define ft_outline_owner FT_OUTLINE_OWNER
  411. #define ft_outline_even_odd_fill FT_OUTLINE_EVEN_ODD_FILL
  412. #define ft_outline_reverse_fill FT_OUTLINE_REVERSE_FILL
  413. #define ft_outline_ignore_dropouts FT_OUTLINE_IGNORE_DROPOUTS
  414. #define ft_outline_high_precision FT_OUTLINE_HIGH_PRECISION
  415. #define ft_outline_single_pass FT_OUTLINE_SINGLE_PASS
  416. /* */
  417. #define FT_CURVE_TAG( flag ) ( flag & 0x03 )
  418. /* see the `tags` field in `FT_Outline` for a description of the values */
  419. #define FT_CURVE_TAG_ON 0x01
  420. #define FT_CURVE_TAG_CONIC 0x00
  421. #define FT_CURVE_TAG_CUBIC 0x02
  422. #define FT_CURVE_TAG_HAS_SCANMODE 0x04
  423. #define FT_CURVE_TAG_TOUCH_X 0x08 /* reserved for TrueType hinter */
  424. #define FT_CURVE_TAG_TOUCH_Y 0x10 /* reserved for TrueType hinter */
  425. #define FT_CURVE_TAG_TOUCH_BOTH ( FT_CURVE_TAG_TOUCH_X | \
  426. FT_CURVE_TAG_TOUCH_Y )
  427. /* values 0x20, 0x40, and 0x80 are reserved */
  428. /* these constants are deprecated; use the corresponding */
  429. /* `FT_CURVE_TAG_XXX` values instead */
  430. #define FT_Curve_Tag_On FT_CURVE_TAG_ON
  431. #define FT_Curve_Tag_Conic FT_CURVE_TAG_CONIC
  432. #define FT_Curve_Tag_Cubic FT_CURVE_TAG_CUBIC
  433. #define FT_Curve_Tag_Touch_X FT_CURVE_TAG_TOUCH_X
  434. #define FT_Curve_Tag_Touch_Y FT_CURVE_TAG_TOUCH_Y
  435. /**************************************************************************
  436. *
  437. * @functype:
  438. * FT_Outline_MoveToFunc
  439. *
  440. * @description:
  441. * A function pointer type used to describe the signature of a 'move to'
  442. * function during outline walking/decomposition.
  443. *
  444. * A 'move to' is emitted to start a new contour in an outline.
  445. *
  446. * @input:
  447. * to ::
  448. * A pointer to the target point of the 'move to'.
  449. *
  450. * user ::
  451. * A typeless pointer, which is passed from the caller of the
  452. * decomposition function.
  453. *
  454. * @return:
  455. * Error code. 0~means success.
  456. */
  457. typedef int
  458. (*FT_Outline_MoveToFunc)( const FT_Vector* to,
  459. void* user );
  460. #define FT_Outline_MoveTo_Func FT_Outline_MoveToFunc
  461. /**************************************************************************
  462. *
  463. * @functype:
  464. * FT_Outline_LineToFunc
  465. *
  466. * @description:
  467. * A function pointer type used to describe the signature of a 'line to'
  468. * function during outline walking/decomposition.
  469. *
  470. * A 'line to' is emitted to indicate a segment in the outline.
  471. *
  472. * @input:
  473. * to ::
  474. * A pointer to the target point of the 'line to'.
  475. *
  476. * user ::
  477. * A typeless pointer, which is passed from the caller of the
  478. * decomposition function.
  479. *
  480. * @return:
  481. * Error code. 0~means success.
  482. */
  483. typedef int
  484. (*FT_Outline_LineToFunc)( const FT_Vector* to,
  485. void* user );
  486. #define FT_Outline_LineTo_Func FT_Outline_LineToFunc
  487. /**************************************************************************
  488. *
  489. * @functype:
  490. * FT_Outline_ConicToFunc
  491. *
  492. * @description:
  493. * A function pointer type used to describe the signature of a 'conic to'
  494. * function during outline walking or decomposition.
  495. *
  496. * A 'conic to' is emitted to indicate a second-order Bezier arc in the
  497. * outline.
  498. *
  499. * @input:
  500. * control ::
  501. * An intermediate control point between the last position and the new
  502. * target in `to`.
  503. *
  504. * to ::
  505. * A pointer to the target end point of the conic arc.
  506. *
  507. * user ::
  508. * A typeless pointer, which is passed from the caller of the
  509. * decomposition function.
  510. *
  511. * @return:
  512. * Error code. 0~means success.
  513. */
  514. typedef int
  515. (*FT_Outline_ConicToFunc)( const FT_Vector* control,
  516. const FT_Vector* to,
  517. void* user );
  518. #define FT_Outline_ConicTo_Func FT_Outline_ConicToFunc
  519. /**************************************************************************
  520. *
  521. * @functype:
  522. * FT_Outline_CubicToFunc
  523. *
  524. * @description:
  525. * A function pointer type used to describe the signature of a 'cubic to'
  526. * function during outline walking or decomposition.
  527. *
  528. * A 'cubic to' is emitted to indicate a third-order Bezier arc.
  529. *
  530. * @input:
  531. * control1 ::
  532. * A pointer to the first Bezier control point.
  533. *
  534. * control2 ::
  535. * A pointer to the second Bezier control point.
  536. *
  537. * to ::
  538. * A pointer to the target end point.
  539. *
  540. * user ::
  541. * A typeless pointer, which is passed from the caller of the
  542. * decomposition function.
  543. *
  544. * @return:
  545. * Error code. 0~means success.
  546. */
  547. typedef int
  548. (*FT_Outline_CubicToFunc)( const FT_Vector* control1,
  549. const FT_Vector* control2,
  550. const FT_Vector* to,
  551. void* user );
  552. #define FT_Outline_CubicTo_Func FT_Outline_CubicToFunc
  553. /**************************************************************************
  554. *
  555. * @struct:
  556. * FT_Outline_Funcs
  557. *
  558. * @description:
  559. * A structure to hold various function pointers used during outline
  560. * decomposition in order to emit segments, conic, and cubic Beziers.
  561. *
  562. * @fields:
  563. * move_to ::
  564. * The 'move to' emitter.
  565. *
  566. * line_to ::
  567. * The segment emitter.
  568. *
  569. * conic_to ::
  570. * The second-order Bezier arc emitter.
  571. *
  572. * cubic_to ::
  573. * The third-order Bezier arc emitter.
  574. *
  575. * shift ::
  576. * The shift that is applied to coordinates before they are sent to the
  577. * emitter.
  578. *
  579. * delta ::
  580. * The delta that is applied to coordinates before they are sent to the
  581. * emitter, but after the shift.
  582. *
  583. * @note:
  584. * The point coordinates sent to the emitters are the transformed version
  585. * of the original coordinates (this is important for high accuracy
  586. * during scan-conversion). The transformation is simple:
  587. *
  588. * ```
  589. * x' = (x << shift) - delta
  590. * y' = (y << shift) - delta
  591. * ```
  592. *
  593. * Set the values of `shift` and `delta` to~0 to get the original point
  594. * coordinates.
  595. */
  596. typedef struct FT_Outline_Funcs_
  597. {
  598. FT_Outline_MoveToFunc move_to;
  599. FT_Outline_LineToFunc line_to;
  600. FT_Outline_ConicToFunc conic_to;
  601. FT_Outline_CubicToFunc cubic_to;
  602. int shift;
  603. FT_Pos delta;
  604. } FT_Outline_Funcs;
  605. /**************************************************************************
  606. *
  607. * @section:
  608. * basic_types
  609. *
  610. */
  611. /**************************************************************************
  612. *
  613. * @macro:
  614. * FT_IMAGE_TAG
  615. *
  616. * @description:
  617. * This macro converts four-letter tags to an unsigned long type.
  618. *
  619. * @note:
  620. * Since many 16-bit compilers don't like 32-bit enumerations, you should
  621. * redefine this macro in case of problems to something like this:
  622. *
  623. * ```
  624. * #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) value
  625. * ```
  626. *
  627. * to get a simple enumeration without assigning special numbers.
  628. */
  629. #ifndef FT_IMAGE_TAG
  630. #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) \
  631. value = ( ( FT_STATIC_BYTE_CAST( unsigned long, _x1 ) << 24 ) | \
  632. ( FT_STATIC_BYTE_CAST( unsigned long, _x2 ) << 16 ) | \
  633. ( FT_STATIC_BYTE_CAST( unsigned long, _x3 ) << 8 ) | \
  634. FT_STATIC_BYTE_CAST( unsigned long, _x4 ) )
  635. #endif /* FT_IMAGE_TAG */
  636. /**************************************************************************
  637. *
  638. * @enum:
  639. * FT_Glyph_Format
  640. *
  641. * @description:
  642. * An enumeration type used to describe the format of a given glyph
  643. * image. Note that this version of FreeType only supports two image
  644. * formats, even though future font drivers will be able to register
  645. * their own format.
  646. *
  647. * @values:
  648. * FT_GLYPH_FORMAT_NONE ::
  649. * The value~0 is reserved.
  650. *
  651. * FT_GLYPH_FORMAT_COMPOSITE ::
  652. * The glyph image is a composite of several other images. This format
  653. * is _only_ used with @FT_LOAD_NO_RECURSE, and is used to report
  654. * compound glyphs (like accented characters).
  655. *
  656. * FT_GLYPH_FORMAT_BITMAP ::
  657. * The glyph image is a bitmap, and can be described as an @FT_Bitmap.
  658. * You generally need to access the `bitmap` field of the
  659. * @FT_GlyphSlotRec structure to read it.
  660. *
  661. * FT_GLYPH_FORMAT_OUTLINE ::
  662. * The glyph image is a vectorial outline made of line segments and
  663. * Bezier arcs; it can be described as an @FT_Outline; you generally
  664. * want to access the `outline` field of the @FT_GlyphSlotRec structure
  665. * to read it.
  666. *
  667. * FT_GLYPH_FORMAT_PLOTTER ::
  668. * The glyph image is a vectorial path with no inside and outside
  669. * contours. Some Type~1 fonts, like those in the Hershey family,
  670. * contain glyphs in this format. These are described as @FT_Outline,
  671. * but FreeType isn't currently capable of rendering them correctly.
  672. *
  673. * FT_GLYPH_FORMAT_SVG ::
  674. * [Since 2.12] The glyph is represented by an SVG document in the
  675. * 'SVG~' table.
  676. */
  677. typedef enum FT_Glyph_Format_
  678. {
  679. FT_IMAGE_TAG( FT_GLYPH_FORMAT_NONE, 0, 0, 0, 0 ),
  680. FT_IMAGE_TAG( FT_GLYPH_FORMAT_COMPOSITE, 'c', 'o', 'm', 'p' ),
  681. FT_IMAGE_TAG( FT_GLYPH_FORMAT_BITMAP, 'b', 'i', 't', 's' ),
  682. FT_IMAGE_TAG( FT_GLYPH_FORMAT_OUTLINE, 'o', 'u', 't', 'l' ),
  683. FT_IMAGE_TAG( FT_GLYPH_FORMAT_PLOTTER, 'p', 'l', 'o', 't' ),
  684. FT_IMAGE_TAG( FT_GLYPH_FORMAT_SVG, 'S', 'V', 'G', ' ' )
  685. } FT_Glyph_Format;
  686. /* these constants are deprecated; use the corresponding */
  687. /* `FT_Glyph_Format` values instead. */
  688. #define ft_glyph_format_none FT_GLYPH_FORMAT_NONE
  689. #define ft_glyph_format_composite FT_GLYPH_FORMAT_COMPOSITE
  690. #define ft_glyph_format_bitmap FT_GLYPH_FORMAT_BITMAP
  691. #define ft_glyph_format_outline FT_GLYPH_FORMAT_OUTLINE
  692. #define ft_glyph_format_plotter FT_GLYPH_FORMAT_PLOTTER
  693. /*************************************************************************/
  694. /*************************************************************************/
  695. /*************************************************************************/
  696. /***** *****/
  697. /***** R A S T E R D E F I N I T I O N S *****/
  698. /***** *****/
  699. /*************************************************************************/
  700. /*************************************************************************/
  701. /*************************************************************************/
  702. /**************************************************************************
  703. *
  704. * @section:
  705. * raster
  706. *
  707. * @title:
  708. * Scanline Converter
  709. *
  710. * @abstract:
  711. * How vectorial outlines are converted into bitmaps and pixmaps.
  712. *
  713. * @description:
  714. * A raster or a rasterizer is a scan converter in charge of producing a
  715. * pixel coverage bitmap that can be used as an alpha channel when
  716. * compositing a glyph with a background. FreeType comes with two
  717. * rasterizers: bilevel `raster1` and anti-aliased `smooth` are two
  718. * separate modules. They are usually called from the high-level
  719. * @FT_Load_Glyph or @FT_Render_Glyph functions and produce the entire
  720. * coverage bitmap at once, while staying largely invisible to users.
  721. *
  722. * Instead of working with complete coverage bitmaps, it is also possible
  723. * to intercept consecutive pixel runs on the same scanline with the same
  724. * coverage, called _spans_, and process them individually. Only the
  725. * `smooth` rasterizer permits this when calling @FT_Outline_Render with
  726. * @FT_Raster_Params as described below.
  727. *
  728. * Working with either complete bitmaps or spans it is important to think
  729. * of them as colorless coverage objects suitable as alpha channels to
  730. * blend arbitrary colors with a background. For best results, it is
  731. * recommended to use gamma correction, too.
  732. *
  733. * This section also describes the public API needed to set up alternative
  734. * @FT_Renderer modules.
  735. *
  736. * @order:
  737. * FT_Span
  738. * FT_SpanFunc
  739. * FT_Raster_Params
  740. * FT_RASTER_FLAG_XXX
  741. *
  742. * FT_Raster
  743. * FT_Raster_NewFunc
  744. * FT_Raster_DoneFunc
  745. * FT_Raster_ResetFunc
  746. * FT_Raster_SetModeFunc
  747. * FT_Raster_RenderFunc
  748. * FT_Raster_Funcs
  749. *
  750. */
  751. /**************************************************************************
  752. *
  753. * @struct:
  754. * FT_Span
  755. *
  756. * @description:
  757. * A structure to model a single span of consecutive pixels when
  758. * rendering an anti-aliased bitmap.
  759. *
  760. * @fields:
  761. * x ::
  762. * The span's horizontal start position.
  763. *
  764. * len ::
  765. * The span's length in pixels.
  766. *
  767. * coverage ::
  768. * The span color/coverage, ranging from 0 (background) to 255
  769. * (foreground).
  770. *
  771. * @note:
  772. * This structure is used by the span drawing callback type named
  773. * @FT_SpanFunc that takes the y~coordinate of the span as a parameter.
  774. *
  775. * The anti-aliased rasterizer produces coverage values from 0 to 255,
  776. * this is, from completely transparent to completely opaque.
  777. */
  778. typedef struct FT_Span_
  779. {
  780. short x;
  781. unsigned short len;
  782. unsigned char coverage;
  783. } FT_Span;
  784. /**************************************************************************
  785. *
  786. * @functype:
  787. * FT_SpanFunc
  788. *
  789. * @description:
  790. * A function used as a call-back by the anti-aliased renderer in order
  791. * to let client applications draw themselves the pixel spans on each
  792. * scan line.
  793. *
  794. * @input:
  795. * y ::
  796. * The scanline's upward y~coordinate.
  797. *
  798. * count ::
  799. * The number of spans to draw on this scanline.
  800. *
  801. * spans ::
  802. * A table of `count` spans to draw on the scanline.
  803. *
  804. * user ::
  805. * User-supplied data that is passed to the callback.
  806. *
  807. * @note:
  808. * This callback allows client applications to directly render the spans
  809. * of the anti-aliased bitmap to any kind of surfaces.
  810. *
  811. * This can be used to write anti-aliased outlines directly to a given
  812. * background bitmap using alpha compositing. It can also be used for
  813. * oversampling and averaging.
  814. */
  815. typedef void
  816. (*FT_SpanFunc)( int y,
  817. int count,
  818. const FT_Span* spans,
  819. void* user );
  820. #define FT_Raster_Span_Func FT_SpanFunc
  821. /**************************************************************************
  822. *
  823. * @functype:
  824. * FT_Raster_BitTest_Func
  825. *
  826. * @description:
  827. * Deprecated, unimplemented.
  828. */
  829. typedef int
  830. (*FT_Raster_BitTest_Func)( int y,
  831. int x,
  832. void* user );
  833. /**************************************************************************
  834. *
  835. * @functype:
  836. * FT_Raster_BitSet_Func
  837. *
  838. * @description:
  839. * Deprecated, unimplemented.
  840. */
  841. typedef void
  842. (*FT_Raster_BitSet_Func)( int y,
  843. int x,
  844. void* user );
  845. /**************************************************************************
  846. *
  847. * @enum:
  848. * FT_RASTER_FLAG_XXX
  849. *
  850. * @description:
  851. * A list of bit flag constants as used in the `flags` field of a
  852. * @FT_Raster_Params structure.
  853. *
  854. * @values:
  855. * FT_RASTER_FLAG_DEFAULT ::
  856. * This value is 0.
  857. *
  858. * FT_RASTER_FLAG_AA ::
  859. * This flag is set to indicate that an anti-aliased glyph image should
  860. * be generated. Otherwise, it will be monochrome (1-bit).
  861. *
  862. * FT_RASTER_FLAG_DIRECT ::
  863. * This flag is set to indicate direct rendering. In this mode, client
  864. * applications must provide their own span callback. This lets them
  865. * directly draw or compose over an existing bitmap. If this bit is
  866. * _not_ set, the target pixmap's buffer _must_ be zeroed before
  867. * rendering and the output will be clipped to its size.
  868. *
  869. * Direct rendering is only possible with anti-aliased glyphs.
  870. *
  871. * FT_RASTER_FLAG_CLIP ::
  872. * This flag is only used in direct rendering mode. If set, the output
  873. * will be clipped to a box specified in the `clip_box` field of the
  874. * @FT_Raster_Params structure. Otherwise, the `clip_box` is
  875. * effectively set to the bounding box and all spans are generated.
  876. *
  877. * FT_RASTER_FLAG_SDF ::
  878. * This flag is set to indicate that a signed distance field glyph
  879. * image should be generated. This is only used while rendering with
  880. * the @FT_RENDER_MODE_SDF render mode.
  881. */
  882. #define FT_RASTER_FLAG_DEFAULT 0x0
  883. #define FT_RASTER_FLAG_AA 0x1
  884. #define FT_RASTER_FLAG_DIRECT 0x2
  885. #define FT_RASTER_FLAG_CLIP 0x4
  886. #define FT_RASTER_FLAG_SDF 0x8
  887. /* these constants are deprecated; use the corresponding */
  888. /* `FT_RASTER_FLAG_XXX` values instead */
  889. #define ft_raster_flag_default FT_RASTER_FLAG_DEFAULT
  890. #define ft_raster_flag_aa FT_RASTER_FLAG_AA
  891. #define ft_raster_flag_direct FT_RASTER_FLAG_DIRECT
  892. #define ft_raster_flag_clip FT_RASTER_FLAG_CLIP
  893. /**************************************************************************
  894. *
  895. * @struct:
  896. * FT_Raster_Params
  897. *
  898. * @description:
  899. * A structure to hold the parameters used by a raster's render function,
  900. * passed as an argument to @FT_Outline_Render.
  901. *
  902. * @fields:
  903. * target ::
  904. * The target bitmap.
  905. *
  906. * source ::
  907. * A pointer to the source glyph image (e.g., an @FT_Outline).
  908. *
  909. * flags ::
  910. * The rendering flags.
  911. *
  912. * gray_spans ::
  913. * The gray span drawing callback.
  914. *
  915. * black_spans ::
  916. * Unused.
  917. *
  918. * bit_test ::
  919. * Unused.
  920. *
  921. * bit_set ::
  922. * Unused.
  923. *
  924. * user ::
  925. * User-supplied data that is passed to each drawing callback.
  926. *
  927. * clip_box ::
  928. * An optional span clipping box expressed in _integer_ pixels
  929. * (not in 26.6 fixed-point units).
  930. *
  931. * @note:
  932. * The @FT_RASTER_FLAG_AA bit flag must be set in the `flags` to
  933. * generate an anti-aliased glyph bitmap, otherwise a monochrome bitmap
  934. * is generated. The `target` should have appropriate pixel mode and its
  935. * dimensions define the clipping region.
  936. *
  937. * If both @FT_RASTER_FLAG_AA and @FT_RASTER_FLAG_DIRECT bit flags
  938. * are set in `flags`, the raster calls an @FT_SpanFunc callback
  939. * `gray_spans` with `user` data as an argument ignoring `target`. This
  940. * allows direct composition over a pre-existing user surface to perform
  941. * the span drawing and composition. To optionally clip the spans, set
  942. * the @FT_RASTER_FLAG_CLIP flag and `clip_box`. The monochrome raster
  943. * does not support the direct mode.
  944. *
  945. * The gray-level rasterizer always uses 256 gray levels. If you want
  946. * fewer gray levels, you have to use @FT_RASTER_FLAG_DIRECT and reduce
  947. * the levels in the callback function.
  948. */
  949. typedef struct FT_Raster_Params_
  950. {
  951. const FT_Bitmap* target;
  952. const void* source;
  953. int flags;
  954. FT_SpanFunc gray_spans;
  955. FT_SpanFunc black_spans; /* unused */
  956. FT_Raster_BitTest_Func bit_test; /* unused */
  957. FT_Raster_BitSet_Func bit_set; /* unused */
  958. void* user;
  959. FT_BBox clip_box;
  960. } FT_Raster_Params;
  961. /**************************************************************************
  962. *
  963. * @type:
  964. * FT_Raster
  965. *
  966. * @description:
  967. * An opaque handle (pointer) to a raster object. Each object can be
  968. * used independently to convert an outline into a bitmap or pixmap.
  969. *
  970. * @note:
  971. * In FreeType 2, all rasters are now encapsulated within specific
  972. * @FT_Renderer modules and only used in their context.
  973. *
  974. */
  975. typedef struct FT_RasterRec_* FT_Raster;
  976. /**************************************************************************
  977. *
  978. * @functype:
  979. * FT_Raster_NewFunc
  980. *
  981. * @description:
  982. * A function used to create a new raster object.
  983. *
  984. * @input:
  985. * memory ::
  986. * A handle to the memory allocator.
  987. *
  988. * @output:
  989. * raster ::
  990. * A handle to the new raster object.
  991. *
  992. * @return:
  993. * Error code. 0~means success.
  994. *
  995. * @note:
  996. * The `memory` parameter is a typeless pointer in order to avoid
  997. * un-wanted dependencies on the rest of the FreeType code. In practice,
  998. * it is an @FT_Memory object, i.e., a handle to the standard FreeType
  999. * memory allocator. However, this field can be completely ignored by a
  1000. * given raster implementation.
  1001. */
  1002. typedef int
  1003. (*FT_Raster_NewFunc)( void* memory,
  1004. FT_Raster* raster );
  1005. #define FT_Raster_New_Func FT_Raster_NewFunc
  1006. /**************************************************************************
  1007. *
  1008. * @functype:
  1009. * FT_Raster_DoneFunc
  1010. *
  1011. * @description:
  1012. * A function used to destroy a given raster object.
  1013. *
  1014. * @input:
  1015. * raster ::
  1016. * A handle to the raster object.
  1017. */
  1018. typedef void
  1019. (*FT_Raster_DoneFunc)( FT_Raster raster );
  1020. #define FT_Raster_Done_Func FT_Raster_DoneFunc
  1021. /**************************************************************************
  1022. *
  1023. * @functype:
  1024. * FT_Raster_ResetFunc
  1025. *
  1026. * @description:
  1027. * FreeType used to provide an area of memory called the 'render pool'
  1028. * available to all registered rasterizers. This was not thread safe,
  1029. * however, and now FreeType never allocates this pool.
  1030. *
  1031. * This function is called after a new raster object is created.
  1032. *
  1033. * @input:
  1034. * raster ::
  1035. * A handle to the new raster object.
  1036. *
  1037. * pool_base ::
  1038. * Previously, the address in memory of the render pool. Set this to
  1039. * `NULL`.
  1040. *
  1041. * pool_size ::
  1042. * Previously, the size in bytes of the render pool. Set this to 0.
  1043. *
  1044. * @note:
  1045. * Rasterizers should rely on dynamic or stack allocation if they want to
  1046. * (a handle to the memory allocator is passed to the rasterizer
  1047. * constructor).
  1048. */
  1049. typedef void
  1050. (*FT_Raster_ResetFunc)( FT_Raster raster,
  1051. unsigned char* pool_base,
  1052. unsigned long pool_size );
  1053. #define FT_Raster_Reset_Func FT_Raster_ResetFunc
  1054. /**************************************************************************
  1055. *
  1056. * @functype:
  1057. * FT_Raster_SetModeFunc
  1058. *
  1059. * @description:
  1060. * This function is a generic facility to change modes or attributes in a
  1061. * given raster. This can be used for debugging purposes, or simply to
  1062. * allow implementation-specific 'features' in a given raster module.
  1063. *
  1064. * @input:
  1065. * raster ::
  1066. * A handle to the new raster object.
  1067. *
  1068. * mode ::
  1069. * A 4-byte tag used to name the mode or property.
  1070. *
  1071. * args ::
  1072. * A pointer to the new mode/property to use.
  1073. */
  1074. typedef int
  1075. (*FT_Raster_SetModeFunc)( FT_Raster raster,
  1076. unsigned long mode,
  1077. void* args );
  1078. #define FT_Raster_Set_Mode_Func FT_Raster_SetModeFunc
  1079. /**************************************************************************
  1080. *
  1081. * @functype:
  1082. * FT_Raster_RenderFunc
  1083. *
  1084. * @description:
  1085. * Invoke a given raster to scan-convert a given glyph image into a
  1086. * target bitmap.
  1087. *
  1088. * @input:
  1089. * raster ::
  1090. * A handle to the raster object.
  1091. *
  1092. * params ::
  1093. * A pointer to an @FT_Raster_Params structure used to store the
  1094. * rendering parameters.
  1095. *
  1096. * @return:
  1097. * Error code. 0~means success.
  1098. *
  1099. * @note:
  1100. * The exact format of the source image depends on the raster's glyph
  1101. * format defined in its @FT_Raster_Funcs structure. It can be an
  1102. * @FT_Outline or anything else in order to support a large array of
  1103. * glyph formats.
  1104. *
  1105. * Note also that the render function can fail and return a
  1106. * `FT_Err_Unimplemented_Feature` error code if the raster used does not
  1107. * support direct composition.
  1108. */
  1109. typedef int
  1110. (*FT_Raster_RenderFunc)( FT_Raster raster,
  1111. const FT_Raster_Params* params );
  1112. #define FT_Raster_Render_Func FT_Raster_RenderFunc
  1113. /**************************************************************************
  1114. *
  1115. * @struct:
  1116. * FT_Raster_Funcs
  1117. *
  1118. * @description:
  1119. * A structure used to describe a given raster class to the library.
  1120. *
  1121. * @fields:
  1122. * glyph_format ::
  1123. * The supported glyph format for this raster.
  1124. *
  1125. * raster_new ::
  1126. * The raster constructor.
  1127. *
  1128. * raster_reset ::
  1129. * Used to reset the render pool within the raster.
  1130. *
  1131. * raster_render ::
  1132. * A function to render a glyph into a given bitmap.
  1133. *
  1134. * raster_done ::
  1135. * The raster destructor.
  1136. */
  1137. typedef struct FT_Raster_Funcs_
  1138. {
  1139. FT_Glyph_Format glyph_format;
  1140. FT_Raster_NewFunc raster_new;
  1141. FT_Raster_ResetFunc raster_reset;
  1142. FT_Raster_SetModeFunc raster_set_mode;
  1143. FT_Raster_RenderFunc raster_render;
  1144. FT_Raster_DoneFunc raster_done;
  1145. } FT_Raster_Funcs;
  1146. /* */
  1147. FT_END_HEADER
  1148. #endif /* FTIMAGE_H_ */
  1149. /* END */
  1150. /* Local Variables: */
  1151. /* coding: utf-8 */
  1152. /* End: */