source: wkhtmltox/trunk/fuentes/src/lib/image_c_bindings.cc @ 51

Last change on this file since 51 was 51, checked in by mabarracus, 4 years ago

wip

File size: 7.7 KB
Line 
1// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2// vi:set ts=4 sts=4 sw=4 noet :
3//
4// Copyright 2010 wkhtmltopdf authors
5//
6// This file is part of wkhtmltopdf.
7//
8// wkhtmltopdf is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Lesser General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12//
13// wkhtmltopdf is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public License
19// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
20
21/**
22 * \page pagesettings Setting
23 * \section pageImageGlobal Image settings
24 * The \ref wkhtmltoimage_global_settings structure contains the following settings:
25 * - \b crop.left left/x coordinate of the window to capture in pixels. E.g. "200"
26 * - \b crop.top top/y coordinate of the window to capture in pixels. E.g. "200"
27 * - \b crop.width Width of the window to capture in pixels. E.g. "200"
28 * - \b crop.height Height of the window to capture in pixels. E.g. "200"
29 * - \b load.cookieJar Path of file used to load and store cookies.
30 * - \b load.* Page specific settings related to loading content, see \ref pageLoad.
31 * - \b web.* See \ref pageWeb.
32 * - \b transparent When outputting a PNG or SVG, make the white background transparent.
33 *      Must be either "true" or "false"
34 * - \b in The URL or path of the input file, if "-" stdin is used. E.g. "http://google.com"
35 * - \b out The path of the output file, if "-" stdout is used, if empty the content is stored
36 *      to a internalBuffer.
37 * - \b fmt The output format to use, must be either "", "jpg", "png", "bmp" or "svg".
38 * - \b screenWidth The with of the screen used to render is pixels, e.g "800".
39 * - \b smartWidth Should we expand the screenWidth if the content does not fit?
40 *      must be either "true" or "false".
41 * - \b quality The compression factor to use when outputting a JPEG image. E.g. "94".
42 */
43
44
45#include "image_c_bindings_p.hh"
46#include "pdf.h"
47
48#include "dllbegin.inc"
49using namespace wkhtmltopdf;
50
51void MyImageConverter::warning(const QString & message) {
52        if (warning_cb) (warning_cb)(reinterpret_cast<wkhtmltoimage_converter*>(this), message.toUtf8().constData());
53}
54
55void MyImageConverter::error(const QString & message) {
56        if (error_cb) (error_cb)(reinterpret_cast<wkhtmltoimage_converter*>(this), message.toUtf8().constData());
57}
58
59void MyImageConverter::phaseChanged() {
60        if (phase_changed) (phase_changed)(reinterpret_cast<wkhtmltoimage_converter*>(this));
61}
62
63void MyImageConverter::progressChanged(int progress) {
64        if (progress_changed) (progress_changed)(reinterpret_cast<wkhtmltoimage_converter*>(this), progress);
65}
66
67void MyImageConverter::finished(bool ok) {
68        if (finished_cb) (finished_cb)(reinterpret_cast<wkhtmltoimage_converter*>(this), ok);
69}
70
71MyImageConverter::MyImageConverter(settings::ImageGlobal * gs, const QString * data):
72        warning_cb(0), error_cb(0), phase_changed(0), progress_changed(0), finished_cb(0),
73        converter(*gs, data), globalSettings(gs) {
74
75    connect(&converter, SIGNAL(warning(const QString &)), this, SLOT(warning(const QString &)));
76        connect(&converter, SIGNAL(error(const QString &)), this, SLOT(error(const QString &)));
77        connect(&converter, SIGNAL(phaseChanged()), this, SLOT(phaseChanged()));
78        connect(&converter, SIGNAL(progressChanged(int)), this, SLOT(progressChanged(int)));
79        connect(&converter, SIGNAL(finished(bool)), this, SLOT(finished(bool)));
80}
81
82MyImageConverter::~MyImageConverter() {
83        delete globalSettings;
84}
85
86CAPI(int) wkhtmltoimage_extended_qt() {
87        return wkhtmltopdf_extended_qt();
88}
89
90CAPI(const char *) wkhtmltoimage_version() {
91        return "NOT IMPLEMENTED";
92}
93
94CAPI(int) wkhtmltoimage_init(int use_graphics) {
95        return wkhtmltopdf_init(use_graphics);
96}
97
98CAPI(int) wkhtmltoimage_deinit() {
99        return wkhtmltopdf_deinit();
100}
101
102CAPI(wkhtmltoimage_global_settings *) wkhtmltoimage_create_global_settings() {
103        return reinterpret_cast<wkhtmltoimage_global_settings *>(new settings::ImageGlobal());
104}
105
106CAPI(int) wkhtmltoimage_set_global_setting(wkhtmltoimage_global_settings * settings, const char * name, const char * value) {
107        return reinterpret_cast<settings::ImageGlobal *>(settings)->set(name, value);
108}
109
110CAPI(int) wkhtmltoimage_get_global_setting(wkhtmltoimage_global_settings * settings, const char * name, char * value, int vs) {
111        QString res = reinterpret_cast<settings::ImageGlobal *>(settings)->get(name);
112        if (res.isNull()) return 0;
113        qstrncpy(value, res.toUtf8().constData(), vs);
114        return 1;
115}
116
117CAPI(wkhtmltoimage_converter *) wkhtmltoimage_create_converter(wkhtmltoimage_global_settings * settings, const char * data) {
118        QString str= QString::fromUtf8(data);
119        return reinterpret_cast<wkhtmltoimage_converter *>(
120                new MyImageConverter(reinterpret_cast<settings::ImageGlobal *>(settings), &str));
121}
122
123CAPI(void) wkhtmltoimage_destroy_converter(wkhtmltoimage_converter * converter) {
124        delete reinterpret_cast<MyImageConverter *>(converter);
125}
126
127CAPI(void) wkhtmltoimage_set_warning_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_str_callback cb) {
128        reinterpret_cast<MyImageConverter *>(converter)->warning_cb = cb;
129}
130
131CAPI(void) wkhtmltoimage_set_error_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_str_callback cb) {
132        reinterpret_cast<MyImageConverter *>(converter)->error_cb = cb;
133}
134
135CAPI(void) wkhtmltoimage_set_phase_changed_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_void_callback cb) {
136        reinterpret_cast<MyImageConverter *>(converter)->phase_changed = cb;
137}
138
139CAPI(void) wkhtmltoimage_set_progress_changed_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_int_callback cb) {
140        reinterpret_cast<MyImageConverter *>(converter)->progress_changed = cb;
141}
142
143CAPI(void) wkhtmltoimage_set_finished_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_int_callback cb) {
144        reinterpret_cast<MyImageConverter *>(converter)->finished_cb = cb;
145}
146
147/*CAPI(void) wkhtmltoimage_begin_conversion(wkhtmltoimage_converter * converter) {
148        reinterpret_cast<MyImageConverter *>(converter)->converter.beginConversion();
149        }*/
150
151CAPI(int) wkhtmltoimage_convert(wkhtmltoimage_converter * converter) {
152        return reinterpret_cast<MyImageConverter *>(converter)->converter.convert();
153}
154
155/*CAPI(void) wkhtmltoimage_cancel(wkhtmltoimage_converter * converter) {
156        reinterpret_cast<MyImageConverter *>(converter)->converter.cancel();
157        }*/
158
159CAPI(int) wkhtmltoimage_current_phase(wkhtmltoimage_converter * converter) {
160        return reinterpret_cast<MyImageConverter *>(converter)->converter.currentPhase();
161}
162
163CAPI(int) wkhtmltoimage_phase_count(wkhtmltoimage_converter * converter) {
164        return reinterpret_cast<MyImageConverter *>(converter)->converter.phaseCount();
165}
166
167CAPI(const char *) wkhtmltoimage_phase_description(wkhtmltoimage_converter * converter, int phase) {
168        return reinterpret_cast<MyImageConverter *>(converter)->converter.phaseDescription(phase).toUtf8().constData();
169}
170
171CAPI(const char *) wkhtmltoimage_progress_string(wkhtmltoimage_converter * converter) {
172        return reinterpret_cast<MyImageConverter *>(converter)->converter.progressString().toUtf8().constData();
173}
174
175CAPI(int) wkhtmltoimage_http_error_code(wkhtmltoimage_converter * converter) {
176        return reinterpret_cast<MyImageConverter *>(converter)->converter.httpErrorCode();
177}
178
179CAPI(long) wkhtmltoimage_get_output(wkhtmltoimage_converter * converter, const unsigned char ** d) {
180        const QByteArray & out = reinterpret_cast<MyImageConverter *>(converter)->converter.output();
181        *d = (const unsigned char*)out.constData();
182        return out.size();
183}
Note: See TracBrowser for help on using the repository browser.