Beispiel #1
0
/**
 * gimp_vectors_export_string:
 * @image: the #GimpImage from which to export vectors
 * @vectors: a #GimpVectors object or %NULL to export all vectors in @image
 *
 * Exports one or more vectors to a SVG string.
 *
 * Return value: a %NUL-terminated string that holds a complete XML document
 **/
gchar *
gimp_vectors_export_string (const GimpImage    *image,
                            const GimpVectors  *vectors)
{
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
  g_return_val_if_fail (vectors == NULL || GIMP_IS_VECTORS (vectors), NULL);

  return g_string_free (gimp_vectors_export (image, vectors), FALSE);
}
/**
 * gimp_vectors_export_file:
 * @image: the #GimpImage from which to export vectors
 * @vectors: a #GimpVectors object or %NULL to export all vectors in @image
 * @filename: the name of the file to write
 * @error: return location for errors
 *
 * Exports one or more vectors to a SVG file.
 *
 * Return value: %TRUE on success,
 *               %FALSE if there was an error writing the file
 **/
gboolean
gimp_vectors_export_file (const GimpImage    *image,
                          const GimpVectors  *vectors,
                          const gchar        *filename,
                          GError            **error)
{
  FILE    *file;
  GString *str;

  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
  g_return_val_if_fail (vectors == NULL || GIMP_IS_VECTORS (vectors), FALSE);
  g_return_val_if_fail (filename != NULL, FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  file = g_fopen (filename, "w");
  if (!file)
    {
      g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
		   _("Could not open '%s' for writing: %s"),
                   gimp_filename_to_utf8 (filename), g_strerror (errno));
      return FALSE;
    }

  str = gimp_vectors_export (image, vectors);

  fprintf (file, "%s", str->str);

  g_string_free (str, TRUE);

  if (fclose (file))
    {
      g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
		   _("Error while writing '%s': %s"),
                   gimp_filename_to_utf8 (filename), g_strerror (errno));
      return FALSE;
    }

  return TRUE;
}