1
// --------------------------------------------------------------------
2
// Conversion to a bitmap
3
// --------------------------------------------------------------------
6
This file is part of the extensible drawing editor Ipe.
7
Copyright (C) 1993-2004 Otfried Cheong
9
Ipe is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
As a special exception, you have permission to link Ipe with the
15
CGAL library and distribute executables, as long as you follow the
16
requirements of the Gnu General Public License in regard to all of
17
the software in the executable aside from CGAL.
19
Ipe is distributed in the hope that it will be useful, but WITHOUT
20
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
22
License for more details.
24
You should have received a copy of the GNU General Public License
25
along with Ipe; if not, you can find it at
26
"http://www.gnu.org/copyleft/gpl.html", or write to the Free
27
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33
#include "ipepdfdoc.h"
34
#include "ipefilter.h"
35
#include "ipefontpool.h"
37
#include "ipecanvas.h"
43
// --------------------------------------------------------------------
45
class PaintServices : public IpeCanvasPaintServices {
47
PaintServices(const IpeFontPool *fp) : iFontPool(fp) { /* nothing */ }
48
virtual void CvSvcSetRenderData(IpeBitmap &bitmap);
49
virtual void CvSvcRenderCharacter(QPixmap *pixmap, int fontObject,
50
const IpeMatrix &m, const IpeVector &pos,
51
QRgb cRgb, uint charCode, uint uniCode);
53
const IpeFontPool *iFontPool;
56
void PaintServices::CvSvcSetRenderData(IpeBitmap &bitmap)
58
QImage img = IpeImageFilter::Decode(bitmap);
59
bitmap.SetRenderData(new QImage(img));
62
void PaintServices::CvSvcRenderCharacter(QPixmap *pixmap, int fontObject,
66
uint charCode, uint uniCode)
69
iFontPool->RenderCharacter(pixmap, fontObject, m, pos,
70
cRgb, charCode, uniCode);
73
// --------------------------------------------------------------------
75
QPixmap toPng(const IpePdfDocument *doc, const IpePage *page,
78
IpeBBoxPainter bboxPainter(doc->StyleSheet());
79
for (IpePage::const_iterator it = page->begin(); it != page->end(); ++it) {
80
if (page->Layer(it->Layer()).IsVisible())
81
it->Object()->Draw(bboxPainter);
84
IpeRect bbox = bboxPainter.BBox();
85
int wid = int(bbox.Width() * zoom);
86
int ht = int(bbox.Height() * zoom);
87
QPixmap pixmap(wid, ht);
88
pixmap.fill(Qt::white);
91
qPainter.begin(&pixmap);
93
PaintServices services(doc->FontPool());
94
IpeCanvasPainter painter(doc->StyleSheet(), &services,
95
&pixmap, &qPainter, zoom, true);
96
painter.Transform(IpeLinear(zoom, 0, 0, -zoom));
97
painter.Translate(-bbox.TopLeft());
99
for (IpePage::const_iterator it = page->begin(); it != page->end(); ++it) {
100
if (page->Layer(it->Layer()).IsVisible())
101
it->Object()->Draw(painter);
109
// --------------------------------------------------------------------