Merge pull request #272 from detro/master

Minor adjustments before 1.6
1.6
Ariya Hidayat 2012-06-17 22:20:12 -07:00
commit 37cfc05a9b
3 changed files with 35 additions and 27 deletions

View File

@ -50,6 +50,7 @@
#include <QMapIterator> #include <QMapIterator>
#include <QBuffer> #include <QBuffer>
#include <QDebug> #include <QDebug>
#include <QImageWriter>
#include "networkaccessmanager.h" #include "networkaccessmanager.h"
#include "utils.h" #include "utils.h"
@ -84,6 +85,8 @@ public:
} }
bool extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output) { bool extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output) {
Q_UNUSED(option);
if (extension == ChooseMultipleFilesExtension) { if (extension == ChooseMultipleFilesExtension) {
static_cast<ChooseMultipleFilesExtensionReturn*>(output)->fileNames = QStringList(m_uploadFile); static_cast<ChooseMultipleFilesExtensionReturn*>(output)->fileNames = QStringList(m_uploadFile);
return true; return true;
@ -612,34 +615,27 @@ bool WebPage::render(const QString &fileName)
return buffer.save(fileName); return buffer.save(fileName);
} }
QString WebPage::renderBase64PNG() QString WebPage::renderBase64(const QByteArray &format)
{ {
return renderBase64("PNG"); QByteArray nformat = format.toLower();
}
QString WebPage::renderBase64JPG() // Check if the given format is supported
{ if (QImageWriter::supportedImageFormats().contains(nformat)) {
return renderBase64("JPG"); QImage rawPageRendering = renderImage();
}
QString WebPage::renderBase64BMP() // Prepare buffer for writing
{ QByteArray bytes;
return renderBase64("BMP"); QBuffer buffer(&bytes);
} buffer.open(QIODevice::WriteOnly);
QString WebPage::renderBase64(const char *format) // Writing image to the buffer, using PNG encoding
{ rawPageRendering.save(&buffer, nformat);
QImage rawPageRendering = renderImage();
// Prepare buffer for writing return bytes.toBase64();
QByteArray bytes; }
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
// Writing image to the buffer, using PNG encoding // Return an empty string in case an unsupported format was provided
rawPageRendering.save(&buffer, format); return "";
return bytes.toBase64();
} }
QImage WebPage::renderImage() QImage WebPage::renderImage()

View File

@ -113,9 +113,19 @@ public slots:
QVariant evaluateJavaScript(const QString &code); QVariant evaluateJavaScript(const QString &code);
bool render(const QString &fileName); bool render(const QString &fileName);
QString renderBase64PNG(); /**
QString renderBase64JPG(); * Render the page as base-64 encoded string.
QString renderBase64BMP(); * Default image format is "png".
*
* To choose a different format, pass a string with it's name.
* Available formats are the one supported by Qt QImageWriter class:
* @link http://qt-project.org/doc/qt-4.8/qimagewriter.html#supportedImageFormats.
*
* @brief renderBase64
* @param format String containing one of the supported types
* @return Rendering base-64 encoded of the page if the given format is supported, otherwise an empty string
*/
QString renderBase64(const QByteArray &format = "png");
bool injectJs(const QString &jsFilePath); bool injectJs(const QString &jsFilePath);
void _appendScriptElement(const QString &scriptUrl); void _appendScriptElement(const QString &scriptUrl);
QObject *_getGenericCallback(); QObject *_getGenericCallback();
@ -191,7 +201,6 @@ private slots:
private: private:
QImage renderImage(); QImage renderImage();
QString renderBase64(const char *format = "PNG");
bool renderPdf(const QString &fileName); bool renderPdf(const QString &fileName);
void applySettings(const QVariantMap &defaultSettings); void applySettings(const QVariantMap &defaultSettings);
QString userAgent() const; QString userAgent() const;

View File

@ -53,8 +53,11 @@ function expectHasPropertyString(o, name) {
}); });
} }
// Load specs // Setting the "working directory" to the "/test" directory
var fs = require('fs'); var fs = require('fs');
fs.changeWorkingDirectory(phantom.libraryPath);
// Load specs
phantom.injectJs("./phantom-spec.js"); phantom.injectJs("./phantom-spec.js");
phantom.injectJs("./module-spec.js"); phantom.injectJs("./module-spec.js");
phantom.injectJs("./webpage-spec.js"); phantom.injectJs("./webpage-spec.js");