plug-ins/common/tiff-load.c Implement the proposed scheme for storing
2007-06-05 Simon Budig <simon@gimp.org> * plug-ins/common/tiff-load.c * plug-ins/common/tiff-save.c: Implement the proposed scheme for storing international path names in TIFF files. svn path=/trunk/; revision=22712
This commit is contained in:
@ -1,3 +1,9 @@
|
|||||||
|
2007-06-05 Simon Budig <simon@gimp.org>
|
||||||
|
|
||||||
|
* plug-ins/common/tiff-load.c
|
||||||
|
* plug-ins/common/tiff-save.c: Implement the proposed scheme for
|
||||||
|
storing international path names in TIFF files.
|
||||||
|
|
||||||
2007-06-05 Sven Neumann <sven@gimp.org>
|
2007-06-05 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* plug-ins/helpbrowser/dialog.c
|
* plug-ins/helpbrowser/dialog.c
|
||||||
|
@ -1115,7 +1115,7 @@ static void
|
|||||||
load_paths (TIFF *tif, gint image)
|
load_paths (TIFF *tif, gint image)
|
||||||
{
|
{
|
||||||
guint16 id;
|
guint16 id;
|
||||||
guint32 len, n_bytes, pos;
|
gsize len, n_bytes, pos;
|
||||||
gchar *bytes, *name;
|
gchar *bytes, *name;
|
||||||
guint32 *val32;
|
guint32 *val32;
|
||||||
guint16 *val16;
|
guint16 *val16;
|
||||||
@ -1126,19 +1126,6 @@ load_paths (TIFF *tif, gint image)
|
|||||||
width = gimp_image_width (image);
|
width = gimp_image_width (image);
|
||||||
height = gimp_image_height (image);
|
height = gimp_image_height (image);
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* TIFFTAG_CLIPPATH seems to be basically unused */
|
|
||||||
|
|
||||||
if (TIFFGetField (tif, TIFFTAG_CLIPPATH, &n_bytes, &bytes) &&
|
|
||||||
TIFFGetField (tif, TIFFTAG_XCLIPPATHUNITS, &xclipunits) &&
|
|
||||||
TIFFGetField (tif, TIFFTAG_YCLIPPATHUNITS, &yclipunits))
|
|
||||||
{
|
|
||||||
/* Tiff clipping path */
|
|
||||||
|
|
||||||
g_printerr ("Tiff clipping path, %d - %d\n", xclipunits, yclipunits);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!TIFFGetField (tif, TIFFTAG_PHOTOSHOP, &n_bytes, &bytes))
|
if (!TIFFGetField (tif, TIFFTAG_PHOTOSHOP, &n_bytes, &bytes))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1163,9 +1150,26 @@ load_paths (TIFF *tif, gint image)
|
|||||||
if (n_bytes - pos < len + 1)
|
if (n_bytes - pos < len + 1)
|
||||||
break; /* block not big enough */
|
break; /* block not big enough */
|
||||||
|
|
||||||
name = g_strndup (bytes + pos + 1, len);
|
/*
|
||||||
if (!g_utf8_validate (name, -1, NULL))
|
* do we have the UTF-marker? is it valid UTF-8?
|
||||||
name = g_strdup ("imported path");
|
* if so, we assume an utf-8 encoded name, otherwise we
|
||||||
|
* assume iso8859-1
|
||||||
|
*/
|
||||||
|
name = bytes + pos + 1;
|
||||||
|
if (len >= 3 &&
|
||||||
|
name[0] == '\xEF' && name[1] == '\xBB' && name[2] == '\xBF' &&
|
||||||
|
g_utf8_validate (name, len - 3, NULL))
|
||||||
|
{
|
||||||
|
name = g_strndup (name + 3, len - 3);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
name = g_convert (name, len, "utf-8", "iso8859-1", NULL, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
name = g_strdup ("(imported path)");
|
||||||
|
|
||||||
pos += len + 1;
|
pos += len + 1;
|
||||||
|
|
||||||
if (pos % 2) /* padding */
|
if (pos % 2) /* padding */
|
||||||
|
@ -465,18 +465,46 @@ save_paths (TIFF *tif,
|
|||||||
{
|
{
|
||||||
GString *data;
|
GString *data;
|
||||||
gchar *name, *nameend;
|
gchar *name, *nameend;
|
||||||
gint len, lenpos;
|
gsize len;
|
||||||
|
gint lenpos;
|
||||||
gchar pointrecord[26] = { 0, };
|
gchar pointrecord[26] = { 0, };
|
||||||
|
gchar *tmpname;
|
||||||
|
GError *err = NULL;
|
||||||
|
|
||||||
data = g_string_new ("8BIM");
|
data = g_string_new ("8BIM");
|
||||||
g_string_append_c (data, id / 256);
|
g_string_append_c (data, id / 256);
|
||||||
g_string_append_c (data, id % 256);
|
g_string_append_c (data, id % 256);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* - use iso8859-1 if possible
|
||||||
|
* - otherwise use UTF-8, prepended with \xef\xbb\xbf (Byte-Order-Mark)
|
||||||
|
*/
|
||||||
name = gimp_vectors_get_name (vectors[v]);
|
name = gimp_vectors_get_name (vectors[v]);
|
||||||
len = g_utf8_strlen (name, 255); /* max. 255 chars in a pascal string */
|
tmpname = g_convert (name, -1, "iso8859-1", "utf-8", NULL, &len, &err);
|
||||||
nameend = g_utf8_offset_to_pointer (name, len);
|
|
||||||
g_string_append_c (data, nameend - name);
|
if (tmpname && err == NULL)
|
||||||
g_string_append_len (data, name, nameend - name);
|
{
|
||||||
|
g_string_append_c (data, MIN (len, 255));
|
||||||
|
g_string_append_len (data, tmpname, MIN (len, 255));
|
||||||
|
g_free (tmpname);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* conversion failed, we fall back to UTF-8 */
|
||||||
|
len = g_utf8_strlen (name, 255 - 3); /* need three marker-bytes */
|
||||||
|
|
||||||
|
nameend = g_utf8_offset_to_pointer (name, len);
|
||||||
|
len = nameend - name; /* in bytes */
|
||||||
|
g_assert (len + 3 <= 255);
|
||||||
|
|
||||||
|
g_string_append_c (data, len + 3);
|
||||||
|
g_string_append_len (data, "\xEF\xBB\xBF", 3); /* Unicode 0xfeff */
|
||||||
|
g_string_append_len (data, name, len);
|
||||||
|
|
||||||
|
if (tmpname)
|
||||||
|
g_free (tmpname);
|
||||||
|
}
|
||||||
|
|
||||||
if (data->len % 2) /* padding to even size */
|
if (data->len % 2) /* padding to even size */
|
||||||
g_string_append_c (data, 0);
|
g_string_append_c (data, 0);
|
||||||
g_free (name);
|
g_free (name);
|
||||||
|
Reference in New Issue
Block a user