55#define FT_COMPONENT cf2hints
63 } CF2_HintMoveRec, *CF2_HintMove;
69 cf2_getWindingMomentum( CF2_Fixed x1,
77 return ( x1 >> 16 ) * ( SUB_INT32( y2, y1 ) >> 16 ) -
78 ( y1 >> 16 ) * ( SUB_INT32( x2, x1 ) >> 16 );
90 cf2_hint_init( CF2_Hint hint,
91 const CF2_ArrStack stemHintArray,
99 const CF2_StemHintRec* stemHint;
104 stemHint = (
const CF2_StemHintRec*)cf2_arrstack_getPointer(
108 width = SUB_INT32( stemHint->max, stemHint->min );
110 if ( width == cf2_intToFixed( -21 ) )
116 hint->csCoord = stemHint->max;
117 hint->flags = CF2_GhostBottom;
123 else if ( width == cf2_intToFixed( -20 ) )
131 hint->csCoord = stemHint->min;
132 hint->flags = CF2_GhostTop;
136 else if ( width < 0 )
158 hint->csCoord = stemHint->max;
159 hint->flags = CF2_PairBottom;
163 hint->csCoord = stemHint->min;
164 hint->flags = CF2_PairTop;
174 hint->csCoord = stemHint->min;
175 hint->flags = CF2_PairBottom;
179 hint->csCoord = stemHint->max;
180 hint->flags = CF2_PairTop;
187 if ( cf2_hint_isTop( hint ) )
188 hint->csCoord = ADD_INT32( hint->csCoord, 2 * font->darkenY );
190 hint->csCoord = ADD_INT32( hint->csCoord, hintOrigin );
192 hint->index = indexStemHint;
195 if ( hint->flags != 0 && stemHint->used )
197 if ( cf2_hint_isTop( hint ) )
198 hint->dsCoord = stemHint->maxDS;
200 hint->dsCoord = stemHint->minDS;
202 cf2_hint_lock( hint );
205 hint->dsCoord = FT_MulFix( hint->csCoord, scale );
211 cf2_hint_initZero( CF2_Hint hint )
217 FT_LOCAL_DEF( FT_Bool )
218 cf2_hint_isValid(
const CF2_Hint hint )
220 return FT_BOOL( hint->flags );
225 cf2_hint_isPair(
const CF2_Hint hint )
227 return FT_BOOL( hint->flags & ( CF2_PairBottom | CF2_PairTop ) );
232 cf2_hint_isPairTop(
const CF2_Hint hint )
234 return FT_BOOL( hint->flags & CF2_PairTop );
238 FT_LOCAL_DEF( FT_Bool )
239 cf2_hint_isTop(
const CF2_Hint hint )
241 return FT_BOOL( hint->flags & ( CF2_PairTop | CF2_GhostTop ) );
245 FT_LOCAL_DEF( FT_Bool )
246 cf2_hint_isBottom(
const CF2_Hint hint )
248 return FT_BOOL( hint->flags & ( CF2_PairBottom | CF2_GhostBottom ) );
253 cf2_hint_isLocked(
const CF2_Hint hint )
255 return FT_BOOL( hint->flags & CF2_Locked );
260 cf2_hint_isSynthetic(
const CF2_Hint hint )
262 return FT_BOOL( hint->flags & CF2_Synthetic );
267 cf2_hint_lock( CF2_Hint hint )
269 hint->flags |= CF2_Locked;
274 cf2_hintmap_init( CF2_HintMap hintmap,
276 CF2_HintMap initialMap,
277 CF2_ArrStack hintMoves,
283 hintmap->hinted = font->hinted;
284 hintmap->scale = scale;
285 hintmap->font = font;
286 hintmap->initialHintMap = initialMap;
288 hintmap->hintMoves = hintMoves;
293 cf2_hintmap_isValid(
const CF2_HintMap hintmap )
295 return hintmap->isValid;
300 cf2_hintmap_dump( CF2_HintMap hintmap )
302#ifdef FT_DEBUG_LEVEL_TRACE
306 FT_TRACE6((
" index csCoord dsCoord scale flags\n" ));
308 for ( i = 0; i < hintmap->count; i++ )
310 CF2_Hint hint = &hintmap->edge[i];
313 FT_TRACE6((
" %3zu %7.2f %7.2f %5d %s%s%s%s\n",
315 hint->csCoord / 65536.0,
316 hint->dsCoord / ( hint->scale * 1.0 ),
318 ( cf2_hint_isPair( hint ) ?
"p" :
"g" ),
319 ( cf2_hint_isTop( hint ) ?
"t" :
"b" ),
320 ( cf2_hint_isLocked( hint ) ?
"L" :
""),
321 ( cf2_hint_isSynthetic( hint ) ?
"S" :
"" ) ));
324 FT_UNUSED( hintmap );
331 cf2_hintmap_map( CF2_HintMap hintmap,
334 if ( hintmap->count == 0 || !hintmap->hinted )
337 return FT_MulFix( csCoord, hintmap->scale );
342 CF2_UInt i = hintmap->lastIndex;
345 FT_ASSERT( hintmap->lastIndex < CF2_MAX_HINT_EDGES );
348 while ( i < hintmap->count - 1 &&
349 csCoord >= hintmap->edge[i + 1].csCoord )
353 while ( i > 0 && csCoord < hintmap->edge[i].csCoord )
356 hintmap->lastIndex = i;
358 if ( i == 0 && csCoord < hintmap->edge[0].csCoord )
361 return ADD_INT32( FT_MulFix( SUB_INT32( csCoord,
362 hintmap->edge[0].csCoord ),
364 hintmap->edge[0].dsCoord );
372 return ADD_INT32( FT_MulFix( SUB_INT32( csCoord,
373 hintmap->edge[i].csCoord ),
374 hintmap->edge[i].scale ),
375 hintmap->edge[i].dsCoord );
396 cf2_hintmap_adjustHints( CF2_HintMap hintmap )
401 cf2_arrstack_clear( hintmap->hintMoves );
411 for ( i = 0; i < hintmap->count; i++ )
413 FT_Bool isPair = cf2_hint_isPair( &hintmap->edge[i] );
423 j = isPair ? i + 1 : i;
425 FT_ASSERT( j < hintmap->count );
426 FT_ASSERT( cf2_hint_isValid( &hintmap->edge[i] ) );
427 FT_ASSERT( cf2_hint_isValid( &hintmap->edge[j] ) );
428 FT_ASSERT( cf2_hint_isLocked( &hintmap->edge[i] ) ==
429 cf2_hint_isLocked( &hintmap->edge[j] ) );
431 dsCoord_i = hintmap->edge[i].dsCoord;
432 dsCoord_j = hintmap->edge[j].dsCoord;
434 if ( !cf2_hint_isLocked( &hintmap->edge[i] ) )
437 CF2_Fixed fracDown = cf2_fixedFraction( dsCoord_i );
438 CF2_Fixed fracUp = cf2_fixedFraction( dsCoord_j );
441 CF2_Fixed downMoveDown = 0 - fracDown;
442 CF2_Fixed upMoveDown = 0 - fracUp;
443 CF2_Fixed downMoveUp = ( fracDown == 0 )
445 : cf2_intToFixed( 1 ) - fracDown;
446 CF2_Fixed upMoveUp = ( fracUp == 0 )
448 : cf2_intToFixed( 1 ) - fracUp;
451 CF2_Fixed moveUp = FT_MIN( downMoveUp, upMoveUp );
453 CF2_Fixed moveDown = FT_MAX( downMoveDown, upMoveDown );
455 CF2_Fixed downMinCounter = CF2_MIN_COUNTER;
456 CF2_Fixed upMinCounter = CF2_MIN_COUNTER;
457 FT_Bool saveEdge = FALSE;
465 cf2_hint_isSynthetic( &hintmap->edge[i - 1] ) )
468 if ( j >= hintmap->count - 1 ||
469 cf2_hint_isSynthetic( &hintmap->edge[j + 1] ) )
476 if ( j >= hintmap->count - 1 ||
477 hintmap->edge[j + 1].dsCoord >=
478 ADD_INT32( dsCoord_j, moveUp + upMinCounter ) )
482 hintmap->edge[i - 1].dsCoord <=
483 ADD_INT32( dsCoord_i, moveDown - downMinCounter ) )
486 move = ( -moveDown < moveUp ) ? moveDown : moveUp;
495 hintmap->edge[i - 1].dsCoord <=
496 ADD_INT32( dsCoord_i, moveDown - downMinCounter ) )
500 saveEdge = FT_BOOL( moveUp < -moveDown );
516 j < hintmap->count - 1 &&
517 !cf2_hint_isLocked( &hintmap->edge[j + 1] ) )
519 CF2_HintMoveRec savedMove;
524 savedMove.moveUp = moveUp - move;
526 cf2_arrstack_push( hintmap->hintMoves, &savedMove );
530 hintmap->edge[i].dsCoord = ADD_INT32( dsCoord_i, move );
532 hintmap->edge[j].dsCoord = ADD_INT32( dsCoord_j, move );
539 ( ( dsCoord_i ^ move ) >= 0 &&
540 ( dsCoord_i ^ hintmap->edge[i].dsCoord ) < 0 ) ||
541 hintmap->edge[i - 1].dsCoord <= hintmap->edge[i].dsCoord );
543 ( ( dsCoord_j ^ move ) >= 0 &&
544 ( dsCoord_j ^ hintmap->edge[j].dsCoord ) < 0 ) ||
545 hintmap->edge[i].dsCoord <= hintmap->edge[j].dsCoord );
550 if ( hintmap->edge[i].csCoord != hintmap->edge[i - 1].csCoord )
551 hintmap->edge[i - 1].scale =
552 FT_DivFix( SUB_INT32( hintmap->edge[i].dsCoord,
553 hintmap->edge[i - 1].dsCoord ),
554 SUB_INT32( hintmap->edge[i].csCoord,
555 hintmap->edge[i - 1].csCoord ) );
560 if ( hintmap->edge[j].csCoord != hintmap->edge[j - 1].csCoord )
561 hintmap->edge[j - 1].scale =
562 FT_DivFix( SUB_INT32( hintmap->edge[j].dsCoord,
563 hintmap->edge[j - 1].dsCoord ),
564 SUB_INT32( hintmap->edge[j].csCoord,
565 hintmap->edge[j - 1].csCoord ) );
573 for ( i = cf2_arrstack_size( hintmap->hintMoves ); i > 0; i-- )
575 CF2_HintMove hintMove = (CF2_HintMove)
576 cf2_arrstack_getPointer( hintmap->hintMoves, i - 1 );
582 FT_ASSERT( j < hintmap->count - 1 );
585 if ( hintmap->edge[j + 1].dsCoord >=
586 ADD_INT32( hintmap->edge[j].dsCoord,
587 hintMove->moveUp + CF2_MIN_COUNTER ) )
590 hintmap->edge[j].dsCoord = ADD_INT32( hintmap->edge[j].dsCoord,
593 if ( cf2_hint_isPair( &hintmap->edge[j] ) )
596 hintmap->edge[j - 1].dsCoord =
597 ADD_INT32( hintmap->edge[j - 1].dsCoord, hintMove->moveUp );
606 cf2_hintmap_insertHint( CF2_HintMap hintmap,
607 CF2_Hint bottomHintEdge,
608 CF2_Hint topHintEdge )
610 CF2_UInt indexInsert;
613 FT_Bool isPair = TRUE;
614 CF2_Hint firstHintEdge = bottomHintEdge;
615 CF2_Hint secondHintEdge = topHintEdge;
620 FT_ASSERT( cf2_hint_isValid( bottomHintEdge ) ||
621 cf2_hint_isValid( topHintEdge ) );
624 if ( !cf2_hint_isValid( bottomHintEdge ) )
627 firstHintEdge = topHintEdge;
630 else if ( !cf2_hint_isValid( topHintEdge ) )
638 topHintEdge->csCoord < bottomHintEdge->csCoord )
643 for ( ; indexInsert < hintmap->count; indexInsert++ )
645 if ( hintmap->edge[indexInsert].csCoord >= firstHintEdge->csCoord )
649 FT_TRACE7((
" Got hint at %.2f (%.2f)\n",
650 firstHintEdge->csCoord / 65536.0,
651 firstHintEdge->dsCoord / 65536.0 ));
653 FT_TRACE7((
" Got hint at %.2f (%.2f)\n",
654 secondHintEdge->csCoord / 65536.0,
655 secondHintEdge->dsCoord / 65536.0 ));
668 if ( indexInsert < hintmap->count )
672 if ( hintmap->edge[indexInsert].csCoord == firstHintEdge->csCoord )
677 hintmap->edge[indexInsert].csCoord <= secondHintEdge->csCoord )
681 if ( cf2_hint_isPairTop( &hintmap->edge[indexInsert] ) )
686 if ( cf2_hintmap_isValid( hintmap->initialHintMap ) &&
687 !cf2_hint_isLocked( firstHintEdge ) )
695 hintmap->initialHintMap,
697 firstHintEdge->csCoord,
698 SUB_INT32 ( secondHintEdge->csCoord,
699 firstHintEdge->csCoord ) / 2 ) );
700 CF2_Fixed halfWidth =
701 FT_MulFix( SUB_INT32( secondHintEdge->csCoord,
702 firstHintEdge->csCoord ) / 2,
706 firstHintEdge->dsCoord = SUB_INT32( midpoint, halfWidth );
707 secondHintEdge->dsCoord = ADD_INT32( midpoint, halfWidth );
710 firstHintEdge->dsCoord = cf2_hintmap_map( hintmap->initialHintMap,
711 firstHintEdge->csCoord );
735 if ( indexInsert > 0 )
738 if ( firstHintEdge->dsCoord < hintmap->edge[indexInsert - 1].dsCoord )
742 if ( indexInsert < hintmap->count )
747 if ( secondHintEdge->dsCoord > hintmap->edge[indexInsert].dsCoord )
752 if ( firstHintEdge->dsCoord > hintmap->edge[indexInsert].dsCoord )
759 CF2_UInt iSrc = hintmap->count - 1;
760 CF2_UInt iDst = isPair ? hintmap->count + 1 : hintmap->count;
762 CF2_UInt count = hintmap->count - indexInsert;
765 if ( iDst >= CF2_MAX_HINT_EDGES )
767 FT_TRACE4((
"cf2_hintmap_insertHint: too many hintmaps\n" ));
772 hintmap->edge[iDst--] = hintmap->edge[iSrc--];
775 hintmap->edge[indexInsert] = *firstHintEdge;
778 FT_TRACE7((
" Inserting hint %.2f (%.2f)\n",
779 firstHintEdge->csCoord / 65536.0,
780 firstHintEdge->dsCoord / 65536.0 ));
785 hintmap->edge[indexInsert + 1] = *secondHintEdge;
788 FT_TRACE7((
" Inserting hint %.2f (%.2f)\n",
789 secondHintEdge->csCoord / 65536.0,
790 secondHintEdge->dsCoord / 65536.0 ));
814 cf2_hintmap_build( CF2_HintMap hintmap,
815 CF2_ArrStack hStemHintArray,
816 CF2_ArrStack vStemHintArray,
817 CF2_HintMask hintMask,
818 CF2_Fixed hintOrigin,
823 CF2_Font font = hintmap->font;
824 CF2_HintMaskRec tempHintMask;
831 if ( !initialMap && !cf2_hintmap_isValid( hintmap->initialHintMap ) )
835 cf2_hintmask_init( &tempHintMask, hintMask->error );
836 cf2_hintmap_build( hintmap->initialHintMap,
844 if ( !cf2_hintmask_isValid( hintMask ) )
847 cf2_hintmask_setAll( hintMask,
848 cf2_arrstack_size( hStemHintArray ) +
849 cf2_arrstack_size( vStemHintArray ) );
850 if ( !cf2_hintmask_isValid( hintMask ) )
855 *hintMask->error = FT_Err_Ok;
856 hintmap->hinted = FALSE;
864 hintmap->lastIndex = 0;
867 tempHintMask = *hintMask;
868 maskPtr = cf2_hintmask_getMaskPtr( &tempHintMask );
871 bitCount = cf2_arrstack_size( hStemHintArray );
874 if ( bitCount > hintMask->bitCount )
878 if ( font->blues.doEmBoxHints )
883 cf2_hint_initZero( &dummy );
886 cf2_hintmap_insertHint( hintmap,
887 &font->blues.emBoxBottomEdge,
890 cf2_hintmap_insertHint( hintmap,
892 &font->blues.emBoxTopEdge );
897 for ( i = 0, maskByte = 0x80; i < bitCount; i++ )
899 if ( maskByte & *maskPtr )
902 CF2_HintRec bottomHintEdge, topHintEdge;
905 cf2_hint_init( &bottomHintEdge,
912 cf2_hint_init( &topHintEdge,
920 if ( cf2_hint_isLocked( &bottomHintEdge ) ||
921 cf2_hint_isLocked( &topHintEdge ) ||
922 cf2_blues_capture( &font->blues,
927 cf2_hintmap_insertHint( hintmap, &bottomHintEdge, &topHintEdge );
929 *maskPtr &= ~maskByte;
933 if ( ( i & 7 ) == 7 )
971 if ( hintmap->count == 0 ||
972 hintmap->edge[0].csCoord > 0 ||
973 hintmap->edge[hintmap->count - 1].csCoord < 0 )
978 CF2_HintRec edge, invalid;
981 cf2_hint_initZero( &edge );
983 edge.flags = CF2_GhostBottom |
986 edge.scale = hintmap->scale;
988 cf2_hint_initZero( &invalid );
989 cf2_hintmap_insertHint( hintmap, &edge, &invalid );
996 maskPtr = cf2_hintmask_getMaskPtr( &tempHintMask );
998 for ( i = 0, maskByte = 0x80; i < bitCount; i++ )
1000 if ( maskByte & *maskPtr )
1002 CF2_HintRec bottomHintEdge, topHintEdge;
1005 cf2_hint_init( &bottomHintEdge,
1012 cf2_hint_init( &topHintEdge,
1020 cf2_hintmap_insertHint( hintmap, &bottomHintEdge, &topHintEdge );
1023 if ( ( i & 7 ) == 7 )
1034#ifdef FT_DEBUG_LEVEL_TRACE
1037 FT_TRACE6((
"flags: [p]air [g]host [t]op"
1038 " [b]ottom [L]ocked [S]ynthetic\n" ));
1039 FT_TRACE6((
"Initial hintmap:\n" ));
1042 FT_TRACE6((
"Hints:\n" ));
1045 cf2_hintmap_dump( hintmap );
1057 cf2_hintmap_adjustHints( hintmap );
1059 FT_TRACE6((
"Hints adjusted:\n" ));
1060 cf2_hintmap_dump( hintmap );
1066 for ( i = 0; i < hintmap->count; i++ )
1068 if ( !cf2_hint_isSynthetic( &hintmap->edge[i] ) )
1072 CF2_StemHint stemhint = (CF2_StemHint)
1073 cf2_arrstack_getPointer( hStemHintArray,
1074 hintmap->edge[i].index );
1077 if ( cf2_hint_isTop( &hintmap->edge[i] ) )
1078 stemhint->maxDS = hintmap->edge[i].dsCoord;
1080 stemhint->minDS = hintmap->edge[i].dsCoord;
1082 stemhint->used = TRUE;
1088 hintmap->isValid = TRUE;
1091 cf2_hintmask_setNew( hintMask, FALSE );
1095 FT_LOCAL_DEF(
void )
1096 cf2_glyphpath_init( CF2_GlyphPath glyphpath,
1098 CF2_OutlineCallbacks callbacks,
1101 CF2_ArrStack hStemHintArray,
1102 CF2_ArrStack vStemHintArray,
1103 CF2_HintMask hintMask,
1104 CF2_Fixed hintOriginY,
1105 const CF2_Blues blues,
1106 const FT_Vector* fractionalTranslation )
1108 FT_ZERO( glyphpath );
1110 glyphpath->font = font;
1111 glyphpath->callbacks = callbacks;
1113 cf2_arrstack_init( &glyphpath->hintMoves,
1116 sizeof ( CF2_HintMoveRec ) );
1118 cf2_hintmap_init( &glyphpath->initialHintMap,
1120 &glyphpath->initialHintMap,
1121 &glyphpath->hintMoves,
1123 cf2_hintmap_init( &glyphpath->firstHintMap,
1125 &glyphpath->initialHintMap,
1126 &glyphpath->hintMoves,
1128 cf2_hintmap_init( &glyphpath->hintMap,
1130 &glyphpath->initialHintMap,
1131 &glyphpath->hintMoves,
1134 glyphpath->scaleX = font->innerTransform.a;
1135 glyphpath->scaleC = font->innerTransform.c;
1136 glyphpath->scaleY = font->innerTransform.d;
1138 glyphpath->fractionalTranslation = *fractionalTranslation;
1141 glyphpath->hShift = hShift;
1144 glyphpath->hStemHintArray = hStemHintArray;
1145 glyphpath->vStemHintArray = vStemHintArray;
1146 glyphpath->hintMask = hintMask;
1147 glyphpath->hintOriginY = hintOriginY;
1148 glyphpath->blues = blues;
1149 glyphpath->darken = font->darkened;
1150 glyphpath->xOffset = font->darkenX;
1151 glyphpath->yOffset = font->darkenY;
1152 glyphpath->miterLimit = 2 * FT_MAX(
1153 cf2_fixedAbs( glyphpath->xOffset ),
1154 cf2_fixedAbs( glyphpath->yOffset ) );
1157 glyphpath->snapThreshold = cf2_doubleToFixed( 0.1 );
1159 glyphpath->moveIsPending = TRUE;
1160 glyphpath->pathIsOpen = FALSE;
1161 glyphpath->pathIsClosing = FALSE;
1162 glyphpath->elemIsQueued = FALSE;
1166 FT_LOCAL_DEF(
void )
1167 cf2_glyphpath_finalize( CF2_GlyphPath glyphpath )
1169 cf2_arrstack_finalize( &glyphpath->hintMoves );
1180 cf2_glyphpath_hintPoint( CF2_GlyphPath glyphpath,
1181 CF2_HintMap hintmap,
1189 pt.x = ADD_INT32( FT_MulFix( glyphpath->scaleX, x ),
1190 FT_MulFix( glyphpath->scaleC, y ) );
1191 pt.y = cf2_hintmap_map( hintmap, y );
1194 FT_MulFix( glyphpath->font->outerTransform.a, pt.x ),
1196 FT_MulFix( glyphpath->font->outerTransform.c, pt.y ),
1197 glyphpath->fractionalTranslation.x ) );
1199 FT_MulFix( glyphpath->font->outerTransform.b, pt.x ),
1201 FT_MulFix( glyphpath->font->outerTransform.d, pt.y ),
1202 glyphpath->fractionalTranslation.y ) );
1214 cf2_glyphpath_computeIntersection( CF2_GlyphPath glyphpath,
1215 const FT_Vector* u1,
1216 const FT_Vector* u2,
1217 const FT_Vector* v1,
1218 const FT_Vector* v2,
1219 FT_Vector* intersection )
1241#define cf2_perp( a, b ) \
1242 ( FT_MulFix( a.x, b.y ) - FT_MulFix( a.y, b.x ) )
1245#define CF2_CS_SCALE( x ) \
1246 ( ( (x) + 0x10 ) >> 5 )
1249 CF2_Fixed denominator, s;
1252 u.x = CF2_CS_SCALE( SUB_INT32( u2->x, u1->x ) );
1253 u.y = CF2_CS_SCALE( SUB_INT32( u2->y, u1->y ) );
1254 v.x = CF2_CS_SCALE( SUB_INT32( v2->x, v1->x ) );
1255 v.y = CF2_CS_SCALE( SUB_INT32( v2->y, v1->y ) );
1256 w.x = CF2_CS_SCALE( SUB_INT32( v1->x, u1->x ) );
1257 w.y = CF2_CS_SCALE( SUB_INT32( v1->y, u1->y ) );
1259 denominator = cf2_perp( u, v );
1261 if ( denominator == 0 )
1264 s = FT_DivFix( cf2_perp( w, v ), denominator );
1266 intersection->x = ADD_INT32( u1->x,
1267 FT_MulFix( s, SUB_INT32( u2->x, u1->x ) ) );
1268 intersection->y = ADD_INT32( u1->y,
1269 FT_MulFix( s, SUB_INT32( u2->y, u1->y ) ) );
1281 if ( u1->x == u2->x &&
1282 cf2_fixedAbs( SUB_INT32( intersection->x,
1283 u1->x ) ) < glyphpath->snapThreshold )
1284 intersection->x = u1->x;
1285 if ( u1->y == u2->y &&
1286 cf2_fixedAbs( SUB_INT32( intersection->y,
1287 u1->y ) ) < glyphpath->snapThreshold )
1288 intersection->y = u1->y;
1290 if ( v1->x == v2->x &&
1291 cf2_fixedAbs( SUB_INT32( intersection->x,
1292 v1->x ) ) < glyphpath->snapThreshold )
1293 intersection->x = v1->x;
1294 if ( v1->y == v2->y &&
1295 cf2_fixedAbs( SUB_INT32( intersection->y,
1296 v1->y ) ) < glyphpath->snapThreshold )
1297 intersection->y = v1->y;
1300 if ( cf2_fixedAbs( intersection->x - ADD_INT32( u2->x, v1->x ) / 2 ) >
1301 glyphpath->miterLimit ||
1302 cf2_fixedAbs( intersection->y - ADD_INT32( u2->y, v1->y ) / 2 ) >
1303 glyphpath->miterLimit )
1334 cf2_glyphpath_pushPrevElem( CF2_GlyphPath glyphpath,
1335 CF2_HintMap hintmap,
1340 CF2_CallbackParamsRec params;
1345 FT_Vector intersection = { 0, 0 };
1346 FT_Bool useIntersection = FALSE;
1349 FT_ASSERT( glyphpath->prevElemOp == CF2_PathOpLineTo ||
1350 glyphpath->prevElemOp == CF2_PathOpCubeTo );
1352 if ( glyphpath->prevElemOp == CF2_PathOpLineTo )
1354 prevP0 = &glyphpath->prevElemP0;
1355 prevP1 = &glyphpath->prevElemP1;
1359 prevP0 = &glyphpath->prevElemP2;
1360 prevP1 = &glyphpath->prevElemP3;
1366 if ( prevP1->x != nextP0->x || prevP1->y != nextP0->y )
1370 useIntersection = cf2_glyphpath_computeIntersection( glyphpath,
1376 if ( useIntersection )
1380 *prevP1 = intersection;
1384 params.pt0 = glyphpath->currentDS;
1386 switch( glyphpath->prevElemOp )
1388 case CF2_PathOpLineTo:
1389 params.op = CF2_PathOpLineTo;
1396 cf2_glyphpath_hintPoint( glyphpath,
1397 &glyphpath->firstHintMap,
1399 glyphpath->prevElemP1.x,
1400 glyphpath->prevElemP1.y );
1404 cf2_glyphpath_hintPoint( glyphpath,
1407 glyphpath->prevElemP1.x,
1408 glyphpath->prevElemP1.y );
1412 if ( params.pt0.x != params.pt1.x || params.pt0.y != params.pt1.y )
1414 glyphpath->callbacks->lineTo( glyphpath->callbacks, ¶ms );
1416 glyphpath->currentDS = params.pt1;
1420 case CF2_PathOpCubeTo:
1421 params.op = CF2_PathOpCubeTo;
1424 cf2_glyphpath_hintPoint( glyphpath,
1427 glyphpath->prevElemP1.x,
1428 glyphpath->prevElemP1.y );
1429 cf2_glyphpath_hintPoint( glyphpath,
1432 glyphpath->prevElemP2.x,
1433 glyphpath->prevElemP2.y );
1434 cf2_glyphpath_hintPoint( glyphpath,
1437 glyphpath->prevElemP3.x,
1438 glyphpath->prevElemP3.y );
1440 glyphpath->callbacks->cubeTo( glyphpath->callbacks, ¶ms );
1442 glyphpath->currentDS = params.pt3;
1447 if ( !useIntersection || close )
1458 cf2_glyphpath_hintPoint( glyphpath,
1459 &glyphpath->firstHintMap,
1466 cf2_glyphpath_hintPoint( glyphpath,
1473 if ( params.pt1.x != glyphpath->currentDS.x ||
1474 params.pt1.y != glyphpath->currentDS.y )
1477 params.op = CF2_PathOpLineTo;
1478 params.pt0 = glyphpath->currentDS;
1481 glyphpath->callbacks->lineTo( glyphpath->callbacks, ¶ms );
1483 glyphpath->currentDS = params.pt1;
1487 if ( useIntersection )
1490 *nextP0 = intersection;
1498 cf2_glyphpath_pushMove( CF2_GlyphPath glyphpath,
1501 CF2_CallbackParamsRec params;
1504 params.op = CF2_PathOpMoveTo;
1505 params.pt0 = glyphpath->currentDS;
1509 if ( !cf2_hintmap_isValid( &glyphpath->hintMap ) )
1513 cf2_glyphpath_moveTo( glyphpath,
1515 glyphpath->start.y );
1518 cf2_glyphpath_hintPoint( glyphpath,
1519 &glyphpath->hintMap,
1525 glyphpath->callbacks->moveTo( glyphpath->callbacks, ¶ms );
1527 glyphpath->currentDS = params.pt1;
1528 glyphpath->offsetStart0 = start;
1543 cf2_glyphpath_computeOffset( CF2_GlyphPath glyphpath,
1551 CF2_Fixed dx = SUB_INT32( x2, x1 );
1552 CF2_Fixed dy = SUB_INT32( y2, y1 );
1557 if ( glyphpath->font->reverseWinding )
1559 dx = NEG_INT32( dx );
1560 dy = NEG_INT32( dy );
1565 if ( !glyphpath->darken )
1569 glyphpath->callbacks->windingMomentum =
1570 ADD_INT32( glyphpath->callbacks->windingMomentum,
1571 cf2_getWindingMomentum( x1, y1, x2, y2 ) );
1580 if ( dx > MUL_INT32( 2, dy ) )
1586 else if ( dy > MUL_INT32( 2, dx ) )
1589 *x = glyphpath->xOffset;
1590 *y = glyphpath->yOffset;
1595 *x = FT_MulFix( cf2_doubleToFixed( 0.7 ),
1596 glyphpath->xOffset );
1597 *y = FT_MulFix( cf2_doubleToFixed( 1.0 - 0.7 ),
1598 glyphpath->yOffset );
1605 if ( dx > MUL_INT32( -2, dy ) )
1611 else if ( NEG_INT32( dy ) > MUL_INT32( 2, dx ) )
1614 *x = NEG_INT32( glyphpath->xOffset );
1615 *y = glyphpath->yOffset;
1620 *x = FT_MulFix( cf2_doubleToFixed( -0.7 ),
1621 glyphpath->xOffset );
1622 *y = FT_MulFix( cf2_doubleToFixed( 1.0 - 0.7 ),
1623 glyphpath->yOffset );
1633 if ( NEG_INT32( dx ) > MUL_INT32( 2, dy ) )
1637 *y = MUL_INT32( 2, glyphpath->yOffset );
1639 else if ( dy > MUL_INT32( -2, dx ) )
1642 *x = glyphpath->xOffset;
1643 *y = glyphpath->yOffset;
1648 *x = FT_MulFix( cf2_doubleToFixed( 0.7 ),
1649 glyphpath->xOffset );
1650 *y = FT_MulFix( cf2_doubleToFixed( 1.0 + 0.7 ),
1651 glyphpath->yOffset );
1658 if ( NEG_INT32( dx ) > MUL_INT32( -2, dy ) )
1662 *y = MUL_INT32( 2, glyphpath->yOffset );
1664 else if ( NEG_INT32( dy ) > MUL_INT32( -2, dx ) )
1667 *x = NEG_INT32( glyphpath->xOffset );
1668 *y = glyphpath->yOffset;
1673 *x = FT_MulFix( cf2_doubleToFixed( -0.7 ),
1674 glyphpath->xOffset );
1675 *y = FT_MulFix( cf2_doubleToFixed( 1.0 + 0.7 ),
1676 glyphpath->yOffset );
1693 FT_LOCAL_DEF(
void )
1694 cf2_glyphpath_moveTo( CF2_GlyphPath glyphpath,
1698 cf2_glyphpath_closeOpenPath( glyphpath );
1703 glyphpath->currentCS.x = glyphpath->start.x = x;
1704 glyphpath->currentCS.y = glyphpath->start.y = y;
1706 glyphpath->moveIsPending = TRUE;
1709 if ( !cf2_hintmap_isValid( &glyphpath->hintMap ) ||
1710 cf2_hintmask_isNew( glyphpath->hintMask ) )
1711 cf2_hintmap_build( &glyphpath->hintMap,
1712 glyphpath->hStemHintArray,
1713 glyphpath->vStemHintArray,
1714 glyphpath->hintMask,
1715 glyphpath->hintOriginY,
1719 glyphpath->firstHintMap = glyphpath->hintMap;
1723 FT_LOCAL_DEF(
void )
1724 cf2_glyphpath_lineTo( CF2_GlyphPath glyphpath,
1728 CF2_Fixed xOffset, yOffset;
1740 newHintMap = cf2_hintmask_isNew( glyphpath->hintMask ) &&
1741 !glyphpath->pathIsClosing;
1760 if ( glyphpath->currentCS.x == x &&
1761 glyphpath->currentCS.y == y &&
1772 cf2_glyphpath_computeOffset( glyphpath,
1773 glyphpath->currentCS.x,
1774 glyphpath->currentCS.y,
1781 P0.x = ADD_INT32( glyphpath->currentCS.x, xOffset );
1782 P0.y = ADD_INT32( glyphpath->currentCS.y, yOffset );
1783 P1.x = ADD_INT32( x, xOffset );
1784 P1.y = ADD_INT32( y, yOffset );
1786 if ( glyphpath->moveIsPending )
1789 cf2_glyphpath_pushMove( glyphpath, P0 );
1791 glyphpath->moveIsPending = FALSE;
1792 glyphpath->pathIsOpen = TRUE;
1794 glyphpath->offsetStart1 = P1;
1797 if ( glyphpath->elemIsQueued )
1799 FT_ASSERT( cf2_hintmap_isValid( &glyphpath->hintMap ) ||
1800 glyphpath->hintMap.count == 0 );
1802 cf2_glyphpath_pushPrevElem( glyphpath,
1803 &glyphpath->hintMap,
1810 glyphpath->elemIsQueued = TRUE;
1811 glyphpath->prevElemOp = CF2_PathOpLineTo;
1812 glyphpath->prevElemP0 = P0;
1813 glyphpath->prevElemP1 = P1;
1817 cf2_hintmap_build( &glyphpath->hintMap,
1818 glyphpath->hStemHintArray,
1819 glyphpath->vStemHintArray,
1820 glyphpath->hintMask,
1821 glyphpath->hintOriginY,
1824 glyphpath->currentCS.x = x;
1825 glyphpath->currentCS.y = y;
1829 FT_LOCAL_DEF(
void )
1830 cf2_glyphpath_curveTo( CF2_GlyphPath glyphpath,
1838 CF2_Fixed xOffset1, yOffset1, xOffset3, yOffset3;
1839 FT_Vector P0, P1, P2, P3;
1843 cf2_glyphpath_computeOffset( glyphpath,
1844 glyphpath->currentCS.x,
1845 glyphpath->currentCS.y,
1850 cf2_glyphpath_computeOffset( glyphpath,
1859 glyphpath->callbacks->windingMomentum =
1860 ADD_INT32( glyphpath->callbacks->windingMomentum,
1861 cf2_getWindingMomentum( x1, y1, x2, y2 ) );
1864 P0.x = ADD_INT32( glyphpath->currentCS.x, xOffset1 );
1865 P0.y = ADD_INT32( glyphpath->currentCS.y, yOffset1 );
1866 P1.x = ADD_INT32( x1, xOffset1 );
1867 P1.y = ADD_INT32( y1, yOffset1 );
1869 P2.x = ADD_INT32( x2, xOffset3 );
1870 P2.y = ADD_INT32( y2, yOffset3 );
1871 P3.x = ADD_INT32( x3, xOffset3 );
1872 P3.y = ADD_INT32( y3, yOffset3 );
1874 if ( glyphpath->moveIsPending )
1877 cf2_glyphpath_pushMove( glyphpath, P0 );
1879 glyphpath->moveIsPending = FALSE;
1880 glyphpath->pathIsOpen = TRUE;
1882 glyphpath->offsetStart1 = P1;
1885 if ( glyphpath->elemIsQueued )
1887 FT_ASSERT( cf2_hintmap_isValid( &glyphpath->hintMap ) ||
1888 glyphpath->hintMap.count == 0 );
1890 cf2_glyphpath_pushPrevElem( glyphpath,
1891 &glyphpath->hintMap,
1898 glyphpath->elemIsQueued = TRUE;
1899 glyphpath->prevElemOp = CF2_PathOpCubeTo;
1900 glyphpath->prevElemP0 = P0;
1901 glyphpath->prevElemP1 = P1;
1902 glyphpath->prevElemP2 = P2;
1903 glyphpath->prevElemP3 = P3;
1906 if ( cf2_hintmask_isNew( glyphpath->hintMask ) )
1907 cf2_hintmap_build( &glyphpath->hintMap,
1908 glyphpath->hStemHintArray,
1909 glyphpath->vStemHintArray,
1910 glyphpath->hintMask,
1911 glyphpath->hintOriginY,
1914 glyphpath->currentCS.x = x3;
1915 glyphpath->currentCS.y = y3;
1919 FT_LOCAL_DEF(
void )
1920 cf2_glyphpath_closeOpenPath( CF2_GlyphPath glyphpath )
1922 if ( glyphpath->pathIsOpen )
1929 glyphpath->pathIsClosing = TRUE;
1931 cf2_glyphpath_lineTo( glyphpath,
1933 glyphpath->start.y );
1936 if ( glyphpath->elemIsQueued )
1937 cf2_glyphpath_pushPrevElem( glyphpath,
1938 &glyphpath->hintMap,
1939 &glyphpath->offsetStart0,
1940 glyphpath->offsetStart1,
1944 glyphpath->moveIsPending = TRUE;
1945 glyphpath->pathIsOpen = FALSE;
1946 glyphpath->pathIsClosing = FALSE;
1947 glyphpath->elemIsQueued = FALSE;