summaryrefslogtreecommitdiff log msg author committer range
blob: cb323d030c2479bc5093b206cf4c916d804a8542 (plain) (blame)
 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 ``` ``````#ifndef SW_FT_IMG_H #define SW_FT_IMG_H /***************************************************************************/ /* */ /* ftimage.h */ /* */ /* FreeType glyph image formats and default raster interface */ /* (specification). */ /* */ /* Copyright 1996-2010, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ /* modified, and distributed under the terms of the FreeType project */ /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ /* this file you indicate that you have read the license and */ /* understand and accept it fully. */ /* */ /***************************************************************************/ /*************************************************************************/ /* */ /* Note: A `raster' is simply a scan-line converter, used to render */ /* SW_FT_Outlines into SW_FT_Bitmaps. */ /* */ /*************************************************************************/ #include "sw_ft_types.h" /*************************************************************************/ /* */ /* */ /* FT_BBox */ /* */ /* */ /* A structure used to hold an outline's bounding box, i.e., the */ /* coordinates of its extrema in the horizontal and vertical */ /* directions. */ /* */ /* */ /* xMin :: The horizontal minimum (left-most). */ /* */ /* yMin :: The vertical minimum (bottom-most). */ /* */ /* xMax :: The horizontal maximum (right-most). */ /* */ /* yMax :: The vertical maximum (top-most). */ /* */ /* */ /* The bounding box is specified with the coordinates of the lower */ /* left and the upper right corner. In PostScript, those values are */ /* often called (llx,lly) and (urx,ury), respectively. */ /* */ /* If `yMin' is negative, this value gives the glyph's descender. */ /* Otherwise, the glyph doesn't descend below the baseline. */ /* Similarly, if `ymax' is positive, this value gives the glyph's */ /* ascender. */ /* */ /* `xMin' gives the horizontal distance from the glyph's origin to */ /* the left edge of the glyph's bounding box. If `xMin' is negative, */ /* the glyph extends to the left of the origin. */ /* */ typedef struct SW_FT_BBox_ { SW_FT_Pos xMin, yMin; SW_FT_Pos xMax, yMax; } SW_FT_BBox; /*************************************************************************/ /* */ /* */ /* SW_FT_Outline */ /* */ /* */ /* This structure is used to describe an outline to the scan-line */ /* converter. */ /* */ /* */ /* n_contours :: The number of contours in the outline. */ /* */ /* n_points :: The number of points in the outline. */ /* */ /* points :: A pointer to an array of `n_points' @SW_FT_Vector */ /* elements, giving the outline's point coordinates. */ /* */ /* tags :: A pointer to an array of `n_points' chars, giving */ /* each outline point's type. */ /* */ /* If bit~0 is unset, the point is `off' the curve, */ /* i.e., a Bézier control point, while it is `on' if */ /* set. */ /* */ /* Bit~1 is meaningful for `off' points only. If set, */ /* it indicates a third-order Bézier arc control point; */ /* and a second-order control point if unset. */ /* */ /* If bit~2 is set, bits 5-7 contain the drop-out mode */ /* (as defined in the OpenType specification; the value */ /* is the same as the argument to the SCANMODE */ /* instruction). */ /* */ /* Bits 3 and~4 are reserved for internal purposes. */ /* */ /* contours :: An array of `n_contours' shorts, giving the end */ /* point of each contour within the outline. For */ /* example, the first contour is defined by the points */ /* `0' to `contours[0]', the second one is defined by */ /* the points `contours[0]+1' to `contours[1]', etc. */ /* */ /* flags :: A set of bit flags used to characterize the outline */ /* and give hints to the scan-converter and hinter on */ /* how to convert/grid-fit it. See @SW_FT_OUTLINE_FLAGS.*/ /* */ typedef struct SW_FT_Outline_ { short n_contours; /* number of contours in glyph */ short n_points; /* number of points in the glyph */ SW_FT_Vector* points; /* the outline's points */ char* tags; /* the points flags */ short* contours; /* the contour end points */ int flags; /* outline masks */ } SW_FT_Outline; /*************************************************************************/ /* */ /* */ /* SW_FT_OUTLINE_FLAGS */ /* */ /* */ /* A list of bit-field constants use for the flags in an outline's */ /* `flags' field. */ /* */ /* */ /* SW_FT_OUTLINE_NONE :: */ /* Value~0 is reserved. */ /* */ /* SW_FT_OUTLINE_OWNER :: */ /* If set, this flag indicates that the outline's field arrays */ /* (i.e., `points', `flags', and `contours') are `owned' by the */ /* outline object, and should thus be freed when it is destroyed. */ /* */ /* SW_FT_OUTLINE_EVEN_ODD_FILL :: */ /* By default, outlines are filled using the non-zero winding rule. */ /* If set to 1, the outline will be filled using the even-odd fill */ /* rule (only works with the smooth rasterizer). */ /* */ /* SW_FT_OUTLINE_REVERSE_FILL :: */ /* By default, outside contours of an outline are oriented in */ /* clock-wise direction, as defined in the TrueType specification. */ /* This flag is set if the outline uses the opposite direction */ /* (typically for Type~1 fonts). This flag is ignored by the scan */ /* converter. */ /* */ /* */ /* */ /* There exists a second mechanism to pass the drop-out mode to the */ /* B/W rasterizer; see the `tags' field in @SW_FT_Outline. */ /* */ /* Please refer to the description of the `SCANTYPE' instruction in */ /* the OpenType specification (in file `ttinst1.doc') how simple */ /* drop-outs, smart drop-outs, and stubs are defined. */ /* */ #define SW_FT_OUTLINE_NONE 0x0 #define SW_FT_OUTLINE_OWNER 0x1 #define SW_FT_OUTLINE_EVEN_ODD_FILL 0x2 #define SW_FT_OUTLINE_REVERSE_FILL 0x4 /* */ #define SW_FT_CURVE_TAG( flag ) ( flag & 3 ) #define SW_FT_CURVE_TAG_ON 1 #define SW_FT_CURVE_TAG_CONIC 0 #define SW_FT_CURVE_TAG_CUBIC 2 #define SW_FT_Curve_Tag_On SW_FT_CURVE_TAG_ON #define SW_FT_Curve_Tag_Conic SW_FT_CURVE_TAG_CONIC #define SW_FT_Curve_Tag_Cubic SW_FT_CURVE_TAG_CUBIC /*************************************************************************/ /* */ /* A raster is a scan converter, in charge of rendering an outline into */ /* a a bitmap. This section contains the public API for rasters. */ /* */ /* Note that in FreeType 2, all rasters are now encapsulated within */ /* specific modules called `renderers'. See `ftrender.h' for more */ /* details on renderers. */ /* */ /*************************************************************************/ /*************************************************************************/ /* */ /* */ /* SW_FT_Raster */ /* */ /* */ /* A handle (pointer) to a raster object. Each object can be used */ /* independently to convert an outline into a bitmap or pixmap. */ /* */ typedef struct SW_FT_RasterRec_* SW_FT_Raster; /*************************************************************************/ /* */ /* */ /* SW_FT_Span */ /* */ /* */ /* A structure used to model a single span of gray (or black) pixels */ /* when rendering a monochrome or anti-aliased bitmap. */ /* */ /* */ /* x :: The span's horizontal start position. */ /* */ /* len :: The span's length in pixels. */ /* */ /* coverage :: The span color/coverage, ranging from 0 (background) */ /* to 255 (foreground). Only used for anti-aliased */ /* rendering. */ /* */ /* */ /* This structure is used by the span drawing callback type named */ /* @SW_FT_SpanFunc that takes the y~coordinate of the span as a */ /* parameter. */ /* */ /* The coverage value is always between 0 and 255. If you want less */ /* gray values, the callback function has to reduce them. */ /* */ typedef struct SW_FT_Span_ { short x; short y; unsigned short len; unsigned char coverage; } SW_FT_Span; /*************************************************************************/ /* */ /* */ /* SW_FT_SpanFunc */ /* */ /* */ /* A function used as a call-back by the anti-aliased renderer in */ /* order to let client applications draw themselves the gray pixel */ /* spans on each scan line. */ /* */ /* */ /* y :: The scanline's y~coordinate. */ /* */ /* count :: The number of spans to draw on this scanline. */ /* */ /* spans :: A table of `count' spans to draw on the scanline. */ /* */ /* user :: User-supplied data that is passed to the callback. */ /* */ /* */ /* This callback allows client applications to directly render the */ /* gray spans of the anti-aliased bitmap to any kind of surfaces. */ /* */ /* This can be used to write anti-aliased outlines directly to a */ /* given background bitmap, and even perform translucency. */ /* */ /* Note that the `count' field cannot be greater than a fixed value */ /* defined by the `SW_FT_MAX_GRAY_SPANS' configuration macro in */ /* `ftoption.h'. By default, this value is set to~32, which means */ /* that if there are more than 32~spans on a given scanline, the */ /* callback is called several times with the same `y' parameter in */ /* order to draw all callbacks. */ /* */ /* Otherwise, the callback is only called once per scan-line, and */ /* only for those scanlines that do have `gray' pixels on them. */ /* */ typedef void (*SW_FT_SpanFunc)( int count, const SW_FT_Span* spans, void* user ); #define SW_FT_Raster_Span_Func SW_FT_SpanFunc /*************************************************************************/ /* */ /* */ /* SW_FT_RASTER_FLAG_XXX */ /* */ /* */ /* A list of bit flag constants as used in the `flags' field of a */ /* @SW_FT_Raster_Params structure. */ /* */ /* */ /* SW_FT_RASTER_FLAG_DEFAULT :: This value is 0. */ /* */ /* SW_FT_RASTER_FLAG_AA :: This flag is set to indicate that an */ /* anti-aliased glyph image should be */ /* generated. Otherwise, it will be */ /* monochrome (1-bit). */ /* */ /* SW_FT_RASTER_FLAG_DIRECT :: This flag is set to indicate direct */ /* rendering. In this mode, client */ /* applications must provide their own span */ /* callback. This lets them directly */ /* draw or compose over an existing bitmap. */ /* If this bit is not set, the target */ /* pixmap's buffer _must_ be zeroed before */ /* rendering. */ /* */ /* Note that for now, direct rendering is */ /* only possible with anti-aliased glyphs. */ /* */ /* SW_FT_RASTER_FLAG_CLIP :: This flag is only used in direct */ /* rendering mode. If set, the output will */ /* be clipped to a box specified in the */ /* `clip_box' field of the */ /* @SW_FT_Raster_Params structure. */ /* */ /* Note that by default, the glyph bitmap */ /* is clipped to the target pixmap, except */ /* in direct rendering mode where all spans */ /* are generated if no clipping box is set. */ /* */ #define SW_FT_RASTER_FLAG_DEFAULT 0x0 #define SW_FT_RASTER_FLAG_AA 0x1 #define SW_FT_RASTER_FLAG_DIRECT 0x2 #define SW_FT_RASTER_FLAG_CLIP 0x4 /* deprecated */ #define ft_raster_flag_default SW_FT_RASTER_FLAG_DEFAULT #define ft_raster_flag_aa SW_FT_RASTER_FLAG_AA #define ft_raster_flag_direct SW_FT_RASTER_FLAG_DIRECT #define ft_raster_flag_clip SW_FT_RASTER_FLAG_CLIP /*************************************************************************/ /* */ /* */ /* SW_FT_Raster_Params */ /* */ /* */ /* A structure to hold the arguments used by a raster's render */ /* function. */ /* */ /* */ /* target :: The target bitmap. */ /* */ /* source :: A pointer to the source glyph image (e.g., an */ /* @SW_FT_Outline). */ /* */ /* flags :: The rendering flags. */ /* */ /* gray_spans :: The gray span drawing callback. */ /* */ /* black_spans :: The black span drawing callback. UNIMPLEMENTED! */ /* */ /* bit_test :: The bit test callback. UNIMPLEMENTED! */ /* */ /* bit_set :: The bit set callback. UNIMPLEMENTED! */ /* */ /* user :: User-supplied data that is passed to each drawing */ /* callback. */ /* */ /* clip_box :: An optional clipping box. It is only used in */ /* direct rendering mode. Note that coordinates here */ /* should be expressed in _integer_ pixels (and not in */ /* 26.6 fixed-point units). */ /* */ /* */ /* An anti-aliased glyph bitmap is drawn if the @SW_FT_RASTER_FLAG_AA */ /* bit flag is set in the `flags' field, otherwise a monochrome */ /* bitmap is generated. */ /* */ /* If the @SW_FT_RASTER_FLAG_DIRECT bit flag is set in `flags', the */ /* raster will call the `gray_spans' callback to draw gray pixel */ /* spans, in the case of an aa glyph bitmap, it will call */ /* `black_spans', and `bit_test' and `bit_set' in the case of a */ /* monochrome bitmap. This allows direct composition over a */ /* pre-existing bitmap through user-provided callbacks to perform the */ /* span drawing/composition. */ /* */ /* Note that the `bit_test' and `bit_set' callbacks are required when */ /* rendering a monochrome bitmap, as they are crucial to implement */ /* correct drop-out control as defined in the TrueType specification. */ /* */ typedef struct SW_FT_Raster_Params_ { const void* source; int flags; SW_FT_SpanFunc gray_spans; void* user; SW_FT_BBox clip_box; } SW_FT_Raster_Params; /*************************************************************************/ /* */ /* */ /* SW_FT_Outline_Check */ /* */ /* */ /* Check the contents of an outline descriptor. */ /* */ /* */ /* outline :: A handle to a source outline. */ /* */ /* */ /* FreeType error code. 0~means success. */ /* */ SW_FT_Error SW_FT_Outline_Check( SW_FT_Outline* outline ); /*************************************************************************/ /* */ /* */ /* SW_FT_Outline_Get_CBox */ /* */ /* */ /* Return an outline's `control box'. The control box encloses all */ /* the outline's points, including Bézier control points. Though it */ /* coincides with the exact bounding box for most glyphs, it can be */ /* slightly larger in some situations (like when rotating an outline */ /* that contains Bézier outside arcs). */ /* */ /* Computing the control box is very fast, while getting the bounding */ /* box can take much more time as it needs to walk over all segments */ /* and arcs in the outline. To get the latter, you can use the */ /* `ftbbox' component, which is dedicated to this single task. */ /* */ /* */ /* outline :: A pointer to the source outline descriptor. */ /* */ /* */ /* acbox :: The outline's control box. */ /* */ /* */ /* See @SW_FT_Glyph_Get_CBox for a discussion of tricky fonts. */ /* */ void SW_FT_Outline_Get_CBox( const SW_FT_Outline* outline, SW_FT_BBox *acbox ); /*************************************************************************/ /* */ /* */ /* SW_FT_Raster_NewFunc */ /* */ /* */ /* A function used to create a new raster object. */ /* */ /* */ /* memory :: A handle to the memory allocator. */ /* */ /* */ /* raster :: A handle to the new raster object. */ /* */ /* */ /* Error code. 0~means success. */ /* */ /* */ /* The `memory' parameter is a typeless pointer in order to avoid */ /* un-wanted dependencies on the rest of the FreeType code. In */ /* practice, it is an @SW_FT_Memory object, i.e., a handle to the */ /* standard FreeType memory allocator. However, this field can be */ /* completely ignored by a given raster implementation. */ /* */ typedef int (*SW_FT_Raster_NewFunc)( SW_FT_Raster* raster ); #define SW_FT_Raster_New_Func SW_FT_Raster_NewFunc /*************************************************************************/ /* */ /* */ /* SW_FT_Raster_DoneFunc */ /* */ /* */ /* A function used to destroy a given raster object. */ /* */ /* */ /* raster :: A handle to the raster object. */ /* */ typedef void (*SW_FT_Raster_DoneFunc)( SW_FT_Raster raster ); #define SW_FT_Raster_Done_Func SW_FT_Raster_DoneFunc /*************************************************************************/ /* */ /* */ /* SW_FT_Raster_ResetFunc */ /* */ /* */ /* FreeType provides an area of memory called the `render pool', */ /* available to all registered rasters. This pool can be freely used */ /* during a given scan-conversion but is shared by all rasters. Its */ /* content is thus transient. */ /* */ /* This function is called each time the render pool changes, or just */ /* after a new raster object is created. */ /* */ /* */ /* raster :: A handle to the new raster object. */ /* */ /* pool_base :: The address in memory of the render pool. */ /* */ /* pool_size :: The size in bytes of the render pool. */ /* */ /* */ /* Rasters can ignore the render pool and rely on dynamic memory */ /* allocation if they want to (a handle to the memory allocator is */ /* passed to the raster constructor). However, this is not */ /* recommended for efficiency purposes. */ /* */ typedef void (*SW_FT_Raster_ResetFunc)( SW_FT_Raster raster, unsigned char* pool_base, unsigned long pool_size ); #define SW_FT_Raster_Reset_Func SW_FT_Raster_ResetFunc /*************************************************************************/ /* */ /* */ /* SW_FT_Raster_RenderFunc */ /* */ /* */ /* Invoke a given raster to scan-convert a given glyph image into a */ /* target bitmap. */ /* */ /* */ /* raster :: A handle to the raster object. */ /* */ /* params :: A pointer to an @SW_FT_Raster_Params structure used to */ /* store the rendering parameters. */ /* */ /* */ /* Error code. 0~means success. */ /* */ /* */ /* The exact format of the source image depends on the raster's glyph */ /* format defined in its @SW_FT_Raster_Funcs structure. It can be an */ /* @SW_FT_Outline or anything else in order to support a large array of */ /* glyph formats. */ /* */ /* Note also that the render function can fail and return a */ /* `SW_FT_Err_Unimplemented_Feature' error code if the raster used does */ /* not support direct composition. */ /* */ /* XXX: For now, the standard raster doesn't support direct */ /* composition but this should change for the final release (see */ /* the files `demos/src/ftgrays.c' and `demos/src/ftgrays2.c' */ /* for examples of distinct implementations that support direct */ /* composition). */ /* */ typedef int (*SW_FT_Raster_RenderFunc)( SW_FT_Raster raster, const SW_FT_Raster_Params* params ); #define SW_FT_Raster_Render_Func SW_FT_Raster_RenderFunc /*************************************************************************/ /* */ /* */ /* SW_FT_Raster_Funcs */ /* */ /* */ /* A structure used to describe a given raster class to the library. */ /* */ /* */ /* glyph_format :: The supported glyph format for this raster. */ /* */ /* raster_new :: The raster constructor. */ /* */ /* raster_reset :: Used to reset the render pool within the raster. */ /* */ /* raster_render :: A function to render a glyph into a given bitmap. */ /* */ /* raster_done :: The raster destructor. */ /* */ typedef struct SW_FT_Raster_Funcs_ { SW_FT_Raster_NewFunc raster_new; SW_FT_Raster_ResetFunc raster_reset; SW_FT_Raster_RenderFunc raster_render; SW_FT_Raster_DoneFunc raster_done; } SW_FT_Raster_Funcs; extern const SW_FT_Raster_Funcs sw_ft_grays_raster; #endif // SW_FT_IMG_H ``````