Browse Source

fix handling of non-ASCII characters in command-line arguments

This was due to QString::fromLocal8Bit not working correctly
when parsing the command-line arguments. The initialization
of QCoreApplication should ideally happen as soon as possible,
but it has to be delayed in our case as we can only know whether
to initialize in graphics mode depending on the --use-xserver
command-line option.

To work this around, we call setlocale(LC_ALL, "") before parsing
the command-line arguments which ensures that the system codec
works correctly as per
http://thread.gmane.org/gmane.comp.lib.qt.general/43325/focus=43339

Fixes #1825 and the duplicates as well (#1990, #2002)
Ashish Kulkarni 11 years ago
parent
commit
6f2cafeca7
2 changed files with 14 additions and 0 deletions
  1. 7 0
      src/image/wkhtmltoimage.cc
  2. 7 0
      src/pdf/wkhtmltopdf.cc

+ 7 - 0
src/image/wkhtmltoimage.cc

@@ -26,7 +26,14 @@
 #include <wkhtmltox/imagesettings.hh>
 #include <wkhtmltox/utilities.hh>
 
+#if defined(Q_OS_UNIX)
+#include <locale.h>
+#endif
+
 int main(int argc, char** argv) {
+#if defined(Q_OS_UNIX)
+	setlocale(LC_ALL, "");
+#endif
 	//This will store all our settings
 	wkhtmltopdf::settings::ImageGlobal settings;
 	//Create a command line parser to parse commandline arguments

+ 7 - 0
src/pdf/wkhtmltopdf.cc

@@ -34,6 +34,10 @@
 #include <wkhtmltox/pdfsettings.hh>
 #include <wkhtmltox/utilities.hh>
 
+#if defined(Q_OS_UNIX)
+#include <locale.h>
+#endif
+
 using namespace wkhtmltopdf::settings;
 using namespace wkhtmltopdf;
 
@@ -113,6 +117,9 @@ void parseString(char * buff, int &nargc, char **nargv) {
 }
 
 int main(int argc, char * argv[]) {
+#if defined(Q_OS_UNIX)
+	setlocale(LC_ALL, "");
+#endif
 	//This will store all our settings
 	PdfGlobal globalSettings;
 	QList<PdfObject> objectSettings;