Remove the ISO8859-1 restriction from the description of png tEXt

* gdk-pixbuf-io.c (gdk_pixbuf_save): Remove the ISO8859-1
	restriction from the description of png tEXt parameters.

	* io-png.c (png_text_to_pixbuf_option):
	(gdk_pixbuf__png_image_save): If libpng supports it,
	store and retrieve non-ISO8859-1 text as UTF-8.  (#76172)
This commit is contained in:
Matthias Clasen 2002-04-24 00:09:29 +00:00
parent a8d22aad99
commit 999748e922
3 changed files with 37 additions and 13 deletions

View File

@ -1,3 +1,12 @@
2002-04-24 Matthias Clasen <maclas@gmx.de>
* gdk-pixbuf-io.c (gdk_pixbuf_save): Remove the ISO8859-1
restriction from the description of png tEXt parameters.
* io-png.c (png_text_to_pixbuf_option):
(gdk_pixbuf__png_image_save): If libpng supports it,
store and retrieve non-ISO8859-1 text as UTF-8. (#76172)
2002-04-11 Matthias Clasen <maclas@gmx.de>
More fixes for #77807:

View File

@ -784,9 +784,7 @@ gdk_pixbuf_real_save (GdkPixbuf *pixbuf,
* "quality" parameter; its value should be in the range [0,100].
* Text chunks can be attached to PNG images by specifying parameters of
* the form "tEXt::key", where key is an ASCII string of length 1-79.
* The values are UTF-8 encoded strings. Note however that PNG text
* chunks are stored in ISO-8859-1 encoding, so you can only set texts
* that can be represented in this encoding.
* The values are UTF-8 encoded strings.
*
* Return value: whether an error was set
**/

View File

@ -204,14 +204,19 @@ png_text_to_pixbuf_option (png_text text_ptr,
gchar **key,
gchar **value)
{
*value = g_convert (text_ptr.text, -1,
"UTF-8", "ISO-8859-1",
NULL, NULL, NULL);
if (text_ptr.text_length > 0) {
*value = g_convert (text_ptr.text, -1,
"UTF-8", "ISO-8859-1",
NULL, NULL, NULL);
}
else {
*value = g_strdup (text_ptr.text);
}
if (*value) {
*key = g_strconcat ("tEXt::", text_ptr.key, NULL);
return TRUE;
} else {
g_warning ("Couldn't convert tEXt chunk value to UTF-8.");
g_warning ("Couldn't convert text chunk value to UTF-8.");
*key = NULL;
return FALSE;
}
@ -602,7 +607,7 @@ png_info_callback (png_structp png_read_ptr,
return;
}
/* Extract tEXt chunks and attach them as pixbuf options */
/* Extract text chunks and attach them as pixbuf options */
if (png_get_text (png_read_ptr, png_info_ptr, &png_text_ptr, &num_texts)) {
for (i = 0; i < num_texts; i++) {
@ -753,8 +758,8 @@ gdk_pixbuf__png_image_save (FILE *f,
for (kiter = keys; *kiter; kiter++) {
if (strncmp (*kiter, "tEXt::", 6) != 0) {
g_warning ("Bad option name '%s' passed to PNG saver", *kiter);
return FALSE;
g_warning ("Bad option name '%s' passed to PNG saver", *kiter);
return FALSE;
}
key = *kiter + 6;
len = strlen (key);
@ -762,7 +767,7 @@ gdk_pixbuf__png_image_save (FILE *f,
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_BAD_OPTION,
_("Keys for PNG tEXt chunks must have at least 1 and at most 79 characters."));
_("Keys for PNG text chunks must have at least 1 and at most 79 characters."));
return FALSE;
}
for (i = 0; i < len; i++) {
@ -770,7 +775,7 @@ gdk_pixbuf__png_image_save (FILE *f,
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_BAD_OPTION,
_("Keys for PNG tEXt chunks must be ASCII characters."));
_("Keys for PNG text chunks must be ASCII characters."));
return FALSE;
}
}
@ -787,11 +792,23 @@ gdk_pixbuf__png_image_save (FILE *f,
"ISO-8859-1", "UTF-8",
NULL, &text_ptr[i].text_length,
NULL);
#ifdef PNG_iTXt_SUPPORTED
if (!text_ptr[i].text) {
text_ptr[i].compression = PNG_ITXT_COMPRESSION_NONE;
text_ptr[i].text = g_strdup (values[i]);
text_ptr[i].text_length = 0;
text_ptr[i].itxt_length = strlen (text_ptr[i].text);
text_ptr[i].lang = NULL;
text_ptr[i].lang_key = NULL;
}
#endif
if (!text_ptr[i].text) {
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_BAD_OPTION,
_("Value for PNG tEXt chunk can not be converted to ISO-8859-1 encoding."));
_("Value for PNG text chunk %s can not be converted to ISO-8859-1 encoding."), keys[i] + 6);
num_keys = i;
for (i = 0; i < num_keys; i++)
g_free (text_ptr[i].text);