1 diff -ru gtkhtml-3.24.4/gtkhtml/gtkhtml.c gtkhtml-3.24.4/gtkhtml/gtkhtml.c
2 --- gtkhtml-3.24.4/gtkhtml/gtkhtml.c 2009-04-07 04:15:16.000000000 +0200
3 +++ gtkhtml-3.24.4/gtkhtml/gtkhtml.c 2009-04-07 04:14:25.000000000 +0200
5 html_engine_get_selection_area (html->engine, x, y, w, h);
9 +gtk_html_set_max_image_size (GtkHTML *html, gint width, gint height)
11 + html_engine_set_max_image_size (html->engine, width, height);
15 gtk_html_set_allow_frameset (GtkHTML *html, gboolean allow)
17 diff -ru gtkhtml-3.24.4/gtkhtml/gtkhtml.h gtkhtml-3.24.4/gtkhtml/gtkhtml.h
18 --- gtkhtml-3.24.4/gtkhtml/gtkhtml.h 2009-04-07 04:15:16.000000000 +0200
19 +++ gtkhtml-3.24.4/gtkhtml/gtkhtml.h 2009-04-07 04:14:25.000000000 +0200
24 +void gtk_html_set_max_image_size (GtkHTML *html,
25 + gint width, gint height);
29 #endif /* _GTKHTML_H_ */
30 diff -ru gtkhtml-3.24.4/gtkhtml/htmlengine.c gtkhtml-3.24.4/gtkhtml/htmlengine.c
31 --- gtkhtml-3.24.4/gtkhtml/htmlengine.c 2009-04-07 04:15:16.000000000 +0200
32 +++ gtkhtml-3.24.4/gtkhtml/htmlengine.c 2009-04-07 04:14:25.000000000 +0200
35 engine->language = NULL;
37 + engine->image_max_size_set = FALSE;
41 @@ -6966,3 +6967,12 @@
42 *w = e->search_area_w;
43 *h = e->search_area_h;
46 +void html_engine_set_max_image_size (HTMLEngine *e,
50 + e->image_max_height = height;
51 + e->image_max_width = width;
52 + e->image_max_size_set = TRUE;
54 diff -ru gtkhtml-3.24.4/gtkhtml/htmlengine.h gtkhtml-3.24.4/gtkhtml/htmlengine.h
55 --- gtkhtml-3.24.4/gtkhtml/htmlengine.h 2009-04-07 04:15:16.000000000 +0200
56 +++ gtkhtml-3.24.4/gtkhtml/htmlengine.h 2009-04-07 04:14:25.000000000 +0200
62 + gboolean image_max_size_set;
63 + gint image_max_width;
64 + gint image_max_height;
67 /* must be forward referenced *sigh* */
69 void html_engine_get_selection_area (HTMLEngine *e,
72 +void html_engine_set_max_image_size (HTMLEngine *e, gint width, gint height);
74 #endif /* _HTMLENGINE_H_ */
75 diff -ru gtkhtml-3.24.4/gtkhtml/htmlimage.c gtkhtml-3.24.4/gtkhtml/htmlimage.c
76 --- gtkhtml-3.24.4/gtkhtml/htmlimage.c 2009-04-07 04:15:16.000000000 +0200
77 +++ gtkhtml-3.24.4/gtkhtml/htmlimage.c 2009-04-07 04:31:37.000000000 +0200
79 html_image_get_actual_width (HTMLImage *image, HTMLPainter *painter)
81 GdkPixbufAnimation *anim = image->image_ptr->animation;
82 + GdkPixbuf *pixbuf = image->image_ptr->pixbuf;
83 gint pixel_size = painter ? html_painter_get_pixel_size (painter) : 1;
85 + gint width, get_width, get_height;
87 if (image->percent_width) {
88 /* The cast to `gdouble' is to avoid overflow (eg. when
90 * image->specified_width) / 100 * image->magnification;
91 } else if (image->specified_width > 0) {
92 width = image->specified_width * pixel_size * image->magnification;
93 - } else if (image->image_ptr == NULL || anim == NULL) {
94 + } else if (image->image_ptr == NULL ||
95 + (anim == NULL && pixbuf == NULL)) {
96 width = DEFAULT_SIZE * pixel_size * image->magnification;
98 - width = gdk_pixbuf_animation_get_width (anim) * pixel_size * image->magnification;
100 + get_width = gdk_pixbuf_animation_get_width (anim);
101 + get_height = gdk_pixbuf_animation_get_height (anim);
103 + get_width = gdk_pixbuf_get_width (pixbuf);
104 + get_height = gdk_pixbuf_get_height (pixbuf);
106 + width = get_width * pixel_size * image->magnification;
108 if (image->specified_height > 0 || image->percent_height) {
111 scale = ((double) html_image_get_actual_height (image, painter))
112 - / (gdk_pixbuf_animation_get_height (anim) * pixel_size);
113 + / (get_height * pixel_size);
118 html_image_get_actual_height (HTMLImage *image, HTMLPainter *painter)
120 GdkPixbufAnimation *anim = image->image_ptr->animation;
121 + GdkPixbuf *pixbuf = image->image_ptr->pixbuf;
122 gint pixel_size = painter ? html_painter_get_pixel_size (painter) : 1;
124 + gint height, get_width, get_height;
126 if (image->percent_height) {
127 /* The cast to `gdouble' is to avoid overflow (eg. when
128 @@ -126,16 +136,24 @@
129 * image->specified_height) / 100 * image->magnification;
130 } else if (image->specified_height > 0) {
131 height = image->specified_height * pixel_size * image->magnification;
132 - } else if (image->image_ptr == NULL || anim == NULL) {
133 + } else if (image->image_ptr == NULL ||
134 + (anim == NULL && pixbuf == NULL)) {
135 height = DEFAULT_SIZE * pixel_size * image->magnification;
137 - height = gdk_pixbuf_animation_get_height (anim) * pixel_size * image->magnification;
139 + get_width = gdk_pixbuf_animation_get_width (anim);
140 + get_height = gdk_pixbuf_animation_get_height (anim);
142 + get_width = gdk_pixbuf_get_width (pixbuf);
143 + get_height = gdk_pixbuf_get_height (pixbuf);
145 + height = get_height * pixel_size * image->magnification;
147 if (image->specified_width > 0 || image->percent_width) {
150 scale = ((double) html_image_get_actual_width (image, painter))
151 - / (gdk_pixbuf_animation_get_width (anim) * pixel_size);
152 + / (get_width * pixel_size);
157 pixbuf = gdk_pixbuf_animation_get_static_image (ip->animation);
161 + pixbuf = ip->pixbuf;
164 pixel_size = html_painter_get_pixel_size (painter);
165 @@ -1121,11 +1139,16 @@
167 gdk_pixbuf_loader_close (ip->loader, NULL);
169 - if (!ip->animation) {
170 - ip->animation = gdk_pixbuf_loader_get_animation (ip->loader);
171 + if (ip->rescaled && !ip->pixbuf) {
172 + ip->pixbuf = gdk_pixbuf_loader_get_pixbuf (ip->loader);
175 - g_object_ref (ip->animation);
177 + g_object_ref (ip->pixbuf);
178 + } else if (!ip->rescaled && !ip->animation) {
179 + ip->animation = gdk_pixbuf_loader_get_animation (ip->loader);
182 + g_object_ref (ip->animation);
184 html_image_pointer_start_animation (ip);
186 @@ -1231,15 +1254,49 @@
188 html_image_factory_area_prepared (GdkPixbufLoader *loader, HTMLImagePointer *ip)
190 - if (!ip->animation) {
191 - ip->animation = gdk_pixbuf_loader_get_animation (loader);
192 + if (ip->rescaled && !ip->pixbuf) {
193 + ip->pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
194 + g_object_ref (ip->pixbuf);
195 + } else if (!ip->rescaled && !ip->animation) {
196 + ip->animation = gdk_pixbuf_loader_get_animation (loader);
197 g_object_ref (ip->animation);
199 - html_image_pointer_start_animation (ip);
200 + html_image_pointer_start_animation (ip);
202 update_or_redraw (ip);
206 +html_image_factory_size_prepared (GdkPixbufLoader *loader,
209 + HTMLImagePointer *ip)
211 + HTMLEngine* e = ip->factory->engine;
212 + gint new_width = width;
213 + gint new_height = height;
215 + if (!e->image_max_size_set)
218 + if (new_width > e->image_max_width) {
219 + new_height = (gint) ((double) new_height *
220 + ((double) e->image_max_width / (double) new_width));
221 + new_width = e->image_max_width;
224 + if (new_height > e->image_max_height) {
225 + new_width = (gint) ((double) new_width *
226 + ((double) e->image_max_height / (double) new_height));
227 + new_height = e->image_max_height;
230 + if ((width != new_width) || (height != new_height)) {
231 + ip->rescaled = TRUE;
232 + gdk_pixbuf_loader_set_size (loader, new_width, new_height);
237 html_image_factory_get_missing (HTMLImageFactory *factory)
239 @@ -1321,6 +1378,8 @@
241 retval->animation = NULL;
242 retval->interests = NULL;
243 + retval->pixbuf = NULL;
244 + retval->rescaled = FALSE;
245 retval->factory = factory;
246 retval->stall = FALSE;
247 retval->stall_timeout = g_timeout_add (STALL_INTERVAL,
248 @@ -1379,6 +1438,10 @@
249 g_object_unref (ip->animation);
250 ip->animation = NULL;
253 + g_object_unref (ip->pixbuf);
257 g_object_unref (ip->iter);
259 @@ -1441,21 +1504,28 @@
262 ip = html_image_pointer_new (url, factory);
263 + g_signal_connect (ip->loader, "size_prepared",
264 + G_CALLBACK (html_image_factory_size_prepared),
266 g_hash_table_insert (factory->loaded_images, ip->url, ip);
268 - g_signal_connect (G_OBJECT (ip->loader), "area_prepared",
269 - G_CALLBACK (html_image_factory_area_prepared),
272 - g_signal_connect (G_OBJECT (ip->loader), "area_updated",
273 - G_CALLBACK (html_image_factory_area_updated),
275 + g_signal_connect (G_OBJECT (ip->loader), "area_prepared",
276 + G_CALLBACK (html_image_factory_area_prepared),
279 + g_signal_connect (G_OBJECT (ip->loader), "area_updated",
280 + G_CALLBACK (html_image_factory_area_updated),
282 stream = html_image_pointer_load (ip);
286 free_image_ptr_data (ip);
287 ip->loader = gdk_pixbuf_loader_new ();
288 + g_signal_connect (ip->loader, "size_prepared",
289 + G_CALLBACK (html_image_factory_size_prepared),
292 stream = html_image_pointer_load (ip);
295 diff -ru gtkhtml-3.24.4/gtkhtml/htmlimage.h gtkhtml-3.24.4/gtkhtml/htmlimage.h
296 --- gtkhtml-3.24.4/gtkhtml/htmlimage.h 2009-04-07 04:15:16.000000000 +0200
297 +++ gtkhtml-3.24.4/gtkhtml/htmlimage.h 2009-04-07 04:23:46.000000000 +0200
301 guint animation_timeout;
302 + GdkPixbuf *pixbuf; /* Only used when image_max_size_set & image rescaled */
303 + gboolean rescaled; /* to know image was rescaled */
306 #define HTML_IMAGE(x) ((HTMLImage *)(x))