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

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

Issue 1413673003: Update bundled freetype to 2.6.1 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: DEPS for corpus Created 5 years, 1 month 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/ftstream.c ('k') | third_party/freetype/src/base/ftsynth.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 /* ftstroke.c */ 3 /* ftstroke.c */
4 /* */ 4 /* */
5 /* FreeType path stroker (body). */ 5 /* FreeType path stroker (body). */
6 /* */ 6 /* */
7 /* Copyright 2002-2006, 2008-2011, 2013, 2014 by */ 7 /* Copyright 2002-2015 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 #include <ft2build.h> 19 #include <ft2build.h>
20 #include FT_STROKER_H 20 #include FT_STROKER_H
21 #include FT_TRIGONOMETRY_H 21 #include FT_TRIGONOMETRY_H
22 #include FT_OUTLINE_H 22 #include FT_OUTLINE_H
23 #include FT_INTERNAL_MEMORY_H 23 #include FT_INTERNAL_MEMORY_H
24 #include FT_INTERNAL_DEBUG_H 24 #include FT_INTERNAL_DEBUG_H
25 #include FT_INTERNAL_OBJECTS_H 25 #include FT_INTERNAL_OBJECTS_H
26 26
27 #include "basepic.h"
28
29
30 /* declare an extern to access `ft_outline_glyph_class' globally */
31 /* allocated in `ftglyph.c', and use the FT_OUTLINE_GLYPH_CLASS_GET */
32 /* macro to access it when FT_CONFIG_OPTION_PIC is defined */
33 #ifndef FT_CONFIG_OPTION_PIC
34 FT_CALLBACK_TABLE const FT_Glyph_Class ft_outline_glyph_class;
35 #endif
36
27 37
28 /* documentation is in ftstroke.h */ 38 /* documentation is in ftstroke.h */
29 39
30 FT_EXPORT_DEF( FT_StrokerBorder ) 40 FT_EXPORT_DEF( FT_StrokerBorder )
31 FT_Outline_GetInsideBorder( FT_Outline* outline ) 41 FT_Outline_GetInsideBorder( FT_Outline* outline )
32 { 42 {
33 FT_Orientation o = FT_Outline_Get_Orientation( outline ); 43 FT_Orientation o = FT_Outline_Get_Orientation( outline );
34 44
35 45
36 return o == FT_ORIENTATION_TRUETYPE ? FT_STROKER_BORDER_RIGHT 46 return o == FT_ORIENTATION_TRUETYPE ? FT_STROKER_BORDER_RIGHT
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 350
341 Exit: 351 Exit:
342 return error; 352 return error;
343 } 353 }
344 354
345 355
346 static void 356 static void
347 ft_stroke_border_close( FT_StrokeBorder border, 357 ft_stroke_border_close( FT_StrokeBorder border,
348 FT_Bool reverse ) 358 FT_Bool reverse )
349 { 359 {
350 FT_UInt start = border->start; 360 FT_UInt start = (FT_UInt)border->start;
351 FT_UInt count = border->num_points; 361 FT_UInt count = border->num_points;
352 362
353 363
354 FT_ASSERT( border->start >= 0 ); 364 FT_ASSERT( border->start >= 0 );
355 365
356 /* don't record empty paths! */ 366 /* don't record empty paths! */
357 if ( count <= start + 1U ) 367 if ( count <= start + 1U )
358 border->num_points = start; 368 border->num_points = start;
359 else 369 else
360 { 370 {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 602
593 603
594 static FT_Error 604 static FT_Error
595 ft_stroke_border_moveto( FT_StrokeBorder border, 605 ft_stroke_border_moveto( FT_StrokeBorder border,
596 FT_Vector* to ) 606 FT_Vector* to )
597 { 607 {
598 /* close current open path if any ? */ 608 /* close current open path if any ? */
599 if ( border->start >= 0 ) 609 if ( border->start >= 0 )
600 ft_stroke_border_close( border, FALSE ); 610 ft_stroke_border_close( border, FALSE );
601 611
602 border->start = border->num_points; 612 border->start = (FT_Int)border->num_points;
603 border->movable = FALSE; 613 border->movable = FALSE;
604 614
605 return ft_stroke_border_lineto( border, to, FALSE ); 615 return ft_stroke_border_lineto( border, to, FALSE );
606 } 616 }
607 617
608 618
609 static void 619 static void
610 ft_stroke_border_init( FT_StrokeBorder border, 620 ft_stroke_border_init( FT_StrokeBorder border,
611 FT_Memory memory ) 621 FT_Memory memory )
612 { 622 {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 for ( ; count > 0; count--, tags++, idx++ ) 745 for ( ; count > 0; count--, tags++, idx++ )
736 { 746 {
737 if ( *tags & FT_STROKE_TAG_END ) 747 if ( *tags & FT_STROKE_TAG_END )
738 { 748 {
739 *write++ = idx; 749 *write++ = idx;
740 outline->n_contours++; 750 outline->n_contours++;
741 } 751 }
742 } 752 }
743 } 753 }
744 754
745 outline->n_points = (short)( outline->n_points + border->num_points ); 755 outline->n_points += (short)border->num_points;
746 756
747 FT_ASSERT( FT_Outline_Check( outline ) == 0 ); 757 FT_ASSERT( FT_Outline_Check( outline ) == 0 );
748 } 758 }
749 759
750 760
751 /*************************************************************************/ 761 /*************************************************************************/
752 /*************************************************************************/ 762 /*************************************************************************/
753 /***** *****/ 763 /***** *****/
754 /***** STROKER *****/ 764 /***** STROKER *****/
755 /***** *****/ 765 /***** *****/
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 { 837 {
828 if ( !stroker ) 838 if ( !stroker )
829 return; 839 return;
830 840
831 stroker->radius = radius; 841 stroker->radius = radius;
832 stroker->line_cap = line_cap; 842 stroker->line_cap = line_cap;
833 stroker->line_join = line_join; 843 stroker->line_join = line_join;
834 stroker->miter_limit = miter_limit; 844 stroker->miter_limit = miter_limit;
835 845
836 /* ensure miter limit has sensible value */ 846 /* ensure miter limit has sensible value */
837 if ( stroker->miter_limit < 0x10000 ) 847 if ( stroker->miter_limit < 0x10000L )
838 stroker->miter_limit = 0x10000; 848 stroker->miter_limit = 0x10000L;
839 849
840 /* save line join style: */ 850 /* save line join style: */
841 /* line join style can be temporarily changed when stroking curves */ 851 /* line join style can be temporarily changed when stroking curves */
842 stroker->line_join_saved = line_join; 852 stroker->line_join_saved = line_join;
843 853
844 FT_Stroker_Rewind( stroker ); 854 FT_Stroker_Rewind( stroker );
845 } 855 }
846 856
847 857
848 /* documentation is in ftstroke.h */ 858 /* documentation is in ftstroke.h */
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 FT_Error error = FT_Err_Ok; 1002 FT_Error error = FT_Err_Ok;
993 FT_Bool intersect; /* use intersection of lines? */ 1003 FT_Bool intersect; /* use intersection of lines? */
994 1004
995 1005
996 rotate = FT_SIDE_TO_ROTATE( side ); 1006 rotate = FT_SIDE_TO_ROTATE( side );
997 1007
998 theta = FT_Angle_Diff( stroker->angle_in, stroker->angle_out ) / 2; 1008 theta = FT_Angle_Diff( stroker->angle_in, stroker->angle_out ) / 2;
999 1009
1000 /* Only intersect borders if between two lineto's and both */ 1010 /* Only intersect borders if between two lineto's and both */
1001 /* lines are long enough (line_length is zero for curves). */ 1011 /* lines are long enough (line_length is zero for curves). */
1002 if ( !border->movable || line_length == 0 ) 1012 /* Also avoid U-turns of nearly 180 degree. */
1013 if ( !border->movable || line_length == 0 ||
1014 theta > 0x59C000 || theta < -0x59C000 )
1003 intersect = FALSE; 1015 intersect = FALSE;
1004 else 1016 else
1005 { 1017 {
1006 /* compute minimum required length of lines */ 1018 /* compute minimum required length of lines */
1007 FT_Fixed min_length = ft_pos_abs( FT_MulFix( stroker->radius, 1019 FT_Fixed min_length = ft_pos_abs( FT_MulFix( stroker->radius,
1008 FT_Tan( theta ) ) ); 1020 FT_Tan( theta ) ) );
1009 1021
1010 1022
1011 intersect = FT_BOOL( min_length && 1023 intersect = FT_BOOL( min_length &&
1012 stroker->line_length >= min_length && 1024 stroker->line_length >= min_length &&
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 FT_Int inside_side; 1225 FT_Int inside_side;
1214 1226
1215 1227
1216 turn = FT_Angle_Diff( stroker->angle_in, stroker->angle_out ); 1228 turn = FT_Angle_Diff( stroker->angle_in, stroker->angle_out );
1217 1229
1218 /* no specific corner processing is required if the turn is 0 */ 1230 /* no specific corner processing is required if the turn is 0 */
1219 if ( turn == 0 ) 1231 if ( turn == 0 )
1220 goto Exit; 1232 goto Exit;
1221 1233
1222 /* when we turn to the right, the inside side is 0 */ 1234 /* when we turn to the right, the inside side is 0 */
1223 inside_side = 0;
1224
1225 /* otherwise, the inside side is 1 */ 1235 /* otherwise, the inside side is 1 */
1226 if ( turn < 0 ) 1236 inside_side = ( turn < 0 );
1227 inside_side = 1;
1228 1237
1229 /* process the inside side */ 1238 /* process the inside side */
1230 error = ft_stroker_inside( stroker, inside_side, line_length ); 1239 error = ft_stroker_inside( stroker, inside_side, line_length );
1231 if ( error ) 1240 if ( error )
1232 goto Exit; 1241 goto Exit;
1233 1242
1234 /* process the outside side */ 1243 /* process the outside side */
1235 error = ft_stroker_outside( stroker, 1 - inside_side, line_length ); 1244 error = ft_stroker_outside( stroker, !inside_side, line_length );
1236 1245
1237 Exit: 1246 Exit:
1238 return error; 1247 return error;
1239 } 1248 }
1240 1249
1241 1250
1242 /* add two points to the left and right borders corresponding to the */ 1251 /* add two points to the left and right borders corresponding to the */
1243 /* start of the subpath */ 1252 /* start of the subpath */
1244 static FT_Error 1253 static FT_Error
1245 ft_stroker_subpath_start( FT_Stroker stroker, 1254 ft_stroker_subpath_start( FT_Stroker stroker,
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
1815 FT_Bool open ) 1824 FT_Bool open )
1816 { 1825 {
1817 FT_StrokeBorder right = stroker->borders + 0; 1826 FT_StrokeBorder right = stroker->borders + 0;
1818 FT_StrokeBorder left = stroker->borders + 1; 1827 FT_StrokeBorder left = stroker->borders + 1;
1819 FT_Int new_points; 1828 FT_Int new_points;
1820 FT_Error error = FT_Err_Ok; 1829 FT_Error error = FT_Err_Ok;
1821 1830
1822 1831
1823 FT_ASSERT( left->start >= 0 ); 1832 FT_ASSERT( left->start >= 0 );
1824 1833
1825 new_points = left->num_points - left->start; 1834 new_points = (FT_Int)left->num_points - left->start;
1826 if ( new_points > 0 ) 1835 if ( new_points > 0 )
1827 { 1836 {
1828 error = ft_stroke_border_grow( right, (FT_UInt)new_points ); 1837 error = ft_stroke_border_grow( right, (FT_UInt)new_points );
1829 if ( error ) 1838 if ( error )
1830 goto Exit; 1839 goto Exit;
1831 1840
1832 { 1841 {
1833 FT_Vector* dst_point = right->points + right->num_points; 1842 FT_Vector* dst_point = right->points + right->num_points;
1834 FT_Byte* dst_tag = right->tags + right->num_points; 1843 FT_Byte* dst_tag = right->tags + right->num_points;
1835 FT_Vector* src_point = left->points + left->num_points - 1; 1844 FT_Vector* src_point = left->points + left->num_points - 1;
(...skipping 19 matching lines...) Expand all
1855 dst_tag[0] ^= FT_STROKE_TAG_BEGIN_END; 1864 dst_tag[0] ^= FT_STROKE_TAG_BEGIN_END;
1856 } 1865 }
1857 1866
1858 src_point--; 1867 src_point--;
1859 src_tag--; 1868 src_tag--;
1860 dst_point++; 1869 dst_point++;
1861 dst_tag++; 1870 dst_tag++;
1862 } 1871 }
1863 } 1872 }
1864 1873
1865 left->num_points = left->start; 1874 left->num_points = (FT_UInt)left->start;
1866 right->num_points += new_points; 1875 right->num_points += (FT_UInt)new_points;
1867 1876
1868 right->movable = FALSE; 1877 right->movable = FALSE;
1869 left->movable = FALSE; 1878 left->movable = FALSE;
1870 } 1879 }
1871 1880
1872 Exit: 1881 Exit:
1873 return error; 1882 return error;
1874 } 1883 }
1875 1884
1876 1885
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 1943
1935 /* process the corner */ 1944 /* process the corner */
1936 stroker->angle_out = stroker->subpath_angle; 1945 stroker->angle_out = stroker->subpath_angle;
1937 turn = FT_Angle_Diff( stroker->angle_in, 1946 turn = FT_Angle_Diff( stroker->angle_in,
1938 stroker->angle_out ); 1947 stroker->angle_out );
1939 1948
1940 /* no specific corner processing is required if the turn is 0 */ 1949 /* no specific corner processing is required if the turn is 0 */
1941 if ( turn != 0 ) 1950 if ( turn != 0 )
1942 { 1951 {
1943 /* when we turn to the right, the inside side is 0 */ 1952 /* when we turn to the right, the inside side is 0 */
1944 inside_side = 0;
1945
1946 /* otherwise, the inside side is 1 */ 1953 /* otherwise, the inside side is 1 */
1947 if ( turn < 0 ) 1954 inside_side = ( turn < 0 );
1948 inside_side = 1;
1949 1955
1950 error = ft_stroker_inside( stroker, 1956 error = ft_stroker_inside( stroker,
1951 inside_side, 1957 inside_side,
1952 stroker->subpath_line_length ); 1958 stroker->subpath_line_length );
1953 if ( error ) 1959 if ( error )
1954 goto Exit; 1960 goto Exit;
1955 1961
1956 /* process the outside side */ 1962 /* process the outside side */
1957 error = ft_stroker_outside( stroker, 1963 error = ft_stroker_outside( stroker,
1958 1 - inside_side, 1964 !inside_side,
1959 stroker->subpath_line_length ); 1965 stroker->subpath_line_length );
1960 if ( error ) 1966 if ( error )
1961 goto Exit; 1967 goto Exit;
1962 } 1968 }
1963 1969
1964 /* then end our two subpaths */ 1970 /* then end our two subpaths */
1965 ft_stroke_border_close( stroker->borders + 0, FALSE ); 1971 ft_stroke_border_close( stroker->borders + 0, FALSE );
1966 ft_stroke_border_close( stroker->borders + 1, TRUE ); 1972 ft_stroke_border_close( stroker->borders + 1, TRUE );
1967 } 1973 }
1968 1974
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
2111 2117
2112 FT_Stroker_Rewind( stroker ); 2118 FT_Stroker_Rewind( stroker );
2113 2119
2114 first = 0; 2120 first = 0;
2115 2121
2116 for ( n = 0; n < outline->n_contours; n++ ) 2122 for ( n = 0; n < outline->n_contours; n++ )
2117 { 2123 {
2118 FT_UInt last; /* index of last point in contour */ 2124 FT_UInt last; /* index of last point in contour */
2119 2125
2120 2126
2121 last = outline->contours[n]; 2127 last = (FT_UInt)outline->contours[n];
2122 limit = outline->points + last; 2128 limit = outline->points + last;
2123 2129
2124 /* skip empty points; we don't stroke these */ 2130 /* skip empty points; we don't stroke these */
2125 if ( last <= first ) 2131 if ( last <= first )
2126 { 2132 {
2127 first = last + 1; 2133 first = last + 1;
2128 continue; 2134 continue;
2129 } 2135 }
2130 2136
2131 v_start = outline->points[first]; 2137 v_start = outline->points[first];
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2282 return FT_Err_Ok; 2288 return FT_Err_Ok;
2283 2289
2284 Exit: 2290 Exit:
2285 return error; 2291 return error;
2286 2292
2287 Invalid_Outline: 2293 Invalid_Outline:
2288 return FT_THROW( Invalid_Outline ); 2294 return FT_THROW( Invalid_Outline );
2289 } 2295 }
2290 2296
2291 2297
2292 /* declare an extern to access `ft_outline_glyph_class' globally */
2293 /* allocated in `ftglyph.c', and use the FT_OUTLINE_GLYPH_CLASS_GET */
2294 /* macro to access it when FT_CONFIG_OPTION_PIC is defined */
2295 #ifndef FT_CONFIG_OPTION_PIC
2296 extern const FT_Glyph_Class ft_outline_glyph_class;
2297 #endif
2298 #include "basepic.h"
2299
2300
2301 /* documentation is in ftstroke.h */ 2298 /* documentation is in ftstroke.h */
2302 2299
2303 FT_EXPORT_DEF( FT_Error ) 2300 FT_EXPORT_DEF( FT_Error )
2304 FT_Glyph_Stroke( FT_Glyph *pglyph, 2301 FT_Glyph_Stroke( FT_Glyph *pglyph,
2305 FT_Stroker stroker, 2302 FT_Stroker stroker,
2306 FT_Bool destroy ) 2303 FT_Bool destroy )
2307 { 2304 {
2308 FT_Error error = FT_ERR( Invalid_Argument ); 2305 FT_Error error = FT_ERR( Invalid_Argument );
2309 FT_Glyph glyph = NULL; 2306 FT_Glyph glyph = NULL;
2310 2307
(...skipping 29 matching lines...) Expand all
2340 2337
2341 error = FT_Stroker_ParseOutline( stroker, outline, FALSE ); 2338 error = FT_Stroker_ParseOutline( stroker, outline, FALSE );
2342 if ( error ) 2339 if ( error )
2343 goto Fail; 2340 goto Fail;
2344 2341
2345 FT_Stroker_GetCounts( stroker, &num_points, &num_contours ); 2342 FT_Stroker_GetCounts( stroker, &num_points, &num_contours );
2346 2343
2347 FT_Outline_Done( glyph->library, outline ); 2344 FT_Outline_Done( glyph->library, outline );
2348 2345
2349 error = FT_Outline_New( glyph->library, 2346 error = FT_Outline_New( glyph->library,
2350 num_points, num_contours, outline ); 2347 num_points,
2348 (FT_Int)num_contours,
2349 outline );
2351 if ( error ) 2350 if ( error )
2352 goto Fail; 2351 goto Fail;
2353 2352
2354 outline->n_points = 0; 2353 outline->n_points = 0;
2355 outline->n_contours = 0; 2354 outline->n_contours = 0;
2356 2355
2357 FT_Stroker_Export( stroker, outline ); 2356 FT_Stroker_Export( stroker, outline );
2358 } 2357 }
2359 2358
2360 if ( destroy ) 2359 if ( destroy )
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2430 if ( error ) 2429 if ( error )
2431 goto Fail; 2430 goto Fail;
2432 2431
2433 FT_Stroker_GetBorderCounts( stroker, border, 2432 FT_Stroker_GetBorderCounts( stroker, border,
2434 &num_points, &num_contours ); 2433 &num_points, &num_contours );
2435 2434
2436 FT_Outline_Done( glyph->library, outline ); 2435 FT_Outline_Done( glyph->library, outline );
2437 2436
2438 error = FT_Outline_New( glyph->library, 2437 error = FT_Outline_New( glyph->library,
2439 num_points, 2438 num_points,
2440 num_contours, 2439 (FT_Int)num_contours,
2441 outline ); 2440 outline );
2442 if ( error ) 2441 if ( error )
2443 goto Fail; 2442 goto Fail;
2444 2443
2445 outline->n_points = 0; 2444 outline->n_points = 0;
2446 outline->n_contours = 0; 2445 outline->n_contours = 0;
2447 2446
2448 FT_Stroker_ExportBorder( stroker, border, outline ); 2447 FT_Stroker_ExportBorder( stroker, border, outline );
2449 } 2448 }
2450 2449
2451 if ( destroy ) 2450 if ( destroy )
2452 FT_Done_Glyph( *pglyph ); 2451 FT_Done_Glyph( *pglyph );
2453 2452
2454 *pglyph = glyph; 2453 *pglyph = glyph;
2455 goto Exit; 2454 goto Exit;
2456 2455
2457 Fail: 2456 Fail:
2458 FT_Done_Glyph( glyph ); 2457 FT_Done_Glyph( glyph );
2459 glyph = NULL; 2458 glyph = NULL;
2460 2459
2461 if ( !destroy ) 2460 if ( !destroy )
2462 *pglyph = NULL; 2461 *pglyph = NULL;
2463 2462
2464 Exit: 2463 Exit:
2465 return error; 2464 return error;
2466 } 2465 }
2467 2466
2468 2467
2469 /* END */ 2468 /* END */
OLDNEW
« no previous file with comments | « third_party/freetype/src/base/ftstream.c ('k') | third_party/freetype/src/base/ftsynth.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698