1 /* Copyright (C) 2003 Aladdin Enterprises. All rights reserved. 2 3 This software is provided AS-IS with no warranty, either express or 4 implied. 5 6 This software is distributed under license and may not be copied, 7 modified or distributed except as expressly authorized under the terms 8 of the license contained in the file LICENSE in this distribution. 9 10 For more information about licensing, please refer to 11 http://www.ghostscript.com/licensing/. For information on 12 commercial licensing, go to http://www.artifex.com/licensing/ or 13 contact Artifex Software, Inc., 101 Lucas Valley Road #110, 14 San Rafael, CA 94903, U.S.A., +1(415)492-9861. 15 */ 16 17 /* $Id: tttype.h,v 1.3 2005/05/31 13:05:20 igor Exp $ */ 18 19 /* Changes after FreeType: cut out the TrueType instruction interpreter. */ 20 21 22 /******************************************************************* 23 * 24 * tttype.h 25 * 26 * High-level interface specification. 27 * 28 * Copyright 1996-1998 by 29 * David Turner, Robert Wilhelm, and Werner Lemberg. 30 * 31 * This file is part of the FreeType project and may only be used, 32 * modified, and distributed under the terms of the FreeType project 33 * license, LICENSE.TXT. By continuing to use, modify, or distribute 34 * this file you indicate that you have read the license and 35 * understand and accept it fully. 36 * 37 * Notes: 38 * 39 * This is the only file that should be included by client 40 * application sources for the final release. All other types 41 * and functions defined in the "tt*.h" files are library 42 * internals, and should not be included (except of course 43 * during development, as now). 44 * 45 * FreeType is still in beta! 46 * 47 ******************************************************************/ 48 49 #ifndef FREETYPE_H 50 #define FREETYPE_H 51 52 #ifdef __cplusplus 53 extern "C" { 54 #endif 55 56 57 /*******************************************************************/ 58 /* */ 59 /* FreeType types definitions. */ 60 /* */ 61 /* All these begin with a 'TT_' prefix. */ 62 /* */ 63 /*******************************************************************/ 64 65 #if ARCH_LOG2_SIZEOF_LONG == 2 66 typedef signed long TT_Fixed; /* Signed Fixed 16.16 Float */ 67 #elif ARCH_LOG2_SIZEOF_INT == 2 68 typedef signed int TT_Fixed; /* Signed Fixed 16.16 Float */ 69 #else 70 #error "No appropriate type for Fixed 16.16 Floats" 71 #endif 72 73 typedef signed short TT_FWord; /* Distance in FUnits */ 74 typedef unsigned short TT_UFWord; /* Unsigned distance */ 75 76 typedef signed short TT_Short; 77 typedef unsigned short TT_UShort; 78 typedef signed long TT_Long; 79 typedef unsigned long TT_ULong; 80 81 typedef signed short TT_F2Dot14; /* Signed fixed float 2.14 used for */ 82 /* unary vectors, with layout: */ 83 /* */ 84 /* s : 1 -- sign bit */ 85 /* m : 1 -- mantissa bit */ 86 /* f : 14 -- unsigned fractional */ 87 /* */ 88 /* 's:m' is the 2-bit signed int */ 89 /* value to which the positive */ 90 /* fractional part should be */ 91 /* added. */ 92 /* */ 93 94 #if ARCH_LOG2_SIZEOF_LONG == 2 95 typedef signed long TT_F26Dot6; /* 26.6 fixed float, used for */ 96 #elif ARCH_LOG2_SIZEOF_INT == 2 97 typedef signed int TT_F26Dot6; /* 26.6 fixed float, used for */ 98 /* glyph points pixel coordinates. */ 99 #else 100 #error "No appropriate type for Fixed 26.6 Floats" 101 #endif 102 103 #if ARCH_LOG2_SIZEOF_LONG == 2 104 typedef signed long TT_Pos; /* point position, expressed either */ 105 #elif ARCH_LOG2_SIZEOF_INT == 2 106 typedef signed int TT_Pos; /* point position, expressed either */ 107 /* in fractional pixels or notional */ 108 /* units, depending on context. For */ 109 /* example, glyph coordinates */ 110 /* returned by TT_Load_Glyph are */ 111 /* expressed in font units when */ 112 /* scaling wasn't requested, and */ 113 /* in 26.6 fractional pixels if it */ 114 /* was */ 115 /* */ 116 #else 117 #error "No appropriate type for point position" 118 #endif 119 120 struct _TT_UnitVector /* guess what... */ 121 { 122 TT_F2Dot14 x; 123 TT_F2Dot14 y; 124 }; 125 126 typedef struct _TT_UnitVector TT_UnitVector; 127 128 129 struct _TT_Vector /* Simple vector type */ 130 { 131 TT_F26Dot6 x; 132 TT_F26Dot6 y; 133 }; 134 135 typedef struct _TT_Vector TT_Vector; 136 137 138 /* A simple 2x2 matrix used for transformations. */ 139 /* You should use 16.16 fixed floats */ 140 /* */ 141 /* x' = xx*x + xy*y */ 142 /* y' = yx*x + yy*y */ 143 /* */ 144 145 struct _TT_Matrix 146 { 147 TT_Fixed xx, xy; 148 TT_Fixed yx, yy; 149 }; 150 151 typedef struct _TT_Matrix TT_Matrix; 152 153 154 /* A structure used to describe the source glyph to the renderer. */ 155 156 struct _TT_Outline 157 { 158 unsigned int contours; /* number of contours in glyph */ 159 unsigned int points; /* number of points in the glyph */ 160 161 unsigned short* conEnds; /* points to an array of each contour's */ 162 /* start point index */ 163 TT_Pos* xCoord; /* table of x coordinates */ 164 TT_Pos* yCoord; /* table of y coordinates */ 165 unsigned char* flag; /* table of flags */ 166 167 /* the following flag indicates that the outline owns the arrays it */ 168 /* refers to. Typically, this is true of outlines created from the */ 169 /* "TT_New_Outline" API, while it isn't for those returned by */ 170 /* "TT_Get_Glyph_Outline" */ 171 172 int owner; /* the outline owns the coordinates, */ 173 /* flags and contours array it uses */ 174 175 /* the following flags are set automatically by TT_Get_Glyph_Outline */ 176 /* their meaning is the following : */ 177 /* */ 178 /* high_precision when true, the scan-line converter will use */ 179 /* a higher precision to render bitmaps (i.e. a */ 180 /* 1/1024 pixel precision). This is important for */ 181 /* small ppem sizes. */ 182 /* */ 183 /* second_pass when true, the scan-line converter performs */ 184 /* a second sweep phase dedicated to find */ 185 /* vertical drop-outs. If false, only horizontal */ 186 /* drop-outs will be checked during the first */ 187 /* vertical sweep (yes, this is a bit confusing */ 188 /* but it's really the way it should work). */ 189 /* This is important for small ppems too. */ 190 /* */ 191 /* dropout_mode specifies the TrueType drop-out mode to */ 192 /* use for continuity checking. valid values */ 193 /* are 0 (no check), 1, 2, 4 and 5 */ 194 /* */ 195 /* Most of the engine's users will safely ignore these fields.. */ 196 /* */ 197 198 int high_precision; /* high precision rendering */ 199 int second_pass; /* two sweeps rendering */ 200 char dropout_mode; /* dropout mode */ 201 }; 202 203 typedef struct _TT_Outline TT_Outline; 204 205 206 /* A structure used to describe a simple bounding box */ 207 208 struct _TT_BBox 209 { 210 TT_Pos xMin; 211 TT_Pos yMin; 212 TT_Pos xMax; 213 TT_Pos yMax; 214 }; 215 216 typedef struct _TT_BBox TT_BBox; 217 218 /* A structure used to return glyph metrics. */ 219 220 /* The "bearingX" isn't called "left-side bearing" anymore because */ 221 /* it has different meanings depending on the glyph's orientation */ 222 /* */ 223 /* The same goes true for "bearingY", which is the top-side bearing */ 224 /* defined by the TT_Spec, i.e. the distance from the baseline to the */ 225 /* top of the glyph's bbox. According to our current convention, this */ 226 /* is always the same as "bbox.yMax" but we make it appear for */ 227 /* consistency in its proper field. */ 228 /* */ 229 /* the "advance" width is the advance width for horizontal layout, */ 230 /* and advance height for vertical layouts. */ 231 /* */ 232 /* Finally, the library (1.0) doesn't support vertical text yet */ 233 /* but these changes were introduced to accomodate it, as it will */ 234 /* most certainly be introduced in later releases. */ 235 /* */ 236 237 struct _TT_Glyph_Metrics 238 { 239 TT_BBox bbox; /* glyph bounding box */ 240 241 TT_Pos bearingX; /* left-side bearing */ 242 TT_Pos bearingY; /* top-side bearing, per se the TT spec */ 243 244 TT_Pos advance; /* advance width (or height) */ 245 }; 246 247 /* A structure used to return horizontal _and_ vertical glyph metrics */ 248 /* */ 249 /* A same glyph can be used either in a horizontal or vertical layout */ 250 /* Its glyph metrics vary with orientation. The Big_Glyph_Metrics */ 251 /* is used to return _all_ metrics in one call. */ 252 /* */ 253 /* This structure is currently unused.. */ 254 /* */ 255 256 struct _TT_Big_Glyph_Metrics 257 { 258 TT_BBox bbox; /* glyph bounding box */ 259 260 TT_Pos horiBearingX; /* left side bearing in horizontal layouts */ 261 TT_Pos horiBearingY; /* top side bearing in horizontal layouts */ 262 263 TT_Pos vertBearingX; /* left side bearing in vertical layouts */ 264 TT_Pos vertBearingY; /* top side bearing in vertical layouts */ 265 266 TT_Pos horiAdvance; /* advance width for horizontal layout */ 267 TT_Pos vertAdvance; /* advance height for vertical layout */ 268 }; 269 270 typedef struct _TT_Glyph_Metrics TT_Glyph_Metrics; 271 typedef struct _TT_Big_Glyph_Metrics TT_Big_Glyph_Metrics; 272 273 274 /* A structure used to return instance metrics. */ 275 276 struct _TT_Instance_Metrics 277 { 278 int pointSize; /* char. size in points (1pt = 1/72 inch) */ 279 280 int x_ppem; /* horizontal pixels per EM square */ 281 int y_ppem; /* vertical pixels per EM square */ 282 283 TT_Fixed x_scale; /* 16.16 to convert from EM units to 26.6 pix */ 284 TT_Fixed y_scale; /* 16.16 to convert from EM units to 26.6 pix */ 285 286 int x_resolution; /* device horizontal resolution in dpi */ 287 int y_resolution; /* device vertical resolution in dpi */ 288 }; 289 290 typedef struct _TT_Instance_Metrics TT_Instance_Metrics; 291 292 293 /* Flow constants: */ 294 /* */ 295 /* The flow of a bitmap refers to the way lines are oriented */ 296 /* within the bitmap data, i.e., the orientation of the Y */ 297 /* coordinate axis. */ 298 299 /* for example, if the first bytes of the bitmap pertain to */ 300 /* its top-most line, then the flow is 'down'. If these bytes */ 301 /* pertain to its lowest line, the the flow is 'up'. */ 302 303 #define TT_Flow_Down -1 /* bitmap is oriented from top to bottom */ 304 #define TT_Flow_Up 1 /* bitmap is oriented from bottom to top */ 305 #define TT_Flow_Error 0 /* an error occurred during rendering */ 306 307 308 /* A structure used to describe the target bitmap or pixmap to the */ 309 /* renderer. Note that there is nothing in this structure that */ 310 /* gives the nature of the buffer. */ 311 312 /* IMPORTANT NOTE: */ 313 /* */ 314 /* A pixmap's width _must_ be a multiple of 4. Clipping */ 315 /* problems will arise otherwise, if not page faults! */ 316 /* */ 317 /* The typical settings are: */ 318 /* */ 319 /* - for an WxH bitmap: */ 320 /* */ 321 /* rows = H */ 322 /* cols = (W+7)/8 */ 323 /* width = W */ 324 /* flow = your_choice */ 325 /* */ 326 /* - for an WxH pixmap: */ 327 /* */ 328 /* rows = H */ 329 /* cols = (W+3) & ~3 */ 330 /* width = cols */ 331 /* flow = your_choice */ 332 333 struct _TT_Raster_Map 334 { 335 int rows; /* number of rows */ 336 int cols; /* number of columns (bytes) per row */ 337 int width; /* number of pixels per line */ 338 int flow; /* bitmap orientation */ 339 340 void* bitmap; /* bit/pixmap buffer */ 341 long size; /* bit/pixmap size in bytes */ 342 }; 343 344 typedef struct _TT_Raster_Map TT_Raster_Map; 345 346 347 348 /* ------- The font header TrueType table structure ----- */ 349 350 struct _TT_Header 351 { 352 TT_Fixed Table_Version; 353 TT_Fixed Font_Revision; 354 355 TT_Long CheckSum_Adjust; 356 TT_Long Magic_Number; 357 358 TT_UShort Flags; 359 TT_UShort Units_Per_EM; 360 361 TT_Long Created [2]; 362 TT_Long Modified[2]; 363 364 TT_FWord xMin; 365 TT_FWord yMin; 366 TT_FWord xMax; 367 TT_FWord yMax; 368 369 TT_UShort Mac_Style; 370 TT_UShort Lowest_Rec_PPEM; 371 372 TT_Short Font_Direction; 373 TT_Short Index_To_Loc_Format; 374 TT_Short Glyph_Data_Format; 375 }; 376 377 typedef struct _TT_Header TT_Header; 378 379 380 /* ------- The horizontal header TrueType table structure ----- */ 381 382 struct _TT_Horizontal_Header 383 { 384 TT_Fixed Version; 385 TT_FWord Ascender; 386 TT_FWord Descender; 387 TT_FWord Line_Gap; 388 389 TT_UFWord advance_Width_Max; 390 391 TT_FWord min_Left_Side_Bearing; 392 TT_FWord min_Right_Side_Bearing; 393 TT_FWord xMax_Extent; 394 TT_FWord caret_Slope_Rise; 395 TT_FWord caret_Slope_Run; 396 397 TT_Short Reserved[5]; 398 399 TT_Short metric_Data_Format; 400 TT_UShort number_Of_HMetrics; 401 }; 402 403 typedef struct _TT_Horizontal_Header TT_Horizontal_Header; 404 405 406 /* ----------- OS/2 Table ----------------------------- */ 407 408 struct _TT_OS2 409 { 410 TT_UShort version; /* 0x0001 */ 411 TT_FWord xAvgCharWidth; 412 TT_UShort usWeightClass; 413 TT_UShort usWidthClass; 414 TT_Short fsType; 415 TT_FWord ySubscriptXSize; 416 TT_FWord ySubscriptYSize; 417 TT_FWord ySubscriptXOffset; 418 TT_FWord ySubscriptYOffset; 419 TT_FWord ySuperscriptXSize; 420 TT_FWord ySuperscriptYSize; 421 TT_FWord ySuperscriptXOffset; 422 TT_FWord ySuperscriptYOffset; 423 TT_FWord yStrikeoutSize; 424 TT_FWord yStrikeoutPosition; 425 TT_Short sFamilyClass; 426 427 char panose[10]; 428 429 TT_ULong ulUnicodeRange1; /* Bits 0-31 */ 430 TT_ULong ulUnicodeRange2; /* Bits 32-63 */ 431 TT_ULong ulUnicodeRange3; /* Bits 64-95 */ 432 TT_ULong ulUnicodeRange4; /* Bits 96-127 */ 433 434 char achVendID[4]; 435 436 TT_UShort fsSelection; 437 TT_UShort usFirstCharIndex; 438 TT_UShort usLastCharIndex; 439 TT_UShort sTypoAscender; 440 TT_UShort sTypoDescender; 441 TT_UShort sTypoLineGap; 442 TT_UShort usWinAscent; 443 TT_UShort usWinDescent; 444 445 /* only version 1 tables: */ 446 447 TT_ULong ulCodePageRange1; /* Bits 0-31 */ 448 TT_ULong ulCodePageRange2; /* Bits 32-63 */ 449 }; 450 451 typedef struct _TT_OS2 TT_OS2; 452 453 454 /* ----------- Postscript table ------------------------ */ 455 456 struct _TT_Postscript 457 { 458 TT_Fixed FormatType; 459 TT_Fixed italicAngle; 460 TT_FWord underlinePosition; 461 TT_FWord underlineThickness; 462 TT_ULong isFixedPitch; 463 TT_ULong minMemType42; 464 TT_ULong maxMemType42; 465 TT_ULong minMemType1; 466 TT_ULong maxMemType1; 467 468 /* glyph names follow in the file, but we don't */ 469 /* load them by default. */ 470 }; 471 472 typedef struct _TT_Postscript TT_Postscript; 473 474 475 /* ------------ horizontal device metrics "hdmx" ---------- */ 476 477 struct _TT_Hdmx_Record 478 { 479 unsigned char ppem; 480 unsigned char max_width; 481 unsigned char* widths; 482 }; 483 484 typedef struct _TT_Hdmx_Record TT_Hdmx_Record; 485 486 487 struct _TT_Hdmx 488 { 489 TT_UShort version; 490 TT_Short num_records; 491 TT_Hdmx_Record* records; 492 }; 493 494 typedef struct _TT_Hdmx TT_Hdmx; 495 496 497 /* A structure used to describe face properties. */ 498 499 struct _TT_Face_Properties 500 { 501 int num_Glyphs; /* number of glyphs in face */ 502 int max_Points; /* maximum number of points in a glyph */ 503 int max_Contours; /* maximum number of contours in a glyph */ 504 505 int num_Faces; /* 0 for normal TrueType files, and the */ 506 /* number of embedded faces minus 1 for */ 507 /* TrueType collections */ 508 509 TT_Header* header; /* TrueType header table */ 510 TT_Horizontal_Header* horizontal; /* TrueType horizontal header */ 511 TT_OS2* os2; /* TrueType OS/2 table */ 512 TT_Postscript* postscript; /* TrueType Postscript table */ 513 TT_Hdmx* hdmx; 514 }; 515 516 typedef struct _TT_Face_Properties TT_Face_Properties; 517 518 /* Here are the definitions of the handle types used for FreeType's */ 519 /* most common objects accessed by the client application. We use */ 520 /* a simple trick there: */ 521 /* */ 522 /* Each handle type is a structure that only contains one */ 523 /* pointer. The advantage of structures is that there are */ 524 /* mutually exclusive types. We could have defined the */ 525 /* following types: */ 526 /* */ 527 /* typedef void* TT_Stream; */ 528 /* typedef void* TT_Face; */ 529 /* typedef void* TT_Instance; */ 530 /* typedef void* TT_Glyph; */ 531 /* typedef void* TT_CharMap; */ 532 /* */ 533 /* but these would have allowed lines like: */ 534 /* */ 535 /* stream = instance; */ 536 /* */ 537 /* in the client code this would be a severe bug, unnoticed */ 538 /* by the compiler! */ 539 /* */ 540 /* Thus, we enforce type checking with a simple language */ 541 /* trick... */ 542 /* */ 543 /* NOTE: Some macros are defined in tttypes.h to perform */ 544 /* automatic type conversions for library hackers... */ 545 /* */ 546 547 struct _TT_Engine { void* z; }; 548 struct _TT_Stream { void* z; }; 549 struct _TT_Face { void* z; }; 550 struct _TT_Instance { void* z; }; 551 struct _TT_Glyph { void* z; }; 552 struct _TT_CharMap { void* z; }; 553 554 typedef struct _TT_Engine TT_Engine; /* engine instance */ 555 typedef struct _TT_Stream TT_Stream; /* stream handle type */ 556 typedef struct _TT_Face TT_Face; /* face handle type */ 557 typedef struct _TT_Instance TT_Instance; /* instance handle type */ 558 typedef struct _TT_Glyph TT_Glyph; /* glyph handle type */ 559 typedef struct _TT_CharMap TT_CharMap; /* character map handle type */ 560 561 typedef int TT_Error; 562 563 extern const TT_Instance TT_Null_Instance; 564 565 /*******************************************************************/ 566 /* */ 567 /* FreeType API */ 568 /* */ 569 /* All these begin with a 'TT_' prefix. */ 570 /* */ 571 /* Most of them are implemented in the 'ttapi.c' source file. */ 572 /* */ 573 /*******************************************************************/ 574 575 /* Initialize the engine. */ 576 577 TT_Error TT_Init_FreeType( TT_Engine* engine ); 578 579 580 /* Finalize the engine, and release all allocated objects. */ 581 TT_Error TT_Done_FreeType( TT_Engine engine ); 582 583 584 /* Set the gray level palette. This is an array of 5 bytes used */ 585 /* to produce the font smoothed pixmaps. By convention: */ 586 /* */ 587 /* palette[0] = background (white) */ 588 /* palette[1] = light */ 589 /* palette[2] = medium */ 590 /* palette[3] = dark */ 591 /* palette[4] = foreground (black) */ 592 /* */ 593 594 TT_Error TT_Set_Raster_Gray_Palette( TT_Engine engine, char* palette ); 595 596 /* ----------------------- face management ----------------------- */ 597 598 /* Open a new TrueType font file, and returns a handle for */ 599 /* it in variable '*face'. */ 600 601 /* Note: the file can be either a TrueType file (*.ttf) or */ 602 /* a TrueType collection (*.ttc), in this case, only */ 603 /* the first face is opened. The number of faces in */ 604 /* the same collection can be obtained in the face's */ 605 /* properties, through TT_Get_Face_Properties and the */ 606 /* 'max_Faces' field. */ 607 608 TT_Error TT_Open_Face( TT_Engine engine, 609 const char* fontpathname, 610 TT_Face* face ); 611 612 613 /* Open a TrueType font file located inside a collection. */ 614 /* The font is designed by its index in 'fontIndex'. */ 615 616 TT_Error TT_Open_Collection( TT_Engine engine, 617 const char* collectionpathname, 618 int fontIndex, 619 TT_Face* face ); 620 621 622 /* Return face properties in the 'properties' structure. */ 623 624 TT_Error TT_Get_Face_Properties( TT_Face face, 625 TT_Face_Properties* properties ); 626 627 628 /* Set a face object's generic pointer */ 629 TT_Error TT_Set_Face_Pointer( TT_Face face, 630 void* data ); 631 632 /* Get a face object's geneeric pointer */ 633 void* TT_Get_Face_Pointer( TT_Face face ); 634 635 /* Close a face's file handle to save system resources. The file */ 636 /* will be re-opened automatically on the next disk access */ 637 TT_Error TT_Flush_Face( TT_Face face ); 638 639 /* Close a given font object, destroying all associated */ 640 /* instances. */ 641 642 TT_Error TT_Close_Face( TT_Face face ); 643 644 /* Get Font or Table Data */ 645 646 TT_Error TT_Get_Font_Data( TT_Face face, 647 long tag, 648 long offset, 649 void* buffer, 650 long* length ); 651 652 /* A simply macro to build table tags from ascii chars */ 653 # define MAKE_TT_TAG( _x1, _x2, _x3, _x4 ) \ 654 (_x1 << 24 | _x2 << 16 | _x3 << 8 | _x4) 655 656 /* ----------------------- instance management -------------------- */ 657 658 /* Open a new font instance and returns an instance handle */ 659 /* for it in '*instance'. */ 660 661 TT_Error TT_New_Instance( TT_Face face, 662 TT_Instance* instance ); 663 664 665 /* Set device resolution for a given instance. The values are */ 666 /* given in dpi (Dots Per Inch). Default is 96 in both directions. */ 667 668 /* NOTE: y_resolution is currently ignored, and the library */ 669 /* assumes square pixels. */ 670 671 TT_Error TT_Set_Instance_Resolutions( TT_Instance instance, 672 int x_resolution, 673 int y_resolution ); 674 675 676 /* Set the pointsize for a given instance. Default is 10pt. */ 677 678 TT_Error TT_Set_Instance_CharSize( TT_Instance instance, 679 TT_F26Dot6 charSize ); 680 681 TT_Error TT_Set_Instance_CharSizes( TT_Instance instance, 682 TT_F26Dot6 charWidth, 683 TT_F26Dot6 charHeight ); 684 685 #define TT_Set_Instance_PointSize( ins, ptsize ) \ 686 TT_Set_Instance_CharSize( ins, ptsize*64 ) 687 688 TT_Error TT_Set_Instance_PixelSizes( TT_Instance instance, 689 int pixelWidth, 690 int pixelHeight, 691 TT_F26Dot6 pointSize ); 692 693 /* We do not provide direct support for rotation or stretching */ 694 /* in the glyph loader. This means that you must perform these */ 695 /* operations yourself through TT_Transform_Outline before */ 696 /* calling TT_Get_Glyph_Bitmap. However, the loader needs to */ 697 /* know what kind of text you're displaying. The following */ 698 /* boolean flags inform the interpreter that: */ 699 /* */ 700 /* rotated : the glyphs will be rotated */ 701 /* stretched: the glyphs will be stretched */ 702 /* */ 703 /* These setting only affect the hinting process! */ 704 /* */ 705 /* NOTE: 'stretched' means any transform that distorts the */ 706 /* glyph (including skewing and 'linear stretching') */ 707 /* */ 708 709 TT_Error TT_Set_Instance_Transform_Flags( TT_Instance instance, 710 int rotated, 711 int stretched ); 712 713 /* Return instance metrics in 'metrics'. */ 714 715 TT_Error TT_Get_Instance_Metrics( TT_Instance instance, 716 TT_Instance_Metrics* metrics ); 717 718 719 /* Set an instance's generic pointer */ 720 721 TT_Error TT_Set_Instance_Pointer( TT_Instance instance, 722 void* data ); 723 724 /* Get an instance's generic pointer */ 725 726 void* TT_Get_Instance_Pointer( TT_Instance instance ); 727 728 729 /* Close a given instance object, destroying all associated */ 730 /* data. */ 731 732 TT_Error TT_Done_Instance( TT_Instance instance ); 733 734 735 /* ----------------------- glyph management ----------------------- */ 736 737 /* Create a new glyph object related to the given 'face'. */ 738 739 TT_Error TT_New_Glyph( TT_Face face, 740 TT_Glyph* glyph ); 741 742 743 /* Discard (and destroy) a given glyph object. */ 744 745 TT_Error TT_Done_Glyph( TT_Glyph glyph ); 746 747 748 #define TTLOAD_SCALE_GLYPH 1 749 #define TTLOAD_HINT_GLYPH 2 750 751 #define TTLOAD_DEFAULT (TTLOAD_SCALE_GLYPH | TTLOAD_HINT_GLYPH) 752 753 /* load and process (scale/transform and hint) a glyph from the */ 754 /* given 'instance'. The glyph and instance handles must be */ 755 /* related to the same face object. The glyph index can be */ 756 /* computed with a call to TT_Char_Index(). */ 757 758 /* the 'load_flags' argument is a combination of the macros */ 759 /* TTLOAD_SCALE_GLYPH and TTLOAD_HINT_GLYPH. Hinting will be */ 760 /* applied only if the scaling is selected. */ 761 762 /* When scaling is off (i.e. load_flags = 0), the returned */ 763 /* outlines are in EM square coordinates (also called FUnits), */ 764 /* extracted directly from the font with no hinting. */ 765 /* Other glyph metrics are also in FUnits. */ 766 767 /* When scaling is on, the returned outlines are in fractional */ 768 /* pixel units (i.e. TT_F26Dot6 = 26.6 fixed floats). */ 769 770 /* NOTE: the glyph index must be in the range 0..num_glyphs-1 */ 771 /* where 'num_glyphs' is the total number of glyphs in */ 772 /* the font file (given in the face properties). */ 773 774 TT_Error TT_Load_Glyph( TT_Instance instance, 775 TT_Glyph glyph, 776 int glyph_index, 777 int load_flags ); 778 779 780 /* Return glyph outline pointers in 'outline'. Note that the returned */ 781 /* pointers are owned by the glyph object, and will be destroyed with */ 782 /* it. The client application should _not_ change the pointers. */ 783 784 TT_Error TT_Get_Glyph_Outline( TT_Glyph glyph, 785 TT_Outline* outline ); 786 787 /* Copy the glyph metrics into 'metrics'. */ 788 789 TT_Error TT_Get_Glyph_Metrics( TT_Glyph glyph, 790 TT_Glyph_Metrics* metrics ); 791 792 793 /* Render the glyph into a bitmap, with given position offsets. */ 794 795 /* Note : Only use integer pixel offsets to preserve the fine */ 796 /* hinting of the glyph and the 'correct' anti-aliasing */ 797 /* (where vertical and horizontal stems aren't grayed). */ 798 /* This means that x_offset and y_offset must be multiples */ 799 /* of 64! */ 800 /* */ 801 802 TT_Error TT_Get_Glyph_Bitmap( TT_Glyph glyph, 803 TT_Raster_Map* raster_map, 804 TT_F26Dot6 x_offset, 805 TT_F26Dot6 y_offset ); 806 807 808 /* Render the glyph into a pixmap, with given position offsets. */ 809 810 /* Note : Only use integer pixel offsets to preserve the fine */ 811 /* hinting of the glyph and the 'correct' anti-aliasing */ 812 /* (where vertical and horizontal stems aren't grayed). */ 813 /* This means that x_offset and y_offset must be multiples */ 814 /* of 64! */ 815 /* */ 816 817 TT_Error TT_Get_Glyph_Pixmap( TT_Glyph glyph, 818 TT_Raster_Map* raster_map, 819 TT_F26Dot6 x_offset, 820 TT_F26Dot6 y_offset ); 821 822 /* ----------------------- outline support ------------------------ */ 823 824 /* Allocate a new outline. Reserve space for 'num_points' and */ 825 /* 'num_contours' */ 826 827 TT_Error TT_New_Outline( int num_points, 828 int num_contours, 829 TT_Outline* outline ); 830 831 /* Release an outline */ 832 833 TT_Error TT_Done_Outline( TT_Outline* outline ); 834 835 /* Copy an outline into another one */ 836 837 TT_Error TT_Copy_Outline( TT_Outline* source, 838 TT_Outline* target ); 839 840 /* Render an outline into a bitmap */ 841 842 TT_Error TT_Get_Outline_Bitmap( TT_Engine engine, 843 TT_Outline* outline, 844 TT_Raster_Map* raster_map ); 845 846 /* Render an outline into a pixmap - note that this function uses */ 847 /* a different pixel scale, where 1.0 pixels = 128 XXXX */ 848 849 TT_Error TT_Get_Outline_Pixmap( TT_Engine engine, 850 TT_Outline* outline, 851 TT_Raster_Map* raster_map ); 852 853 /* return an outline's bounding box - this function is slow as it */ 854 /* performs a complete scan-line process, without drawing, to get */ 855 /* the most accurate values XXXX */ 856 857 TT_Error TT_Get_Outline_BBox( TT_Outline* outline, 858 TT_BBox* bbox ); 859 860 /* Apply a transformation to a glyph outline */ 861 862 void TT_Transform_Outline( TT_Outline* outline, 863 TT_Matrix* matrix ); 864 865 /* backwards compatibility macro */ 866 # define TT_Appy_Outline_Matrix TT_Transform_Matrix; 867 868 /* Apply a translation to a glyph outline */ 869 870 void TT_Translate_Outline( TT_Outline* outline, 871 TT_F26Dot6 x_offset, 872 TT_F26Dot6 y_offset ); 873 874 /* backwards compatibility */ 875 # define TT_Apply_Outline_Translation TT_Translate_Outline 876 877 /* Apply a transformation to a vector */ 878 879 void TT_Transform_Vector( TT_F26Dot6* x, 880 TT_F26Dot6* y, 881 TT_Matrix* matrix ); 882 /* backwards compatibility */ 883 # define TT_Apply_Vector_Matrix( x, y, m ) \ 884 TT_Transform_Vector( x, y, m ) 885 886 /* Multiply a matrix with another - computes "b := a*b" */ 887 888 void TT_Matrix_Multiply( TT_Matrix* a, 889 TT_Matrix* b ); 890 891 /* Invert a transformation matrix */ 892 893 TT_Error TT_Matrix_Invert( TT_Matrix* matrix ); 894 895 896 897 /* ----------------- character mappings support ------------- */ 898 899 /* Return the number of character mappings found in this file. */ 900 /* Returns -1 in case of failure (invalid face handle). */ 901 902 int TT_Get_CharMap_Count( TT_Face face ); 903 904 905 /* Return the ID of charmap number 'charmapIndex' of a given face */ 906 /* used to enumerate the charmaps present in a TrueType file. */ 907 908 TT_Error TT_Get_CharMap_ID( TT_Face face, 909 int charmapIndex, 910 short* platformID, 911 short* encodingID ); 912 913 914 /* Look up the character maps found in 'face' and return a handle */ 915 /* for the one matching 'platformID' and 'platformEncodingID' */ 916 /* (see the TrueType specs relating to the 'cmap' table for */ 917 /* information on these ID numbers). Returns an error code. */ 918 /* In case of failure, the handle is set to NULL and is invalid. */ 919 920 TT_Error TT_Get_CharMap( TT_Face face, 921 int charmapIndex, 922 TT_CharMap* charMap ); 923 924 925 /* Translate a character code through a given character map */ 926 /* and return the corresponding glyph index to be used in */ 927 /* a TT_Load_Glyph call. This function returns -1 in case of */ 928 /* failure. */ 929 930 int TT_Char_Index( TT_CharMap charMap, 931 unsigned short charCode ); 932 933 934 935 /* --------------------- names table support ------------------- */ 936 937 /* Return the number of name strings found in the name table. */ 938 /* Returns -1 in case of failure (invalid face handle). */ 939 940 int TT_Get_Name_Count( TT_Face face ); 941 942 943 /* Return the ID of the name number 'nameIndex' of a given face */ 944 /* used to enumerate the charmaps present in a TrueType file. */ 945 946 TT_Error TT_Get_Name_ID( TT_Face face, 947 int nameIndex, 948 short* platformID, 949 short* encodingID, 950 short* languageID, 951 short* nameID ); 952 953 954 /* Return the address and length of the name number 'nameIndex' */ 955 /* of a given face. The string is part of the face object and */ 956 /* shouldn't be written to or released. */ 957 958 /* Note that if the string platformID is not in the range 0..3, */ 959 /* a null pointer will be returned */ 960 961 TT_Error TT_Get_Name_String( TT_Face face, 962 int nameIndex, 963 char** stringPtr, /* pointer address */ 964 int* length ); /* str. length address */ 965 966 967 968 /************************ callback definition ******************/ 969 970 /* NOTE : Callbacks are still in beta stage, they'll be used to */ 971 /* perform efficient glyph outline caching. */ 972 973 /* There is currently only one callback defined */ 974 #define TT_Callback_Glyph_Outline_Load 0 975 976 /* The glyph loader callback type defines a function that will */ 977 /* be called by the TrueType glyph loader to query an already */ 978 /* cached glyph outline from higher-level libraries. Normal */ 979 /* clients of the TrueType engine shouldn't worry about this */ 980 981 typedef int (*TT_Glyph_Loader_Callback)( void* instance_ptr, 982 int glyph_index, 983 TT_Outline* outline, 984 TT_F26Dot6* lsb, 985 TT_F26Dot6* aw ); 986 987 /* Register a new callback to the TrueType engine - this should */ 988 /* only be used by higher-level libraries, not typical clients */ 989 990 TT_Error TT_Register_Callback( TT_Engine engine, 991 int callback_id, 992 void* callback_ptr ); 993 994 /************************ error codes declaration **************/ 995 996 /* The error codes are grouped in 'classes' used to indicate the */ 997 /* 'level' at which the error happened. */ 998 /* The class is given by an error code's high byte. */ 999 1000 1001 /* ------------- Success is always 0 -------- */ 1002 1003 #define TT_Err_Ok 0 1004 1005 1006 /* -------- High-level API error codes ------ */ 1007 1008 #define TT_Err_Invalid_Face_Handle 0x001 1009 #define TT_Err_Invalid_Instance_Handle 0x002 1010 #define TT_Err_Invalid_Glyph_Handle 0x003 1011 #define TT_Err_Invalid_CharMap_Handle 0x004 1012 #define TT_Err_Invalid_Result_Address 0x005 1013 #define TT_Err_Invalid_Glyph_Index 0x006 1014 #define TT_Err_Invalid_Argument 0x007 1015 #define TT_Err_Could_Not_Open_File 0x008 1016 #define TT_Err_File_Is_Not_Collection 0x009 1017 1018 #define TT_Err_Table_Missing 0x00A 1019 #define TT_Err_Invalid_Horiz_Metrics 0x00B 1020 #define TT_Err_Invalid_CharMap_Format 0x00C 1021 #define TT_Err_Invalid_PPem 0x00D 1022 1023 #define TT_Err_Invalid_File_Format 0x010 1024 1025 #define TT_Err_Invalid_Engine 0x020 1026 #define TT_Err_Too_Many_Extensions 0x021 1027 #define TT_Err_Extensions_Unsupported 0x022 1028 #define TT_Err_Invalid_Extension_Id 0x023 1029 1030 #define TT_Err_Max_Profile_Missing 0x080 1031 #define TT_Err_Header_Table_Missing 0x081 1032 #define TT_Err_Horiz_Header_Missing 0x082 1033 #define TT_Err_Locations_Missing 0x083 1034 #define TT_Err_Name_Table_Missing 0x084 1035 #define TT_Err_CMap_Table_Missing 0x085 1036 #define TT_Err_Hmtx_Table_Missing 0x086 1037 #define TT_Err_OS2_Table_Missing 0x087 1038 #define TT_Err_Post_Table_Missing 0x088 1039 1040 1041 /* -------- Memory component error codes ---- */ 1042 1043 /* this error indicates that an operation cannot */ 1044 /* be performed due to memory exhaustion. */ 1045 1046 #define TT_Err_Out_Of_Memory 0x100 1047 1048 1049 /* -------- File component error codes ------ */ 1050 1051 /* these error codes indicate that the file could */ 1052 /* not be accessed properly. Usually, this means */ 1053 /* a broken font file! */ 1054 1055 #define TT_Err_Invalid_File_Offset 0x200 1056 #define TT_Err_Invalid_File_Read 0x201 1057 #define TT_Err_Invalid_Frame_Access 0x202 1058 1059 1060 /* -------- Glyph loader error codes -------- */ 1061 1062 /* Produced only by the glyph loader, these error */ 1063 /* codes indicate a broken glyph in a font file. */ 1064 1065 #define TT_Err_Too_Many_Points 0x300 1066 #define TT_Err_Too_Many_Contours 0x301 1067 #define TT_Err_Invalid_Composite 0x302 1068 #define TT_Err_Too_Many_Ins 0x303 1069 1070 1071 /* --- bytecode interpreter error codes ----- */ 1072 1073 /* These error codes are produced by the TrueType */ 1074 /* bytecode interpreter. They usually indicate a */ 1075 /* broken font file, a broken glyph within a font */ 1076 /* file, or a bug in the interpreter! */ 1077 1078 #define TT_Err_Invalid_Opcode 0x400 1079 #define TT_Err_Too_Few_Arguments 0x401 1080 #define TT_Err_Stack_Overflow 0x402 1081 #define TT_Err_Code_Overflow 0x403 1082 #define TT_Err_Bad_Argument 0x404 1083 #define TT_Err_Divide_By_Zero 0x405 1084 #define TT_Err_Storage_Overflow 0x406 1085 #define TT_Err_Cvt_Overflow 0x407 1086 #define TT_Err_Invalid_Reference 0x408 1087 #define TT_Err_Invalid_Distance 0x409 1088 #define TT_Err_Interpolate_Twilight 0x40A 1089 #define TT_Err_Debug_OpCode 0x40B 1090 #define TT_Err_ENDF_In_Exec_Stream 0x40C 1091 #define TT_Err_Out_Of_CodeRanges 0x40D 1092 #define TT_Err_Nested_DEFS 0x40E 1093 #define TT_Err_Invalid_CodeRange 0x40F 1094 #define TT_Err_Invalid_Displacement 0x410 1095 1096 1097 /* ------ internal failure error codes ----- */ 1098 1099 /* These error codes are produced when an incoherent */ 1100 /* library state has been detected. These reflect a */ 1101 /* severe bug in the engine! (or a major overwrite */ 1102 /* of your application into the library's data). */ 1103 1104 #define TT_Err_Nested_Frame_Access 0x500 1105 #define TT_Err_Invalid_Cache_List 0x501 1106 #define TT_Err_Could_Not_Find_Context 0x502 1107 #define TT_Err_Unlisted_Object 0x503 1108 1109 1110 /* ---- scan-line converter error codes ----- */ 1111 1112 /* These error codes are produced by the raster component. */ 1113 /* They indicate that an outline structure was incoherently */ 1114 /* setup, or that you're trying to render an horribly */ 1115 /* complex glyph! */ 1116 1117 #define TT_Err_Raster_Pool_Overflow 0x600 1118 #define TT_Err_Raster_Negative_Height 0x601 1119 #define TT_Err_Raster_Invalid_Value 0x602 1120 #define TT_Err_Raster_Not_Initialized 0x603 1121 1122 1123 #ifdef __cplusplus 1124 } 1125 #endif 1126 1127 #endif /* FREETYPE_H */ 1128 1129 1130 /* END */ 1131