1 /***************************************************************************/ 2 /* */ 3 /* ahtypes.h */ 4 /* */ 5 /* General types and definitions for the auto-hint module */ 6 /* (specification only). */ 7 /* */ 8 /* Copyright 2000-2001, 2002 Catharon Productions Inc. */ 9 /* Author: David Turner */ 10 /* */ 11 /* This file is part of the Catharon Typography Project and shall only */ 12 /* be used, modified, and distributed under the terms of the Catharon */ 13 /* Open Source License that should come with this file under the name */ 14 /* `CatharonLicense.txt'. By continuing to use, modify, or distribute */ 15 /* this file you indicate that you have read the license and */ 16 /* understand and accept it fully. */ 17 /* */ 18 /* Note that this license is compatible with the FreeType license. */ 19 /* */ 20 /***************************************************************************/ 21 22 23 #ifndef __AHTYPES_H__ 24 #define __AHTYPES_H__ 25 26 27 #include <ft2build.h> 28 #include FT_INTERNAL_OBJECTS_H 29 30 #ifdef DEBUG_HINTER 31 #include <../src/autohint/ahloader.h> 32 #else 33 #include "ahloader.h" 34 #endif 35 36 37 #define xxAH_DEBUG 38 39 40 #ifdef AH_DEBUG 41 42 #include <stdio.h> 43 #define AH_LOG( x ) printf ## x 44 45 #else 46 47 #define AH_LOG( x ) do ; while ( 0 ) /* nothing */ 48 49 #endif /* AH_DEBUG */ 50 51 52 FT_BEGIN_HEADER 53 54 55 /*************************************************************************/ 56 /*************************************************************************/ 57 /*************************************************************************/ 58 /**** ****/ 59 /**** COMPILE-TIME BUILD OPTIONS ****/ 60 /**** ****/ 61 /**** Toggle these configuration macros to experiment with `features' ****/ 62 /**** of the auto-hinter. ****/ 63 /**** ****/ 64 /*************************************************************************/ 65 /*************************************************************************/ 66 /*************************************************************************/ 67 68 69 /*************************************************************************/ 70 /* */ 71 /* If this option is defined, only strong interpolation will be used to */ 72 /* place the points between edges. Otherwise, `smooth' points are */ 73 /* detected and later hinted through weak interpolation to correct some */ 74 /* unpleasant artefacts. */ 75 /* */ 76 #undef AH_OPTION_NO_WEAK_INTERPOLATION 77 78 79 /*************************************************************************/ 80 /* */ 81 /* If this option is defined, only weak interpolation will be used to */ 82 /* place the points between edges. Otherwise, `strong' points are */ 83 /* detected and later hinted through strong interpolation to correct */ 84 /* some unpleasant artefacts. */ 85 /* */ 86 #undef AH_OPTION_NO_STRONG_INTERPOLATION 87 88 89 /*************************************************************************/ 90 /* */ 91 /* Undefine this macro if you don't want to hint the metrics. There is */ 92 /* no reason to do this (at least for non-CJK scripts), except for */ 93 /* experimentation. */ 94 /* */ 95 #undef AH_HINT_METRICS 96 97 98 /*************************************************************************/ 99 /* */ 100 /* Define this macro if you do not want to insert extra edges at a */ 101 /* glyph's x and y extremum (if there isn't one already available). */ 102 /* This helps to reduce a number of artefacts and allows hinting of */ 103 /* metrics. */ 104 /* */ 105 #undef AH_OPTION_NO_EXTREMUM_EDGES 106 107 108 /* don't touch for now */ 109 #define AH_MAX_WIDTHS 12 110 #define AH_MAX_HEIGHTS 12 111 112 113 /*************************************************************************/ 114 /*************************************************************************/ 115 /*************************************************************************/ 116 /**** ****/ 117 /**** TYPE DEFINITIONS ****/ 118 /**** ****/ 119 /*************************************************************************/ 120 /*************************************************************************/ 121 /*************************************************************************/ 122 123 124 /* see agangles.h */ 125 typedef FT_Int AH_Angle; 126 127 128 /* hint flags */ 129 #define AH_FLAG_NONE 0 130 131 /* bezier control points flags */ 132 #define AH_FLAG_CONIC 1 133 #define AH_FLAG_CUBIC 2 134 #define AH_FLAG_CONTROL ( AH_FLAG_CONIC | AH_FLAG_CUBIC ) 135 136 /* extrema flags */ 137 #define AH_FLAG_EXTREMA_X 4 138 #define AH_FLAG_EXTREMA_Y 8 139 140 /* roundness */ 141 #define AH_FLAG_ROUND_X 16 142 #define AH_FLAG_ROUND_Y 32 143 144 /* touched */ 145 #define AH_FLAG_TOUCH_X 64 146 #define AH_FLAG_TOUCH_Y 128 147 148 /* weak interpolation */ 149 #define AH_FLAG_WEAK_INTERPOLATION 256 150 #define AH_FLAG_INFLECTION 512 151 152 typedef FT_Int AH_Flags; 153 154 155 /* edge hint flags */ 156 #define AH_EDGE_NORMAL 0 157 #define AH_EDGE_ROUND 1 158 #define AH_EDGE_SERIF 2 159 #define AH_EDGE_DONE 4 160 161 typedef FT_Int AH_Edge_Flags; 162 163 164 /* hint directions -- the values are computed so that two vectors are */ 165 /* in opposite directions iff `dir1+dir2 == 0' */ 166 #define AH_DIR_NONE 4 167 #define AH_DIR_RIGHT 1 168 #define AH_DIR_LEFT -1 169 #define AH_DIR_UP 2 170 #define AH_DIR_DOWN -2 171 172 typedef FT_Int AH_Direction; 173 174 175 typedef struct AH_PointRec_* AH_Point; 176 typedef struct AH_SegmentRec_* AH_Segment; 177 typedef struct AH_EdgeRec_* AH_Edge; 178 179 180 /*************************************************************************/ 181 /* */ 182 /* <Struct> */ 183 /* AH_PointRec */ 184 /* */ 185 /* <Description> */ 186 /* A structure used to model an outline point to the AH_OutlineRec */ 187 /* type. */ 188 /* */ 189 /* <Fields> */ 190 /* flags :: The current point hint flags. */ 191 /* */ 192 /* ox, oy :: The current original scaled coordinates. */ 193 /* */ 194 /* fx, fy :: The current coordinates in font units. */ 195 /* */ 196 /* x, y :: The current hinted coordinates. */ 197 /* */ 198 /* u, v :: Point coordinates -- meaning varies with context. */ 199 /* */ 200 /* in_dir :: The direction of the inwards vector (prev->point). */ 201 /* */ 202 /* out_dir :: The direction of the outwards vector (point->next). */ 203 /* */ 204 /* in_angle :: The angle of the inwards vector. */ 205 /* */ 206 /* out_angle :: The angle of the outwards vector. */ 207 /* */ 208 /* next :: The next point in same contour. */ 209 /* */ 210 /* prev :: The previous point in same contour. */ 211 /* */ 212 typedef struct AH_PointRec_ 213 { 214 AH_Flags flags; /* point flags used by hinter */ 215 FT_Pos ox, oy; 216 FT_Pos fx, fy; 217 FT_Pos x, y; 218 FT_Pos u, v; 219 220 AH_Direction in_dir; /* direction of inwards vector */ 221 AH_Direction out_dir; /* direction of outwards vector */ 222 223 AH_Angle in_angle; 224 AH_Angle out_angle; 225 226 AH_Point next; /* next point in contour */ 227 AH_Point prev; /* previous point in contour */ 228 229 } AH_PointRec; 230 231 232 /*************************************************************************/ 233 /* */ 234 /* <Struct> */ 235 /* AH_SegmentRec */ 236 /* */ 237 /* <Description> */ 238 /* A structure used to describe an edge segment to the auto-hinter. */ 239 /* A segment is simply a sequence of successive points located on the */ 240 /* same horizontal or vertical `position', in a given direction. */ 241 /* */ 242 /* <Fields> */ 243 /* flags :: The segment edge flags (straight, rounded, etc.). */ 244 /* */ 245 /* dir :: The segment direction. */ 246 /* */ 247 /* first :: The first point in the segment. */ 248 /* */ 249 /* last :: The last point in the segment. */ 250 /* */ 251 /* contour :: A pointer to the first point of the segment's */ 252 /* contour. */ 253 /* */ 254 /* pos :: The segment position in font units. */ 255 /* */ 256 /* size :: The segment size. */ 257 /* */ 258 /* edge :: The edge of the current segment. */ 259 /* */ 260 /* edge_next :: The next segment on the same edge. */ 261 /* */ 262 /* link :: The pairing segment for this edge. */ 263 /* */ 264 /* serif :: The primary segment for serifs. */ 265 /* */ 266 /* num_linked :: The number of other segments that link to this one. */ 267 /* */ 268 /* score :: Used to score the segment when selecting them. */ 269 /* */ 270 typedef struct AH_SegmentRec_ 271 { 272 AH_Edge_Flags flags; 273 AH_Direction dir; 274 275 AH_Point first; /* first point in edge segment */ 276 AH_Point last; /* last point in edge segment */ 277 AH_Point* contour; /* ptr to first point of segment's contour */ 278 279 FT_Pos pos; /* position of segment */ 280 FT_Pos min_coord; /* minimum coordinate of segment */ 281 FT_Pos max_coord; /* maximum coordinate of segment */ 282 283 AH_Edge edge; 284 AH_Segment edge_next; 285 286 AH_Segment link; /* link segment */ 287 AH_Segment serif; /* primary segment for serifs */ 288 FT_Pos num_linked; /* number of linked segments */ 289 FT_Pos score; 290 291 } AH_SegmentRec; 292 293 294 /*************************************************************************/ 295 /* */ 296 /* <Struct> */ 297 /* AH_EdgeRec */ 298 /* */ 299 /* <Description> */ 300 /* A structure used to describe an edge, which really is a horizontal */ 301 /* or vertical coordinate to be hinted depending on the segments */ 302 /* located on it. */ 303 /* */ 304 /* <Fields> */ 305 /* flags :: The segment edge flags (straight, rounded, etc.). */ 306 /* */ 307 /* dir :: The main segment direction on this edge. */ 308 /* */ 309 /* first :: The first edge segment. */ 310 /* */ 311 /* last :: The last edge segment. */ 312 /* */ 313 /* fpos :: The original edge position in font units. */ 314 /* */ 315 /* opos :: The original scaled edge position. */ 316 /* */ 317 /* pos :: The hinted edge position. */ 318 /* */ 319 /* link :: The linked edge. */ 320 /* */ 321 /* serif :: The serif edge. */ 322 /* */ 323 /* num_paired :: The number of other edges that pair to this one. */ 324 /* */ 325 /* score :: Used to score the edge when selecting them. */ 326 /* */ 327 /* blue_edge :: Indicate the blue zone edge this edge is related to. */ 328 /* Only set for some of the horizontal edges in a Latin */ 329 /* font. */ 330 /* */ 331 typedef struct AH_EdgeRec_ 332 { 333 AH_Edge_Flags flags; 334 AH_Direction dir; 335 336 AH_Segment first; 337 AH_Segment last; 338 339 FT_Pos fpos; 340 FT_Pos opos; 341 FT_Pos pos; 342 343 AH_Edge link; 344 AH_Edge serif; 345 FT_Int num_linked; 346 347 FT_Int score; 348 FT_Pos* blue_edge; 349 350 } AH_EdgeRec; 351 352 353 /* an outline as seen by the hinter */ 354 typedef struct AH_OutlineRec_ 355 { 356 FT_Memory memory; 357 358 AH_Direction vert_major_dir; /* vertical major direction */ 359 AH_Direction horz_major_dir; /* horizontal major direction */ 360 361 FT_Fixed x_scale; 362 FT_Fixed y_scale; 363 FT_Pos edge_distance_threshold; 364 365 FT_Int max_points; 366 FT_Int num_points; 367 AH_Point points; 368 369 FT_Int max_contours; 370 FT_Int num_contours; 371 AH_Point * contours; 372 373 FT_Int num_hedges; 374 AH_Edge horz_edges; 375 376 FT_Int num_vedges; 377 AH_Edge vert_edges; 378 379 FT_Int num_hsegments; 380 AH_Segment horz_segments; 381 382 FT_Int num_vsegments; 383 AH_Segment vert_segments; 384 385 } AH_OutlineRec, *AH_Outline; 386 387 388 #define AH_BLUE_CAPITAL_TOP 0 /* THEZOCQS */ 389 #define AH_BLUE_CAPITAL_BOTTOM ( AH_BLUE_CAPITAL_TOP + 1 ) /* HEZLOCUS */ 390 #define AH_BLUE_SMALL_TOP ( AH_BLUE_CAPITAL_BOTTOM + 1 ) /* xzroesc */ 391 #define AH_BLUE_SMALL_BOTTOM ( AH_BLUE_SMALL_TOP + 1 ) /* xzroesc */ 392 #define AH_BLUE_SMALL_MINOR ( AH_BLUE_SMALL_BOTTOM + 1 ) /* pqgjy */ 393 #define AH_BLUE_MAX ( AH_BLUE_SMALL_MINOR + 1 ) 394 395 typedef FT_Int AH_Blue; 396 397 398 #define AH_HINTER_MONOCHROME 1 399 #define AH_HINTER_OPTIMIZE 2 400 401 typedef FT_Int AH_Hinter_Flags; 402 403 404 /*************************************************************************/ 405 /* */ 406 /* <Struct> */ 407 /* AH_GlobalsRec */ 408 /* */ 409 /* <Description> */ 410 /* Holds the global metrics for a given font face (be it in design */ 411 /* units or scaled pixel values). */ 412 /* */ 413 /* <Fields> */ 414 /* num_widths :: The number of widths. */ 415 /* */ 416 /* num_heights :: The number of heights. */ 417 /* */ 418 /* widths :: Snap widths, including standard one. */ 419 /* */ 420 /* heights :: Snap height, including standard one. */ 421 /* */ 422 /* blue_refs :: The reference positions of blue zones. */ 423 /* */ 424 /* blue_shoots :: The overshoot positions of blue zones. */ 425 /* */ 426 typedef struct AH_GlobalsRec_ 427 { 428 FT_Int num_widths; 429 FT_Int num_heights; 430 431 FT_Pos stds[2]; 432 433 FT_Pos widths [AH_MAX_WIDTHS]; 434 FT_Pos heights[AH_MAX_HEIGHTS]; 435 436 FT_Pos blue_refs [AH_BLUE_MAX]; 437 FT_Pos blue_shoots[AH_BLUE_MAX]; 438 439 } AH_GlobalsRec, *AH_Globals; 440 441 442 /*************************************************************************/ 443 /* */ 444 /* <Struct> */ 445 /* AH_Face_GlobalsRec */ 446 /* */ 447 /* <Description> */ 448 /* Holds the complete global metrics for a given font face (i.e., the */ 449 /* design units version + a scaled version + the current scales */ 450 /* used). */ 451 /* */ 452 /* <Fields> */ 453 /* face :: A handle to the source face object */ 454 /* */ 455 /* design :: The globals in font design units. */ 456 /* */ 457 /* scaled :: Scaled globals in sub-pixel values. */ 458 /* */ 459 /* x_scale :: The current horizontal scale. */ 460 /* */ 461 /* y_scale :: The current vertical scale. */ 462 /* */ 463 typedef struct AH_Face_GlobalsRec_ 464 { 465 FT_Face face; 466 AH_GlobalsRec design; 467 AH_GlobalsRec scaled; 468 FT_Fixed x_scale; 469 FT_Fixed y_scale; 470 FT_Bool control_overshoot; 471 472 } AH_Face_GlobalsRec, *AH_Face_Globals; 473 474 475 typedef struct AH_HinterRec 476 { 477 FT_Memory memory; 478 AH_Hinter_Flags flags; 479 480 FT_Int algorithm; 481 FT_Face face; 482 483 AH_Face_Globals globals; 484 485 AH_Outline glyph; 486 487 AH_Loader loader; 488 FT_Vector pp1; 489 FT_Vector pp2; 490 491 FT_Bool transformed; 492 FT_Vector trans_delta; 493 FT_Matrix trans_matrix; 494 495 FT_Bool do_horz_hints; /* disable X hinting */ 496 FT_Bool do_vert_hints; /* disable Y hinting */ 497 FT_Bool do_horz_snapping; /* disable X stem size snapping */ 498 FT_Bool do_vert_snapping; /* disable Y stem size snapping */ 499 500 } AH_HinterRec, *AH_Hinter; 501 502 503 #ifdef DEBUG_HINTER 504 extern AH_Hinter ah_debug_hinter; 505 extern FT_Bool ah_debug_disable_horz; 506 extern FT_Bool ah_debug_disable_vert; 507 #else 508 #define ah_debug_disable_horz 0 509 #define ah_debug_disable_vert 0 510 #endif /* DEBUG_HINTER */ 511 512 513 FT_END_HEADER 514 515 #endif /* __AHTYPES_H__ */ 516 517 518 /* END */ 519