~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/common/svg.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
16
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
17
 */
18
18
 
19
 
/* SVG loader for The GIMP
 
19
/* SVG loader plug-in
20
20
 * (C) Copyright 2003  Dom Lachowicz <cinamod@hotmail.com>
21
21
 *
22
22
 * Largely rewritten in September 2003 by Sven Neumann <sven@gimp.org>
30
30
#include <librsvg/rsvg.h>
31
31
#include <librsvg/librsvg-features.h>  /* for version check */
32
32
 
33
 
#include <gtk/gtk.h>
34
 
 
35
33
#include "libgimp/gimp.h"
36
34
#include "libgimp/gimpui.h"
37
35
 
38
36
#include "libgimp/stdplugins-intl.h"
39
37
 
40
38
 
 
39
#define LOAD_PROC               "file-svg-load"
 
40
#define LOAD_THUMB_PROC         "file-svg-load-thumb"
 
41
#define PLUG_IN_BINARY          "svg"
41
42
#define SVG_VERSION             "2.5.0"
42
43
#define SVG_DEFAULT_RESOLUTION  90.0
43
44
#define SVG_DEFAULT_SIZE        500
80
81
static gboolean    load_dialog       (const gchar  *filename);
81
82
 
82
83
 
83
 
GimpPlugInInfo PLUG_IN_INFO =
 
84
const GimpPlugInInfo PLUG_IN_INFO =
84
85
{
85
86
  NULL,
86
87
  NULL,
94
95
static void
95
96
query (void)
96
97
{
97
 
  static GimpParamDef load_args[] =
 
98
  static const GimpParamDef load_args[] =
98
99
  {
99
 
    { GIMP_PDB_INT32,  "run_mode",     "Interactive, non-interactive"        },
 
100
    { GIMP_PDB_INT32,  "run-mode",     "Interactive, non-interactive"        },
100
101
    { GIMP_PDB_STRING, "filename",     "The name of the file to load"        },
101
 
    { GIMP_PDB_STRING, "raw_filename", "The name of the file to load"        },
 
102
    { GIMP_PDB_STRING, "raw-filename", "The name of the file to load"        },
102
103
    { GIMP_PDB_FLOAT,  "resolution",
103
 
      "Resolution to use for rendering the SVG (defaults to 72 dpi"          },
 
104
      "Resolution to use for rendering the SVG (defaults to 90 dpi)"         },
104
105
    { GIMP_PDB_INT32,  "width",
105
106
      "Width (in pixels) to load the SVG in. "
106
107
      "(0 for original width, a negative width to specify a maximum width)"  },
111
112
      "Whether to not import paths (0), import paths individually (1) "
112
113
      "or merge all imported paths (2)"                                      }
113
114
  };
114
 
  static GimpParamDef load_return_vals[] =
 
115
  static const GimpParamDef load_return_vals[] =
115
116
  {
116
117
    { GIMP_PDB_IMAGE,  "image",        "Output image" }
117
118
  };
118
119
 
119
 
  static GimpParamDef thumb_args[] =
 
120
  static const GimpParamDef thumb_args[] =
120
121
  {
121
122
    { GIMP_PDB_STRING, "filename",     "The name of the file to load"  },
122
 
    { GIMP_PDB_INT32,  "thumb_size",   "Preferred thumbnail size"      }
 
123
    { GIMP_PDB_INT32,  "thumb-size",   "Preferred thumbnail size"      }
123
124
  };
124
 
  static GimpParamDef thumb_return_vals[] =
 
125
  static const GimpParamDef thumb_return_vals[] =
125
126
  {
126
127
    { GIMP_PDB_IMAGE,  "image",        "Thumbnail image"               },
127
 
    { GIMP_PDB_INT32,  "image_width",  "Width of full-sized image"     },
128
 
    { GIMP_PDB_INT32,  "image_height", "Height of full-sized image"    }
 
128
    { GIMP_PDB_INT32,  "image-width",  "Width of full-sized image"     },
 
129
    { GIMP_PDB_INT32,  "image-height", "Height of full-sized image"    }
129
130
  };
130
131
 
131
 
  gimp_install_procedure ("file_svg_load",
 
132
  gimp_install_procedure (LOAD_PROC,
132
133
                          "Loads files in the SVG file format",
133
134
                          "Renders SVG files to raster graphics using librsvg.",
134
135
                          "Dom Lachowicz, Sven Neumann",
135
136
                          "Dom Lachowicz <cinamod@hotmail.com>",
136
137
                          SVG_VERSION,
137
 
                          N_("Scalable SVG image"),
138
 
                          NULL,
 
138
                          N_("SVG image"),
 
139
                          NULL,
139
140
                          GIMP_PLUGIN,
140
141
                          G_N_ELEMENTS (load_args),
141
142
                          G_N_ELEMENTS (load_return_vals),
142
143
                          load_args, load_return_vals);
143
144
 
144
 
  gimp_register_file_handler_mime ("file_svg_load", "image/svg+xml");
145
 
  gimp_register_magic_load_handler ("file_svg_load",
146
 
                                    "svg", "",
147
 
                                    "0,string,<?xml,0,string,<svg");
 
145
  gimp_register_file_handler_mime (LOAD_PROC, "image/svg+xml");
 
146
  gimp_register_magic_load_handler (LOAD_PROC,
 
147
                                    "svg", "",
 
148
                                    "0,string,<?xml,0,string,<svg");
148
149
 
149
 
  gimp_install_procedure ("file_svg_load_thumb",
 
150
  gimp_install_procedure (LOAD_THUMB_PROC,
150
151
                          "Loads a small preview from an SVG image",
151
152
                          "",
152
153
                          "Dom Lachowicz, Sven Neumann",
153
154
                          "Dom Lachowicz <cinamod@hotmail.com>",
154
155
                          SVG_VERSION,
155
 
                          NULL,
156
 
                          NULL,
 
156
                          NULL,
 
157
                          NULL,
157
158
                          GIMP_PLUGIN,
158
159
                          G_N_ELEMENTS (thumb_args),
159
160
                          G_N_ELEMENTS (thumb_return_vals),
160
161
                          thumb_args, thumb_return_vals);
161
162
 
162
 
  gimp_register_thumbnail_loader ("file_svg_load", "file_svg_load_thumb");
 
163
  gimp_register_thumbnail_loader (LOAD_PROC, LOAD_THUMB_PROC);
163
164
}
164
165
 
165
166
static void
186
187
  /* MUST call this before any RSVG funcs */
187
188
  g_type_init ();
188
189
 
189
 
  if (strcmp (name, "file_svg_load") == 0)
 
190
  if (strcmp (name, LOAD_PROC) == 0)
190
191
    {
191
 
      gimp_get_data ("file_svg_load", &load_vals);
 
192
      gimp_get_data (LOAD_PROC, &load_vals);
192
193
 
193
194
      switch (run_mode)
194
195
        {
204
205
          break;
205
206
 
206
207
        case GIMP_RUN_INTERACTIVE:
207
 
          if (!load_dialog (param[1].data.d_string))
208
 
            status = GIMP_PDB_CANCEL;
 
208
          if (!load_dialog (param[1].data.d_string))
 
209
            status = GIMP_PDB_CANCEL;
209
210
          break;
210
211
 
211
212
        case GIMP_RUN_WITH_LAST_VALS:
212
213
          break;
213
 
        }
 
214
        }
214
215
 
 
216
      /* Don't clamp this; insane values are probably not meant to be
 
217
       * used as resolution anyway.
 
218
       */
215
219
      if (load_vals.resolution < GIMP_MIN_RESOLUTION ||
216
220
          load_vals.resolution > GIMP_MAX_RESOLUTION)
217
221
        {
219
223
        }
220
224
 
221
225
      if (status == GIMP_PDB_SUCCESS)
222
 
        {
223
 
          const gchar *filename = param[1].data.d_string;
 
226
        {
 
227
          const gchar *filename = param[1].data.d_string;
224
228
          gint32       image_ID = load_image (filename);
225
229
 
226
 
          if (image_ID != -1)
227
 
            {
 
230
          if (image_ID != -1)
 
231
            {
228
232
              if (load_vals.import)
229
 
                gimp_path_import (image_ID, filename, load_vals.merge, TRUE);
230
 
 
231
 
              *nreturn_vals = 2;
232
 
              values[1].type         = GIMP_PDB_IMAGE;
233
 
              values[1].data.d_image = image_ID;
234
 
            }
235
 
          else
 
233
                {
 
234
                  gint32 *vectors;
 
235
                  gint    num_vectors;
 
236
 
 
237
                  gimp_vectors_import_from_file (image_ID, filename,
 
238
                                                 load_vals.merge, TRUE,
 
239
                                                 &num_vectors, &vectors);
 
240
                  if (num_vectors > 0)
 
241
                    g_free (vectors);
 
242
                }
 
243
 
 
244
              *nreturn_vals = 2;
 
245
 
 
246
              values[1].type         = GIMP_PDB_IMAGE;
 
247
              values[1].data.d_image = image_ID;
 
248
            }
 
249
          else
236
250
            {
237
251
              status = GIMP_PDB_EXECUTION_ERROR;
238
252
            }
239
253
 
240
 
          gimp_set_data ("file_svg_load", &load_vals, sizeof (load_vals));
 
254
          gimp_set_data (LOAD_PROC, &load_vals, sizeof (load_vals));
241
255
        }
242
256
    }
243
 
  else if (strcmp (name, "file_svg_load_thumb") == 0)
 
257
  else if (strcmp (name, LOAD_THUMB_PROC) == 0)
244
258
    {
245
259
      if (nparams < 2)
246
260
        {
267
281
 
268
282
          if (image_ID != -1)
269
283
            {
270
 
              *nreturn_vals = 4;
271
 
              values[1].type         = GIMP_PDB_IMAGE;
272
 
              values[1].data.d_image = image_ID;
273
 
              values[2].type         = GIMP_PDB_INT32;
274
 
              values[2].data.d_int32 = width;
275
 
              values[3].type         = GIMP_PDB_INT32;
276
 
              values[3].data.d_int32 = height;
 
284
              *nreturn_vals = 4;
 
285
              values[1].type         = GIMP_PDB_IMAGE;
 
286
              values[1].data.d_image = image_ID;
 
287
              values[2].type         = GIMP_PDB_INT32;
 
288
              values[2].data.d_int32 = width;
 
289
              values[3].type         = GIMP_PDB_INT32;
 
290
              values[3].data.d_int32 = height;
277
291
            }
278
292
          else
279
293
            {
293
307
load_image (const gchar *filename)
294
308
{
295
309
  gint32        image;
296
 
  gint32        layer;
297
 
  GimpDrawable *drawable;
298
 
  GimpPixelRgn  rgn;
 
310
  gint32        layer;
299
311
  GdkPixbuf    *pixbuf;
300
 
  gchar        *pixels;
301
312
  gint          width;
302
313
  gint          height;
303
 
  gint          rowstride;
304
 
  gint          bpp;
305
 
  gpointer      pr;
306
314
  GError       *error = NULL;
307
315
 
308
316
  pixbuf = load_rsvg_pixbuf (filename, &load_vals, &error);
312
320
      g_message (_("Could not open '%s' for reading: %s"),
313
321
                 gimp_filename_to_utf8 (filename),
314
322
                 error ? error->message : _("Unknown reason"));
315
 
      gimp_quit ();
 
323
      return -1;
316
324
    }
317
325
 
318
 
  gimp_progress_init (_("Rendering SVG..."));
 
326
  gimp_progress_init (_("Rendering SVG"));
319
327
 
320
328
  width  = gdk_pixbuf_get_width (pixbuf);
321
329
  height = gdk_pixbuf_get_height (pixbuf);
322
330
 
323
331
  image = gimp_image_new (width, height, GIMP_RGB);
 
332
  gimp_image_undo_disable (image);
 
333
 
324
334
  gimp_image_set_filename (image, filename);
325
335
  gimp_image_set_resolution (image,
326
336
                             load_vals.resolution, load_vals.resolution);
327
337
 
328
 
  layer = gimp_layer_new (image, _("Rendered SVG"), width, height,
329
 
                          GIMP_RGBA_IMAGE, 100, GIMP_NORMAL_MODE);
330
 
 
331
 
  drawable = gimp_drawable_get (layer);
332
 
 
333
 
  gimp_pixel_rgn_init (&rgn, drawable, 0, 0, width, height, TRUE, FALSE);
334
 
 
335
 
  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
336
 
  bpp       = gdk_pixbuf_get_n_channels (pixbuf);
337
 
  pixels    = gdk_pixbuf_get_pixels (pixbuf);
338
 
 
339
 
  g_assert (bpp == rgn.bpp);
340
 
 
341
 
  for (pr = gimp_pixel_rgns_register (1, &rgn);
342
 
       pr != NULL;
343
 
       pr = gimp_pixel_rgns_process (pr))
344
 
    {
345
 
      const guchar *src;
346
 
      guchar       *dest;
347
 
      gint          y;
348
 
 
349
 
      src  = pixels + rgn.y * rowstride + rgn.x * bpp;
350
 
      dest = rgn.data;
351
 
 
352
 
      for (y = 0; y < rgn.h; y++)
353
 
        {
354
 
          memcpy (dest, src, rgn.w * rgn.bpp);
355
 
 
356
 
          src  += rowstride;
357
 
          dest += rgn.rowstride;
358
 
        }
359
 
    }
360
 
 
361
 
  gimp_drawable_detach (drawable);
362
 
  g_object_unref (pixbuf);
363
 
 
364
 
  gimp_progress_update (1.0);
365
 
 
 
338
  layer = gimp_layer_new_from_pixbuf (image, _("Rendered SVG"), pixbuf,
 
339
                                      100, GIMP_NORMAL_MODE, 0.0, 1.0);
366
340
  gimp_image_add_layer (image, layer, 0);
367
341
 
 
342
  gimp_image_undo_enable (image);
 
343
 
368
344
  return image;
369
345
}
370
346
 
460
436
 
461
437
  while (success && status != G_IO_STATUS_EOF)
462
438
    {
463
 
      guchar buf[8192];
 
439
      gchar  buf[8192];
464
440
      gsize  len;
465
441
 
466
442
      status = g_io_channel_read_chars (io, buf, sizeof (buf), &len, error);
474
450
          success = rsvg_handle_close (handle, error);
475
451
          break;
476
452
        case G_IO_STATUS_NORMAL:
477
 
          success = rsvg_handle_write (handle, buf, len, error);
 
453
          success = rsvg_handle_write (handle,
 
454
                                       (const guchar *) buf, len, error);
478
455
          break;
479
456
        case G_IO_STATUS_AGAIN:
480
457
          break;
514
491
    {
515
492
      if (size_label)
516
493
        {
517
 
          gchar *text = g_strdup_printf (_("%d x %d"), *width, *height);
 
494
          gchar *text = g_strdup_printf (_("%d × %d"), *width, *height);
518
495
 
519
496
          gtk_label_set_text (GTK_LABEL (size_label), text);
520
497
          g_free (text);
555
532
 
556
533
  while (success && status != G_IO_STATUS_EOF && vals->resolution > 0.0)
557
534
    {
558
 
      guchar buf[1024];
 
535
      gchar  buf[1024];
559
536
      gsize  len;
560
537
 
561
538
      status = g_io_channel_read_chars (io, buf, sizeof (buf), &len, error);
569
546
          success = rsvg_handle_close (handle, error);
570
547
          break;
571
548
        case G_IO_STATUS_NORMAL:
572
 
          success = rsvg_handle_write (handle, buf, len, error);
 
549
          success = rsvg_handle_write (handle,
 
550
                                       (const guchar *) buf, len, error);
573
551
          break;
574
552
        case G_IO_STATUS_AGAIN:
575
553
          break;
715
693
      return FALSE;
716
694
    }
717
695
 
718
 
  gimp_ui_init ("svg", FALSE);
 
696
  gimp_ui_init (PLUG_IN_BINARY, FALSE);
719
697
 
720
698
  /* Scalable Vector Graphics is SVG, should perhaps not be translated */
721
 
  dialog = gimp_dialog_new (_("Render Scalable Vector Graphics"), "svg",
 
699
  dialog = gimp_dialog_new (_("Render Scalable Vector Graphics"),
 
700
                            PLUG_IN_BINARY,
722
701
                            NULL, 0,
723
 
                            gimp_standard_help_func, "file-svg-load",
 
702
                            gimp_standard_help_func, LOAD_PROC,
724
703
 
725
704
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
726
705
                            GTK_STOCK_OK,     GTK_RESPONSE_OK,
727
706
 
728
707
                            NULL);
729
708
 
 
709
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
710
                                           GTK_RESPONSE_OK,
 
711
                                           GTK_RESPONSE_CANCEL,
 
712
                                           -1);
 
713
 
730
714
  gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
731
715
 
732
716
  hbox = gtk_hbox_new (FALSE, 12);
826
810
  gimp_size_entry_set_resolution (size, 0, load_vals.resolution, FALSE);
827
811
  gimp_size_entry_set_resolution (size, 1, load_vals.resolution, FALSE);
828
812
 
829
 
  g_signal_connect (size, "value_changed",
830
 
                    G_CALLBACK (load_dialog_size_callback),
 
813
  g_signal_connect (size, "value-changed",
 
814
                    G_CALLBACK (load_dialog_size_callback),
831
815
                    NULL);
832
816
 
833
817
  /*  Scale ratio  */
834
818
  hbox = gtk_hbox_new (FALSE, 0);
835
819
  gtk_table_attach (GTK_TABLE (table), hbox, 1, 2, 2, 4,
836
 
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
 
820
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
837
821
  gtk_widget_show (hbox);
838
822
 
839
823
  table2 = gtk_table_new (2, 2, FALSE);
852
836
  gtk_table_attach_defaults (GTK_TABLE (table2), spinbutton, 0, 1, 0, 1);
853
837
  gtk_widget_show (spinbutton);
854
838
 
855
 
  g_signal_connect (xadj, "value_changed",
856
 
                    G_CALLBACK (load_dialog_ratio_callback),
857
 
                    NULL);
 
839
  g_signal_connect (xadj, "value-changed",
 
840
                    G_CALLBACK (load_dialog_ratio_callback),
 
841
                    NULL);
858
842
 
859
843
  label = gtk_label_new_with_mnemonic (_("_X ratio:"));
860
844
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
861
845
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
862
846
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
863
 
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
 
847
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
864
848
  gtk_widget_show (label);
865
849
 
866
850
  spinbutton =
874
858
  gtk_table_attach_defaults (GTK_TABLE (table2), spinbutton, 0, 1, 1, 2);
875
859
  gtk_widget_show (spinbutton);
876
860
 
877
 
  g_signal_connect (yadj, "value_changed",
878
 
                    G_CALLBACK (load_dialog_ratio_callback),
879
 
                    NULL);
 
861
  g_signal_connect (yadj, "value-changed",
 
862
                    G_CALLBACK (load_dialog_ratio_callback),
 
863
                    NULL);
880
864
 
881
865
  label = gtk_label_new_with_mnemonic (_("_Y ratio:"));
882
866
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
883
867
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
884
868
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4,
885
 
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
 
869
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
886
870
  gtk_widget_show (label);
887
871
 
888
872
  /*  the constrain ratio chainbutton  */
970
954
 
971
955
  return run;
972
956
}
973