[gimp] tools: update the build-only tool compute-svg-viewbox.



commit cb1f01a42b9cc50b786b436586d4497bc14935af
Author: Jehan <jehan girinstud io>
Date:   Fri Aug 28 13:03:23 2020 +0200

    tools: update the build-only tool compute-svg-viewbox.
    
    It now uses rsvg_handle_get_geometry_for_layer() instead of
    rsvg_handle_get_(position|dimensions)_sub() which have been deprecated
    in favor of the new function which returns accurate (double) positioning
    and size.
    
    Back when I first made this build tool, librsvg had several blocking
    bugs to make icon extraction work properly. This seems to improve
    nicely.
    
    Nevertheless I still don't build this tool because after testing, more
    bugs remain and icon extraction is still not right. Just updating the
    code to undeprecate it but leave the build commented out for now. ;-(
    
    See librsvg#134, librsvg#128 and librsvg#250 for bug reports following
    these issues.

 tools/Makefile.am            |  2 ++
 tools/compute-svg-viewbox.c  | 35 ++++++++++++++++++-----------------
 tools/extract-vector-icon.sh |  2 +-
 3 files changed, 21 insertions(+), 18 deletions(-)
---
diff --git a/tools/Makefile.am b/tools/Makefile.am
index b785a07a19..85ec53b527 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -58,6 +58,8 @@ if ENABLE_VECTOR_ICONS
 # Build tools which must be built for the host platform.
 #all-local: compute-svg-viewbox$(BUILD_EXEEXT)
 
+#noinst_PROGRAMS = compute-svg-viewbox
+
 #DISTCLEANFILES = compute-svg-viewbox$(BUILD_EXEEXT)
 endif
 
diff --git a/tools/compute-svg-viewbox.c b/tools/compute-svg-viewbox.c
index 1fcb08b1ed..a62df14aa7 100644
--- a/tools/compute-svg-viewbox.c
+++ b/tools/compute-svg-viewbox.c
@@ -21,15 +21,16 @@
 
 int main (int argc, char **argv)
 {
-  RsvgHandle        *handle;
-  RsvgPositionData   position_data;
-  RsvgDimensionData  dimension;
+  RsvgHandle    *handle;
+  RsvgRectangle  viewport = { 0.0, 0.0, 16.0, 16.0 };
+  RsvgRectangle  out_ink_rect;
+  RsvgRectangle  out_logical_rect;
 
-  gchar             *endptr;
-  gchar             *path;
-  gchar             *id;
-  gint               prev_x;
-  gint               prev_y;
+  gchar         *endptr;
+  gchar         *path;
+  gchar         *id;
+  gint           prev_x;
+  gint           prev_y;
 
   if (argc != 5)
     {
@@ -66,18 +67,18 @@ int main (int argc, char **argv)
       return 1;
     }
 
-  rsvg_handle_get_position_sub (handle, &position_data, id);
-  rsvg_handle_get_dimensions_sub (handle, &dimension, id);
-  if (dimension.width != dimension.height)
+  rsvg_handle_get_geometry_for_layer (handle, id, &viewport, &out_ink_rect, &out_logical_rect, NULL);
+
+  if (out_ink_rect.width != out_ink_rect.height)
     {
       /* Right now, we are constraining all objects into square objects. */
-      fprintf (stderr, "WARNING: object \"%s\" has unexpected size %dx%d [pos: (%d, %d)].\n",
-               id, dimension.width, dimension.height,
-               position_data.x, position_data.y);
+      fprintf (stderr, "WARNING: object \"%s\" has unexpected size %fx%f [pos: (%f, %f)].\n",
+               id, out_ink_rect.width, out_ink_rect.height,
+               out_ink_rect.x, out_ink_rect.y);
     }
-  printf ("viewBox=\"%d %d %d %d\"",
-          position_data.x + prev_x, position_data.y + prev_y,
-          dimension.width, dimension.height);
+  printf ("viewBox=\"%f %f %f %f\"",
+          out_ink_rect.x + prev_x, out_ink_rect.y + prev_y,
+          out_ink_rect.width, out_ink_rect.height);
 
   g_object_unref (handle);
   g_free (id);
diff --git a/tools/extract-vector-icon.sh b/tools/extract-vector-icon.sh
index 91fd2d0f06..3282276546 100755
--- a/tools/extract-vector-icon.sh
+++ b/tools/extract-vector-icon.sh
@@ -31,7 +31,7 @@ if [ "$#" != 2 ]; then
   fi
 fi
 
-# The script is run from $(top_builddir)/icons/Symbolic/
+# The script is run from $(top_builddir)/icons/*/
 compute_viewbox="$(pwd)/../../tools/compute-svg-viewbox"
 source="$1"
 id="$2"


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