Partial Patch - Add the ability to scale images
Darren Albers <[email protected]>
| Newsgroups | gmane.comp.gnome.apps.pan.devel |
|---|---|
| Message-ID | <[email protected]> |
All, Attached is a partial patch that gives the ability to scale images in the body pane. I am posting it here in hopes that someone can point me in the right direction for the last piece, how do I determine the geometry of the body pane so I can scale the image appropriately? The GTK toolkit has a number of function to determine window size but not the pane itself. At this time I am just hard coding a value height and width to verify that everything works. If all else fails I can make the scale size a user configurable option... This patch adds a preference option to scale attached images and then uses the gdk_pixbuf_scale_simple() to scale the image down. This patch should maintain the proper aspect ratio, I reused some code from eog to determine how to properly scale the image and it seems to handle all images properly but I thought a bit about it today and I think it is flawed for this use and I think I have a better way to handle it that I will look at tonight. I am a poor programmer so I would appreciate any feedback, help, and hints! Thanks! Darren _______________________________________________ Pan-devel mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/pan-devel
scaleimage0.101.patch
(text/x-patch, 3.3 KB)
diff -Nru /home/darren/pan-0.101/pan/gui/body-pane.cc /home/darren/pan-0.101.1/pan/gui/body-pane.cc
--- /home/darren/pan-0.101/pan/gui/body-pane.cc 2006-06-24 23:44:24.000000000 -0400
+++ /home/darren/pan-0.101.1/pan/gui/body-pane.cc 2006-06-28 21:37:54.000000000 -0400
@@ -505,7 +505,7 @@
* Generates a GtkPixmap object from a given GMimePart that contains an image.
* Used for displaying attached pictures inline.
*/
- GdkPixbuf* get_pixbuf_from_gmime_part (const GMimePart * part)
+ GdkPixbuf* get_pixbuf_from_gmime_part (const GMimePart * part, const Prefs& prefs)
{
GdkPixbufLoader * l = gdk_pixbuf_loader_new ();
GError * err (0);
@@ -525,6 +525,7 @@
// create the pixbuf
GdkPixbuf * pixbuf (0);
+ GdkPixbuf * scaled (0);
if (!err)
pixbuf = gdk_pixbuf_loader_get_pixbuf (l);
else {
@@ -540,9 +541,29 @@
}
if (pixbuf)
g_object_ref (G_OBJECT(pixbuf));
- g_object_unref (G_OBJECT(l));
-
- return pixbuf;
+ g_object_unref (G_OBJECT(l));
+ if (prefs.get_flag ("scale-images-to-fit", true))
+ {
+ //Hard coding the pane height and width temporarily until I can figure out how to get the pane geometry.
+ int height = 600;
+ int width = 600;
+ int image_width = gdk_pixbuf_get_width (pixbuf);
+ int image_height = gdk_pixbuf_get_height (pixbuf);
+ //stolen from eog eog-image.c, this section determines how we scale the image
+ if (((gdouble) image_height/image_width) >
+ ((gdouble)width/height)) {
+ /* We scale to the top */
+ width = height * (gdouble)image_width/image_height;
+ } else {
+ /* We scale to the sides of the page */
+ height = width * (gdouble)image_height/image_width;
+ }
+ scaled = gdk_pixbuf_scale_simple (pixbuf, width, height ,GDK_INTERP_BILINEAR);
+ return scaled;
+ }
+ else {
+ return pixbuf;
+ }
}
}
@@ -604,7 +625,7 @@
// if it's a picture, draw it
if (is_image) {
- GdkPixbuf * pixbuf = get_pixbuf_from_gmime_part (part);
+ GdkPixbuf * pixbuf = get_pixbuf_from_gmime_part (part, _prefs);
if (pixbuf != 0) {
GtkTextIter iter;
gtk_text_buffer_get_end_iter (_buffer, &iter);
@@ -1136,7 +1157,7 @@
if ((key=="wrap-article-body") || (key=="mute-quoted-text") ||
(key=="show-smilies-as-graphics") || (key=="show-all-headers") ||
- (key=="show-text-markup"))
+ (key=="show-text-markup") || (key=="scale-images-to-fit"))
refresh ();
}
diff -Nru /home/darren/pan-0.101/pan/gui/prefs-ui.cc /home/darren/pan-0.101.1/pan/gui/prefs-ui.cc
--- /home/darren/pan-0.101/pan/gui/prefs-ui.cc 2006-05-28 13:54:00.000000000 -0400
+++ /home/darren/pan-0.101.1/pan/gui/prefs-ui.cc 2006-06-28 21:13:25.000000000 -0400
@@ -321,6 +321,11 @@
HIG :: workarea_add_wide_control (t, &row, w);
#if GTK_CHECK_VERSION(2,6,0)
HIG::workarea_add_section_divider (t, &row);
+ HIG::workarea_add_section_title (t, &row, _("Image Options"));
+ HIG :: workarea_add_section_spacer (t, row, 1);
+ w = new_check_button (_("Scale Images to fit"), "scale-images-to-fit", false, prefs);
+ HIG :: workarea_add_wide_control (t, &row, w);
+ HIG::workarea_add_section_divider (t, &row);
HIG::workarea_add_section_title (t, &row, _("Tasks"));
HIG::workarea_add_section_spacer (t, row, 1);
l = gtk_label_new_with_mnemonic (_("Save a_ttachments to path:"));