From: Jim Evins Date: Tue, 3 Feb 2004 04:31:17 +0000 (+0000) Subject: 2004-02-02 Jim Evins X-Git-Tag: glabels-2_3_0~486 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8d1652bfd6e74700063cdccb120693515c71e6ea;p=glabels 2004-02-02 Jim Evins * src/label-image.c: (gl_label_image_set_filename): When setting a new filename adjust size such that the aspect ratio of the image is preserved using the current size as a bounding box. * src/view-image.c: (update_object_from_editor_cb): When updating object from editor, feed back possible size changes to editor as a result of a possible change in image. * src/object-editor-size-page.c: (size_reset_cb): Fixed typo when blocking spin handlers. If the base size is larger than the max size, treat max size as a bounding box while keeping aspect ratio. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@410 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 165c7596..00aa3a24 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,19 @@ +2004-02-02 Jim Evins + + * src/label-image.c: (gl_label_image_set_filename): + When setting a new filename adjust size such that the aspect ratio of + the image is preserved using the current size as a bounding box. + + * src/view-image.c: (update_object_from_editor_cb): + When updating object from editor, feed back possible size changes to + editor as a result of a possible change in image. + + * src/object-editor-size-page.c: (size_reset_cb): + Fixed typo when blocking spin handlers. If the base size is larger than + the max size, treat max size as a bounding box while keeping aspect + ratio. + + 2004-02-02 Jim Evins * src/label-object.h: diff --git a/glabels2/src/label-image.c b/glabels2/src/label-image.c index 1ab49aa4..0f51bc89 100644 --- a/glabels2/src/label-image.c +++ b/glabels2/src/label-image.c @@ -199,6 +199,7 @@ gl_label_image_set_filename (glLabelImage *limage, glTextNode *old_filename; GHashTable *pixbuf_cache; GdkPixbuf *pixbuf; + gdouble image_w, image_h, aspect_ratio, w, h; gl_debug (DEBUG_LABEL, "START"); @@ -242,6 +243,19 @@ gl_label_image_set_filename (glLabelImage *limage, } } + /* Treat current size as a bounding box, scale image to maintain aspect + * ratio while fitting it in this bounding box. */ + image_w = gdk_pixbuf_get_width (limage->private->pixbuf); + image_h = gdk_pixbuf_get_height (limage->private->pixbuf); + aspect_ratio = image_h / image_w; + gl_label_object_get_size (GL_LABEL_OBJECT(limage), &w, &h); + if ( h > w*aspect_ratio ) { + h = w * aspect_ratio; + } else { + w = h / aspect_ratio; + } + gl_label_object_set_size (GL_LABEL_OBJECT(limage), w, h); + gl_label_object_emit_changed (GL_LABEL_OBJECT(limage)); gl_debug (DEBUG_LABEL, "END"); diff --git a/glabels2/src/object-editor-size-page.c b/glabels2/src/object-editor-size-page.c index 85b26cec..9b289387 100644 --- a/glabels2/src/object-editor-size-page.c +++ b/glabels2/src/object-editor-size-page.c @@ -230,16 +230,38 @@ static void size_reset_cb (glObjectEditor *editor) { gdouble w_base, h_base; + gdouble w_max, h_max; + gdouble aspect_ratio; g_signal_handlers_block_by_func (G_OBJECT (editor->priv->size_w_spin), - G_CALLBACK (h_spin_cb), + G_CALLBACK (w_spin_cb), editor); g_signal_handlers_block_by_func (G_OBJECT (editor->priv->size_h_spin), G_CALLBACK (h_spin_cb), editor); - w_base = editor->priv->w_base * editor->priv->units_per_point; - h_base = editor->priv->h_base * editor->priv->units_per_point; + w_base = editor->priv->w_base; + h_base = editor->priv->h_base; + + w_max = editor->priv->w_max; + h_max = editor->priv->h_max; + + if ( (w_base > w_max) || (h_base > h_max) ) { + + aspect_ratio = h_base / w_base; + + if ( h_max > w_max*aspect_ratio ) { + w_base = w_max; + h_base = w_max * aspect_ratio; + + } else { + w_base = h_max / aspect_ratio; + h_base = h_max; + } + } + + w_base *= editor->priv->units_per_point; + h_base *= editor->priv->units_per_point; gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->size_w_spin), w_base); @@ -247,7 +269,7 @@ size_reset_cb (glObjectEditor *editor) h_base); g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->size_w_spin), - G_CALLBACK (h_spin_cb), + G_CALLBACK (w_spin_cb), editor); g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->size_h_spin), G_CALLBACK (h_spin_cb), diff --git a/glabels2/src/view-image.c b/glabels2/src/view-image.c index 287d0e88..1521b300 100644 --- a/glabels2/src/view-image.c +++ b/glabels2/src/view-image.c @@ -283,6 +283,8 @@ update_object_from_editor_cb (glObjectEditor *editor, { gdouble x, y, w, h; glTextNode *filename; + const GdkPixbuf *pixbuf; + gdouble image_w, image_h; gl_debug (DEBUG_VIEW, "START"); @@ -303,6 +305,16 @@ update_object_from_editor_cb (glObjectEditor *editor, filename = gl_object_editor_get_image (editor); gl_label_image_set_filename (GL_LABEL_IMAGE(object), filename); + /* Setting filename may have modified the size. */ + gl_label_object_get_size (object, &w, &h); + gl_object_editor_set_size (editor, w, h); + + /* It may also have a new base size. */ + pixbuf = gl_label_image_get_pixbuf (GL_LABEL_IMAGE(object), NULL); + image_w = gdk_pixbuf_get_width (pixbuf); + image_h = gdk_pixbuf_get_height (pixbuf); + gl_object_editor_set_base_size (editor, image_w, image_h); + g_signal_handlers_unblock_by_func (G_OBJECT(object), update_editor_from_object_cb, editor);