hello
I did some more testing and found the problem: with www.heise.de for
some reason a call to page->mainFrame()->render() changes the value of
page->mainFrame()->contentsSize() (it grows in width)!
I patched the code to check that and retry the rendering if the sizes
differ. for www.heise.de it takes 6 to 8 iterations until the size
changes no more! I had not time to do extensive testing but I found no
other site were this happens!
any thought?
is this a bug or a feature of QWebPage/QFrame?
if you want to verify this apply the attached patch (which is quickly
and dirty written just for testing purposes!).
regards
hermann
--- webkit-image.cpp 2008-12-21 22:11:04.000000000 +0100
+++ webkit-image_webpage.cpp 2008-12-21 22:05:08.000000000 +0100
@@ -13,6 +13,8 @@
#include <QtWebKit/QWebPage>
#include <QtWebKit/QWebFrame>
+#include <iostream>
+
/* using mingw to set binary mode */
#ifdef WIN32
#include <io.h>
@@ -35,18 +37,34 @@
{
if(ok)
{
- page->setViewportSize(page->mainFrame()->contentsSize());
- QImage im(page->viewportSize(), QImage::Format_ARGB32);
- QPainter painter(&im);
- page->mainFrame()->render(&painter);
+ int retries = 10;
+ QImage *im;
+ QPainter *painter;
+ do {
+ page->setViewportSize( page->mainFrame()->contentsSize() );
+ im = new QImage( page->viewportSize(), QImage::Format_ARGB32 );
+ painter = new QPainter( im );
+ page->mainFrame()->render( painter );
+ retries--;
+ if (retries >= 0 && page->viewportSize() !=
page->mainFrame()->contentsSize()) {
+ // rendering changed the size of the page!
+ std::cerr << "contentsSize before call to render (" <<
+ page->viewportSize().height() << ", " <<
page->viewportSize().width() << ") differs from that afterwards (" <<
+ page->mainFrame()->contentsSize().height() << ", " <<
page->mainFrame()->contentsSize().width() << ")" << std::endl;
+ delete painter;
+ delete im;
+ }
+ else
+ break;
+ } while (retries >= 0);
QFile f;
BINARYSTDOUT
if(f.open(stdout, QIODevice::WriteOnly|QIODevice::Unbuffered))
{
- if(!im.save(&f, "JPEG"))
+ if(!im->save(&f, "JPEG"))
{
- im.save(&f, "PNG");
+ im->save(&f, "PNG");
}
}
}
@@ -73,6 +91,9 @@
QObject::connect(page, SIGNAL(loadFinished(bool)), s, SLOT(loaded(bool)));
QObject::connect(s, SIGNAL(finish(void)), &a, SLOT(quit()));
+
+ page->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff);
+ page->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff);
page->mainFrame()->load (QUrl(url));
return a.exec();
}
_______________________________________________
josm-dev mailing list
[email protected]
http://lists.openstreetmap.org/listinfo/josm-dev