Browse Source

add option --dump-render-tree for viewing the WebKit render tree

This can be useful for understanding the structure of the input HTML
and seeing how it translates into the browser's render tree.

This is not available for Qt5 as support for it was removed:
http://trac.webkit.org/changeset/136235/trunk/Source/WebKit/qt/WidgetApi/qwebframe.h
Ashish Kulkarni 10 years ago
parent
commit
715cc3dd48

+ 1 - 0
CHANGELOG.md

@@ -2,6 +2,7 @@ v0.12.2 (unreleased)
 --------------------
 * use OpenSSL 1.0.1j for the Windows builds
 * fix build failure with unpatched Qt >= 5.3
+* add option --dump-render-tree for viewing the WebKit render tree
 * **#1539**: **[qt]** using OpenType fonts now results in selectable text on Windows
 * **#1638**: **[qt]** fix incorrect rendering of JPEG images on Windows Server 2008 x64
 * **#1640**: **[qt]** make table page-break logic opt-in via CSS at the row level

+ 3 - 0
include/wkhtmltox/pdfsettings.hh

@@ -121,6 +121,9 @@ struct DLL_PUBLIC PdfGlobal {
 	//! The file where in to store the output
 	QString out;
 
+	//! dump render tree information to this file
+	QString dumpRenderTree;
+
 	QString documentTitle;
 
 	bool useCompression;

+ 1 - 0
src/lib/pdf_c_bindings.cc

@@ -114,6 +114,7 @@
  * - \b outlineDepth The maximal depth of the outline, e.g. "4".
  * - \b dumpOutline If not set to the empty string a XML representation of the outline is dumped to this file.
  * - \b out The path of the output file, if "-" output is sent to stdout, if empty the output is stored in a buffer.
+ * - \b dumpRenderTree If not set to the empty string the WebKit render tree is dumped to this file.
  * - \b documentTitle The title of the PDF document.
  * - \b useCompression Should we use loss less compression when creating the pdf file? Must be either "true" or "false".
  * - \b margin.top Size of the top margin, e.g. "2cm"

+ 17 - 0
src/lib/pdfconverter.cc

@@ -1008,6 +1008,23 @@ void PdfConverterPrivate::printDocument() {
 		outline->dump(sd.stream);
 	}
 
+	if (!settings.dumpRenderTree.isEmpty()) {
+#if QT_VERSION < 0x050000
+		StreamDumper sd(settings.dumpRenderTree);
+		for (int d=0; d < objects.size(); ++d) {
+			if (!objects[d].loaderObject || objects[d].loaderObject->skip || objects[d].settings.isTableOfContent)
+				continue;
+
+			sd.stream << "===========================================================" << endl
+				<< objects[d].settings.page.toUtf8().constData() << endl
+				<< "===========================================================" << endl
+				<< objects[d].page->mainFrame()->renderTreeDump().toUtf8().constData() << endl << endl;
+		}
+#else
+		emit out.warning("dumpRenderTree is not supported on Qt5.");
+#endif
+	}
+
  	painter->end();
 #endif
 	if (settings.out == "-" && lout != "/dev/stdout") {

+ 2 - 0
src/lib/pdfsettings.cc

@@ -119,6 +119,7 @@ struct DLL_LOCAL ReflectImpl<PdfGlobal>: public ReflectClass {
 		WKHTMLTOPDF_REFLECT(outline);
 		WKHTMLTOPDF_REFLECT(dumpOutline);
 		WKHTMLTOPDF_REFLECT(out);
+		WKHTMLTOPDF_REFLECT(dumpRenderTree);
 		WKHTMLTOPDF_REFLECT(documentTitle);
 		WKHTMLTOPDF_REFLECT(useCompression);
 		WKHTMLTOPDF_REFLECT(margin);
@@ -378,6 +379,7 @@ PdfGlobal::PdfGlobal():
 	outlineDepth(4),
 	dumpOutline(""),
 	out(""),
+	dumpRenderTree(""),
 	documentTitle(""),
 	useCompression(true),
 	viewportSize(""),

+ 3 - 0
src/lib/pdfsettings.hh

@@ -124,6 +124,9 @@ struct DLL_PUBLIC PdfGlobal {
 	//! The file where in to store the output
 	QString out;
 
+	//! dump render tree information to this file
+	QString dumpRenderTree;
+
 	QString documentTitle;
 
 	bool useCompression;

+ 3 - 2
src/pdf/pdfarguments.cc

@@ -203,10 +203,11 @@ PdfCommandLineParser::PdfCommandLineParser(PdfGlobal & s, QList<PdfObject> & ps)
  	addarg("page-height", 0, "Page height", new UnitRealSetter(s.size.height,"unitreal"));
  	addarg("page-width", 0, "Page width", new UnitRealSetter(s.size.width,"unitreal"));
 
-// 	addarg("book",'b',"Set the options one would usually set when printing a book", new Caller<BookFunc>());
+#if QT_VERSION < 0x050000
+	addarg("dump-render-tree",0,"Dump the WebKit render tree to a file (for debugging)",new QStrSetter(s.dumpRenderTree,"file"));
+#endif
 	addGlobalLoadArgs(s.load);
 
-
 	extended(true);
  	qthack(true);