On Wednesday 11 April 2012 20:05:39 Milian Wolff wrote: > Hey all, > > I'm interested in improving the printing support of the QtWebKit port. > > I notice that a lot of unit tests are skipped and that apparently > isPrinting() is not implemented/handled at all yet. > > For quite some time now I'm trying to figure out what exactly would be > required to get this done but it seems to be far from easy... Is there any > documentation besides the chromium spagetthi test code on how the output > should look like or when to output what (image, text, both, ...)? > > As far as I can see, I will probably have to handle the isPrinting() mode in > DumpRenderTreeQt.cpp ~ ::dump() in the if(m_dumpPixels) branch. Currently, > that only paints the viewportSize() to an image. If I'm not mistaken, one > needs to create a copy or QWebFrame::print, similar to chromiums' > WebViewHost::paintPagesWithBoundaries. But what are the requirements on the > output? Is there *any* documentation on what the tests should output?
I've done this now, see the attached patch. It kind-of-works, e.g. for media- queries-print.html: http://imagebin.org/207870 But for setPrint.html I see horrible render bug which I do not the reason to: http://imagebin.org/207871 Note how the right border of the box is not properly drawn. Furthermore, the box is one pixel too high, or well - the bottom border is painted one pixel too far below. Compare to e.g. LayoutTests/platform/mac/printing/setPrinting- expected.png to see how it should look like. So... has anyone an idea of what could be going on here? Bye -- Milian Wolff | [email protected] | Software Engineer KDAB (Deutschland) GmbH&Co KG, a KDAB Group company Tel. Germany +49-30-521325470, Sweden (HQ) +46-563-540090 KDAB - Qt Experts - Platform-independent software solutions
diff --git a/Source/WebKit/qt/Api/qwebframe.cpp b/Source/WebKit/qt/Api/qwebframe.cpp
index dcf2306..a478b23 100644
--- a/Source/WebKit/qt/Api/qwebframe.cpp
+++ b/Source/WebKit/qt/Api/qwebframe.cpp
@@ -1509,7 +1509,7 @@ void QWebFrame::print(QPrinter *printer) const
int(qprinterRect.width() / zoomFactorX),
int(qprinterRect.height() / zoomFactorY));
- printContext.begin(pageRect.width());
+ printContext.begin(pageRect.width(), pageRect.height());
printContext.computePageRects(pageRect, /* headerHeight */ 0, /* footerHeight */ 0, /* userScaleFactor */ 1.0, pageHeight);
@@ -1584,6 +1584,51 @@ void QWebFrame::print(QPrinter *printer) const
#endif // QT_NO_PRINTER
/*!
+ Prints the frame to the given \a image with a 1px blue line between each page.
+
+ \sa print()
+*/
+void QWebFrame::paintPagesWithBoundaries(QImage& image)
+{
+ PrintContext printContext(d->frame);
+
+ QRect rect = d->frame->view()->frameRect();
+
+ IntRect pageRect(0, 0, rect.width(), rect.height());
+
+ printContext.begin(pageRect.width(), pageRect.height());
+ float pageHeight = 0;
+ printContext.computePageRects(pageRect, /* headerHeight */ 0, /* footerHeight */ 0, /* userScaleFactor */ 1.0, pageHeight);
+
+ QPainter painter;
+ int pageCount = printContext.pageCount();
+ // pages * pageHeight and 1px line between each page
+ int totalHeight = pageCount * (pageRect.height() + 1) - 1;
+ image = QImage(pageRect.width(), totalHeight, QImage::Format_ARGB32);
+ image.fill(Qt::white);
+ painter.begin(&image);
+
+ GraphicsContext ctx(&painter);
+ for(int i = 0; i < printContext.pageCount(); ++i) {
+ printContext.spoolPage(ctx, i, pageRect.width());
+ // translate to next page coordinates
+ ctx.translate(0, pageRect.height() + 1);
+
+ // if there is a next page, draw a blue line between these two
+ if (i + 1 < printContext.pageCount()) {
+ ctx.save();
+ ctx.setStrokeColor(Color(0, 0, 255), ColorSpaceDeviceRGB);
+ ctx.setFillColor(Color(0, 0, 255), ColorSpaceDeviceRGB);
+ ctx.drawLine(IntPoint(0, -1), IntPoint(pageRect.width(), -1));
+ ctx.restore();
+ }
+ }
+
+ painter.end();
+ printContext.end();
+}
+
+/*!
Evaluates the JavaScript defined by \a scriptSource using this frame as context
and returns the result of the last executed statement.
diff --git a/Source/WebKit/qt/Api/qwebframe.h b/Source/WebKit/qt/Api/qwebframe.h
index ff15777..a9092b3 100644
--- a/Source/WebKit/qt/Api/qwebframe.h
+++ b/Source/WebKit/qt/Api/qwebframe.h
@@ -226,6 +226,7 @@ Q_SIGNALS:
void pageChanged();
private:
+ void paintPagesWithBoundaries(QImage &);
friend class QGraphicsWebView;
friend class QWebPage;
friend class QWebPagePrivate;
diff --git a/Source/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp b/Source/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp
index ff7c094..986fe78 100644
--- a/Source/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp
+++ b/Source/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp
@@ -1213,6 +1213,11 @@ void DumpRenderTreeSupportQt::setHixie76WebSocketProtocolEnabled(QWebPage* page,
#endif
}
+void DumpRenderTreeSupportQt::paintPagesWithBoundaries(QWebFrame* frame, QImage& image)
+{
+ frame->paintPagesWithBoundaries(image);
+}
+
// Provide a backward compatibility with previously exported private symbols as of QtWebKit 4.6 release
void QWEBKIT_EXPORT qt_resumeActiveDOMObjects(QWebFrame* frame)
diff --git a/Source/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h b/Source/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h
index c77c41b..1bb4a9a 100644
--- a/Source/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h
+++ b/Source/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h
@@ -234,6 +234,8 @@ public:
static bool defaultHixie76WebSocketProtocolEnabled();
static void setHixie76WebSocketProtocolEnabled(QWebPage*, bool);
+
+ static void paintPagesWithBoundaries(QWebFrame*, QImage&);
};
#endif
diff --git a/Tools/DumpRenderTree/qt/DumpRenderTreeQt.cpp b/Tools/DumpRenderTree/qt/DumpRenderTreeQt.cpp
index 55d64ef..596f34f 100644
--- a/Tools/DumpRenderTree/qt/DumpRenderTreeQt.cpp
+++ b/Tools/DumpRenderTree/qt/DumpRenderTreeQt.cpp
@@ -950,11 +950,25 @@ void DumpRenderTree::dump()
// FIXME: All other ports don't dump pixels, if generatePixelResults is false.
if (m_dumpPixels) {
- QImage image(m_page->viewportSize(), QImage::Format_ARGB32);
- image.fill(Qt::white);
- QPainter painter(&image);
- mainFrame->render(&painter);
- painter.end();
+ QImage image;
+ if (!m_controller->isPrinting()) {
+ image = QImage(m_page->viewportSize(), QImage::Format_ARGB32);
+ image.fill(Qt::white);
+ QPainter painter(&image);
+ mainFrame->render(&painter);
+ painter.end();
+ } else {
+ /*
+ QPrinter printer;
+ printer.setOutputFormat(QPrinter::PdfFormat);
+ printer.setOutputFileName("test-dump-print.pdf");
+ printer.setResolution(96);
+ printer.setPaperSize(QSizeF(800, 600), QPrinter::DevicePixel);
+ printer.setPageMargins(qreal(0), qreal(0), qreal(0), qreal(0), QPrinter::DevicePixel);
+ mainFrame->print(&printer);
+ */
+ DumpRenderTreeSupportQt::paintPagesWithBoundaries(mainFrame, image);
+ }
QCryptographicHash hash(QCryptographicHash::Md5);
for (int row = 0; row < image.height(); ++row)
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ webkit-qt mailing list [email protected] http://lists.webkit.org/mailman/listinfo.cgi/webkit-qt
