[gimp/wip/wormnest/iptc-multiple-keys: 3/14] libgimpbase: fix incorrect reading of iptc tags that appear more than once.




commit d0f67faf29a9732f8af18b61af7313efc4f00ff3
Author: Jacob Boerema <jgboerema gmail com>
Date:   Mon Nov 16 13:01:55 2020 -0500

    libgimpbase: fix incorrect reading of iptc tags that appear more than once.
    
    This is one of the problems mentioned in issue #5863. This commit only fixes
    our loading (and saving) of this metadata.
    Certain iptc tags like "Keywords" can appear multiple times. We were using
    gexiv2_metadata_get_tag_string to get the value but that always returns
    the first value so we replaced that by gexiv2_metadata_get_tag_multiple.

 libgimpbase/gimpmetadata.c | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)
---
diff --git a/libgimpbase/gimpmetadata.c b/libgimpbase/gimpmetadata.c
index 719b13e335..dbc3dd9fa6 100644
--- a/libgimpbase/gimpmetadata.c
+++ b/libgimpbase/gimpmetadata.c
@@ -838,14 +838,35 @@ gimp_metadata_serialize (GimpMetadata *metadata)
 
   if (iptc_data)
     {
-      for (i = 0; iptc_data[i] != NULL; i++)
+      gchar **iptc_tags = iptc_data;
+      gchar  *last_tag  = NULL;
+
+      while (*iptc_tags)
         {
-          value = gexiv2_metadata_get_tag_string (GEXIV2_METADATA (metadata),
-                                                  iptc_data[i]);
-          escaped = gimp_metadata_escape (iptc_data[i], value, &base64);
-          g_free (value);
+          gchar **values;
+
+          if (last_tag && ! strcmp (*iptc_tags, last_tag))
+            {
+              iptc_tags++;
+              continue;
+            }
+          last_tag = *iptc_tags;
+
+          values = gexiv2_metadata_get_tag_multiple (GEXIV2_METADATA (metadata),
+                                                     *iptc_tags);
+
+          if (values)
+            {
+              for (i = 0; values[i] != NULL; i++)
+                {
+                  escaped = gimp_metadata_escape (*iptc_tags, values[i], &base64);
+                  gimp_metadata_append_tag (string, *iptc_tags, escaped, base64);
+                }
+
+              g_strfreev (values);
+            }
 
-          gimp_metadata_append_tag (string, iptc_data[i], escaped, base64);
+          iptc_tags++;
         }
 
       g_strfreev (iptc_data);


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