Qt 4.8
Public Functions | List of all members
QSvgPaintEngine Class Reference
Inheritance diagram for QSvgPaintEngine:
QPaintEngine

Public Functions

bool begin (QPaintDevice *device)
 Reimplement this function to initialise your paint engine when painting is to start on the paint device pdev. More...
 
QString documentDescription () const
 
QString documentTitle () const
 
void drawImage (const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlag=Qt::AutoColor)
 
void drawPath (const QPainterPath &path)
 The default implementation ignores the path and does nothing. More...
 
void drawPixmap (const QRectF &r, const QPixmap &pm, const QRectF &sr)
 Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r. More...
 
void drawPolygon (const QPointF *points, int pointCount, PolygonDrawMode mode)
 Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode. More...
 
void drawTextItem (const QPointF &pt, const QTextItem &item)
 This function draws the text item textItem at position p. More...
 
bool end ()
 Reimplement this function to finish painting on the current paint device. More...
 
void generateQtDefaults ()
 
QIODeviceoutputDevice () const
 
void popGroup ()
 
void qbrushToSvg (const QBrush &sbrush)
 
void qfontToSvg (const QFont &sfont)
 
void qpenToSvg (const QPen &spen)
 
 QSvgPaintEngine ()
 
int resolution ()
 
void saveConicalGradientBrush (const QGradient *)
 
void saveGradientStops (QTextStream &str, const QGradient *g)
 
void saveGradientUnits (QTextStream &str, const QGradient *gradient)
 
void saveLinearGradientBrush (const QGradient *g)
 
void saveRadialGradientBrush (const QGradient *g)
 
void setDocumentDescription (const QString &description)
 
void setDocumentTitle (const QString &title)
 
void setOutputDevice (QIODevice *device)
 
void setResolution (int resolution)
 
void setSize (const QSize &size)
 
void setViewBox (const QRectF &viewBox)
 
QSize size () const
 
QTextStreamstream ()
 
QPaintEngine::Type type () const
 Reimplement this function to return the paint engine Type. More...
 
void updateState (const QPaintEngineState &state)
 Reimplement this function to update the state of a paint engine. More...
 
QRectF viewBox () const
 
- Public Functions inherited from QPaintEngine
void clearDirty (DirtyFlags df)
 
virtual QPoint coordinateOffset () const
 Returns the offset from the painters origo to the engines origo. More...
 
virtual void drawEllipse (const QRectF &r)
 Reimplement this function to draw the largest ellipse that can be contained within rectangle rect. More...
 
virtual void drawEllipse (const QRect &r)
 The default implementation of this function calls the floating point version of this function. More...
 
virtual void drawImage (const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags=Qt::AutoColor)
 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. More...
 
virtual void drawLines (const QLine *lines, int lineCount)
 The default implementation converts the first lineCount lines in lines to a QLineF and calls the floating point version of this function. More...
 
virtual void drawLines (const QLineF *lines, int lineCount)
 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. More...
 
virtual void drawPoints (const QPointF *points, int pointCount)
 Draws the first pointCount points in the buffer points. More...
 
virtual void drawPoints (const QPoint *points, int pointCount)
 Draws the first pointCount points in the buffer points. More...
 
virtual void drawPolygon (const QPoint *points, int pointCount, PolygonDrawMode mode)
 Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode. More...
 
virtual void drawRects (const QRect *rects, int rectCount)
 The default implementation converts the first rectCount rectangles in the buffer rects to a QRectF and calls the floating point version of this function. More...
 
virtual void drawRects (const QRectF *rects, int rectCount)
 Draws the first rectCount rectangles in the buffer rects. More...
 
virtual void drawTiledPixmap (const QRectF &r, const QPixmap &pixmap, const QPointF &s)
 Reimplement this function to draw the pixmap in the given rect, starting at the given p. More...
 
void fix_neg_rect (int *x, int *y, int *w, int *h)
 
virtual HDC getDC () const
 Empty default implementation. More...
 
bool hasFeature (PaintEngineFeatures feature) const
 Returns true if the paint engine supports the specified feature; otherwise returns false. More...
 
bool isActive () const
 Returns true if the paint engine is actively drawing; otherwise returns false. More...
 
bool isExtended () const
 Returns true if the paint engine is a QPaintEngineEx derivative. More...
 
QPaintDevicepaintDevice () const
 Returns the device that this engine is painting on, if painting is active; otherwise returns 0. More...
 
QPainterpainter () const
 Returns the paint engine's painter. More...
 
 QPaintEngine (PaintEngineFeatures features=0)
 Creates a paint engine with the featureset specified by caps. More...
 
virtual void releaseDC (HDC hdc) const
 Empty default implementation. More...
 
void setActive (bool newState)
 Sets the active state of the paint engine to state. More...
 
void setDirty (DirtyFlags df)
 
void setPaintDevice (QPaintDevice *device)
 
void setSystemClip (const QRegion &baseClip)
 Sets the system clip for this engine. More...
 
void setSystemRect (const QRect &rect)
 Sets the target rect for drawing within the backing store. More...
 
void syncState ()
 Updates all dirty states in this engine. More...
 
QRegion systemClip () const
 Returns the system clip. More...
 
QRect systemRect () const
 Retrieves the rect for drawing within the backing store. More...
 
bool testDirty (DirtyFlags df)
 
virtual ~QPaintEngine ()
 Destroys the paint engine. More...
 

Additional Inherited Members

- Public Types inherited from QPaintEngine
enum  DirtyFlag {
  DirtyPen = 0x0001, DirtyBrush = 0x0002, DirtyBrushOrigin = 0x0004, DirtyFont = 0x0008,
  DirtyBackground = 0x0010, DirtyBackgroundMode = 0x0020, DirtyTransform = 0x0040, DirtyClipRegion = 0x0080,
  DirtyClipPath = 0x0100, DirtyHints = 0x0200, DirtyCompositionMode = 0x0400, DirtyClipEnabled = 0x0800,
  DirtyOpacity = 0x1000, AllDirty = 0xffff
}
 QPaintEngine::updateState(). More...
 
enum  PaintEngineFeature {
  PrimitiveTransform = 0x00000001, PatternTransform = 0x00000002, PixmapTransform = 0x00000004, PatternBrush = 0x00000008,
  LinearGradientFill = 0x00000010, RadialGradientFill = 0x00000020, ConicalGradientFill = 0x00000040, AlphaBlend = 0x00000080,
  PorterDuff = 0x00000100, PainterPaths = 0x00000200, Antialiasing = 0x00000400, BrushStroke = 0x00000800,
  ConstantOpacity = 0x00001000, MaskedBrush = 0x00002000, PerspectiveTransform = 0x00004000, BlendModes = 0x00008000,
  ObjectBoundingModeGradients = 0x00010000, RasterOpModes = 0x00020000, PaintOutsidePaintEvent = 0x20000000, AllFeatures = 0xffffffff
}
 This enum is used to describe the features or capabilities that the paint engine has. More...
 
enum  PolygonDrawMode { OddEvenMode, WindingMode, ConvexMode, PolylineMode }
 
enum  Type {
  X11, Windows, QuickDraw, CoreGraphics,
  MacPrinter, QWindowSystem, PostScript, OpenGL,
  Picture, SVG, Raster, Direct3D,
  Pdf, OpenVG, OpenGL2, PaintBuffer,
  Blitter, User = 50, MaxUser = 100
}
 
- Protected Functions inherited from QPaintEngine
 QPaintEngine (QPaintEnginePrivate &data, PaintEngineFeatures devcaps=0)
 
- Protected Variables inherited from QPaintEngine
uint active: 1
 
QScopedPointer< QPaintEnginePrivated_ptr
 
uint extended: 1
 
PaintEngineFeatures gccaps
 
uint selfDestruct: 1
 
QPaintEngineStatestate
 

Detailed Description

Definition at line 156 of file qsvggenerator.cpp.

Constructors and Destructors

◆ QSvgPaintEngine()

QSvgPaintEngine::QSvgPaintEngine ( )
inline

Definition at line 161 of file qsvggenerator.cpp.

164  {
165  }
QPaintEngine(PaintEngineFeatures features=0)
Creates a paint engine with the featureset specified by caps.
static QPaintEngine::PaintEngineFeatures svgEngineFeatures()

Functions

◆ begin()

bool QSvgPaintEngine::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.

See also
end() isActive()

Implements QPaintEngine.

Definition at line 842 of file qsvggenerator.cpp.

843 {
845  if (!d->outputDevice) {
846  qWarning("QSvgPaintEngine::begin(), no output device");
847  return false;
848  }
849 
850  if (!d->outputDevice->isOpen()) {
851  if (!d->outputDevice->open(QIODevice::WriteOnly | QIODevice::Text)) {
852  qWarning("QSvgPaintEngine::begin(), could not open output device: '%s'",
853  qPrintable(d->outputDevice->errorString()));
854  return false;
855  }
856  } else if (!d->outputDevice->isWritable()) {
857  qWarning("QSvgPaintEngine::begin(), could not write to read-only output device: '%s'",
858  qPrintable(d->outputDevice->errorString()));
859  return false;
860  }
861 
862  d->stream = new QTextStream(&d->header);
863 
864  // stream out the header...
865  *d->stream << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" << endl << "<svg";
866 
867  if (d->size.isValid()) {
868  qreal wmm = d->size.width() * 25.4 / d->resolution;
869  qreal hmm = d->size.height() * 25.4 / d->resolution;
870  *d->stream << " width=\"" << wmm << "mm\" height=\"" << hmm << "mm\"" << endl;
871  }
872 
873  if (d->viewBox.isValid()) {
874  *d->stream << " viewBox=\"" << d->viewBox.left() << ' ' << d->viewBox.top();
875  *d->stream << ' ' << d->viewBox.width() << ' ' << d->viewBox.height() << '\"' << endl;
876  }
877 
878  *d->stream << " xmlns=\"http://www.w3.org/2000/svg\""
879  " xmlns:xlink=\"http://www.w3.org/1999/xlink\" "
880  " version=\"1.2\" baseProfile=\"tiny\">" << endl;
881 
882  if (!d->attributes.document_title.isEmpty()) {
883  *d->stream << "<title>" << d->attributes.document_title << "</title>" << endl;
884  }
885 
886  if (!d->attributes.document_description.isEmpty()) {
887  *d->stream << "<desc>" << d->attributes.document_description << "</desc>" << endl;
888  }
889 
890  d->stream->setString(&d->defs);
891  *d->stream << "<defs>\n";
892 
893  d->stream->setString(&d->body);
894  // Start the initial graphics state...
895  *d->stream << "<g ";
897  *d->stream << endl;
898 
899  return true;
900 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
#define qPrintable(string)
Definition: qglobal.h:1750
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)

◆ documentDescription()

QString QSvgPaintEngine::documentDescription ( ) const
inline

Definition at line 199 of file qsvggenerator.cpp.

199 { return d_func()->attributes.document_description; }

◆ documentTitle()

QString QSvgPaintEngine::documentTitle ( ) const
inline

Definition at line 194 of file qsvggenerator.cpp.

194 { return d_func()->attributes.document_title; }

◆ drawImage()

void QSvgPaintEngine::drawImage ( const QRectF r,
const QImage pm,
const QRectF sr,
Qt::ImageConversionFlag  flags = Qt::AutoColor 
)

Definition at line 934 of file qsvggenerator.cpp.

937 {
938  //Q_D(QSvgPaintEngine);
939 
940  Q_UNUSED(sr);
941  Q_UNUSED(flags);
942  stream() << "<image ";
943  stream() << "x=\""<<r.x()<<"\" "
944  "y=\""<<r.y()<<"\" "
945  "width=\""<<r.width()<<"\" "
946  "height=\""<<r.height()<<"\" "
947  "preserveAspectRatio=\"none\" ";
948 
950  QBuffer buffer(&data);
951  buffer.open(QBuffer::ReadWrite);
952  image.save(&buffer, "PNG");
953  buffer.close();
954  stream() << "xlink:href=\"data:image/png;base64,"
955  << data.toBase64()
956  <<"\" />\n";
957 }
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QTextStream & stream()
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
static const char * data(const QByteArray &arr)
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
QByteArray toBase64() const
Returns a copy of the byte array, encoded as Base64.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ drawPath()

void QSvgPaintEngine::drawPath ( const QPainterPath path)
virtual

The default implementation ignores the path and does nothing.

Reimplemented from QPaintEngine.

Definition at line 1005 of file qsvggenerator.cpp.

1006 {
1008 
1009  *d->stream << "<path vector-effect=\""
1010  << (state->pen().isCosmetic() ? "non-scaling-stroke" : "none")
1011  << "\" fill-rule=\""
1012  << (p.fillRule() == Qt::OddEvenFill ? "evenodd" : "nonzero")
1013  << "\" d=\"";
1014 
1015  for (int i=0; i<p.elementCount(); ++i) {
1016  const QPainterPath::Element &e = p.elementAt(i);
1017  switch (e.type) {
1019  *d->stream << 'M' << e.x << ',' << e.y;
1020  break;
1022  *d->stream << 'L' << e.x << ',' << e.y;
1023  break;
1025  *d->stream << 'C' << e.x << ',' << e.y;
1026  ++i;
1027  while (i < p.elementCount()) {
1028  const QPainterPath::Element &e = p.elementAt(i);
1030  --i;
1031  break;
1032  } else
1033  *d->stream << ' ';
1034  *d->stream << e.x << ',' << e.y;
1035  ++i;
1036  }
1037  break;
1038  default:
1039  break;
1040  }
1041  if (i != p.elementCount() - 1) {
1042  *d->stream << ' ';
1043  }
1044  }
1045 
1046  *d->stream << "\"/>" << endl;
1047 }
ElementType type
the type of element
Definition: qpainterpath.h:81
double d
Definition: qnumeric_p.h:62
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
QPaintEngineState * state
Definition: qpaintengine.h:239
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
#define Q_D(Class)
Definition: qglobal.h:2482
bool isCosmetic() const
Returns true if the pen is cosmetic; otherwise returns false.
Definition: qpen.cpp:840
qreal x
the x coordinate of the element&#39;s position.
Definition: qpainterpath.h:79
QPen pen() const
Returns the pen in the current paint engine state.
Definition: qpainter.cpp:9259
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)

◆ drawPixmap()

void QSvgPaintEngine::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 928 of file qsvggenerator.cpp.

930 {
931  drawImage(r, pm.toImage(), sr);
932 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlag=Qt::AutoColor)

◆ drawPolygon()

void QSvgPaintEngine::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.

Note
At least one of the drawPolygon() functions must be reimplemented.

Reimplemented from QPaintEngine.

Definition at line 1049 of file qsvggenerator.cpp.

1051 {
1052  Q_ASSERT(pointCount >= 2);
1053 
1054  //Q_D(QSvgPaintEngine);
1055 
1056  QPainterPath path(points[0]);
1057  for (int i=1; i<pointCount; ++i)
1058  path.lineTo(points[i]);
1059 
1060  if (mode == PolylineMode) {
1061  stream() << "<polyline fill=\"none\" vector-effect=\""
1062  << (state->pen().isCosmetic() ? "non-scaling-stroke" : "none")
1063  << "\" points=\"";
1064  for (int i = 0; i < pointCount; ++i) {
1065  const QPointF &pt = points[i];
1066  stream() << pt.x() << ',' << pt.y() << ' ';
1067  }
1068  stream() << "\" />" <<endl;
1069  } else {
1070  path.closeSubpath();
1071  drawPath(path);
1072  }
1073 }
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QPaintEngineState * state
Definition: qpaintengine.h:239
void drawPath(const QPainterPath &path)
The default implementation ignores the path and does nothing.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QTextStream & stream()
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
bool isCosmetic() const
Returns true if the pen is cosmetic; otherwise returns false.
Definition: qpen.cpp:840
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QPen pen() const
Returns the pen in the current paint engine state.
Definition: qpainter.cpp:9259
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)

◆ drawTextItem()

void QSvgPaintEngine::drawTextItem ( const QPointF p,
const QTextItem textItem 
)
virtual

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 1075 of file qsvggenerator.cpp.

1076 {
1078  if (d->pen.style() == Qt::NoPen)
1079  return;
1080 
1081  const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
1083 
1084  *d->stream << "<text "
1085  "fill=\"" << d->attributes.stroke << "\" "
1086  "fill-opacity=\"" << d->attributes.strokeOpacity << "\" "
1087  "stroke=\"none\" "
1088  "xml:space=\"preserve\" "
1089  "x=\"" << pt.x() << "\" y=\"" << pt.y() << "\" ";
1090  qfontToSvg(textItem.font());
1091  *d->stream << " >"
1092  << Qt::escape(s)
1093  << "</text>"
1094  << endl;
1095 }
double d
Definition: qnumeric_p.h:62
const QChar * chars
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
static QString fromRawData(const QChar *, int size)
Constructs a QString that uses the first size Unicode characters in the array unicode.
Definition: qstring.cpp:7673
Internal QTextItem.
Q_GUI_EXPORT QString escape(const QString &plain)
Converts the plain text string plain to a HTML string with HTML metacharacters <, >...
QFont font() const
Returns the font that should be used to draw the text.
void qfontToSvg(const QFont &sfont)
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)

◆ end()

bool QSvgPaintEngine::end ( )
virtual

Reimplement this function to finish painting on the current paint device.

Return true if painting was finished successfully; otherwise return false.

See also
begin() isActive()

Implements QPaintEngine.

Definition at line 902 of file qsvggenerator.cpp.

903 {
905 
906  d->stream->setString(&d->defs);
907  *d->stream << "</defs>\n";
908 
909  d->stream->setDevice(d->outputDevice);
910 #ifndef QT_NO_TEXTCODEC
911  d->stream->setCodec(QTextCodec::codecForName("UTF-8"));
912 #endif
913 
914  *d->stream << d->header;
915  *d->stream << d->defs;
916  *d->stream << d->body;
917  if (d->afterFirstUpdate)
918  *d->stream << "</g>" << endl; // close the updateState
919 
920  *d->stream << "</g>" << endl // close the Qt defaults
921  << "</svg>" << endl;
922 
923  delete d->stream;
924 
925  return true;
926 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static QTextCodec * codecForName(const QByteArray &name)
Searches all installed QTextCodec objects and returns the one which best matches name; the match is c...
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)

◆ generateQtDefaults()

void QSvgPaintEngine::generateQtDefaults ( )
inline

Definition at line 309 of file qsvggenerator.cpp.

310  {
311  *d_func()->stream << QLatin1String("fill=\"none\" ");
312  *d_func()->stream << QLatin1String("stroke=\"black\" ");
313  *d_func()->stream << QLatin1String("stroke-width=\"1\" ");
314  *d_func()->stream << QLatin1String("fill-rule=\"evenodd\" ");
315  *d_func()->stream << QLatin1String("stroke-linecap=\"square\" ");
316  *d_func()->stream << QLatin1String("stroke-linejoin=\"bevel\" ");
317  *d_func()->stream << QLatin1String(">\n");
318  }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ outputDevice()

QIODevice* QSvgPaintEngine::outputDevice ( ) const
inline

Definition at line 204 of file qsvggenerator.cpp.

204 { return d_func()->outputDevice; }

◆ popGroup()

void QSvgPaintEngine::popGroup ( )

◆ qbrushToSvg()

void QSvgPaintEngine::qbrushToSvg ( const QBrush sbrush)
inline

Definition at line 419 of file qsvggenerator.cpp.

420  {
421  d_func()->brush = sbrush;
422  switch (sbrush.style()) {
423  case Qt::SolidPattern: {
424  QString color, colorOpacity;
425  translate_color(sbrush.color(), &color, &colorOpacity);
426  stream() << "fill=\"" << color << "\" "
427  "fill-opacity=\""
428  << colorOpacity << "\" ";
429  d_func()->attributes.fill = color;
430  d_func()->attributes.fillOpacity = colorOpacity;
431  }
432  break;
435  d_func()->attributes.fill = QString::fromLatin1("url(#%1)").arg(d_func()->currentGradientName);
436  d_func()->attributes.fillOpacity = QString();
437  stream() << QLatin1String("fill=\"url(#") << d_func()->currentGradientName << QLatin1String(")\" ");
438  break;
441  d_func()->attributes.fill = QString::fromLatin1("url(#%1)").arg(d_func()->currentGradientName);
442  d_func()->attributes.fillOpacity = QString();
443  stream() << QLatin1String("fill=\"url(#") << d_func()->currentGradientName << QLatin1String(")\" ");
444  break;
447  d_func()->attributes.fill = QString::fromLatin1("url(#%1)").arg(d_func()->currentGradientName);
448  d_func()->attributes.fillOpacity = QString();
449  stream() << QLatin1String("fill=\"url(#") << d_func()->currentGradientName << QLatin1String(")\" ");
450  break;
451  case Qt::NoBrush:
452  stream() << QLatin1String("fill=\"none\" ");
453  d_func()->attributes.fill = QLatin1String("none");
454  d_func()->attributes.fillOpacity = QString();
455  return;
456  break;
457  default:
458  break;
459  }
460  }
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
QTextStream & stream()
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static void translate_color(const QColor &color, QString *color_string, QString *opacity_string)
The QString class provides a Unicode character string.
Definition: qstring.h:83
void saveConicalGradientBrush(const QGradient *)
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
void saveLinearGradientBrush(const QGradient *g)
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QString & fill(QChar c, int size=-1)
Sets every character in the string to character ch.
Definition: qstring.cpp:4641
void saveRadialGradientBrush(const QGradient *g)

◆ qfontToSvg()

void QSvgPaintEngine::qfontToSvg ( const QFont sfont)
inline

Definition at line 461 of file qsvggenerator.cpp.

462  {
464 
465  d->font = sfont;
466 
467  if (d->font.pixelSize() == -1)
468  d->attributes.font_size = QString::number(d->font.pointSizeF() * d->resolution / 72);
469  else
470  d->attributes.font_size = QString::number(d->font.pixelSize());
471 
472  int svgWeight = d->font.weight();
473  switch (svgWeight) {
474  case QFont::Light:
475  svgWeight = 100;
476  break;
477  case QFont::Normal:
478  svgWeight = 400;
479  break;
480  case QFont::Bold:
481  svgWeight = 700;
482  break;
483  default:
484  svgWeight *= 10;
485  }
486 
487  d->attributes.font_weight = QString::number(svgWeight);
488  d->attributes.font_family = d->font.family();
489  d->attributes.font_style = d->font.italic() ? QLatin1String("italic") : QLatin1String("normal");
490 
491  *d->stream << "font-family=\"" << d->attributes.font_family << "\" "
492  "font-size=\"" << d->attributes.font_size << "\" "
493  "font-weight=\"" << d->attributes.font_weight << "\" "
494  "font-style=\"" << d->attributes.font_style << "\" "
495  << endl;
496  }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
double d
Definition: qnumeric_p.h:62
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_D(Class)
Definition: qglobal.h:2482
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)

◆ qpenToSvg()

void QSvgPaintEngine::qpenToSvg ( const QPen spen)
inline

Definition at line 325 of file qsvggenerator.cpp.

326  {
327  QString width;
328 
329  d_func()->pen = spen;
330 
331  switch (spen.style()) {
332  case Qt::NoPen:
333  stream() << QLatin1String("stroke=\"none\" ");
334 
335  d_func()->attributes.stroke = QLatin1String("none");
336  d_func()->attributes.strokeOpacity = QString();
337  return;
338  break;
339  case Qt::SolidLine: {
340  QString color, colorOpacity;
341 
342  translate_color(spen.color(), &color,
343  &colorOpacity);
344  d_func()->attributes.stroke = color;
345  d_func()->attributes.strokeOpacity = colorOpacity;
346 
347  stream() << QLatin1String("stroke=\"")<<color<< QLatin1String("\" ");
348  stream() << QLatin1String("stroke-opacity=\"")<<colorOpacity<< QLatin1String("\" ");
349  }
350  break;
351  case Qt::DashLine:
352  case Qt::DotLine:
353  case Qt::DashDotLine:
354  case Qt::DashDotDotLine:
355  case Qt::CustomDashLine: {
356  QString color, colorOpacity, dashPattern, dashOffset;
357 
358  qreal penWidth = spen.width() == 0 ? qreal(1) : spen.widthF();
359 
360  translate_color(spen.color(), &color, &colorOpacity);
361  translate_dashPattern(spen.dashPattern(), penWidth, &dashPattern);
362 
363  // SVG uses absolute offset
364  dashOffset = QString::number(spen.dashOffset() * penWidth);
365 
366  d_func()->attributes.stroke = color;
367  d_func()->attributes.strokeOpacity = colorOpacity;
368  d_func()->attributes.dashPattern = dashPattern;
369  d_func()->attributes.dashOffset = dashOffset;
370 
371  stream() << QLatin1String("stroke=\"")<<color<< QLatin1String("\" ");
372  stream() << QLatin1String("stroke-opacity=\"")<<colorOpacity<< QLatin1String("\" ");
373  stream() << QLatin1String("stroke-dasharray=\"")<<dashPattern<< QLatin1String("\" ");
374  stream() << QLatin1String("stroke-dashoffset=\"")<<dashOffset<< QLatin1String("\" ");
375  break;
376  }
377  default:
378  qWarning("Unsupported pen style");
379  break;
380  }
381 
382  if (spen.widthF() == 0)
383  stream() <<"stroke-width=\"1\" ";
384  else
385  stream() <<"stroke-width=\"" << spen.widthF() << "\" ";
386 
387  switch (spen.capStyle()) {
388  case Qt::FlatCap:
389  stream() << "stroke-linecap=\"butt\" ";
390  break;
391  case Qt::SquareCap:
392  stream() << "stroke-linecap=\"square\" ";
393  break;
394  case Qt::RoundCap:
395  stream() << "stroke-linecap=\"round\" ";
396  break;
397  default:
398  qWarning("Unhandled cap style");
399  }
400  switch (spen.joinStyle()) {
401  case Qt::MiterJoin:
402  stream() << "stroke-linejoin=\"miter\" "
403  "stroke-miterlimit=\""<<spen.miterLimit()<<"\" ";
404  break;
405  case Qt::BevelJoin:
406  stream() << "stroke-linejoin=\"bevel\" ";
407  break;
408  case Qt::RoundJoin:
409  stream() << "stroke-linejoin=\"round\" ";
410  break;
411  case Qt::SvgMiterJoin:
412  stream() << "stroke-linejoin=\"miter\" "
413  "stroke-miterlimit=\""<<spen.miterLimit()<<"\" ";
414  break;
415  default:
416  qWarning("Unhandled join style");
417  }
418  }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
double qreal
Definition: qglobal.h:1193
static void translate_dashPattern(QVector< qreal > pattern, const qreal &width, QString *pattern_string)
Qt::PenStyle style() const
Returns the pen style.
Definition: qpen.cpp:428
QColor color() const
Returns the color of this pen&#39;s brush.
Definition: qpen.cpp:771
QTextStream & stream()
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static void translate_color(const QColor &color, QString *color_string, QString *opacity_string)
The QString class provides a Unicode character string.
Definition: qstring.h:83
QVector< qreal > dashPattern() const
Returns the dash pattern of this pen.
Definition: qpen.cpp:466
Qt::PenJoinStyle joinStyle() const
Returns the pen&#39;s join style.
Definition: qpen.cpp:736
Q_CORE_EXPORT void qWarning(const char *,...)
int width() const
Returns the pen width with integer precision.
Definition: qpen.cpp:630
qreal miterLimit() const
Returns the miter limit of the pen.
Definition: qpen.cpp:589
qreal widthF() const
Returns the pen width with floating point precision.
Definition: qpen.cpp:645
qreal dashOffset() const
Returns the dash offset for the pen.
Definition: qpen.cpp:547
Qt::PenCapStyle capStyle() const
Returns the pen&#39;s cap style.
Definition: qpen.cpp:706

◆ resolution()

int QSvgPaintEngine::resolution ( )
inline

Definition at line 210 of file qsvggenerator.cpp.

210 { return d_func()->resolution; }

◆ saveConicalGradientBrush()

void QSvgPaintEngine::saveConicalGradientBrush ( const QGradient )
inline

Definition at line 249 of file qsvggenerator.cpp.

250  {
251  qWarning("svg's don't support conical gradients!");
252  }
Q_CORE_EXPORT void qWarning(const char *,...)

◆ saveGradientStops()

void QSvgPaintEngine::saveGradientStops ( QTextStream str,
const QGradient g 
)
inline

Definition at line 254 of file qsvggenerator.cpp.

254  {
255  QGradientStops stops = g->stops();
256 
258  bool constantAlpha = true;
259  int alpha = stops.at(0).second.alpha();
260  for (int i = 1; i < stops.size(); ++i)
261  constantAlpha &= (stops.at(i).second.alpha() == alpha);
262 
263  if (!constantAlpha) {
264  const qreal spacing = qreal(0.02);
265  QGradientStops newStops;
266  QRgb fromColor = PREMUL(stops.at(0).second.rgba());
267  QRgb toColor;
268  for (int i = 0; i + 1 < stops.size(); ++i) {
269  int parts = qCeil((stops.at(i + 1).first - stops.at(i).first) / spacing);
270  newStops.append(stops.at(i));
271  toColor = PREMUL(stops.at(i + 1).second.rgba());
272 
273  if (parts > 1) {
274  qreal step = (stops.at(i + 1).first - stops.at(i).first) / parts;
275  for (int j = 1; j < parts; ++j) {
276  QRgb color = INV_PREMUL(INTERPOLATE_PIXEL_256(fromColor, 256 - 256 * j / parts, toColor, 256 * j / parts));
277  newStops.append(QGradientStop(stops.at(i).first + j * step, QColor::fromRgba(color)));
278  }
279  }
280  fromColor = toColor;
281  }
282  newStops.append(stops.back());
283  stops = newStops;
284  }
285  }
286 
287  foreach(QGradientStop stop, stops) {
288  QString color =
289  QString::fromLatin1("#%1%2%3")
290  .arg(stop.second.red(), 2, 16, QLatin1Char('0'))
291  .arg(stop.second.green(), 2, 16, QLatin1Char('0'))
292  .arg(stop.second.blue(), 2, 16, QLatin1Char('0'));
293  str << QLatin1String(" <stop offset=\"")<< stop.first << QLatin1String("\" ")
294  << QLatin1String("stop-color=\"") << color << QLatin1String("\" ")
295  << QLatin1String("stop-opacity=\"") << stop.second.alphaF() <<QLatin1String("\" />\n");
296  }
297  }
unsigned int QRgb
Definition: qrgb.h:53
double qreal
Definition: qglobal.h:1193
int qCeil(qreal v)
Definition: qmath.h:63
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
InterpolationMode interpolationMode() const
Returns the interpolation mode of this gradient.
Definition: qbrush.cpp:1607
QGradientStops stops() const
Returns the stop points for this gradient.
Definition: qbrush.cpp:1520
static QColor fromRgba(QRgb rgba)
Static convenience function that returns a QColor constructed from the given QRgb value rgba...
Definition: qcolor.cpp:1974
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
Q_STATIC_INLINE_FUNCTION uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b)
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
QPair< qreal, QColor > QGradientStop
Definition: qbrush.h:196
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
reference back()
This function is provided for STL compatibility.
Definition: qvector.h:289
#define INV_PREMUL(p)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ saveGradientUnits()

void QSvgPaintEngine::saveGradientUnits ( QTextStream str,
const QGradient gradient 
)
inline

Definition at line 299 of file qsvggenerator.cpp.

300  {
301  str << QLatin1String("gradientUnits=\"");
302  if (gradient && gradient->coordinateMode() == QGradient::ObjectBoundingMode)
303  str << QLatin1String("objectBoundingBox");
304  else
305  str << QLatin1String("userSpaceOnUse");
306  str << QLatin1String("\" ");
307  }
CoordinateMode coordinateMode() const
Returns the coordinate mode of this gradient.
Definition: qbrush.cpp:1563
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ saveLinearGradientBrush()

void QSvgPaintEngine::saveLinearGradientBrush ( const QGradient g)
inline

Definition at line 215 of file qsvggenerator.cpp.

216  {
217  QTextStream str(&d_func()->defs, QIODevice::Append);
218  const QLinearGradient *grad = static_cast<const QLinearGradient*>(g);
219  str << QLatin1String("<linearGradient ");
220  saveGradientUnits(str, g);
221  if (grad) {
222  str << QLatin1String("x1=\"") <<grad->start().x()<< QLatin1String("\" ")
223  << QLatin1String("y1=\"") <<grad->start().y()<< QLatin1String("\" ")
224  << QLatin1String("x2=\"") <<grad->finalStop().x() << QLatin1String("\" ")
225  << QLatin1String("y2=\"") <<grad->finalStop().y() << QLatin1String("\" ");
226  }
227 
228  str << QLatin1String("id=\"") << d_func()->generateGradientName() << QLatin1String("\">\n");
229  saveGradientStops(str, g);
230  str << QLatin1String("</linearGradient>") <<endl;
231  }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void saveGradientUnits(QTextStream &str, const QGradient *gradient)
void saveGradientStops(QTextStream &str, const QGradient *g)
QPointF start() const
Returns the start point of this linear gradient in logical coordinates.
Definition: qbrush.cpp:1796
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
The QLinearGradient class is used in combination with QBrush to specify a linear gradient brush...
Definition: qbrush.h:280
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QPointF finalStop() const
Returns the final stop point of this linear gradient in logical coordinates.
Definition: qbrush.cpp:1856
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)

◆ saveRadialGradientBrush()

void QSvgPaintEngine::saveRadialGradientBrush ( const QGradient g)
inline

Definition at line 232 of file qsvggenerator.cpp.

233  {
234  QTextStream str(&d_func()->defs, QIODevice::Append);
235  const QRadialGradient *grad = static_cast<const QRadialGradient*>(g);
236  str << QLatin1String("<radialGradient ");
237  saveGradientUnits(str, g);
238  if (grad) {
239  str << QLatin1String("cx=\"") <<grad->center().x()<< QLatin1String("\" ")
240  << QLatin1String("cy=\"") <<grad->center().y()<< QLatin1String("\" ")
241  << QLatin1String("r=\"") <<grad->radius() << QLatin1String("\" ")
242  << QLatin1String("fx=\"") <<grad->focalPoint().x() << QLatin1String("\" ")
243  << QLatin1String("fy=\"") <<grad->focalPoint().y() << QLatin1String("\" ");
244  }
245  str << QLatin1String("xml:id=\"") <<d_func()->generateGradientName()<< QLatin1String("\">\n");
246  saveGradientStops(str, g);
247  str << QLatin1String("</radialGradient>") << endl;
248  }
QPointF focalPoint() const
Returns the focal point of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2251
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QRadialGradient class is used in combination with QBrush to specify a radial gradient brush...
Definition: qbrush.h:297
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void saveGradientUnits(QTextStream &str, const QGradient *gradient)
void saveGradientStops(QTextStream &str, const QGradient *g)
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
qreal radius() const
Returns the radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2150
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QPointF center() const
Returns the center of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2102
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)

◆ setDocumentDescription()

void QSvgPaintEngine::setDocumentDescription ( const QString description)
inline

Definition at line 200 of file qsvggenerator.cpp.

200  {
201  d_func()->attributes.document_description = description;
202  }

◆ setDocumentTitle()

void QSvgPaintEngine::setDocumentTitle ( const QString title)
inline

Definition at line 195 of file qsvggenerator.cpp.

195  {
196  d_func()->attributes.document_title = title;
197  }

◆ setOutputDevice()

void QSvgPaintEngine::setOutputDevice ( QIODevice device)
inline

Definition at line 205 of file qsvggenerator.cpp.

205  {
206  Q_ASSERT(!isActive());
207  d_func()->outputDevice = device;
208  }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154

◆ setResolution()

void QSvgPaintEngine::setResolution ( int  resolution)
inline

Definition at line 211 of file qsvggenerator.cpp.

211  {
212  Q_ASSERT(!isActive());
213  d_func()->resolution = resolution;
214  }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154

◆ setSize()

void QSvgPaintEngine::setSize ( const QSize size)
inline

Definition at line 183 of file qsvggenerator.cpp.

183  {
184  Q_ASSERT(!isActive());
185  d_func()->size = size;
186  }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154
QSize size() const

◆ setViewBox()

void QSvgPaintEngine::setViewBox ( const QRectF viewBox)
inline

Definition at line 189 of file qsvggenerator.cpp.

189  {
190  Q_ASSERT(!isActive());
191  d_func()->viewBox = viewBox;
192  }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154
QRectF viewBox() const

◆ size()

QSize QSvgPaintEngine::size ( ) const
inline

Definition at line 182 of file qsvggenerator.cpp.

182 { return d_func()->size; }

◆ stream()

QTextStream& QSvgPaintEngine::stream ( )
inline

Definition at line 319 of file qsvggenerator.cpp.

320  {
321  return *d_func()->stream;
322  }

◆ type()

QPaintEngine::Type QSvgPaintEngine::type ( ) const
inlinevirtual

Reimplement this function to return the paint engine Type.

Implements QPaintEngine.

Definition at line 180 of file qsvggenerator.cpp.

◆ updateState()

void QSvgPaintEngine::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.

See also
QPaintEngineState

Implements QPaintEngine.

Definition at line 959 of file qsvggenerator.cpp.

960 {
962  QPaintEngine::DirtyFlags flags = state.state();
963 
964  // always stream full gstate, which is not required, but...
965  flags |= QPaintEngine::AllDirty;
966 
967  // close old state and start a new one...
968  if (d->afterFirstUpdate)
969  *d->stream << "</g>\n\n";
970 
971  *d->stream << "<g ";
972 
973  if (flags & QPaintEngine::DirtyBrush) {
974  qbrushToSvg(state.brush());
975  }
976 
977  if (flags & QPaintEngine::DirtyPen) {
978  qpenToSvg(state.pen());
979  }
980 
981  if (flags & QPaintEngine::DirtyTransform) {
982  d->matrix = state.matrix();
983  *d->stream << "transform=\"matrix(" << d->matrix.m11() << ','
984  << d->matrix.m12() << ','
985  << d->matrix.m21() << ',' << d->matrix.m22() << ','
986  << d->matrix.dx() << ',' << d->matrix.dy()
987  << ")\""
988  << endl;
989  }
990 
991  if (flags & QPaintEngine::DirtyFont) {
992  qfontToSvg(state.font());
993  }
994 
995  if (flags & QPaintEngine::DirtyOpacity) {
996  if (!qFuzzyIsNull(state.opacity() - 1))
997  stream() << "opacity=\""<<state.opacity()<<"\" ";
998  }
999 
1000  *d->stream << '>' << endl;
1001 
1002  d->afterFirstUpdate = true;
1003 }
double d
Definition: qnumeric_p.h:62
QPaintEngine::DirtyFlags state() const
Returns a combination of flags identifying the set of properties that need to be updated when updatin...
Definition: qpaintengine.h:292
qreal opacity() const
Returns the opacity in the current paint engine state.
Definition: qpainter.cpp:9529
QTextStream & stream()
void qbrushToSvg(const QBrush &sbrush)
void qpenToSvg(const QPen &spen)
QMatrix matrix() const
Returns the matrix in the current paint engine state.
Definition: qpainter.cpp:9355
#define Q_D(Class)
Definition: qglobal.h:2482
QBrush brush() const
Returns the brush in the current paint engine state.
Definition: qpainter.cpp:9273
QFont font() const
Returns the font in the current paint engine state.
Definition: qpainter.cpp:9331
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
QPen pen() const
Returns the pen in the current paint engine state.
Definition: qpainter.cpp:9259
void qfontToSvg(const QFont &sfont)
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)

◆ viewBox()

QRectF QSvgPaintEngine::viewBox ( ) const
inline

Definition at line 188 of file qsvggenerator.cpp.

188 { return d_func()->viewBox; }

The documentation for this class was generated from the following file: