Qt 4.8
qsvggraphics.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSvg module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qsvggraphics_p.h"
43 
44 #ifndef QT_NO_SVG
45 
46 #include "qsvgfont_p.h"
47 
48 #include "qpainter.h"
49 #include "qtextdocument.h"
51 #include "qtextcursor.h"
52 #include "qdebug.h"
53 
54 #include <math.h>
55 #include <limits.h>
56 
58 
59 #define QT_SVG_DRAW_SHAPE(command) \
60  qreal oldOpacity = p->opacity(); \
61  QBrush oldBrush = p->brush(); \
62  QPen oldPen = p->pen(); \
63  p->setPen(Qt::NoPen); \
64  p->setOpacity(oldOpacity * states.fillOpacity); \
65  command; \
66  p->setPen(oldPen); \
67  if (oldPen.widthF() != 0) { \
68  p->setOpacity(oldOpacity * states.strokeOpacity); \
69  p->setBrush(Qt::NoBrush); \
70  command; \
71  p->setBrush(oldBrush); \
72  } \
73  p->setOpacity(oldOpacity);
74 
75 
77 {
78  qWarning("<animation> no implemented");
79 }
80 
81 static inline QRectF boundsOnStroke(QPainter *p, const QPainterPath &path, qreal width)
82 {
83  QPainterPathStroker stroker;
84  stroker.setWidth(width);
85  QPainterPath stroke = stroker.createStroke(path);
86  return p->transform().map(stroke).boundingRect();
87 }
88 
90  : QSvgNode(parent), m_bounds(rect)
91 {
92 }
93 
94 
96 {
97  QPainterPath path;
98  path.addEllipse(m_bounds);
99  qreal sw = strokeWidth(p);
100  return qFuzzyIsNull(sw) ? p->transform().map(path).boundingRect() : boundsOnStroke(p, path, sw);
101 }
102 
104 {
105  applyStyle(p, states);
107  revertStyle(p, states);
108 }
109 
111  : QSvgNode(parent), m_path(path)
112 {
113 }
114 
116 {
117  applyStyle(p, states);
118  if (p->pen().widthF() != 0) {
119  qreal oldOpacity = p->opacity();
120  p->setOpacity(oldOpacity * states.strokeOpacity);
121  p->drawPath(m_path);
122  p->setOpacity(oldOpacity);
123  }
124  revertStyle(p, states);
125 }
126 
128  const QRect &bounds)
129  : QSvgNode(parent), m_image(image),
130  m_bounds(bounds)
131 {
132  if (m_bounds.width() == 0)
134  if (m_bounds.height() == 0)
136 }
137 
139 {
140  applyStyle(p, states);
142  revertStyle(p, states);
143 }
144 
145 
147  : QSvgNode(parent), m_line(line)
148 {
149 }
150 
151 
153 {
154  applyStyle(p, states);
155  if (p->pen().widthF() != 0) {
156  qreal oldOpacity = p->opacity();
157  p->setOpacity(oldOpacity * states.strokeOpacity);
158  p->drawLine(m_line);
159  p->setOpacity(oldOpacity);
160  }
161  revertStyle(p, states);
162 }
163 
165  : QSvgNode(parent), m_path(qpath)
166 {
167 }
168 
170 {
171  applyStyle(p, states);
172  m_path.setFillRule(states.fillRule);
174  revertStyle(p, states);
175 }
176 
178 {
179  qreal sw = strokeWidth(p);
180  return qFuzzyIsNull(sw) ? p->transform().map(m_path).boundingRect()
181  : boundsOnStroke(p, m_path, sw);
182 }
183 
185  : QSvgNode(parent), m_poly(poly)
186 {
187 }
188 
190 {
191  qreal sw = strokeWidth(p);
192  if (qFuzzyIsNull(sw)) {
193  return p->transform().map(m_poly).boundingRect();
194  } else {
195  QPainterPath path;
196  path.addPolygon(m_poly);
197  return boundsOnStroke(p, path, sw);
198  }
199 }
200 
202 {
203  applyStyle(p, states);
205  revertStyle(p, states);
206 }
207 
208 
210  : QSvgNode(parent), m_poly(poly)
211 {
212 
213 }
214 
216 {
217  applyStyle(p, states);
218  qreal oldOpacity = p->opacity();
219  if (p->brush().style() != Qt::NoBrush) {
220  QPen save = p->pen();
221  p->setPen(QPen(Qt::NoPen));
222  p->setOpacity(oldOpacity * states.fillOpacity);
223  p->drawPolygon(m_poly, states.fillRule);
224  p->setPen(save);
225  }
226  if (p->pen().widthF() != 0) {
227  p->setOpacity(oldOpacity * states.strokeOpacity);
228  p->drawPolyline(m_poly);
229  }
230  p->setOpacity(oldOpacity);
231  revertStyle(p, states);
232 }
233 
234 QSvgRect::QSvgRect(QSvgNode *node, const QRectF &rect, int rx, int ry)
235  : QSvgNode(node),
236  m_rect(rect), m_rx(rx), m_ry(ry)
237 {
238 }
239 
241 {
242  qreal sw = strokeWidth(p);
243  if (qFuzzyIsNull(sw)) {
244  return p->transform().mapRect(m_rect);
245  } else {
246  QPainterPath path;
247  path.addRect(m_rect);
248  return boundsOnStroke(p, path, sw);
249  }
250 }
251 
253 {
254  applyStyle(p, states);
255  if (m_rx || m_ry) {
257  } else {
259  }
260  revertStyle(p, states);
261 }
262 
263 QSvgTspan * const QSvgText::LINEBREAK = 0;
264 
266  : QSvgNode(parent)
267  , m_coord(coord)
268  , m_type(TEXT)
269  , m_size(0, 0)
270  , m_mode(Default)
271 {
272 }
273 
275 {
276  for (int i = 0; i < m_tspans.size(); ++i) {
277  if (m_tspans[i] != LINEBREAK)
278  delete m_tspans[i];
279  }
280 }
281 
282 void QSvgText::setTextArea(const QSizeF &size)
283 {
284  m_size = size;
285  m_type = TEXTAREA;
286 }
287 
288 //QRectF QSvgText::bounds(QPainter *p, QSvgExtraStates &) const {}
289 
291 {
292  applyStyle(p, states);
293  qreal oldOpacity = p->opacity();
294  p->setOpacity(oldOpacity * states.fillOpacity);
295 
296  // Force the font to have a size of 100 pixels to avoid truncation problems
297  // when the font is very small.
298  qreal scale = 100.0 / p->font().pointSizeF();
299  Qt::Alignment alignment = states.textAnchor;
300 
301  QTransform oldTransform = p->worldTransform();
302  p->scale(1 / scale, 1 / scale);
303 
304  qreal y = 0;
305  bool initial = true;
306  qreal px = m_coord.x() * scale;
307  qreal py = m_coord.y() * scale;
308  QSizeF scaledSize = m_size * scale;
309 
310  if (m_type == TEXTAREA) {
311  if (alignment == Qt::AlignHCenter)
312  px += scaledSize.width() / 2;
313  else if (alignment == Qt::AlignRight)
314  px += scaledSize.width();
315  }
316 
317  QRectF bounds;
318  if (m_size.height() != 0)
319  bounds = QRectF(0, py, 1, scaledSize.height()); // x and width are not used.
320 
321  bool appendSpace = false;
322  QVector<QString> paragraphs;
323  QStack<QTextCharFormat> formats;
325  paragraphs.push_back(QString());
327 
328  for (int i = 0; i < m_tspans.size(); ++i) {
329  if (m_tspans[i] == LINEBREAK) {
330  if (m_type == TEXTAREA) {
331  if (paragraphs.back().isEmpty()) {
332  QFont font = p->font();
333  font.setPixelSize(font.pointSizeF() * scale);
334 
336  range.start = 0;
337  range.length = 1;
338  range.format.setFont(font);
339  formatRanges.back().append(range);
340 
341  paragraphs.back().append(QLatin1Char(' '));;
342  }
343  appendSpace = false;
344  paragraphs.push_back(QString());
346  }
347  } else {
348  WhitespaceMode mode = m_tspans[i]->whitespaceMode();
349  m_tspans[i]->applyStyle(p, states);
350 
351  QFont font = p->font();
352  font.setPixelSize(font.pointSizeF() * scale);
353 
354  QString newText(m_tspans[i]->text());
355  newText.replace(QLatin1Char('\t'), QLatin1Char(' '));
356  newText.replace(QLatin1Char('\n'), QLatin1Char(' '));
357 
358  bool prependSpace = !appendSpace && !m_tspans[i]->isTspan() && (mode == Default) && !paragraphs.back().isEmpty() && newText.startsWith(QLatin1Char(' '));
359  if (appendSpace || prependSpace)
360  paragraphs.back().append(QLatin1Char(' '));
361 
362  bool appendSpaceNext = (!m_tspans[i]->isTspan() && (mode == Default) && newText.endsWith(QLatin1Char(' ')));
363 
364  if (mode == Default) {
365  newText = newText.simplified();
366  if (newText.isEmpty())
367  appendSpaceNext = false;
368  }
369 
371  range.start = paragraphs.back().length();
372  range.length = newText.length();
373  range.format.setFont(font);
374  range.format.setTextOutline(p->pen());
375  range.format.setForeground(p->brush());
376 
377  if (appendSpace) {
378  Q_ASSERT(!formatRanges.back().isEmpty());
379  ++formatRanges.back().back().length;
380  } else if (prependSpace) {
381  --range.start;
382  ++range.length;
383  }
384  formatRanges.back().append(range);
385 
386  appendSpace = appendSpaceNext;
387  paragraphs.back() += newText;
388 
389  m_tspans[i]->revertStyle(p, states);
390  }
391  }
392 
393  if (states.svgFont) {
394  // SVG fonts not fully supported...
395  QString text = paragraphs.front();
396  for (int i = 1; i < paragraphs.size(); ++i) {
397  text.append(QLatin1Char('\n'));
398  text.append(paragraphs[i]);
399  }
400  states.svgFont->draw(p, m_coord * scale, text, p->font().pointSizeF() * scale, states.textAnchor);
401  } else {
402  for (int i = 0; i < paragraphs.size(); ++i) {
403  QTextLayout tl(paragraphs[i]);
404  QTextOption op = tl.textOption();
406  tl.setTextOption(op);
407  tl.setAdditionalFormats(formatRanges[i]);
408  tl.beginLayout();
409 
410  forever {
411  QTextLine line = tl.createLine();
412  if (!line.isValid())
413  break;
414  if (m_size.width() != 0)
415  line.setLineWidth(scaledSize.width());
416  }
417  tl.endLayout();
418 
419  bool endOfBoundsReached = false;
420  for (int i = 0; i < tl.lineCount(); ++i) {
421  QTextLine line = tl.lineAt(i);
422 
423  qreal x = 0;
424  if (alignment == Qt::AlignHCenter)
425  x -= 0.5 * line.naturalTextWidth();
426  else if (alignment == Qt::AlignRight)
427  x -= line.naturalTextWidth();
428 
429  if (initial && m_type == TEXT)
430  y -= line.ascent();
431  initial = false;
432 
433  line.setPosition(QPointF(x, y));
434 
435  // Check if the current line fits into the bounding rectangle.
436  if ((m_size.width() != 0 && line.naturalTextWidth() > scaledSize.width())
437  || (m_size.height() != 0 && y + line.height() > scaledSize.height())) {
438  // I need to set the bounds height to 'y-epsilon' to avoid drawing the current
439  // line. Since the font is scaled to 100 units, 1 should be a safe epsilon.
440  bounds.setHeight(y - 1);
441  endOfBoundsReached = true;
442  break;
443  }
444 
445  y += 1.1 * line.height();
446  }
447  tl.draw(p, QPointF(px, py), QVector<QTextLayout::FormatRange>(), bounds);
448 
449  if (endOfBoundsReached)
450  break;
451  }
452  }
453 
454  p->setWorldTransform(oldTransform, false);
455  p->setOpacity(oldOpacity);
456  revertStyle(p, states);
457 }
458 
460 {
461  m_tspans.append(new QSvgTspan(this, false));
463  m_tspans.back()->addText(text);
464 }
465 
467  : QSvgNode(parent), m_link(node), m_start(start)
468 {
469 
470 }
471 
473 {
474  applyStyle(p, states);
475 
476  if (!m_start.isNull()) {
477  p->translate(m_start);
478  }
479  m_link->draw(p, states);
480  if (!m_start.isNull()) {
481  p->translate(-m_start);
482  }
483 
484  revertStyle(p, states);
485 }
486 
488 {
489  applyStyle(p, states);
490 
491  revertStyle(p, states);
492 }
493 
495 {
496  return ANIMATION;
497 }
498 
500 {
501  return ARC;
502 }
503 
505 {
506  return CIRCLE;
507 }
508 
510 {
511  return ELLIPSE;
512 }
513 
515 {
516  return IMAGE;
517 }
518 
520 {
521  return LINE;
522 }
523 
525 {
526  return PATH;
527 }
528 
530 {
531  return POLYGON;
532 }
533 
535 {
536  return POLYLINE;
537 }
538 
540 {
541  return RECT;
542 }
543 
545 {
546  return m_type;
547 }
548 
550 {
551  return USE;
552 }
553 
555 {
556  return VIDEO;
557 }
558 
560 {
561  QRectF bounds;
562  if (m_link) {
563  p->translate(m_start);
564  bounds = m_link->transformedBounds(p, states);
565  p->translate(-m_start);
566  }
567  return bounds;
568 }
569 
571 {
572  qreal sw = strokeWidth(p);
573  if (qFuzzyIsNull(sw)) {
574  return p->transform().map(m_poly).boundingRect();
575  } else {
576  QPainterPath path;
577  path.addPolygon(m_poly);
578  return boundsOnStroke(p, path, sw);
579  }
580 }
581 
583 {
584  qreal sw = strokeWidth(p);
585  return qFuzzyIsNull(sw) ? p->transform().map(m_path).boundingRect()
586  : boundsOnStroke(p, m_path, sw);
587 }
588 
590 {
591  return p->transform().mapRect(m_bounds);
592 }
593 
595 {
596  qreal sw = strokeWidth(p);
597  if (qFuzzyIsNull(sw)) {
598  QPointF p1 = p->transform().map(m_line.p1());
599  QPointF p2 = p->transform().map(m_line.p2());
600  qreal minX = qMin(p1.x(), p2.x());
601  qreal minY = qMin(p1.y(), p2.y());
602  qreal maxX = qMax(p1.x(), p2.x());
603  qreal maxY = qMax(p1.y(), p2.y());
604  return QRectF(minX, minY, maxX - minX, maxY - minY);
605  } else {
606  QPainterPath path;
607  path.moveTo(m_line.p1());
608  path.lineTo(m_line.p2());
609  return boundsOnStroke(p, path, sw);
610  }
611 }
612 
614 
615 #endif // QT_NO_SVG
virtual Type type() const
QPolygonF m_poly
virtual QRectF bounds(QPainter *p, QSvgExtraStates &states) const
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
void setAdditionalFormats(const QList< FormatRange > &overrides)
Sets the additional formats supported by the text layout to formatList.
virtual QRectF transformedBounds(QPainter *p, QSvgExtraStates &states) const
Definition: qsvgnode.cpp:307
QTextOption textOption() const
Returns the current text option used to control the layout process.
The QTextLayout::FormatRange structure is used to apply extra formatting information for a specified ...
Definition: qtextlayout.h:128
virtual void draw(QPainter *p, QSvgExtraStates &states)
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling...
Definition: qpainter.cpp:3502
void setTextOutline(const QPen &pen)
Sets the pen used to draw the outlines of characters to the given pen.
Definition: qtextformat.h:489
void addText(const QString &text)
void setHeight(int h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:445
double qreal
Definition: qglobal.h:1193
void setHeight(qreal h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:787
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
virtual QRectF bounds(QPainter *p, QSvgExtraStates &states) const
const QTransform & transform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9558
qreal opacity() const
Returns the opacity of the painter.
Definition: qpainter.cpp:2115
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QSvgLine(QSvgNode *parent, const QLineF &line)
QSvgNode * m_link
void setPosition(const QPointF &pos)
Moves the line to position pos.
virtual Type type() const
QLineF m_line
virtual Type type() const
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
virtual void draw(QPainter *p, QSvgExtraStates &states)
qreal width() const
Returns the width.
Definition: qsize.h:284
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QPolygonF m_poly
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QPainterPath m_path
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal height() const
Returns the height.
Definition: qsize.h:287
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
QSvgUse(const QPointF &start, QSvgNode *parent, QSvgNode *link)
void setFont(const QFont &font)
Sets the text format&#39;s font.
QSvgArc(QSvgNode *parent, const QPainterPath &path)
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
virtual Type type() const
virtual Type type() const
The QStack class is a template class that provides a stack.
Definition: qcontainerfwd.h:63
void setLineWidth(qreal width)
Lays out the line with the given width.
void addPolygon(const QPolygonF &polygon)
Adds the given polygon to the path as an (unclosed) subpath.
void drawLine(const QLineF &line)
Draws a line defined by line.
Definition: qpainter.h:573
int start
Specifies the beginning of the format range within the text layout&#39;s text.
Definition: qtextlayout.h:129
virtual QRectF bounds(QPainter *p, QSvgExtraStates &states) const
void applyStyle(QPainter *p, QSvgExtraStates &states) const
Definition: qsvgnode.cpp:118
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QSvgNode * parent() const
Definition: qsvgnode_p.h:183
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual Type type() const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
qreal ascent() const
Returns the line&#39;s ascent.
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
QSvgRect(QSvgNode *paren, const QRectF &rect, int rx=0, int ry=0)
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QSvgPolyline(QSvgNode *parent, const QPolygonF &poly)
static const uint Default
Definition: qsplitter_p.h:61
QSvgPath(QSvgNode *parent, const QPainterPath &qpath)
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
virtual QRectF bounds(QPainter *p, QSvgExtraStates &states) const
Definition: qsvgnode.cpp:199
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
void setFillRule(Qt::FillRule fillRule)
Sets the fill rule of the painter path to the given fillRule.
virtual QRectF bounds(QPainter *p, QSvgExtraStates &states) const
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
QVector< QSvgTspan * > m_tspans
virtual QRectF bounds(QPainter *p, QSvgExtraStates &states) const
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
qreal pointSizeF() const
Returns the point size of the font.
Definition: qfont.cpp:1142
void drawEllipse(const QRectF &r)
Draws the ellipse defined by the given rectangle.
Definition: qpainter.cpp:4464
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
virtual void draw(QPainter *p, QSvgExtraStates &states)
QPainterPath createStroke(const QPainterPath &path) const
Generates a new path that is a fillable area representing the outline of the given path...
QImage m_image
QSvgText(QSvgNode *parent, const QPointF &coord)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
virtual Type type() const
const QFont & font() const
Returns the currently set font used for drawing text.
Definition: qpainter.cpp:4312
virtual void draw(QPainter *p, QSvgExtraStates &states)
QSvgEllipse(QSvgNode *parent, const QRectF &rect)
QSizeF m_size
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
Q_CORE_EXPORT void qWarning(const char *,...)
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
virtual QRectF bounds(QPainter *p, QSvgExtraStates &states) const
QSvgFont * svgFont
Definition: qsvgstyle_p.h:147
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill)
Draws the polygon defined by the first pointCount points in the array points using the current pen an...
Definition: qpainter.cpp:5205
The QPainterPathStroker class is used to generate fillable outlines for a given painter path...
Definition: qpainterpath.h:264
void draw(QPainter *p, const QPointF &pos, const QVector< FormatRange > &selections=QVector< FormatRange >(), const QRectF &clip=QRectF()) const
Draws the whole layout on the painter p at the position specified by pos.
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
static qreal strokeWidth(QPainter *p)
Definition: qsvgnode.cpp:335
Qt::FillRule fillRule
Definition: qsvgstyle_p.h:150
virtual void draw(QPainter *p, QSvgExtraStates &states)
#define QT_SVG_DRAW_SHAPE(command)
QPointF m_start
void addText(const QString &text)
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
virtual void draw(QPainter *p, QSvgExtraStates &states)
virtual void draw(QPainter *p, QSvgExtraStates &states)
T & front()
This function is provided for STL compatibility.
Definition: qvector.h:287
WhitespaceMode m_mode
virtual void draw(QPainter *p, QSvgExtraStates &states)
const QBrush & brush() const
Returns the painter&#39;s current brush.
Definition: qpainter.cpp:4232
QRect m_bounds
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
QString & append(QChar c)
Definition: qstring.cpp:1777
const QTransform & worldTransform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9652
virtual QRectF bounds(QPainter *p, QSvgExtraStates &states) const
QRectF m_rect
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
Definition: qstring.cpp:4415
QSvgPolygon(QSvgNode *parent, const QPolygonF &poly)
QPointF m_coord
QTextLine createLine()
Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise ret...
qreal naturalTextWidth() const
Returns the width of the line that is occupied by text.
virtual Type type() const
virtual QRectF bounds(QPainter *p, QSvgExtraStates &states) const
void setTextOption(const QTextOption &option)
Sets the text option structure that controls the layout process to the given option.
virtual void draw(QPainter *p, QSvgExtraStates &states)
static QRectF boundsOnStroke(QPainter *p, const QPainterPath &path, qreal width)
QSvgImage(QSvgNode *parent, const QImage &image, const QRect &bounds)
void draw(QPainter *p, const QPointF &point, const QString &str, qreal pixelSize, Qt::Alignment alignment) const
Definition: qsvgfont.cpp:79
reference back()
This function is provided for STL compatibility.
Definition: qvector.h:289
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
qreal widthF() const
Returns the pen width with floating point precision.
Definition: qpen.cpp:645
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static QSvgTspan *const LINEBREAK
bool isNull() const
Returns true if both the x and y coordinates are set to +0.
Definition: qpoint.h:277
void push_back(const T &t)
This function is provided for STL compatibility.
Definition: qvector.h:281
The QTextOption class provides a description of general rich text properties.
Definition: qtextoption.h:59
void setWorldTransform(const QTransform &matrix, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9630
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Definition: qpainter.cpp:5936
Qt::Alignment textAnchor
Definition: qsvgstyle_p.h:148
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
virtual void draw(QPainter *p, QSvgExtraStates &states)
virtual Type type() const
void scale(qreal sx, qreal sy)
Scales the coordinate system by ({sx}, {sy}).
Definition: qpainter.cpp:3234
virtual void draw(QPainter *p, QSvgExtraStates &states)=0
int length
Specifies the numer of characters the format range spans.
Definition: qtextlayout.h:130
QTextCharFormat format
Specifies the format to apply.
Definition: qtextlayout.h:131
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
void setWrapMode(WrapMode wrap)
Sets the option&#39;s text wrap mode to the given mode.
Definition: qtextoption.h:109
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
Definition: qtextformat.h:350
virtual Type type() const
virtual void draw(QPainter *p, QSvgExtraStates &states)
virtual void draw(QPainter *p, QSvgExtraStates &states)
void endLayout()
Ends the layout process.
void setOpacity(qreal opacity)
Sets the opacity of the painter to opacity.
Definition: qpainter.cpp:2139
void setTextArea(const QSizeF &size)
void setPixelSize(int)
Sets the font size to pixelSize pixels.
Definition: qfont.cpp:1156
virtual Type type() const
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
Draws the given rectangle rect with rounded corners.
Definition: qpainter.cpp:4348
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
void revertStyle(QPainter *p, QSvgExtraStates &states) const
Definition: qsvgnode.cpp:123
void drawPolyline(const QPointF *points, int pointCount)
Draws the polyline defined by the first pointCount points in points using the current pen...
Definition: qpainter.cpp:5055
QRectF m_bounds
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
qreal height() const
Returns the line&#39;s height.
void beginLayout()
Begins the layout process.
void addEllipse(const QRectF &rect)
Creates an ellipse within the specified boundingRectangle and adds it to the painter path as a closed...
QPainterPath m_path
#define text
Definition: qobjectdefs.h:80
virtual QRectF bounds(QPainter *p, QSvgExtraStates &states) const
virtual Type type() const
int lineCount() const
Returns the number of lines in this text layout.
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
void setWidth(qreal width)
Sets the width of the generated outline painter path to width.
virtual Type type() const
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311
void setWhitespaceMode(QSvgText::WhitespaceMode mode)
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452