lottie/vector: extend freetype stroker to provide the contour open flag for each... 61/193261/2
authorsub.mohanty@samsung.com <smohantty@gmail.com>
Fri, 16 Nov 2018 12:38:30 +0000 (21:38 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Mon, 19 Nov 2018 00:31:39 +0000 (09:31 +0900)
Change-Id: Ibe4f8e4f45c90f5b03fd528c460e040fef13b375

src/vector/freetype/v_ft_raster.h
src/vector/freetype/v_ft_stroker.cpp
src/vector/freetype/v_ft_stroker.h
src/vector/vraster.cpp

index e67f480..aad2a8a 100644 (file)
@@ -120,6 +120,7 @@ typedef struct  SW_FT_Outline_
   SW_FT_Vector*  points;          /* the outline's points               */
   char*       tags;            /* the points flags                   */
   short*      contours;        /* the contour end points             */
+  char*       contours_flag;   /* the contour open flags             */
 
   int         flags;           /* outline masks                      */
 
index 7192d53..2a85707 100644 (file)
@@ -1741,8 +1741,7 @@ void SW_FT_Stroker_Export(SW_FT_Stroker stroker, SW_FT_Outline* outline)
  *  that we do support opened paths, and do not scale the outline.
  */
 SW_FT_Error SW_FT_Stroker_ParseOutline(SW_FT_Stroker        stroker,
-                                       const SW_FT_Outline* outline,
-                                       SW_FT_Bool           opened)
+                                       const SW_FT_Outline* outline)
 {
     SW_FT_Vector v_last;
     SW_FT_Vector v_control;
@@ -1805,7 +1804,7 @@ SW_FT_Error SW_FT_Stroker_ParseOutline(SW_FT_Stroker        stroker,
             tags--;
         }
 
-        error = SW_FT_Stroker_BeginSubPath(stroker, &v_start, opened);
+        error = SW_FT_Stroker_BeginSubPath(stroker, &v_start, outline->contours_flag[n]);
         if (error) goto Exit;
 
         while (point < limit) {
index d2b54e4..1514cf3 100644 (file)
    *   outline ::
    *     The source outline.
    *
-   *   opened ::
-   *     A boolean.  If~1, the outline is treated as an open path instead
-   *     of a closed one.
    *
    * @return:
    *   FreeType error code.  0~means success.
    *   If `opened' is~0 (the default), the outline is treated as a closed
    *   path, and the stroker generates two distinct `border' outlines.
    *
-   *   If `opened' is~1, the outline is processed as an open path, and the
-   *   stroker generates a single `stroke' outline.
    *
    *   This function calls @SW_FT_Stroker_Rewind automatically.
    */
   SW_FT_Error
   SW_FT_Stroker_ParseOutline( SW_FT_Stroker   stroker,
-                             const SW_FT_Outline*  outline,
-                             SW_FT_Bool      opened );
+                             const SW_FT_Outline*  outline);
 
 
   /**************************************************************
index b5e58f4..11015a3 100644 (file)
@@ -17,7 +17,10 @@ public:
     {
         if (mPointSize) delete[] ft.points;
         if (mTagSize) delete[] ft.tags;
-        if (mSegmentSize) delete[] ft.contours;
+        if (mSegmentSize) {
+            delete[] ft.contours;
+            delete[] ft.contours_flag;
+        }
     }
     void reset();
     void grow(int, int);
@@ -38,7 +41,6 @@ public:
     SW_FT_Stroker_LineJoin ftJoin;
     SW_FT_Fixed            ftWidth;
     SW_FT_Fixed            ftMeterLimit;
-    SW_FT_Bool             ftClosed;
 };
 
 void FTOutline::reset()
@@ -62,8 +64,12 @@ void FTOutline::grow(int points, int segments)
     }
 
     if (segment_size > mSegmentSize) {
-        if (mSegmentSize) delete [] ft.contours;
+        if (mSegmentSize) {
+            delete [] ft.contours;
+            delete [] ft.contours_flag;
+        }
         ft.contours = new short[segment_size];
+        ft.contours_flag = new char[segment_size];
         mSegmentSize = segment_size;
     }
 
@@ -109,8 +115,6 @@ void FTOutline::convert(const VPath &path)
 void FTOutline::convert(CapStyle cap, JoinStyle join, float width,
                         float meterLimit)
 {
-    ftClosed = (SW_FT_Bool)closed;
-
     // map strokeWidth to freetype. It uses as the radius of the pen not the
     // diameter
     width = width / 2.0;
@@ -156,8 +160,11 @@ void FTOutline::moveTo(const VPointF &pt)
         ft.contours[ft.n_contours] = ft.n_points - 1;
         ft.n_contours++;
     }
+    // mark the current contour as open
+    // will be updated if ther is a close tag at the end.
+    ft.contours_flag[ft.n_contours] = 1;
+
     ft.n_points++;
-    closed = false;
 }
 
 void FTOutline::lineTo(const VPointF &pt)
@@ -166,7 +173,6 @@ void FTOutline::lineTo(const VPointF &pt)
     ft.points[ft.n_points].y = TO_FT_COORD(pt.y());
     ft.tags[ft.n_points] = SW_FT_CURVE_TAG_ON;
     ft.n_points++;
-    closed = false;
 }
 
 void FTOutline::cubicTo(const VPointF &cp1, const VPointF &cp2,
@@ -186,10 +192,12 @@ void FTOutline::cubicTo(const VPointF &cp1, const VPointF &cp2,
     ft.points[ft.n_points].y = TO_FT_COORD(ep.y());
     ft.tags[ft.n_points] = SW_FT_CURVE_TAG_ON;
     ft.n_points++;
-    closed = false;
 }
 void FTOutline::close()
 {
+    // mark the contour as a close path.
+    ft.contours_flag[ft.n_contours] = 0;
+
     int index;
     if (ft.n_contours) {
         index = ft.contours[ft.n_contours - 1] + 1;
@@ -207,7 +215,6 @@ void FTOutline::close()
     ft.points[ft.n_points].y = ft.points[index].y;
     ft.tags[ft.n_points] = SW_FT_CURVE_TAG_ON;
     ft.n_points++;
-    closed = true;
 }
 
 void FTOutline::end()
@@ -256,7 +263,7 @@ VRle RleTask::operator()(FTOutline &outRef, SW_FT_Stroker &stroker)
 
         SW_FT_Stroker_Set(stroker, outRef.ftWidth, outRef.ftCap, outRef.ftJoin,
                           outRef.ftMeterLimit);
-        SW_FT_Stroker_ParseOutline(stroker, &outRef.ft, !outRef.ftClosed);
+        SW_FT_Stroker_ParseOutline(stroker, &outRef.ft);
         SW_FT_Stroker_GetCounts(stroker, &points, &contors);
 
         outRef.grow(points, contors);