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

« back to all changes in this revision

Viewing changes to app/vectors/gimpvectors.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
 * gimpvectors.c
24
24
#include <glib-object.h>
25
25
 
26
26
#include "libgimpcolor/gimpcolor.h"
 
27
#include "libgimpmath/gimpmath.h"
27
28
 
28
29
#include "vectors-types.h"
29
30
 
57
58
};
58
59
 
59
60
 
60
 
static void       gimp_vectors_class_init   (GimpVectorsClass *klass);
61
 
static void       gimp_vectors_init         (GimpVectors      *vectors);
62
 
 
63
61
static void       gimp_vectors_finalize     (GObject          *object);
64
62
 
65
63
static gint64     gimp_vectors_get_memsize  (GimpObject       *object,
106
104
                                             GimpInterpolationType interp_type,
107
105
                                             gboolean          supersample,
108
106
                                             gint              recursion_level,
109
 
                                             gboolean          clip_result,
 
107
                                             GimpTransformResize   clip_result,
110
108
                                             GimpProgress     *progress);
111
109
static gboolean   gimp_vectors_stroke       (GimpItem         *item,
112
110
                                             GimpDrawable     *drawable,
113
 
                                             GimpContext      *context,
114
111
                                             GimpStrokeDesc   *stroke_desc);
115
112
 
116
113
static void       gimp_vectors_real_thaw            (GimpVectors       *vectors);
141
138
static GimpVectors * gimp_vectors_real_make_bezier  (const GimpVectors *vectors);
142
139
 
143
140
 
144
 
/*  private variables  */
 
141
G_DEFINE_TYPE (GimpVectors, gimp_vectors, GIMP_TYPE_ITEM)
 
142
 
 
143
#define parent_class gimp_vectors_parent_class
145
144
 
146
145
static guint gimp_vectors_signals[LAST_SIGNAL] = { 0 };
147
146
 
148
 
static GimpItemClass *parent_class = NULL;
149
 
 
150
 
 
151
 
GType
152
 
gimp_vectors_get_type (void)
153
 
{
154
 
  static GType vectors_type = 0;
155
 
 
156
 
  if (! vectors_type)
157
 
    {
158
 
      static const GTypeInfo vectors_info =
159
 
      {
160
 
        sizeof (GimpVectorsClass),
161
 
        (GBaseInitFunc) NULL,
162
 
        (GBaseFinalizeFunc) NULL,
163
 
        (GClassInitFunc) gimp_vectors_class_init,
164
 
        NULL,           /* class_finalize */
165
 
        NULL,           /* class_data     */
166
 
        sizeof (GimpVectors),
167
 
        0,              /* n_preallocs    */
168
 
        (GInstanceInitFunc) gimp_vectors_init,
169
 
      };
170
 
 
171
 
      vectors_type = g_type_register_static (GIMP_TYPE_ITEM,
172
 
                                             "GimpVectors",
173
 
                                             &vectors_info, 0);
174
 
    }
175
 
 
176
 
  return vectors_type;
177
 
}
178
147
 
179
148
static void
180
149
gimp_vectors_class_init (GimpVectorsClass *klass)
181
150
{
182
 
  GObjectClass      *object_class;
183
 
  GimpObjectClass   *gimp_object_class;
184
 
  GimpViewableClass *viewable_class;
185
 
  GimpItemClass     *item_class;
186
 
 
187
 
  object_class      = G_OBJECT_CLASS (klass);
188
 
  gimp_object_class = GIMP_OBJECT_CLASS (klass);
189
 
  viewable_class    = GIMP_VIEWABLE_CLASS (klass);
190
 
  item_class        = GIMP_ITEM_CLASS (klass);
191
 
 
192
 
  parent_class = g_type_class_peek_parent (klass);
 
151
  GObjectClass      *object_class      = G_OBJECT_CLASS (klass);
 
152
  GimpObjectClass   *gimp_object_class = GIMP_OBJECT_CLASS (klass);
 
153
  GimpViewableClass *viewable_class    = GIMP_VIEWABLE_CLASS (klass);
 
154
  GimpItemClass     *item_class        = GIMP_ITEM_CLASS (klass);
193
155
 
194
156
  gimp_vectors_signals[FREEZE] =
195
157
    g_signal_new ("freeze",
260
222
{
261
223
  GimpItem *item = GIMP_ITEM (vectors);
262
224
 
263
 
  item->visible         = FALSE;
264
 
  vectors->strokes      = NULL;
265
 
  vectors->freeze_count = 0;
 
225
  item->visible           = FALSE;
 
226
  vectors->strokes        = NULL;
 
227
  vectors->last_stroke_ID = 0;
 
228
  vectors->freeze_count   = 0;
 
229
  vectors->precision      = 0.2;
266
230
}
267
231
 
268
232
static void
301
265
static gboolean
302
266
gimp_vectors_is_attached (GimpItem *item)
303
267
{
304
 
  return (GIMP_IS_IMAGE (item->gimage) &&
305
 
          gimp_container_have (item->gimage->vectors, GIMP_OBJECT (item)));
 
268
  return (GIMP_IS_IMAGE (item->image) &&
 
269
          gimp_container_have (item->image->vectors, GIMP_OBJECT (item)));
306
270
}
307
271
 
308
272
static GimpItem *
310
274
                        GType     new_type,
311
275
                        gboolean  add_alpha)
312
276
{
313
 
  GimpVectors *vectors;
314
 
  GimpItem    *new_item;
315
 
  GimpVectors *new_vectors;
 
277
  GimpItem *new_item;
316
278
 
317
279
  g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_VECTORS), NULL);
318
280
 
319
281
  new_item = GIMP_ITEM_CLASS (parent_class)->duplicate (item, new_type,
320
282
                                                        add_alpha);
321
283
 
322
 
  if (! GIMP_IS_VECTORS (new_item))
323
 
    return new_item;
324
 
 
325
 
  vectors     = GIMP_VECTORS (item);
326
 
  new_vectors = GIMP_VECTORS (new_item);
327
 
 
328
 
  gimp_vectors_copy_strokes (vectors, new_vectors);
 
284
  if (GIMP_IS_VECTORS (new_item))
 
285
    {
 
286
      GimpVectors *vectors     = GIMP_VECTORS (item);
 
287
      GimpVectors *new_vectors = GIMP_VECTORS (new_item);
 
288
 
 
289
      gimp_vectors_copy_strokes (vectors, new_vectors);
 
290
    }
329
291
 
330
292
  return new_item;
331
293
}
381
343
 
382
344
  gimp_vectors_freeze (vectors);
383
345
 
384
 
  gimp_image_undo_push_vectors_mod (image, NULL, vectors);
 
346
  if (gimp_item_is_attached (item))
 
347
    gimp_image_undo_push_vectors_mod (image, NULL, vectors);
385
348
 
386
349
  for (list = vectors->strokes; list; list = g_list_next (list))
387
350
    {
413
376
 
414
377
  gimp_vectors_freeze (vectors);
415
378
 
416
 
  gimp_image_undo_push_vectors_mod (image, NULL, vectors);
 
379
  if (gimp_item_is_attached (item))
 
380
    gimp_image_undo_push_vectors_mod (image, NULL, vectors);
417
381
 
418
382
  for (list = vectors->strokes; list; list = g_list_next (list))
419
383
    {
439
403
  GList       *list;
440
404
  GimpMatrix3  matrix;
441
405
 
442
 
  gimp_transform_matrix_flip (flip_type, axis, &matrix);
 
406
  gimp_matrix3_identity (&matrix);
 
407
  gimp_transform_matrix_flip (&matrix, flip_type, axis);
443
408
 
444
409
  gimp_vectors_freeze (vectors);
445
410
 
468
433
  GimpVectors *vectors = GIMP_VECTORS (item);
469
434
  GList       *list;
470
435
  GimpMatrix3  matrix;
471
 
  gdouble      angle = 0.0;
472
 
 
473
 
  switch (rotate_type)
474
 
    {
475
 
    case GIMP_ROTATE_90:
476
 
      angle = G_PI_2;
477
 
      break;
478
 
    case GIMP_ROTATE_180:
479
 
      angle = G_PI;
480
 
      break;
481
 
    case GIMP_ROTATE_270:
482
 
      angle = - G_PI_2;
483
 
      break;
484
 
    }
485
 
 
486
 
  gimp_transform_matrix_rotate_center (center_x, center_y, angle, &matrix);
 
436
 
 
437
  gimp_matrix3_identity (&matrix);
 
438
  gimp_transform_matrix_rotate (&matrix, rotate_type, center_x, center_y);
487
439
 
488
440
  gimp_vectors_freeze (vectors);
489
441
 
509
461
                        GimpInterpolationType   interpolation_type,
510
462
                        gboolean                supersample,
511
463
                        gint                    recursion_level,
512
 
                        gboolean                clip_result,
 
464
                        GimpTransformResize     clip_result,
513
465
                        GimpProgress           *progress)
514
466
{
515
467
  GimpVectors *vectors = GIMP_VECTORS (item);
540
492
static gboolean
541
493
gimp_vectors_stroke (GimpItem       *item,
542
494
                     GimpDrawable   *drawable,
543
 
                     GimpContext    *context,
544
495
                     GimpStrokeDesc *stroke_desc)
545
496
{
546
497
  GimpVectors *vectors = GIMP_VECTORS (item);
547
498
  gboolean     retval  = FALSE;
548
499
 
 
500
  /*  return successfully on an empty path, there's nothing to stroke  */
549
501
  if (! vectors->strokes)
550
 
    {
551
 
      g_message (_("Cannot stroke empty path."));
552
 
      return FALSE;
553
 
    }
 
502
    return TRUE;
554
503
 
555
504
  switch (stroke_desc->method)
556
505
    {
592
541
/*  public functions  */
593
542
 
594
543
GimpVectors *
595
 
gimp_vectors_new (GimpImage   *gimage,
 
544
gimp_vectors_new (GimpImage   *image,
596
545
                  const gchar *name)
597
546
{
598
547
  GimpVectors *vectors;
599
548
 
600
 
  g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
 
549
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
601
550
 
602
551
  vectors = g_object_new (GIMP_TYPE_VECTORS, NULL);
603
552
 
604
 
  gimp_item_configure (GIMP_ITEM (vectors), gimage,
605
 
                       0, 0, gimage->width, gimage->height,
 
553
  gimp_item_configure (GIMP_ITEM (vectors), image,
 
554
                       0, 0, image->width, image->height,
606
555
                       name);
607
556
 
608
557
  return vectors;
647
596
    }
648
597
 
649
598
  dest_vectors->strokes = NULL;
 
599
  dest_vectors->last_stroke_ID = 0;
650
600
 
651
601
  gimp_vectors_add_strokes (src_vectors, dest_vectors);
652
602
 
672
622
  while (current_lstroke)
673
623
    {
674
624
      current_lstroke->data = gimp_stroke_duplicate (current_lstroke->data);
 
625
      dest_vectors->last_stroke_ID ++;
 
626
      gimp_stroke_set_ID (current_lstroke->data,
 
627
                          dest_vectors->last_stroke_ID);
675
628
      current_lstroke = g_list_next (current_lstroke);
676
629
    }
677
630
 
681
634
}
682
635
 
683
636
 
684
 
/* Calling the virtual functions */
685
 
 
686
637
void
687
638
gimp_vectors_stroke_add (GimpVectors *vectors,
688
639
                         GimpStroke  *stroke)
704
655
  /*  Don't g_list_prepend() here.  See ChangeLog 2003-05-21 --Mitch  */
705
656
 
706
657
  vectors->strokes = g_list_append (vectors->strokes, stroke);
 
658
  vectors->last_stroke_ID ++;
 
659
  gimp_stroke_set_ID (stroke, vectors->last_stroke_ID);
707
660
  g_object_ref (stroke);
708
661
}
709
662
 
736
689
    }
737
690
}
738
691
 
 
692
gint
 
693
gimp_vectors_get_n_strokes (const GimpVectors *vectors)
 
694
{
 
695
  g_return_val_if_fail (GIMP_IS_VECTORS (vectors), 0);
 
696
 
 
697
  return g_list_length (vectors->strokes);
 
698
}
 
699
 
739
700
 
740
701
GimpStroke *
741
702
gimp_vectors_stroke_get (const GimpVectors *vectors,
776
737
  return minstroke;
777
738
}
778
739
 
 
740
GimpStroke *
 
741
gimp_vectors_stroke_get_by_ID (const GimpVectors *vectors,
 
742
                               gint               id)
 
743
{
 
744
  GList      *stroke;
 
745
 
 
746
  g_return_val_if_fail (GIMP_IS_VECTORS (vectors), NULL);
 
747
 
 
748
  for (stroke = vectors->strokes; stroke; stroke = g_list_next (stroke))
 
749
    {
 
750
      if (gimp_stroke_get_ID (stroke->data) == id)
 
751
        return stroke->data;
 
752
    }
 
753
 
 
754
  return NULL;
 
755
}
 
756
 
779
757
 
780
758
GimpStroke *
781
759
gimp_vectors_stroke_get_next (const GimpVectors *vectors,
809
787
 
810
788
gdouble
811
789
gimp_vectors_stroke_get_length (const GimpVectors *vectors,
812
 
                                const GimpStroke  *prev)
 
790
                                const GimpStroke  *stroke)
813
791
{
814
792
  g_return_val_if_fail (GIMP_IS_VECTORS (vectors), 0.0);
 
793
  g_return_val_if_fail (GIMP_IS_STROKE (stroke), 0.0);
815
794
 
816
 
  return GIMP_VECTORS_GET_CLASS (vectors)->stroke_get_length (vectors, prev);
 
795
  return GIMP_VECTORS_GET_CLASS (vectors)->stroke_get_length (vectors, stroke);
817
796
}
818
797
 
819
798
static gdouble
820
799
gimp_vectors_real_stroke_get_length (const GimpVectors *vectors,
821
 
                                     const GimpStroke  *prev)
 
800
                                     const GimpStroke  *stroke)
822
801
{
823
 
  g_printerr ("gimp_vectors_stroke_get_length: default implementation\n");
 
802
  g_return_val_if_fail (GIMP_IS_VECTORS (vectors), 0.0);
 
803
  g_return_val_if_fail (GIMP_IS_STROKE (stroke), 0.0);
 
804
 
 
805
  return (gimp_stroke_get_length (stroke, vectors->precision));
824
806
 
825
807
  return 0.0;
826
808
}