Re: Partial Patch - Add the ability to scale images

Danny Milosavljevic <[email protected]>
Newsgroups gmane.comp.gnome.apps.pan.devel
Message-ID <[email protected]>
Hi,

On Wed, 28 Jun 2006 21:51:16 -0400, Darren Albers wrote:
> 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

in body-pane.cc, read GTK_WIDGET(_root)->allocation.width

after you got a "size-allocate" signal (i.e. in your signal handler for
that).

> so I can scale the image appropriately?  The
> GTK toolkit has a number of function to determine window size but not
> the pane itself.  

It's a public member variable. Yeah, weird :)

> [...]
> This patch adds a preference option to scale attached images and
then
> uses the gdk_pixbuf_scale_simple() to scale the image down.  

Don't forget to unreference the pixbuf.

> 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.

In my holy opinion horizontal scrolling sucks but vertical scrolling is
normal. Because of this, I suggest always scaling to the maximum possible
width and adjust height as needed to keep aspect ratio. 

> [...]
> -    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); 

g_object_unref(G_OBJECT(pixbuf));

> +     return scaled; +    }
> +    else {
> +       return pixbuf;
> +    }
>    }
>  }
>[...]

p.s.: sorry about the weird reply (without the proper 
thread references), but gmane is acting up for me and so
I post this with a mail client :)

cheers,
  Danny
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.