This repository has been archived by the owner on Jan 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 177
/
cuty_capt.rb
278 lines (261 loc) · 9.01 KB
/
cuty_capt.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
class CutyCapt < Formula
desc "Converts web pages to vector/bitmap images using WebKit"
homepage "http://cutycapt.sourceforge.net/"
#url "https://mirrorservice.org/sites/ftp.debian.org/debian/pool/main/c/cutycapt/cutycapt_0.0~svn6.orig.tar.gz"
#sha256 "cf85226a25731aff644f87a4e40b8878154667a6725a4dc0d648d7ec2d842264"
url 'https://github.com/hoehrmann/CutyCapt', :using => :git, :revision => 'bea8c78'
version "0.0.10"
# Update to svn version 10
#patch :DATA
depends_on "qt"
def install
system "qmake", "CONFIG-=app_bundle"
system "make"
bin.install "CutyCapt"
end
test do
system "#{bin}/CutyCapt", "--url=http://brew.sh", "--out=brew.png"
assert File.exist? "brew.png"
end
end
__END__
diff --git a/CutyCapt.cpp b/CutyCapt.cpp
index c0839a6..c732cb9 100644
--- a/CutyCapt.cpp
+++ b/CutyCapt.cpp
@@ -2,13 +2,18 @@
//
// CutyCapt - A Qt WebKit Web Page Rendering Capture Utility
//
-// Copyright (C) 2003-2010 Bjoern Hoehrmann <[email protected]>
+// Copyright (C) 2003-2013 Bjoern Hoehrmann <[email protected]>
//
// This program 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 2
// of the License, or (at your option) any later version.
//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
// This program 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
@@ -22,10 +27,15 @@
#include <QtWebKit>
#include <QtGui>
#include <QSvgGenerator>
+
+#if QT_VERSION < 0x050000
#include <QPrinter>
+#endif
+
#include <QTimer>
#include <QByteArray>
#include <QNetworkRequest>
+#include <QNetworkProxy>
#include "CutyCapt.hpp"
#if QT_VERSION >= 0x040600 && 0
@@ -51,7 +61,9 @@ static struct _CutyExtMap {
{ CutyCapt::PsFormat, ".ps", "ps" },
{ CutyCapt::InnerTextFormat, ".txt", "itext" },
{ CutyCapt::HtmlFormat, ".html", "html" },
+#if QT_VERSION < 0x050000
{ CutyCapt::RenderTreeFormat, ".rtree", "rtree" },
+#endif
{ CutyCapt::JpegFormat, ".jpeg", "jpeg" },
{ CutyCapt::PngFormat, ".png", "png" },
{ CutyCapt::MngFormat, ".mng", "mng" },
@@ -149,10 +161,13 @@ CutyPage::setAttribute(QWebSettings::WebAttribute option,
// TODO: Consider merging some of main() and CutyCap
CutyCapt::CutyCapt(CutyPage* page, const QString& output, int delay, OutputFormat format,
- const QString& scriptProp, const QString& scriptCode) {
+ const QString& scriptProp, const QString& scriptCode, bool insecure,
+ bool smooth) {
mPage = page;
mOutput = output;
mDelay = delay;
+ mInsecure = insecure;
+ mSmooth = smooth;
mSawInitialLayout = false;
mSawDocumentComplete = false;
mFormat = format;
@@ -226,6 +241,15 @@ CutyCapt::Delayed() {
}
void
+CutyCapt::handleSslErrors(QNetworkReply* reply, QList<QSslError> errors) {
+ if (mInsecure) {
+ reply->ignoreSslErrors();
+ } else {
+ // TODO: what to do here instead of hanging?
+ }
+}
+
+void
CutyCapt::saveSnapshot() {
QWebFrame *mainFrame = mPage->mainFrame();
QPainter painter;
@@ -265,15 +289,23 @@ CutyCapt::saveSnapshot() {
mainFrame->print(&printer);
break;
}
- case RenderTreeFormat:
+#if QT_VERSION < 0x050000
+ case RenderTreeFormat: {
+ QFile file(mOutput);
+ file.open(QIODevice::WriteOnly | QIODevice::Text);
+ QTextStream s(&file);
+ s.setCodec("utf-8");
+ s << mainFrame->renderTreeDump();
+ break;
+ }
+#endif
case InnerTextFormat:
case HtmlFormat: {
QFile file(mOutput);
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream s(&file);
s.setCodec("utf-8");
- s << (mFormat == RenderTreeFormat ? mainFrame->renderTreeDump() :
- mFormat == InnerTextFormat ? mainFrame->toPlainText() :
+ s << (mFormat == InnerTextFormat ? mainFrame->toPlainText() :
mFormat == HtmlFormat ? mainFrame->toHtml() :
"bug");
break;
@@ -281,6 +313,14 @@ CutyCapt::saveSnapshot() {
default: {
QImage image(mPage->viewportSize(), QImage::Format_ARGB32);
painter.begin(&image);
+#if QT_VERSION >= 0x050000
+ if (mSmooth) {
+ painter.setRenderHint(QPainter::SmoothPixmapTransform);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.setRenderHint(QPainter::TextAntialiasing);
+ painter.setRenderHint(QPainter::HighQualityAntialiasing);
+ }
+#endif
mainFrame->render(&painter);
painter.end();
// TODO: add quality
@@ -333,6 +373,10 @@ CaptHelp(void) {
" --expect-alert=<string> Try waiting for alert(string) before capture \n"
" --debug-print-alerts Prints out alert(...) strings for debugging. \n"
#endif
+#if QT_VERSION >= 0x050000
+ " --smooth Attempt to enable Qt's high-quality settings.\n"
+#endif
+ " --insecure Ignore SSL/TLS certificate errors \n"
" -----------------------------------------------------------------------------\n"
" <f> is svg,ps,pdf,itext,html,rtree,png,jpeg,mng,tiff,gif,bmp,ppm,xbm,xpm \n"
" -----------------------------------------------------------------------------\n"
@@ -347,7 +391,7 @@ CaptHelp(void) {
" This an experimental and easily abused and misused feature. Use with caution.\n"
" -----------------------------------------------------------------------------\n"
#endif
- " http://cutycapt.sf.net - (c) 2003-2010 Bjoern Hoehrmann - [email protected]\n"
+ " http://cutycapt.sf.net - (c) 2003-2013 Bjoern Hoehrmann - [email protected]\n"
"");
}
@@ -357,11 +401,13 @@ main(int argc, char *argv[]) {
int argHelp = 0;
int argDelay = 0;
int argSilent = 0;
+ int argInsecure = 0;
int argMinWidth = 800;
int argMinHeight = 600;
int argMaxWait = 90000;
int argVerbosity = 0;
-
+ int argSmooth = 0;
+
const char* argUrl = NULL;
const char* argUserStyle = NULL;
const char* argUserStylePath = NULL;
@@ -402,6 +448,16 @@ main(int argc, char *argv[]) {
argVerbosity++;
continue;
+ } else if (strcmp("--insecure", s) == 0) {
+ argInsecure = 1;
+ continue;
+
+#if QT_VERSION >= 0x050000
+ } else if (strcmp("--smooth", s) == 0) {
+ argSmooth = 1;
+ continue;
+#endif
+
#if CUTYCAPT_SCRIPT
} else if (strcmp("--debug-print-alerts", s) == 0) {
page.setPrintAlerts(true);
@@ -594,7 +650,8 @@ main(int argc, char *argv[]) {
}
}
- CutyCapt main(&page, argOut, argDelay, format, scriptProp, scriptCode);
+ CutyCapt main(&page, argOut, argDelay, format, scriptProp, scriptCode,
+ !!argInsecure, !!argSmooth);
app.connect(&page,
SIGNAL(loadFinished(bool)),
@@ -648,6 +705,11 @@ main(int argc, char *argv[]) {
SLOT(JavaScriptWindowObjectCleared()));
#endif
+ app.connect(page.networkAccessManager(),
+ SIGNAL(sslErrors(QNetworkReply*, QList<QSslError>)),
+ &main,
+ SLOT(handleSslErrors(QNetworkReply*, QList<QSslError>)));
+
if (!body.isNull())
page.mainFrame()->load(req, method, body);
else
diff --git a/CutyCapt.hpp b/CutyCapt.hpp
index b7c26eb..15f3864 100644
--- a/CutyCapt.hpp
+++ b/CutyCapt.hpp
@@ -1,5 +1,9 @@
#include <QtWebKit>
+#if QT_VERSION >= 0x050000
+#include <QtWebKitWidgets>
+#endif
+
class CutyCapt;
class CutyPage : public QWebPage {
Q_OBJECT
@@ -40,7 +44,9 @@ public:
int delay,
OutputFormat format,
const QString& scriptProp,
- const QString& scriptCode);
+ const QString& scriptCode,
+ bool insecure,
+ bool smooth);
private slots:
void DocumentComplete(bool ok);
@@ -48,6 +54,7 @@ private slots:
void JavaScriptWindowObjectCleared();
void Timeout();
void Delayed();
+ void handleSslErrors(QNetworkReply* reply, QList<QSslError> errors);
private:
void TryDelayedRender();
@@ -63,4 +70,6 @@ protected:
QObject* mScriptObj;
QString mScriptProp;
QString mScriptCode;
+ bool mInsecure;
+ bool mSmooth;
};
diff --git a/CutyCapt.pro b/CutyCapt.pro
index 5064a20..10dda79 100644
--- a/CutyCapt.pro
+++ b/CutyCapt.pro
@@ -3,6 +3,10 @@ SOURCES = CutyCapt.cpp
HEADERS = CutyCapt.hpp
CONFIG += qt console
+greaterThan(QT_MAJOR_VERSION, 4): {
+ QT += webkitwidgets
+}
+
contains(CONFIG, static): {
QTPLUGIN += qjpeg qgif qsvg qmng qico qtiff
DEFINES += STATIC_PLUGINS