Browse Source

Preformed lib app split
added c bindings

Jakob Truelsen 15 years ago
parent
commit
c1d6c1c1c2
72 changed files with 2599 additions and 516 deletions
  1. 2 0
      common.pri
  2. 54 0
      include/wkhtmltox/converter.hh
  3. 36 0
      include/wkhtmltox/dllbegin.inc
  4. 22 0
      include/wkhtmltox/dllend.inc
  5. 57 0
      include/wkhtmltox/image.h
  6. 18 24
      include/wkhtmltox/imageconverter.hh
  7. 88 0
      include/wkhtmltox/imagesettings.hh
  8. 115 0
      include/wkhtmltox/loadsettings.hh
  9. 69 0
      include/wkhtmltox/multipageloader.hh
  10. 67 0
      include/wkhtmltox/pdf.h
  11. 21 19
      include/wkhtmltox/pdfconverter.hh
  12. 222 0
      include/wkhtmltox/pdfsettings.hh
  13. 29 18
      include/wkhtmltox/settings.hh
  14. 61 0
      include/wkhtmltox/websettings.hh
  15. 1 0
      scripts/sourcefix.py
  16. 7 9
      src/image/image.pro
  17. 2 2
      src/image/imagearguments.cc
  18. 7 7
      src/image/imagecommandlineparser.cc
  19. 8 8
      src/image/imagecommandlineparser.hh
  20. 9 9
      src/image/imagedocparts.cc
  21. 5 5
      src/image/wkhtmltoimage.cc
  22. 0 0
      src/lib/converter.cc
  23. 4 2
      src/lib/converter.hh
  24. 4 1
      src/lib/converter_p.hh
  25. 39 0
      src/lib/dllbegin.inc
  26. 25 0
      src/lib/dllend.inc
  27. 60 0
      src/lib/image.h
  28. 128 0
      src/lib/image_c_bindings.cc
  29. 55 0
      src/lib/image_c_bindings_p.hh
  30. 3 3
      src/lib/imageconverter.cc
  31. 7 5
      src/lib/imageconverter.hh
  32. 6 3
      src/lib/imageconverter_p.hh
  33. 82 0
      src/lib/imagesettings.cc
  34. 13 18
      src/lib/imagesettings.hh
  35. 47 0
      src/lib/lib.pri
  36. 28 0
      src/lib/lib.pro
  37. 16 0
      src/lib/loadsettings.cc
  38. 11 8
      src/lib/loadsettings.hh
  39. 0 0
      src/lib/multipageloader.cc
  40. 7 5
      src/lib/multipageloader.hh
  41. 10 9
      src/lib/multipageloader_p.hh
  42. 6 6
      src/lib/outline.cc
  43. 11 10
      src/lib/outline.hh
  44. 6 7
      src/lib/outline_p.hh
  45. 70 0
      src/lib/pdf.h
  46. 153 0
      src/lib/pdf_c_bindings.cc
  47. 57 0
      src/lib/pdf_c_bindings_p.hh
  48. 20 17
      src/lib/pdfconverter.cc
  49. 10 8
      src/lib/pdfconverter.hh
  50. 10 8
      src/lib/pdfconverter_p.hh
  51. 194 4
      src/lib/pdfsettings.cc
  52. 225 0
      src/lib/pdfsettings.hh
  53. 82 0
      src/lib/reflect.cc
  54. 225 0
      src/lib/reflect.hh
  55. 2 0
      src/lib/tempfile.cc
  56. 5 1
      src/lib/tempfile.hh
  57. 1 1
      src/lib/tocstylesheet.cc
  58. 0 0
      src/lib/websettings.cc
  59. 4 1
      src/lib/websettings.hh
  60. 7 8
      src/pdf/pdf.pro
  61. 7 7
      src/pdf/pdfarguments.cc
  62. 10 10
      src/pdf/pdfcommandlineparser.cc
  63. 11 11
      src/pdf/pdfcommandlineparser.hh
  64. 15 15
      src/pdf/pdfdocparts.cc
  65. 0 219
      src/pdf/tocprinter.cc
  66. 13 13
      src/pdf/wkhtmltopdf.cc
  67. 1 1
      src/shared/arghandler.inl
  68. 2 2
      src/shared/commandlineparserbase.hh
  69. 1 1
      src/shared/commonarguments.cc
  70. 1 1
      src/shared/progressfeedback.hh
  71. 3 9
      src/shared/shared.pri
  72. 2 1
      wkhtmltopdf.pro

+ 2 - 0
common.pri

@@ -37,6 +37,8 @@ MOC_DIR = ../../build
 OBJECTS_DIR = ../../build
 OBJECTS_DIR = ../../build
 UI_DIR = ../../build
 UI_DIR = ../../build
 
 
+INCLUDEPATH += ../../include
+
 win32 {
 win32 {
     CONFIG += console
     CONFIG += console
 }
 }

+ 54 - 0
include/wkhtmltox/converter.hh

@@ -0,0 +1,54 @@
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __CONVERTER_HH__
+#define __CONVERTER_HH__
+#include <QObject>
+
+#include <wkhtmltox/dllbegin.inc>
+namespace wkhtmltopdf {
+
+class DLL_LOCAL ConverterPrivate;
+
+class DLL_PUBLIC Converter: public QObject {
+    Q_OBJECT
+public:
+	virtual ~Converter() {};
+
+    int currentPhase();
+	int phaseCount();
+    QString phaseDescription(int phase=-1);
+    QString progressString();
+    int httpErrorCode();
+signals:
+    void warning(const QString & message);
+    void error(const QString & message);
+    void phaseChanged();
+    void progressChanged(int progress);
+    void finished(bool ok);
+public slots:
+    void beginConvertion();
+	bool convert();
+	void cancel();
+protected:
+	virtual ConverterPrivate & priv() = 0;
+	friend class ConverterPrivate;
+};
+
+}
+#include <wkhtmltox/dllend.inc>
+#endif //__CONVERTER_HH__

+ 36 - 0
include/wkhtmltox/dllbegin.inc

@@ -0,0 +1,36 @@
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+#ifndef __WKHTMLTOPDF_DLLBEGIN__
+#define __WKHTMLTOPDF_DLLBEGIN__
+
+#if defined _WIN32 || defined __CYGWIN__
+  #ifdef BUILDING_DLL
+     #define DLL_PUBLIC __declspec(dllexport)
+  #else
+     #define DLL_PUBLIC __declspec(dllimport)
+  #endif
+  #define DLL_LOCAL
+#else
+  #if __GNUC__ >= 4
+    #define DLL_PUBLIC __attribute__ ((visibility("default")))
+    #define DLL_LOCAL  __attribute__ ((visibility("hidden")))
+  #else
+    #define DLL_PUBLIC
+    #define DLL_LOCAL
+  #endif
+#endif
+
+#define CAPI extern "C" DLL_PUBLIC
+
+#endif //__WKHTMLTOPDF_DLLBEGIN__

+ 22 - 0
include/wkhtmltox/dllend.inc

@@ -0,0 +1,22 @@
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+#ifdef __WKHTMLTOPDF_DLLBEGIN__
+
+#undef __WKHTMLTOPDF_DLLBEGIN__
+#undef DLL_PUBLIC
+#undef DLL_LOCAL
+#undef CAPI
+
+#endif //__WKHTMLTOPDF_DLLBEGIN__
+

+ 57 - 0
include/wkhtmltox/image.h

@@ -0,0 +1,57 @@
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __IMAGE_H__
+#define __IMAGE_H__
+#include <wkhtmltox/dllbegin.inc>
+
+struct wkhtmltoimage_global_settings;
+typedef struct wkhtmltoimage_global_settings wkhtmltoimage_global_settings;
+
+struct wkhtmltoimage_converter;
+typedef struct wkhtmltoimage_converter wkhtmltoimage_converter;
+
+typedef void (*wkhtmltoimage_str_callback)(wkhtmltoimage_converter * converter, const char * str);
+typedef void (*wkhtmltoimage_int_callback)(wkhtmltoimage_converter * converter, const int val);
+typedef void (*wkhtmltoimage_bool_callback)(wkhtmltoimage_converter * converter, const bool val);
+typedef void (*wkhtmltoimage_void_callback)(wkhtmltoimage_converter * converter);
+
+CAPI wkhtmltoimage_global_settings * wkhtmltoinage_create_global_settings();
+
+CAPI int wkhtmltoimage_set_global_option(wkhtmltoimage_global_settings * settings, const char * name, const char * value);
+CAPI int wkhtmltoimage_get_global_option(wkhtmltoimage_global_settings * settings, const char * name, char * value, int vs);
+
+CAPI wkhtmltoimage_converter * wkhtmltoimage_create_converter(wkhtmltoimage_global_settings * settings);
+CAPI void wkhtmltoimage_destroy_converter(wkhtmltoimage_converter * converter);
+
+CAPI void wkhtmltoimage_set_warning_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_str_callback * cb);
+CAPI void wkhtmltoimage_set_error_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_str_callback * cb);
+CAPI void wkhtmltoimage_set_phase_changed_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_void_callback * cb);
+CAPI void wkhtmltoimage_set_progress_changed_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_int_callback * cb);
+CAPI void wkhtmltoimage_set_finished_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_bool_callback * cb);
+CAPI void wkhtmltoimage_begin_convertion(wkhtmltoimage_converter * converter);
+CAPI bool wkhtmltoimage_convert(wkhtmltoimage_converter * converter);
+CAPI void wkhtmltoimage_cancel(wkhtmltoimage_converter * converter);
+
+CAPI int wkhtmltoimage_current_phase(wkhtmltoimage_converter * converter);
+CAPI int wkhtmltoimage_phase_count(wkhtmltoimage_converter * converter);
+CAPI const char * wkhtmltoimage_phase_description(wkhtmltoimage_converter * converter, int phase);
+CAPI const char * wkhtmltoimage_progress_string(wkhtmltoimage_converter * converter);
+CAPI int wkhtmltoimage_http_error_code(wkhtmltoimage_converter * converter);
+
+#include <wkhtmltox/dllend.inc>
+#endif //__IMAGE_H__

+ 18 - 24
src/image/settings.cc → include/wkhtmltox/imageconverter.hh

@@ -1,6 +1,3 @@
-// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
-// vi:set ts=4 sts=4 sw=4 noet :
-//
 // Copyright 2010 wkhtmltopdf authors
 // Copyright 2010 wkhtmltopdf authors
 //
 //
 // This file is part of wkhtmltopdf.
 // This file is part of wkhtmltopdf.
@@ -18,30 +15,27 @@
 // You should have received a copy of the GNU General Public License
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
-#include "settings.hh"
+#ifndef __IMAGECONVERTER_HH__
+#define __IMAGECONVERTER_HH__
+#include <wkhtmltox/converter.hh>
+#include <wkhtmltox/imagesettings.hh>
 
 
+#include <wkhtmltox/dllbegin.inc>
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
-	namespace settings {
 
 
-	CropSettings:: CropSettings():
-		left(-1),
-		top(-1),
-		width(-1),
-		height(-1) {}
+class DLL_LOCAL ImageConverterPrivate;
 
 
-	//ScaleSettings::ScaleSettings():
-	//	width(-1),
-	//	height(-1) {}
+class DLL_PUBLIC ImageConverter: public Converter {
+	Q_OBJECT
+public:
+	ImageConverter(settings::ImageGlobal & settings);
+	~ImageConverter();
+private:
+	ImageConverterPrivate * d;
+	virtual ConverterPrivate & priv();
+	friend class ImageConverterPrivate;
+};
 
 
-	Global::Global():
-		screenWidth(1024),
-		quiet(false),
-		transparent(false),
-		useGraphics(false),
-		in(""),
-		out(""),
-		fmt(""),
-		quality(94),
-		smartWidth(true) {}
-	}
+#include <wkhtmltox/dllend.inc>
 }
 }
+#endif //__IMAGECONVERTER_HH__

+ 88 - 0
include/wkhtmltox/imagesettings.hh

@@ -0,0 +1,88 @@
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __IMAGESETTINGS_HH__
+#define __IMAGESETTINGS_HH__
+#include <QString>
+#include <wkhtmltox/loadsettings.hh>
+#include <wkhtmltox/websettings.hh>
+
+#include <wkhtmltox/dllbegin.inc>
+namespace wkhtmltopdf {
+namespace settings {
+
+/*! \brief Settings for cropping image */
+struct DLL_PUBLIC CropSettings {
+	CropSettings();
+	//! Cropping left/x coord
+	int left;
+	//! Cropping top/y coord
+	int top;
+	//! Cropping width/w dime
+	int width;
+	//! Cropping height/h dime
+	int height;
+};
+
+/*! \brief Class holding all user settings.
+
+    This class holds all the user settings, settings can be filled in by hand,
+    or with other methods.
+    \sa CommandLineParser::parse()
+*/
+struct DLL_PUBLIC ImageGlobal {
+	ImageGlobal();
+
+	//! Crop related settings
+	CropSettings crop;
+	//! Scale related settings
+	// ScaleSettings scale;
+
+	LoadGlobal loadGlobal;
+	LoadPage loadPage;
+	Web web;
+
+	//! Be less verbose
+	bool quiet;
+
+	bool transparent;
+
+	//! Should we use the graphics system
+	bool useGraphics;
+
+	QString in;
+	//! The file for output
+	QString out;
+	//! The output format
+	QString fmt;
+
+	//! Set the screen width
+	int screenWidth;
+
+	//! Image Quality
+	int quality;
+
+	bool smartWidth;
+
+	QString get(const char * name);
+	bool set(const char * name, const QString & value);
+};
+
+#include <wkhtmltox/dllend.inc>
+}
+}
+#endif //__IMAGESETTINGS_HH__

+ 115 - 0
include/wkhtmltox/loadsettings.hh

@@ -0,0 +1,115 @@
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __LOADSETTINGS_HH__
+#define __LOADSETTINGS_HH__
+#include <QNetworkProxy>
+#include <QString>
+
+#include <wkhtmltox/dllbegin.inc>
+namespace wkhtmltopdf {
+namespace settings {
+
+/*! \brief Settings consdering proxy */
+struct DLL_PUBLIC Proxy {
+	Proxy();
+	//! Type of proxy to use
+	QNetworkProxy::ProxyType type;
+	//! The port of the proxy to use
+	int port;
+	//! The host name of the proxy to use or NULL
+	QString host;
+	//! Username for the said proxy or NULL
+	QString user;
+	//! Password for the said proxy or NULL
+	QString password;
+};
+
+struct DLL_PUBLIC PostItem {
+	QString name;
+	QString value;
+	bool file;
+};
+
+struct DLL_PUBLIC LoadGlobal {
+	LoadGlobal();
+	//! Path of the cookie jar file
+	QString cookieJar;
+};
+
+struct DLL_PUBLIC LoadPage {
+	LoadPage();
+
+	enum LoadErrorHandling {
+		abort,
+		skip,
+		ignore
+	};
+
+	//! Username used for http auth login
+	QString username;
+
+	//! Password used for http auth login
+	QString password;
+
+	//! How many milliseconds should we wait for a Javascript redirect
+	int jsdelay;
+
+	//! What zoom factor should we apply when printing
+	// TODO MOVE
+	float zoomFactor;
+
+	//! Map of custum header variables
+	QList< QPair<QString, QString> > customHeaders;
+
+	//! Set if the custom header should be repeated for each resource request
+	bool repeatCustomHeaders;
+
+	//! Map of cookies
+	QList< QPair<QString, QString> > cookies;
+
+	QList< PostItem > post;
+
+	//! Block access to local files for the given page
+	bool blockLocalFileAccess;
+
+	//! If access to local files is not allowed in general, allow it for these files
+	QList< QString > allowed;
+
+	//! Stop Javascript from running too long
+	bool stopSlowScripts;
+
+	//! Output Javascript debug messages
+	bool debugJavascript;
+
+	//! What should we do about load errors
+	LoadErrorHandling loadErrorHandling;
+
+	//! Proxy related settings
+	Proxy proxy;
+};
+
+DLL_PUBLIC LoadPage::LoadErrorHandling strToLoadErrorHandling(const char * s, bool * ok=0);
+DLL_PUBLIC QString loadErrorHandlingToStr(LoadPage::LoadErrorHandling leh);
+
+DLL_PUBLIC Proxy strToProxy(const char * s, bool * ok=0);
+DLL_PUBLIC QString proxyToStr(const Proxy & proxy);
+
+}
+}
+#include <wkhtmltox/dllend.inc>
+#endif //__LOADSETTINGS_HH__

+ 69 - 0
include/wkhtmltox/multipageloader.hh

@@ -0,0 +1,69 @@
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __MULTIPAGELOADER_HH__
+#define __MULTIPAGELOADER_HH__
+#include <QFile>
+#include <QObject>
+#include <QUrl>
+#include <QWebPage>
+#include <wkhtmltox/loadsettings.hh>
+
+#include <wkhtmltox/dllbegin.inc>
+namespace wkhtmltopdf {
+
+class DLL_LOCAL MyQWebPage;
+
+class DLL_LOCAL LoaderObject {
+public:
+	QWebPage & page;
+	bool skip;
+
+	LoaderObject(QWebPage & page);
+};
+
+class DLL_LOCAL MultiPageLoaderPrivate;
+class DLL_LOCAL MultiPageLoader: public QObject {
+	Q_OBJECT
+public:
+	MultiPageLoader(settings::LoadGlobal & s);
+	~MultiPageLoader();
+	LoaderObject * addResource(const QString & url, const settings::LoadPage & settings);
+	LoaderObject * addResource(const QUrl & url, const settings::LoadPage & settings);
+	static QUrl guessUrlFromString(const QString &string);
+	int httpErrorCode();
+	static bool copyFile(QFile & src, QFile & dst);
+public slots:
+	void load();
+	void clearResources();
+	void cancel();
+signals:
+	void loadFinished(bool ok);
+	void loadProgress(int progress);
+	void loadStarted();
+	void warning(QString text);
+	void error(QString text);
+private:
+	MultiPageLoaderPrivate * d;
+	friend class MultiPageLoaderPrivate;
+	friend class MyQWebPage;
+	friend class ResourceObject;
+};
+
+}
+#include <wkhtmltox/dllend.inc>
+#endif //__MULTIPAGELOADER_HH__

+ 67 - 0
include/wkhtmltox/pdf.h

@@ -0,0 +1,67 @@
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __PDF_H__
+#define __PDF_H__
+#include <wkhtmltox/dllbegin.inc>
+
+struct wkhtmltopdf_global_settings;
+typedef struct wkhtmltopdf_global_settings wkhtmltopdf_global_settings;
+
+struct wkhtmltopdf_object_settings;
+typedef struct wkhtmltopdf_object_settings wkhtmltopdf_object_settings;
+
+struct wkhtmltopdf_converter;
+typedef struct wkhtmltopdf_converter wkhtmltopdf_converter;
+
+
+typedef void (*wkhtmltopdf_str_callback)(wkhtmltopdf_converter * converter, const char * str);
+typedef void (*wkhtmltopdf_int_callback)(wkhtmltopdf_converter * converter, const int val);
+typedef void (*wkhtmltopdf_bool_callback)(wkhtmltopdf_converter * converter, const bool val);
+typedef void (*wkhtmltopdf_void_callback)(wkhtmltopdf_converter * converter);
+
+CAPI wkhtmltopdf_global_settings * wkhtmltopdf_create_global_settings();
+CAPI wkhtmltopdf_object_settings * wkhtmltopdf_create_object_settings();
+
+CAPI int wkhtmltopdf_set_global_option(wkhtmltopdf_global_settings * settings, const char * name, const char * value);
+CAPI int wkhtmltopdf_get_global_option(wkhtmltopdf_global_settings * settings, const char * name, char * value, int vs);
+CAPI int wkhtmltopdf_set_object_option(wkhtmltopdf_object_settings * settings, const char * name, const char * value);
+CAPI int wkhtmltopdf_get_object_option(wkhtmltopdf_object_settings * settings, const char * name, char * value, int vs);
+
+
+CAPI wkhtmltopdf_converter * wkhtmltopdf_create_converter(wkhtmltopdf_global_settings * settings);
+CAPI void wkhtmltopdf_destroy_converter(wkhtmltopdf_converter * converter);
+
+CAPI void wkhtmltopdf_set_warning_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_str_callback * cb);
+CAPI void wkhtmltopdf_set_error_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_str_callback * cb);
+CAPI void wkhtmltopdf_set_phase_changed_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_void_callback * cb);
+CAPI void wkhtmltopdf_set_progress_changed_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_int_callback * cb);
+CAPI void wkhtmltopdf_set_finished_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_bool_callback * cb);
+CAPI void wkhtmltopdf_begin_convertion(wkhtmltopdf_converter * converter);
+CAPI bool wkhtmltopdf_convert(wkhtmltopdf_converter * converter);
+CAPI void wkhtmltopdf_cancel(wkhtmltopdf_converter * converter);
+CAPI void wkhtmltopdf_add_resource(
+	wkhtmltopdf_converter * converter, wkhtmltopdf_object_settings * setting, const char * data=0);
+
+CAPI int wkhtmltopdf_current_phase(wkhtmltopdf_converter * converter);
+CAPI int wkhtmltopdf_phase_count(wkhtmltopdf_converter * converter);
+CAPI const char * wkhtmltopdf_phase_description(wkhtmltopdf_converter * converter, int phase);
+CAPI const char * wkhtmltopdf_progress_string(wkhtmltopdf_converter * converter);
+CAPI int wkhtmltopdf_http_error_code(wkhtmltopdf_converter * converter);
+
+#include <wkhtmltox/dllend.inc>
+#endif //__PDF_H__

+ 21 - 19
src/pdf/tocprinter.hh → include/wkhtmltox/pdfconverter.hh

@@ -1,6 +1,3 @@
-// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
-// vi:set ts=4 sts=4 sw=4 noet :
-//
 // Copyright 2010 wkhtmltopdf authors
 // Copyright 2010 wkhtmltopdf authors
 //
 //
 // This file is part of wkhtmltopdf.
 // This file is part of wkhtmltopdf.
@@ -18,29 +15,34 @@
 // You should have received a copy of the GNU General Public License
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
-#ifndef __TOCPRINTER_HH__
-#define __TOCPRINTER_HH__
-#include <QWebFrame>
-#ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
-#include "outline.hh"
-#include <QPainter>
-#include <QPrinter>
+#ifndef __PDFCONVERTER_HH__
+#define __PDFCONVERTER_HH__
+#include <wkhtmltox/converter.hh>
+#include <wkhtmltox/pdfsettings.hh>
 
 
+#include <wkhtmltox/dllbegin.inc>
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 
 
-class TocPrinterPrivate;
+DLL_PUBLIC void dumpDefaultTOCStyleSheet(QTextStream & stream, settings::TableOfContent & s);
+
+class DLL_LOCAL PdfConverterPrivate;
 
 
-class TocPrinter {
+class DLL_PUBLIC PdfConverter: public Converter {
+	Q_OBJECT
 public:
 public:
-	TocPrinter(Outline * outline, QPrinter * printer, QPainter & painter);
-	~TocPrinter();
+	PdfConverter(settings::PdfGlobal & globalSettings);
+	~PdfConverter();
 	int pageCount();
 	int pageCount();
-	void spoolPage(int page);
-	void fillLinks(int doc, QVector<QPair<QWebElement, QString> > & links);
+	void addResource(const settings::PdfObject & pageSettings);
+	const settings::PdfGlobal & globalSettings() const;
 private:
 private:
-	TocPrinterPrivate * d;
+	PdfConverterPrivate * d;
+	virtual ConverterPrivate & priv();
+	friend class PdfConverterPrivate;
+signals:
+	void producingForms(bool);
 };
 };
 
 
 }
 }
-#endif //__EXTENSIVE_WKHTMLTOPDF_QT_HACK__
-#endif //__TOCPRINTER_HH__
+#include <wkhtmltox/dllend.inc>
+#endif //__PDFCONVERTER_HH__

+ 222 - 0
include/wkhtmltox/pdfsettings.hh

@@ -0,0 +1,222 @@
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __PDFSETTINGS_HH__
+#define __PDFSETTINGS_HH__
+#include <QNetworkProxy>
+#include <QPrinter>
+#include <QString>
+#include <wkhtmltox/loadsettings.hh>
+#include <wkhtmltox/websettings.hh>
+
+#include <wkhtmltox/dllbegin.inc>
+namespace wkhtmltopdf {
+namespace settings {
+
+typedef QPair<qreal, QPrinter::Unit> UnitReal;
+
+/*! \brief Settings consdering margins */
+struct DLL_PUBLIC Margin {
+	Margin();
+	//!Margin applied to the top of the page
+	UnitReal top;
+	//!Margin applied to the right of the page
+	UnitReal right;
+	//!Margin applied to the bottom of the page
+	UnitReal bottom;
+	//!Margin applied to the leftp of the page
+	UnitReal left;
+};
+
+/*! \brief Settings considering page size */
+struct DLL_PUBLIC Size {
+	Size();
+	//! What size paper should we use
+	QPrinter::PageSize pageSize;
+	//!Height of the page
+	UnitReal height;
+	//!Width of the page
+	UnitReal width;
+};
+
+/*! \brief Settings considdirng the table of content */
+struct DLL_PUBLIC TableOfContent {
+	TableOfContent();
+	//! Should we print dots between the name and the page number?
+	bool useDottedLines;
+	//! Name af the TOC
+	QString captionText;
+	//! Link from TOC to section headers
+	bool forwardLinks;
+	//! Link from section headers to TOC
+	bool backLinks;
+	//! How fare should we indent on every level
+	QString indentation;
+	//! Factor we should scale the font with on every level
+	float fontScale;
+};
+
+/*! \brief Class holding all user setting.
+    This class holds all the user settings, settings can be filled in by hand,
+    or with other methods.
+    \sa CommandLineParser::parse()
+*/
+struct DLL_PUBLIC PdfGlobal {
+	PdfGlobal();
+
+	//! Size related settings
+	Size size;
+
+	//! Be less verbose
+	bool quiet;
+
+	//! Should we use the graphics system
+	bool useGraphics;
+
+	//! Should we orientate in landscape or portrate
+	QPrinter::Orientation orientation;
+
+	//! Color or grayscale
+	QPrinter::ColorMode colorMode;
+
+	//! What overall resolution should we use
+	QPrinter::PrinterMode resolution;
+
+	//! What dpi should be used when printing
+	int dpi;
+
+	//! When pagenumbers are printed, apply this offset to them all
+	int pageOffset;
+
+	//! How many copies do we wan to print
+	int copies;
+
+	//! Should be print a whole copy before beginnig the next
+	bool collate;
+
+	//! Should we generate an outline and put it into the pdf file
+	bool outline;
+
+	//! Maximal depth of the generated outline
+	int outlineDepth;
+
+	//! dump outline to this filename
+	QString dumpOutline;
+
+	//! The file where in to store the output
+	QString out;
+
+	QString documentTitle;
+
+	bool useCompression;
+
+	//! Margin related settings
+	Margin margin;
+
+	//! Specify the output format we should use
+	QString outputFormat;
+
+	int imageDPI;
+	int imageQuality;
+
+	LoadGlobal load;
+
+	QString get(const char * name);
+	bool set(const char * name, const QString & value);
+};
+
+/*! \brief Settings considering headers and footers */
+struct DLL_PUBLIC HeaderFooter {
+	HeaderFooter();
+	//! Size of the font used to render the text
+	int fontSize;
+	//! Name of font used to render text
+	QString fontName;
+	//! Text to render at the left
+	QString left;
+	//! Text to render at the right
+	QString right;
+	//! Text to render at the center
+	QString center;
+	//! Should a line seperate the header/footer and the document
+	bool line;
+	//! Url of the document the html document that should be used as a header/footer
+	QString htmlUrl;
+	//! Spacing
+	float spacing;
+};
+
+struct DLL_PUBLIC PdfObject {
+	PdfObject();
+	//! Settings regarding the TOC
+	TableOfContent toc;
+
+	QString page;
+
+	//! Header related settings
+	HeaderFooter header;
+
+	//! Header related settings
+	HeaderFooter footer;
+
+	//! Should external links be links in the PDF
+	bool useExternalLinks;
+
+	//! Should internal links be links in the PDF
+	bool useLocalLinks;
+
+	//! Replacements
+	QList< QPair<QString, QString> > replacements;
+
+	//! Convert forms on the pages into PDF forms
+	bool produceForms;
+
+	LoadPage load;
+
+	Web web;
+
+	bool includeInOutline;
+
+	bool pagesCount;
+
+	bool isTableOfContent;
+
+	QString tocXsl;
+
+	QString get(const char * name);
+	bool set(const char * name, const QString & value);
+};
+
+DLL_PUBLIC QPrinter::PageSize strToPageSize(const char * s, bool * ok=0);
+DLL_PUBLIC QString pageSizeToStr(QPrinter::PageSize ps);
+
+DLL_PUBLIC UnitReal strToUnitReal(const char * s, bool * ok=0);
+DLL_PUBLIC QString unitRealToStr(const UnitReal & ur, bool * ok);
+
+DLL_PUBLIC QPrinter::Orientation strToOrientation(const char * s, bool * ok=0);
+DLL_PUBLIC QString orientationToStr(QPrinter::Orientation o);
+
+DLL_PUBLIC QPrinter::PrinterMode strToPrinterMode(const char * s, bool * ok=0);
+DLL_PUBLIC QString printerModeToStr(QPrinter::PrinterMode o);
+
+DLL_PUBLIC QPrinter::ColorMode strToColorMode(const char * s, bool * ok=0);
+DLL_PUBLIC QString colorModeToStr(QPrinter::ColorMode o);
+
+}
+}
+#include <wkhtmltox/dllend.inc>
+#endif //__PDFSETTINGS_HH__

+ 29 - 18
src/pdf/settings.hh → include/wkhtmltox/settings.hh

@@ -1,6 +1,3 @@
-// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
-// vi:set ts=4 sts=4 sw=4 noet :
-//
 // Copyright 2010 wkhtmltopdf authors
 // Copyright 2010 wkhtmltopdf authors
 //
 //
 // This file is part of wkhtmltopdf.
 // This file is part of wkhtmltopdf.
@@ -20,19 +17,20 @@
 
 
 #ifndef __SETTINGS_HH__
 #ifndef __SETTINGS_HH__
 #define __SETTINGS_HH__
 #define __SETTINGS_HH__
-#include "loadsettings.hh"
-#include "websettings.hh"
+#include <wkhtmltopdf/loadsettings.hh>
+#include <wkhtmltopdf/websettings.hh>
 #include <QNetworkProxy>
 #include <QNetworkProxy>
 #include <QPrinter>
 #include <QPrinter>
 #include <QString>
 #include <QString>
 
 
+#include <wkhtmltopdf/dllbegin.inc>
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 namespace settings {
 namespace settings {
 
 
 typedef QPair<qreal, QPrinter::Unit> UnitReal;
 typedef QPair<qreal, QPrinter::Unit> UnitReal;
 
 
 /*! \brief Settings consdering margins */
 /*! \brief Settings consdering margins */
-struct Margin {
+struct DLL_PUBLIC Margin {
 	Margin();
 	Margin();
 	//!Margin applied to the top of the page
 	//!Margin applied to the top of the page
 	UnitReal top;
 	UnitReal top;
@@ -45,7 +43,7 @@ struct Margin {
 };
 };
 
 
 /*! \brief Settings considering page size */
 /*! \brief Settings considering page size */
-struct Size {
+struct DLL_PUBLIC Size {
 	Size();
 	Size();
 	//! What size paper should we use
 	//! What size paper should we use
 	QPrinter::PageSize pageSize;
 	QPrinter::PageSize pageSize;
@@ -56,7 +54,7 @@ struct Size {
 };
 };
 
 
 /*! \brief Settings considdirng the table of content */
 /*! \brief Settings considdirng the table of content */
-struct TableOfContent {
+struct DLL_PUBLIC TableOfContent {
 	TableOfContent();
 	TableOfContent();
 	//! Should we print dots between the name and the page number?
 	//! Should we print dots between the name and the page number?
 	bool useDottedLines;
 	bool useDottedLines;
@@ -72,13 +70,12 @@ struct TableOfContent {
 	float fontScale;
 	float fontScale;
 };
 };
 
 
-
 /*! \brief Class holding all user setting.
 /*! \brief Class holding all user setting.
     This class holds all the user settings, settings can be filled in by hand,
     This class holds all the user settings, settings can be filled in by hand,
     or with other methods.
     or with other methods.
     \sa CommandLineParser::parse()
     \sa CommandLineParser::parse()
 */
 */
-struct Global {
+struct DLL_PUBLIC Global {
 	Global();
 	Global();
 
 
 	//! Size related settings
 	//! Size related settings
@@ -137,10 +134,13 @@ struct Global {
 	int imageQuality;
 	int imageQuality;
 
 
 	LoadGlobal load;
 	LoadGlobal load;
+
+	QString get(const char * name);
+	bool set(const char * name, const QString & value);
 };
 };
 
 
 /*! \brief Settings considering headers and footers */
 /*! \brief Settings considering headers and footers */
-struct HeaderFooter {
+struct DLL_PUBLIC HeaderFooter {
 	HeaderFooter();
 	HeaderFooter();
 	//! Size of the font used to render the text
 	//! Size of the font used to render the text
 	int fontSize;
 	int fontSize;
@@ -160,7 +160,7 @@ struct HeaderFooter {
 	float spacing;
 	float spacing;
 };
 };
 
 
-struct Page {
+struct DLL_PUBLIC Page {
 	Page();
 	Page();
 	//! Settings regarding the TOC
 	//! Settings regarding the TOC
 	TableOfContent toc;
 	TableOfContent toc;
@@ -196,16 +196,27 @@ struct Page {
 	bool isTableOfContent;
 	bool isTableOfContent;
 
 
 	QString tocXsl;
 	QString tocXsl;
+
+	QString get(const char * name);
+	bool set(const char * name, const QString & value);
 };
 };
 
 
-QPrinter::PageSize strToPageSize(const char * s, bool * ok=0);
-QString pageSizeToStr(QPrinter::PageSize ps);
+DLL_PUBLIC QPrinter::PageSize strToPageSize(const char * s, bool * ok=0);
+DLL_PUBLIC QString pageSizeToStr(QPrinter::PageSize ps);
+
+DLL_PUBLIC UnitReal strToUnitReal(const char * s, bool * ok=0);
+DLL_PUBLIC QString unitRealToStr(const UnitReal & ur, bool * ok);
+
+DLL_PUBLIC QPrinter::Orientation strToOrientation(const char * s, bool * ok=0);
+DLL_PUBLIC QString orientationToStr(QPrinter::Orientation o);
+
+DLL_PUBLIC QPrinter::PrinterMode strToPrinterMode(const char * s, bool * ok=0);
+DLL_PUBLIC QString printerModeToStr(QPrinter::PrinterMode o);
 
 
-UnitReal strToUnitReal(const char * s, bool * ok=0);
-QString unitRealToStr(const UnitReal & ur, bool * ok);
+DLL_PUBLIC QPrinter::ColorMode strToColorMode(const char * s, bool * ok=0);
+DLL_PUBLIC QString colorModeToStr(QPrinter::ColorMode o);
 
 
-QPrinter::Orientation strToOrientation(const char * s, bool * ok=0);
-QString orientationToStr(QPrinter::Orientation o);
 }
 }
 }
 }
+#include <wkhtmltopdf/dllend.inc>
 #endif //__SETTINGS_HH__
 #endif //__SETTINGS_HH__

+ 61 - 0
include/wkhtmltox/websettings.hh

@@ -0,0 +1,61 @@
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __WEBSETTINGS_HH__
+#define __WEBSETTINGS_HH__
+#include <QNetworkProxy>
+#include <QString>
+
+#include <wkhtmltox/dllbegin.inc>
+namespace wkhtmltopdf {
+namespace settings {
+
+struct DLL_PUBLIC Web {
+	Web();
+
+	//! Should we print background images
+	bool background;
+
+	//! Should we load images
+	bool loadImages;
+
+	//! Should we enable Javascript
+	bool enableJavascript;
+
+	//! Should the horrible intelligent shrinking feature be enabled?
+	bool enableIntelligentShrinking;
+
+	//! Minimum font size
+	int minimumFontSize;
+
+	//! Should we use the print or the screen media type
+	bool printMediaType;
+
+	//! Encoding used to enterpit a document with do supplied encoding
+	QString defaultEncoding;
+
+	//! Stylesheet supplied by the user
+	QString userStyleSheet;
+
+	//! Should plugins be allowed
+	bool enablePlugins;
+};
+
+}
+}
+#include <wkhtmltox/dllend.inc>
+#endif //__WEBSETTINGS_HH__

+ 1 - 0
scripts/sourcefix.py

@@ -38,6 +38,7 @@ def includesort(x):
 changes=False
 changes=False
 progname="wkhtmltopdf"
 progname="wkhtmltopdf"
 for path in argv[1:]:
 for path in argv[1:]:
+	if path.split("/")[0] == "include": continue
 	try:
 	try:
 		data = file(path).read()
 		data = file(path).read()
 	except:
 	except:

+ 7 - 9
src/image/image.pro

@@ -18,12 +18,6 @@
 include(../../version.pri)
 include(../../version.pri)
 include(../../common.pri)
 include(../../common.pri)
 
 
-QT += svg
-
-MOC_DIR = ../../build/image
-OBJECTS_DIR = ../../build/image
-UI_DIR = ../../build/image
-
 TEMPLATE = app
 TEMPLATE = app
 TARGET = wkhtmltoimage
 TARGET = wkhtmltoimage
 DESTDIR = ../../bin
 DESTDIR = ../../bin
@@ -55,7 +49,11 @@ target.path=$$INSTALLBASE/bin
 
 
 include(../shared/shared.pri)
 include(../shared/shared.pri)
 
 
+contains(DEFINES, QT_SHARED) {
+  LIBS += -L../../bin -lwkhtmltox
+} else {
+  include(../lib/lib.pri)
+}
+
 # Input
 # Input
-HEADERS += imageconverter.hh imageconverter_p.hh settings.hh converter.hh
-SOURCES += wkhtmltoimage.cc arguments.cc commandlineparser.cc docparts.cc \
-           imageconverter.cc settings.cc
+SOURCES += wkhtmltoimage.cc imagearguments.cc imagecommandlineparser.cc imagedocparts.cc

+ 2 - 2
src/image/arguments.cc → src/image/imagearguments.cc

@@ -19,10 +19,10 @@
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
 #include "arghandler.inl"
 #include "arghandler.inl"
-#include "commandlineparser.hh"
+#include "imagecommandlineparser.hh"
 #include <qglobal.h>
 #include <qglobal.h>
 
 
-CommandLineParser::CommandLineParser(wkhtmltopdf::settings::Global & s):
+ImageCommandLineParser::ImageCommandLineParser(wkhtmltopdf::settings::ImageGlobal & s):
 	settings(s) {
 	settings(s) {
 	mode(global);
 	mode(global);
 	section("General Options");
 	section("General Options");

+ 7 - 7
src/image/commandlineparser.cc → src/image/imagecommandlineparser.cc

@@ -18,20 +18,20 @@
 // You should have received a copy of the GNU General Public License
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
-#include "commandlineparser.hh"
+#include "imagecommandlineparser.hh"
 #include "outputter.hh"
 #include "outputter.hh"
 #include <qwebframe.h>
 #include <qwebframe.h>
 
 
 /*!
 /*!
   \file commandlineparser.hh
   \file commandlineparser.hh
-  \brief Defines the CommandLineParser class
+  \brief Defines the ImageCommandLineParser class
 */
 */
 
 
 /*!
 /*!
   Output the man page to a given file
   Output the man page to a given file
   \param fd The file to store the man page
   \param fd The file to store the man page
 */
 */
-void CommandLineParser::manpage(FILE * fd) const {
+void ImageCommandLineParser::manpage(FILE * fd) const {
 	Outputter * o = Outputter::man(fd);
 	Outputter * o = Outputter::man(fd);
  	outputManName(o);
  	outputManName(o);
  	outputSynopsis(o);
  	outputSynopsis(o);
@@ -47,7 +47,7 @@ void CommandLineParser::manpage(FILE * fd) const {
   \param fd The file to output the information to
   \param fd The file to output the information to
   \param extended Should we show extended arguments
   \param extended Should we show extended arguments
 */
 */
-void CommandLineParser::usage(FILE * fd, bool extended) const {
+void ImageCommandLineParser::usage(FILE * fd, bool extended) const {
 	Outputter * o = Outputter::text(fd,false);
 	Outputter * o = Outputter::text(fd,false);
 	outputName(o);
 	outputName(o);
 	outputSynopsis(o);
 	outputSynopsis(o);
@@ -65,7 +65,7 @@ void CommandLineParser::usage(FILE * fd, bool extended) const {
   \param fd The file to output to
   \param fd The file to output to
   \param html Do we want the html manaul, or the README
   \param html Do we want the html manaul, or the README
 */
 */
-void CommandLineParser::readme(FILE * fd, bool html) const {
+void ImageCommandLineParser::readme(FILE * fd, bool html) const {
 	Outputter * o = html?Outputter::html(fd):Outputter::text(fd, true);
 	Outputter * o = html?Outputter::html(fd):Outputter::text(fd, true);
 	outputDocStart(o);
 	outputDocStart(o);
 	outputContact(o);
 	outputContact(o);
@@ -85,7 +85,7 @@ void CommandLineParser::readme(FILE * fd, bool html) const {
 /*!
 /*!
  * Load default arguments and put them in the settings structure
  * Load default arguments and put them in the settings structure
  */
  */
-// void CommandLineParser::loadDefaults() {
+// void ImageCommandLineParser::loadDefaults() {
 // 	d->settings.in = "-";
 // 	d->settings.in = "-";
 // 	d->settings.proxy.host = "";
 // 	d->settings.proxy.host = "";
 // 	foreach (ArgHandler * h, d->longToHandler)
 // 	foreach (ArgHandler * h, d->longToHandler)
@@ -109,7 +109,7 @@ void CommandLineParser::readme(FILE * fd, bool html) const {
  * \param argc the number of command line arguments
  * \param argc the number of command line arguments
  * \param argv a NULL terminated list with the arguments
  * \param argv a NULL terminated list with the arguments
  */
  */
-void CommandLineParser::parseArguments(int argc, const char ** argv, bool final) {
+void ImageCommandLineParser::parseArguments(int argc, const char ** argv, bool final) {
 	settings.in="";
 	settings.in="";
     settings.out="";
     settings.out="";
 	bool defaultMode=false;
 	bool defaultMode=false;

+ 8 - 8
src/image/commandlineparser.hh → src/image/imagecommandlineparser.hh

@@ -18,22 +18,22 @@
 // You should have received a copy of the GNU General Public License
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
-#ifndef __COMMANDLINEPARSER_HH__
-#define __COMMANDLINEPARSER_HH__
+#ifndef __IMAGECOMMANDLINEPARSER_HH__
+#define __IMAGECOMMANDLINEPARSER_HH__
 #include "commandlineparserbase.hh"
 #include "commandlineparserbase.hh"
-#include "settings.hh"
 #include <cstdio>
 #include <cstdio>
+#include <wkhtmltox/imagesettings.hh>
 
 
 /*! \brief The class is responcible for parsing command line information
 /*! \brief The class is responcible for parsing command line information
 */
 */
-class CommandLineParser: public CommandLineParserBase {
+class ImageCommandLineParser: public CommandLineParserBase {
 public:
 public:
 	const static int global = 1;
 	const static int global = 1;
-	wkhtmltopdf::settings::Global & settings;
+	wkhtmltopdf::settings::ImageGlobal & settings;
 
 
 	//arguments.cc
 	//arguments.cc
-	CommandLineParser(wkhtmltopdf::settings::Global & settings);
-	~CommandLineParser() {};
+	ImageCommandLineParser(wkhtmltopdf::settings::ImageGlobal & settings);
+	~ImageCommandLineParser() {};
 	//docparts.cc
 	//docparts.cc
 	void outputManName(Outputter * o) const;
 	void outputManName(Outputter * o) const;
 	void outputSynopsis(Outputter * o) const;
 	void outputSynopsis(Outputter * o) const;
@@ -57,4 +57,4 @@ public:
 	void parseArguments(int argc, const char ** argv, bool final=false);
 	void parseArguments(int argc, const char ** argv, bool final=false);
 
 
 };
 };
-#endif //__COMMANDLINEPARSER_HH__
+#endif //__IMAGECOMMANDLINEPARSER_HH__

+ 9 - 9
src/image/docparts.cc → src/image/imagedocparts.cc

@@ -18,7 +18,7 @@
 // You should have received a copy of the GNU General Public License
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
-#include "commandlineparser.hh"
+#include "imagecommandlineparser.hh"
 #include "outputter.hh"
 #include "outputter.hh"
 #include <QWebFrame>
 #include <QWebFrame>
 
 
@@ -29,7 +29,7 @@
   Output name and a short description
   Output name and a short description
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputManName(Outputter * o) const {
+void ImageCommandLineParser::outputManName(Outputter * o) const {
 	o->beginSection("Name");
 	o->beginSection("Name");
 	o->paragraph("wkhtmltoimage - html to image converter");
 	o->paragraph("wkhtmltoimage - html to image converter");
 	o->endSection();
 	o->endSection();
@@ -39,7 +39,7 @@ void CommandLineParser::outputManName(Outputter * o) const {
   Output a short synopsis on how to call the command line program
   Output a short synopsis on how to call the command line program
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputSynopsis(Outputter * o) const {
+void ImageCommandLineParser::outputSynopsis(Outputter * o) const {
 	o->beginSection("Synopsis");
 	o->beginSection("Synopsis");
 	o->verbatim("wkhtmltoimage [OPTIONS]... <input file> <output file>\n");
 	o->verbatim("wkhtmltoimage [OPTIONS]... <input file> <output file>\n");
 	o->endSection();
 	o->endSection();
@@ -49,7 +49,7 @@ void CommandLineParser::outputSynopsis(Outputter * o) const {
   Explain what the program does
   Explain what the program does
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputDescripton(Outputter * o) const {
+void ImageCommandLineParser::outputDescripton(Outputter * o) const {
 	o->beginSection("Description");
 	o->beginSection("Description");
 	o->beginParagraph();
 	o->beginParagraph();
 	o->text("Converts an HTML page into an image, ");
 	o->text("Converts an HTML page into an image, ");
@@ -62,7 +62,7 @@ void CommandLineParser::outputDescripton(Outputter * o) const {
   Output contact information
   Output contact information
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputContact(Outputter * o) const {
+void ImageCommandLineParser::outputContact(Outputter * o) const {
 	o->beginSection("Contact");
 	o->beginSection("Contact");
 	o->beginParagraph();
 	o->beginParagraph();
 	o->text("If you experience bugs or want to request new features please visit ");
 	o->text("If you experience bugs or want to request new features please visit ");
@@ -77,7 +77,7 @@ void CommandLineParser::outputContact(Outputter * o) const {
   Output beginning of the readme
   Output beginning of the readme
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputDocStart(Outputter * o) const {
+void ImageCommandLineParser::outputDocStart(Outputter * o) const {
 	o->beginSection(QString("wkhtmltoimage ")+QString::number(MAJOR_VERSION)+"."+QString::number(MINOR_VERSION)+"."+QString::number(PATCH_VERSION)+(QString(STRINGIZE(BUILD)).isEmpty()?"":" ")+STRINGIZE(BUILD) + " Manual");
 	o->beginSection(QString("wkhtmltoimage ")+QString::number(MAJOR_VERSION)+"."+QString::number(MINOR_VERSION)+"."+QString::number(PATCH_VERSION)+(QString(STRINGIZE(BUILD)).isEmpty()?"":" ")+STRINGIZE(BUILD) + " Manual");
 	o->paragraph("This file documents wkhtmltoimage, a program capable of converting HTML "
 	o->paragraph("This file documents wkhtmltoimage, a program capable of converting HTML "
 				 "documents into images.");
 				 "documents into images.");
@@ -88,7 +88,7 @@ void CommandLineParser::outputDocStart(Outputter * o) const {
   Output information on how to compile
   Output information on how to compile
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputCompilation(Outputter * o) const {
+void ImageCommandLineParser::outputCompilation(Outputter * o) const {
 	o->beginSection("Compilation");
 	o->beginSection("Compilation");
 	o->paragraph("It can happen that the static binary does not work for your system "
 	o->paragraph("It can happen that the static binary does not work for your system "
 		     "for one reason or the other, in that case you might need to compile "
 		     "for one reason or the other, in that case you might need to compile "
@@ -101,7 +101,7 @@ void CommandLineParser::outputCompilation(Outputter * o) const {
   Output information on how to install
   Output information on how to install
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputInstallation(Outputter * o) const {
+void ImageCommandLineParser::outputInstallation(Outputter * o) const {
 	o->beginSection("Installation");
 	o->beginSection("Installation");
 	o->paragraph(
 	o->paragraph(
 		"There are several ways to install wkhtmltoimage.  You can download a "
 		"There are several ways to install wkhtmltoimage.  You can download a "
@@ -113,7 +113,7 @@ void CommandLineParser::outputInstallation(Outputter * o) const {
   Output examples on how to use wkhtmltoimage
   Output examples on how to use wkhtmltoimage
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputExamples(Outputter * o) const {
+void ImageCommandLineParser::outputExamples(Outputter * o) const {
 	o->beginSection("Examples");
 	o->beginSection("Examples");
 	o->paragraph("This section presents a number of examples of how to invoke wkhtmltoimage.");
 	o->paragraph("This section presents a number of examples of how to invoke wkhtmltoimage.");
 	o->paragraph("To convert a remote HTML file to PNG:");
 	o->paragraph("To convert a remote HTML file to PNG:");

+ 5 - 5
src/image/wkhtmltoimage.cc

@@ -18,19 +18,19 @@
 // You should have received a copy of the GNU General Public License
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
-#include "commandlineparser.hh"
-#include "imageconverter.hh"
+#include "imagecommandlineparser.hh"
 #include "progressfeedback.hh"
 #include "progressfeedback.hh"
-#include "settings.hh"
 #include "utilities.hh"
 #include "utilities.hh"
 #include <QApplication>
 #include <QApplication>
 #include <QWebFrame>
 #include <QWebFrame>
+#include <wkhtmltox/imageconverter.hh>
+#include <wkhtmltox/imagesettings.hh>
 
 
 int main(int argc, char** argv) {
 int main(int argc, char** argv) {
 	//This will store all our settings
 	//This will store all our settings
-	wkhtmltopdf::settings::Global settings;
+	wkhtmltopdf::settings::ImageGlobal settings;
 	//Create a command line parser to parse commandline arguments
 	//Create a command line parser to parse commandline arguments
-	CommandLineParser parser(settings);
+	ImageCommandLineParser parser(settings);
 	//Parse the arguments
 	//Parse the arguments
 	parser.parseArguments(argc, (const char**)argv);
 	parser.parseArguments(argc, (const char**)argv);
 
 

+ 0 - 0
src/shared/converter.cc → src/lib/converter.cc


+ 4 - 2
src/shared/converter.hh → src/lib/converter.hh

@@ -22,11 +22,12 @@
 #define __CONVERTER_HH__
 #define __CONVERTER_HH__
 #include <QObject>
 #include <QObject>
 
 
+#include <wkhtmltox/dllbegin.inc>
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 
 
-class ConverterPrivate;
+class DLL_LOCAL ConverterPrivate;
 
 
-class Converter: public QObject {
+class DLL_PUBLIC Converter: public QObject {
     Q_OBJECT
     Q_OBJECT
 public:
 public:
 	virtual ~Converter() {};
 	virtual ~Converter() {};
@@ -52,4 +53,5 @@ protected:
 };
 };
 
 
 }
 }
+#include <wkhtmltox/dllend.inc>
 #endif //__CONVERTER_HH__
 #endif //__CONVERTER_HH__

+ 4 - 1
src/shared/converter_p.hh → src/lib/converter_p.hh

@@ -25,9 +25,11 @@
 #include <QFile>
 #include <QFile>
 #include <QWebSettings>
 #include <QWebSettings>
 
 
+#include "dllbegin.inc"
+
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 
 
-class ConverterPrivate: public QObject {
+class DLL_LOCAL ConverterPrivate: public QObject {
 	Q_OBJECT
 	Q_OBJECT
 public:
 public:
 	void copyFile(QFile & src, QFile & dst);
 	void copyFile(QFile & src, QFile & dst);
@@ -59,4 +61,5 @@ private:
 };
 };
 
 
 }
 }
+#include "dllend.inc"
 #endif //__CONVERTER_P_HH__
 #endif //__CONVERTER_P_HH__

+ 39 - 0
src/lib/dllbegin.inc

@@ -0,0 +1,39 @@
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+#ifndef __WKHTMLTOPDF_DLLBEGIN__
+#define __WKHTMLTOPDF_DLLBEGIN__
+
+#if defined _WIN32 || defined __CYGWIN__
+  #ifdef BUILDING_DLL
+     #define DLL_PUBLIC __declspec(dllexport)
+  #else
+     #define DLL_PUBLIC __declspec(dllimport)
+  #endif
+  #define DLL_LOCAL
+#else
+  #if __GNUC__ >= 4
+    #define DLL_PUBLIC __attribute__ ((visibility("default")))
+    #define DLL_LOCAL  __attribute__ ((visibility("hidden")))
+  #else
+    #define DLL_PUBLIC
+    #define DLL_LOCAL
+  #endif
+#endif
+
+#define CAPI extern "C" DLL_PUBLIC
+
+#endif //__WKHTMLTOPDF_DLLBEGIN__

+ 25 - 0
src/lib/dllend.inc

@@ -0,0 +1,25 @@
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+#ifdef __WKHTMLTOPDF_DLLBEGIN__
+
+#undef __WKHTMLTOPDF_DLLBEGIN__
+#undef DLL_PUBLIC
+#undef DLL_LOCAL
+#undef CAPI
+
+#endif //__WKHTMLTOPDF_DLLBEGIN__
+

+ 60 - 0
src/lib/image.h

@@ -0,0 +1,60 @@
+// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
+// vi:set ts=4 sts=4 sw=4 noet :
+//
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __IMAGE_H__
+#define __IMAGE_H__
+#include <wkhtmltox/dllbegin.inc>
+
+struct wkhtmltoimage_global_settings;
+typedef struct wkhtmltoimage_global_settings wkhtmltoimage_global_settings;
+
+struct wkhtmltoimage_converter;
+typedef struct wkhtmltoimage_converter wkhtmltoimage_converter;
+
+typedef void (*wkhtmltoimage_str_callback)(wkhtmltoimage_converter * converter, const char * str);
+typedef void (*wkhtmltoimage_int_callback)(wkhtmltoimage_converter * converter, const int val);
+typedef void (*wkhtmltoimage_bool_callback)(wkhtmltoimage_converter * converter, const bool val);
+typedef void (*wkhtmltoimage_void_callback)(wkhtmltoimage_converter * converter);
+
+CAPI wkhtmltoimage_global_settings * wkhtmltoinage_create_global_settings();
+
+CAPI int wkhtmltoimage_set_global_option(wkhtmltoimage_global_settings * settings, const char * name, const char * value);
+CAPI int wkhtmltoimage_get_global_option(wkhtmltoimage_global_settings * settings, const char * name, char * value, int vs);
+
+CAPI wkhtmltoimage_converter * wkhtmltoimage_create_converter(wkhtmltoimage_global_settings * settings);
+CAPI void wkhtmltoimage_destroy_converter(wkhtmltoimage_converter * converter);
+
+CAPI void wkhtmltoimage_set_warning_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_str_callback * cb);
+CAPI void wkhtmltoimage_set_error_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_str_callback * cb);
+CAPI void wkhtmltoimage_set_phase_changed_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_void_callback * cb);
+CAPI void wkhtmltoimage_set_progress_changed_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_int_callback * cb);
+CAPI void wkhtmltoimage_set_finished_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_bool_callback * cb);
+CAPI void wkhtmltoimage_begin_convertion(wkhtmltoimage_converter * converter);
+CAPI bool wkhtmltoimage_convert(wkhtmltoimage_converter * converter);
+CAPI void wkhtmltoimage_cancel(wkhtmltoimage_converter * converter);
+
+CAPI int wkhtmltoimage_current_phase(wkhtmltoimage_converter * converter);
+CAPI int wkhtmltoimage_phase_count(wkhtmltoimage_converter * converter);
+CAPI const char * wkhtmltoimage_phase_description(wkhtmltoimage_converter * converter, int phase);
+CAPI const char * wkhtmltoimage_progress_string(wkhtmltoimage_converter * converter);
+CAPI int wkhtmltoimage_http_error_code(wkhtmltoimage_converter * converter);
+
+#include <wkhtmltox/dllend.inc>
+#endif //__IMAGE_H__

+ 128 - 0
src/lib/image_c_bindings.cc

@@ -0,0 +1,128 @@
+// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
+// vi:set ts=4 sts=4 sw=4 noet :
+//
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "image_c_bindings_p.hh"
+
+#include "dllbegin.inc"
+using namespace wkhtmltopdf;
+
+void MyImageConverter::warning(const QString & message) {
+	if (warning_cb) (*warning_cb)(reinterpret_cast<wkhtmltoimage_converter*>(this), message.toUtf8().constData());
+}
+
+void MyImageConverter::error(const QString & message) {
+	if (error_cb) (*error_cb)(reinterpret_cast<wkhtmltoimage_converter*>(this), message.toUtf8().constData());
+}
+
+void MyImageConverter::phaseChanged() {
+	if (phase_changed) (*phase_changed)(reinterpret_cast<wkhtmltoimage_converter*>(this));
+}
+
+void MyImageConverter::progressChanged(int progress) {
+	if (progress_changed) (*progress_changed)(reinterpret_cast<wkhtmltoimage_converter*>(this), progress);
+}
+
+void MyImageConverter::finished(bool ok) {
+	if (finished_cb) (*finished_cb)(reinterpret_cast<wkhtmltoimage_converter*>(this), ok);
+}
+
+MyImageConverter::MyImageConverter(settings::ImageGlobal * gs):
+	warning_cb(0), error_cb(0), phase_changed(0), progress_changed(0), finished_cb(0),
+	converter(*gs), globalSettings(gs) {}
+
+MyImageConverter::~MyImageConverter() {
+	delete globalSettings;
+}
+
+CAPI wkhtmltoimage_global_settings * wkhtmltoimage_create_global_settings() {
+	return reinterpret_cast<wkhtmltoimage_global_settings *>(new settings::ImageGlobal());
+}
+
+CAPI int wkhtmltoimage_set_global_option(wkhtmltoimage_global_settings * settings, const char * name, const char * value) {
+	return reinterpret_cast<settings::ImageGlobal *>(settings)->set(name, value);
+}
+
+CAPI int wkhtmltoimage_get_global_option(wkhtmltoimage_global_settings * settings, const char * name, char * value, int vs) {
+	QString res = reinterpret_cast<settings::ImageGlobal *>(settings)->get(name);
+	if (res.isNull()) return 0;
+	qstrncpy(value, res.toUtf8().constData(), vs);
+	return 1;
+}
+
+CAPI wkhtmltoimage_converter * wkhtmltoimage_create_converter(wkhtmltoimage_global_settings * settings) {
+	return reinterpret_cast<wkhtmltoimage_converter *>(
+		new MyImageConverter(reinterpret_cast<settings::ImageGlobal *>(settings)));
+}
+
+CAPI void wkhtmltoimage_destroy_converter(wkhtmltoimage_converter * converter) {
+	delete reinterpret_cast<MyImageConverter *>(converter);
+}
+
+CAPI void wkhtmltoimage_set_warning_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_str_callback * cb) {
+	reinterpret_cast<MyImageConverter *>(converter)->warning_cb = cb;
+}
+
+CAPI void wkhtmltoimage_set_error_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_str_callback * cb) {
+	reinterpret_cast<MyImageConverter *>(converter)->error_cb = cb;
+}
+
+CAPI void wkhtmltoimage_set_phase_changed_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_void_callback * cb) {
+	reinterpret_cast<MyImageConverter *>(converter)->phase_changed = cb;
+}
+
+CAPI void wkhtmltoimage_set_progress_changed_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_int_callback * cb) {
+	reinterpret_cast<MyImageConverter *>(converter)->progress_changed = cb;
+}
+
+CAPI void wkhtmltoimage_set_finished_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_bool_callback * cb) {
+	reinterpret_cast<MyImageConverter *>(converter)->finished_cb = cb;
+}
+
+CAPI void wkhtmltoimage_begin_convertion(wkhtmltoimage_converter * converter) {
+	reinterpret_cast<MyImageConverter *>(converter)->converter.beginConvertion();
+}
+
+CAPI bool wkhtmltoimage_convert(wkhtmltoimage_converter * converter) {
+	return reinterpret_cast<MyImageConverter *>(converter)->converter.convert();
+}
+
+CAPI void wkhtmltoimage_cancel(wkhtmltoimage_converter * converter) {
+	reinterpret_cast<MyImageConverter *>(converter)->converter.cancel();
+}
+
+CAPI int wkhtmltoimage_current_phase(wkhtmltoimage_converter * converter) {
+	return reinterpret_cast<MyImageConverter *>(converter)->converter.currentPhase();
+}
+
+CAPI int wkhtmltoimage_phase_count(wkhtmltoimage_converter * converter) {
+	return reinterpret_cast<MyImageConverter *>(converter)->converter.phaseCount();
+}
+
+CAPI const char * wkhtmltoimage_phase_description(wkhtmltoimage_converter * converter, int phase) {
+	return reinterpret_cast<MyImageConverter *>(converter)->converter.phaseDescription(phase).toUtf8().constData();
+}
+
+CAPI const char * wkhtmltoimage_progress_string(wkhtmltoimage_converter * converter) {
+	return reinterpret_cast<MyImageConverter *>(converter)->converter.progressString().toUtf8().constData();
+}
+
+CAPI int wkhtmltoimage_http_error_code(wkhtmltoimage_converter * converter) {
+	return reinterpret_cast<MyImageConverter *>(converter)->converter.httpErrorCode();
+}

+ 55 - 0
src/lib/image_c_bindings_p.hh

@@ -0,0 +1,55 @@
+// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
+// vi:set ts=4 sts=4 sw=4 noet :
+//
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __IMAGE_C_BINDINGS_P_HH__
+#define __IMAGE_C_BINDINGS_P_HH__
+#include "image.h"
+#include "imageconverter.hh"
+#include <QObject>
+
+#include "dllbegin.inc"
+
+class DLL_LOCAL MyImageConverter: public QObject {
+    Q_OBJECT
+public:
+	wkhtmltoimage_str_callback * warning_cb;
+	wkhtmltoimage_str_callback * error_cb;
+	wkhtmltoimage_void_callback * phase_changed;
+	wkhtmltoimage_int_callback * progress_changed;
+	wkhtmltoimage_bool_callback * finished_cb;
+
+	wkhtmltopdf::ImageConverter converter;
+
+	wkhtmltopdf::settings::ImageGlobal * globalSettings;
+
+	MyImageConverter(wkhtmltopdf::settings::ImageGlobal * gs);
+	~MyImageConverter();
+public slots:
+    void warning(const QString & message);
+    void error(const QString & message);
+    void phaseChanged();
+    void progressChanged(int progress);
+    void finished(bool ok);
+private:
+    MyImageConverter(const MyImageConverter&);
+};
+
+#include "dllend.inc"
+#endif //__IMAGE_C_BINDINGS_P_HH__

+ 3 - 3
src/image/imageconverter.cc → src/lib/imageconverter.cc

@@ -19,7 +19,7 @@
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
 #include "imageconverter_p.hh"
 #include "imageconverter_p.hh"
-#include "settings.hh"
+#include "imagesettings.hh"
 #include <QDebug>
 #include <QDebug>
 #include <QEventLoop>
 #include <QEventLoop>
 #include <QFileInfo>
 #include <QFileInfo>
@@ -34,7 +34,7 @@
 #include <qapplication.h>
 #include <qapplication.h>
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 
 
-ImageConverterPrivate::ImageConverterPrivate(ImageConverter & o, wkhtmltopdf::settings::Global & s):
+ImageConverterPrivate::ImageConverterPrivate(ImageConverter & o, wkhtmltopdf::settings::ImageGlobal & s):
 	settings(s),
 	settings(s),
 	loader(s.loadGlobal),
 	loader(s.loadGlobal),
 	out(o) {
 	out(o) {
@@ -214,7 +214,7 @@ ConverterPrivate & ImageConverter::priv() {
 }
 }
 
 
 
 
-ImageConverter::ImageConverter(wkhtmltopdf::settings::Global & s) {
+ImageConverter::ImageConverter(wkhtmltopdf::settings::ImageGlobal & s) {
 	d = new ImageConverterPrivate(*this, s);
 	d = new ImageConverterPrivate(*this, s);
 }
 }
 
 

+ 7 - 5
src/image/imageconverter.hh → src/lib/imageconverter.hh

@@ -20,17 +20,18 @@
 
 
 #ifndef __IMAGECONVERTER_HH__
 #ifndef __IMAGECONVERTER_HH__
 #define __IMAGECONVERTER_HH__
 #define __IMAGECONVERTER_HH__
-#include "converter.hh"
-#include "settings.hh"
+#include <wkhtmltox/converter.hh>
+#include <wkhtmltox/imagesettings.hh>
 
 
+#include <wkhtmltox/dllbegin.inc>
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 
 
-class ImageConverterPrivate;
+class DLL_LOCAL ImageConverterPrivate;
 
 
-class ImageConverter: public Converter {
+class DLL_PUBLIC ImageConverter: public Converter {
 	Q_OBJECT
 	Q_OBJECT
 public:
 public:
-	ImageConverter(settings::Global & settings);
+	ImageConverter(settings::ImageGlobal & settings);
 	~ImageConverter();
 	~ImageConverter();
 private:
 private:
 	ImageConverterPrivate * d;
 	ImageConverterPrivate * d;
@@ -38,5 +39,6 @@ private:
 	friend class ImageConverterPrivate;
 	friend class ImageConverterPrivate;
 };
 };
 
 
+#include <wkhtmltox/dllend.inc>
 }
 }
 #endif //__IMAGECONVERTER_HH__
 #endif //__IMAGECONVERTER_HH__

+ 6 - 3
src/image/imageconverter_p.hh → src/lib/imageconverter_p.hh

@@ -23,14 +23,16 @@
 #include "converter_p.hh"
 #include "converter_p.hh"
 #include "imageconverter.hh"
 #include "imageconverter.hh"
 #include "multipageloader.hh"
 #include "multipageloader.hh"
+
+#include "dllbegin.inc"
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 
 
-class ImageConverterPrivate: public ConverterPrivate {
+class DLL_LOCAL ImageConverterPrivate: public ConverterPrivate {
 	Q_OBJECT
 	Q_OBJECT
 public:
 public:
-	ImageConverterPrivate(ImageConverter & o, wkhtmltopdf::settings::Global & s);
+	ImageConverterPrivate(ImageConverter & o, wkhtmltopdf::settings::ImageGlobal & s);
 
 
-	wkhtmltopdf::settings::Global settings;
+	wkhtmltopdf::settings::ImageGlobal settings;
 	MultiPageLoader loader;
 	MultiPageLoader loader;
 private:
 private:
 	ImageConverter & out;
 	ImageConverter & out;
@@ -48,4 +50,5 @@ public slots:
 };
 };
 
 
 }
 }
+#include "dllend.inc"
 #endif //__IMAGECONVERTER_P_HH__
 #endif //__IMAGECONVERTER_P_HH__

+ 82 - 0
src/lib/imagesettings.cc

@@ -0,0 +1,82 @@
+// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
+// vi:set ts=4 sts=4 sw=4 noet :
+//
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "imagesettings.hh"
+#include "reflect.hh"
+
+#include "dllbegin.inc"
+namespace wkhtmltopdf {
+namespace settings {
+
+template<>
+struct DLL_LOCAL ReflectImpl<CropSettings>: public ReflectClass {
+	ReflectImpl(CropSettings & c) {
+		WKHTMLTOPDF_REFLECT(left);
+		WKHTMLTOPDF_REFLECT(top);
+		WKHTMLTOPDF_REFLECT(width);
+		WKHTMLTOPDF_REFLECT(height);
+	}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<ImageGlobal>: public ReflectClass {
+	ReflectImpl(ImageGlobal & c) {
+		WKHTMLTOPDF_REFLECT(screenWidth);
+		WKHTMLTOPDF_REFLECT(quiet);
+		WKHTMLTOPDF_REFLECT(transparent);
+		WKHTMLTOPDF_REFLECT(useGraphics);
+		WKHTMLTOPDF_REFLECT(in);
+		WKHTMLTOPDF_REFLECT(out);
+		WKHTMLTOPDF_REFLECT(fmt);
+		WKHTMLTOPDF_REFLECT(quality);
+		WKHTMLTOPDF_REFLECT(smartWidth);
+	}
+};
+
+CropSettings::CropSettings():
+	left(-1),
+	top(-1),
+	width(-1),
+	height(-1) {}
+
+ImageGlobal::ImageGlobal():
+	screenWidth(1024),
+	quiet(false),
+	transparent(false),
+	useGraphics(false),
+	in(""),
+	out(""),
+	fmt(""),
+	quality(94),
+	smartWidth(true) {}
+
+QString ImageGlobal::get(const char * name) {
+	ReflectImpl<ImageGlobal> impl(*this);
+	return impl.get(name);
+}
+
+bool ImageGlobal::set(const char * name, const QString & value) {
+	ReflectImpl<ImageGlobal> impl(*this);
+	return impl.set(name, value);
+}
+
+
+}
+}

+ 13 - 18
src/image/settings.hh → src/lib/imagesettings.hh

@@ -18,18 +18,18 @@
 // You should have received a copy of the GNU General Public License
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
-#ifndef __SETTINGS_HH__
-#define __SETTINGS_HH__
-#include "loadsettings.hh"
-#include "websettings.hh"
+#ifndef __IMAGESETTINGS_HH__
+#define __IMAGESETTINGS_HH__
 #include <QString>
 #include <QString>
+#include <wkhtmltox/loadsettings.hh>
+#include <wkhtmltox/websettings.hh>
 
 
+#include <wkhtmltox/dllbegin.inc>
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 namespace settings {
 namespace settings {
 
 
-
 /*! \brief Settings for cropping image */
 /*! \brief Settings for cropping image */
-struct CropSettings {
+struct DLL_PUBLIC CropSettings {
 	CropSettings();
 	CropSettings();
 	//! Cropping left/x coord
 	//! Cropping left/x coord
 	int left;
 	int left;
@@ -41,23 +41,14 @@ struct CropSettings {
 	int height;
 	int height;
 };
 };
 
 
-// /*! \brief Settings for scaling image */
-// struct ScaleSettings {
-// 	ScaleSettings();
-// 	//! Scale width/w dime
-// 	int width;
-// 	//! Scale height/h dime
-// 	int height;
-// };
-
 /*! \brief Class holding all user settings.
 /*! \brief Class holding all user settings.
 
 
     This class holds all the user settings, settings can be filled in by hand,
     This class holds all the user settings, settings can be filled in by hand,
     or with other methods.
     or with other methods.
     \sa CommandLineParser::parse()
     \sa CommandLineParser::parse()
 */
 */
-struct Global {
-	Global();
+struct DLL_PUBLIC ImageGlobal {
+	ImageGlobal();
 
 
 	//! Crop related settings
 	//! Crop related settings
 	CropSettings crop;
 	CropSettings crop;
@@ -89,8 +80,12 @@ struct Global {
 	int quality;
 	int quality;
 
 
 	bool smartWidth;
 	bool smartWidth;
+
+	QString get(const char * name);
+	bool set(const char * name, const QString & value);
 };
 };
 
 
+#include <wkhtmltox/dllend.inc>
 }
 }
 }
 }
-#endif //__SETTINGS_HH__
+#endif //__IMAGESETTINGS_HH__

+ 47 - 0
src/lib/lib.pri

@@ -0,0 +1,47 @@
+# Copyright 2010 wkhtmltopdf authors
+#
+# This file is part of wkhtmltopdf.
+#
+# wkhtmltopdf is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wkhtmltopdf is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with wkhtmltopdf.  If not, see <http:#www.gnu.org/licenses/>.
+
+DEFINES += BUILDING_DLL
+
+#Shared
+PUBLIC_HEADERS += ../lib/converter.hh ../lib/multipageloader.hh ../lib/dllbegin.inc
+PUBLIC_HEADERS += ../lib/dllend.inc ../lib/loadsettings.hh ../lib/websettings.hh
+HEADERS += ../lib/multipageloader_p.hh  ../lib/converter_p.hh
+SOURCES += ../lib/loadsettings.cc ../lib/multipageloader.cc ../lib/tempfile.cc \
+	   ../lib/converter.cc ../lib/websettings.cc  \
+  	   ../lib/reflect.cc
+
+#Pdf
+PUBLIC_HEADERS += ../lib/pdfconverter.hh ../lib/pdfsettings.hh
+HEADERS += ../lib/pdfconverter_p.hh
+SOURCES += ../lib/pdfsettings.cc ../lib/pdfconverter.cc \
+           ../lib/outline.cc ../lib/tocstylesheet.cc
+
+#Image
+QT += svg
+
+PUBLIC_HEADERS += ../lib/imageconverter.hh ../lib/imagesettings.hh
+HEADERS += ../lib/imageconverter_p.hh
+SOURCES += ../lib/imagesettings.cc ../lib/imageconverter.cc
+
+#C-Bindings
+PUBLIC_HEADERS += ../lib/pdf.h ../lib/image.h
+HEADERS += ../lib/pdf_c_bindings_p.hh ../lib/image_c_bindings_p.hh
+SOURCES += ../lib/pdf_c_bindings.cc ../lib/image_c_bindings.cc
+
+
+HEADERS += $$PUBLIC_HEADERS

+ 28 - 0
src/lib/lib.pro

@@ -0,0 +1,28 @@
+# Copyright 2010 wkhtmltopdf authors
+#
+# This file is part of wkhtmltopdf.
+#
+# wkhtmltopdf is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wkhtmltopdf is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with wkhtmltopdf.  If not, see <http:#www.gnu.org/licenses/>.
+
+TEMPLATE = lib
+CONFIG += dll
+
+CXX += -fvisibility=hidden -fvisibility-inlines-hidden
+
+include(../../version.pri)
+include(../../common.pri)
+include(lib.pri)
+
+TARGET = wkhtmltox
+DESTDIR = ../../bin

+ 16 - 0
src/shared/loadsettings.cc → src/lib/loadsettings.cc

@@ -95,6 +95,22 @@ Proxy strToProxy(const char * proxy, bool * ok) {
 	return p;
 	return p;
 }
 }
 
 
+QString proxyToStr(const Proxy & p) {
+	QString res="";
+	if (p.type == QNetworkProxy::HttpProxy)
+		res += "http://";
+	else if (p.type == QNetworkProxy::Socks5Proxy)
+		res += "socks5://";
+
+	if (!p.user.isEmpty()) {
+		res += "@" + p.user;
+		if (!p.password.isEmpty()) res += ":" + p.password;
+	}
+	res += p.host;
+	if (!p.host.isEmpty()) res += ":" + p.port;
+	return res;
+}
+
 Proxy::Proxy():
 Proxy::Proxy():
     type(QNetworkProxy::NoProxy),
     type(QNetworkProxy::NoProxy),
 	port(-1),
 	port(-1),

+ 11 - 8
src/shared/loadsettings.hh → src/lib/loadsettings.hh

@@ -22,11 +22,13 @@
 #define __LOADSETTINGS_HH__
 #define __LOADSETTINGS_HH__
 #include <QNetworkProxy>
 #include <QNetworkProxy>
 #include <QString>
 #include <QString>
+
+#include <wkhtmltox/dllbegin.inc>
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 namespace settings {
 namespace settings {
 
 
 /*! \brief Settings consdering proxy */
 /*! \brief Settings consdering proxy */
-struct Proxy {
+struct DLL_PUBLIC Proxy {
 	Proxy();
 	Proxy();
 	//! Type of proxy to use
 	//! Type of proxy to use
 	QNetworkProxy::ProxyType type;
 	QNetworkProxy::ProxyType type;
@@ -40,19 +42,19 @@ struct Proxy {
 	QString password;
 	QString password;
 };
 };
 
 
-struct PostItem {
+struct DLL_PUBLIC PostItem {
 	QString name;
 	QString name;
 	QString value;
 	QString value;
 	bool file;
 	bool file;
 };
 };
 
 
-struct LoadGlobal {
+struct DLL_PUBLIC LoadGlobal {
 	LoadGlobal();
 	LoadGlobal();
 	//! Path of the cookie jar file
 	//! Path of the cookie jar file
 	QString cookieJar;
 	QString cookieJar;
 };
 };
 
 
-struct LoadPage {
+struct DLL_PUBLIC LoadPage {
 	LoadPage();
 	LoadPage();
 
 
 	enum LoadErrorHandling {
 	enum LoadErrorHandling {
@@ -104,12 +106,13 @@ struct LoadPage {
 	Proxy proxy;
 	Proxy proxy;
 };
 };
 
 
-LoadPage::LoadErrorHandling strToLoadErrorHandling(const char * s, bool * ok=0);
-QString loadErrorHandlingToStr(LoadPage::LoadErrorHandling leh);
-
-Proxy strToProxy(const char * s, bool * ok=0);
+DLL_PUBLIC LoadPage::LoadErrorHandling strToLoadErrorHandling(const char * s, bool * ok=0);
+DLL_PUBLIC QString loadErrorHandlingToStr(LoadPage::LoadErrorHandling leh);
 
 
+DLL_PUBLIC Proxy strToProxy(const char * s, bool * ok=0);
+DLL_PUBLIC QString proxyToStr(const Proxy & proxy);
 
 
 }
 }
 }
 }
+#include <wkhtmltox/dllend.inc>
 #endif //__LOADSETTINGS_HH__
 #endif //__LOADSETTINGS_HH__

+ 0 - 0
src/shared/multipageloader.cc → src/lib/multipageloader.cc


+ 7 - 5
src/shared/multipageloader.hh → src/lib/multipageloader.hh

@@ -20,17 +20,18 @@
 
 
 #ifndef __MULTIPAGELOADER_HH__
 #ifndef __MULTIPAGELOADER_HH__
 #define __MULTIPAGELOADER_HH__
 #define __MULTIPAGELOADER_HH__
-#include "loadsettings.hh"
 #include <QFile>
 #include <QFile>
 #include <QObject>
 #include <QObject>
 #include <QUrl>
 #include <QUrl>
 #include <QWebPage>
 #include <QWebPage>
+#include <wkhtmltox/loadsettings.hh>
 
 
+#include <wkhtmltox/dllbegin.inc>
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 
 
-class MyQWebPage;
+class DLL_LOCAL MyQWebPage;
 
 
-class LoaderObject {
+class DLL_LOCAL LoaderObject {
 public:
 public:
 	QWebPage & page;
 	QWebPage & page;
 	bool skip;
 	bool skip;
@@ -38,8 +39,8 @@ public:
 	LoaderObject(QWebPage & page);
 	LoaderObject(QWebPage & page);
 };
 };
 
 
-class MultiPageLoaderPrivate;
-class MultiPageLoader: public QObject {
+class DLL_LOCAL MultiPageLoaderPrivate;
+class DLL_LOCAL MultiPageLoader: public QObject {
 	Q_OBJECT
 	Q_OBJECT
 public:
 public:
 	MultiPageLoader(settings::LoadGlobal & s);
 	MultiPageLoader(settings::LoadGlobal & s);
@@ -67,4 +68,5 @@ private:
 };
 };
 
 
 }
 }
+#include <wkhtmltox/dllend.inc>
 #endif //__MULTIPAGELOADER_HH__
 #endif //__MULTIPAGELOADER_HH__

+ 10 - 9
src/shared/multipageloader_p.hh → src/lib/multipageloader_p.hh

@@ -30,9 +30,11 @@
 #include <QNetworkCookieJar>
 #include <QNetworkCookieJar>
 #include <QNetworkReply>
 #include <QNetworkReply>
 #include <QWebFrame>
 #include <QWebFrame>
+
+#include "dllbegin.inc"
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 
 
-class MyNetworkAccessManager: public QNetworkAccessManager {
+class DLL_LOCAL MyNetworkAccessManager: public QNetworkAccessManager {
 	Q_OBJECT
 	Q_OBJECT
 private:
 private:
 	QSet<QString> allowed;
 	QSet<QString> allowed;
@@ -45,10 +47,10 @@ signals:
 	void warning(const QString & text);
 	void warning(const QString & text);
 };
 };
 
 
-class MultiPageLoaderPrivate;
-class ResourceObject;
+class DLL_LOCAL MultiPageLoaderPrivate;
+class DLL_LOCAL ResourceObject;
 
 
-class MyQWebPage: public QWebPage {
+class DLL_LOCAL MyQWebPage: public QWebPage {
 	Q_OBJECT ;
 	Q_OBJECT ;
 private:
 private:
 	ResourceObject & resource;
 	ResourceObject & resource;
@@ -62,7 +64,7 @@ public slots:
 	bool shouldInterruptJavaScript();
 	bool shouldInterruptJavaScript();
 };
 };
 
 
-class ResourceObject: public QObject {
+class DLL_LOCAL ResourceObject: public QObject {
 	Q_OBJECT
 	Q_OBJECT
 private:
 private:
 	MyNetworkAccessManager networkAccessManager;
 	MyNetworkAccessManager networkAccessManager;
@@ -92,8 +94,7 @@ public slots:
 	void amfinished(QNetworkReply * reply);
 	void amfinished(QNetworkReply * reply);
 };
 };
 
 
-
-class MyCookieJar: public QNetworkCookieJar {
+class DLL_LOCAL MyCookieJar: public QNetworkCookieJar {
 private:
 private:
 	QHash<QString, QList<QNetworkCookie> > extraCookies;
 	QHash<QString, QList<QNetworkCookie> > extraCookies;
 public:
 public:
@@ -103,8 +104,7 @@ public:
 	void saveToFile(const QString & path);
 	void saveToFile(const QString & path);
 };
 };
 
 
-
-class MultiPageLoaderPrivate: public QObject {
+class DLL_LOCAL MultiPageLoaderPrivate: public QObject {
 	Q_OBJECT
 	Q_OBJECT
 public:
 public:
 	MyCookieJar * cookieJar;
 	MyCookieJar * cookieJar;
@@ -133,4 +133,5 @@ public slots:
 };
 };
 
 
 }
 }
+#include "dllend.inc"
 #endif //__MULTIPAGELOADER_P_HH__
 #endif //__MULTIPAGELOADER_P_HH__

+ 6 - 6
src/pdf/outline.cc → src/lib/outline.cc

@@ -36,7 +36,7 @@ namespace wkhtmltopdf {
 */
 */
 
 
 OutlineItem::OutlineItem():
 OutlineItem::OutlineItem():
-	parent(NULL), page(-1) {}
+	parent(NULL), page(-1), display(true), forwardLinks(false), backLinks(false) {}
 
 
 /*!
 /*!
   \brief Recursivily delete the subtree
   \brief Recursivily delete the subtree
@@ -92,7 +92,7 @@ bool OutlineItem::differentFrom(const OutlineItem * other) const {
   \brief Class providing implemenation details of Outline
   \brief Class providing implemenation details of Outline
 */
 */
 
 
-OutlinePrivate::OutlinePrivate(const settings::Global & s):
+OutlinePrivate::OutlinePrivate(const settings::PdfGlobal & s):
 	settings(s), pageCount(0), anchorCounter(0) {
 	settings(s), pageCount(0), anchorCounter(0) {
 }
 }
 
 
@@ -170,7 +170,7 @@ void Outline::dump(QTextStream & stream, const QString & xsl) const {
   \brief Construct a new outline class
   \brief Construct a new outline class
   \param settings The settings to use
   \param settings The settings to use
 */
 */
-Outline::Outline(const settings::Global & settings): d(new OutlinePrivate(settings)) {}
+Outline::Outline(const settings::PdfGlobal & settings): d(new OutlinePrivate(settings)) {}
 Outline::~Outline() {delete d;}
 Outline::~Outline() {delete d;}
 
 
 
 
@@ -185,7 +185,7 @@ bool Outline::replaceWebPage(int document,
 							 const QString & name,
 							 const QString & name,
 							 QWebPrinter & wp,
 							 QWebPrinter & wp,
 							 QWebFrame * frame,
 							 QWebFrame * frame,
-							 const settings::Page & ps,
+							 const settings::PdfObject & ps,
 							 QVector<QPair<QWebElement, QString> > & local,
 							 QVector<QPair<QWebElement, QString> > & local,
 							 QHash<QString, QWebElement> & anchors) {
 							 QHash<QString, QWebElement> & anchors) {
 	QMap< QPair<int, QPair<qreal,qreal> >, QWebElement> headings;
 	QMap< QPair<int, QPair<qreal,qreal> >, QWebElement> headings;
@@ -251,7 +251,7 @@ bool Outline::replaceWebPage(int document,
   \param wp A webprinter for the page
   \param wp A webprinter for the page
   \param frame The frame containing the webpage
   \param frame The frame containing the webpage
 */
 */
-void Outline::addWebPage(const QString & name, QWebPrinter & wp, QWebFrame * frame, const settings::Page & ps,
+void Outline::addWebPage(const QString & name, QWebPrinter & wp, QWebFrame * frame, const settings::PdfObject & ps,
 						 QVector<QPair<QWebElement, QString> > & local,
 						 QVector<QPair<QWebElement, QString> > & local,
 						 QHash<QString, QWebElement> & anchors) {
 						 QHash<QString, QWebElement> & anchors) {
 	Q_UNUSED(name);
 	Q_UNUSED(name);
@@ -289,7 +289,7 @@ void OutlinePrivate::buildHFCache(OutlineItem * i, int level) {
   \param page The page to fill in for
   \param page The page to fill in for
   \param parms The structure to fill
   \param parms The structure to fill
  */
  */
-void Outline::fillHeaderFooterParms(int page, QHash<QString, QString> & parms, const settings::Page & ps) {
+void Outline::fillHeaderFooterParms(int page, QHash<QString, QString> & parms, const settings::PdfObject & ps) {
 	//Build hfcache
 	//Build hfcache
 	if (d->hfCache.size() == 0) {
 	if (d->hfCache.size() == 0) {
 		for (int i=0; i < 3; ++i) {
 		for (int i=0; i < 3; ++i) {

+ 11 - 10
src/pdf/outline.hh → src/lib/outline.hh

@@ -20,24 +20,25 @@
 
 
 #ifndef __OUTLINE_HH__
 #ifndef __OUTLINE_HH__
 #define __OUTLINE_HH__
 #define __OUTLINE_HH__
-#include <QWebFrame>
-#ifdef  __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
-#include "settings.hh"
+#include "pdfsettings.hh"
 #include <QWebElement>
 #include <QWebElement>
+#include <QWebFrame>
 
 
+#ifdef  __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
+#include "dllbegin.inc"
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 
 
-class OutlinePrivate;
+class DLL_LOCAL OutlinePrivate;
 
 
-class Outline {
+class DLL_LOCAL Outline {
 public:
 public:
-	Outline(const settings::Global & settings);
+	Outline(const settings::PdfGlobal & settings);
 	~Outline();
 	~Outline();
 	void addEmptyWebPage();
 	void addEmptyWebPage();
-	bool replaceWebPage(int d, const QString & name, QWebPrinter & wp, QWebFrame * f, const settings::Page & ps, QVector<QPair<QWebElement, QString> > & local, QHash<QString, QWebElement> & anchors);
-	void addWebPage(const QString & name, QWebPrinter & wp, QWebFrame * frame, const settings::Page & ps, QVector<QPair<QWebElement, QString> > & local, QHash<QString, QWebElement> & external);
+	bool replaceWebPage(int d, const QString & name, QWebPrinter & wp, QWebFrame * f, const settings::PdfObject & ps, QVector<QPair<QWebElement, QString> > & local, QHash<QString, QWebElement> & anchors);
+	void addWebPage(const QString & name, QWebPrinter & wp, QWebFrame * frame, const settings::PdfObject & ps, QVector<QPair<QWebElement, QString> > & local, QHash<QString, QWebElement> & external);
 
 
-	void fillHeaderFooterParms(int page, QHash<QString, QString> & parms, const settings::Page & ps);
+	void fillHeaderFooterParms(int page, QHash<QString, QString> & parms, const settings::PdfObject & ps);
 	void fillAnchors(int d, QHash<QString, QWebElement> & anchors);
 	void fillAnchors(int d, QHash<QString, QWebElement> & anchors);
 	int pageCount();
 	int pageCount();
 	void printOutline(QPrinter * printer);
 	void printOutline(QPrinter * printer);
@@ -49,7 +50,7 @@ private:
 	friend class TocPrinterPrivate;
 	friend class TocPrinterPrivate;
 };
 };
 
 
-
+#include "dllend.inc"
 }
 }
 #endif //__EXTENSIVE_WKHTMLTOPDF_QT_HACK__
 #endif //__EXTENSIVE_WKHTMLTOPDF_QT_HACK__
 #endif //__OUTLINE_HH__
 #endif //__OUTLINE_HH__

+ 6 - 7
src/pdf/outline_p.hh → src/lib/outline_p.hh

@@ -20,13 +20,12 @@
 
 
 #ifndef __OUTLINE_P_HH__
 #ifndef __OUTLINE_P_HH__
 #define __OUTLINE_P_HH__
 #define __OUTLINE_P_HH__
-#ifndef __OUTLINE_P_HH
-#define __OUTLINE_P_HH
 #include "outline.hh"
 #include "outline.hh"
 #ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
 #ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
+#include "dllbegin.inc"
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 
 
-class OutlineItem {
+class DLL_LOCAL OutlineItem {
 public:
 public:
 	QList<OutlineItem *> children;
 	QList<OutlineItem *> children;
 	OutlineItem * parent;
 	OutlineItem * parent;
@@ -48,9 +47,9 @@ public:
 	~OutlineItem();
 	~OutlineItem();
 };
 };
 
 
-class OutlinePrivate {
+class DLL_LOCAL OutlinePrivate {
 public:
 public:
-	const settings::Global & settings;
+	const settings::PdfGlobal & settings;
 	QList<OutlineItem *> documentOutlines;
 	QList<OutlineItem *> documentOutlines;
 	QList<int> documentPages;
 	QList<int> documentPages;
 	QList<int> prefixSum;
 	QList<int> prefixSum;
@@ -59,7 +58,7 @@ public:
 
 
 	QList< QList< OutlineItem *> > hfCache;
 	QList< QList< OutlineItem *> > hfCache;
 
 
-	OutlinePrivate(const settings::Global & settings);
+	OutlinePrivate(const settings::PdfGlobal & settings);
 	~OutlinePrivate();
 	~OutlinePrivate();
 	void fillChildAnchors(OutlineItem * item, QHash<QString, QWebElement> & anchors);
 	void fillChildAnchors(OutlineItem * item, QHash<QString, QWebElement> & anchors);
 	void outlineChildren(OutlineItem * item, QPrinter * printer, int level);
 	void outlineChildren(OutlineItem * item, QPrinter * printer, int level);
@@ -67,7 +66,7 @@ public:
 	void dumpChildren(QTextStream & stream, const QList<OutlineItem *> & items, int level) const;
 	void dumpChildren(QTextStream & stream, const QList<OutlineItem *> & items, int level) const;
 };
 };
 
 
+#include "dllend.inc"
 }
 }
 #endif //__EXTENSIVE_WKHTMLTOPDF_QT_HACK__
 #endif //__EXTENSIVE_WKHTMLTOPDF_QT_HACK__
-#endif //__OUTLINE_P_HH
 #endif //__OUTLINE_P_HH__
 #endif //__OUTLINE_P_HH__

+ 70 - 0
src/lib/pdf.h

@@ -0,0 +1,70 @@
+// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
+// vi:set ts=4 sts=4 sw=4 noet :
+//
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __PDF_H__
+#define __PDF_H__
+#include <wkhtmltox/dllbegin.inc>
+
+struct wkhtmltopdf_global_settings;
+typedef struct wkhtmltopdf_global_settings wkhtmltopdf_global_settings;
+
+struct wkhtmltopdf_object_settings;
+typedef struct wkhtmltopdf_object_settings wkhtmltopdf_object_settings;
+
+struct wkhtmltopdf_converter;
+typedef struct wkhtmltopdf_converter wkhtmltopdf_converter;
+
+
+typedef void (*wkhtmltopdf_str_callback)(wkhtmltopdf_converter * converter, const char * str);
+typedef void (*wkhtmltopdf_int_callback)(wkhtmltopdf_converter * converter, const int val);
+typedef void (*wkhtmltopdf_bool_callback)(wkhtmltopdf_converter * converter, const bool val);
+typedef void (*wkhtmltopdf_void_callback)(wkhtmltopdf_converter * converter);
+
+CAPI wkhtmltopdf_global_settings * wkhtmltopdf_create_global_settings();
+CAPI wkhtmltopdf_object_settings * wkhtmltopdf_create_object_settings();
+
+CAPI int wkhtmltopdf_set_global_option(wkhtmltopdf_global_settings * settings, const char * name, const char * value);
+CAPI int wkhtmltopdf_get_global_option(wkhtmltopdf_global_settings * settings, const char * name, char * value, int vs);
+CAPI int wkhtmltopdf_set_object_option(wkhtmltopdf_object_settings * settings, const char * name, const char * value);
+CAPI int wkhtmltopdf_get_object_option(wkhtmltopdf_object_settings * settings, const char * name, char * value, int vs);
+
+
+CAPI wkhtmltopdf_converter * wkhtmltopdf_create_converter(wkhtmltopdf_global_settings * settings);
+CAPI void wkhtmltopdf_destroy_converter(wkhtmltopdf_converter * converter);
+
+CAPI void wkhtmltopdf_set_warning_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_str_callback * cb);
+CAPI void wkhtmltopdf_set_error_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_str_callback * cb);
+CAPI void wkhtmltopdf_set_phase_changed_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_void_callback * cb);
+CAPI void wkhtmltopdf_set_progress_changed_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_int_callback * cb);
+CAPI void wkhtmltopdf_set_finished_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_bool_callback * cb);
+CAPI void wkhtmltopdf_begin_convertion(wkhtmltopdf_converter * converter);
+CAPI bool wkhtmltopdf_convert(wkhtmltopdf_converter * converter);
+CAPI void wkhtmltopdf_cancel(wkhtmltopdf_converter * converter);
+CAPI void wkhtmltopdf_add_resource(
+	wkhtmltopdf_converter * converter, wkhtmltopdf_object_settings * setting, const char * data=0);
+
+CAPI int wkhtmltopdf_current_phase(wkhtmltopdf_converter * converter);
+CAPI int wkhtmltopdf_phase_count(wkhtmltopdf_converter * converter);
+CAPI const char * wkhtmltopdf_phase_description(wkhtmltopdf_converter * converter, int phase);
+CAPI const char * wkhtmltopdf_progress_string(wkhtmltopdf_converter * converter);
+CAPI int wkhtmltopdf_http_error_code(wkhtmltopdf_converter * converter);
+
+#include <wkhtmltox/dllend.inc>
+#endif //__PDF_H__

+ 153 - 0
src/lib/pdf_c_bindings.cc

@@ -0,0 +1,153 @@
+// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
+// vi:set ts=4 sts=4 sw=4 noet :
+//
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "pdf_c_bindings_p.hh"
+
+#include "dllbegin.inc"
+using namespace wkhtmltopdf;
+
+void MyPdfConverter::warning(const QString & message) {
+	if (warning_cb) (*warning_cb)(reinterpret_cast<wkhtmltopdf_converter*>(this), message.toUtf8().constData());
+}
+
+void MyPdfConverter::error(const QString & message) {
+	if (error_cb) (*error_cb)(reinterpret_cast<wkhtmltopdf_converter*>(this), message.toUtf8().constData());
+}
+
+void MyPdfConverter::phaseChanged() {
+	if (phase_changed) (*phase_changed)(reinterpret_cast<wkhtmltopdf_converter*>(this));
+}
+
+void MyPdfConverter::progressChanged(int progress) {
+	if (progress_changed) (*progress_changed)(reinterpret_cast<wkhtmltopdf_converter*>(this), progress);
+}
+
+void MyPdfConverter::finished(bool ok) {
+	if (finished_cb) (*finished_cb)(reinterpret_cast<wkhtmltopdf_converter*>(this), ok);
+}
+
+MyPdfConverter::MyPdfConverter(settings::PdfGlobal * gs):
+	warning_cb(0), error_cb(0), phase_changed(0), progress_changed(0), finished_cb(0),
+	converter(*gs), globalSettings(gs) {}
+
+MyPdfConverter::~MyPdfConverter() {
+	delete globalSettings;
+	for (size_t i=0; i < objectSettings.size(); ++i)
+		delete objectSettings[i];
+	objectSettings.clear();
+}
+
+CAPI wkhtmltopdf_global_settings * wkhtmltopdf_create_global_settings() {
+	return reinterpret_cast<wkhtmltopdf_global_settings *>(new settings::PdfGlobal());
+}
+
+CAPI wkhtmltopdf_object_settings * wkhtmltopdf_create_object_settings() {
+	return reinterpret_cast<wkhtmltopdf_object_settings *>(new settings::PdfObject());
+}
+
+CAPI int wkhtmltopdf_set_global_option(wkhtmltopdf_global_settings * settings, const char * name, const char * value) {
+	return reinterpret_cast<settings::PdfGlobal *>(settings)->set(name, value);
+}
+
+CAPI int wkhtmltopdf_get_global_option(wkhtmltopdf_global_settings * settings, const char * name, char * value, int vs) {
+	QString res = reinterpret_cast<settings::PdfGlobal *>(settings)->get(name);
+	if (res.isNull()) return 0;
+	qstrncpy(value, res.toUtf8().constData(), vs);
+	return 1;
+}
+
+CAPI int wkhtmltopdf_set_object_option(wkhtmltopdf_object_settings * settings, const char * name, const char * value) {
+	return reinterpret_cast<settings::PdfObject *>(settings)->set(name, value);
+}
+
+CAPI int wkhtmltopdf_get_object_option(wkhtmltopdf_object_settings * settings, const char * name, char * value, int vs) {
+	QString res = reinterpret_cast<settings::PdfObject *>(settings)->get(name);
+	if (res.isNull()) return 0;
+	qstrncpy(value, res.toUtf8().constData(), vs);
+	return 1;
+}
+
+CAPI wkhtmltopdf_converter * wkhtmltopdf_create_converter(wkhtmltopdf_global_settings * settings) {
+	return reinterpret_cast<wkhtmltopdf_converter *>(
+		new MyPdfConverter(reinterpret_cast<settings::PdfGlobal *>(settings)));
+}
+
+CAPI void wkhtmltopdf_destroy_converter(wkhtmltopdf_converter * converter) {
+	delete reinterpret_cast<MyPdfConverter *>(converter);
+}
+
+CAPI void wkhtmltopdf_set_warning_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_str_callback * cb) {
+	reinterpret_cast<MyPdfConverter *>(converter)->warning_cb = cb;
+}
+
+CAPI void wkhtmltopdf_set_error_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_str_callback * cb) {
+	reinterpret_cast<MyPdfConverter *>(converter)->error_cb = cb;
+}
+
+CAPI void wkhtmltopdf_set_phase_changed_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_void_callback * cb) {
+	reinterpret_cast<MyPdfConverter *>(converter)->phase_changed = cb;
+}
+
+CAPI void wkhtmltopdf_set_progress_changed_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_int_callback * cb) {
+	reinterpret_cast<MyPdfConverter *>(converter)->progress_changed = cb;
+}
+
+CAPI void wkhtmltopdf_set_finished_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_bool_callback * cb) {
+	reinterpret_cast<MyPdfConverter *>(converter)->finished_cb = cb;
+}
+
+CAPI void wkhtmltopdf_begin_convertion(wkhtmltopdf_converter * converter) {
+	reinterpret_cast<MyPdfConverter *>(converter)->converter.beginConvertion();
+}
+
+CAPI bool wkhtmltopdf_convert(wkhtmltopdf_converter * converter) {
+	return reinterpret_cast<MyPdfConverter *>(converter)->converter.convert();
+}
+
+CAPI void wkhtmltopdf_cancel(wkhtmltopdf_converter * converter) {
+	reinterpret_cast<MyPdfConverter *>(converter)->converter.cancel();
+}
+
+CAPI void wkhtmltopdf_add_resource(
+	wkhtmltopdf_converter * converter, wkhtmltopdf_object_settings * settings, const char * data) {
+	reinterpret_cast<MyPdfConverter *>(converter)->converter.addResource(
+		*reinterpret_cast<settings::PdfObject *>(settings) );
+	reinterpret_cast<MyPdfConverter *>(converter)->objectSettings.push_back(reinterpret_cast<settings::PdfObject *>(settings));
+}
+
+CAPI int wkhtmltopdf_current_phase(wkhtmltopdf_converter * converter) {
+	return reinterpret_cast<MyPdfConverter *>(converter)->converter.currentPhase();
+}
+
+CAPI int wkhtmltopdf_phase_count(wkhtmltopdf_converter * converter) {
+	return reinterpret_cast<MyPdfConverter *>(converter)->converter.phaseCount();
+}
+
+CAPI const char * wkhtmltopdf_phase_description(wkhtmltopdf_converter * converter, int phase) {
+	return reinterpret_cast<MyPdfConverter *>(converter)->converter.phaseDescription(phase).toUtf8().constData();
+}
+
+CAPI const char * wkhtmltopdf_progress_string(wkhtmltopdf_converter * converter) {
+	return reinterpret_cast<MyPdfConverter *>(converter)->converter.progressString().toUtf8().constData();
+}
+
+CAPI int wkhtmltopdf_http_error_code(wkhtmltopdf_converter * converter) {
+	return reinterpret_cast<MyPdfConverter *>(converter)->converter.httpErrorCode();
+}

+ 57 - 0
src/lib/pdf_c_bindings_p.hh

@@ -0,0 +1,57 @@
+// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
+// vi:set ts=4 sts=4 sw=4 noet :
+//
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __PDF_C_BINDINGS_P_HH__
+#define __PDF_C_BINDINGS_P_HH__
+#include "pdf.h"
+#include "pdfconverter.hh"
+#include <QObject>
+#include <vector>
+
+#include "dllbegin.inc"
+
+class DLL_LOCAL MyPdfConverter: public QObject {
+    Q_OBJECT
+public:
+	wkhtmltopdf_str_callback * warning_cb;
+	wkhtmltopdf_str_callback * error_cb;
+	wkhtmltopdf_void_callback * phase_changed;
+	wkhtmltopdf_int_callback * progress_changed;
+	wkhtmltopdf_bool_callback * finished_cb;
+
+	wkhtmltopdf::PdfConverter converter;
+
+	wkhtmltopdf::settings::PdfGlobal * globalSettings;
+	std::vector<wkhtmltopdf::settings::PdfObject *> objectSettings;
+
+	MyPdfConverter(wkhtmltopdf::settings::PdfGlobal * gs);
+	~MyPdfConverter();
+public slots:
+    void warning(const QString & message);
+    void error(const QString & message);
+    void phaseChanged();
+    void progressChanged(int progress);
+    void finished(bool ok);
+private:
+    MyPdfConverter(const MyPdfConverter&);
+};
+
+#include "dllend.inc"
+#endif //__PDF_C_BINDINGS_P_HH__

+ 20 - 17
src/pdf/pdfconverter.cc → src/lib/pdfconverter.cc

@@ -37,13 +37,13 @@
 #include <io.h>
 #include <io.h>
 #endif
 #endif
 
 
+#include "dllbegin.inc"
 using namespace wkhtmltopdf;
 using namespace wkhtmltopdf;
 using namespace wkhtmltopdf::settings;
 using namespace wkhtmltopdf::settings;
 
 
-QMap<QWebPage *, PageObject *> PageObject::webPageToObject;
+DLL_LOCAL QMap<QWebPage *, PageObject *> PageObject::webPageToObject;
 
 
-
-struct StreamDumper {
+struct DLL_LOCAL StreamDumper {
 	QFile out;
 	QFile out;
 	QTextStream stream;
 	QTextStream stream;
 
 
@@ -63,12 +63,12 @@ struct StreamDumper {
   \brief Defines the PdfConverterPrivate class
   \brief Defines the PdfConverterPrivate class
 */
 */
 
 
-bool looksLikeHtmlAndNotAUrl(QString str) {
+bool DLL_LOCAL looksLikeHtmlAndNotAUrl(QString str) {
 	QString s = str.split("?")[0];
 	QString s = str.split("?")[0];
 	return s.count('<') > 0 || s.count('<') > 0;
 	return s.count('<') > 0 || s.count('<') > 0;
 }
 }
 
 
-PdfConverterPrivate::PdfConverterPrivate(Global & s, PdfConverter & o) :
+PdfConverterPrivate::PdfConverterPrivate(PdfGlobal & s, PdfConverter & o) :
 	settings(s), pageLoader(s.load),
 	settings(s), pageLoader(s.load),
 	out(o), printer(0), painter(0)
 	out(o), printer(0), painter(0)
 #ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
 #ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
@@ -134,7 +134,7 @@ void PdfConverterPrivate::beginConvert() {
 
 
 	for (QList<PageObject>::iterator i=objects.begin(); i != objects.end(); ++i) {
 	for (QList<PageObject>::iterator i=objects.begin(); i != objects.end(); ++i) {
 		PageObject & o=*i;
 		PageObject & o=*i;
-		settings::Page & s = o.settings;
+		settings::PdfObject & s = o.settings;
 
 
 		if (!s.header.htmlUrl.isEmpty() && looksLikeHtmlAndNotAUrl(s.header.htmlUrl)) {
 		if (!s.header.htmlUrl.isEmpty() && looksLikeHtmlAndNotAUrl(s.header.htmlUrl)) {
 			emit out.error("--header-html should be a URL and not a string containing HTML code.");
 			emit out.error("--header-html should be a URL and not a string containing HTML code.");
@@ -300,7 +300,7 @@ void PdfConverterPrivate::loadHeaders() {
 		PageObject & obj = objects[d];
 		PageObject & obj = objects[d];
 		if (!obj.loaderObject || obj.loaderObject->skip) continue;
 		if (!obj.loaderObject || obj.loaderObject->skip) continue;
 
 
-		settings::Page & ps = obj.settings;
+		settings::PdfObject & ps = obj.settings;
 		for (int op=0; op < obj.pageCount; ++op) {
 		for (int op=0; op < obj.pageCount; ++op) {
 			if (!ps.header.htmlUrl.isEmpty() || !ps.footer.htmlUrl.isEmpty()) {
 			if (!ps.header.htmlUrl.isEmpty() || !ps.footer.htmlUrl.isEmpty()) {
 				QHash<QString, QString> parms;
 				QHash<QString, QString> parms;
@@ -322,7 +322,6 @@ void PdfConverterPrivate::loadHeaders() {
 #endif
 #endif
 }
 }
 
 
-
 void PdfConverterPrivate::loadTocs() {
 void PdfConverterPrivate::loadTocs() {
 #ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
 #ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
 	std::swap(tocLoaderOld, tocLoader);
 	std::swap(tocLoaderOld, tocLoader);
@@ -331,7 +330,7 @@ void PdfConverterPrivate::loadTocs() {
 	bool toc=false;
 	bool toc=false;
 	for (int d=0; d < objects.size(); ++d) {
 	for (int d=0; d < objects.size(); ++d) {
 		PageObject & obj = objects[d];
 		PageObject & obj = objects[d];
-		settings::Page & ps = obj.settings;
+		settings::PdfObject & ps = obj.settings;
 		if (!ps.isTableOfContent) continue;
 		if (!ps.isTableOfContent) continue;
 		obj.clear();
 		obj.clear();
 
 
@@ -420,7 +419,7 @@ void PdfConverterPrivate::beginPage(int actualPage) {
 
 
 void PdfConverterPrivate::endPage(PageObject & object, bool hasHeaderFooter, int objectPage, int pageNumber) {
 void PdfConverterPrivate::endPage(PageObject & object, bool hasHeaderFooter, int objectPage, int pageNumber) {
 	typedef QPair<QWebElement, QString> p_t;
 	typedef QPair<QWebElement, QString> p_t;
-	settings::Page & s = object.settings;
+	settings::PdfObject & s = object.settings;
 	if (hasHeaderFooter) {
 	if (hasHeaderFooter) {
 		QHash<QString, QString> parms;
 		QHash<QString, QString> parms;
 		fillParms(parms, pageNumber, object);
 		fillParms(parms, pageNumber, object);
@@ -513,7 +512,9 @@ void PdfConverterPrivate::endPage(PageObject & object, bool hasHeaderFooter, int
 #endif
 #endif
 
 
 void PdfConverterPrivate::tocLoaded(bool ok) {
 void PdfConverterPrivate::tocLoaded(bool ok) {
-	if (errorCode == 0) errorCode = pageLoader.httpErrorCode();
+#ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
+	if (errorCode == 0) errorCode = tocLoader->httpErrorCode();
+#endif
 	if (!ok) {
 	if (!ok) {
 		fail();
 		fail();
 		return;
 		return;
@@ -569,7 +570,9 @@ void PdfConverterPrivate::tocLoaded(bool ok) {
 }
 }
 
 
 void PdfConverterPrivate::headersLoaded(bool ok) {
 void PdfConverterPrivate::headersLoaded(bool ok) {
-	if (errorCode == 0) errorCode = pageLoader.httpErrorCode();
+#ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
+	if (errorCode == 0) errorCode = hfLoader.httpErrorCode();
+#endif
 	if (!ok) {
 	if (!ok) {
 		fail();
 		fail();
 		return;
 		return;
@@ -602,7 +605,7 @@ void PdfConverterPrivate::printDocument() {
 		for (int d=0; d < objects.size(); ++d) {
 		for (int d=0; d < objects.size(); ++d) {
 			PageObject & obj = objects[d];
 			PageObject & obj = objects[d];
 			if (!obj.loaderObject || obj.loaderObject->skip) continue;
 			if (!obj.loaderObject || obj.loaderObject->skip) continue;
-			const settings::Page & ps = obj.settings;
+			const settings::PdfObject & ps = obj.settings;
 			bool hasHeaderFooter = ps.header.line || ps.footer.line ||
 			bool hasHeaderFooter = ps.header.line || ps.footer.line ||
 				!ps.header.left.isEmpty() || !ps.footer.left.isEmpty() ||
 				!ps.header.left.isEmpty() || !ps.footer.left.isEmpty() ||
 				!ps.header.center.isEmpty() || !ps.footer.center.isEmpty() ||
 				!ps.header.center.isEmpty() || !ps.footer.center.isEmpty() ||
@@ -735,7 +738,7 @@ void PdfConverterPrivate::printDocument() {
 }
 }
 
 
 #ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
 #ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
-QWebPage * PdfConverterPrivate::loadHeaderFooter(QString url, const QHash<QString, QString> & parms, const settings::Page & ps) {
+QWebPage * PdfConverterPrivate::loadHeaderFooter(QString url, const QHash<QString, QString> & parms, const settings::PdfObject & ps) {
 	QUrl u = MultiPageLoader::guessUrlFromString(url);
 	QUrl u = MultiPageLoader::guessUrlFromString(url);
 	for (QHash<QString, QString>::const_iterator i=parms.begin(); i != parms.end(); ++i)
 	for (QHash<QString, QString>::const_iterator i=parms.begin(); i != parms.end(); ++i)
 		u.addQueryItem(i.key(), i.value());
 		u.addQueryItem(i.key(), i.value());
@@ -790,7 +793,7 @@ Converter & PdfConverterPrivate::outer() {
   \brief Create a page converter object based on the supplied settings
   \brief Create a page converter object based on the supplied settings
   \param settings Settings for the conversion
   \param settings Settings for the conversion
 */
 */
-PdfConverter::PdfConverter(settings::Global & settings):
+PdfConverter::PdfConverter(settings::PdfGlobal & settings):
 	d(new PdfConverterPrivate(settings, *this)) {
 	d(new PdfConverterPrivate(settings, *this)) {
 }
 }
 
 
@@ -805,7 +808,7 @@ PdfConverter::~PdfConverter() {
   \brief add a resource we want to convert
   \brief add a resource we want to convert
   \param url The url of the object we want to convert
   \param url The url of the object we want to convert
 */
 */
-void PdfConverter::addResource(const settings::Page & page) {
+void PdfConverter::addResource(const settings::PdfObject & page) {
 	d->objects.push_back( PageObject(page) );
 	d->objects.push_back( PageObject(page) );
 }
 }
 
 
@@ -813,7 +816,7 @@ void PdfConverter::addResource(const settings::Page & page) {
 /*!
 /*!
   \brief Returns the settings object associated with the page converter
   \brief Returns the settings object associated with the page converter
 */
 */
-const settings::Global & PdfConverter::globalSettings() const {
+const settings::PdfGlobal & PdfConverter::globalSettings() const {
 	return d->settings;
 	return d->settings;
 }
 }
 
 

+ 10 - 8
src/pdf/pdfconverter.hh → src/lib/pdfconverter.hh

@@ -20,23 +20,24 @@
 
 
 #ifndef __PDFCONVERTER_HH__
 #ifndef __PDFCONVERTER_HH__
 #define __PDFCONVERTER_HH__
 #define __PDFCONVERTER_HH__
-#include "converter.hh"
-#include "settings.hh"
+#include <wkhtmltox/converter.hh>
+#include <wkhtmltox/pdfsettings.hh>
 
 
+#include <wkhtmltox/dllbegin.inc>
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 
 
-void dumpDefaultTOCStyleSheet(QTextStream & stream, settings::TableOfContent & s);
+DLL_PUBLIC void dumpDefaultTOCStyleSheet(QTextStream & stream, settings::TableOfContent & s);
 
 
-class PdfConverterPrivate;
+class DLL_LOCAL PdfConverterPrivate;
 
 
-class PdfConverter: public Converter {
+class DLL_PUBLIC PdfConverter: public Converter {
 	Q_OBJECT
 	Q_OBJECT
 public:
 public:
-	PdfConverter(settings::Global & globalSettings);
+	PdfConverter(settings::PdfGlobal & globalSettings);
 	~PdfConverter();
 	~PdfConverter();
 	int pageCount();
 	int pageCount();
-	void addResource(const settings::Page & pageSettings);
-	const settings::Global & globalSettings() const;
+	void addResource(const settings::PdfObject & pageSettings);
+	const settings::PdfGlobal & globalSettings() const;
 private:
 private:
 	PdfConverterPrivate * d;
 	PdfConverterPrivate * d;
 	virtual ConverterPrivate & priv();
 	virtual ConverterPrivate & priv();
@@ -46,4 +47,5 @@ signals:
 };
 };
 
 
 }
 }
+#include <wkhtmltox/dllend.inc>
 #endif //__PDFCONVERTER_HH__
 #endif //__PDFCONVERTER_HH__

+ 10 - 8
src/pdf/pdfconverter_p.hh → src/lib/pdfconverter_p.hh

@@ -24,7 +24,7 @@
 #include "multipageloader.hh"
 #include "multipageloader.hh"
 #include "outline.hh"
 #include "outline.hh"
 #include "pdfconverter.hh"
 #include "pdfconverter.hh"
-#include "settings.hh"
+#include "pdfsettings.hh"
 #include "tempfile.hh"
 #include "tempfile.hh"
 #include "tocprinter.hh"
 #include "tocprinter.hh"
 #include <QAtomicInt>
 #include <QAtomicInt>
@@ -40,13 +40,14 @@
 #include <QWebElement>
 #include <QWebElement>
 #endif
 #endif
 
 
+#include "dllbegin.inc"
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 
 
-class PageObject {
+class DLL_LOCAL PageObject {
 public:
 public:
 	static QMap<QWebPage *, PageObject *> webPageToObject;
 	static QMap<QWebPage *, PageObject *> webPageToObject;
 
 
-	settings::Page settings;
+	settings::PdfObject settings;
 	LoaderObject * loaderObject;
 	LoaderObject * loaderObject;
 	QWebPage * page;
 	QWebPage * page;
 
 
@@ -77,7 +78,7 @@ public:
 		tocFile.remove();
 		tocFile.remove();
 	}
 	}
 
 
-	PageObject(const settings::Page & set): settings(set), loaderObject(0), page(0) {};
+	PageObject(const settings::PdfObject & set): settings(set), loaderObject(0), page(0) {};
 
 
 	~PageObject() {
 	~PageObject() {
 		clear();
 		clear();
@@ -85,13 +86,13 @@ public:
 
 
 };
 };
 
 
-class PdfConverterPrivate: public ConverterPrivate {
+class DLL_LOCAL PdfConverterPrivate: public ConverterPrivate {
 	Q_OBJECT
 	Q_OBJECT
 public:
 public:
-	PdfConverterPrivate(settings::Global & s, PdfConverter & o);
+	PdfConverterPrivate(settings::PdfGlobal & s, PdfConverter & o);
 	~PdfConverterPrivate();
 	~PdfConverterPrivate();
 
 
-	settings::Global & settings;
+	settings::PdfGlobal & settings;
 
 
 	MultiPageLoader pageLoader;
 	MultiPageLoader pageLoader;
 
 
@@ -129,7 +130,7 @@ private:
 	void endPage(PageObject & object, bool hasHeaderFooter, int objectPage,  int pageNumber);
 	void endPage(PageObject & object, bool hasHeaderFooter, int objectPage,  int pageNumber);
 	void fillParms(QHash<QString, QString> & parms, int page, const PageObject & object);
 	void fillParms(QHash<QString, QString> & parms, int page, const PageObject & object);
 	QString hfreplace(const QString & q, const QHash<QString, QString> & parms);
 	QString hfreplace(const QString & q, const QHash<QString, QString> & parms);
-	QWebPage * loadHeaderFooter(QString url, const QHash<QString, QString> & parms, const settings::Page & ps);
+	QWebPage * loadHeaderFooter(QString url, const QHash<QString, QString> & parms, const settings::PdfObject & ps);
 #endif
 #endif
 
 
 	void loadTocs();
 	void loadTocs();
@@ -149,4 +150,5 @@ public slots:
 };
 };
 
 
 }
 }
+#include "dllend.inc"
 #endif //__PDFCONVERTER_P_HH__
 #endif //__PDFCONVERTER_P_HH__

+ 194 - 4
src/pdf/settings.cc → src/lib/pdfsettings.cc

@@ -18,17 +18,153 @@
 // You should have received a copy of the GNU General Public License
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
+#include "pdfsettings.hh"
+#include "reflect.hh"
 #include <QMap>
 #include <QMap>
-#include <settings.hh>
 #include <stdexcept>
 #include <stdexcept>
+
+#include "dllbegin.inc"
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 namespace settings {
 namespace settings {
 
 
+template<>
+struct DLL_LOCAL ReflectImpl<UnitReal>: public ReflectSimple {
+	UnitReal & ur;
+	ReflectImpl(UnitReal & _): ur(_) {}
+	QString get() {bool d; return unitRealToStr(ur, &d);}
+	void set(const QString & value, bool * ok) {ur = strToUnitReal(value.toUtf8().constData(), ok);}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<QPrinter::PageSize>: public ReflectSimple {
+	QPrinter::PageSize & ps;
+	ReflectImpl(QPrinter::PageSize & _): ps(_) {}
+	QString get() {return pageSizeToStr(ps);}
+	void set(const QString & value, bool * ok) {ps = strToPageSize(value.toUtf8().constData(), ok);}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<QPrinter::Orientation>: public ReflectSimple {
+	QPrinter::Orientation & o;
+	ReflectImpl(QPrinter::Orientation & _): o(_) {}
+	QString get() {return orientationToStr(o);}
+	void set(const QString & value, bool * ok) {o = strToOrientation(value.toUtf8().constData(), ok);}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<QPrinter::PrinterMode>: public ReflectSimple {
+	QPrinter::PrinterMode & m;
+	ReflectImpl(QPrinter::PrinterMode & _): m(_) {}
+	QString get() {return printerModeToStr(m);}
+	void set(const QString & value, bool * ok) {m = strToPrinterMode(value.toUtf8().constData(), ok);}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<QPrinter::ColorMode>: public ReflectSimple {
+	QPrinter::ColorMode & m;
+	ReflectImpl(QPrinter::ColorMode & _): m(_) {}
+	QString get() {return colorModeToStr(m);}
+	void set(const QString & value, bool * ok) {m = strToColorMode(value.toUtf8().constData(), ok);}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<Margin>: public ReflectClass {
+	ReflectImpl(Margin & c) {
+		WKHTMLTOPDF_REFLECT(top);
+		WKHTMLTOPDF_REFLECT(right);
+		WKHTMLTOPDF_REFLECT(bottom);
+		WKHTMLTOPDF_REFLECT(left);
+	}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<Size>: public ReflectClass {
+	ReflectImpl(Size & c) {
+		WKHTMLTOPDF_REFLECT(pageSize);
+		WKHTMLTOPDF_REFLECT(height);
+		WKHTMLTOPDF_REFLECT(width);
+	}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<TableOfContent>: public ReflectClass {
+	ReflectImpl(TableOfContent & c) {
+		WKHTMLTOPDF_REFLECT(useDottedLines);
+		WKHTMLTOPDF_REFLECT(captionText);
+		WKHTMLTOPDF_REFLECT(forwardLinks);
+		WKHTMLTOPDF_REFLECT(backLinks);
+		WKHTMLTOPDF_REFLECT(indentation);
+		WKHTMLTOPDF_REFLECT(fontScale);
+	}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<PdfGlobal>: public ReflectClass {
+	ReflectImpl(PdfGlobal & c) {
+		WKHTMLTOPDF_REFLECT(size);
+		WKHTMLTOPDF_REFLECT(quiet);
+		WKHTMLTOPDF_REFLECT(useGraphics);
+		WKHTMLTOPDF_REFLECT(orientation);
+		WKHTMLTOPDF_REFLECT(colorMode);
+		WKHTMLTOPDF_REFLECT(resolution);
+		WKHTMLTOPDF_REFLECT(dpi);
+		WKHTMLTOPDF_REFLECT(pageOffset);
+		WKHTMLTOPDF_REFLECT(copies);
+		WKHTMLTOPDF_REFLECT(collate);
+		WKHTMLTOPDF_REFLECT(outline);
+		WKHTMLTOPDF_REFLECT(dumpOutline);
+		WKHTMLTOPDF_REFLECT(out);
+		WKHTMLTOPDF_REFLECT(documentTitle);
+		WKHTMLTOPDF_REFLECT(useCompression);
+		WKHTMLTOPDF_REFLECT(margin);
+		WKHTMLTOPDF_REFLECT(outputFormat);
+		WKHTMLTOPDF_REFLECT(imageDPI);
+		WKHTMLTOPDF_REFLECT(imageQuality);
+		WKHTMLTOPDF_REFLECT(load);
+	}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<HeaderFooter>: public ReflectClass {
+	ReflectImpl(HeaderFooter & c) {
+		WKHTMLTOPDF_REFLECT(fontSize);
+		WKHTMLTOPDF_REFLECT(fontName);
+		WKHTMLTOPDF_REFLECT(left);
+		WKHTMLTOPDF_REFLECT(right);
+		WKHTMLTOPDF_REFLECT(center);
+		WKHTMLTOPDF_REFLECT(line);
+		WKHTMLTOPDF_REFLECT(htmlUrl);
+		WKHTMLTOPDF_REFLECT(spacing);
+	}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<PdfObject>: public ReflectClass {
+	ReflectImpl(PdfObject & c) {
+		WKHTMLTOPDF_REFLECT(toc);
+		WKHTMLTOPDF_REFLECT(page);
+		WKHTMLTOPDF_REFLECT(header);
+		WKHTMLTOPDF_REFLECT(footer);
+		WKHTMLTOPDF_REFLECT(useExternalLinks);
+		WKHTMLTOPDF_REFLECT(useLocalLinks);
+		WKHTMLTOPDF_REFLECT(replacements);
+		WKHTMLTOPDF_REFLECT(produceForms);
+		WKHTMLTOPDF_REFLECT(load);
+		WKHTMLTOPDF_REFLECT(web);
+		WKHTMLTOPDF_REFLECT(includeInOutline);
+		WKHTMLTOPDF_REFLECT(pagesCount);
+		WKHTMLTOPDF_REFLECT(isTableOfContent);
+		WKHTMLTOPDF_REFLECT(tocXsl);
+	}
+};
+
+
+
 /*!
 /*!
   \file settings.hh
   \file settings.hh
   \brief Defines the Settings class
   \brief Defines the Settings class
 */
 */
-QMap<QString, QPrinter::PageSize> pageSizeMap() {
+DLL_LOCAL QMap<QString, QPrinter::PageSize> pageSizeMap() {
 	QMap<QString, QPrinter::PageSize> res;
 	QMap<QString, QPrinter::PageSize> res;
 	res["A0"] = QPrinter::A0;
 	res["A0"] = QPrinter::A0;
 	res["A1"] = QPrinter::A1;
 	res["A1"] = QPrinter::A1;
@@ -169,6 +305,39 @@ QString unitRealToStr(const UnitReal & ur, bool * ok) {
 	return QString("%1%2").arg(ur.first).arg(c);
 	return QString("%1%2").arg(ur.first).arg(c);
 }
 }
 
 
+QPrinter::PrinterMode strToPrinterMode(const char * s, bool * ok) {
+	if (ok) *ok=true;
+	if (strcmp(s,"screen"))	return QPrinter::ScreenResolution;
+	if (strcmp(s,"printer")) return QPrinter::PrinterResolution;
+	if (strcmp(s,"high")) return QPrinter::HighResolution;
+	*ok=false;
+	return QPrinter::HighResolution;
+}
+
+QString printerModeToStr(QPrinter::PrinterMode o) {
+	switch (o) {
+	case QPrinter::ScreenResolution: return "screen";
+	case QPrinter::PrinterResolution: return "printer";
+	case QPrinter::HighResolution: return "high";
+	}
+	return QString();
+}
+
+QPrinter::ColorMode strToColorMode(const char * s, bool * ok) {
+	if (ok) *ok=true;
+	if (strcmp(s,"color"))	return QPrinter::Color;
+	if (strcmp(s,"grayscale")) return QPrinter::GrayScale;
+	*ok=false;
+	return QPrinter::Color;
+}
+
+QString colorModeToStr(QPrinter::ColorMode o) {
+	switch (o) {
+	case QPrinter::Color: return "color";
+	case QPrinter::GrayScale: return "glayscale";
+	}
+	return QString();
+}
 
 
 Size::Size():
 Size::Size():
 	pageSize(QPrinter::A4),
 	pageSize(QPrinter::A4),
@@ -191,7 +360,7 @@ Margin::Margin():
 	bottom(UnitReal(10,QPrinter::Millimeter)),
 	bottom(UnitReal(10,QPrinter::Millimeter)),
 	left(UnitReal(10,QPrinter::Millimeter)) {}
 	left(UnitReal(10,QPrinter::Millimeter)) {}
 
 
-Global::Global():
+PdfGlobal::PdfGlobal():
 	quiet(false),
 	quiet(false),
 	useGraphics(false),
 	useGraphics(false),
 	orientation(QPrinter::Portrait),
 	orientation(QPrinter::Portrait),
@@ -218,7 +387,7 @@ TableOfContent::TableOfContent():
 	indentation("1em"),
 	indentation("1em"),
 	fontScale(0.8) {}
 	fontScale(0.8) {}
 
 
-Page::Page():
+PdfObject::PdfObject():
 	useExternalLinks(true),
 	useExternalLinks(true),
 	useLocalLinks(true),
 	useLocalLinks(true),
 	produceForms(false),
 	produceForms(false),
@@ -226,5 +395,26 @@ Page::Page():
 	pagesCount(true),
 	pagesCount(true),
 	isTableOfContent(false),
 	isTableOfContent(false),
 	tocXsl("") {};
 	tocXsl("") {};
+
+QString PdfGlobal::get(const char * name) {
+	ReflectImpl<PdfGlobal> impl(*this);
+	return impl.get(name);
+}
+
+bool PdfGlobal::set(const char * name, const QString & value) {
+	ReflectImpl<PdfGlobal> impl(*this);
+	return impl.set(name, value);
+}
+
+QString PdfObject::get(const char * name) {
+	ReflectImpl<PdfObject> impl(*this);
+	return impl.get(name);
+}
+
+bool PdfObject::set(const char * name, const QString & value) {
+	ReflectImpl<PdfObject> impl(*this);
+	return impl.set(name, value);
+}
+
 }
 }
 }
 }

+ 225 - 0
src/lib/pdfsettings.hh

@@ -0,0 +1,225 @@
+// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
+// vi:set ts=4 sts=4 sw=4 noet :
+//
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __PDFSETTINGS_HH__
+#define __PDFSETTINGS_HH__
+#include <QNetworkProxy>
+#include <QPrinter>
+#include <QString>
+#include <wkhtmltox/loadsettings.hh>
+#include <wkhtmltox/websettings.hh>
+
+#include <wkhtmltox/dllbegin.inc>
+namespace wkhtmltopdf {
+namespace settings {
+
+typedef QPair<qreal, QPrinter::Unit> UnitReal;
+
+/*! \brief Settings consdering margins */
+struct DLL_PUBLIC Margin {
+	Margin();
+	//!Margin applied to the top of the page
+	UnitReal top;
+	//!Margin applied to the right of the page
+	UnitReal right;
+	//!Margin applied to the bottom of the page
+	UnitReal bottom;
+	//!Margin applied to the leftp of the page
+	UnitReal left;
+};
+
+/*! \brief Settings considering page size */
+struct DLL_PUBLIC Size {
+	Size();
+	//! What size paper should we use
+	QPrinter::PageSize pageSize;
+	//!Height of the page
+	UnitReal height;
+	//!Width of the page
+	UnitReal width;
+};
+
+/*! \brief Settings considdirng the table of content */
+struct DLL_PUBLIC TableOfContent {
+	TableOfContent();
+	//! Should we print dots between the name and the page number?
+	bool useDottedLines;
+	//! Name af the TOC
+	QString captionText;
+	//! Link from TOC to section headers
+	bool forwardLinks;
+	//! Link from section headers to TOC
+	bool backLinks;
+	//! How fare should we indent on every level
+	QString indentation;
+	//! Factor we should scale the font with on every level
+	float fontScale;
+};
+
+/*! \brief Class holding all user setting.
+    This class holds all the user settings, settings can be filled in by hand,
+    or with other methods.
+    \sa CommandLineParser::parse()
+*/
+struct DLL_PUBLIC PdfGlobal {
+	PdfGlobal();
+
+	//! Size related settings
+	Size size;
+
+	//! Be less verbose
+	bool quiet;
+
+	//! Should we use the graphics system
+	bool useGraphics;
+
+	//! Should we orientate in landscape or portrate
+	QPrinter::Orientation orientation;
+
+	//! Color or grayscale
+	QPrinter::ColorMode colorMode;
+
+	//! What overall resolution should we use
+	QPrinter::PrinterMode resolution;
+
+	//! What dpi should be used when printing
+	int dpi;
+
+	//! When pagenumbers are printed, apply this offset to them all
+	int pageOffset;
+
+	//! How many copies do we wan to print
+	int copies;
+
+	//! Should be print a whole copy before beginnig the next
+	bool collate;
+
+	//! Should we generate an outline and put it into the pdf file
+	bool outline;
+
+	//! Maximal depth of the generated outline
+	int outlineDepth;
+
+	//! dump outline to this filename
+	QString dumpOutline;
+
+	//! The file where in to store the output
+	QString out;
+
+	QString documentTitle;
+
+	bool useCompression;
+
+	//! Margin related settings
+	Margin margin;
+
+	//! Specify the output format we should use
+	QString outputFormat;
+
+	int imageDPI;
+	int imageQuality;
+
+	LoadGlobal load;
+
+	QString get(const char * name);
+	bool set(const char * name, const QString & value);
+};
+
+/*! \brief Settings considering headers and footers */
+struct DLL_PUBLIC HeaderFooter {
+	HeaderFooter();
+	//! Size of the font used to render the text
+	int fontSize;
+	//! Name of font used to render text
+	QString fontName;
+	//! Text to render at the left
+	QString left;
+	//! Text to render at the right
+	QString right;
+	//! Text to render at the center
+	QString center;
+	//! Should a line seperate the header/footer and the document
+	bool line;
+	//! Url of the document the html document that should be used as a header/footer
+	QString htmlUrl;
+	//! Spacing
+	float spacing;
+};
+
+struct DLL_PUBLIC PdfObject {
+	PdfObject();
+	//! Settings regarding the TOC
+	TableOfContent toc;
+
+	QString page;
+
+	//! Header related settings
+	HeaderFooter header;
+
+	//! Header related settings
+	HeaderFooter footer;
+
+	//! Should external links be links in the PDF
+	bool useExternalLinks;
+
+	//! Should internal links be links in the PDF
+	bool useLocalLinks;
+
+	//! Replacements
+	QList< QPair<QString, QString> > replacements;
+
+	//! Convert forms on the pages into PDF forms
+	bool produceForms;
+
+	LoadPage load;
+
+	Web web;
+
+	bool includeInOutline;
+
+	bool pagesCount;
+
+	bool isTableOfContent;
+
+	QString tocXsl;
+
+	QString get(const char * name);
+	bool set(const char * name, const QString & value);
+};
+
+DLL_PUBLIC QPrinter::PageSize strToPageSize(const char * s, bool * ok=0);
+DLL_PUBLIC QString pageSizeToStr(QPrinter::PageSize ps);
+
+DLL_PUBLIC UnitReal strToUnitReal(const char * s, bool * ok=0);
+DLL_PUBLIC QString unitRealToStr(const UnitReal & ur, bool * ok);
+
+DLL_PUBLIC QPrinter::Orientation strToOrientation(const char * s, bool * ok=0);
+DLL_PUBLIC QString orientationToStr(QPrinter::Orientation o);
+
+DLL_PUBLIC QPrinter::PrinterMode strToPrinterMode(const char * s, bool * ok=0);
+DLL_PUBLIC QString printerModeToStr(QPrinter::PrinterMode o);
+
+DLL_PUBLIC QPrinter::ColorMode strToColorMode(const char * s, bool * ok=0);
+DLL_PUBLIC QString colorModeToStr(QPrinter::ColorMode o);
+
+}
+}
+#include <wkhtmltox/dllend.inc>
+#endif //__PDFSETTINGS_HH__

+ 82 - 0
src/lib/reflect.cc

@@ -0,0 +1,82 @@
+// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
+// vi:set ts=4 sts=4 sw=4 noet :
+//
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "reflect.hh"
+
+namespace wkhtmltopdf {
+namespace settings {
+
+bool ReflectSimple::set(const char * name, const QString & value) {
+	bool ok=false;
+	if (name[0]=='\0') set(value, &ok);
+	return ok;
+}
+
+QString ReflectClass::get(const char * name) {
+	int i=0;
+	while (name[i] !=0 && name[i] != '.' && name[i] != '[') ++i;
+	if (!elms.contains(QString::fromAscii(name, i))) return QString();
+	return elms[QString::fromAscii(name,i)]->get(name + (name[i] == '.'?i+1:i));
+}
+
+bool ReflectClass::set(const char * name, const QString & value) {
+	int i=0;
+	while (name[i] !=0 && name[i] != '.' && name[i] != '[') ++i;
+	if (!elms.contains(QString::fromAscii(name, i))) return false;
+	return elms[QString::fromAscii(name,i)]->set(name + (name[i] == '.'?i+1:i), value);
+}
+
+
+ReflectClass::~ReflectClass() {
+	for (QMap<QString, Reflect *>::iterator i=elms.begin(); i != elms.end(); ++i)
+		delete i.value();
+}
+
+ReflectImpl<LoadPage>::ReflectImpl(LoadPage & c) {
+	WKHTMLTOPDF_REFLECT(username);
+	WKHTMLTOPDF_REFLECT(password);
+	WKHTMLTOPDF_REFLECT(jsdelay);
+	WKHTMLTOPDF_REFLECT(zoomFactor);
+	WKHTMLTOPDF_REFLECT(customHeaders);
+	WKHTMLTOPDF_REFLECT(repeatCustomHeaders);
+	WKHTMLTOPDF_REFLECT(cookies);
+	WKHTMLTOPDF_REFLECT(post);
+	WKHTMLTOPDF_REFLECT(blockLocalFileAccess);
+	WKHTMLTOPDF_REFLECT(allowed);
+	WKHTMLTOPDF_REFLECT(stopSlowScripts);
+	WKHTMLTOPDF_REFLECT(debugJavascript);
+	WKHTMLTOPDF_REFLECT(loadErrorHandling);
+	WKHTMLTOPDF_REFLECT(proxy);
+}
+
+ReflectImpl<Web>::ReflectImpl(Web & c) {
+	WKHTMLTOPDF_REFLECT(background);
+	WKHTMLTOPDF_REFLECT(loadImages);
+	WKHTMLTOPDF_REFLECT(enableJavascript);
+	WKHTMLTOPDF_REFLECT(enableIntelligentShrinking);
+	WKHTMLTOPDF_REFLECT(minimumFontSize);
+	WKHTMLTOPDF_REFLECT(printMediaType);
+	WKHTMLTOPDF_REFLECT(defaultEncoding);
+	WKHTMLTOPDF_REFLECT(userStyleSheet);
+	WKHTMLTOPDF_REFLECT(enablePlugins);
+}
+
+}
+}

+ 225 - 0
src/lib/reflect.hh

@@ -0,0 +1,225 @@
+// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
+// vi:set ts=4 sts=4 sw=4 noet :
+//
+// Copyright 2010 wkhtmltopdf authors
+//
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __REFLECT_HH__
+#define __REFLECT_HH__
+#include "loadsettings.hh"
+#include "websettings.hh"
+#include <QStringList>
+#include <cstring>
+
+#include "dllbegin.inc"
+namespace wkhtmltopdf {
+namespace settings {
+
+#define WKHTMLTOPDF_REFLECT(name) ReflectClass::add(#name, new ReflectImpl<typeof(c.name)> (c.name));
+
+class DLL_LOCAL Reflect {
+public:
+	virtual QString get(const char * name) = 0;
+	virtual bool set(const char * name, const QString & value) = 0;
+	virtual ~Reflect() {};
+};
+
+class DLL_LOCAL ReflectSimple: public Reflect {
+public:
+	virtual QString get() = 0;
+	virtual void set(const QString & value, bool * ok) = 0;
+
+	virtual QString get(const char * name) {return name[0]=='\0'?get():QString();}
+	virtual bool set(const char * name, const QString & value);
+};
+
+class DLL_LOCAL ReflectClass: public Reflect {
+public:
+	QMap<QString, Reflect *> elms;
+	void add(const char * name, Reflect * r) {elms[name] = r;}
+	QString get(const char * name);
+	bool set(const char * name, const QString & value);
+	~ReflectClass();
+};
+
+template <typename X>
+class DLL_LOCAL ReflectImpl {
+private:
+	ReflectImpl();
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<bool>: public ReflectSimple {
+	bool & b;
+	ReflectImpl(bool & _): b(_) {}
+	QString get() {return b?"true":"false";}
+	void set(const QString & value, bool * ok) {
+		if (value == "true") b=true;
+		else if (value == "false") b=false;
+		else *ok=false;
+		*ok=true;
+	}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<QString>: public ReflectSimple {
+	QString & s;
+	ReflectImpl(QString & _): s(_) {}
+	QString get() {return s;}
+	void set(const QString & value, bool * ok) {s=value; *ok=true;}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<int>: public ReflectSimple {
+	int & i;
+	ReflectImpl(int & _): i(_) {}
+	QString get() {return QString::number(i);}
+	void set(const QString & value, bool * ok) {i = value.toInt(ok);}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<float>: public ReflectSimple {
+	float & f;
+	ReflectImpl(float & _): f(_) {}
+	QString get() {return QString::number(f);}
+	void set(const QString & value, bool * ok) {f = value.toDouble(ok);}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl< QPair<QString, QString> >: public ReflectSimple {
+	QPair<QString, QString> & p;
+	ReflectImpl(QPair<QString, QString> & _): p(_) {};
+
+	QString get() {
+		return p.first.replace("\\", "\\\\").replace(",", "\\,") + "," +
+			p.second.replace("\\", "\\\\").replace(",", "\\,");
+	}
+
+	void set(const QString & value, bool * ok) {
+		QStringList l = value.split(",");
+		if (l.size() != 0) {*ok=false; return;}
+		*ok=true;
+		p.first = l[0].replace("\\,",",").replace("\\\\","\\");
+		p.second = l[1].replace("\\,",",").replace("\\\\","\\");
+	}
+};
+
+template<typename X>
+struct DLL_LOCAL ReflectImpl< QList< X> >: public Reflect {
+	QList<X> & l;
+
+	ReflectImpl(QList<X> & _): l(_) {}
+
+	bool parse(const char * name, int & parmsize, int & next, int & elm) {
+		elm=-1;
+		parmsize = -1;
+		if (name[0] == '[') {
+			next = 0;
+			while (name[next] != '\0' && name[next] != ']') ++next;
+			bool ok=true;
+			elm = QString::fromAscii(name+1,next-1).toInt(&ok);
+			if (name[next] == ']') ++next;
+			return ok;
+		}
+		parmsize = 0;
+		while (name[parmsize] != '\0' || name[parmsize] != '.' || name[parmsize] != '[') ++parmsize;
+		next = parmsize;
+		if (name[next] == '.') ++next;
+		return true;
+	}
+
+	virtual QString get(const char * name) {
+		int ps, next, elm;
+		if (!strcmp(name,"size")) return QString::number(l.size());
+		parse(name, ps, next, elm);
+		if (ps > 0 || !strncmp(name, "last", ps)) elm = l.size() -1;
+		if (elm < 0 || elm >= l.size()) return QString();
+		ReflectImpl<X> impl(l[elm]);
+		return static_cast<Reflect*>(&impl)->get(name+next);
+	};
+
+	virtual bool set(const char * name, const QString & value) {
+		int ps, next, elm;
+		if (!strcmp(name,"clear"))
+			l.clear();
+		else if (!strcmp(name,"pop"))
+			l.pop_back();
+		else if (!strcmp(name,"append"))
+			l.push_front(X());
+		else {
+			parse(name, ps, next, elm);
+			if (ps > 0 || !strncmp(name, "last", ps)) elm = l.size() -1;
+			if (ps > 0 || !strncmp(name, "append", ps)) {
+				l.push_front(X());
+				elm = l.size() -1;
+			}
+			ReflectImpl<X> impl(l[elm]);
+			return static_cast<Reflect *>(&impl)->set(name+next, value);
+		}
+		return true;
+	}
+};
+
+
+template<>
+struct DLL_LOCAL ReflectImpl<LoadPage::LoadErrorHandling>: public ReflectSimple {
+	LoadPage::LoadErrorHandling & l;
+	ReflectImpl(LoadPage::LoadErrorHandling & _): l(_) {}
+	QString get() {return loadErrorHandlingToStr(l);}
+	void set(const QString & value, bool * ok) {l = strToLoadErrorHandling(value.toUtf8().constData(), ok);}
+};
+
+
+template<>
+struct DLL_LOCAL ReflectImpl<Proxy>: public ReflectSimple {
+	Proxy & p;
+	ReflectImpl(Proxy & _): p(_) {}
+	QString get() {return proxyToStr(p);}
+	void set(const QString & value, bool * ok) {p = strToProxy(value.toUtf8().constData(), ok);}
+};
+
+template<>
+struct DLL_LOCAL ReflectImpl<PostItem>: public ReflectClass {
+	ReflectImpl(PostItem & c) {
+		WKHTMLTOPDF_REFLECT(name);
+		WKHTMLTOPDF_REFLECT(value);
+		WKHTMLTOPDF_REFLECT(file);
+	}
+};
+
+template <>
+struct DLL_LOCAL ReflectImpl<LoadGlobal>: public ReflectClass {
+	ReflectImpl(LoadGlobal & c) {
+		WKHTMLTOPDF_REFLECT(cookieJar);
+	};
+};
+
+
+template <>
+struct DLL_LOCAL ReflectImpl<LoadPage>: public ReflectClass {
+	ReflectImpl(LoadPage & c);
+};
+
+template <>
+struct DLL_LOCAL ReflectImpl<Web>: public ReflectClass {
+	ReflectImpl(Web & c);
+};
+
+}
+}
+#include "dllend.inc"
+#endif //__REFLECT_HH__

+ 2 - 0
src/shared/tempfile.cc → src/lib/tempfile.cc

@@ -22,6 +22,8 @@
 #include <QDir>
 #include <QDir>
 #include <QFile>
 #include <QFile>
 #include <QUuid>
 #include <QUuid>
+
+#include "dllbegin.inc"
 /*!
 /*!
   \file tempfile.hh
   \file tempfile.hh
   \brief Defines the TempFile class
   \brief Defines the TempFile class

+ 5 - 1
src/shared/tempfile.hh → src/lib/tempfile.hh

@@ -22,7 +22,9 @@
 #define __TEMPFILE_HH__
 #define __TEMPFILE_HH__
 #include <QString>
 #include <QString>
 
 
-class TempFile {
+#include "dllbegin.inc"
+
+class DLL_LOCAL TempFile {
 private:
 private:
 	QString path;
 	QString path;
 public:
 public:
@@ -31,4 +33,6 @@ public:
 	QString create(const QString & ext);
 	QString create(const QString & ext);
 	void remove();
 	void remove();
 };
 };
+
+#include "dllend.inc"
 #endif //__TEMPFILE_HH__
 #endif //__TEMPFILE_HH__

+ 1 - 1
src/pdf/tocstylesheet.cc → src/lib/tocstylesheet.cc

@@ -19,7 +19,7 @@
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
 #include "outline_p.hh"
 #include "outline_p.hh"
-#include "settings.hh"
+#include "pdfsettings.hh"
 #include <QTextOStream>
 #include <QTextOStream>
 
 
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {

+ 0 - 0
src/shared/websettings.cc → src/lib/websettings.cc


+ 4 - 1
src/shared/websettings.hh → src/lib/websettings.hh

@@ -22,10 +22,12 @@
 #define __WEBSETTINGS_HH__
 #define __WEBSETTINGS_HH__
 #include <QNetworkProxy>
 #include <QNetworkProxy>
 #include <QString>
 #include <QString>
+
+#include <wkhtmltox/dllbegin.inc>
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 namespace settings {
 namespace settings {
 
 
-struct Web {
+struct DLL_PUBLIC Web {
 	Web();
 	Web();
 
 
 	//! Should we print background images
 	//! Should we print background images
@@ -58,4 +60,5 @@ struct Web {
 
 
 }
 }
 }
 }
+#include <wkhtmltox/dllend.inc>
 #endif //__WEBSETTINGS_HH__
 #endif //__WEBSETTINGS_HH__

+ 7 - 8
src/pdf/pdf.pro

@@ -49,13 +49,12 @@ target.path=$$INSTALLBASE/bin
 
 
 include(../shared/shared.pri)
 include(../shared/shared.pri)
 
 
-#Libaray part
-HEADERS += pdfconverter.hh pdfconverter_p.hh
-
-SOURCES += settings.cc pdfconverter.cc \
-           outline.cc tocstylesheet.cc
+contains(DEFINES, QT_SHARED) {
+  LIBS += -L../../bin -lwkhtmltox
+} else {
+  include(../lib/lib.pri)
+}
 
 
 #Application part
 #Application part
-
-SOURCES += wkhtmltopdf.cc arguments.cc commandlineparser.cc \
-           docparts.cc
+SOURCES += wkhtmltopdf.cc pdfarguments.cc pdfcommandlineparser.cc \
+           pdfdocparts.cc

+ 7 - 7
src/pdf/arguments.cc → src/pdf/pdfarguments.cc

@@ -19,10 +19,10 @@
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
 #include "arghandler.inl"
 #include "arghandler.inl"
-#include "commandlineparser.hh"
-#include "pdfconverter.hh"
+#include "pdfcommandlineparser.hh"
 #include <QFile>
 #include <QFile>
 #include <qglobal.h>
 #include <qglobal.h>
+#include <wkhtmltox/pdfconverter.hh>
 
 
 /*!
 /*!
   \class ArgHandler
   \class ArgHandler
@@ -137,10 +137,10 @@ struct DefaultTocFunc {
 */
 */
 struct DefaultHeaderFunc {
 struct DefaultHeaderFunc {
 	bool operator()(const char **, CommandLineParserBase & p, char * page) {
 	bool operator()(const char **, CommandLineParserBase & p, char * page) {
-		reinterpret_cast<Page*>(page)->header.left="[webpage]";
-		reinterpret_cast<Page*>(page)->header.right="[page]/[toPage]";
-		reinterpret_cast<Page*>(page)->header.line=true;
-		static_cast<CommandLineParser&>(p).globalSettings.margin.top = strToUnitReal("2cm");
+		reinterpret_cast<PdfObject*>(page)->header.left="[webpage]";
+		reinterpret_cast<PdfObject*>(page)->header.right="[page]/[toPdfObject]";
+		reinterpret_cast<PdfObject*>(page)->header.line=true;
+		static_cast<PdfCommandLineParser&>(p).globalSettings.margin.top = strToUnitReal("2cm");
 		return true;
 		return true;
 	}
 	}
 };
 };
@@ -164,7 +164,7 @@ struct BookFunc {
   Construct the commandline parser adding all the arguments
   Construct the commandline parser adding all the arguments
   \param s The settings to store values in
   \param s The settings to store values in
 */
 */
-CommandLineParser::CommandLineParser(Global & s, QList<Page> & ps):
+PdfCommandLineParser::PdfCommandLineParser(PdfGlobal & s, QList<PdfObject> & ps):
 	readArgsFromStdin(false),
 	readArgsFromStdin(false),
 	globalSettings(s),
 	globalSettings(s),
 	pageSettings(ps) {
 	pageSettings(ps) {

+ 10 - 10
src/pdf/commandlineparser.cc → src/pdf/pdfcommandlineparser.cc

@@ -18,26 +18,26 @@
 // You should have received a copy of the GNU General Public License
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
-#include "commandlineparser.hh"
 #include "outputter.hh"
 #include "outputter.hh"
+#include "pdfcommandlineparser.hh"
 #include <qwebframe.h>
 #include <qwebframe.h>
 
 
 using namespace wkhtmltopdf::settings;
 using namespace wkhtmltopdf::settings;
 /*!
 /*!
   \file commandlineparser.hh
   \file commandlineparser.hh
-  \brief Defines the CommandLineParser class
+  \brief Defines the PdfCommandLineParser class
 */
 */
 
 
 /*!
 /*!
   \file commandlineparser_p.hh
   \file commandlineparser_p.hh
-  \brief Defines the CommandLineParserPrivate, ArgHandler and Outputter class
+  \brief Defines the PdfCommandLineParserPrivate, ArgHandler and Outputter class
 */
 */
 
 
 /*!
 /*!
   Output the man page to a given file
   Output the man page to a given file
   \param fd The file to store the man page
   \param fd The file to store the man page
 */
 */
-void CommandLineParser::manpage(FILE * fd) const {
+void PdfCommandLineParser::manpage(FILE * fd) const {
 	Outputter * o = Outputter::man(fd);
 	Outputter * o = Outputter::man(fd);
  	outputManName(o);
  	outputManName(o);
  	outputSynopsis(o);
  	outputSynopsis(o);
@@ -63,7 +63,7 @@ void CommandLineParser::manpage(FILE * fd) const {
   \param fd The file to output the information to
   \param fd The file to output the information to
   \param extended Should we show extended arguments
   \param extended Should we show extended arguments
 */
 */
-void CommandLineParser::usage(FILE * fd, bool extended) const {
+void PdfCommandLineParser::usage(FILE * fd, bool extended) const {
 	Outputter * o = Outputter::text(fd,false);
 	Outputter * o = Outputter::text(fd,false);
 	outputName(o);
 	outputName(o);
 	outputSynopsis(o);
 	outputSynopsis(o);
@@ -88,7 +88,7 @@ void CommandLineParser::usage(FILE * fd, bool extended) const {
   \param fd The file to output to
   \param fd The file to output to
   \param html Do we want the html manaul, or the README
   \param html Do we want the html manaul, or the README
 */
 */
-void CommandLineParser::readme(FILE * fd, bool html) const {
+void PdfCommandLineParser::readme(FILE * fd, bool html) const {
 	Outputter * o = html?Outputter::html(fd):Outputter::text(fd, true);
 	Outputter * o = html?Outputter::html(fd):Outputter::text(fd, true);
 	outputDocStart(o);
 	outputDocStart(o);
 	outputContact(o);
 	outputContact(o);
@@ -113,7 +113,7 @@ void CommandLineParser::readme(FILE * fd, bool html) const {
 /*!
 /*!
  * Load default arguments and put them in the settings structure
  * Load default arguments and put them in the settings structure
  */
  */
-//void CommandLineParser::loadDefaults() {
+//void PdfCommandLineParser::loadDefaults() {
 	//settings.in.clear();
 	//settings.in.clear();
 	//settings.proxy.host = "";
 	//settings.proxy.host = "";
 	//foreach(ArgHandler * h, longToHandler)
 	//foreach(ArgHandler * h, longToHandler)
@@ -138,11 +138,11 @@ void CommandLineParser::readme(FILE * fd, bool html) const {
  * \param argc the number of command line arguments
  * \param argc the number of command line arguments
  * \param argv a NULL terminated list with the arguments
  * \param argv a NULL terminated list with the arguments
  */
  */
-void CommandLineParser::parseArguments(int argc, const char ** argv, bool fromStdin) {
+void PdfCommandLineParser::parseArguments(int argc, const char ** argv, bool fromStdin) {
 	bool defaultMode = false;
 	bool defaultMode = false;
 	int arg=1;
 	int arg=1;
 
 
-	Page def;
+	PdfObject def;
 
 
 	//Parse global options
 	//Parse global options
 	for (;arg < argc;++arg) {
 	for (;arg < argc;++arg) {
@@ -155,7 +155,7 @@ void CommandLineParser::parseArguments(int argc, const char ** argv, bool fromSt
 	//Parse page options
 	//Parse page options
 	while (arg < argc-1) {
 	while (arg < argc-1) {
 		pageSettings.push_back(def);
 		pageSettings.push_back(def);
-		Page & ps = pageSettings.back();
+		PdfObject & ps = pageSettings.back();
 		int sections = page;
 		int sections = page;
 		if (!strcmp(argv[arg],"cover")) {
 		if (!strcmp(argv[arg],"cover")) {
 			++arg;
 			++arg;

+ 11 - 11
src/pdf/commandlineparser.hh → src/pdf/pdfcommandlineparser.hh

@@ -18,26 +18,26 @@
 // You should have received a copy of the GNU General Public License
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
-#ifndef __COMMANDLINEPARSER_HH__
-#define __COMMANDLINEPARSER_HH__
+#ifndef __PDFCOMMANDLINEPARSER_HH__
+#define __PDFCOMMANDLINEPARSER_HH__
 #include "commandlineparserbase.hh"
 #include "commandlineparserbase.hh"
-#include "settings.hh"
 #include <cstdio>
 #include <cstdio>
+#include <wkhtmltox/pdfsettings.hh>
 
 
-class CommandLineParser: public CommandLineParserBase {
+class PdfCommandLineParser: public CommandLineParserBase {
 public:
 public:
 	const static int global = 1;
 	const static int global = 1;
 	const static int page = 2;
 	const static int page = 2;
 	const static int toc = 4;
 	const static int toc = 4;
 	bool readArgsFromStdin;
 	bool readArgsFromStdin;
-	wkhtmltopdf::settings::Global & globalSettings;
-	QList<wkhtmltopdf::settings::Page> & pageSettings;
+	wkhtmltopdf::settings::PdfGlobal & globalSettings;
+	QList<wkhtmltopdf::settings::PdfObject> & pageSettings;
 
 
-	wkhtmltopdf::settings::Page od;
+	wkhtmltopdf::settings::PdfObject od;
 
 
 	//Arguments.cc
 	//Arguments.cc
-	CommandLineParser(wkhtmltopdf::settings::Global & globalSettings,
-					  QList<wkhtmltopdf::settings::Page> & pageSettings);
+	PdfCommandLineParser(wkhtmltopdf::settings::PdfGlobal & globalSettings,
+					  QList<wkhtmltopdf::settings::PdfObject> & pageSettings);
 
 
 	//docparts.cc
 	//docparts.cc
 	void outputManName(Outputter * o) const;
 	void outputManName(Outputter * o) const;
@@ -65,9 +65,9 @@ public:
 
 
 	virtual char * mapAddress(char * d, char * ns) const {
 	virtual char * mapAddress(char * d, char * ns) const {
 		const char * _od = reinterpret_cast<const char *>(&od);
 		const char * _od = reinterpret_cast<const char *>(&od);
-		if (_od > d || d >= _od + sizeof(wkhtmltopdf::settings::Page)) return d;;
+		if (_od > d || d >= _od + sizeof(wkhtmltopdf::settings::PdfObject)) return d;;
 		return d - _od + ns;
 		return d - _od + ns;
 	}
 	}
 
 
 };
 };
-#endif //__COMMANDLINEPARSER_HH__
+#endif //__PDFCOMMANDLINEPARSER_HH__

+ 15 - 15
src/pdf/docparts.cc → src/pdf/pdfdocparts.cc

@@ -18,8 +18,8 @@
 // You should have received a copy of the GNU General Public License
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
-#include "commandlineparser.hh"
 #include "outputter.hh"
 #include "outputter.hh"
+#include "pdfcommandlineparser.hh"
 #include <QWebFrame>
 #include <QWebFrame>
 
 
 #define STRINGIZE_(x) #x
 #define STRINGIZE_(x) #x
@@ -29,7 +29,7 @@
   Output name and a short description
   Output name and a short description
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputManName(Outputter * o) const {
+void PdfCommandLineParser::outputManName(Outputter * o) const {
 	o->beginSection("Name");
 	o->beginSection("Name");
 	o->paragraph("wkhtmltopdf - html to pdf converter");
 	o->paragraph("wkhtmltopdf - html to pdf converter");
 	o->endSection();
 	o->endSection();
@@ -39,7 +39,7 @@ void CommandLineParser::outputManName(Outputter * o) const {
   Output a short synopsis on how to call the command line program
   Output a short synopsis on how to call the command line program
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputSynopsis(Outputter * o) const {
+void PdfCommandLineParser::outputSynopsis(Outputter * o) const {
 	o->beginSection("Synopsis");
 	o->beginSection("Synopsis");
 	o->verbatim("wkhtmltopdf [GLOBAL OPTION]... [OBJECT]... <output file>\n");
 	o->verbatim("wkhtmltopdf [GLOBAL OPTION]... [OBJECT]... <output file>\n");
 	o->endSection();
 	o->endSection();
@@ -91,7 +91,7 @@ void CommandLineParser::outputSynopsis(Outputter * o) const {
   Explain what the program does
   Explain what the program does
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputDescripton(Outputter * o) const {
+void PdfCommandLineParser::outputDescripton(Outputter * o) const {
 	o->beginSection("Description");
 	o->beginSection("Description");
 	o->beginParagraph();
 	o->beginParagraph();
 	o->text("Converts one or more HTML pages into a PDF document, ");
 	o->text("Converts one or more HTML pages into a PDF document, ");
@@ -110,7 +110,7 @@ void CommandLineParser::outputDescripton(Outputter * o) const {
   \param o The outputter to output to
   \param o The outputter to output to
   \param sure Is the functionality restricted in this wkhtmltopdf
   \param sure Is the functionality restricted in this wkhtmltopdf
 */
 */
-void CommandLineParser::outputNotPatched(Outputter * o, bool sure) const {
+void PdfCommandLineParser::outputNotPatched(Outputter * o, bool sure) const {
 	o->beginSection("Reduced Functionality");
 	o->beginSection("Reduced Functionality");
 	if (sure)
 	if (sure)
 		o->paragraph("This version of wkhtmltopdf has been compiled against a version of "
 		o->paragraph("This version of wkhtmltopdf has been compiled against a version of "
@@ -140,7 +140,7 @@ void CommandLineParser::outputNotPatched(Outputter * o, bool sure) const {
   Explain the page breaking is somewhat broken
   Explain the page breaking is somewhat broken
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputPageBreakDoc(Outputter * o) const {
+void PdfCommandLineParser::outputPageBreakDoc(Outputter * o) const {
 	o->beginSection("Page Breaking");
 	o->beginSection("Page Breaking");
 	o->paragraph(
 	o->paragraph(
 		"The current page breaking algorithm of WebKit leaves much to be desired. "
 		"The current page breaking algorithm of WebKit leaves much to be desired. "
@@ -169,7 +169,7 @@ void CommandLineParser::outputPageBreakDoc(Outputter * o) const {
   Output documentation about headers and footers
   Output documentation about headers and footers
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputHeaderFooterDoc(Outputter * o) const {
+void PdfCommandLineParser::outputHeaderFooterDoc(Outputter * o) const {
 	o->beginSection("Footers And Headers");
 	o->beginSection("Footers And Headers");
 	o->paragraph("Headers and footers can be added to the document by the --header-* and --footer* "
 	o->paragraph("Headers and footers can be added to the document by the --header-* and --footer* "
 				 "arguments respectfully.  In header and footer text string supplied to e.g. --header-left, "
 				 "arguments respectfully.  In header and footer text string supplied to e.g. --header-left, "
@@ -225,7 +225,7 @@ void CommandLineParser::outputHeaderFooterDoc(Outputter * o) const {
   Output documentation about outlines
   Output documentation about outlines
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputOutlineDoc(Outputter * o) const {
+void PdfCommandLineParser::outputOutlineDoc(Outputter * o) const {
 	o->beginSection("Outlines");
 	o->beginSection("Outlines");
 	o->beginParagraph();
 	o->beginParagraph();
 	o->text(
 	o->text(
@@ -247,7 +247,7 @@ void CommandLineParser::outputOutlineDoc(Outputter * o) const {
   Output contact information
   Output contact information
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputContact(Outputter * o) const {
+void PdfCommandLineParser::outputContact(Outputter * o) const {
 	o->beginSection("Contact");
 	o->beginSection("Contact");
 	o->beginParagraph();
 	o->beginParagraph();
 	o->text("If you experience bugs or want to request new features please visit ");
 	o->text("If you experience bugs or want to request new features please visit ");
@@ -262,7 +262,7 @@ void CommandLineParser::outputContact(Outputter * o) const {
   Output beginning of the readme
   Output beginning of the readme
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputDocStart(Outputter * o) const {
+void PdfCommandLineParser::outputDocStart(Outputter * o) const {
 	o->beginSection(QString("wkhtmltopdf ")+QString::number(MAJOR_VERSION)+"."+QString::number(MINOR_VERSION)+"."+QString::number(PATCH_VERSION)+(QString(STRINGIZE(BUILD)).isEmpty()?"":" ")+STRINGIZE(BUILD) + " Manual");
 	o->beginSection(QString("wkhtmltopdf ")+QString::number(MAJOR_VERSION)+"."+QString::number(MINOR_VERSION)+"."+QString::number(PATCH_VERSION)+(QString(STRINGIZE(BUILD)).isEmpty()?"":" ")+STRINGIZE(BUILD) + " Manual");
 	o->paragraph("This file documents wkhtmltopdf, a program capable of converting html "
 	o->paragraph("This file documents wkhtmltopdf, a program capable of converting html "
 				 "documents into PDF documents.");
 				 "documents into PDF documents.");
@@ -273,7 +273,7 @@ void CommandLineParser::outputDocStart(Outputter * o) const {
   Output information on how to use read-args-from-stdin
   Output information on how to use read-args-from-stdin
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputArgsFromStdin(Outputter * o) const {
+void PdfCommandLineParser::outputArgsFromStdin(Outputter * o) const {
 	o->beginSection("Reading arguments from stdin");
 	o->beginSection("Reading arguments from stdin");
 	o->paragraph("If you need to convert a lot of pages in a batch, and you feel that wkhtmltopdf "
 	o->paragraph("If you need to convert a lot of pages in a batch, and you feel that wkhtmltopdf "
 				 "is a bit to slow to start up, then you should try --read-args-from-stdin,");
 				 "is a bit to slow to start up, then you should try --read-args-from-stdin,");
@@ -291,7 +291,7 @@ void CommandLineParser::outputArgsFromStdin(Outputter * o) const {
   Output information on how to compile
   Output information on how to compile
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputCompilation(Outputter * o) const {
+void PdfCommandLineParser::outputCompilation(Outputter * o) const {
 	o->beginSection("Compilation");
 	o->beginSection("Compilation");
 	o->paragraph("It can happen that the static binary does not work for your system "
 	o->paragraph("It can happen that the static binary does not work for your system "
 				 "for one reason or the other, in that case you might need to compile "
 				 "for one reason or the other, in that case you might need to compile "
@@ -340,7 +340,7 @@ void CommandLineParser::outputCompilation(Outputter * o) const {
   Output information on how to install
   Output information on how to install
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputInstallation(Outputter * o) const {
+void PdfCommandLineParser::outputInstallation(Outputter * o) const {
 	o->beginSection("Installation");
 	o->beginSection("Installation");
 	o->paragraph(
 	o->paragraph(
 		"There are several ways to install wkhtmltopdf.  You can download a "
 		"There are several ways to install wkhtmltopdf.  You can download a "
@@ -358,7 +358,7 @@ void CommandLineParser::outputInstallation(Outputter * o) const {
   \param o The outputter to output to
   \param o The outputter to output to
 
 
 */
 */
-void CommandLineParser::outputPageSizes(Outputter * o) const {
+void PdfCommandLineParser::outputPageSizes(Outputter * o) const {
 	o->beginSection("Page sizes");
 	o->beginSection("Page sizes");
 	o->beginParagraph();
 	o->beginParagraph();
 	o->text("The default page size of the rendered document is A4, but using this --page-size option"
 	o->text("The default page size of the rendered document is A4, but using this --page-size option"
@@ -376,7 +376,7 @@ void CommandLineParser::outputPageSizes(Outputter * o) const {
   Output examples on how to use wkhtmltopdf
   Output examples on how to use wkhtmltopdf
   \param o The outputter to output to
   \param o The outputter to output to
 */
 */
-void CommandLineParser::outputExampels(Outputter * o) const {
+void PdfCommandLineParser::outputExampels(Outputter * o) const {
 	o->beginSection("Examples");
 	o->beginSection("Examples");
 	o->paragraph("This section presents a number of examples of how to invoke wkhtmltopdf.");
 	o->paragraph("This section presents a number of examples of how to invoke wkhtmltopdf.");
 	o->paragraph("To convert a remote HTML file to PDF:");
 	o->paragraph("To convert a remote HTML file to PDF:");

+ 0 - 219
src/pdf/tocprinter.cc

@@ -1,219 +0,0 @@
-// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
-// vi:set ts=4 sts=4 sw=4 noet :
-//
-// Copyright 2010 wkhtmltopdf authors
-//
-// This file is part of wkhtmltopdf.
-//
-// wkhtmltopdf is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// wkhtmltopdf is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
-
-#include "outline_p.hh"
-#include "settings.hh"
-#include "tocprinter.hh"
-#ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
-
-
-typedef QPair<int, OutlineItem *> line_t;
-/*!
-  We imploy a cheep strategy of not using a render tree,
-  insted we just store the state render state for every page start,
-  the render state is uniquly defined by a OutlineItem,
- */
-class TocPrinterPrivate {
-public:
-	static const uint levels = Settings::TOCSettings::levels;
-
-	Outline * outline;
-	QPrinter * printer;
-	QPainter & painter;
-	double dw[levels];
-	double step[levels];
-	QVector<OutlineItem *> pageItems;
-
-	QList< QList< line_t > > pages;
-
-	TocPrinterPrivate(Outline * o, QPrinter * pr, QPainter & pa);
-	void revLinkChildren(OutlineItem * i, QVector<QPair<QWebElement, QString> > & links, int level);
-	void renderPage(OutlineItem * & cur, bool first, bool dry);
-	void layoutChildren(OutlineItem * item, double & y, int level);
-	void incChildren(OutlineItem * item);
-};
-
-
-void TocPrinterPrivate::incChildren(OutlineItem * item) {
-	foreach (OutlineItem * i, item->children) {
-		i->page += pages.size();
-		incChildren(i);
-	}
-}
-
-void TocPrinterPrivate::layoutChildren(OutlineItem * item, double & y, int level) {
-	const Settings::TOCSettings & s = outline->d->settings.toc;
-	if (level >= s.depth) return;
-	QRect pr = printer->pageRect();
-	foreach (OutlineItem * i, item->children) {
-		y += step[level];
-		if (y > pr.height()) {
-			pages.push_back( QList< QPair<int, OutlineItem *> >() );
-			y = step[level];
-		}
-		pages.back().push_back( qMakePair(level, i) );
-		layoutChildren(i, y, level+1);
-	}
-}
-
-TocPrinterPrivate::TocPrinterPrivate(Outline * o, QPrinter * pr, QPainter & pa):
-	outline(o), printer(pr), painter(pa) {
-	const Settings::TOCSettings & s = outline->d->settings.toc;
-	painter.save();
-	painter.resetTransform();
-	QRectF pageRect = printer->pageRect();
-	for (uint level=0; level < levels; ++level) {
-		painter.setFont(QFont(s.fontName, s.fontSize[level]));
-		step[level] = painter.fontMetrics().height();
-		dw[level] = painter.boundingRect(pageRect, Qt::AlignRight | Qt::AlignTop, ".").width();
-	}
-	painter.setFont(QFont(s.fontName, s.captionFontSize));
-	//The height of the caption
-	double y = painter.boundingRect(pageRect, Qt::AlignTop | Qt::AlignHCenter, s.captionText).height() * 3;
-	painter.restore();
-	pages.push_back( QList< QPair<int, OutlineItem *> >() );
-
-	OutlineItem * root = new OutlineItem();
-	OutlineItem * toc = new OutlineItem();
-	root->children.push_back(toc);
-	toc->value = s.captionText;
-	toc->anchor = "_WK_TOC";
-	toc->parent = root;
-	toc->page = outline->d->settings.pageOffset;
-
-	y += step[0];
-	pages.back().push_back( qMakePair(0, toc) );
-
-	foreach (OutlineItem * i, o->d->documentOutlines)
-		layoutChildren(i, y, 0);
-
-	outline->d->pageCount += pages.size();
-
-	foreach (OutlineItem * i, outline->d->documentOutlines)
-		incChildren(i);
-
-	outline->d->documentOutlines.push_front(root);
-}
-
-
-void TocPrinterPrivate::revLinkChildren(OutlineItem * i, QVector<QPair<QWebElement, QString> > & links, int level) {
-	const Settings::TOCSettings & s = outline->d->settings.toc;
-	if (level >= s.depth) return;
-	foreach (OutlineItem * j,i->children) {
-		links.push_back( qMakePair(j->element, j->anchor+QString("_R") ) );
-		revLinkChildren(j, links, level+1);
-	}
-}
-
-/*!
-  \file tocprinter.hh
-  \brief Defines the TocPrinter class
-*/
-
-/*!
-  \class TocPrinter
-  \brief Class responsible for rendering a table of content
-*/
-
-
-TocPrinter::TocPrinter(Outline * outline, QPrinter * printer, QPainter & painter):
-  d(new TocPrinterPrivate(outline, printer, painter)) {
-}
-
-TocPrinter::~TocPrinter() {
-  delete d;
-}
-
-/*!
-  \brief Return the number of pages in the table of content
-*/
-int TocPrinter::pageCount() {
-	return d->pages.size();
-}
-
-/*!
-  \brief Output a given page to the printer
-  \param The page to output, between 1 and pageCount()
-*/
-void TocPrinter::spoolPage(int page) {
-	d->painter.save();
-	d->painter.resetTransform();
-	d->painter.setBackgroundMode(Qt::TransparentMode);
-	d->painter.setBrush(QBrush(Qt::black));
-
-	double y = 0;
-	const Settings::TOCSettings & s = d->outline->d->settings.toc;
-	QRect pr = d->printer->pageRect();
-
-	if (page == 0) {
-		double h = d->painter.boundingRect(pr,Qt::AlignTop | Qt::AlignHCenter, s.captionText).height();
-		QRect r((int)h,0,pr.width(),(int)h*3);
-
-		d->painter.setFont(QFont(s.captionFontName.isEmpty()?s.fontName:s.captionFontName, s.captionFontSize));
-		d->painter.drawText(r, Qt::AlignVCenter | Qt::AlignHCenter, s.captionText);
-		d->painter.addAnchor(r, "_WK_TOC");
-		y += r.height();
-	}
-
-	int lvl=-1;
-	foreach (const line_t & line, d->pages[page]) {
-		if (line.first != lvl) {
-			lvl = line.first;
-			d->painter.setFont(QFont(s.fontName, s.fontSize[lvl]));
-		}
-
-		double startX = pr.width()*s.indentation[lvl]/1000.0;
-
-		QRectF lineRect(startX,y,pr.width()-startX, d->step[lvl]);
-
-		QRectF br;
-		d->painter.drawText(lineRect,Qt::AlignBottom | Qt::AlignRight, QString(" ") + QString::number(line.second->page),&br);
-		QString v = line.second->value;
-		lineRect.setRight(br.left());
-		if (s.useDots) {
-			v.append(' ');
-			//Calculate the number of dots needed to fill the line
-			int ndots = (lineRect.right() - d->painter.boundingRect(lineRect, Qt::AlignLeft, v).right())/d->dw[lvl];
-			for (int i=0; i < ndots; ++i) v.append(".");
-		}
-		d->painter.drawText(lineRect,Qt::AlignBottom | Qt::AlignLeft, v);
-
-		QRectF r(0,y, pr.width(), d->step[lvl]);
-		if (s.forwardLinks)
-			d->painter.addLink(r, line.second->anchor);
-		if (s.backLinks)
-			d->painter.addAnchor(r, line.second->anchor+"_R");
-		y += d->step[lvl];
-	}
-	d->painter.restore();
-}
-
-/*!
-  \brief Fill in document link structure with links linking back to the toc.
-  \param doc The 0' indexed document to fill the structure for
-  \param links The structure to fill
-*/
-void TocPrinter::fillLinks(int doc, QVector<QPair<QWebElement, QString> > & links) {
-	if (doc < 0 || doc >= d->outline->d->documentOutlines.size()) return;
-	d->revLinkChildren(d->outline->d->documentOutlines[doc], links, 0);
-}
-
-
-#endif //__EXTENSIVE_WKHTMLTOPDF_QT_HACK__

+ 13 - 13
src/pdf/wkhtmltopdf.cc

@@ -18,10 +18,8 @@
 // You should have received a copy of the GNU General Public License
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
 
-#include "commandlineparser.hh"
-#include "pdfconverter.hh"
+#include "pdfcommandlineparser.hh"
 #include "progressfeedback.hh"
 #include "progressfeedback.hh"
-#include "settings.hh"
 #include "utilities.hh"
 #include "utilities.hh"
 #include <QCleanlooksStyle>
 #include <QCleanlooksStyle>
 #include <QCommonStyle>
 #include <QCommonStyle>
@@ -34,6 +32,8 @@
 #include <qapplication.h>
 #include <qapplication.h>
 #include <qglobal.h>
 #include <qglobal.h>
 #include <string.h>
 #include <string.h>
+#include <wkhtmltox/pdfconverter.hh>
+#include <wkhtmltox/pdfsettings.hh>
 
 
 using namespace wkhtmltopdf::settings;
 using namespace wkhtmltopdf::settings;
 using namespace wkhtmltopdf;
 using namespace wkhtmltopdf;
@@ -115,10 +115,10 @@ void parseString(char * buff, int &nargc, char **nargv) {
 
 
 int main(int argc, char * argv[]) {
 int main(int argc, char * argv[]) {
 	//This will store all our settings
 	//This will store all our settings
-	Global globalSettings;
-	QList<Page> pageSettings;
+	PdfGlobal globalSettings;
+	QList<PdfObject> objectSettings;
 	//Create a command line parser to parse commandline arguments
 	//Create a command line parser to parse commandline arguments
-	CommandLineParser parser(globalSettings, pageSettings);
+	PdfCommandLineParser parser(globalSettings, objectSettings);
 
 
 	//Setup default values in settings
 	//Setup default values in settings
 	//parser.loadDefaults();
 	//parser.loadDefaults();
@@ -147,10 +147,10 @@ int main(int argc, char * argv[]) {
 			int nargc=argc;
 			int nargc=argc;
 			parseString(buff,nargc,nargv);
 			parseString(buff,nargc,nargv);
 
 
-			Global globalSettings;
-			QList<Page> pageSettings;
+			PdfGlobal globalSettings;
+			QList<PdfObject> objectSettings;
 			//Create a command line parser to parse commandline arguments
 			//Create a command line parser to parse commandline arguments
-			CommandLineParser parser(globalSettings, pageSettings);
+			PdfCommandLineParser parser(globalSettings, objectSettings);
 			//Setup default values in settings
 			//Setup default values in settings
 			//parser.loadDefaults();
 			//parser.loadDefaults();
 			//Parse the arguments
 			//Parse the arguments
@@ -158,8 +158,8 @@ int main(int argc, char * argv[]) {
 
 
 			PdfConverter converter(globalSettings);
 			PdfConverter converter(globalSettings);
 			ProgressFeedback feedback(globalSettings.quiet, converter);
 			ProgressFeedback feedback(globalSettings.quiet, converter);
-			foreach (const Page & page, pageSettings)
-				converter.addResource(page);
+			foreach (const PdfObject & object, objectSettings)
+				converter.addResource(object);
 
 
 			if (!converter.convert())
 			if (!converter.convert())
 				exit(EXIT_FAILURE);
 				exit(EXIT_FAILURE);
@@ -170,8 +170,8 @@ int main(int argc, char * argv[]) {
 	PdfConverter converter(globalSettings);
 	PdfConverter converter(globalSettings);
 	QObject::connect(&converter, SIGNAL(producingForms(bool)), style, SLOT(producingForms(bool)));
 	QObject::connect(&converter, SIGNAL(producingForms(bool)), style, SLOT(producingForms(bool)));
 	ProgressFeedback feedback(globalSettings.quiet, converter);
 	ProgressFeedback feedback(globalSettings.quiet, converter);
-	foreach (const Page & page, pageSettings)
-		converter.addResource(page);
+	foreach (const PdfObject & object, objectSettings)
+		converter.addResource(object);
 
 
 	bool success = converter.convert();
 	bool success = converter.convert();
 	return handleError(success, converter.httpErrorCode());
 	return handleError(success, converter.httpErrorCode());

+ 1 - 1
src/shared/arghandler.inl

@@ -21,7 +21,7 @@
 #ifndef __ARGHANDLER_INL__
 #ifndef __ARGHANDLER_INL__
 #define __ARGHANDLER_INL__
 #define __ARGHANDLER_INL__
 #include "commandlineparserbase.hh"
 #include "commandlineparserbase.hh"
-#include "loadsettings.hh"
+#include <wkhtmltox/loadsettings.hh>
 
 
 template <typename T> class DstArgHandler: public ArgHandler {
 template <typename T> class DstArgHandler: public ArgHandler {
 public:
 public:

+ 2 - 2
src/shared/commandlineparserbase.hh

@@ -20,8 +20,8 @@
 
 
 #ifndef __COMMANDLINEPARSERBASE_HH__
 #ifndef __COMMANDLINEPARSERBASE_HH__
 #define __COMMANDLINEPARSERBASE_HH__
 #define __COMMANDLINEPARSERBASE_HH__
-#include "loadsettings.hh"
-#include "websettings.hh"
+#include <wkhtmltox/loadsettings.hh>
+#include <wkhtmltox/websettings.hh>
 class Outputter;
 class Outputter;
 class CommandLineParserBase;
 class CommandLineParserBase;
 
 

+ 1 - 1
src/shared/commonarguments.cc

@@ -20,7 +20,7 @@
 
 
 #include "arghandler.inl"
 #include "arghandler.inl"
 #include "commandlineparserbase.hh"
 #include "commandlineparserbase.hh"
-#include "loadsettings.hh"
+#include <wkhtmltox/loadsettings.hh>
 using namespace wkhtmltopdf::settings;
 using namespace wkhtmltopdf::settings;
 
 
 struct LoadErrorHandlingTM: public SomeSetterTM<LoadPage::LoadErrorHandling> {
 struct LoadErrorHandlingTM: public SomeSetterTM<LoadPage::LoadErrorHandling> {

+ 1 - 1
src/shared/progressfeedback.hh

@@ -20,7 +20,7 @@
 
 
 #ifndef __PROGRESSFEEDBACK_HH__
 #ifndef __PROGRESSFEEDBACK_HH__
 #define __PROGRESSFEEDBACK_HH__
 #define __PROGRESSFEEDBACK_HH__
-#include "converter.hh"
+#include <wkhtmltox/converter.hh>
 namespace wkhtmltopdf {
 namespace wkhtmltopdf {
 
 
 class ProgressFeedback: public QObject {
 class ProgressFeedback: public QObject {

+ 3 - 9
src/shared/shared.pri

@@ -15,15 +15,9 @@
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
 # along with wkhtmltopdf.  If not, see <http:#www.gnu.org/licenses/>.
 # along with wkhtmltopdf.  If not, see <http:#www.gnu.org/licenses/>.
 
 
-#Lbaray Part
-HEADERS += ../shared/multipageloader_p.hh ../shared/multipageloader.hh ../shared/converter.hh \
-	 ../shared/converter_p.hh ../shared/progressfeedback.hh
-SOURCES += ../shared/loadsettings.cc ../shared/multipageloader.cc ../shared/tempfile.cc \
-	../shared/converter.cc ../shared/websettings.cc ../shared/progressfeedback.cc
-
-#Application part
-HEADERS +=  ../shared/utilities.hh
+HEADERS +=  ../shared/utilities.hh  ../shared/progressfeedback.hh
 
 
 SOURCES += ../shared/outputter.cc ../shared/manoutputter.cc ../shared/htmloutputter.cc \
 SOURCES += ../shared/outputter.cc ../shared/manoutputter.cc ../shared/htmloutputter.cc \
            ../shared/textoutputter.cc ../shared/arghandler.cc ../shared/commondocparts.cc \
            ../shared/textoutputter.cc ../shared/arghandler.cc ../shared/commondocparts.cc \
- 	   ../shared/commandlineparserbase.cc ../shared/commonarguments.cc ../shared/utilities.cc
+ 	   ../shared/commandlineparserbase.cc ../shared/commonarguments.cc ../shared/utilities.cc \
+	   ../shared/progressfeedback.cc

+ 2 - 1
wkhtmltopdf.pro

@@ -17,5 +17,6 @@
 
 
 TEMPLATE = subdirs
 TEMPLATE = subdirs
 
 
+
 CONFIG += ordered
 CONFIG += ordered
-SUBDIRS = src/pdf src/image
+SUBDIRS = src/lib src/pdf src/image