Bill Skaggs <weskaggs@primate.ucdavis.edu>

* tools/pdbgen/pdb/vectors.pdb:  add code for
	vectors-export-to-file and vectors-export-to-string, as
	requested in bug #497159.

	* app/pdb/vectors_cmds.c
	* app/pdb/internal_procs.c
	* libgimp/gimpvectors_pdb.c
	* libgimp/gimpvectors_pdb.h: rebuilt accordingly.

svn path=/trunk/; revision=24189
This commit is contained in:
William Skaggs 2007-11-18 18:51:54 +00:00
parent 39a2b1c6a3
commit 10f66b04c7
6 changed files with 348 additions and 2 deletions

View File

@ -1,3 +1,14 @@
2007-11-18 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* tools/pdbgen/pdb/vectors.pdb: add code for
vectors-export-to-file and vectors-export-to-string, as
requested in bug #497159.
* app/pdb/vectors_cmds.c
* app/pdb/internal_procs.c
* libgimp/gimpvectors_pdb.c
* libgimp/gimpvectors_pdb.h: rebuilt accordingly.
2007-11-18 Sven Neumann <sven@gimp.org>
* gimptool-2.0.in: removed.

View File

@ -29,7 +29,7 @@
#include "internal_procs.h"
/* 552 procedures registered total */
/* 554 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)

View File

@ -37,6 +37,7 @@
#include "vectors/gimpanchor.h"
#include "vectors/gimpbezierstroke.h"
#include "vectors/gimpstroke-new.h"
#include "vectors/gimpvectors-export.h"
#include "vectors/gimpvectors-import.h"
#include "vectors/gimpvectors.h"
@ -1245,6 +1246,89 @@ vectors_import_from_string_invoker (GimpProcedure *procedure,
return return_vals;
}
static GValueArray *
vectors_export_to_file_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args)
{
gboolean success = TRUE;
GimpImage *image;
const gchar *filename;
GimpVectors *vectors;
image = gimp_value_get_image (&args->values[0], gimp);
filename = g_value_get_string (&args->values[1]);
vectors = gimp_value_get_vectors (&args->values[2], gimp);
if (success)
{
GError *error = NULL;
if (vectors != NULL && ! GIMP_IS_VECTORS (vectors))
{
g_set_error (&error, 0, 0, _("argument is not a valid Vectors object"));
success = FALSE;
}
else
success = gimp_vectors_export_file (image, vectors, filename, &error);
if (! success && error)
{
g_message (_("Failed to export path: %s"), error->message);
g_clear_error (&error);
}
}
return gimp_procedure_get_return_values (procedure, success);
}
static GValueArray *
vectors_export_to_string_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args)
{
gboolean success = TRUE;
GValueArray *return_vals;
GimpImage *image;
GimpVectors *vectors;
gchar *string = NULL;
image = gimp_value_get_image (&args->values[0], gimp);
vectors = gimp_value_get_vectors (&args->values[1], gimp);
if (success)
{
GError *error = NULL;
if (vectors != NULL && ! GIMP_IS_VECTORS (vectors))
{
g_set_error (&error, 0, 0, _("argument is not a valid Vectors object"));
success = FALSE;
}
else
string = gimp_vectors_export_string (image, vectors);
success = (string != NULL);
if (! success && error)
{
g_message (_("Failed to save path as string: %s"), error->message);
g_clear_error (&error);
}
}
return_vals = gimp_procedure_get_return_values (procedure, success);
if (success)
g_value_take_string (&return_vals->values[1], string);
return return_vals;
}
void
register_vectors_procs (GimpPDB *pdb)
{
@ -2552,4 +2636,74 @@ register_vectors_procs (GimpPDB *pdb)
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-vectors-export-to-file
*/
procedure = gimp_procedure_new (vectors_export_to_file_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-vectors-export-to-file");
gimp_procedure_set_static_strings (procedure,
"gimp-vectors-export-to-file",
"save a path as an SVG file.",
"This procedure creates an SVG file to save a Vectors object, that is, a path. The resulting file can be edited using a vector graphics application, or later reloaded into GIMP. If you pass 0 as the 'vectors' argument, then all paths in the image will be exported.",
"Bill Skaggs <weskaggs@primate.ucdavis.edu>",
"Bill Skaggs",
"2007",
NULL);
gimp_procedure_add_argument (procedure,
gimp_param_spec_image_id ("image",
"image",
"The image",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("filename",
"filename",
"The name of the SVG file to create.",
TRUE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_vectors_id ("vectors",
"vectors",
"The vectors object to be saved, or 0 for all in the image",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-vectors-export-to-string
*/
procedure = gimp_procedure_new (vectors_export_to_string_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-vectors-export-to-string");
gimp_procedure_set_static_strings (procedure,
"gimp-vectors-export-to-string",
"Save a path as an SVG string.",
"This procedure works like 'gimp-vectors-export-to-file' but creates a string rather than a file. The contents are a %NUL-terminated string that holds a complete XML document. If you pass 0 as the 'vectors' argument, then all paths in the image will be exported.",
"Bill Skaggs <weskaggs@primate.ucdavis.edu>",
"Bill Skaggs",
"2007",
NULL);
gimp_procedure_add_argument (procedure,
gimp_param_spec_image_id ("image",
"image",
"The image",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_vectors_id ("vectors",
"vectors",
"The vectors object to save, or 0 for all in the image",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_string ("string",
"string",
"A string whose contents are a complete SVG document.",
FALSE, FALSE, FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
}

View File

@ -1363,3 +1363,81 @@ gimp_vectors_import_from_string (gint32 image_ID,
return success;
}
/**
* gimp_vectors_export_to_file:
* @image_ID: The image.
* @filename: The name of the SVG file to create.
* @vectors_ID: The vectors object to be saved, or 0 for all in the image.
*
* save a path as an SVG file.
*
* This procedure creates an SVG file to save a Vectors object, that
* is, a path. The resulting file can be edited using a vector graphics
* application, or later reloaded into GIMP. If you pass 0 as the
* 'vectors' argument, then all paths in the image will be exported.
*
* Returns: TRUE on success.
*
* Since: GIMP 2.6
*/
gboolean
gimp_vectors_export_to_file (gint32 image_ID,
const gchar *filename,
gint32 vectors_ID)
{
GimpParam *return_vals;
gint nreturn_vals;
gboolean success = TRUE;
return_vals = gimp_run_procedure ("gimp-vectors-export-to-file",
&nreturn_vals,
GIMP_PDB_IMAGE, image_ID,
GIMP_PDB_STRING, filename,
GIMP_PDB_VECTORS, vectors_ID,
GIMP_PDB_END);
success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
gimp_destroy_params (return_vals, nreturn_vals);
return success;
}
/**
* gimp_vectors_export_to_string:
* @image_ID: The image.
* @vectors_ID: The vectors object to save, or 0 for all in the image.
*
* Save a path as an SVG string.
*
* This procedure works like gimp_vectors_export_to_file() but creates
* a string rather than a file. The contents are a %NUL-terminated
* string that holds a complete XML document. If you pass 0 as the
* 'vectors' argument, then all paths in the image will be exported.
*
* Returns: A string whose contents are a complete SVG document.
*
* Since: GIMP 2.6
*/
gchar *
gimp_vectors_export_to_string (gint32 image_ID,
gint32 vectors_ID)
{
GimpParam *return_vals;
gint nreturn_vals;
gchar *string = NULL;
return_vals = gimp_run_procedure ("gimp-vectors-export-to-string",
&nreturn_vals,
GIMP_PDB_IMAGE, image_ID,
GIMP_PDB_VECTORS, vectors_ID,
GIMP_PDB_END);
if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
string = g_strdup (return_vals[1].data.d_string);
gimp_destroy_params (return_vals, nreturn_vals);
return string;
}

View File

@ -146,6 +146,11 @@ gboolean gimp_vectors_import_from_string (gint32
gboolean scale,
gint *num_vectors,
gint32 **vectors_ids);
gboolean gimp_vectors_export_to_file (gint32 image_ID,
const gchar *filename,
gint32 vectors_ID);
gchar* gimp_vectors_export_to_string (gint32 image_ID,
gint32 vectors_ID);
G_END_DECLS

View File

@ -1276,6 +1276,102 @@ CODE
);
}
sub vectors_export_to_file {
$blurb = 'save a path as an SVG file.';
$help = <<'HELP';
This procedure creates an SVG file to save a Vectors object, that is,
a path. The resulting file can be edited using a vector graphics
application, or later reloaded into GIMP. If you pass 0 as the 'vectors'
argument, then all paths in the image will be exported.
HELP
&bill_pdb_misc('2007', '2.6');
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image' },
{ name => 'filename', type => 'string', allow_non_utf8 => 1,
non_empty => 1,
desc => 'The name of the SVG file to create.' },
{ name => 'vectors', type => 'vectors', no_validate => 1,
desc => 'The vectors object to be saved, or 0 for all in the image' }
);
%invoke = (
headers => [ qw("vectors/gimpvectors-export.h") ],
code => <<'CODE'
{
GError *error = NULL;
if (vectors != NULL && ! GIMP_IS_VECTORS (vectors))
{
g_set_error (&error, 0, 0, _("argument is not a valid Vectors object"));
success = FALSE;
}
else
success = gimp_vectors_export_file (image, vectors, filename, &error);
if (! success && error)
{
g_message (_("Failed to export path: %s"), error->message);
g_clear_error (&error);
}
}
CODE
);
}
sub vectors_export_to_string {
$blurb = 'Save a path as an SVG string.';
$help = <<'HELP';
This procedure works like gimp_vectors_export_to_file() but creates a string
rather than a file. The contents are a %NUL-terminated string that holds a
complete XML document. If you pass 0 as the 'vectors' argument, then all
paths in the image will be exported.
HELP
&bill_pdb_misc('2007', '2.6');
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image' },
{ name => 'vectors', type => 'vectors', no_validate => 1,
desc => 'The vectors object to save, or 0 for all in the image' }
);
@outargs = (
{ name => 'string', type => 'string',
desc => 'A string whose contents are a complete SVG document.' }
);
%invoke = (
headers => [ qw("vectors/gimpvectors-export.h") ],
code => <<'CODE'
{
GError *error = NULL;
if (vectors != NULL && ! GIMP_IS_VECTORS (vectors))
{
g_set_error (&error, 0, 0, _("argument is not a valid Vectors object"));
success = FALSE;
}
else
string = gimp_vectors_export_string (image, vectors);
success = (string != NULL);
if (! success && error)
{
g_message (_("Failed to save path as string: %s"), error->message);
g_clear_error (&error);
}
}
CODE
);
}
@headers = qw(<string.h> "core/gimp.h" "core/gimplist.h" "core/gimpimage.h"
"core/gimpchannel-select.h" "vectors/gimpanchor.h"
@ -1311,7 +1407,9 @@ CODE
vectors_bezier_stroke_new_ellipse
vectors_to_selection
vectors_import_from_file
vectors_import_from_string);
vectors_import_from_string
vectors_export_to_file
vectors_export_to_string);
%exports = (app => [@procs], lib => [@procs]);