~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/ipe/topng.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2004-06-08 00:44:02 UTC
  • Revision ID: james.westby@ubuntu.com-20040608004402-72yu51xlh7vt6p9m
Tags: upstream-6.0pre16
ImportĀ upstreamĀ versionĀ 6.0pre16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// --------------------------------------------------------------------
 
2
// Conversion to a bitmap
 
3
// --------------------------------------------------------------------
 
4
/*
 
5
 
 
6
    This file is part of the extensible drawing editor Ipe.
 
7
    Copyright (C) 1993-2004  Otfried Cheong
 
8
 
 
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.
 
13
 
 
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.
 
18
 
 
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.
 
23
 
 
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.
 
28
 
 
29
*/
 
30
 
 
31
#include "ipeutils.h"
 
32
 
 
33
#include "ipepdfdoc.h"
 
34
#include "ipefilter.h"
 
35
#include "ipefontpool.h"
 
36
 
 
37
#include "ipecanvas.h"
 
38
 
 
39
#include <qpixmap.h>
 
40
#include <qimage.h>
 
41
#include <qpainter.h>
 
42
 
 
43
// --------------------------------------------------------------------
 
44
 
 
45
class PaintServices : public IpeCanvasPaintServices {
 
46
public:
 
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);
 
52
private:
 
53
  const IpeFontPool *iFontPool;
 
54
};
 
55
 
 
56
void PaintServices::CvSvcSetRenderData(IpeBitmap &bitmap)
 
57
{
 
58
  QImage img = IpeImageFilter::Decode(bitmap);
 
59
  bitmap.SetRenderData(new QImage(img));
 
60
}
 
61
 
 
62
void PaintServices::CvSvcRenderCharacter(QPixmap *pixmap, int fontObject,
 
63
                                         const IpeMatrix &m,
 
64
                                         const IpeVector &pos,
 
65
                                         QRgb cRgb,
 
66
                                         uint charCode, uint uniCode)
 
67
{
 
68
  if (iFontPool)
 
69
    iFontPool->RenderCharacter(pixmap, fontObject, m, pos,
 
70
                               cRgb, charCode, uniCode);
 
71
}
 
72
 
 
73
// --------------------------------------------------------------------
 
74
 
 
75
QPixmap toPng(const IpePdfDocument *doc, const IpePage *page,
 
76
              double zoom)
 
77
{
 
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);
 
82
  }
 
83
 
 
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);
 
89
 
 
90
  QPainter qPainter;
 
91
  qPainter.begin(&pixmap);
 
92
 
 
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());
 
98
  painter.Push();
 
99
  for (IpePage::const_iterator it = page->begin(); it != page->end(); ++it) {
 
100
    if (page->Layer(it->Layer()).IsVisible())
 
101
      it->Object()->Draw(painter);
 
102
  }
 
103
  painter.Pop();
 
104
  qPainter.end();
 
105
 
 
106
  return pixmap;
 
107
}
 
108
 
 
109
// --------------------------------------------------------------------