* 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
+2004-02-02 Jim Evins <evins@snaught.com>
+
+ * 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 <evins@snaught.com>
* src/label-object.h:
glTextNode *old_filename;
GHashTable *pixbuf_cache;
GdkPixbuf *pixbuf;
+ gdouble image_w, image_h, aspect_ratio, w, h;
gl_debug (DEBUG_LABEL, "START");
}
}
+ /* 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");
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);
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),
{
gdouble x, y, w, h;
glTextNode *filename;
+ const GdkPixbuf *pixbuf;
+ gdouble image_w, image_h;
gl_debug (DEBUG_VIEW, "START");
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);