[gtk/matthiasc/lottie: 3/4] path: Fix serialization for circles




commit f8aa3c09010845d8016bb49199ca48880665a516
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Nov 24 02:20:09 2020 -0500

    path: Fix serialization for circles
    
    The svg A can not do a full circle, since it is
    a two point parametrization - if the start and
    end point are the same, it draws nothing.
    So, use two arcs.

 gsk/gskpath.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)
---
diff --git a/gsk/gskpath.c b/gsk/gskpath.c
index 166791a211..1125dbd26a 100644
--- a/gsk/gskpath.c
+++ b/gsk/gskpath.c
@@ -381,17 +381,22 @@ gsk_circle_contour_print (const GskContour *contour,
                           GString          *string)
 {
   const GskCircleContour *self = (const GskCircleContour *) contour;
-  graphene_point_t start = GRAPHENE_POINT_INIT (cos (DEG_TO_RAD (self->start_angle)) * self->radius,
-                                                sin (DEG_TO_RAD (self->start_angle)) * self->radius);
-  graphene_point_t end = GRAPHENE_POINT_INIT (cos (DEG_TO_RAD (self->end_angle)) * self->radius,
-                                              sin (DEG_TO_RAD (self->end_angle)) * self->radius);
+  double mid_angle = (self->end_angle - self->start_angle) / 2;
+  graphene_point_t start = GRAPHENE_POINT_INIT (self->center.x + cos (DEG_TO_RAD (self->start_angle)) * 
self->radius,
+                                                self->center.y + sin (DEG_TO_RAD (self->start_angle)) * 
self->radius);
+  graphene_point_t mid = GRAPHENE_POINT_INIT (self->center.x + cos (DEG_TO_RAD (mid_angle)) * self->radius,
+                                                self->center.y + sin (DEG_TO_RAD (mid_angle)) * 
self->radius);
+  graphene_point_t end = GRAPHENE_POINT_INIT (self->center.x + cos (DEG_TO_RAD (self->end_angle)) * 
self->radius,
+                                              self->center.y + sin (DEG_TO_RAD (self->end_angle)) * 
self->radius);
 
-  g_string_append_printf (string, "M %g %g A %g %g 0 %u %u %g %g",
-                          self->center.x + start.x, self->center.y + start.y, 
-                          self->radius, self->radius,
-                          fabs (self->start_angle - self->end_angle) > 180 ? 1 : 0,
-                          self->start_angle < self->end_angle ? 0 : 1,
-                          self->center.x + end.x, self->center.y + end.y);
+  g_string_append_printf (string, "M %g %g ", start.x, start.y);
+  g_string_append_printf (string, "A %g %g 0 1 0 %g %g ",
+                          self->radius, self->radius, mid.x, mid.y);
+  g_string_append_printf (string, "A %g %g 0 1 0 %g %g ",
+                          self->radius, self->radius, end.x, end.y);
+
+  if (fabs (self->start_angle - self->end_angle) >= 360)
+    g_string_append (string, "Z");
 }
 
 static gboolean
@@ -2555,7 +2560,7 @@ gsk_path_from_string (const char *s)
   return gsk_path_builder_free_to_path (builder);
 
 error:
-  //g_warning ("Can't parse string '%s' as GskPath, error at %ld", s, p - s);
+  g_warning ("Can't parse string '%s' as GskPath, error at %ld", s, p - s);
   gsk_path_builder_unref (builder);
 
   return NULL;


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