Commit 47bd472e authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

added a preliminary PDB API for vectors import. Will change when the new

2003-09-21  Sven Neumann  <sven@gimp.org>

	* tools/pdbgen/pdb/paths.pdb: added a preliminary PDB API for
	vectors import. Will change when the new vectors PDB API gets
	added.

	* app/pdb/internal_procs.c
	* app/pdb/paths_cmds.c
	* libgimp/gimppaths_pdb.[ch]: regenerated.

	* plug-ins/common/svg.c: allow to import paths when rendering a
	SVG file.
parent 75cf42f8
2003-09-21 Sven Neumann <sven@gimp.org>
* tools/pdbgen/pdb/paths.pdb: added a preliminary PDB API for
vectors import. Will change when the new vectors PDB API gets
added.
* app/pdb/internal_procs.c
* app/pdb/paths_cmds.c
* libgimp/gimppaths_pdb.[ch]: regenerated.
* plug-ins/common/svg.c: allow to import paths when rendering a
SVG file.
2003-09-21 Sven Neumann <sven@gimp.org>
 
* plug-ins/common/svg.c: added a resolution entry and implemented
......@@ -69,7 +69,7 @@ void register_transform_tools_procs (Gimp *gimp);
void register_undo_procs (Gimp *gimp);
void register_unit_procs (Gimp *gimp);
/* 347 procedures registered total */
/* 348 procedures registered total */
void
internal_procs_init (Gimp *gimp,
......@@ -93,7 +93,7 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Convert"), 0.124);
register_convert_procs (gimp);
(* status_callback) (NULL, _("Display procedures"), 0.133);
(* status_callback) (NULL, _("Display procedures"), 0.132);
register_display_procs (gimp);
(* status_callback) (NULL, _("Drawable procedures"), 0.144);
......@@ -102,94 +102,94 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Edit procedures"), 0.21);
register_edit_procs (gimp);
(* status_callback) (NULL, _("File Operations"), 0.228);
(* status_callback) (NULL, _("File Operations"), 0.227);
register_fileops_procs (gimp);
(* status_callback) (NULL, _("Floating selections"), 0.251);
(* status_callback) (NULL, _("Floating selections"), 0.25);
register_floating_sel_procs (gimp);
(* status_callback) (NULL, _("Font UI"), 0.268);
(* status_callback) (NULL, _("Font UI"), 0.267);
register_font_select_procs (gimp);
(* status_callback) (NULL, _("Fonts"), 0.277);
(* status_callback) (NULL, _("Fonts"), 0.276);
register_fonts_procs (gimp);
(* status_callback) (NULL, _("Gimprc procedures"), 0.282);
register_gimprc_procs (gimp);
(* status_callback) (NULL, _("Gradient UI"), 0.294);
(* status_callback) (NULL, _("Gradient UI"), 0.293);
register_gradient_select_procs (gimp);
(* status_callback) (NULL, _("Gradients"), 0.303);
(* status_callback) (NULL, _("Gradients"), 0.302);
register_gradients_procs (gimp);
(* status_callback) (NULL, _("Guide procedures"), 0.323);
(* status_callback) (NULL, _("Guide procedures"), 0.322);
register_guides_procs (gimp);
(* status_callback) (NULL, _("Help procedures"), 0.34);
(* status_callback) (NULL, _("Help procedures"), 0.339);
register_help_procs (gimp);
(* status_callback) (NULL, _("Image"), 0.343);
(* status_callback) (NULL, _("Image"), 0.342);
register_image_procs (gimp);
(* status_callback) (NULL, _("Layer"), 0.527);
(* status_callback) (NULL, _("Layer"), 0.526);
register_layer_procs (gimp);
(* status_callback) (NULL, _("Message procedures"), 0.62);
(* status_callback) (NULL, _("Message procedures"), 0.618);
register_message_procs (gimp);
(* status_callback) (NULL, _("Miscellaneous"), 0.628);
(* status_callback) (NULL, _("Miscellaneous"), 0.626);
register_misc_procs (gimp);
(* status_callback) (NULL, _("Misc Tool procedures"), 0.634);
(* status_callback) (NULL, _("Misc Tool procedures"), 0.632);
register_misc_tools_procs (gimp);
(* status_callback) (NULL, _("Paint Tool procedures"), 0.643);
(* status_callback) (NULL, _("Paint Tool procedures"), 0.641);
register_paint_tools_procs (gimp);
(* status_callback) (NULL, _("Palette"), 0.686);
(* status_callback) (NULL, _("Palette"), 0.684);
register_palette_procs (gimp);
(* status_callback) (NULL, _("Palette UI"), 0.703);
(* status_callback) (NULL, _("Palette UI"), 0.701);
register_palette_select_procs (gimp);
(* status_callback) (NULL, _("Palettes"), 0.712);
(* status_callback) (NULL, _("Palettes"), 0.71);
register_palettes_procs (gimp);
(* status_callback) (NULL, _("Parasite procedures"), 0.726);
(* status_callback) (NULL, _("Parasite procedures"), 0.724);
register_parasite_procs (gimp);
(* status_callback) (NULL, _("Paths"), 0.761);
(* status_callback) (NULL, _("Paths"), 0.759);
register_paths_procs (gimp);
(* status_callback) (NULL, _("Pattern UI"), 0.801);
(* status_callback) (NULL, _("Pattern UI"), 0.802);
register_pattern_select_procs (gimp);
(* status_callback) (NULL, _("Patterns"), 0.81);
register_patterns_procs (gimp);
(* status_callback) (NULL, _("Plug-in"), 0.824);
(* status_callback) (NULL, _("Plug-in"), 0.825);
register_plug_in_procs (gimp);
(* status_callback) (NULL, _("Procedural database"), 0.841);
(* status_callback) (NULL, _("Procedural database"), 0.842);
register_procedural_db_procs (gimp);
(* status_callback) (NULL, _("Image mask"), 0.865);
register_selection_procs (gimp);
(* status_callback) (NULL, _("Selection Tool procedures"), 0.916);
(* status_callback) (NULL, _("Selection Tool procedures"), 0.917);
register_selection_tools_procs (gimp);
(* status_callback) (NULL, _("Text procedures"), 0.931);
register_text_tool_procs (gimp);
(* status_callback) (NULL, _("Transform Tool procedures"), 0.942);
(* status_callback) (NULL, _("Transform Tool procedures"), 0.943);
register_transform_tools_procs (gimp);
(* status_callback) (NULL, _("Undo"), 0.96);
register_undo_procs (gimp);
(* status_callback) (NULL, _("Units"), 0.965);
(* status_callback) (NULL, _("Units"), 0.966);
register_unit_procs (gimp);
}
......@@ -39,6 +39,7 @@
#include "vectors/gimpanchor.h"
#include "vectors/gimpbezierstroke.h"
#include "vectors/gimpvectors-compat.h"
#include "vectors/gimpvectors-import.h"
#include "vectors/gimpvectors.h"
static ProcRecord path_list_proc;
......@@ -55,6 +56,7 @@ static ProcRecord get_path_by_tattoo_proc;
static ProcRecord path_get_locked_proc;
static ProcRecord path_set_locked_proc;
static ProcRecord path_to_selection_proc;
static ProcRecord path_import_proc;
void
register_paths_procs (Gimp *gimp)
......@@ -73,6 +75,7 @@ register_paths_procs (Gimp *gimp)
procedural_db_register (gimp, &path_get_locked_proc);
procedural_db_register (gimp, &path_set_locked_proc);
procedural_db_register (gimp, &path_to_selection_proc);
procedural_db_register (gimp, &path_import_proc);
}
static Argument *
......@@ -1193,3 +1196,63 @@ static ProcRecord path_to_selection_proc =
NULL,
{ { path_to_selection_invoker } }
};
static Argument *
path_import_invoker (Gimp *gimp,
Argument *args)
{
gboolean success = TRUE;
GimpImage *gimage;
gchar *filename;
gboolean merge;
gimage = gimp_image_get_by_ID (gimp, args[0].value.pdb_int);
if (! GIMP_IS_IMAGE (gimage))
success = FALSE;
filename = (gchar *) args[1].value.pdb_pointer;
if (filename == NULL)
success = FALSE;
merge = args[2].value.pdb_int ? TRUE : FALSE;
if (success)
success = gimp_vectors_import (gimage, filename, merge, NULL);
return procedural_db_return_args (&path_import_proc, success);
}
static ProcArg path_import_inargs[] =
{
{
GIMP_PDB_IMAGE,
"image",
"The image"
},
{
GIMP_PDB_STRING,
"filename",
"The name of the SVG file to import."
},
{
GIMP_PDB_INT32,
"merge",
"Merge paths into a single vectors object"
}
};
static ProcRecord path_import_proc =
{
"gimp_path_import",
"Import paths from an SVG file.",
"This procedure imports path from an SVG file. This is a temporary solution until the new vectors PDB API is in place. Don't rely on this function being available in future GIMP releases.",
"Sven Neumann",
"Sven Neumann",
"2003",
GIMP_INTERNAL,
3,
path_import_inargs,
0,
NULL,
{ { path_import_invoker } }
};
......@@ -37,22 +37,27 @@
#include "libgimp/stdplugins-intl.h"
#define SVG_VERSION "2.5.0"
#define SVG_BUFFER_SIZE (8 * 1024)
#define SVG_VERSION "2.5.0"
#define SVG_DEFAULT_RESOLUTION 72.0
#define SVG_BUFFER_SIZE (8 * 1024)
typedef struct
{
gdouble resolution;
gint width;
gint height;
gdouble resolution;
gint width;
gint height;
gboolean import;
gboolean merge;
} SvgLoadVals;
static SvgLoadVals load_vals =
{
72.0, /* resolution */
0, /* width */
0 /* height */
SVG_DEFAULT_RESOLUTION,
0,
0,
FALSE,
FALSE
};
typedef struct
......@@ -62,7 +67,7 @@ typedef struct
static SvgLoadInterface load_interface =
{
FALSE /* run */
FALSE
};
......@@ -102,11 +107,14 @@ query (void)
{ GIMP_PDB_FLOAT, "resolution",
"Resolution to use for rendering the SVG (defaults to 72 dpi" },
{ GIMP_PDB_INT32, "width",
"Width (in pixels) to load the SVG in."
"Width (in pixels) to load the SVG in. "
"(0 for original width, a negative width to specify a maximum width)" },
{ GIMP_PDB_INT32, "height",
"Height (in pixels) to load the SVG in."
"(0 for original height, a negative width to specify a maximum height)"}
"Height (in pixels) to load the SVG in. "
"(0 for original height, a negative width to specify a maximum height)"},
{ GIMP_PDB_INT32, "paths",
"Whether to not import paths (0), import paths individually (1) "
"or merge all imported paths (2)" }
};
static GimpParamDef load_return_vals[] =
{
......@@ -141,7 +149,6 @@ run (const gchar *name,
static GimpParam values[2];
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_ID;
run_mode = param[0].data.d_int32;
......@@ -161,9 +168,14 @@ run (const gchar *name,
switch (run_mode)
{
case GIMP_RUN_NONINTERACTIVE:
if (nparams > 2) load_vals.resolution = param[3].data.d_float;
if (nparams > 3) load_vals.width = param[4].data.d_int32;
if (nparams > 4) load_vals.height = param[5].data.d_int32;
if (nparams > 3) load_vals.resolution = param[3].data.d_float;
if (nparams > 4) load_vals.width = param[4].data.d_int32;
if (nparams > 5) load_vals.height = param[5].data.d_int32;
if (nparams > 6)
{
load_vals.import = param[6].data.d_int32 != FALSE;
load_vals.merge = param[6].data.d_int32 > TRUE;
}
break;
case GIMP_RUN_INTERACTIVE:
......@@ -177,14 +189,20 @@ run (const gchar *name,
break;
}
if (load_vals.resolution < GIMP_MIN_RESOLUTION ||
load_vals.resolution > GIMP_MAX_RESOLUTION)
load_vals.resolution = SVG_DEFAULT_RESOLUTION;
if (status == GIMP_PDB_SUCCESS)
{
image_ID = load_image (param[1].data.d_string);
gimp_set_data ("file_svg_load", &load_vals, sizeof (load_vals));
gint32 image_ID = load_image (param[1].data.d_string);
if (image_ID != -1)
{
if (load_vals.import)
gimp_path_import (image_ID,
param[1].data.d_string, load_vals.merge);
*nreturn_vals = 2;
values[1].type = GIMP_PDB_IMAGE;
values[1].data.d_image = image_ID;
......@@ -193,6 +211,8 @@ run (const gchar *name,
{
status = GIMP_PDB_EXECUTION_ERROR;
}
gimp_set_data ("file_svg_load", &load_vals, sizeof (load_vals));
}
}
else
......@@ -211,7 +231,6 @@ load_image (const gchar *filename)
GimpDrawable *drawable;
GimpPixelRgn rgn;
GdkPixbuf *pixbuf;
gchar *status;
gchar *pixels;
gint width;
gint height;
......@@ -230,9 +249,7 @@ load_image (const gchar *filename)
gimp_quit ();
}
status = g_strdup_printf (_("Loading %s:"), filename);
gimp_progress_init (status);
g_free (status);
gimp_progress_init (_("Rendering SVG..."));
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
......@@ -433,14 +450,16 @@ load_dialog (const gchar *filename)
GtkWidget *dialog;
GtkWidget *frame;
GtkWidget *hbox;
GtkWidget *image;
GdkPixbuf *preview;
GtkWidget *table;
GtkWidget *abox;
GtkWidget *size;
GtkWidget *res;
GtkWidget *label;
GtkWidget *spinbutton;
GtkWidget *image;
GdkPixbuf *preview;
GtkWidget *toggle;
GtkWidget *toggle2;
GtkObject *adj;
GError *error = NULL;
......@@ -491,22 +510,29 @@ load_dialog (const gchar *filename)
gtk_container_add (GTK_CONTAINER (frame), hbox);
gtk_widget_show (hbox);
/* The SVG preview */
abox = gtk_alignment_new (0.0, 0.0, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (hbox), abox, FALSE, FALSE, 0);
gtk_widget_show (abox);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (abox), frame);
gtk_widget_show (frame);
image = gtk_image_new_from_pixbuf (preview);
gtk_container_add (GTK_CONTAINER (frame), image);
gtk_widget_show (image);
table = gtk_table_new (3, 3, FALSE);
table = gtk_table_new (3, 5, FALSE);
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_row_spacing (GTK_TABLE (table), 1, 4);
gtk_table_set_row_spacing (GTK_TABLE (table), 2, 4);
gtk_box_pack_start (GTK_BOX (hbox), table, TRUE, TRUE, 0);
gtk_widget_show (table);
/* Width and Height */
label = gtk_label_new (_("Width:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
......@@ -562,6 +588,7 @@ load_dialog (const gchar *filename)
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size), 1,
load_vals.resolution, FALSE);
/* Resolution */
label = gtk_label_new (_("Resolution:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
......@@ -591,6 +618,35 @@ load_dialog (const gchar *filename)
G_CALLBACK (load_resolution_callback),
size);
/* Path Import */
toggle = gtk_check_button_new_with_label (_("Import Paths"));
gtk_table_attach (GTK_TABLE (table), toggle, 1, 2, 3, 4,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (toggle);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), load_vals.import);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&load_vals.import);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_sensitive_update),
NULL);
toggle2 = gtk_check_button_new_with_label (_("Merge Imported Paths"));
gtk_table_attach (GTK_TABLE (table), toggle2, 1, 2, 4, 5,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_set_sensitive (toggle2, load_vals.import);
gtk_widget_show (toggle2);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle2), load_vals.merge);
g_signal_connect (toggle2, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&load_vals.merge);
g_object_set_data (G_OBJECT (toggle), "set_sensitive", toggle2);
gtk_widget_show (dialog);
gtk_main ();
......
......@@ -619,6 +619,31 @@ CODE
);
}
sub path_import {
$blurb = 'Import paths from an SVG file.';
$help = <<'HELP';
This procedure imports path from an SVG file. This is a temporary solution
until the new vectors PDB API is in place. Don't rely on this function
being available in future GIMP releases.
HELP
$author = $copyright = 'Sven Neumann';
$date = '2003';
@inargs = (
&std_image_arg,
{ name => 'filename', type => 'string', no_validate => 1,
desc => 'The name of the SVG file to import.' },
{ name => 'merge', type => 'boolean',
desc => 'Merge paths into a single vectors object' }
);
%invoke = (
headers => [ qw("vectors/gimpvectors-import.h") ],
code => 'success = gimp_vectors_import (gimage, filename, merge, NULL);'
);
}
@headers = qw(<string.h> "core/gimp.h" "core/gimpcontext.h" "core/gimplist.h"
"core/gimptoolinfo.h" "core/gimpimage-mask-select.h"
......@@ -630,7 +655,8 @@ CODE
path_get_points path_set_points
path_stroke_current path_get_point_at_dist
path_get_tattoo path_set_tattoo get_path_by_tattoo
path_get_locked path_set_locked path_to_selection);
path_get_locked path_set_locked path_to_selection
path_import);
%exports = (app => [@procs], lib => [@procs]);
$desc = 'Paths';
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment