[gimp/wip/wormnest/iptc-multiple-keys: 17/17] plug-ins: in metadata editor and viewer only convert values to UTF-8 if they are not.




commit d7b640900d442430b71574f63831771ea121c3e7
Author: Jacob Boerema <jgboerema gmail com>
Date:   Thu Nov 19 17:33:41 2020 -0500

    plug-ins: in metadata editor and viewer only convert values to UTF-8 if they are not.
    
    Certain metadata is already UTF-8. Converting them from locale
    to UTF-8 again leads to incorrectly shown strings.

 plug-ins/metadata/metadata-editor.c | 10 +++++++++-
 plug-ins/metadata/metadata-viewer.c |  9 ++++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/plug-ins/metadata/metadata-editor.c b/plug-ins/metadata/metadata-editor.c
index e5eccd9e24..1f96d00578 100644
--- a/plug-ins/metadata/metadata-editor.c
+++ b/plug-ins/metadata/metadata-editor.c
@@ -669,7 +669,15 @@ clean_xmp_string (const gchar *value)
         }
     }
 
-  value_utf8 = g_locale_to_utf8 (value_clean, -1, NULL, NULL, NULL);
+  if (! g_utf8_validate (value_clean, -1, NULL))
+    {
+      value_utf8 = g_locale_to_utf8 (value_clean, -1, NULL, NULL, NULL);
+    }
+  else
+    {
+      value_utf8 = g_strdup (value_clean);
+    }
+
   g_free (value_clean);
 
   return value_utf8;
diff --git a/plug-ins/metadata/metadata-viewer.c b/plug-ins/metadata/metadata-viewer.c
index 9f2c849e43..3d7aa93e47 100644
--- a/plug-ins/metadata/metadata-viewer.c
+++ b/plug-ins/metadata/metadata-viewer.c
@@ -452,7 +452,14 @@ metadata_dialog_format_tag_value (GExiv2Metadata *metadata,
       gchar *value_utf8;
 
       value      = gexiv2_metadata_get_tag_interpreted_string (metadata, tag);
-      value_utf8 = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
+      if (! g_utf8_validate (value, -1, NULL))
+        {
+          value_utf8 = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
+        }
+      else
+        {
+          value_utf8 = g_strdup (value);
+        }
 
       g_free (value);
 


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