Browse Source

wkhtmltoimage: set stdout to binary mode before writing to it on Windows

This fixes #1758 and is essentially porting the fix for issue 61 on
Google Code (48bc4c82eb4b0fc4e78b865a15d957ce59280990).
Ashish Kulkarni 11 years ago
parent
commit
c2053e9842
2 changed files with 12 additions and 1 deletions
  1. 1 0
      CHANGELOG.md
  2. 11 1
      src/lib/imageconverter.cc

+ 1 - 0
CHANGELOG.md

@@ -1,5 +1,6 @@
 v0.12.2 (unreleased)
 --------------------
+* **#1758**: fix corrupt image when output is specified as "-" in wkhtmltoimage on Windows
 
 v0.12.1 (2014-06-26)
 --------------------

+ 11 - 1
src/lib/imageconverter.cc

@@ -35,6 +35,12 @@
 #include <QWebFrame>
 #include <QWebPage>
 #include <qapplication.h>
+
+#ifdef Q_OS_WIN32
+#include <fcntl.h>
+#include <io.h>
+#endif
+
 namespace wkhtmltopdf {
 
 ImageConverterPrivate::ImageConverterPrivate(ImageConverter & o, wkhtmltopdf::settings::ImageGlobal & s, const QString * data):
@@ -148,8 +154,12 @@ void ImageConverterPrivate::pagesLoaded(bool ok) {
 	else if (settings.out != "-" ) {
 		file.setFileName(settings.out);
 		openOk = file.open(QIODevice::WriteOnly);
-	} else
+	} else {
+#ifdef Q_OS_WIN32
+		_setmode(_fileno(stdout), _O_BINARY);
+#endif
 		openOk = file.open(stdout, QIODevice::WriteOnly);
+    }
 
 	if (!openOk) {
 		emit out.error("Could not write to output file");