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

« back to all changes in this revision

Viewing changes to app/core/gimptemplate.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-1997 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * gimptemplate.c
26
26
#include <glib-object.h>
27
27
 
28
28
#include "libgimpbase/gimpbase.h"
 
29
#include "libgimpconfig/gimpconfig.h"
29
30
 
30
31
#include "core-types.h"
31
32
 
32
 
#include "config/gimpconfig.h"
33
 
#include "config/gimpconfig-params.h"
34
 
 
35
33
#include "gimp.h"
36
34
#include "gimpcontext.h"
37
35
#include "gimpimage.h"
40
38
 
41
39
#include "gimp-intl.h"
42
40
 
 
41
 
43
42
/*  The default image aspect ratio is the golden mean. We use
44
43
 *  two adjacent fibonacci numbers for the unstable series and
45
44
 *  some less odd values for the stable version.
70
69
};
71
70
 
72
71
 
73
 
static void      gimp_template_class_init    (GimpTemplateClass *klass);
74
 
 
75
 
static void      gimp_template_finalize      (GObject           *object);
76
 
static void      gimp_template_set_property  (GObject           *object,
77
 
                                              guint              property_id,
78
 
                                              const GValue      *value,
79
 
                                              GParamSpec        *pspec);
80
 
static void      gimp_template_get_property  (GObject           *object,
81
 
                                              guint              property_id,
82
 
                                              GValue            *value,
83
 
                                              GParamSpec        *pspec);
84
 
static void      gimp_template_notify        (GObject           *object,
85
 
                                              GParamSpec        *pspec);
86
 
 
87
 
 
88
 
static GimpViewableClass *parent_class = NULL;
89
 
 
90
 
 
91
 
GType
92
 
gimp_template_get_type (void)
93
 
{
94
 
  static GType template_type = 0;
95
 
 
96
 
  if (! template_type)
97
 
    {
98
 
      static const GTypeInfo template_info =
99
 
      {
100
 
        sizeof (GimpTemplateClass),
101
 
        (GBaseInitFunc) NULL,
102
 
        (GBaseFinalizeFunc) NULL,
103
 
        (GClassInitFunc) gimp_template_class_init,
104
 
        NULL,           /* class_finalize */
105
 
        NULL,           /* class_data     */
106
 
        sizeof (GimpTemplate),
107
 
        0,              /* n_preallocs    */
108
 
        NULL            /* instance_init  */
109
 
      };
110
 
      static const GInterfaceInfo config_iface_info =
111
 
      {
112
 
        NULL,           /* iface_init     */
113
 
        NULL,           /* iface_finalize */
114
 
        NULL            /* iface_data     */
115
 
      };
116
 
 
117
 
      template_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
118
 
                                              "GimpTemplate",
119
 
                                              &template_info, 0);
120
 
 
121
 
      g_type_add_interface_static (template_type, GIMP_TYPE_CONFIG,
122
 
                                   &config_iface_info);
123
 
    }
124
 
 
125
 
  return template_type;
126
 
}
 
72
static void      gimp_template_finalize     (GObject      *object);
 
73
static void      gimp_template_set_property (GObject      *object,
 
74
                                             guint         property_id,
 
75
                                             const GValue *value,
 
76
                                             GParamSpec   *pspec);
 
77
static void      gimp_template_get_property (GObject      *object,
 
78
                                             guint         property_id,
 
79
                                             GValue       *value,
 
80
                                             GParamSpec   *pspec);
 
81
static void      gimp_template_notify       (GObject      *object,
 
82
                                             GParamSpec   *pspec);
 
83
 
 
84
 
 
85
G_DEFINE_TYPE_WITH_CODE (GimpTemplate, gimp_template, GIMP_TYPE_VIEWABLE,
 
86
                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG, NULL))
 
87
 
 
88
#define parent_class gimp_template_parent_class
 
89
 
127
90
 
128
91
static void
129
92
gimp_template_class_init (GimpTemplateClass *klass)
130
93
{
131
 
  GObjectClass      *object_class;
132
 
  GimpViewableClass *viewable_class;
133
 
 
134
 
  object_class   = G_OBJECT_CLASS (klass);
135
 
  viewable_class = GIMP_VIEWABLE_CLASS (klass);
136
 
 
137
 
  parent_class = g_type_class_peek_parent (klass);
138
 
 
139
 
  object_class->finalize = gimp_template_finalize;
 
94
  GObjectClass      *object_class   = G_OBJECT_CLASS (klass);
 
95
  GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
 
96
 
 
97
  object_class->finalize     = gimp_template_finalize;
140
98
 
141
99
  object_class->set_property = gimp_template_set_property;
142
100
  object_class->get_property = gimp_template_get_property;
148
106
                                NULL,
149
107
                                GIMP_MIN_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE,
150
108
                                DEFAULT_IMAGE_WIDTH,
151
 
                                0);
 
109
                                GIMP_PARAM_STATIC_STRINGS);
152
110
  GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_HEIGHT, "height",
153
111
                                NULL,
154
112
                                GIMP_MIN_IMAGE_SIZE, GIMP_MAX_IMAGE_SIZE,
155
113
                                DEFAULT_IMAGE_HEIGHT,
156
 
                                0);
 
114
                                GIMP_PARAM_STATIC_STRINGS);
157
115
  GIMP_CONFIG_INSTALL_PROP_UNIT (object_class, PROP_UNIT, "unit",
158
116
                                 N_("The unit used for coordinate display "
159
117
                                    "when not in dot-for-dot mode."),
160
118
                                 TRUE, FALSE, GIMP_UNIT_PIXEL,
161
 
                                 0);
 
119
                                 GIMP_PARAM_STATIC_STRINGS);
162
120
 
163
121
  GIMP_CONFIG_INSTALL_PROP_RESOLUTION (object_class, PROP_XRESOLUTION,
164
122
                                       "xresolution",
165
123
                                       N_("The horizontal image resolution."),
166
124
                                       72.0,
167
 
                                       0);
 
125
                                       GIMP_PARAM_STATIC_STRINGS);
168
126
  GIMP_CONFIG_INSTALL_PROP_RESOLUTION (object_class, PROP_YRESOLUTION,
169
127
                                       "yresolution",
170
128
                                       N_("The vertical image resolution."),
171
129
                                       72.0,
172
 
                                       0);
 
130
                                       GIMP_PARAM_STATIC_STRINGS);
173
131
  GIMP_CONFIG_INSTALL_PROP_UNIT (object_class, PROP_RESOLUTION_UNIT,
174
132
                                 "resolution-unit",
175
133
                                 NULL,
176
134
                                 FALSE, FALSE, GIMP_UNIT_INCH,
177
 
                                 0);
 
135
                                 GIMP_PARAM_STATIC_STRINGS);
178
136
 
179
137
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_IMAGE_TYPE,
180
138
                                 "image-type",
181
139
                                 NULL,
182
140
                                 GIMP_TYPE_IMAGE_BASE_TYPE, GIMP_RGB,
183
 
                                 0);
 
141
                                 GIMP_PARAM_STATIC_STRINGS);
184
142
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_FILL_TYPE,
185
143
                                 "fill-type",
186
144
                                 NULL,
187
145
                                 GIMP_TYPE_FILL_TYPE, GIMP_BACKGROUND_FILL,
188
 
                                 0);
 
146
                                 GIMP_PARAM_STATIC_STRINGS);
189
147
 
190
148
  GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_COMMENT,
191
149
                                   "comment",
192
150
                                   NULL,
193
151
                                   NULL,
194
 
                                   0);
 
152
                                   GIMP_PARAM_STATIC_STRINGS);
195
153
 
196
154
  GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_FILENAME,
197
155
                                   "filename",
198
156
                                   NULL,
199
157
                                   NULL,
200
 
                                   0);
 
158
                                   GIMP_PARAM_STATIC_STRINGS);
 
159
}
 
160
 
 
161
static void
 
162
gimp_template_init (GimpTemplate *template)
 
163
{
201
164
}
202
165
 
203
166
static void
320
283
gimp_template_notify (GObject    *object,
321
284
                      GParamSpec *pspec)
322
285
{
323
 
  GimpTemplate *template;
 
286
  GimpTemplate *template = GIMP_TEMPLATE (object);
324
287
  gint          channels;
325
288
 
326
 
  template = GIMP_TEMPLATE (object);
327
 
 
328
289
  if (G_OBJECT_CLASS (parent_class)->notify)
329
290
    G_OBJECT_CLASS (parent_class)->notify (object, pspec);
330
291
 
356
317
 
357
318
void
358
319
gimp_template_set_from_image (GimpTemplate *template,
359
 
                              GimpImage    *gimage)
 
320
                              GimpImage    *image)
360
321
{
361
 
  gdouble            xresolution;
362
 
  gdouble            yresolution;
363
 
  GimpImageBaseType  image_type;
364
 
  GimpParasite      *parasite;
365
 
  gchar             *comment = NULL;
 
322
  gdouble             xresolution;
 
323
  gdouble             yresolution;
 
324
  GimpImageBaseType   image_type;
 
325
  const GimpParasite *parasite;
 
326
  gchar              *comment = NULL;
366
327
 
367
328
  g_return_if_fail (GIMP_IS_TEMPLATE (template));
368
 
  g_return_if_fail (GIMP_IS_IMAGE (gimage));
369
 
 
370
 
  gimp_image_get_resolution (gimage, &xresolution, &yresolution);
371
 
 
372
 
  image_type = gimp_image_base_type (gimage);
 
329
  g_return_if_fail (GIMP_IS_IMAGE (image));
 
330
 
 
331
  gimp_image_get_resolution (image, &xresolution, &yresolution);
 
332
 
 
333
  image_type = gimp_image_base_type (image);
373
334
 
374
335
  if (image_type == GIMP_INDEXED)
375
336
    image_type = GIMP_RGB;
376
337
 
377
 
  parasite =  gimp_image_parasite_find (gimage, "gimp-comment");
 
338
  parasite =  gimp_image_parasite_find (image, "gimp-comment");
378
339
  if (parasite)
379
340
    comment = g_strndup (gimp_parasite_data (parasite),
380
341
                         gimp_parasite_data_size (parasite));
381
342
 
382
343
  g_object_set (template,
383
 
                "width",           gimp_image_get_width (gimage),
384
 
                "height",          gimp_image_get_height (gimage),
 
344
                "width",           gimp_image_get_width (image),
 
345
                "height",          gimp_image_get_height (image),
385
346
                "xresolution",     xresolution,
386
347
                "yresolution",     yresolution,
387
 
                "resolution-unit", gimp_image_get_unit (gimage),
 
348
                "resolution-unit", gimp_image_get_unit (image),
388
349
                "image-type",      image_type,
389
350
                "comment",         comment,
390
351
                NULL);
398
359
                            GimpTemplate *template,
399
360
                            GimpContext  *context)
400
361
{
401
 
  GimpImage     *gimage;
 
362
  GimpImage     *image;
402
363
  GimpLayer     *layer;
403
364
  GimpImageType  type;
404
365
  gint           width, height;
407
368
  g_return_val_if_fail (GIMP_IS_TEMPLATE (template), NULL);
408
369
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
409
370
 
410
 
  gimage = gimp_create_image (gimp,
411
 
                              template->width, template->height,
412
 
                              template->image_type,
413
 
                              FALSE);
 
371
  image = gimp_create_image (gimp,
 
372
                             template->width, template->height,
 
373
                             template->image_type,
 
374
                             FALSE);
414
375
 
415
 
  gimp_image_undo_disable (gimage);
 
376
  gimp_image_undo_disable (image);
416
377
 
417
378
  if (template->comment)
418
379
    {
422
383
                                    GIMP_PARASITE_PERSISTENT,
423
384
                                    strlen (template->comment) + 1,
424
385
                                    template->comment);
425
 
      gimp_image_parasite_attach (gimage, parasite);
 
386
      gimp_image_parasite_attach (image, parasite);
426
387
      gimp_parasite_free (parasite);
427
388
    }
428
389
 
429
 
  gimp_image_set_resolution (gimage,
 
390
  gimp_image_set_resolution (image,
430
391
                             template->xresolution, template->yresolution);
431
 
 
432
 
  gimp_image_set_unit (gimage, template->resolution_unit);
433
 
 
434
 
  width  = gimp_image_get_width (gimage);
435
 
  height = gimp_image_get_height (gimage);
 
392
  gimp_image_set_unit (image, template->resolution_unit);
 
393
 
 
394
  width  = gimp_image_get_width (image);
 
395
  height = gimp_image_get_height (image);
436
396
 
437
397
  switch (template->fill_type)
438
398
    {
446
406
      break;
447
407
    }
448
408
 
449
 
  layer = gimp_layer_new (gimage, width, height, type,
 
409
  layer = gimp_layer_new (image, width, height, type,
450
410
                          _("Background"),
451
 
                          GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
452
 
 
453
 
  gimp_image_add_layer (gimage, layer, 0);
454
 
 
455
 
  gimp_drawable_fill_by_type (GIMP_DRAWABLE (layer), context,
456
 
                              template->fill_type);
457
 
 
458
 
  gimp_image_undo_enable (gimage);
459
 
  gimp_image_clean_all (gimage);
460
 
 
461
 
  gimp_create_display (gimp, gimage, template->unit, 1.0);
462
 
 
463
 
  g_object_unref (gimage);
464
 
 
465
 
  return gimage;
 
411
                          GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
 
412
 
 
413
  gimp_drawable_fill_by_type (GIMP_DRAWABLE (layer),
 
414
                              context, template->fill_type);
 
415
 
 
416
  gimp_image_add_layer (image, layer, 0);
 
417
 
 
418
  gimp_image_undo_enable (image);
 
419
  gimp_image_clean_all (image);
 
420
 
 
421
  gimp_create_display (gimp, image, template->unit, 1.0);
 
422
 
 
423
  g_object_unref (image);
 
424
 
 
425
  return image;
466
426
}