00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "private/qpicture_p.h"
00025 #include "qfile.h"
00026 #include "qpainter.h"
00027 #include "q3picture.h"
00028 #include "q3paintengine_svg_p.h"
00029
00030 class Q3SvgDevice : public QPaintDevice
00031 {
00032 public:
00033 Q3SvgDevice() : QPaintDevice() {}
00034 bool load(QIODevice *dev) { return svgEngine.load(dev); }
00035 bool save(const QString &fileName) { return svgEngine.save(fileName); }
00036 bool save(QIODevice *dev) { return svgEngine.save(dev); }
00037 void setBoundingRect(const QRect &rect) { svgEngine.setBoundingRect(rect); }
00038 QRect boundingRect() const { return svgEngine.boundingRect(); }
00039 QPaintEngine *paintEngine() const { return (QPaintEngine *)&svgEngine; }
00040 bool play(QPainter *p) { return svgEngine.play(p); }
00041 int metric(PaintDeviceMetric m) const;
00042
00043 private:
00044 Q3SVGPaintEngine svgEngine;
00045 };
00046
00047 int Q3SvgDevice::metric(PaintDeviceMetric m) const
00048 {
00049 int val;
00050 QRect br = svgEngine.boundingRect();
00051 switch (m) {
00052 case PdmWidth:
00053 val = br.width();
00054 break;
00055 case PdmHeight:
00056 val = br.height();
00057 break;
00058 case PdmWidthMM:
00059 val = int(25.4/72.0*br.width());
00060 break;
00061 case PdmHeightMM:
00062 val = int(25.4/72.0*br.height());
00063 break;
00064 case PdmDpiX:
00065 val = 72;
00066 break;
00067 case PdmDpiY:
00068 val = 72;
00069 break;
00070 case PdmNumColors:
00071 val = 16777216;
00072 break;
00073 case PdmDepth:
00074 val = 24;
00075 break;
00076 default:
00077 val = 0;
00078 qWarning("Q3SvgDevice::metric: Invalid metric command");
00079 }
00080 return val;
00081 }
00082
00117 bool Q3Picture::load(const QString &fileName, const char *format)
00118 {
00119 QFile f(fileName);
00120 if (!f.open(QIODevice::ReadOnly))
00121 return false;
00122 return load(&f, format);
00123 }
00124
00141 bool Q3Picture::load(QIODevice *dev, const char *format)
00142 {
00143 if (qstrcmp(format, "svg" ) == 0) {
00144 Q3SvgDevice svg;
00145 if (!svg.load(dev))
00146 return false;
00147 QPainter p(this);
00148 p.setRenderHint(QPainter::Antialiasing);
00149 bool b = svg.play(&p);
00150 d_func()->brect = svg.boundingRect();
00151 return b;
00152 }
00153 return QPicture::load(dev, format);
00154 }
00155
00163 bool Q3Picture::save(const QString &fileName, const char *format)
00164 {
00165 if (paintingActive()) {
00166 qWarning("Q3Picture::save: still being painted on. "
00167 "Call QPainter::end() first");
00168 return false;
00169 }
00170
00171
00172
00173 if (qstricmp( format, "svg") == 0) {
00174 Q3SvgDevice svg;
00175 QPainter p(&svg);
00176 if (!play(&p))
00177 return false;
00178 svg.setBoundingRect(boundingRect());
00179 return svg.save(fileName);
00180 }
00181
00182 return QPicture::save(fileName, format);
00183 }
00184
00204 bool Q3Picture::save(QIODevice *dev, const char *format)
00205 {
00206 if (paintingActive()) {
00207 qWarning("Q3Picture::save: still being painted on. "
00208 "Call QPainter::end() first");
00209 return false;
00210 }
00211
00212 if (qstricmp(format, "svg") == 0) {
00213 Q3SvgDevice svg;
00214 QPainter p(&svg);
00215 if (!play(&p))
00216 return false;
00217 svg.setBoundingRect(boundingRect());
00218 return svg.save(dev);
00219 }
00220
00221 return QPicture::save(dev, format);
00222 }