~ubuntu-branches/ubuntu/saucy/gimp/saucy-security

« back to all changes in this revision

Viewing changes to app/vectors/gimpvectors-import.c

  • Committer: Package Import Robot
  • Author(s): Micah Gersten
  • Date: 2012-05-20 19:21:01 UTC
  • mfrom: (1.1.26) (0.4.16 sid)
  • Revision ID: package-import@ubuntu.com-20120520192101-bs7zetx8ffoq2nfv
Tags: 2.8.0-2ubuntu1
* Merge from Debian unstable (LP: #908472). Remaining Changes:
  - debian/patches/02_help-message.patch,
    debian/patches/03_gimp.desktop.in.in.patch:
    + Update some strings for Ubuntu
  - debian/control:
    + Update description
  - debian/rules:
    + Set gettext domain and update translation templates
* Drop the following patches that were applied upstream:
  - debian/patches/ghost-cursor.patch: fix Wacom tablet cursor events
  - debian/patches/embed-page-setup-dialog.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 * by GIMP but it is also supposed to be able to extract paths and
15
15
 * shapes from foreign SVG documents.
16
16
 *
17
 
 * This program is free software; you can redistribute it and/or modify
 
17
 * This program is free software: you can redistribute it and/or modify
18
18
 * it under the terms of the GNU General Public License as published by
19
 
 * the Free Software Foundation; either version 2 of the License, or
 
19
 * the Free Software Foundation; either version 3 of the License, or
20
20
 * (at your option) any later version.
21
21
 *
22
22
 * This program is distributed in the hope that it will be useful,
25
25
 * GNU General Public License for more details.
26
26
 *
27
27
 * You should have received a copy of the GNU General Public License
28
 
 * along with this program; if not, write to the Free Software
29
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
28
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
29
 */
31
30
 
32
31
#include "config.h"
34
33
#include <string.h>
35
34
#include <errno.h>
36
35
 
37
 
#include <glib-object.h>
 
36
#include <gegl.h>
38
37
 
39
38
#include "libgimpbase/gimpbase.h"
40
39
#include "libgimpmath/gimpmath.h"
43
42
 
44
43
#include "config/gimpxmlparser.h"
45
44
 
 
45
#include "core/gimperror.h"
46
46
#include "core/gimpimage.h"
47
47
#include "core/gimpimage-undo.h"
48
48
 
97
97
                                       gsize                 len,
98
98
                                       gboolean              merge,
99
99
                                       gboolean              scale,
 
100
                                       GimpVectors          *parent,
100
101
                                       gint                  position,
101
102
                                       GList               **ret_vectors,
102
103
                                       GError              **error);
198
199
                          const gchar  *filename,
199
200
                          gboolean      merge,
200
201
                          gboolean      scale,
 
202
                          GimpVectors  *parent,
201
203
                          gint          position,
202
204
                          GList       **ret_vectors,
203
205
                          GError      **error)
204
206
{
205
207
  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
206
208
  g_return_val_if_fail (filename != NULL, FALSE);
 
209
  g_return_val_if_fail (parent == NULL ||
 
210
                        parent == GIMP_IMAGE_ACTIVE_PARENT ||
 
211
                        GIMP_IS_VECTORS (parent), FALSE);
 
212
  g_return_val_if_fail (parent == NULL ||
 
213
                        parent == GIMP_IMAGE_ACTIVE_PARENT ||
 
214
                        gimp_item_is_attached (GIMP_ITEM (parent)), FALSE);
 
215
  g_return_val_if_fail (parent == NULL ||
 
216
                        parent == GIMP_IMAGE_ACTIVE_PARENT ||
 
217
                        gimp_item_get_image (GIMP_ITEM (parent)) == image,
 
218
                        FALSE);
 
219
  g_return_val_if_fail (parent == NULL ||
 
220
                        parent == GIMP_IMAGE_ACTIVE_PARENT ||
 
221
                        gimp_viewable_get_children (GIMP_VIEWABLE (parent)),
 
222
                        FALSE);
207
223
  g_return_val_if_fail (ret_vectors == NULL || *ret_vectors == NULL, FALSE);
208
224
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
209
225
 
210
 
  return gimp_vectors_import (image, filename, NULL, 0, merge, scale, position,
 
226
  return gimp_vectors_import (image, filename, NULL, 0, merge, scale,
 
227
                              parent, position,
211
228
                              ret_vectors, error);
212
229
}
213
230
 
230
247
                            gsize         len,
231
248
                            gboolean      merge,
232
249
                            gboolean      scale,
 
250
                            GimpVectors  *parent,
233
251
                            gint          position,
234
252
                            GList       **ret_vectors,
235
253
                            GError      **error)
236
254
{
237
255
  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
238
256
  g_return_val_if_fail (buffer != NULL || len == 0, FALSE);
 
257
  g_return_val_if_fail (parent == NULL ||
 
258
                        parent == GIMP_IMAGE_ACTIVE_PARENT ||
 
259
                        GIMP_IS_VECTORS (parent), FALSE);
 
260
  g_return_val_if_fail (parent == NULL ||
 
261
                        parent == GIMP_IMAGE_ACTIVE_PARENT ||
 
262
                        gimp_item_is_attached (GIMP_ITEM (parent)), FALSE);
 
263
  g_return_val_if_fail (parent == NULL ||
 
264
                        parent == GIMP_IMAGE_ACTIVE_PARENT ||
 
265
                        gimp_item_get_image (GIMP_ITEM (parent)) == image,
 
266
                        FALSE);
 
267
  g_return_val_if_fail (parent == NULL ||
 
268
                        parent == GIMP_IMAGE_ACTIVE_PARENT ||
 
269
                        gimp_viewable_get_children (GIMP_VIEWABLE (parent)),
 
270
                        FALSE);
239
271
  g_return_val_if_fail (ret_vectors == NULL || *ret_vectors == NULL, FALSE);
240
272
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
241
273
 
242
 
  return gimp_vectors_import (image, NULL, buffer, len, merge, scale, position,
 
274
  return gimp_vectors_import (image, NULL, buffer, len, merge, scale,
 
275
                              parent, position,
243
276
                              ret_vectors, error);
244
277
}
245
278
 
250
283
                     gsize         len,
251
284
                     gboolean      merge,
252
285
                     gboolean      scale,
 
286
                     GimpVectors  *parent,
253
287
                     gint          position,
254
288
                     GList       **ret_vectors,
255
289
                     GError      **error)
300
334
              SvgPath *path = paths->data;
301
335
              GList   *list;
302
336
 
303
 
              if (!merge || !vectors)
 
337
              if (! merge || ! vectors)
304
338
                {
305
339
                  vectors = gimp_vectors_new (image,
306
 
                                              ((merge || !path->id) ?
 
340
                                              ((merge || ! path->id) ?
307
341
                                               _("Imported Path") : path->id));
308
 
                  gimp_image_add_vectors (image, vectors, position);
 
342
                  gimp_image_add_vectors (image, vectors,
 
343
                                          parent, position, TRUE);
309
344
                  gimp_vectors_freeze (vectors);
310
345
 
311
346
                  if (ret_vectors)
318
353
              for (list = path->strokes; list; list = list->next)
319
354
                gimp_vectors_stroke_add (vectors, GIMP_STROKE (list->data));
320
355
 
321
 
              if (!merge)
 
356
              if (! merge)
322
357
                gimp_vectors_thaw (vectors);
323
358
 
324
 
              g_list_free (path->strokes);
 
359
              g_list_free_full (path->strokes, g_object_unref);
325
360
              path->strokes = NULL;
326
361
            }
327
362
 
333
368
      else
334
369
        {
335
370
          if (filename)
336
 
            g_set_error (error, 0, 0, _("No paths found in '%s'"),
 
371
            g_set_error (error, GIMP_ERROR, GIMP_FAILED,
 
372
                         _("No paths found in '%s'"),
337
373
                         gimp_filename_to_utf8 (filename));
338
374
          else
339
 
            g_set_error (error, 0, 0, _("No paths found in the buffer"));
 
375
            g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
 
376
                                 _("No paths found in the buffer"));
340
377
 
341
378
          success = FALSE;
342
379
        }
560
597
{
561
598
  while (*names)
562
599
    {
563
 
      if (strcmp (*names, "transform") == 0 && !handler->transform)
 
600
      if (strcmp (*names, "transform") == 0 && ! handler->transform)
564
601
        {
565
602
          GimpMatrix3  matrix;
566
603
 
602
639
      switch (*names[0])
603
640
        {
604
641
        case 'i':
605
 
          if (strcmp (*names, "id") == 0 && !path->id)
 
642
          if (strcmp (*names, "id") == 0 && ! path->id)
606
643
            path->id = g_strdup (*values);
607
644
          break;
608
645
 
609
646
        case 'd':
610
 
          if (strcmp (*names, "d") == 0 && !path->strokes)
 
647
          if (strcmp (*names, "d") == 0 && ! path->strokes)
611
648
            path->strokes = parse_path_data (*values);
612
649
          break;
613
650
 
614
651
        case 't':
615
 
          if (strcmp (*names, "transform") == 0 && !handler->transform)
 
652
          if (strcmp (*names, "transform") == 0 && ! handler->transform)
616
653
            {
617
654
              GimpMatrix3  matrix;
618
655
 
654
691
      switch (*names[0])
655
692
        {
656
693
        case 'i':
657
 
          if (strcmp (*names, "id") == 0 && !path->id)
 
694
          if (strcmp (*names, "id") == 0 && ! path->id)
658
695
            path->id = g_strdup (*values);
659
696
          break;
660
697
 
686
723
          break;
687
724
 
688
725
        case 't':
689
 
          if (strcmp (*names, "transform") == 0 && !handler->transform)
 
726
          if (strcmp (*names, "transform") == 0 && ! handler->transform)
690
727
            {
691
728
              GimpMatrix3  matrix;
692
729
 
800
837
      switch (*names[0])
801
838
        {
802
839
        case 'i':
803
 
          if (strcmp (*names, "id") == 0 && !path->id)
 
840
          if (strcmp (*names, "id") == 0 && ! path->id)
804
841
            path->id = g_strdup (*values);
805
842
          break;
806
843
 
828
865
          break;
829
866
 
830
867
        case 't':
831
 
          if (strcmp (*names, "transform") == 0 && !handler->transform)
 
868
          if (strcmp (*names, "transform") == 0 && ! handler->transform)
832
869
            {
833
870
              GimpMatrix3  matrix;
834
871
 
873
910
      switch (*names[0])
874
911
        {
875
912
        case 'i':
876
 
          if (strcmp (*names, "id") == 0 && !path->id)
 
913
          if (strcmp (*names, "id") == 0 && ! path->id)
877
914
            path->id = g_strdup (*values);
878
915
          break;
879
916
 
892
929
          break;
893
930
 
894
931
        case 't':
895
 
          if (strcmp (*names, "transform") == 0 && !handler->transform)
 
932
          if (strcmp (*names, "transform") == 0 && ! handler->transform)
896
933
            {
897
934
              GimpMatrix3  matrix;
898
935
 
930
967
      switch (*names[0])
931
968
        {
932
969
        case 'i':
933
 
          if (strcmp (*names, "id") == 0 && !path->id)
 
970
          if (strcmp (*names, "id") == 0 && ! path->id)
934
971
            path->id = g_strdup (*values);
935
972
          break;
936
973
 
937
974
        case 'p':
938
 
          if (strcmp (*names, "points") == 0 && !points)
 
975
          if (strcmp (*names, "points") == 0 && ! points)
939
976
            {
940
977
              const gchar *p = *values;
941
978
              const gchar *m = NULL;
957
994
                      break;
958
995
                    }
959
996
 
960
 
                  while (*p && !g_ascii_isspace (*p) && *p != ',')
 
997
                  if (*p)
 
998
                    n++;
 
999
 
 
1000
                  while (*p && ! g_ascii_isspace (*p) && *p != ',')
961
1001
                    p++;
962
 
 
963
 
                  n++;
964
1002
                }
965
1003
 
966
1004
              if ((n > 3) && (n % 2 == 0))
980
1018
          break;
981
1019
 
982
1020
        case 't':
983
 
          if (strcmp (*names, "transform") == 0 && !handler->transform)
 
1021
          if (strcmp (*names, "transform") == 0 && ! handler->transform)
984
1022
            {
985
1023
              GimpMatrix3  matrix;
986
1024
 
1235
1273
 
1236
1274
      /* OK, have parsed keyword and args, now calculate the transform matrix */
1237
1275
 
1238
 
      if (!strcmp (keyword, "matrix"))
 
1276
      if (strcmp (keyword, "matrix") == 0)
1239
1277
        {
1240
1278
          if (n_args != 6)
1241
1279
            return FALSE;
1245
1283
                               args[2], args[3],
1246
1284
                               args[4], args[5]);
1247
1285
        }
1248
 
      else if (!strcmp (keyword, "translate"))
 
1286
      else if (strcmp (keyword, "translate") == 0)
1249
1287
        {
1250
1288
          if (n_args == 1)
1251
1289
            args[1] = 0.0;
1254
1292
 
1255
1293
          gimp_matrix3_translate (&trafo, args[0], args[1]);
1256
1294
        }
1257
 
      else if (!strcmp (keyword, "scale"))
 
1295
      else if (strcmp (keyword, "scale") == 0)
1258
1296
        {
1259
1297
          if (n_args == 1)
1260
1298
            args[1] = args[0];
1263
1301
 
1264
1302
          gimp_matrix3_scale (&trafo, args[0], args[1]);
1265
1303
        }
1266
 
      else if (!strcmp (keyword, "rotate"))
 
1304
      else if (strcmp (keyword, "rotate") == 0)
1267
1305
        {
1268
1306
          if (n_args == 1)
1269
1307
            {
1278
1316
          else
1279
1317
            return FALSE;
1280
1318
        }
1281
 
      else if (!strcmp (keyword, "skewX"))
 
1319
      else if (strcmp (keyword, "skewX") == 0)
1282
1320
        {
1283
1321
          if (n_args != 1)
1284
1322
            return FALSE;
1285
1323
 
1286
1324
          gimp_matrix3_xshear (&trafo, tan (gimp_deg_to_rad (args[0])));
1287
1325
        }
1288
 
      else if (!strcmp (keyword, "skewY"))
 
1326
      else if (strcmp (keyword, "skewY") == 0)
1289
1327
        {
1290
1328
          if (n_args != 1)
1291
1329
            return FALSE;
1355
1393
  for (i = 0; ; i++)
1356
1394
    {
1357
1395
      c = data[i];
 
1396
 
1358
1397
      if (c >= '0' && c <= '9')
1359
1398
        {
1360
1399
          /* digit */
1384
1423
        }
1385
1424
      else if (c == '.')
1386
1425
        {
1387
 
          if (!in_num)
 
1426
          if (! in_num)
1388
1427
            {
1389
1428
              in_num = TRUE;
1390
1429
              val = 0;
1391
1430
            }
 
1431
 
1392
1432
          in_frac = TRUE;
1393
1433
          frac = 1;
1394
1434
        }
1408
1448
          /* end of number */
1409
1449
 
1410
1450
          val *= sign * pow (10, exp_sign * exp);
 
1451
 
1411
1452
          if (ctx.rel)
1412
1453
            {
1413
1454
              /* Handle relative coordinates. This switch statement attempts
1437
1478
                  else if (ctx.param == 6)
1438
1479
                    val += ctx.cpy;
1439
1480
                  break;
 
1481
 
1440
1482
                case 'h':
1441
1483
                  /* rule: x-relative */
1442
1484
                  val += ctx.cpx;
1443
1485
                  break;
 
1486
 
1444
1487
                case 'v':
1445
1488
                  /* rule: y-relative */
1446
1489
                  val += ctx.cpy;
1454
1497
        }
1455
1498
 
1456
1499
      if (c == '\0')
1457
 
        break;
1458
 
      else if ((c == '+' || c == '-') && !exp_wait_sign)
 
1500
        {
 
1501
          break;
 
1502
        }
 
1503
      else if ((c == '+' || c == '-') && ! exp_wait_sign)
1459
1504
        {
1460
1505
          sign = c == '+' ? 1 : -1;
1461
1506
          val = 0;
1470
1515
        {
1471
1516
          if (ctx.param)
1472
1517
            parse_path_do_cmd (&ctx, TRUE);
 
1518
 
1473
1519
          if (ctx.stroke)
1474
1520
            gimp_stroke_close (ctx.stroke);
1475
1521
        }
1477
1523
        {
1478
1524
          if (ctx.param)
1479
1525
            parse_path_do_cmd (&ctx, TRUE);
 
1526
 
1480
1527
          ctx.cmd = c + 'a' - 'A';
1481
1528
          ctx.rel = FALSE;
1482
1529
        }
1484
1531
        {
1485
1532
          if (ctx.param)
1486
1533
            parse_path_do_cmd (&ctx, TRUE);
 
1534
 
1487
1535
          ctx.cmd = c;
1488
1536
          ctx.rel = TRUE;
1489
1537
        }