#include <q3paintengine_svg_p.h>
Inheritance diagram for Q3SVGPaintEngine:


Definition at line 44 of file q3paintengine_svg_p.h.
Public Member Functions | |
| Q3SVGPaintEngine () | |
| ~Q3SVGPaintEngine () | |
| bool | begin (QPaintDevice *pdev) |
| bool | end () |
| void | updateState (const QPaintEngineState &state) |
| void | updatePen (const QPen &pen) |
| void | updateBrush (const QBrush &brush, const QPointF &origin) |
| void | updateFont (const QFont &font) |
| void | updateBackground (Qt::BGMode bgmode, const QBrush &bgBrush) |
| void | updateMatrix (const QMatrix &matrix) |
| void | updateClipRegion (const QRegion ®ion, Qt::ClipOperation op) |
| void | updateClipPath (const QPainterPath &path, Qt::ClipOperation op) |
| void | updateRenderHints (QPainter::RenderHints hints) |
| void | drawEllipse (const QRect &r) |
| void | drawLine (const QLineF &line) |
| void | drawLines (const QLineF *lines, int lineCount) |
| void | drawRect (const QRectF &r) |
| void | drawPoint (const QPointF &p) |
| void | drawPoints (const QPointF *points, int pointCount) |
| void | drawPath (const QPainterPath &path) |
| void | drawPolygon (const QPointF *points, int pointCount, PolygonDrawMode mode) |
| void | drawPolygon (const QPoint *points, int pointCount, PolygonDrawMode mode) |
| void | drawPixmap (const QRectF &r, const QPixmap &pm, const QRectF &sr) |
| void | drawTiledPixmap (const QRectF &r, const QPixmap &pixmap, const QPointF &s) |
| void | drawTextItem (const QPointF &p, const QTextItem &ti) |
| void | drawImage (const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags=Qt::AutoColor) |
| Qt::HANDLE | handle () const |
| Type | type () const |
| bool | play (QPainter *p) |
| QString | toString () const |
| bool | load (QIODevice *dev) |
| bool | save (QIODevice *dev) |
| bool | save (const QString &fileName) |
| QRect | boundingRect () const |
| void | setBoundingRect (const QRect &r) |
Protected Member Functions | |
| Q3SVGPaintEngine (Q3SVGPaintEnginePrivate &dptr) | |
| Q3SVGPaintEngine::Q3SVGPaintEngine | ( | ) |
Definition at line 151 of file q3paintengine_svg.cpp.
References d.
00152 : QPaintEngine(*(new Q3SVGPaintEnginePrivate), AllFeatures) 00153 { 00154 Q_D(Q3SVGPaintEngine); 00155 d->init(); 00156 }
| Q3SVGPaintEngine::~Q3SVGPaintEngine | ( | ) |
Definition at line 165 of file q3paintengine_svg.cpp.
References qSvgColMap, and qSvgTypeMap.
00166 { 00167 delete qSvgTypeMap; qSvgTypeMap = 0; // static 00168 delete qSvgColMap; qSvgColMap = 0; 00169 }
| Q3SVGPaintEngine::Q3SVGPaintEngine | ( | Q3SVGPaintEnginePrivate & | dptr | ) | [protected] |
Definition at line 158 of file q3paintengine_svg.cpp.
References d.
00159 : QPaintEngine(dptr, AllFeatures) 00160 { 00161 Q_D(Q3SVGPaintEngine); 00162 d->init(); 00163 }
| bool Q3SVGPaintEngine::begin | ( | QPaintDevice * | pdev | ) | [virtual] |
Reimplement this function to initialise your paint engine when painting is to start on the paint device pdev. Return true if the initialization was successful; otherwise return false.
Implements QPaintEngine.
Definition at line 171 of file q3paintengine_svg.cpp.
References d, and QPaintEngine::setActive().
00172 { 00173 Q_D(Q3SVGPaintEngine); 00174 d->dirtyTransform = d->dirtyStyle = false; 00175 d->dev = pdev; 00176 setActive(true); 00177 return true; 00178 }
Here is the call graph for this function:

| bool Q3SVGPaintEngine::end | ( | ) | [virtual] |
Reimplement this function to finish painting on the current paint device. Return true if painting was finished successfully; otherwise return false.
Implements QPaintEngine.
Definition at line 180 of file q3paintengine_svg.cpp.
References d, and QPaintEngine::setActive().
00181 { 00182 Q_D(Q3SVGPaintEngine); 00183 d->dev = 0; 00184 setActive(false); 00185 return true; 00186 }
Here is the call graph for this function:

| void Q3SVGPaintEngine::updateState | ( | const QPaintEngineState & | state | ) | [virtual] |
Reimplement this function to update the state of a paint engine.
When implemented, this function is responsible for checking the paint engine's current state and update the properties that are changed. Use the QPaintEngineState::state() function to find out which properties that must be updated, then use the corresponding {GetFunction}{get function} to retrieve the current values for the given properties.
Implements QPaintEngine.
Definition at line 188 of file q3paintengine_svg.cpp.
References QPaintEngineState::backgroundBrush(), QPaintEngineState::backgroundMode(), QPaintEngineState::brush(), QPaintEngineState::brushOrigin(), QPaintEngineState::clipOperation(), QPaintEngineState::clipPath(), QPaintEngineState::clipRegion(), QPaintEngine::DirtyBackground, QPaintEngine::DirtyBrush, QPaintEngine::DirtyBrushOrigin, QPaintEngine::DirtyClipPath, QPaintEngine::DirtyClipRegion, QPaintEngine::DirtyFont, QPaintEngine::DirtyPen, QPaintEngine::DirtyTransform, flags, QPaintEngineState::font(), QPaintEngineState::matrix(), QPaintEngineState::pen(), QPaintEngineState::state(), QPaintEngine::state, updateBackground(), updateBrush(), updateClipPath(), updateClipRegion(), updateFont(), updateMatrix(), and updatePen().
00189 { 00190 QPaintEngine::DirtyFlags flags = state.state(); 00191 if (flags & DirtyPen) updatePen(state.pen()); 00192 if ((flags & DirtyBrush) || (flags & DirtyBrushOrigin)) 00193 updateBrush(state.brush(), state.brushOrigin()); 00194 if (flags & DirtyBackground) updateBackground(state.backgroundMode(), state.backgroundBrush()); 00195 if (flags & DirtyFont) updateFont(state.font()); 00196 if (flags & DirtyTransform) updateMatrix(state.matrix()); 00197 if (flags & DirtyClipRegion) updateClipRegion(state.clipRegion(), state.clipOperation()); 00198 if (flags & DirtyClipPath) updateClipPath(state.clipPath(), state.clipOperation()); 00199 }
Here is the call graph for this function:

| void Q3SVGPaintEngine::updatePen | ( | const QPen & | pen | ) |
Definition at line 201 of file q3paintengine_svg.cpp.
References d.
Referenced by updateState().
00202 { 00203 Q_D(Q3SVGPaintEngine); 00204 d->cpen = pen; 00205 d->dirtyStyle = true; 00206 }
Definition at line 208 of file q3paintengine_svg.cpp.
References d.
Referenced by updateState().
00209 { 00210 Q_D(Q3SVGPaintEngine); 00211 d->cbrush = brush; 00212 d->dirtyStyle = true; 00213 }
| void Q3SVGPaintEngine::updateFont | ( | const QFont & | font | ) |
Definition at line 215 of file q3paintengine_svg.cpp.
References d.
Referenced by updateState().
00216 { 00217 Q_D(Q3SVGPaintEngine); 00218 d->cfont = font; 00219 d->dirtyStyle = true; 00220 }
| void Q3SVGPaintEngine::updateBackground | ( | Qt::BGMode | bgmode, | |
| const QBrush & | bgBrush | |||
| ) |
Definition at line 222 of file q3paintengine_svg.cpp.
References d.
Referenced by updateState().
00223 { 00224 Q_D(Q3SVGPaintEngine); 00225 d->dirtyStyle = true; 00226 }
| void Q3SVGPaintEngine::updateMatrix | ( | const QMatrix & | matrix | ) |
Definition at line 228 of file q3paintengine_svg.cpp.
References d.
Referenced by updateState().
00229 { 00230 Q_D(Q3SVGPaintEngine); 00231 d->dirtyTransform = true; 00232 d->worldMatrix = matrix; 00233 // d->wwidth = ps->ww; 00234 // d->wheight = ps->wh; 00235 }
| void Q3SVGPaintEngine::updateClipRegion | ( | const QRegion & | region, | |
| Qt::ClipOperation | op | |||
| ) |
Definition at line 255 of file q3paintengine_svg.cpp.
References QPainterPath::addRegion(), and updateClipPath().
Referenced by updateState().
00256 { 00257 QPainterPath clipPath; 00258 clipPath.addRegion(clipRegion); 00259 updateClipPath(clipPath, op); 00260 }
Here is the call graph for this function:

| void Q3SVGPaintEngine::updateClipPath | ( | const QPainterPath & | path, | |
| Qt::ClipOperation | op | |||
| ) |
Definition at line 237 of file q3paintengine_svg.cpp.
References QDomNode::appendChild(), d, Qt::NoClip, path, QPicturePrivate::PdcSetClipPath, qt_svg_compose_path(), and QDomElement::setAttribute().
Referenced by updateClipRegion(), and updateState().
00238 { 00239 Q_D(Q3SVGPaintEngine); 00240 if (op == Qt::NoClip) 00241 return; 00242 00243 QDomElement e; 00244 d->currentClip++; 00245 e = d->doc.createElement("clipPath"); 00246 e.setAttribute("id", QString("clip%1").arg(d->currentClip)); 00247 00248 QDomElement path_element = d->doc.createElement("path"); 00249 path_element.setAttribute("d", qt_svg_compose_path(path)); 00250 e.appendChild(path_element); 00251 00252 d->appendChild(e, QPicturePrivate::PdcSetClipPath); 00253 }
Here is the call graph for this function:

| void Q3SVGPaintEngine::updateRenderHints | ( | QPainter::RenderHints | hints | ) |
| void Q3SVGPaintEngine::drawEllipse | ( | const QRect & | r | ) | [virtual] |
The default implementation of this function calls the floating point version of this function
Reimplemented from QPaintEngine.
Definition at line 293 of file q3paintengine_svg.cpp.
References d, QRect::height(), QPicturePrivate::PdcDrawEllipse, QDomElement::setAttribute(), QRect::width(), QRect::x(), and QRect::y().
00294 { 00295 Q_D(Q3SVGPaintEngine); 00296 QDomElement e; 00297 00298 if (r.width() == r.height()) { 00299 e = d->doc.createElement("circle"); 00300 double cx = r.x() + (r.width() / 2.0); 00301 double cy = r.y() + (r.height() / 2.0); 00302 e.setAttribute("cx", cx); 00303 e.setAttribute("cy", cy); 00304 e.setAttribute("r", cx - r.x()); 00305 } else { 00306 e = d->doc.createElement("ellipse"); 00307 double cx = r.x() + (r.width() / 2.0); 00308 double cy = r.y() + (r.height() / 2.0); 00309 e.setAttribute("cx", cx); 00310 e.setAttribute("cy", cy); 00311 e.setAttribute("rx", cx - r.x()); 00312 e.setAttribute("ry", cy - r.y()); 00313 } 00314 d->appendChild(e, QPicturePrivate::PdcDrawEllipse); 00315 }
Here is the call graph for this function:

| void Q3SVGPaintEngine::drawLine | ( | const QLineF & | line | ) |
Definition at line 317 of file q3paintengine_svg.cpp.
References drawLines().
00318 { 00319 drawLines(&line, 1); 00320 }
Here is the call graph for this function:

| void Q3SVGPaintEngine::drawLines | ( | const QLineF * | lines, | |
| int | lineCount | |||
| ) | [virtual] |
The default implementation splits the list of lines in lines into lineCount separate calls to drawPath() or drawPolygon() depending on the feature set of the paint engine.
Reimplemented from QPaintEngine.
Definition at line 322 of file q3paintengine_svg.cpp.
References d, i, QPicturePrivate::PdcDrawLineSegments, and QDomElement::setAttribute().
Referenced by drawLine(), drawPoint(), and drawPoints().
00323 { 00324 Q_D(Q3SVGPaintEngine); 00325 QDomElement e; 00326 00327 for (int i = 0; i < lineCount; ++i) { 00328 e = d->doc.createElement("line"); 00329 e.setAttribute("x1", lines[i].x1()); 00330 e.setAttribute("y1", lines[i].y1()); 00331 e.setAttribute("x2", lines[i].x2()); 00332 e.setAttribute("y2", lines[i].y2()); 00333 d->appendChild(e, QPicturePrivate::PdcDrawLineSegments); 00334 } 00335 }
Here is the call graph for this function:

| void Q3SVGPaintEngine::drawRect | ( | const QRectF & | r | ) |
Definition at line 266 of file q3paintengine_svg.cpp.
References d, QRectF::height(), QPicturePrivate::PdcDrawRect, QDomElement::setAttribute(), QRectF::width(), QRectF::x(), and QRectF::y().
00267 { 00268 Q_D(Q3SVGPaintEngine); 00269 QDomElement e; 00270 e = d->doc.createElement("rect"); 00271 00272 e.setAttribute("x", r.x()); 00273 e.setAttribute("y", r.y()); 00274 e.setAttribute("width", r.width()); 00275 e.setAttribute("height", r.height()); 00276 d->appendChild(e, QPicturePrivate::PdcDrawRect); 00277 }
Here is the call graph for this function:

| void Q3SVGPaintEngine::drawPoint | ( | const QPointF & | p | ) |
Definition at line 279 of file q3paintengine_svg.cpp.
References drawLines(), l, and p.
Here is the call graph for this function:

| void Q3SVGPaintEngine::drawPoints | ( | const QPointF * | points, | |
| int | pointCount | |||
| ) | [virtual] |
Draws the first pointCount points in the buffer points
Reimplemented from QPaintEngine.
Definition at line 285 of file q3paintengine_svg.cpp.
References drawLines(), i, and l.
00286 { 00287 for (int i = 0; i < pointCount; ++i) { 00288 QLineF l(points[i], points[i]); 00289 drawLines(&l, 1); 00290 } 00291 }
Here is the call graph for this function:

| void Q3SVGPaintEngine::drawPath | ( | const QPainterPath & | path | ) | [virtual] |
The default implementation ignores the path and does nothing.
Reimplemented from QPaintEngine.
Definition at line 337 of file q3paintengine_svg.cpp.
References d, path, QPicturePrivate::PdcDrawPath, qt_svg_compose_path(), and QDomElement::setAttribute().
00338 { 00339 Q_D(Q3SVGPaintEngine); 00340 QDomElement e = d->doc.createElement("path"); 00341 e.setAttribute("d", qt_svg_compose_path(path)); 00342 d->appendChild(e, QPicturePrivate::PdcDrawPath); 00343 }
Here is the call graph for this function:

| void Q3SVGPaintEngine::drawPolygon | ( | const QPointF * | points, | |
| int | pointCount, | |||
| PolygonDrawMode | mode | |||
| ) | [virtual] |
Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode.
The default implementation of this function will try to use drawPath if the engine supports the feature QPaintEngine::PainterPaths or try the float based drawPolygon() implementation if not.
Reimplemented from QPaintEngine.
Definition at line 345 of file q3paintengine_svg.cpp.
References d, i, QPicturePrivate::PdcDrawPolygon, QPicturePrivate::PdcDrawPolyline, QPaintEngine::PolylineMode, QDomElement::setAttribute(), QString::trimmed(), x, and y.
Referenced by drawPolygon().
00346 { 00347 Q_D(Q3SVGPaintEngine); 00348 QString str; 00349 if (mode == PolylineMode) { 00350 QDomElement e = d->doc.createElement("polyline"); 00351 for (int i = 0; i < pointCount; ++i) { 00352 QString tmp; 00353 tmp.sprintf("%f %f ", points[i].x(), points[i].y()); 00354 str += tmp; 00355 } 00356 e.setAttribute("points", str.trimmed()); 00357 d->appendChild(e, QPicturePrivate::PdcDrawPolyline); 00358 } else { 00359 QDomElement e = d->doc.createElement("polygon"); 00360 for (int i = 0; i < pointCount; ++i) { 00361 QString tmp; 00362 tmp.sprintf("%f %f ", points[i].x(), points[i].y()); 00363 str += tmp; 00364 } 00365 e.setAttribute("points", str.trimmed()); 00366 d->appendChild(e, QPicturePrivate::PdcDrawPolygon); 00367 } 00368 }
Here is the call graph for this function:

| void Q3SVGPaintEngine::drawPolygon | ( | const QPoint * | points, | |
| int | pointCount, | |||
| PolygonDrawMode | mode | |||
| ) | [virtual] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode.
The default implementation of this function will try to use drawPath() if the engine supports the feature QPaintEngine::PainterPaths or try the int based drawPolygon() implementation if not.
Reimplemented from QPaintEngine.
Definition at line 370 of file q3paintengine_svg.cpp.
References QVector< T >::constData(), drawPolygon(), and i.
00371 { 00372 QPolygonF poly; 00373 for (int i = 0; i < pointCount; ++i) 00374 poly << points[i]; 00375 drawPolygon(poly.constData(), pointCount, mode); 00376 }
Here is the call graph for this function:

| void Q3SVGPaintEngine::drawPixmap | ( | const QRectF & | r, | |
| const QPixmap & | pm, | |||
| const QRectF & | sr | |||
| ) | [virtual] |
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r.
Implements QPaintEngine.
Definition at line 378 of file q3paintengine_svg.cpp.
References d, QPixElement::element, QRectF::height(), QPicturePrivate::PdcDrawPixmap, QPixElement::pixmap, QDomElement::setAttribute(), QRectF::width(), QRectF::x(), and QRectF::y().
00379 { 00380 Q_D(Q3SVGPaintEngine); 00381 QDomElement e = d->doc.createElement("image"); 00382 e.setAttribute("x", r.x()); 00383 e.setAttribute("y", r.y()); 00384 e.setAttribute("width", r.width()); 00385 e.setAttribute("height", r.height()); 00386 00387 QPixElement pe; 00388 pe.element = e; 00389 pe.pixmap = pm; 00390 d->pixmaps.append(pe); 00391 00392 // saving to disk and setting the xlink:href attribute will be 00393 // done later in save() once we now the svg document name. 00394 d->appendChild(e, QPicturePrivate::PdcDrawPixmap); 00395 }
Here is the call graph for this function:

| void Q3SVGPaintEngine::drawTiledPixmap | ( | const QRectF & | r, | |
| const QPixmap & | pixmap, | |||
| const QPointF & | s | |||
| ) | [virtual] |
Reimplement this function to draw the pixmap in the given rect, starting at the given p. The pixmap will be drawn repeatedly until the rect is filled.
Reimplemented from QPaintEngine.
Definition at line 397 of file q3paintengine_svg.cpp.
This function draws the text item textItem at position p. The default implementation of this function converts the text to a QPainterPath and paints the resulting path.
Reimplemented from QPaintEngine.
Definition at line 402 of file q3paintengine_svg.cpp.
References QDomNode::appendChild(), d, p, QDomElement::setAttribute(), and QTextItem::text().
00403 { 00404 Q_D(Q3SVGPaintEngine); 00405 QDomElement e = d->doc.createElement("text"); 00406 // int x, y; 00407 // const QRect r(p.x(), p.y(), ti.width, ti.ascent + ti.descent); 00408 // horizontal text alignment 00409 // if ((ti.flags & Qt::AlignHCenter) != 0) { 00410 // x = r.x() + r.width() / 2; 00411 // e.setAttribute("text-anchor", "middle"); 00412 // } else if ((textflags & Qt::AlignRight) != 0) { 00413 // x = r.right(); 00414 // e.setAttribute("text-anchor", "end"); 00415 // } else { 00416 // x = r.x(); 00417 // } 00418 // // vertical text alignment 00419 // if ((textflags & Qt::AlignVCenter) != 0) 00420 // y = r.y() + (r.height() + ti.ascent) / 2; 00421 // else if ((textflags & Qt::AlignBottom) != 0) 00422 // y = r.bottom(); 00423 // else 00424 // y = r.y() + ti.ascent; 00425 // if (x) 00426 // e.setAttribute("x", x); 00427 // if (y) 00428 // e.setAttribute("y", y); 00429 e.setAttribute("x", p.x()); 00430 e.setAttribute("y", p.y()); 00431 e.appendChild(d->doc.createTextNode(ti.text())); 00432 }
Here is the call graph for this function:

| void Q3SVGPaintEngine::drawImage | ( | const QRectF & | r, | |
| const QImage & | pm, | |||
| const QRectF & | sr, | |||
| Qt::ImageConversionFlags | flags = Qt::AutoColor | |||
| ) | [virtual] |
Reimplement this function to draw the part of the image specified by the sr rectangle in the given rectangle using the given conversion flags flags, to convert it to a pixmap.
Reimplemented from QPaintEngine.
Definition at line 434 of file q3paintengine_svg.cpp.
References d, QImgElement::element, QRectF::height(), QImgElement::image, QPicturePrivate::PdcDrawImage, QDomElement::setAttribute(), QRectF::width(), QRectF::x(), and QRectF::y().
00436 { 00437 Q_D(Q3SVGPaintEngine); 00438 QDomElement e = d->doc.createElement("image"); 00439 e.setAttribute("x", r.x()); 00440 e.setAttribute("y", r.y()); 00441 e.setAttribute("width", r.width()); 00442 e.setAttribute("height", r.height()); 00443 QImgElement ie; 00444 ie.element = e; 00445 ie.image = im; 00446 d->images.append(ie); 00447 // saving to disk and setting the xlink:href attribute will be 00448 // done later in save() once we now the svg document name. 00449 d->appendChild(e, QPicturePrivate::PdcDrawImage); 00450 }
Here is the call graph for this function:

| Qt::HANDLE Q3SVGPaintEngine::handle | ( | ) | const [inline] |
| Type Q3SVGPaintEngine::type | ( | ) | const [inline, virtual] |
Reimplement this function to return the paint engine {Type}.
Implements QPaintEngine.
Definition at line 87 of file q3paintengine_svg_p.h.
References QPaintEngine::SVG.
Referenced by play().
00087 { return SVG; }
| bool Q3SVGPaintEngine::play | ( | QPainter * | p | ) |
Definition at line 678 of file q3paintengine_svg.cpp.
References Qt::AlignLeft, AnchorElement, QDomNode::attributes(), b, Qt::black, CircleElement, ClipElement, CommentElement, QDomNamedNodeMap::contains(), d, DescElement, QPainter::device(), EllipseElement, QString::fromLatin1(), GroupElement, h, height, QRect::height(), ImageElement, QMap< Key, T >::insert(), InvalidElement, QDomNode::isElement(), QDomNode::isNull(), LineElement, name, QDomNamedNodeMap::namedItem(), QDomNode::nodeValue(), Qt::NoPen, PathElement, PolygonElement, PolylineElement, qSvgTypeMap, qWarning(), RectElement, QPainter::scale(), QPainter::setBrush(), QPainter::setClipRect(), QPainter::setPen(), SvgElement, t, Q3SVGPaintEngineState::textalign, TextElement, Q3SVGPaintEngineState::textx, Q3SVGPaintEngineState::texty, TitleElement, QPainter::translate(), TSpanElement, type(), w, QRect::width(), width, QPainter::window(), x, and y.
Referenced by Q3SvgDevice::play().
00679 { 00680 Q_D(Q3SVGPaintEngine); 00681 if (!pt) { 00682 Q_ASSERT(pt); 00683 return false; 00684 } 00685 if (d->dev == 0) 00686 d->dev = pt->device(); 00687 d->wwidth = pt->window().width(); 00688 d->wheight = pt->window().height(); 00689 00690 pt->setPen(Qt::NoPen); // SVG default pen and brush 00691 pt->setBrush(Qt::black); 00692 if (d->doc.isNull()) { 00693 qWarning("Q3SVGPaintEngine::play: No SVG data set."); 00694 return false; 00695 } 00696 00697 QDomNode svg = d->doc.namedItem("svg"); 00698 if (svg.isNull() || !svg.isElement()) { 00699 qWarning("Q3SVGPaintEngine::play: Couldn't find any svg element."); 00700 return false; 00701 } 00702 00703 // force transform to be activated in case our sequences 00704 // are replayed later with a transformed painter 00705 pt->setWorldXForm(true); 00706 00707 QDomNamedNodeMap attr = svg.attributes(); 00708 int x = d->lenToInt(attr, "x"); 00709 int y = d->lenToInt(attr, "y"); 00710 d->brect.setX(x); 00711 d->brect.setY(y); 00712 QString wstr = attr.contains("width") 00713 ? attr.namedItem("width").nodeValue() : QString("100%"); 00714 QString hstr = attr.contains("height") 00715 ? attr.namedItem("height").nodeValue() : QString("100%"); 00716 double width = d->parseLen(wstr, 0, true); 00717 double height = d->parseLen(hstr, 0, false); 00718 // SVG doesn't respect x and y. But we want a proper bounding rect. 00719 d->brect.setWidth(int(width) - x); 00720 d->brect.setHeight(int(height) - y); 00721 pt->setClipRect(d->brect); 00722 00723 if (attr.contains("viewBox")) { 00724 QRegExp re(QString::fromLatin1("\\s*(\\S+)\\s*,?\\s*(\\S+)\\s*,?" 00725 "\\s*(\\S+)\\s*,?\\s*(\\S+)\\s*")); 00726 if (re.indexIn(attr.namedItem("viewBox").nodeValue()) < 0) { 00727 qWarning("Q3SVGPaintEngine::play: Invalid viewBox attribute."); 00728 return false; 00729 } else { 00730 double x = re.cap(1).toDouble(); 00731 double y = re.cap(2).toDouble(); 00732 double w = re.cap(3).toDouble(); 00733 double h = re.cap(4).toDouble(); 00734 if (w < 0 || h < 0) { 00735 qWarning("Q3SVGPaintEngine::play: Invalid viewBox dimension."); 00736 return false; 00737 } else if (w == 0 || h == 0) { 00738 return true; 00739 } 00740 pt->scale(width/w, height/h); 00741 pt->translate(-x, -y); 00742 } 00743 } 00744 00745 const struct ElementTable { 00746 const char *name; 00747 ElementType type; 00748 } etab[] = { 00749 {"a", AnchorElement }, 00750 {"#comment", CommentElement }, 00751 {"circle", CircleElement }, 00752 {"clipPath", ClipElement }, 00753 {"desc", DescElement }, 00754 {"ellipse", EllipseElement }, 00755 {"g", GroupElement }, 00756 {"image", ImageElement }, 00757 {"line", LineElement }, 00758 {"polyline", PolylineElement}, 00759 {"polygon", PolygonElement }, 00760 {"path", PathElement }, 00761 {"rect", RectElement }, 00762 {"svg", SvgElement }, 00763 {"text", TextElement }, 00764 {"tspan", TSpanElement }, 00765 {"title", TitleElement }, 00766 {0, InvalidElement } 00767 }; 00768 // initialize only once 00769 if (!qSvgTypeMap) { 00770 qSvgTypeMap = new QSvgTypeMap; 00771 const ElementTable *t = etab; 00772 while (t->name) { 00773 qSvgTypeMap->insert(t->name, t->type); 00774 t++; 00775 } 00776 } 00777 00778 // initial state 00779 Q3SVGPaintEngineState st; 00780 st.textx = st.texty = 0; 00781 st.textalign = Qt::AlignLeft; 00782 d->stack.append(st); 00783 d->curr = &d->stack.last(); 00784 // 'play' all elements recursively starting with 'svg' as root 00785 bool b = d->play(svg, pt); 00786 d->stack.removeFirst(); 00787 return b; 00788 }
Here is the call graph for this function:

| QString Q3SVGPaintEngine::toString | ( | ) | const |
Returns the SVG as a single string of XML.
Definition at line 457 of file q3paintengine_svg.cpp.
References d.
00458 { 00459 Q_D(const Q3SVGPaintEngine); 00460 if (d->doc.isNull()) 00461 return QString(); 00462 00463 return d->doc.toString(); 00464 }
| bool Q3SVGPaintEngine::load | ( | QIODevice * | dev | ) |
Loads and parses a SVG from dev into the device. Returns true on success (i.e. loaded and parsed without error); otherwise returns false.
Definition at line 560 of file q3paintengine_svg.cpp.
Referenced by Q3SvgDevice::load().
| bool Q3SVGPaintEngine::save | ( | QIODevice * | dev | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. dev is the device to use for saving.
Definition at line 521 of file q3paintengine_svg.cpp.
References d, qWarning(), and s.
Referenced by Q3SvgDevice::save().
00522 { 00523 Q_D(Q3SVGPaintEngine); 00524 #if defined(CHECK_RANGE) 00525 if (!d->images.isEmpty() || !d->pixmaps.isEmpty()) 00526 qWarning("Q3SVGPaintEngine::save: skipping external images"); 00527 #endif 00528 00529 QTextStream s(dev); 00530 s.setEncoding(QTextStream::UnicodeUTF8); 00531 s << d->doc; 00532 00533 return true; 00534 }
Here is the call graph for this function:

| bool Q3SVGPaintEngine::save | ( | const QString & | fileName | ) |
Saves the SVG to fileName.
Definition at line 470 of file q3paintengine_svg.cpp.
References d, QString::endsWith(), QString::left(), QString::length(), QFile::open(), s, QDomElement::setAttribute(), and QIODevice::WriteOnly.
00471 { 00472 Q_D(Q3SVGPaintEngine); 00473 // guess svg id from fileName 00474 QString svgName = fileName.endsWith(".svg") ? 00475 fileName.left(fileName.length()-4) : fileName; 00476 00477 // now we have the info about name and dimensions available 00478 QDomElement root = d->doc.documentElement(); 00479 root.setAttribute("id", svgName); 00480 // the standard doesn't take respect x and y. But we want a 00481 // proper bounding rect. We make width and height bigger when 00482 // writing out and subtract x and y when reading in. 00483 root.setAttribute("x", d->brect.x()); 00484 root.setAttribute("y", d->brect.y()); 00485 root.setAttribute("width", d->brect.width() + d->brect.x()); 00486 root.setAttribute("height", d->brect.height() + d->brect.y()); 00487 00488 // ... and know how to name any image files to be written out 00489 int icount = 0; 00490 ImageList::Iterator iit = d->images.begin(); 00491 for (; iit != d->images.end(); ++iit) { 00492 QString href = QString("%1_%2.png").arg(svgName).arg(icount); 00493 (*iit).image.save(href, "PNG"); 00494 (*iit).element.setAttribute("xlink:href", href); 00495 icount++; 00496 } 00497 PixmapList::Iterator pit = d->pixmaps.begin(); 00498 for (; pit != d->pixmaps.end(); ++pit) { 00499 QString href = QString("%1_%2.png").arg(svgName).arg(icount); 00500 (*pit).pixmap.save(href, "PNG"); 00501 (*pit).element.setAttribute("xlink:href", href); 00502 icount++; 00503 } 00504 00505 QFile f(fileName); 00506 if (!f.open (QIODevice::WriteOnly)) 00507 return false; 00508 QTextStream s(&f); 00509 s.setEncoding(QTextStream::UnicodeUTF8); 00510 s << d->doc; 00511 00512 return true; 00513 }
Here is the call graph for this function:

| QRect Q3SVGPaintEngine::boundingRect | ( | ) | const |
Returns the SVG's bounding rectangle.
Definition at line 549 of file q3paintengine_svg.cpp.
Referenced by Q3SvgDevice::boundingRect(), and Q3SvgDevice::metric().
| void Q3SVGPaintEngine::setBoundingRect | ( | const QRect & | r | ) |
Sets the bounding rectangle of the SVG to rectangle r.
Definition at line 540 of file q3paintengine_svg.cpp.
Referenced by Q3SvgDevice::setBoundingRect().
1.5.1