Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: third_party/freetype/src/base/ftoutln.c

Issue 815103002: Update freetype to 2.5.4. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Adjust GYP and GN Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/freetype/src/base/ftotval.c ('k') | third_party/freetype/src/base/ftpatent.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /***************************************************************************/ 1 /***************************************************************************/
2 /* */ 2 /* */
3 /* ftoutln.c */ 3 /* ftoutln.c */
4 /* */ 4 /* */
5 /* FreeType outline management (body). */ 5 /* FreeType outline management (body). */
6 /* */ 6 /* */
7 /* Copyright 1996-2008, 2010, 2012-2013 by */ 7 /* Copyright 1996-2008, 2010, 2012-2014 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */ 9 /* */
10 /* This file is part of the FreeType project, and may only be used, */ 10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */ 11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */ 13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */ 14 /* understand and accept it fully. */
15 /* */ 15 /* */
16 /***************************************************************************/ 16 /***************************************************************************/
17 17
18 18
19 /*************************************************************************/ 19 /*************************************************************************/
20 /* */ 20 /* */
21 /* All functions are declared in freetype.h. */ 21 /* All functions are declared in freetype.h. */
22 /* */ 22 /* */
23 /*************************************************************************/ 23 /*************************************************************************/
24 24
25 25
26 #include "../../include/ft2build.h" 26 #include <ft2build.h>
27 #include "../../include/freetype/ftoutln.h" 27 #include FT_OUTLINE_H
28 #include "../../include/freetype/internal/ftobjs.h" 28 #include FT_INTERNAL_OBJECTS_H
29 #include "../../include/freetype/internal/ftcalc.h" 29 #include FT_INTERNAL_CALC_H
30 #include "../../include/freetype/internal/ftdebug.h" 30 #include FT_INTERNAL_DEBUG_H
31 #include "../../include/freetype/fttrigon.h" 31 #include FT_TRIGONOMETRY_H
32 32
33 33
34 /*************************************************************************/ 34 /*************************************************************************/
35 /* */ 35 /* */
36 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ 36 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
37 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ 37 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
38 /* messages during execution. */ 38 /* messages during execution. */
39 /* */ 39 /* */
40 #undef FT_COMPONENT 40 #undef FT_COMPONENT
41 #define FT_COMPONENT trace_outline 41 #define FT_COMPONENT trace_outline
(...skipping 24 matching lines...) Expand all
66 FT_Error error; 66 FT_Error error;
67 67
68 FT_Int n; /* index of contour in outline */ 68 FT_Int n; /* index of contour in outline */
69 FT_UInt first; /* index of first point in contour */ 69 FT_UInt first; /* index of first point in contour */
70 FT_Int tag; /* current point's state */ 70 FT_Int tag; /* current point's state */
71 71
72 FT_Int shift; 72 FT_Int shift;
73 FT_Pos delta; 73 FT_Pos delta;
74 74
75 75
76 if ( !outline || !func_interface ) 76 if ( !outline )
77 return FT_THROW( Invalid_Outline );
78
79 if ( !func_interface )
77 return FT_THROW( Invalid_Argument ); 80 return FT_THROW( Invalid_Argument );
78 81
79 shift = func_interface->shift; 82 shift = func_interface->shift;
80 delta = func_interface->delta; 83 delta = func_interface->delta;
81 first = 0; 84 first = 0;
82 85
83 for ( n = 0; n < outline->n_contours; n++ ) 86 for ( n = 0; n < outline->n_contours; n++ )
84 { 87 {
85 FT_Int last; /* index of last point in contour */ 88 FT_Int last; /* index of last point in contour */
86 89
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 limit--; 124 limit--;
122 } 125 }
123 else 126 else
124 { 127 {
125 /* if both first and last points are conic, */ 128 /* if both first and last points are conic, */
126 /* start at their middle and record its position */ 129 /* start at their middle and record its position */
127 /* for closure */ 130 /* for closure */
128 v_start.x = ( v_start.x + v_last.x ) / 2; 131 v_start.x = ( v_start.x + v_last.x ) / 2;
129 v_start.y = ( v_start.y + v_last.y ) / 2; 132 v_start.y = ( v_start.y + v_last.y ) / 2;
130 133
131 v_last = v_start; 134 /* v_last = v_start; */
132 } 135 }
133 point--; 136 point--;
134 tags--; 137 tags--;
135 } 138 }
136 139
137 FT_TRACE5(( " move to (%.2f, %.2f)\n", 140 FT_TRACE5(( " move to (%.2f, %.2f)\n",
138 v_start.x / 64.0, v_start.y / 64.0 )); 141 v_start.x / 64.0, v_start.y / 64.0 ));
139 error = func_interface->move_to( &v_start, user ); 142 error = func_interface->move_to( &v_start, user );
140 if ( error ) 143 if ( error )
141 goto Exit; 144 goto Exit;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 if ( outline ) 358 if ( outline )
356 { 359 {
357 FT_Int n_points = outline->n_points; 360 FT_Int n_points = outline->n_points;
358 FT_Int n_contours = outline->n_contours; 361 FT_Int n_contours = outline->n_contours;
359 FT_Int end0, end; 362 FT_Int end0, end;
360 FT_Int n; 363 FT_Int n;
361 364
362 365
363 /* empty glyph? */ 366 /* empty glyph? */
364 if ( n_points == 0 && n_contours == 0 ) 367 if ( n_points == 0 && n_contours == 0 )
365 return 0; 368 return FT_Err_Ok;
366 369
367 /* check point and contour counts */ 370 /* check point and contour counts */
368 if ( n_points <= 0 || n_contours <= 0 ) 371 if ( n_points <= 0 || n_contours <= 0 )
369 goto Bad; 372 goto Bad;
370 373
371 end0 = end = -1; 374 end0 = end = -1;
372 for ( n = 0; n < n_contours; n++ ) 375 for ( n = 0; n < n_contours; n++ )
373 { 376 {
374 end = outline->contours[n]; 377 end = outline->contours[n];
375 378
376 /* note that we don't accept empty contours */ 379 /* note that we don't accept empty contours */
377 if ( end <= end0 || end >= n_points ) 380 if ( end <= end0 || end >= n_points )
378 goto Bad; 381 goto Bad;
379 382
380 end0 = end; 383 end0 = end;
381 } 384 }
382 385
383 if ( end != n_points - 1 ) 386 if ( end != n_points - 1 )
384 goto Bad; 387 goto Bad;
385 388
386 /* XXX: check the tags array */ 389 /* XXX: check the tags array */
387 return 0; 390 return FT_Err_Ok;
388 } 391 }
389 392
390 Bad: 393 Bad:
391 return FT_THROW( Invalid_Argument ); 394 return FT_THROW( Invalid_Argument );
392 } 395 }
393 396
394 397
395 /* documentation is in ftoutln.h */ 398 /* documentation is in ftoutln.h */
396 399
397 FT_EXPORT_DEF( FT_Error ) 400 FT_EXPORT_DEF( FT_Error )
398 FT_Outline_Copy( const FT_Outline* source, 401 FT_Outline_Copy( const FT_Outline* source,
399 FT_Outline *target ) 402 FT_Outline *target )
400 { 403 {
401 FT_Int is_owner; 404 FT_Int is_owner;
402 405
403 406
404 if ( !source || !target || 407 if ( !source || !target )
405 source->n_points != target->n_points || 408 return FT_THROW( Invalid_Outline );
409
410 if ( source->n_points != target->n_points ||
406 source->n_contours != target->n_contours ) 411 source->n_contours != target->n_contours )
407 return FT_THROW( Invalid_Argument ); 412 return FT_THROW( Invalid_Argument );
408 413
409 if ( source == target ) 414 if ( source == target )
410 return FT_Err_Ok; 415 return FT_Err_Ok;
411 416
412 FT_ARRAY_COPY( target->points, source->points, source->n_points ); 417 FT_ARRAY_COPY( target->points, source->points, source->n_points );
413 418
414 FT_ARRAY_COPY( target->tags, source->tags, source->n_points ); 419 FT_ARRAY_COPY( target->tags, source->tags, source->n_points );
415 420
416 FT_ARRAY_COPY( target->contours, source->contours, source->n_contours ); 421 FT_ARRAY_COPY( target->contours, source->contours, source->n_contours );
417 422
418 /* copy all flags, except the `FT_OUTLINE_OWNER' one */ 423 /* copy all flags, except the `FT_OUTLINE_OWNER' one */
419 is_owner = target->flags & FT_OUTLINE_OWNER; 424 is_owner = target->flags & FT_OUTLINE_OWNER;
420 target->flags = source->flags; 425 target->flags = source->flags;
421 426
422 target->flags &= ~FT_OUTLINE_OWNER; 427 target->flags &= ~FT_OUTLINE_OWNER;
423 target->flags |= is_owner; 428 target->flags |= is_owner;
424 429
425 return FT_Err_Ok; 430 return FT_Err_Ok;
426 } 431 }
427 432
428 433
429 FT_EXPORT_DEF( FT_Error ) 434 FT_EXPORT_DEF( FT_Error )
430 FT_Outline_Done_Internal( FT_Memory memory, 435 FT_Outline_Done_Internal( FT_Memory memory,
431 FT_Outline* outline ) 436 FT_Outline* outline )
432 { 437 {
433 if ( memory && outline ) 438 if ( !outline )
439 return FT_THROW( Invalid_Outline );
440
441 if ( !memory )
442 return FT_THROW( Invalid_Argument );
443
444 if ( outline->flags & FT_OUTLINE_OWNER )
434 { 445 {
435 if ( outline->flags & FT_OUTLINE_OWNER ) 446 FT_FREE( outline->points );
436 { 447 FT_FREE( outline->tags );
437 FT_FREE( outline->points ); 448 FT_FREE( outline->contours );
438 FT_FREE( outline->tags ); 449 }
439 FT_FREE( outline->contours ); 450 *outline = null_outline;
440 }
441 *outline = null_outline;
442 451
443 return FT_Err_Ok; 452 return FT_Err_Ok;
444 }
445 else
446 return FT_THROW( Invalid_Argument );
447 } 453 }
448 454
449 455
450 /* documentation is in ftoutln.h */ 456 /* documentation is in ftoutln.h */
451 457
452 FT_EXPORT_DEF( FT_Error ) 458 FT_EXPORT_DEF( FT_Error )
453 FT_Outline_Done( FT_Library library, 459 FT_Outline_Done( FT_Library library,
454 FT_Outline* outline ) 460 FT_Outline* outline )
455 { 461 {
456 /* check for valid `outline' in FT_Outline_Done_Internal() */ 462 /* check for valid `outline' in FT_Outline_Done_Internal() */
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 *q = swap; 575 *q = swap;
570 p++; 576 p++;
571 q--; 577 q--;
572 } 578 }
573 } 579 }
574 580
575 /* reverse tags table */ 581 /* reverse tags table */
576 { 582 {
577 char* p = outline->tags + first; 583 char* p = outline->tags + first;
578 char* q = outline->tags + last; 584 char* q = outline->tags + last;
579 char swap;
580 585
581 586
582 while ( p < q ) 587 while ( p < q )
583 { 588 {
589 char swap;
590
591
584 swap = *p; 592 swap = *p;
585 *p = *q; 593 *p = *q;
586 *q = swap; 594 *q = swap;
587 p++; 595 p++;
588 q--; 596 q--;
589 } 597 }
590 } 598 }
591 599
592 first = last + 1; 600 first = last + 1;
593 } 601 }
(...skipping 11 matching lines...) Expand all
605 { 613 {
606 FT_Error error; 614 FT_Error error;
607 FT_Bool update = FALSE; 615 FT_Bool update = FALSE;
608 FT_Renderer renderer; 616 FT_Renderer renderer;
609 FT_ListNode node; 617 FT_ListNode node;
610 618
611 619
612 if ( !library ) 620 if ( !library )
613 return FT_THROW( Invalid_Library_Handle ); 621 return FT_THROW( Invalid_Library_Handle );
614 622
615 if ( !outline || !params ) 623 if ( !outline )
624 return FT_THROW( Invalid_Outline );
625
626 if ( !params )
616 return FT_THROW( Invalid_Argument ); 627 return FT_THROW( Invalid_Argument );
617 628
618 renderer = library->cur_renderer; 629 renderer = library->cur_renderer;
619 node = library->renderers.head; 630 node = library->renderers.head;
620 631
621 params->source = (void*)outline; 632 params->source = (void*)outline;
622 633
623 error = FT_ERR( Cannot_Render_Glyph ); 634 error = FT_ERR( Cannot_Render_Glyph );
624 while ( renderer ) 635 while ( renderer )
625 { 636 {
626 error = renderer->raster_render( renderer->raster, params ); 637 error = renderer->raster_render( renderer->raster, params );
627 if ( !error || FT_ERR_NEQ( error, Cannot_Render_Glyph ) ) 638 if ( !error || FT_ERR_NEQ( error, Cannot_Render_Glyph ) )
628 break; 639 break;
629 640
630 /* FT_Err_Cannot_Render_Glyph is returned if the render mode */ 641 /* FT_Err_Cannot_Render_Glyph is returned if the render mode */
631 /* is unsupported by the current renderer for this glyph image */ 642 /* is unsupported by the current renderer for this glyph image */
632 /* format */ 643 /* format */
633 644
634 /* now, look for another renderer that supports the same */ 645 /* now, look for another renderer that supports the same */
635 /* format */ 646 /* format */
636 renderer = FT_Lookup_Renderer( library, FT_GLYPH_FORMAT_OUTLINE, 647 renderer = FT_Lookup_Renderer( library, FT_GLYPH_FORMAT_OUTLINE,
637 &node ); 648 &node );
638 update = TRUE; 649 update = TRUE;
639 } 650 }
640 651
641 /* if we changed the current renderer for the glyph image format */ 652 /* if we changed the current renderer for the glyph image format */
642 /* we need to select it as the next current one */ 653 /* we need to select it as the next current one */
643 if ( !error && update && renderer ) 654 if ( !error && update && renderer )
644 FT_Set_Renderer( library, renderer, 0, 0 ); 655 error = FT_Set_Renderer( library, renderer, 0, 0 );
645 656
646 return error; 657 return error;
647 } 658 }
648 659
649 660
650 /* documentation is in ftoutln.h */ 661 /* documentation is in ftoutln.h */
651 662
652 FT_EXPORT_DEF( FT_Error ) 663 FT_EXPORT_DEF( FT_Error )
653 FT_Outline_Get_Bitmap( FT_Library library, 664 FT_Outline_Get_Bitmap( FT_Library library,
654 FT_Outline* outline, 665 FT_Outline* outline,
655 const FT_Bitmap *abitmap ) 666 const FT_Bitmap *abitmap )
656 { 667 {
657 FT_Raster_Params params; 668 FT_Raster_Params params;
658 669
659 670
660 if ( !abitmap ) 671 if ( !abitmap )
661 return FT_THROW( Invalid_Argument ); 672 return FT_THROW( Invalid_Argument );
662 673
663 /* other checks are delayed to FT_Outline_Render() */ 674 /* other checks are delayed to `FT_Outline_Render' */
664 675
665 params.target = abitmap; 676 params.target = abitmap;
666 params.flags = 0; 677 params.flags = 0;
667 678
668 if ( abitmap->pixel_mode == FT_PIXEL_MODE_GRAY || 679 if ( abitmap->pixel_mode == FT_PIXEL_MODE_GRAY ||
669 abitmap->pixel_mode == FT_PIXEL_MODE_LCD || 680 abitmap->pixel_mode == FT_PIXEL_MODE_LCD ||
670 abitmap->pixel_mode == FT_PIXEL_MODE_LCD_V ) 681 abitmap->pixel_mode == FT_PIXEL_MODE_LCD_V )
671 params.flags |= FT_RASTER_FLAG_AA; 682 params.flags |= FT_RASTER_FLAG_AA;
672 683
673 return FT_Outline_Render( library, outline, &params ); 684 return FT_Outline_Render( library, outline, &params );
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 limit = vec + outline->n_points; 725 limit = vec + outline->n_points;
715 726
716 for ( ; vec < limit; vec++ ) 727 for ( ; vec < limit; vec++ )
717 FT_Vector_Transform( vec, matrix ); 728 FT_Vector_Transform( vec, matrix );
718 } 729 }
719 730
720 731
721 #if 0 732 #if 0
722 733
723 #define FT_OUTLINE_GET_CONTOUR( outline, c, first, last ) \ 734 #define FT_OUTLINE_GET_CONTOUR( outline, c, first, last ) \
724 do { \ 735 do \
736 { \
725 (first) = ( c > 0 ) ? (outline)->points + \ 737 (first) = ( c > 0 ) ? (outline)->points + \
726 (outline)->contours[c - 1] + 1 \ 738 (outline)->contours[c - 1] + 1 \
727 : (outline)->points; \ 739 : (outline)->points; \
728 (last) = (outline)->points + (outline)->contours[c]; \ 740 (last) = (outline)->points + (outline)->contours[c]; \
729 } while ( 0 ) 741 } while ( 0 )
730 742
731 743
732 /* Is a point in some contour? */ 744 /* Is a point in some contour? */
733 /* */ 745 /* */
734 /* We treat every point of the contour as if it */ 746 /* We treat every point of the contour as if it */
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 FT_Pos xstrength, 913 FT_Pos xstrength,
902 FT_Pos ystrength ) 914 FT_Pos ystrength )
903 { 915 {
904 FT_Vector* points; 916 FT_Vector* points;
905 FT_Vector v_prev, v_first, v_next, v_cur; 917 FT_Vector v_prev, v_first, v_next, v_cur;
906 FT_Int c, n, first; 918 FT_Int c, n, first;
907 FT_Int orientation; 919 FT_Int orientation;
908 920
909 921
910 if ( !outline ) 922 if ( !outline )
911 return FT_THROW( Invalid_Argument ); 923 return FT_THROW( Invalid_Outline );
912 924
913 xstrength /= 2; 925 xstrength /= 2;
914 ystrength /= 2; 926 ystrength /= 2;
915 if ( xstrength == 0 && ystrength == 0 ) 927 if ( xstrength == 0 && ystrength == 0 )
916 return FT_Err_Ok; 928 return FT_Err_Ok;
917 929
918 orientation = FT_Outline_Get_Orientation( outline ); 930 orientation = FT_Outline_Get_Orientation( outline );
919 if ( orientation == FT_ORIENTATION_NONE ) 931 if ( orientation == FT_ORIENTATION_NONE )
920 { 932 {
921 if ( outline->n_contours ) 933 if ( outline->n_contours )
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 if ( !outline || outline->n_points <= 0 ) 1047 if ( !outline || outline->n_points <= 0 )
1036 return FT_ORIENTATION_TRUETYPE; 1048 return FT_ORIENTATION_TRUETYPE;
1037 1049
1038 /* We use the nonzero winding rule to find the orientation. */ 1050 /* We use the nonzero winding rule to find the orientation. */
1039 /* Since glyph outlines behave much more `regular' than arbitrary */ 1051 /* Since glyph outlines behave much more `regular' than arbitrary */
1040 /* cubic or quadratic curves, this test deals with the polygon */ 1052 /* cubic or quadratic curves, this test deals with the polygon */
1041 /* only which is spanned up by the control points. */ 1053 /* only which is spanned up by the control points. */
1042 1054
1043 FT_Outline_Get_CBox( outline, &cbox ); 1055 FT_Outline_Get_CBox( outline, &cbox );
1044 1056
1057 /* Handle collapsed outlines to avoid undefined FT_MSB. */
1058 if ( cbox.xMin == cbox.xMax || cbox.yMin == cbox.yMax )
1059 return FT_ORIENTATION_NONE;
1060
1045 xshift = FT_MSB( FT_ABS( cbox.xMax ) | FT_ABS( cbox.xMin ) ) - 14; 1061 xshift = FT_MSB( FT_ABS( cbox.xMax ) | FT_ABS( cbox.xMin ) ) - 14;
1046 xshift = FT_MAX( xshift, 0 ); 1062 xshift = FT_MAX( xshift, 0 );
1047 1063
1048 yshift = FT_MSB( cbox.yMax - cbox.yMin ) - 14; 1064 yshift = FT_MSB( cbox.yMax - cbox.yMin ) - 14;
1049 yshift = FT_MAX( yshift, 0 ); 1065 yshift = FT_MAX( yshift, 0 );
1050 1066
1051 points = outline->points; 1067 points = outline->points;
1052 1068
1053 first = 0; 1069 first = 0;
1054 for ( c = 0; c < outline->n_contours; c++ ) 1070 for ( c = 0; c < outline->n_contours; c++ )
(...skipping 17 matching lines...) Expand all
1072 if ( area > 0 ) 1088 if ( area > 0 )
1073 return FT_ORIENTATION_POSTSCRIPT; 1089 return FT_ORIENTATION_POSTSCRIPT;
1074 else if ( area < 0 ) 1090 else if ( area < 0 )
1075 return FT_ORIENTATION_TRUETYPE; 1091 return FT_ORIENTATION_TRUETYPE;
1076 else 1092 else
1077 return FT_ORIENTATION_NONE; 1093 return FT_ORIENTATION_NONE;
1078 } 1094 }
1079 1095
1080 1096
1081 /* END */ 1097 /* END */
OLDNEW
« no previous file with comments | « third_party/freetype/src/base/ftotval.c ('k') | third_party/freetype/src/base/ftpatent.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698