author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
#include "qengines.h" |
|
42 |
#include "paintcommands.h" |
|
43 |
||
44 |
#include <QApplication> |
|
45 |
#include <QProcess> |
|
46 |
#include <QPainter> |
|
47 |
#include <QSvgRenderer> |
|
48 |
#include <QStringList> |
|
49 |
#include <QDir> |
|
50 |
#include <QDebug> |
|
51 |
#include <QPrintEngine> |
|
52 |
#include <QWidget> |
|
53 |
||
54 |
// For QApplicationPrivate::graphics_system_name |
|
55 |
#include <private/qapplication_p.h> |
|
56 |
||
57 |
QEngine::~QEngine() |
|
58 |
{ |
|
59 |
} |
|
60 |
||
61 |
Q_GLOBAL_STATIC(QtEngines, qtengines_global) |
|
62 |
QtEngines * QtEngines::self() |
|
63 |
{ |
|
64 |
return qtengines_global(); |
|
65 |
} |
|
66 |
||
67 |
||
68 |
QList<QEngine*> QtEngines::engines() const |
|
69 |
{ |
|
70 |
return m_engines; |
|
71 |
} |
|
72 |
||
73 |
||
74 |
QList<QEngine*> QtEngines::foreignEngines() const |
|
75 |
{ |
|
76 |
return m_foreignEngines; |
|
77 |
} |
|
78 |
||
79 |
||
80 |
QEngine * QtEngines::defaultEngine() const |
|
81 |
{ |
|
82 |
return m_defaultEngine; |
|
83 |
} |
|
84 |
||
85 |
||
86 |
QtEngines::QtEngines() |
|
87 |
{ |
|
88 |
init(); |
|
89 |
} |
|
90 |
||
91 |
||
92 |
void QtEngines::init() |
|
93 |
{ |
|
94 |
m_defaultEngine = new RasterEngine; |
|
95 |
m_engines << m_defaultEngine |
|
96 |
<< new NativeEngine |
|
97 |
<< new WidgetEngine; |
|
98 |
||
99 |
#if defined(BUILD_OPENGL) |
|
100 |
if (QGLFormat::hasOpenGL()) |
|
101 |
m_engines << new GLEngine; |
|
102 |
#endif |
|
103 |
||
104 |
#ifndef QT_NO_PRINTER |
|
105 |
m_engines << new PDFEngine |
|
106 |
#ifdef Q_WS_X11 |
|
107 |
<< new PSEngine |
|
108 |
#endif |
|
109 |
#ifdef Q_WS_WIN |
|
110 |
<< new WinPrintEngine |
|
111 |
#endif |
|
112 |
; |
|
113 |
#endif //QT_NO_PRINTER |
|
114 |
||
115 |
m_foreignEngines << new RSVGEngine; |
|
116 |
} |
|
117 |
||
118 |
RasterEngine::RasterEngine() |
|
119 |
{ |
|
120 |
||
121 |
} |
|
122 |
||
123 |
QString RasterEngine::name() const |
|
124 |
{ |
|
125 |
return QLatin1String("Raster"); |
|
126 |
} |
|
127 |
||
128 |
||
129 |
void RasterEngine::prepare(const QSize &size, const QColor &fillColor) |
|
130 |
{ |
|
131 |
image = QImage(size, QImage::Format_ARGB32_Premultiplied); |
|
132 |
QPainter p(&image); |
|
133 |
p.setCompositionMode(QPainter::CompositionMode_Source); |
|
134 |
p.fillRect(image.rect(), fillColor); |
|
135 |
} |
|
136 |
||
137 |
||
138 |
void RasterEngine::render(QSvgRenderer *r, const QString &) |
|
139 |
{ |
|
140 |
QPainter p(&image); |
|
141 |
r->render(&p); |
|
142 |
p.end(); |
|
143 |
} |
|
144 |
||
145 |
||
146 |
void RasterEngine::render(const QStringList &qpsScript, |
|
147 |
const QString &absFilePath) |
|
148 |
{ |
|
149 |
QPainter pt(&image); |
|
150 |
PaintCommands pcmd(qpsScript, 800, 800); |
|
151 |
pcmd.setPainter(&pt); |
|
152 |
pcmd.setFilePath(absFilePath); |
|
153 |
pcmd.runCommands(); |
|
154 |
pt.end(); |
|
155 |
} |
|
156 |
||
157 |
bool RasterEngine::drawOnPainter(QPainter *p) |
|
158 |
{ |
|
159 |
p->drawImage(0, 0, image); |
|
160 |
return true; |
|
161 |
} |
|
162 |
||
163 |
void RasterEngine::save(const QString &file) |
|
164 |
{ |
|
165 |
image.save(file, "PNG"); |
|
166 |
} |
|
167 |
||
168 |
||
169 |
NativeEngine::NativeEngine() |
|
170 |
{ |
|
171 |
||
172 |
} |
|
173 |
||
174 |
||
175 |
QString NativeEngine::name() const |
|
176 |
{ |
|
177 |
#ifdef Q_WS_X11 |
|
178 |
#ifndef QT_NO_XRENDER |
|
179 |
return QLatin1String("NativeXRender"); |
|
180 |
#else |
|
181 |
return QLatin1String("NativeXLib"); |
|
182 |
#endif |
|
183 |
#elif (defined Q_WS_WIN32) |
|
184 |
return QLatin1String("NativeWin32"); |
|
185 |
#elif (defined Q_WS_MAC) |
|
186 |
return QLatin1String("NativeMac"); |
|
187 |
#elif defined(Q_WS_QWS) |
|
188 |
return QLatin1String("NativeEmbedded"); |
|
189 |
#endif |
|
190 |
} |
|
191 |
||
192 |
||
193 |
void NativeEngine::prepare(const QSize &size, const QColor &fillColor) |
|
194 |
{ |
|
195 |
pixmap = QPixmap(size); |
|
196 |
pixmap.fill(fillColor); |
|
197 |
} |
|
198 |
||
199 |
||
200 |
void NativeEngine::render(QSvgRenderer *r, const QString &) |
|
201 |
{ |
|
202 |
QPainter p(&pixmap); |
|
203 |
r->render(&p); |
|
204 |
p.end(); |
|
205 |
} |
|
206 |
||
207 |
||
208 |
void NativeEngine::render(const QStringList &qpsScript, |
|
209 |
const QString &absFilePath) |
|
210 |
{ |
|
211 |
QPainter pt(&pixmap); |
|
212 |
PaintCommands pcmd(qpsScript, 800, 800); |
|
213 |
pcmd.setPainter(&pt); |
|
214 |
pcmd.setFilePath(absFilePath); |
|
215 |
pcmd.runCommands(); |
|
216 |
pt.end(); |
|
217 |
} |
|
218 |
||
219 |
bool NativeEngine::drawOnPainter(QPainter *p) |
|
220 |
{ |
|
221 |
p->drawPixmap(0, 0, pixmap); |
|
222 |
return true; |
|
223 |
} |
|
224 |
||
225 |
void NativeEngine::save(const QString &file) |
|
226 |
{ |
|
227 |
pixmap.save(file, "PNG"); |
|
228 |
} |
|
229 |
||
230 |
||
231 |
#if defined(BUILD_OPENGL) |
|
232 |
GLEngine::GLEngine() |
|
233 |
: pbuffer(0), widget(0) |
|
234 |
{ |
|
235 |
usePixelBuffers = QGLPixelBuffer::hasOpenGLPbuffers(); |
|
236 |
} |
|
237 |
||
238 |
||
239 |
QString GLEngine::name() const |
|
240 |
{ |
|
241 |
return QLatin1String("OpenGL"); |
|
242 |
} |
|
243 |
||
244 |
void GLEngine::prepare(const QSize &_size, const QColor &color) |
|
245 |
{ |
|
246 |
size = _size; |
|
247 |
fillColor = color; |
|
248 |
if (usePixelBuffers) { |
|
249 |
pbuffer = new QGLPixelBuffer(size, QGLFormat(QGL::SampleBuffers)); |
|
250 |
} else { |
|
251 |
widget = new QGLWidget(QGLFormat(QGL::SampleBuffers)); |
|
252 |
widget->setAutoFillBackground(false); |
|
253 |
widget->resize(size); |
|
254 |
widget->show(); |
|
255 |
QApplication::flush(); |
|
256 |
QApplication::syncX(); |
|
257 |
} |
|
258 |
} |
|
259 |
||
260 |
void GLEngine::render(QSvgRenderer *r, const QString &) |
|
261 |
{ |
|
262 |
QPainter *p; |
|
263 |
if (usePixelBuffers) |
|
264 |
p = new QPainter(pbuffer); |
|
265 |
else |
|
266 |
p = new QPainter(widget); |
|
267 |
p->fillRect(0, 0, size.width(), size.height(), fillColor); |
|
268 |
r->render(p); |
|
269 |
p->end(); |
|
270 |
delete p; |
|
271 |
} |
|
272 |
||
273 |
void GLEngine::render(const QStringList &qpsScript, |
|
274 |
const QString &absFilePath) |
|
275 |
{ |
|
276 |
QPainter *p; |
|
277 |
if (usePixelBuffers) |
|
278 |
p = new QPainter(pbuffer); |
|
279 |
else |
|
280 |
p = new QPainter(widget); |
|
281 |
||
282 |
PaintCommands pcmd(qpsScript, 800, 800); |
|
283 |
pcmd.setPainter(p); |
|
284 |
pcmd.setFilePath(absFilePath); |
|
285 |
pcmd.runCommands(); |
|
286 |
p->end(); |
|
287 |
delete p; |
|
288 |
} |
|
289 |
||
290 |
bool GLEngine::drawOnPainter(QPainter *p) |
|
291 |
{ |
|
292 |
if (usePixelBuffers) { |
|
293 |
QImage img = pbuffer->toImage(); |
|
294 |
p->drawImage(0, 0, img); |
|
295 |
} else { |
|
296 |
QImage img = widget->grabFrameBuffer(); |
|
297 |
p->drawImage(0, 0, img); |
|
298 |
} |
|
299 |
return true; |
|
300 |
} |
|
301 |
||
302 |
||
303 |
void GLEngine::save(const QString &file) |
|
304 |
{ |
|
305 |
if (usePixelBuffers) { |
|
306 |
QImage img = pbuffer->toImage(); |
|
307 |
img.save(file, "PNG"); |
|
308 |
} else { |
|
309 |
QImage img = widget->grabFrameBuffer(); |
|
310 |
img.save(file, "PNG"); |
|
311 |
} |
|
312 |
} |
|
313 |
||
314 |
void GLEngine::cleanup() |
|
315 |
{ |
|
316 |
delete pbuffer; |
|
317 |
delete widget; |
|
318 |
} |
|
319 |
||
320 |
#endif |
|
321 |
||
322 |
class WidgetEngineWidget : public QWidget |
|
323 |
{ |
|
324 |
public: |
|
325 |
WidgetEngineWidget(QWidget* =0); |
|
326 |
||
327 |
void paintEvent(QPaintEvent*); |
|
328 |
void render(QSvgRenderer*); |
|
329 |
void render(QStringList const&,QString const&); |
|
330 |
||
331 |
QSize m_size; |
|
332 |
QColor m_fillColor; |
|
333 |
||
334 |
private: |
|
335 |
QSvgRenderer* m_svgr; |
|
336 |
QStringList m_qpsScript; |
|
337 |
QString m_absFilePath; |
|
338 |
}; |
|
339 |
||
340 |
WidgetEngineWidget::WidgetEngineWidget(QWidget* parent) |
|
341 |
: QWidget(parent) |
|
342 |
, m_size() |
|
343 |
, m_fillColor() |
|
344 |
, m_svgr(0) |
|
345 |
, m_qpsScript() |
|
346 |
, m_absFilePath() |
|
347 |
{} |
|
348 |
||
349 |
void WidgetEngineWidget::render(QSvgRenderer* r) |
|
350 |
{ |
|
351 |
m_svgr = r; |
|
352 |
repaint(); |
|
353 |
m_svgr = 0; |
|
354 |
} |
|
355 |
||
356 |
void WidgetEngineWidget::render(QStringList const& qpsScript, QString const& absFilePath) |
|
357 |
{ |
|
358 |
m_qpsScript = qpsScript; |
|
359 |
m_absFilePath = absFilePath; |
|
360 |
repaint(); |
|
361 |
m_qpsScript = QStringList(); |
|
362 |
m_absFilePath = QString(); |
|
363 |
} |
|
364 |
||
365 |
void WidgetEngineWidget::paintEvent(QPaintEvent*) |
|
366 |
{ |
|
367 |
if (m_svgr) { |
|
368 |
QPainter p(this); |
|
369 |
p.fillRect(0, 0, m_size.width(), m_size.height(), m_fillColor); |
|
370 |
m_svgr->render(&p); |
|
371 |
p.end(); |
|
372 |
} |
|
373 |
else { |
|
374 |
QPainter p(this); |
|
375 |
||
376 |
PaintCommands pcmd(m_qpsScript, 800, 800); |
|
377 |
pcmd.setPainter(&p); |
|
378 |
pcmd.setFilePath(m_absFilePath); |
|
379 |
pcmd.runCommands(); |
|
380 |
p.end(); |
|
381 |
} |
|
382 |
} |
|
383 |
||
384 |
WidgetEngine::WidgetEngine() |
|
385 |
: m_widget(0) |
|
386 |
{ |
|
387 |
} |
|
388 |
||
389 |
||
390 |
QString WidgetEngine::name() const |
|
391 |
{ |
|
392 |
QString gs = QApplicationPrivate::graphics_system_name; |
|
393 |
if (!gs.isEmpty()) gs[0] = gs[0].toUpper(); |
|
394 |
return QString::fromLatin1("Widget") + gs; |
|
395 |
} |
|
396 |
||
397 |
void WidgetEngine::prepare(const QSize &size, const QColor &color) |
|
398 |
{ |
|
399 |
m_widget = new WidgetEngineWidget; |
|
400 |
m_widget->m_size = size; |
|
401 |
m_widget->m_fillColor = color; |
|
402 |
m_widget->setAutoFillBackground(false); |
|
403 |
m_widget->resize(size); |
|
404 |
m_widget->show(); |
|
405 |
QApplication::flush(); |
|
406 |
QApplication::syncX(); |
|
407 |
} |
|
408 |
||
409 |
void WidgetEngine::render(QSvgRenderer *r, const QString &) |
|
410 |
{ |
|
411 |
m_widget->render(r); |
|
412 |
} |
|
413 |
||
414 |
void WidgetEngine::render(const QStringList &qpsScript, |
|
415 |
const QString &absFilePath) |
|
416 |
{ |
|
417 |
m_widget->render(qpsScript, absFilePath); |
|
418 |
} |
|
419 |
||
420 |
bool WidgetEngine::drawOnPainter(QPainter *p) |
|
421 |
{ |
|
422 |
p->drawPixmap(0, 0, QPixmap::grabWindow(m_widget->winId())); |
|
423 |
return true; |
|
424 |
} |
|
425 |
||
426 |
||
427 |
void WidgetEngine::save(const QString &file) |
|
428 |
{ |
|
429 |
QImage img = QPixmap::grabWindow(m_widget->winId()).toImage(); |
|
430 |
img.save(file, "PNG"); |
|
431 |
} |
|
432 |
||
433 |
void WidgetEngine::cleanup() |
|
434 |
{ |
|
435 |
delete m_widget; |
|
436 |
} |
|
437 |
||
438 |
#ifndef QT_NO_PRINTER |
|
439 |
PDFEngine::PDFEngine() |
|
440 |
{ |
|
441 |
} |
|
442 |
||
443 |
||
444 |
QString PDFEngine::name() const |
|
445 |
{ |
|
446 |
return QLatin1String("PDF"); |
|
447 |
} |
|
448 |
||
449 |
void PDFEngine::prepare(const QSize &size, const QColor &fillColor) |
|
450 |
{ |
|
451 |
Q_UNUSED(fillColor); |
|
452 |
||
453 |
static int i = 1; |
|
454 |
||
455 |
m_size = size; |
|
456 |
printer = new QPrinter(QPrinter::ScreenResolution); |
|
457 |
printer->setOutputFormat(QPrinter::PdfFormat); |
|
458 |
printer->setFullPage(true); |
|
459 |
//printer->setOrientation(QPrinter::Landscape); |
|
460 |
m_tempFile = QDir::tempPath() + QString("temp%1.pdf").arg(i++); |
|
461 |
printer->setOutputFileName(m_tempFile); |
|
462 |
} |
|
463 |
||
464 |
void PDFEngine::render(QSvgRenderer *r, const QString &) |
|
465 |
{ |
|
466 |
QPainter p(printer); |
|
467 |
r->render(&p); |
|
468 |
p.end(); |
|
469 |
} |
|
470 |
||
471 |
||
472 |
void PDFEngine::render(const QStringList &qpsScript, |
|
473 |
const QString &absFilePath) |
|
474 |
{ |
|
475 |
QPainter pt(printer); |
|
476 |
PaintCommands pcmd(qpsScript, 800, 800); |
|
477 |
pcmd.setPainter(&pt); |
|
478 |
pcmd.setFilePath(absFilePath); |
|
479 |
pcmd.runCommands(); |
|
480 |
pt.end(); |
|
481 |
} |
|
482 |
||
483 |
bool PDFEngine::drawOnPainter(QPainter *) |
|
484 |
{ |
|
485 |
return false; |
|
486 |
} |
|
487 |
||
488 |
void PDFEngine::save(const QString &file) |
|
489 |
{ |
|
490 |
#ifdef USE_ACROBAT |
|
491 |
QString psFile = m_tempFile; |
|
492 |
psFile.replace(".pdf", ".ps"); |
|
493 |
QProcess toPs; |
|
494 |
QStringList args1; |
|
495 |
args1 << "-toPostScript" |
|
496 |
<< "-level3" |
|
497 |
<< "-transQuality" |
|
498 |
<< "1"; |
|
499 |
args1 << m_tempFile; |
|
500 |
toPs.start("acroread", args1); |
|
501 |
toPs.waitForFinished(); |
|
502 |
||
503 |
QProcess convert; |
|
504 |
QStringList args; |
|
505 |
args << psFile; |
|
506 |
args << QString("-resize") |
|
507 |
<< QString("%1x%2") |
|
508 |
.arg(m_size.width()) |
|
509 |
.arg(m_size.height()); |
|
510 |
args << file; |
|
511 |
||
512 |
convert.start("convert", args); |
|
513 |
convert.waitForFinished(); |
|
514 |
QFile::remove(psFile); |
|
515 |
#else |
|
516 |
QProcess toPng; |
|
517 |
QStringList args1; |
|
518 |
args1 << "-sDEVICE=png16m" |
|
519 |
<< QString("-sOutputFile=") + file |
|
520 |
<< "-r97x69" |
|
521 |
<< "-dBATCH" |
|
522 |
<< "-dNOPAUSE"; |
|
523 |
args1 << m_tempFile; |
|
524 |
toPng.start("gs", args1); |
|
525 |
toPng.waitForFinished(); |
|
526 |
#endif |
|
527 |
||
528 |
QString pfile = file; |
|
529 |
pfile.replace(".png", ".pdf"); |
|
530 |
QFile::rename(m_tempFile, pfile); |
|
531 |
// QFile::remove(m_tempFile); |
|
532 |
} |
|
533 |
||
534 |
void PDFEngine::cleanup() |
|
535 |
{ |
|
536 |
delete printer; printer = 0; |
|
537 |
} |
|
538 |
||
539 |
#ifdef Q_WS_X11 |
|
540 |
PSEngine::PSEngine() |
|
541 |
{ |
|
542 |
} |
|
543 |
||
544 |
||
545 |
QString PSEngine::name() const |
|
546 |
{ |
|
547 |
return QLatin1String("PS"); |
|
548 |
} |
|
549 |
||
550 |
void PSEngine::prepare(const QSize &size, const QColor &fillColor) |
|
551 |
{ |
|
552 |
Q_UNUSED(fillColor); |
|
553 |
||
554 |
static int i = 1; |
|
555 |
||
556 |
m_size = size; |
|
557 |
printer = new QPrinter(QPrinter::ScreenResolution); |
|
558 |
printer->setOutputFormat(QPrinter::PostScriptFormat); |
|
559 |
printer->setFullPage(true); |
|
560 |
m_tempFile = QDir::tempPath() + QString("temp%1.ps").arg(i++); |
|
561 |
printer->setOutputFileName(m_tempFile); |
|
562 |
} |
|
563 |
||
564 |
void PSEngine::render(QSvgRenderer *r, const QString &) |
|
565 |
{ |
|
566 |
QPainter p(printer); |
|
567 |
r->render(&p); |
|
568 |
p.end(); |
|
569 |
} |
|
570 |
||
571 |
||
572 |
void PSEngine::render(const QStringList &qpsScript, |
|
573 |
const QString &absFilePath) |
|
574 |
{ |
|
575 |
QPainter pt(printer); |
|
576 |
PaintCommands pcmd(qpsScript, 800, 800); |
|
577 |
pcmd.setPainter(&pt); |
|
578 |
pcmd.setFilePath(absFilePath); |
|
579 |
pcmd.runCommands(); |
|
580 |
pt.end(); |
|
581 |
} |
|
582 |
||
583 |
bool PSEngine::drawOnPainter(QPainter *) |
|
584 |
{ |
|
585 |
return false; |
|
586 |
} |
|
587 |
||
588 |
void PSEngine::save(const QString &file) |
|
589 |
{ |
|
590 |
QProcess toPng; |
|
591 |
QStringList args1; |
|
592 |
args1 << "-sDEVICE=png16m" |
|
593 |
<< QString("-sOutputFile=") + file |
|
594 |
<< "-r97x69" |
|
595 |
<< "-dBATCH" |
|
596 |
<< "-dNOPAUSE"; |
|
597 |
args1 << m_tempFile; |
|
598 |
toPng.start("gs", args1); |
|
599 |
toPng.waitForFinished(); |
|
600 |
||
601 |
QString pfile = file; |
|
602 |
pfile.replace(".png", ".ps"); |
|
603 |
QFile::rename(m_tempFile, pfile); |
|
604 |
} |
|
605 |
||
606 |
void PSEngine::cleanup() |
|
607 |
{ |
|
608 |
delete printer; printer = 0; |
|
609 |
} |
|
610 |
#endif |
|
611 |
#endif //QT_NO_PRINTER |
|
612 |
||
613 |
RSVGEngine::RSVGEngine() |
|
614 |
{ |
|
615 |
||
616 |
} |
|
617 |
||
618 |
QString RSVGEngine::name() const |
|
619 |
{ |
|
620 |
return QLatin1String("RSVG"); |
|
621 |
} |
|
622 |
||
623 |
void RSVGEngine::prepare(const QSize &size, const QColor &fillColor) |
|
624 |
{ |
|
625 |
Q_UNUSED(fillColor); |
|
626 |
||
627 |
m_size = size; |
|
628 |
} |
|
629 |
||
630 |
void RSVGEngine::render(QSvgRenderer *, const QString &fileName) |
|
631 |
{ |
|
632 |
m_fileName = fileName; |
|
633 |
} |
|
634 |
||
635 |
void RSVGEngine::render(const QStringList &, const QString &) |
|
636 |
{ |
|
637 |
} |
|
638 |
||
639 |
bool RSVGEngine::drawOnPainter(QPainter *) |
|
640 |
{ |
|
641 |
return false; |
|
642 |
} |
|
643 |
||
644 |
||
645 |
void RSVGEngine::save(const QString &file) |
|
646 |
{ |
|
647 |
QProcess rsvg; |
|
648 |
QStringList args; |
|
649 |
args << QString("-w %1").arg(m_size.width()); |
|
650 |
args << QString("-h %1").arg(m_size.height()); |
|
651 |
args << m_fileName; |
|
652 |
args << file; |
|
653 |
rsvg.start("rsvg", args); |
|
654 |
rsvg.waitForFinished(); |
|
655 |
} |
|
656 |
||
657 |
void QEngine::cleanup() |
|
658 |
{ |
|
659 |
} |
|
660 |
||
661 |
#ifdef Q_WS_WIN |
|
662 |
WinPrintEngine::WinPrintEngine() |
|
663 |
{ |
|
664 |
} |
|
665 |
||
666 |
||
667 |
QString WinPrintEngine::name() const |
|
668 |
{ |
|
669 |
return QLatin1String("WinPrint"); |
|
670 |
} |
|
671 |
||
672 |
void WinPrintEngine::prepare(const QSize &size, const QColor &fillColor) |
|
673 |
{ |
|
674 |
Q_UNUSED(fillColor); |
|
675 |
||
676 |
static int i = 1; |
|
677 |
||
678 |
m_size = size; |
|
679 |
printer = new QPrinter(QPrinter::ScreenResolution); |
|
680 |
printer->setFullPage(true); |
|
681 |
printer->setPrinterName("HP 2500C Series PS3"); |
|
682 |
m_tempFile = QDir::tempPath() + QString("temp%1.ps").arg(i++); |
|
683 |
printer->setOutputFileName(m_tempFile); |
|
684 |
} |
|
685 |
||
686 |
void WinPrintEngine::render(QSvgRenderer *r, const QString &) |
|
687 |
{ |
|
688 |
QPainter p(printer); |
|
689 |
r->render(&p); |
|
690 |
p.end(); |
|
691 |
} |
|
692 |
||
693 |
||
694 |
void WinPrintEngine::render(const QStringList &qpsScript, |
|
695 |
const QString &absFilePath) |
|
696 |
{ |
|
697 |
QPainter pt(printer); |
|
698 |
PaintCommands pcmd(qpsScript, 800, 800); |
|
699 |
pcmd.setPainter(&pt); |
|
700 |
pcmd.setFilePath(absFilePath); |
|
701 |
pcmd.runCommands(); |
|
702 |
pt.end(); |
|
703 |
} |
|
704 |
||
705 |
bool WinPrintEngine::drawOnPainter(QPainter *) |
|
706 |
{ |
|
707 |
return false; |
|
708 |
} |
|
709 |
||
710 |
void WinPrintEngine::save(const QString &file) |
|
711 |
{ |
|
712 |
QProcess toPng; |
|
713 |
QStringList args1; |
|
714 |
args1 << "-sDEVICE=png16m" |
|
715 |
<< QString("-sOutputFile=") + file |
|
716 |
<< "-r97x69" |
|
717 |
<< "-dBATCH" |
|
718 |
<< "-dNOPAUSE"; |
|
719 |
args1 << m_tempFile; |
|
720 |
toPng.start("gswin32", args1); |
|
721 |
toPng.waitForFinished(); |
|
722 |
||
723 |
QString pfile = file; |
|
724 |
pfile.replace(".png", ".ps"); |
|
725 |
QFile::rename(m_tempFile, pfile); |
|
726 |
} |
|
727 |
||
728 |
void WinPrintEngine::cleanup() |
|
729 |
{ |
|
730 |
delete printer; printer = 0; |
|
731 |
} |
|
732 |
||
733 |
#endif |