[gimp] plug-ins: fix #6258 Hierarchical XMP tag should be written to Array



commit af888e481fb2cd21840b385377898bb32914bac9
Author: Jacob Boerema <jgboerema gmail com>
Date:   Fri Sep 24 13:42:45 2021 -0400

    plug-ins: fix #6258 Hierarchical XMP tag should be written to Array
    
    When saving XMP metadata were using gexiv2_metadata_get_tag_string for all
    tags, even those that can have multiple values. This caused those values
    to be saved as one value instead of multiple.
    
    To fix this we use gexiv2_metadata_get_tag_multiple, except for XmpText.
    Then we add all returned values for that tag separately to our metadata.

 libgimpbase/gimpmetadata.c | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)
---
diff --git a/libgimpbase/gimpmetadata.c b/libgimpbase/gimpmetadata.c
index 6df5bb61ef..705cc950e4 100644
--- a/libgimpbase/gimpmetadata.c
+++ b/libgimpbase/gimpmetadata.c
@@ -823,14 +823,39 @@ gimp_metadata_serialize (GimpMetadata *metadata)
     {
       for (i = 0; xmp_data[i] != NULL; i++)
         {
-          value = gexiv2_metadata_get_tag_string (GEXIV2_METADATA (metadata),
-                                                  xmp_data[i]);
-          escaped = gimp_metadata_escape (xmp_data[i], value, &base64);
-          g_free (value);
+          /* XmpText is always a single value, but structures like
+           * XmpBag and XmpSeq can have multiple values that need to be
+           * treated separately or else saving will do things wrong. */
+          if (! g_strcmp0 (gexiv2_metadata_get_tag_type (xmp_data[i]), "XmpText"))
+            {
+              value = gexiv2_metadata_get_tag_string (GEXIV2_METADATA (metadata),
+                                                      xmp_data[i]);
+              escaped = gimp_metadata_escape (xmp_data[i], value, &base64);
+              g_free (value);
 
-          gimp_metadata_append_tag (string, xmp_data[i], escaped, base64);
-        }
+              gimp_metadata_append_tag (string, xmp_data[i], escaped, base64);
+            }
+          else
+            {
+              gchar **values;
 
+              values = gexiv2_metadata_get_tag_multiple (GEXIV2_METADATA (metadata),
+                                                         xmp_data[i]);
+
+              if (values)
+                {
+                  gint  vi;
+
+                  for (vi = 0; values[vi] != NULL; vi++)
+                    {
+                      escaped = gimp_metadata_escape (xmp_data[i], values[vi], &base64);
+                      gimp_metadata_append_tag (string, xmp_data[i], escaped, base64);
+                    }
+
+                  g_strfreev (values);
+                }
+            }
+        }
       g_strfreev (xmp_data);
     }
 


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