[gnome-color-manager] Support localized descriptions (mluc tag) too



commit e7df862a445d8d1108c28940e96f00a08784d83c
Author: Richard Hughes <richard hughsie com>
Date:   Wed Dec 9 10:52:34 2009 +0000

    Support localized descriptions (mluc tag) too

 src/gcm-profile.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 52 insertions(+), 1 deletions(-)
---
diff --git a/src/gcm-profile.c b/src/gcm-profile.c
index bbea4ab..893a856 100644
--- a/src/gcm-profile.c
+++ b/src/gcm-profile.c
@@ -539,15 +539,51 @@ gcm_profile_ensure_printable (gchar *data)
 }
 
 /**
+ * gcm_profile_utf16be_to_locale:
+ *
+ * Convert ICC encoded UTF-16BE into a string the user can understand
+ **/
+static gchar *
+gcm_profile_utf16be_to_locale (const gchar *text, guint size)
+{
+	gsize items_written;
+	gchar *text_utf8 = NULL;
+	gchar *text_locale = NULL;
+	GError *error = NULL;
+
+	/* convert from ICC text encoding to UTF-8 */
+	text_utf8 = g_convert (text, size, "UTF-8", "UTF-16BE", NULL, &items_written, &error);
+	if (text_utf8 == NULL) {
+		egg_warning ("failed to convert to UTF-8: %s", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	/* convert from UTF-8 to the users locale*/
+	text_locale = g_locale_from_utf8 (text_utf8, items_written, NULL, NULL, &error);
+	if (text_locale == NULL) {
+		egg_warning ("failed to convert to locale: %s", error->message);
+		g_error_free (error);
+		goto out;
+	}
+out:
+	g_free (text_utf8);
+	return text_locale;
+}
+
+/**
  * gcm_profile_parse_multi_localized_unicode:
  **/
 static gchar *
 gcm_profile_parse_multi_localized_unicode (GcmProfile *profile, const gchar *data, gsize offset)
 {
-	gint i;
+	guint i;
 	gboolean ret;
 	gchar *text = NULL;
 	guint record_size;
+	guint names_size;
+	guint len;
+	guint offset_name;
 
 	/* check we are not a localized tag */
 	ret = (memcmp (&data[offset], "desc", 4) == 0);
@@ -564,6 +600,21 @@ gcm_profile_parse_multi_localized_unicode (GcmProfile *profile, const gchar *dat
 		goto out;
 	}
 
+	/* check we are not a localized tag */
+	ret = (memcmp (&data[offset], "mluc", 4) == 0);
+	if (ret) {
+		names_size = gcm_parser_unencode_32 (data, offset + 8);
+		if (names_size != 1) {
+			/* there is more than one language encoded */
+			egg_warning ("more than one item of data in MLUC (names size: %i), using first one", names_size);
+		}
+		record_size = gcm_parser_unencode_32 (data, offset + 12);
+		len = gcm_parser_unencode_32 (data, offset + 20);
+		offset_name = gcm_parser_unencode_32 (data, offset + 24);
+		text = gcm_profile_utf16be_to_locale (data+offset+offset_name, len);
+		goto out;
+	}
+
 	/* correct broken profiles, seen in ISOuncoatedyellowish.icc : FIXME: why is the offset one off? */
 	ret = (memcmp (&data[offset+1], "text", 4) == 0);
 	if (ret) {



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