freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Git][freetype/freetype][gsoc-anurag-2023] Add decompose logic


From: Anurag Thakur (@AdbhutDev)
Subject: [Git][freetype/freetype][gsoc-anurag-2023] Add decompose logic
Date: Thu, 31 Aug 2023 16:55:49 +0000

Anurag Thakur pushed to branch gsoc-anurag-2023 at FreeType / FreeType

Commits:

  • ebf1f327
    by Anurag Thakur at 2023-08-31T22:25:22+05:30
    Add decompose logic
    

1 changed file:

Changes:

  • src/base/ftobjs.c
    ... ... @@ -2542,6 +2542,147 @@
    2542 2542
       }
    
    2543 2543
     
    
    2544 2544
     
    
    2545
    +
    
    2546
    +
    
    2547
    +
    
    2548
    +  static FT_Error ft_decompose_outline(FT_GlyphSlot* slot){
    
    2549
    +    FT_Vector   v_last;
    
    2550
    +    FT_Vector   v_control;
    
    2551
    +    FT_Vector   v_start;
    
    2552
    +
    
    2553
    +    FT_Vector*  point;
    
    2554
    +    FT_Vector*  limit;
    
    2555
    +    char*       tags;
    
    2556
    +
    
    2557
    +    FT_Error    error;
    
    2558
    +
    
    2559
    +    FT_Int   n;         /* index of contour in outline     */
    
    2560
    +    FT_Int   first;     /* index of first point in contour */
    
    2561
    +    FT_Int   last;      /* index of last point in contour  */
    
    2562
    +
    
    2563
    +    FT_Int   tag;       /* current point's state           */
    
    2564
    +
    
    2565
    +    FT_Int   shift;
    
    2566
    +    FT_Pos   delta;
    
    2567
    +
    
    2568
    +    FT_Outline* outline = &(*slot)->outline;
    
    2569
    +
    
    2570
    +    if ( !outline )
    
    2571
    +      return FT_THROW( Invalid_Outline );
    
    2572
    +    
    
    2573
    +     for ( n = 0; n < outline->n_contours; n++ )
    
    2574
    +    {
    
    2575
    +      FT_TRACE5(( "FT_Outline_Decompose: Contour %d\n", n ));
    
    2576
    +
    
    2577
    +      first = last + 1;
    
    2578
    +      last  = outline->contours[n];
    
    2579
    +      if ( last < first ){
    
    2580
    +        FT_TRACE5(( "Invalid Outline"));
    
    2581
    +        break;
    
    2582
    +      }
    
    2583
    +      limit = outline->points + last;
    
    2584
    +
    
    2585
    +      v_start   = outline->points[first];
    
    2586
    +
    
    2587
    +
    
    2588
    +      v_last   = outline->points[last];
    
    2589
    +
    
    2590
    +      v_control = v_start;
    
    2591
    +
    
    2592
    +      point = outline->points + first;
    
    2593
    +      tags  = outline->tags   + first;
    
    2594
    +      tag   = FT_CURVE_TAG( tags[0] );
    
    2595
    +
    
    2596
    +      /* A contour cannot start with a cubic control point! */
    
    2597
    +      if ( tag == FT_CURVE_TAG_CUBIC )
    
    2598
    +      {
    
    2599
    +        FT_TRACE5(( "Invalid Outline"));
    
    2600
    +        break;
    
    2601
    +      }
    
    2602
    +      /* check first point to determine origin */
    
    2603
    +      if ( tag == FT_CURVE_TAG_CONIC )
    
    2604
    +      {
    
    2605
    +        /* first point is conic control.  Yes, this happens. */
    
    2606
    +        if ( FT_CURVE_TAG( outline->tags[last] ) == FT_CURVE_TAG_ON )
    
    2607
    +        {
    
    2608
    +          /* start at last point if it is on the curve */
    
    2609
    +          v_start = v_last;
    
    2610
    +          limit--;
    
    2611
    +        }
    
    2612
    +        else
    
    2613
    +        {
    
    2614
    +          /* if both first and last points are conic,         */
    
    2615
    +          /* start at their middle and record its position    */
    
    2616
    +          /* for closure                                      */
    
    2617
    +          v_start.x = ( v_start.x + v_last.x ) / 2;
    
    2618
    +          v_start.y = ( v_start.y + v_last.y ) / 2;
    
    2619
    +
    
    2620
    +       /* v_last = v_start; */
    
    2621
    +        }
    
    2622
    +        point--;
    
    2623
    +        tags--;
    
    2624
    +      }
    
    2625
    +
    
    2626
    +      FT_TRACE5(( "  move to (%.2f, %.2f)\n",
    
    2627
    +                  (double)v_start.x / 64, (double)v_start.y / 64 ));
    
    2628
    +     // error = func_interface->move_to( &v_start, user );
    
    2629
    +      // if ( error )
    
    2630
    +      //   goto Exit;
    
    2631
    +
    
    2632
    +      while ( point < limit )
    
    2633
    +      {
    
    2634
    +        point++;
    
    2635
    +        tags++;
    
    2636
    +
    
    2637
    +        tag = FT_CURVE_TAG( tags[0] );
    
    2638
    +        switch ( tag )
    
    2639
    +        {
    
    2640
    +        case FT_CURVE_TAG_ON:  /* emit a single line_to */
    
    2641
    +          {
    
    2642
    +            FT_Vector  vec;
    
    2643
    +
    
    2644
    +
    
    2645
    +            vec.x = SCALED( point->x );
    
    2646
    +            vec.y = SCALED( point->y );
    
    2647
    +
    
    2648
    +            FT_TRACE5(( "  line to (%.2f, %.2f)\n",
    
    2649
    +                        (double)vec.x / 64, (double)vec.y / 64 ));
    
    2650
    +            //error = func_interface->line_to( &vec, user );
    
    2651
    +            FT_PreLine pl  = malloc(sizeof(FT_PreLineRec));
    
    2652
    +            pl->x1 = v_last.x;
    
    2653
    +            pl->y1 = v_last.y;
    
    2654
    +            pl->x2 = vec.x;
    
    2655
    +            pl->y2 = vec.y;
    
    2656
    +            pl->next = NULL;
    
    2657
    +            (*slot)->prelines->next = pl;
    
    2658
    +            continue;
    
    2659
    +          }
    
    2660
    +
    
    2661
    +        }
    
    2662
    +      }
    
    2663
    +
    
    2664
    +      // /* close the contour with a line segment */
    
    2665
    +      // FT_TRACE5(( "  line to (%.2f, %.2f)\n",
    
    2666
    +      //             (double)v_start.x / 64, (double)v_start.y / 64 ));
    
    2667
    +      // error = func_interface->line_to( &v_start, user );
    
    2668
    +      
    
    2669
    +    }
    
    2670
    +
    
    2671
    +      return 0;
    
    2672
    +
    
    2673
    +  }
    
    2674
    +
    
    2675
    +
    
    2676
    +
    
    2677
    +
    
    2678
    +
    
    2679
    +
    
    2680
    +
    
    2681
    +
    
    2682
    +
    
    2683
    +
    
    2684
    +
    
    2685
    +
    
    2545 2686
       static FT_Error
    
    2546 2687
       ft_open_face_internal( FT_Library           library,
    
    2547 2688
                              const FT_Open_Args*  args,
    
    ... ... @@ -2813,6 +2954,8 @@
    2813 2954
             pl->y2 = 3;
    
    2814 2955
             pl->next = NULL;
    
    2815 2956
     
    
    2957
    +        ft_decompose_outline(face->garray[gindex]);
    
    2958
    +
    
    2816 2959
     
    
    2817 2960
           }
    
    2818 2961
     
    


  • reply via email to

    [Prev in Thread] Current Thread [Next in Thread]