Added gtkhtml,libhildonhelp and maemopad
[oespirit1] / gtkhtml / gtkhtml_290_set_image_max_size.diff
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
4 @@ -6139,6 +6139,12 @@
5         html_engine_get_selection_area (html->engine, x, y, w, h);
6  }
7  
8 +void
9 +gtk_html_set_max_image_size (GtkHTML *html, gint width, gint height)
10 +{
11 +       html_engine_set_max_image_size (html->engine, width, height);
12 +}
13 +
14  void 
15  gtk_html_set_allow_frameset (GtkHTML *html, gboolean allow)
16  {
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
20 @@ -366,6 +366,9 @@
21                                                                    gint *w,
22                                                                    gint *h);
23  
24 +void               gtk_html_set_max_image_size                    (GtkHTML           *html,
25 +                                                                   gint width, gint height);
26 +
27  #endif
28  
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
33 @@ -4413,6 +4413,7 @@
34  
35         engine->language = NULL;
36  
37 +  engine->image_max_size_set = FALSE;
38  }
39  
40  HTMLEngine *
41 @@ -6966,3 +6967,12 @@
42         *w = e->search_area_w;
43         *h = e->search_area_h;
44  }
45 +
46 +void html_engine_set_max_image_size (HTMLEngine *e, 
47 +                                     gint width,
48 +                                     gint height)
49 +{
50 +  e->image_max_height = height;
51 +  e->image_max_width = width;
52 +  e->image_max_size_set = TRUE;
53 +}
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
57 @@ -270,6 +270,10 @@
58         gint search_area_y;
59         gint search_area_w;
60         gint search_area_h;
61 +
62 +  gboolean image_max_size_set;
63 +  gint image_max_width;
64 +  gint image_max_height;
65  };
66  
67  /* must be forward referenced *sigh* */
68 @@ -500,5 +504,6 @@
69  void html_engine_get_selection_area (HTMLEngine *e, 
70                                      gint *x, gint *y, 
71                                      gint *w, gint *h);
72 +void html_engine_set_max_image_size (HTMLEngine *e, gint width, gint height);
73  
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
78 @@ -83,8 +83,9 @@
79  html_image_get_actual_width (HTMLImage *image, HTMLPainter *painter)
80  {
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;
84 -       gint width;
85 +       gint width, get_width, get_height;
86  
87         if (image->percent_width) {
88                 /* The cast to `gdouble' is to avoid overflow (eg. when
89 @@ -93,16 +94,24 @@
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;
97         } else {
98 -               width = gdk_pixbuf_animation_get_width (anim) * pixel_size * image->magnification;
99 +    if (anim) {
100 +      get_width = gdk_pixbuf_animation_get_width (anim);
101 +      get_height = gdk_pixbuf_animation_get_height (anim);
102 +    } else {
103 +      get_width = gdk_pixbuf_get_width (pixbuf); 
104 +      get_height = gdk_pixbuf_get_height (pixbuf);
105 +    }
106 +               width = get_width * pixel_size * image->magnification;
107  
108                 if (image->specified_height > 0 || image->percent_height) {
109                         double scale;
110  
111                         scale =  ((double) html_image_get_actual_height (image, painter))
112 -                               / (gdk_pixbuf_animation_get_height (anim) * pixel_size);
113 +                               / (get_height * pixel_size);
114  
115                         width *= scale;
116                 }
117 @@ -116,8 +125,9 @@
118  html_image_get_actual_height (HTMLImage *image, HTMLPainter *painter)
119  {
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;
123 -       gint height;
124 +       gint height, get_width, get_height;
125  
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;
136         } else {
137 -               height = gdk_pixbuf_animation_get_height (anim) * pixel_size * image->magnification;
138 +    if (anim) {
139 +      get_width = gdk_pixbuf_animation_get_width (anim);
140 +      get_height = gdk_pixbuf_animation_get_height (anim);
141 +    } else {
142 +      get_width = gdk_pixbuf_get_width (pixbuf); 
143 +      get_height = gdk_pixbuf_get_height (pixbuf);
144 +    }
145 +               height = get_height * pixel_size * image->magnification;
146  
147                 if (image->specified_width > 0 || image->percent_width) {
148                         double scale;
149  
150                         scale = ((double) html_image_get_actual_width (image, painter))
151 -                               / (gdk_pixbuf_animation_get_width (anim) * pixel_size);
152 +                               / (get_width * pixel_size);
153  
154                         height *= scale;
155                 }
156 @@ -454,7 +472,7 @@
157                         pixbuf = gdk_pixbuf_animation_get_static_image (ip->animation);
158                 }
159         } else {
160 -               pixbuf = NULL;
161 +    pixbuf = ip->pixbuf;
162         }
163  
164         pixel_size = html_painter_get_pixel_size (painter);
165 @@ -1121,11 +1139,16 @@
166  
167         gdk_pixbuf_loader_close (ip->loader, NULL);
168  
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);
173  
174 -               if (ip->animation)
175 -                       g_object_ref (ip->animation);
176 +    if (ip->pixbuf)
177 +      g_object_ref (ip->pixbuf);
178 +  } else if (!ip->rescaled && !ip->animation) {
179 +    ip->animation = gdk_pixbuf_loader_get_animation (ip->loader);
180 +
181 +    if (ip->animation)
182 +           g_object_ref (ip->animation);
183         }
184         html_image_pointer_start_animation (ip);
185  
186 @@ -1231,15 +1254,49 @@
187  static void
188  html_image_factory_area_prepared (GdkPixbufLoader *loader, HTMLImagePointer *ip)
189  {
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);
198  
199 -               html_image_pointer_start_animation (ip);
200 +    html_image_pointer_start_animation (ip);
201         }
202         update_or_redraw (ip);
203  }
204  
205 +static void
206 +html_image_factory_size_prepared (GdkPixbufLoader *loader,
207 +                                  gint width,
208 +                                  gint height,
209 +                                  HTMLImagePointer *ip)
210 +{
211 +  HTMLEngine* e = ip->factory->engine;
212 +  gint new_width = width;
213 +  gint new_height = height;
214 +
215 +  if (!e->image_max_size_set)
216 +    return;
217 +
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;
222 +  }
223 +
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;
228 +  }
229 +
230 +  if ((width != new_width) || (height != new_height)) {
231 +    ip->rescaled = TRUE;
232 +    gdk_pixbuf_loader_set_size (loader, new_width, new_height);
233 +  }
234 +}
235 +
236  static GdkPixbuf *
237  html_image_factory_get_missing (HTMLImageFactory *factory)
238  {
239 @@ -1321,6 +1378,8 @@
240         retval->iter = NULL;
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;
251         }
252 +       if (ip->pixbuf) {
253 +               g_object_unref (ip->pixbuf);
254 +               ip->pixbuf = NULL;
255 +       }
256         if (ip->iter) {
257                 g_object_unref (ip->iter);
258                 ip->iter = NULL;
259 @@ -1441,21 +1504,28 @@
260  
261         if (!ip) {
262                 ip = html_image_pointer_new (url, factory);
263 +    g_signal_connect (ip->loader, "size_prepared",
264 +                      G_CALLBACK (html_image_factory_size_prepared),
265 +                      ip);
266                 g_hash_table_insert (factory->loaded_images, ip->url, ip);
267                 if (*url) {
268 -                       g_signal_connect (G_OBJECT (ip->loader), "area_prepared",
269 -                                         G_CALLBACK (html_image_factory_area_prepared),
270 -                                         ip);
271 -
272 -                       g_signal_connect (G_OBJECT (ip->loader), "area_updated",
273 -                                         G_CALLBACK (html_image_factory_area_updated),
274 -                                         ip);
275 +                       g_signal_connect (G_OBJECT (ip->loader), "area_prepared",
276 +                                   G_CALLBACK (html_image_factory_area_prepared),
277 +                                 ip);
278 +
279 +                 g_signal_connect (G_OBJECT (ip->loader), "area_updated",
280 +                                 G_CALLBACK (html_image_factory_area_updated),
281 +                                 ip);
282                         stream = html_image_pointer_load (ip);
283                 }
284         } else {
285                 if (reload) {
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),
290 +                        ip);
291 +
292                         stream = html_image_pointer_load (ip);
293                 }
294         }
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
298 @@ -41,6 +41,8 @@
299         gint stall;
300         guint stall_timeout;
301         guint animation_timeout;
302 +  GdkPixbuf *pixbuf; /* Only used when image_max_size_set & image rescaled */
303 +  gboolean rescaled; /* to know image was rescaled */
304  };
305  
306  #define HTML_IMAGE(x) ((HTMLImage *)(x))