1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
* (C) Copyright 2003 Dom Lachowicz <cinamod@hotmail.com>
22
* Largely rewritten in September 2003 by Sven Neumann <sven@gimp.org>
30
#include <librsvg/rsvg.h>
31
#include <librsvg/librsvg-features.h> /* for version check */
33
#include "libgimp/gimp.h"
34
#include "libgimp/gimpui.h"
36
#include "libgimp/stdplugins-intl.h"
39
#define LOAD_PROC "file-svg-load"
40
#define LOAD_THUMB_PROC "file-svg-load-thumb"
41
#define PLUG_IN_BINARY "file-svg"
42
#define SVG_VERSION "2.5.0"
43
#define SVG_DEFAULT_RESOLUTION 90.0
44
#define SVG_DEFAULT_SIZE 500
45
#define SVG_PREVIEW_SIZE 128
57
static SvgLoadVals load_vals =
59
SVG_DEFAULT_RESOLUTION,
67
static void query (void);
68
static void run (const gchar *name,
70
const GimpParam *param,
72
GimpParam **return_vals);
74
static gint32 load_image (const gchar *filename,
76
static GdkPixbuf * load_rsvg_pixbuf (const gchar *filename,
79
static gboolean load_rsvg_size (const gchar *filename,
82
static GimpPDBStatusType load_dialog (const gchar *filename,
86
const GimpPlugInInfo PLUG_IN_INFO =
100
static const GimpParamDef load_args[] =
102
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
103
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
104
{ GIMP_PDB_STRING, "raw-filename", "The name of the file to load" },
105
{ GIMP_PDB_FLOAT, "resolution",
106
"Resolution to use for rendering the SVG (defaults to 90 dpi)" },
107
{ GIMP_PDB_INT32, "width",
108
"Width (in pixels) to load the SVG in. "
109
"(0 for original width, a negative width to specify a maximum width)" },
110
{ GIMP_PDB_INT32, "height",
111
"Height (in pixels) to load the SVG in. "
112
"(0 for original height, a negative width to specify a maximum height)"},
113
{ GIMP_PDB_INT32, "paths",
114
"Whether to not import paths (0), import paths individually (1) "
115
"or merge all imported paths (2)" }
117
static const GimpParamDef load_return_vals[] =
119
{ GIMP_PDB_IMAGE, "image", "Output image" }
122
static const GimpParamDef thumb_args[] =
124
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
125
{ GIMP_PDB_INT32, "thumb-size", "Preferred thumbnail size" }
127
static const GimpParamDef thumb_return_vals[] =
129
{ GIMP_PDB_IMAGE, "image", "Thumbnail image" },
130
{ GIMP_PDB_INT32, "image-width", "Width of full-sized image" },
131
{ GIMP_PDB_INT32, "image-height", "Height of full-sized image" }
134
gimp_install_procedure (LOAD_PROC,
135
"Loads files in the SVG file format",
136
"Renders SVG files to raster graphics using librsvg.",
137
"Dom Lachowicz, Sven Neumann",
138
"Dom Lachowicz <cinamod@hotmail.com>",
143
G_N_ELEMENTS (load_args),
144
G_N_ELEMENTS (load_return_vals),
145
load_args, load_return_vals);
147
gimp_register_file_handler_mime (LOAD_PROC, "image/svg+xml");
148
gimp_register_magic_load_handler (LOAD_PROC,
150
"0,string,<?xml,0,string,<svg");
152
gimp_install_procedure (LOAD_THUMB_PROC,
153
"Loads a small preview from an SVG image",
155
"Dom Lachowicz, Sven Neumann",
156
"Dom Lachowicz <cinamod@hotmail.com>",
161
G_N_ELEMENTS (thumb_args),
162
G_N_ELEMENTS (thumb_return_vals),
163
thumb_args, thumb_return_vals);
165
gimp_register_thumbnail_loader (LOAD_PROC, LOAD_THUMB_PROC);
169
run (const gchar *name,
171
const GimpParam *param,
173
GimpParam **return_vals)
175
static GimpParam values[4];
176
GimpRunMode run_mode;
177
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
178
GError *error = NULL;
182
run_mode = param[0].data.d_int32;
185
*return_vals = values;
187
values[0].type = GIMP_PDB_STATUS;
188
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
190
/* MUST call this before any RSVG funcs */
193
if (strcmp (name, LOAD_PROC) == 0)
195
gimp_get_data (LOAD_PROC, &load_vals);
199
case GIMP_RUN_NONINTERACTIVE:
200
if (nparams > 3) load_vals.resolution = param[3].data.d_float;
201
if (nparams > 4) load_vals.width = param[4].data.d_int32;
202
if (nparams > 5) load_vals.height = param[5].data.d_int32;
205
load_vals.import = param[6].data.d_int32 != FALSE;
206
load_vals.merge = param[6].data.d_int32 > TRUE;
210
case GIMP_RUN_INTERACTIVE:
211
status = load_dialog (param[1].data.d_string, &error);
214
case GIMP_RUN_WITH_LAST_VALS:
218
/* Don't clamp this; insane values are probably not meant to be
219
* used as resolution anyway.
221
if (load_vals.resolution < GIMP_MIN_RESOLUTION ||
222
load_vals.resolution > GIMP_MAX_RESOLUTION)
224
load_vals.resolution = SVG_DEFAULT_RESOLUTION;
227
if (status == GIMP_PDB_SUCCESS)
229
const gchar *filename = param[1].data.d_string;
230
gint32 image_ID = load_image (filename, &error);
234
if (load_vals.import)
239
gimp_vectors_import_from_file (image_ID, filename,
240
load_vals.merge, TRUE,
241
&num_vectors, &vectors);
248
values[1].type = GIMP_PDB_IMAGE;
249
values[1].data.d_image = image_ID;
253
status = GIMP_PDB_EXECUTION_ERROR;
256
gimp_set_data (LOAD_PROC, &load_vals, sizeof (load_vals));
259
else if (strcmp (name, LOAD_THUMB_PROC) == 0)
263
status = GIMP_PDB_CALLING_ERROR;
267
const gchar *filename = param[0].data.d_string;
272
if (load_rsvg_size (filename, &load_vals, NULL))
274
width = load_vals.width;
275
height = load_vals.height;
278
load_vals.resolution = SVG_DEFAULT_RESOLUTION;
279
load_vals.width = - param[1].data.d_int32;
280
load_vals.height = - param[1].data.d_int32;
282
image_ID = load_image (filename, &error);
287
values[1].type = GIMP_PDB_IMAGE;
288
values[1].data.d_image = image_ID;
289
values[2].type = GIMP_PDB_INT32;
290
values[2].data.d_int32 = width;
291
values[3].type = GIMP_PDB_INT32;
292
values[3].data.d_int32 = height;
296
status = GIMP_PDB_EXECUTION_ERROR;
302
status = GIMP_PDB_CALLING_ERROR;
305
if (status != GIMP_PDB_SUCCESS && error)
308
values[1].type = GIMP_PDB_STRING;
309
values[1].data.d_string = error->message;
312
values[0].data.d_status = status;
316
load_image (const gchar *filename,
324
GError *error = NULL;
326
pixbuf = load_rsvg_pixbuf (filename, &load_vals, &error);
330
/* Do not rely on librsvg setting GError on failure! */
331
g_set_error (load_error,
332
error ? error->domain : 0, error ? error->code : 0,
333
_("Could not open '%s' for reading: %s"),
334
gimp_filename_to_utf8 (filename),
335
error ? error->message : _("Unknown reason"));
336
g_clear_error (&error);
341
gimp_progress_init (_("Rendering SVG"));
343
width = gdk_pixbuf_get_width (pixbuf);
344
height = gdk_pixbuf_get_height (pixbuf);
346
image = gimp_image_new (width, height, GIMP_RGB);
347
gimp_image_undo_disable (image);
349
gimp_image_set_filename (image, filename);
350
gimp_image_set_resolution (image,
351
load_vals.resolution, load_vals.resolution);
353
layer = gimp_layer_new_from_pixbuf (image, _("Rendered SVG"), pixbuf,
354
100, GIMP_NORMAL_MODE, 0.0, 1.0);
355
gimp_image_add_layer (image, layer, 0);
357
gimp_image_undo_enable (image);
362
/* This is the callback used from load_rsvg_pixbuf(). */
364
load_set_size_callback (gint *width,
368
SvgLoadVals *vals = data;
370
if (*width < 1 || *height < 1)
372
*width = SVG_DEFAULT_SIZE;
373
*height = SVG_DEFAULT_SIZE;
376
if (!vals->width || !vals->height)
379
/* either both arguments negative or none */
380
if ((vals->width * vals->height) < 0)
385
*width = vals->width;
386
*height = vals->height;
392
gdouble aspect = (gdouble) vals->width / (gdouble) vals->height;
394
if (aspect > (w / h))
396
*height = abs (vals->height);
397
*width = (gdouble) abs (vals->width) * (w / h) + 0.5;
401
*width = abs (vals->width);
402
*height = (gdouble) abs (vals->height) / (w / h) + 0.5;
405
vals->width = *width;
406
vals->height = *height;
411
load_rsvg_handle_new (gdouble xres,
414
RsvgHandle *handle = rsvg_handle_new ();
416
#if (((LIBRSVG_MAJOR_VERSION == 2) && (LIBRSVG_MINOR_VERSION == 13) && \
417
((LIBRSVG_MICRO_VERSION == 0) || \
418
(LIBRSVG_MICRO_VERSION == 1) || \
419
(LIBRSVG_MICRO_VERSION == 2))) || \
420
((LIBRSVG_MAJOR_VERSION == 2) && (LIBRSVG_MINOR_VERSION == 11) && \
421
(LIBRSVG_MICRO_VERSION == 0)))
422
rsvg_handle_set_dpi (handle, xres, yres);
424
rsvg_handle_set_dpi_x_y (handle, xres, yres);
430
/* This function renders a pixbuf from an SVG file according to vals. */
432
load_rsvg_pixbuf (const gchar *filename,
436
GdkPixbuf *pixbuf = NULL;
440
GIOStatus status = G_IO_STATUS_NORMAL;
441
gboolean success = TRUE;
443
io = g_io_channel_new_file (filename, "r", error);
447
g_io_channel_set_encoding (io, NULL, NULL);
449
handle = load_rsvg_handle_new (vals->resolution, vals->resolution);
451
/* set the base URI so that librsvg can resolve relative paths */
452
uri = g_filename_to_uri (filename, NULL, NULL);
455
gchar *p = strrchr (uri, '/');
460
rsvg_handle_set_base_uri (handle, uri);
464
rsvg_handle_set_size_callback (handle, load_set_size_callback, vals, NULL);
466
while (success && status != G_IO_STATUS_EOF)
471
status = g_io_channel_read_chars (io, buf, sizeof (buf), &len, error);
475
case G_IO_STATUS_ERROR:
478
case G_IO_STATUS_EOF:
479
success = rsvg_handle_close (handle, error);
481
case G_IO_STATUS_NORMAL:
482
success = rsvg_handle_write (handle,
483
(const guchar *) buf, len, error);
485
case G_IO_STATUS_AGAIN:
490
g_io_channel_unref (io);
493
pixbuf = rsvg_handle_get_pixbuf (handle);
495
rsvg_handle_free (handle);
500
static GtkWidget *size_label = NULL;
502
/* This function retrieves the pixel size from an SVG file. Parsing
503
* stops after the first chunk that provided the parser with enough
504
* information to determine the size. This is usally the opening
505
* <svg> element and should thus be in the first chunk (1024 bytes).
508
load_rsvg_size (const gchar *filename,
514
GIOStatus status = G_IO_STATUS_NORMAL;
515
gboolean success = TRUE;
516
gboolean done = FALSE;
518
io = g_io_channel_new_file (filename, "r", error);
522
g_io_channel_set_encoding (io, NULL, NULL);
524
handle = load_rsvg_handle_new (vals->resolution, vals->resolution);
526
vals->width = SVG_DEFAULT_SIZE;
527
vals->height = SVG_DEFAULT_SIZE;
529
while (success && status != G_IO_STATUS_EOF && (! done))
533
RsvgDimensionData dim = { 0, 0, 0.0, 0.0 };
535
status = g_io_channel_read_chars (io, buf, sizeof (buf), &len, error);
539
case G_IO_STATUS_ERROR:
542
case G_IO_STATUS_EOF:
543
success = rsvg_handle_close (handle, error);
545
case G_IO_STATUS_NORMAL:
546
success = rsvg_handle_write (handle,
547
(const guchar *) buf, len, error);
548
rsvg_handle_get_dimensions (handle, &dim);
550
if (dim.width > 0 && dim.height > 0)
552
vals->width = dim.width;
553
vals->height = dim.height;
558
case G_IO_STATUS_AGAIN:
567
gchar *text = g_strdup_printf (_("%d × %d"),
568
vals->width, vals->height);
569
gtk_label_set_text (GTK_LABEL (size_label), text);
574
gtk_label_set_text (GTK_LABEL (size_label),
575
_("SVG file does not\nspecify a size!"));
579
g_io_channel_unref (io);
580
rsvg_handle_free (handle);
582
if (vals->width < 1) vals->width = 1;
583
if (vals->height < 1) vals->height = 1;
591
static GimpSizeEntry *size = NULL;
592
static GtkObject *xadj = NULL;
593
static GtkObject *yadj = NULL;
594
static GtkWidget *constrain = NULL;
595
static gdouble ratio_x = 1.0;
596
static gdouble ratio_y = 1.0;
597
static gint svg_width = 0;
598
static gint svg_height = 0;
600
static void load_dialog_set_ratio (gdouble x,
605
load_dialog_size_callback (GtkWidget *widget,
608
if (gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (constrain)))
610
gdouble x = gimp_size_entry_get_refval (size, 0) / (gdouble) svg_width;
611
gdouble y = gimp_size_entry_get_refval (size, 1) / (gdouble) svg_height;
615
load_dialog_set_ratio (x, x);
617
else if (y != ratio_y)
619
load_dialog_set_ratio (y, y);
625
load_dialog_ratio_callback (GtkAdjustment *adj,
628
gdouble x = gtk_adjustment_get_value (GTK_ADJUSTMENT (xadj));
629
gdouble y = gtk_adjustment_get_value (GTK_ADJUSTMENT (yadj));
631
if (gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (constrain)))
639
load_dialog_set_ratio (x, y);
643
load_dialog_resolution_callback (GimpSizeEntry *res,
644
const gchar *filename)
646
SvgLoadVals vals = { 0.0, 0, 0 };
648
load_vals.resolution = vals.resolution = gimp_size_entry_get_refval (res, 0);
650
if (!load_rsvg_size (filename, &vals, NULL))
653
svg_width = vals.width;
654
svg_height = vals.height;
656
load_dialog_set_ratio (ratio_x, ratio_y);
660
load_dialog_set_ratio (gdouble x,
666
g_signal_handlers_block_by_func (size, load_dialog_size_callback, NULL);
668
gimp_size_entry_set_refval (size, 0, svg_width * x);
669
gimp_size_entry_set_refval (size, 1, svg_height * y);
671
g_signal_handlers_unblock_by_func (size, load_dialog_size_callback, NULL);
673
g_signal_handlers_block_by_func (xadj, load_dialog_ratio_callback, NULL);
674
g_signal_handlers_block_by_func (yadj, load_dialog_ratio_callback, NULL);
676
gtk_adjustment_set_value (GTK_ADJUSTMENT (xadj), x);
677
gtk_adjustment_set_value (GTK_ADJUSTMENT (yadj), y);
679
g_signal_handlers_unblock_by_func (xadj, load_dialog_ratio_callback, NULL);
680
g_signal_handlers_unblock_by_func (yadj, load_dialog_ratio_callback, NULL);
683
static GimpPDBStatusType
684
load_dialog (const gchar *filename,
698
GtkWidget *spinbutton;
703
GError *error = NULL;
706
SVG_DEFAULT_RESOLUTION,
711
preview = load_rsvg_pixbuf (filename, &vals, &error);
715
/* Do not rely on librsvg setting GError on failure! */
716
g_set_error (load_error,
717
error ? error->domain : 0, error ? error->code : 0,
718
_("Could not open '%s' for reading: %s"),
719
gimp_filename_to_utf8 (filename),
720
error ? error->message : _("Unknown reason"));
721
g_clear_error (&error);
723
return GIMP_PDB_EXECUTION_ERROR;
726
gimp_ui_init (PLUG_IN_BINARY, FALSE);
728
/* Scalable Vector Graphics is SVG, should perhaps not be translated */
729
dialog = gimp_dialog_new (_("Render Scalable Vector Graphics"),
732
gimp_standard_help_func, LOAD_PROC,
734
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
735
GTK_STOCK_OK, GTK_RESPONSE_OK,
739
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
744
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
746
gimp_window_set_transient (GTK_WINDOW (dialog));
748
hbox = gtk_hbox_new (FALSE, 12);
749
gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
750
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox,
752
gtk_widget_show (hbox);
754
/* The SVG preview */
755
vbox = gtk_vbox_new (FALSE, 6);
756
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
757
gtk_widget_show (vbox);
759
abox = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
760
gtk_box_pack_start (GTK_BOX (vbox), abox, FALSE, FALSE, 0);
761
gtk_widget_show (abox);
763
frame = gtk_frame_new (NULL);
764
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
765
gtk_container_add (GTK_CONTAINER (abox), frame);
766
gtk_widget_show (frame);
768
image = gtk_image_new_from_pixbuf (preview);
769
gtk_container_add (GTK_CONTAINER (frame), image);
770
gtk_widget_show (image);
772
size_label = gtk_label_new (NULL);
773
gtk_label_set_justify (GTK_LABEL (size_label), GTK_JUSTIFY_CENTER);
774
gtk_misc_set_alignment (GTK_MISC (size_label), 0.5, 0.0);
775
gtk_box_pack_start (GTK_BOX (vbox), size_label, TRUE, TRUE, 4);
776
gtk_widget_show (size_label);
778
/* query the initial size after the size label is created */
779
vals.resolution = load_vals.resolution;
781
load_rsvg_size (filename, &vals, NULL);
783
svg_width = vals.width;
784
svg_height = vals.height;
786
table = gtk_table_new (7, 3, FALSE);
787
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
788
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
789
gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
790
gtk_table_set_row_spacing (GTK_TABLE (table), 2, 2);
791
gtk_box_pack_start (GTK_BOX (hbox), table, TRUE, TRUE, 0);
792
gtk_widget_show (table);
794
/* Width and Height */
795
label = gtk_label_new (_("Width:"));
796
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
797
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
798
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
799
gtk_widget_show (label);
801
label = gtk_label_new (_("Height:"));
802
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
803
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
804
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
805
gtk_widget_show (label);
807
hbox = gtk_hbox_new (FALSE, 0);
808
gtk_table_attach (GTK_TABLE (table), hbox, 1, 2, 0, 1,
809
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
810
gtk_widget_show (hbox);
812
spinbutton = gimp_spin_button_new (&adj, 1, 1, 1, 1, 10, 0, 1, 2);
813
gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 10);
814
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
815
gtk_widget_show (spinbutton);
817
hbox = gtk_hbox_new (FALSE, 0);
818
gtk_table_attach (GTK_TABLE (table), hbox, 1, 2, 1, 2,
819
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
820
gtk_widget_show (hbox);
822
size = GIMP_SIZE_ENTRY (gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a",
823
TRUE, FALSE, FALSE, 10,
824
GIMP_SIZE_ENTRY_UPDATE_SIZE));
825
gtk_table_set_col_spacing (GTK_TABLE (size), 1, 6);
827
gimp_size_entry_add_field (size, GTK_SPIN_BUTTON (spinbutton), NULL);
829
gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (size), FALSE, FALSE, 0);
830
gtk_widget_show (GTK_WIDGET (size));
832
gimp_size_entry_set_refval_boundaries (size, 0,
834
GIMP_MAX_IMAGE_SIZE);
835
gimp_size_entry_set_refval_boundaries (size, 1,
837
GIMP_MAX_IMAGE_SIZE);
839
gimp_size_entry_set_refval (size, 0, svg_width);
840
gimp_size_entry_set_refval (size, 1, svg_height);
842
gimp_size_entry_set_resolution (size, 0, load_vals.resolution, FALSE);
843
gimp_size_entry_set_resolution (size, 1, load_vals.resolution, FALSE);
845
g_signal_connect (size, "value-changed",
846
G_CALLBACK (load_dialog_size_callback),
850
hbox = gtk_hbox_new (FALSE, 0);
851
gtk_table_attach (GTK_TABLE (table), hbox, 1, 2, 2, 4,
852
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
853
gtk_widget_show (hbox);
855
table2 = gtk_table_new (2, 2, FALSE);
856
gtk_table_set_col_spacing (GTK_TABLE (table2), 0, 2);
857
gtk_table_set_row_spacing (GTK_TABLE (table2), 0, 4);
858
gtk_box_pack_start (GTK_BOX (hbox), table2, FALSE, FALSE, 0);
861
gimp_spin_button_new (&xadj,
863
(gdouble) GIMP_MIN_IMAGE_SIZE / (gdouble) svg_width,
864
(gdouble) GIMP_MAX_IMAGE_SIZE / (gdouble) svg_width,
867
gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 10);
868
gtk_table_attach_defaults (GTK_TABLE (table2), spinbutton, 0, 1, 0, 1);
869
gtk_widget_show (spinbutton);
871
g_signal_connect (xadj, "value-changed",
872
G_CALLBACK (load_dialog_ratio_callback),
875
label = gtk_label_new_with_mnemonic (_("_X ratio:"));
876
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
877
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
878
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
879
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
880
gtk_widget_show (label);
883
gimp_spin_button_new (&yadj,
885
(gdouble) GIMP_MIN_IMAGE_SIZE / (gdouble) svg_height,
886
(gdouble) GIMP_MAX_IMAGE_SIZE / (gdouble) svg_height,
889
gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 10);
890
gtk_table_attach_defaults (GTK_TABLE (table2), spinbutton, 0, 1, 1, 2);
891
gtk_widget_show (spinbutton);
893
g_signal_connect (yadj, "value-changed",
894
G_CALLBACK (load_dialog_ratio_callback),
897
label = gtk_label_new_with_mnemonic (_("_Y ratio:"));
898
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
899
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
900
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4,
901
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
902
gtk_widget_show (label);
904
/* the constrain ratio chainbutton */
905
constrain = gimp_chain_button_new (GIMP_CHAIN_RIGHT);
906
gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (constrain), TRUE);
907
gtk_table_attach_defaults (GTK_TABLE (table2), constrain, 1, 2, 0, 2);
908
gtk_widget_show (constrain);
910
gimp_help_set_help_data (GIMP_CHAIN_BUTTON (constrain)->button,
911
_("Constrain aspect ratio"), NULL);
913
gtk_widget_show (table2);
916
label = gtk_label_new (_("Resolution:"));
917
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
918
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 4, 5,
919
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
920
gtk_widget_show (label);
922
res = gimp_size_entry_new (1, GIMP_UNIT_INCH, _("pixels/%a"),
923
FALSE, FALSE, FALSE, 10,
924
GIMP_SIZE_ENTRY_UPDATE_RESOLUTION);
925
gtk_table_set_col_spacing (GTK_TABLE (res), 1, 6);
927
gtk_table_attach (GTK_TABLE (table), res, 1, 2, 4, 5,
928
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
929
gtk_widget_show (res);
931
/* don't let the resolution become too small, librsvg tends to
932
crash with very small resolutions */
933
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (res), 0,
934
5.0, GIMP_MAX_RESOLUTION);
935
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (res), 0, load_vals.resolution);
937
g_signal_connect (res, "value-changed",
938
G_CALLBACK (load_dialog_resolution_callback),
939
(gpointer) filename);
942
toggle = gtk_check_button_new_with_mnemonic (_("Import _paths"));
943
gtk_table_attach (GTK_TABLE (table), toggle, 0, 2, 5, 6,
944
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
945
gtk_widget_show (toggle);
947
gimp_help_set_help_data (toggle,
948
_("Import path elements of the SVG so they "
949
"can be used with the GIMP path tool"),
952
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), load_vals.import);
953
g_signal_connect (toggle, "toggled",
954
G_CALLBACK (gimp_toggle_button_update),
957
g_signal_connect (toggle, "toggled",
958
G_CALLBACK (gimp_toggle_button_sensitive_update),
961
toggle2 = gtk_check_button_new_with_mnemonic (_("Merge imported paths"));
962
gtk_table_attach (GTK_TABLE (table), toggle2, 0, 2, 6, 7,
963
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
964
gtk_widget_set_sensitive (toggle2, load_vals.import);
965
gtk_widget_show (toggle2);
967
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle2), load_vals.merge);
968
g_signal_connect (toggle2, "toggled",
969
G_CALLBACK (gimp_toggle_button_update),
972
g_object_set_data (G_OBJECT (toggle), "set_sensitive", toggle2);
975
gtk_widget_show (dialog);
977
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
981
load_vals.width = ROUND (gimp_size_entry_get_refval (size, 0));
982
load_vals.height = ROUND (gimp_size_entry_get_refval (size, 1));
985
gtk_widget_destroy (dialog);
987
return run ? GIMP_PDB_SUCCESS : GIMP_PDB_CANCEL;