Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsvggraphics.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
8#include "qsvgfont_p.h"
9
10#include <qabstracttextdocumentlayout.h>
11#include <qdebug.h>
12#include <qloggingcategory.h>
13#include <qpainter.h>
14#include <qscopedvaluerollback.h>
15#include <qtextcursor.h>
16#include <qtextdocument.h>
17#include <private/qfixed_p.h>
18
19#include <QElapsedTimer>
20#include <QLoggingCategory>
21
22#include <math.h>
23
24QT_BEGIN_NAMESPACE
25
26Q_LOGGING_CATEGORY(lcSvgDraw, "qt.svg.draw")
27
28#ifndef QT_SVG_MAX_LAYOUT_SIZE
29#define QT_SVG_MAX_LAYOUT_SIZE (qint64(QFIXED_MAX / 2))
30#endif
31
32QSvgDummyNode::~QSvgDummyNode()
33 = default;
34
35void QSvgDummyNode::drawCommand(QPainter *, QSvgExtraStates &)
36{
37 qWarning("Dummy node not meant to be drawn");
38}
39
40QSvgEllipse::QSvgEllipse(QSvgNode *parent, const QRectF &rect)
41 : QSvgNode(parent), m_bounds(rect)
42{
43}
44
45QSvgEllipse::~QSvgEllipse()
46 = default;
47
48QRectF QSvgEllipse::internalFastBounds(QPainter *p, QSvgExtraStates &) const
49{
50 return p->transform().mapRect(m_bounds);
51}
52
53QRectF QSvgEllipse::internalBounds(QPainter *p, QSvgExtraStates &) const
54{
55 QPainterPath path;
56 path.addEllipse(m_bounds);
57 qreal sw = strokeWidth(p);
58 return qFuzzyIsNull(sw) ? p->transform().map(path).boundingRect()
59 : boundsOnStroke(p, path, sw, BoundsMode::Simplistic);
60}
61
62QRectF QSvgEllipse::decoratedInternalBounds(QPainter *p, QSvgExtraStates &) const
63{
64 QPainterPath path;
65 path.addEllipse(m_bounds);
66 qreal sw = strokeWidth(p);
67 QRectF rect = qFuzzyIsNull(sw) ? p->transform().map(path).boundingRect()
68 : boundsOnStroke(p, path, sw, BoundsMode::IncludeMiterLimit);
69 return filterRegion(rect);
70}
71
72void QSvgEllipse::drawCommand(QPainter *p, QSvgExtraStates &)
73{
74 p->drawEllipse(m_bounds);
75}
76
77bool QSvgEllipse::separateFillStroke(const QPainter *, const QSvgExtraStates &) const
78{
79 return true;
80}
81
82QSvgImage::QSvgImage(QSvgNode *parent,
83 const QImage &image,
84 const QString &filename,
85 const QRectF &bounds)
86 : QSvgNode(parent)
87 , m_filename(filename)
88 , m_image(image)
89 , m_bounds(bounds)
90{
91 if (m_bounds.width() == 0.0)
92 m_bounds.setWidth(static_cast<qreal>(m_image.width()));
93 if (m_bounds.height() == 0.0)
94 m_bounds.setHeight(static_cast<qreal>(m_image.height()));
95}
96
97QSvgImage::~QSvgImage()
98 = default;
99
100void QSvgImage::drawCommand(QPainter *p, QSvgExtraStates &)
101{
102 p->drawImage(m_bounds, m_image);
103}
104
105QSvgLine::QSvgLine(QSvgNode *parent, const QLineF &line)
106 : QSvgNode(parent), m_line(line)
107{
108}
109
110QSvgLine::~QSvgLine()
111 = default;
112
113void QSvgLine::drawCommand(QPainter *p, QSvgExtraStates &states)
114{
115 if (p->pen().widthF() != 0) {
116 qreal oldOpacity = p->opacity();
117 p->setOpacity(oldOpacity * states.strokeOpacity);
118 if (m_line.isNull() && p->pen().capStyle() != Qt::FlatCap)
119 p->drawPoint(m_line.p1());
120 else
121 p->drawLine(m_line);
122 p->setOpacity(oldOpacity);
123 }
124 QSvgMarker::drawMarkersForNode(this, p, states);
125}
126
127QSvgPath::QSvgPath(QSvgNode *parent, const QPainterPath &qpath)
128 : QSvgNode(parent), m_path(qpath)
129{
130}
131
132QSvgPath::~QSvgPath()
133 = default;
134
135void QSvgPath::drawCommand(QPainter *p, QSvgExtraStates &states)
136{
137 const qreal oldOpacity = p->opacity();
138 const bool drawingInOnePass = !separateFillStroke(p, states);
139 if (drawingInOnePass)
140 p->setOpacity(oldOpacity * states.fillOpacity);
141 m_path.setFillRule(states.fillRule);
142 if (m_path.boundingRect().isNull() && p->pen().capStyle() != Qt::FlatCap)
143 p->drawPoint(m_path.boundingRect().topLeft());
144 else
145 p->drawPath(m_path);
146 if (!path().isEmpty())
147 QSvgMarker::drawMarkersForNode(this, p, states);
148 if (drawingInOnePass)
149 p->setOpacity(oldOpacity);
150}
151
152bool QSvgPath::separateFillStroke(const QPainter *p, const QSvgExtraStates &s) const
153{
154 return !qFuzzyCompare(s.fillOpacity, s.strokeOpacity)
155 || qFuzzyIsNull(p->pen().widthF());
156}
157
158QRectF QSvgPath::internalFastBounds(QPainter *p, QSvgExtraStates &) const
159{
160 return p->transform().mapRect(m_path.controlPointRect());
161}
162
163QRectF QSvgPath::internalBounds(QPainter *p, QSvgExtraStates &) const
164{
165 qreal sw = strokeWidth(p);
166 return qFuzzyIsNull(sw) ? p->transform().map(m_path).boundingRect()
167 : boundsOnStroke(p, m_path, sw, BoundsMode::Simplistic);
168}
169
170QRectF QSvgPath::decoratedInternalBounds(QPainter *p, QSvgExtraStates &s) const
171{
172 qreal sw = strokeWidth(p);
173 QRectF rect = qFuzzyIsNull(sw) ? p->transform().map(m_path).boundingRect()
174 : boundsOnStroke(p, m_path, sw, BoundsMode::IncludeMiterLimit);
175 rect |= QSvgMarker::markersBoundsForNode(this, p, s);
176 return filterRegion(rect);
177}
178
179bool QSvgPath::requiresGroupRendering() const
180{
181 return hasAnyMarker();
182}
183
184QSvgPolygon::QSvgPolygon(QSvgNode *parent, const QPolygonF &poly)
185 : QSvgNode(parent), m_poly(poly)
186{
187}
188
189QSvgPolygon::~QSvgPolygon()
190 = default;
191
192QRectF QSvgPolygon::internalFastBounds(QPainter *p, QSvgExtraStates &) const
193{
194 return p->transform().mapRect(m_poly.boundingRect());
195}
196
197QRectF QSvgPolygon::internalBounds(QPainter *p, QSvgExtraStates &s) const
198{
199 return internalBounds(p, s, BoundsMode::Simplistic);
200}
201
202QRectF QSvgPolygon::decoratedInternalBounds(QPainter *p, QSvgExtraStates &s) const
203{
204 QRectF rect = internalBounds(p, s, BoundsMode::IncludeMiterLimit);
205 rect |= QSvgMarker::markersBoundsForNode(this, p, s);
206 return filterRegion(rect);
207}
208
209bool QSvgPolygon::requiresGroupRendering() const
210{
211 return hasAnyMarker();
212}
213
214QRectF QSvgPolygon::internalBounds(QPainter *p, QSvgExtraStates &, BoundsMode mode) const
215{
216 qreal sw = strokeWidth(p);
217 if (qFuzzyIsNull(sw)) {
218 return p->transform().map(m_poly).boundingRect();
219 } else {
220 QPainterPath path;
221 path.addPolygon(m_poly);
222 return boundsOnStroke(p, path, sw, mode);
223 }
224}
225
226void QSvgPolygon::drawCommand(QPainter *p, QSvgExtraStates &states)
227{
228 if (m_poly.boundingRect().isNull() && p->pen().capStyle() != Qt::FlatCap)
229 p->drawPoint(m_poly.first());
230 else
231 p->drawPolygon(m_poly, states.fillRule);
232 QSvgMarker::drawMarkersForNode(this, p, states);
233}
234
235bool QSvgPolygon::separateFillStroke(const QPainter *, const QSvgExtraStates &) const
236{
237 return true;
238}
239
240QSvgPolyline::QSvgPolyline(QSvgNode *parent, const QPolygonF &poly)
241 : QSvgNode(parent), m_poly(poly)
242{
243
244}
245
246QSvgPolyline::~QSvgPolyline()
247 = default;
248
249void QSvgPolyline::drawCommand(QPainter *p, QSvgExtraStates &states)
250{
251 if (p->brush().style() != Qt::NoBrush) {
252 p->drawPolygon(m_poly, states.fillRule);
253 } else {
254 if (m_poly.boundingRect().isNull() && p->pen().capStyle() != Qt::FlatCap)
255 p->drawPoint(m_poly.first());
256 else
257 p->drawPolyline(m_poly);
258 QSvgMarker::drawMarkersForNode(this, p, states);
259 }
260}
261
262bool QSvgPolyline::separateFillStroke(const QPainter *, const QSvgExtraStates &) const
263{
264 return true;
265}
266
267QSvgRect::QSvgRect(QSvgNode *node, const QRectF &rect, qreal rx, qreal ry)
268 : QSvgNode(node),
269 m_rect(rect), m_rx(rx), m_ry(ry)
270{
271}
272
273QSvgRect::~QSvgRect()
274 = default;
275
276QRectF QSvgRect::internalFastBounds(QPainter *p, QSvgExtraStates &) const
277{
278 return p->transform().mapRect(m_rect);
279}
280
281QRectF QSvgRect::internalBounds(QPainter *p, QSvgExtraStates &s) const
282{
283 return internalBounds(p, s, BoundsMode::Simplistic);
284}
285
286QRectF QSvgRect::decoratedInternalBounds(QPainter *p, QSvgExtraStates &s) const
287{
288 return filterRegion(internalBounds(p, s, BoundsMode::IncludeMiterLimit));
289}
290
291QRectF QSvgRect::internalBounds(QPainter *p, QSvgExtraStates &, BoundsMode mode) const
292{
293 qreal sw = strokeWidth(p);
294 if (qFuzzyIsNull(sw)) {
295 return p->transform().mapRect(m_rect);
296 } else {
297 QPainterPath path;
298 path.addRect(m_rect);
299 return boundsOnStroke(p, path, sw, mode);
300 }
301}
302
303void QSvgRect::drawCommand(QPainter *p, QSvgExtraStates &)
304{
305 if (m_rx || m_ry)
306 p->drawRoundedRect(m_rect, m_rx, m_ry, Qt::RelativeSize);
307 else
308 p->drawRect(m_rect);
309}
310
311bool QSvgRect::separateFillStroke(const QPainter *, const QSvgExtraStates &) const
312{
313 return true;
314}
315
316QSvgTspan * const QSvgText::LINEBREAK = 0;
317
318QSvgText::QSvgText(QSvgNode *parent, const QPointF &coord)
319 : QSvgNode(parent)
320 , m_coord(coord)
321 , m_size(0, 0)
322 , m_type(Text)
323 , m_mode(Default)
324{
325}
326
327QSvgText::~QSvgText()
328{
329 for (int i = 0; i < m_tspans.size(); ++i) {
330 if (m_tspans[i] != LINEBREAK)
331 delete m_tspans[i];
332 }
333}
334
335void QSvgText::setTextArea(const QSizeF &size)
336{
337 m_size = size;
338 m_type = Textarea;
339}
340
341QRectF QSvgText::internalFastBounds(QPainter *p, QSvgExtraStates &) const
342{
343 QSvgFontStyle *fontProperty = static_cast<QSvgFontStyle *>(m_style.property(QSvgStyleProperty::Font));
344 QFont font = fontProperty ? fontProperty->qfont() : p->font();
345 QFontMetricsF fm(font);
346
347 int charCount = 0;
348 for (int i = 0; i < m_tspans.size(); ++i) {
349 if (m_tspans.at(i) != LINEBREAK)
350 charCount += m_tspans.at(i)->text().size();
351 }
352
353 QRectF approxMaximumBrect(m_coord.x(),
354 m_coord.y(),
355 charCount * fm.averageCharWidth(),
356 -m_tspans.size() * fm.height());
357 return p->transform().mapRect(approxMaximumBrect);
358}
359
360QRectF QSvgText::internalBounds(QPainter *p, QSvgExtraStates &states) const
361{
362 QRectF boundingRect;
363 if (shouldDrawNode(p, states))
364 draw_helper(p, states, &boundingRect);
365 return p->transform().mapRect(boundingRect);
366}
367
368void QSvgText::drawCommand(QPainter *p, QSvgExtraStates &states)
369{
370 draw_helper(p, states);
371}
372
373bool QSvgText::shouldDrawNode(QPainter *p, QSvgExtraStates &) const
374{
375 qsizetype numChars = 0;
376 qreal originalFontSize = p->font().pointSizeF();
377 qreal maxFontSize = originalFontSize;
378 for (const QSvgTspan *span : std::as_const(m_tspans)) {
379 if (span == LINEBREAK)
380 continue;
381
382 numChars += span->text().size();
383
384 QSvgFontStyle *style = static_cast<QSvgFontStyle *>(span->styleProperty(QSvgStyleProperty::Font));
385 if (style != nullptr && style->qfont().pointSizeF() > maxFontSize)
386 maxFontSize = style->qfont().pointSizeF();
387 }
388
389 QFont font = p->font();
390 font.setPixelSize(maxFontSize);
391 QFontMetricsF fm(font);
392 if (m_tspans.size() * fm.height() >= QT_SVG_MAX_LAYOUT_SIZE) {
393 qCWarning(lcSvgDraw) << "Text element too high to lay out, ignoring";
394 return false;
395 }
396
397 if (numChars * fm.maxWidth() >= QT_SVG_MAX_LAYOUT_SIZE) {
398 qCWarning(lcSvgDraw) << "Text element too wide to lay out, ignoring";
399 return false;
400 }
401
402 return true;
403}
404
405bool QSvgText::separateFillStroke(const QPainter *, const QSvgExtraStates &) const
406{
407 return true;
408}
409
410void QSvgText::draw_helper(QPainter *p, QSvgExtraStates &states, QRectF *boundingRect) const
411{
412 const bool isPainting = (boundingRect == nullptr);
413 if (!isPainting || shouldDrawNode(p, states)) {
414 QFont font = p->font();
415 Qt::Alignment alignment = states.textAnchor;
416
417 qreal y = 0;
418 bool initial = true;
419 qreal px = m_coord.x();
420 qreal py = m_coord.y();
421
422 if (m_type == Textarea) {
423 if (alignment == Qt::AlignHCenter)
424 px += m_size.width() / 2;
425 else if (alignment == Qt::AlignRight)
426 px += m_size.width();
427 }
428
429 QRectF bounds;
430 if (m_size.height() != 0)
431 bounds = QRectF(0, py, 1, m_size.height()); // x and width are not used.
432
433 bool appendSpace = false;
434 QStringList paragraphs;
435 QList<QList<QTextLayout::FormatRange> > formatRanges(1);
436 paragraphs.push_back(QString());
437
438 for (int i = 0; i < m_tspans.size(); ++i) {
439 if (m_tspans[i] == LINEBREAK) {
440 if (m_type == Textarea) {
441 if (paragraphs.back().isEmpty()) {
442 font.setPixelSize(font.pointSizeF());
443 font.setHintingPreference(QFont::PreferNoHinting);
444
445 QTextLayout::FormatRange range;
446 range.start = 0;
447 range.length = 1;
448 range.format.setFont(font);
449 formatRanges.back().append(range);
450
451 paragraphs.back().append(QLatin1Char(' '));;
452 }
453 appendSpace = false;
454 paragraphs.push_back(QString());
455 formatRanges.resize(formatRanges.size() + 1);
456 }
457 } else {
458 WhitespaceMode mode = m_tspans[i]->whitespaceMode();
459 m_tspans[i]->applyStyle(p, states);
460
461 font = p->font();
462 font.setPixelSize(font.pointSizeF());
463 font.setHintingPreference(QFont::PreferNoHinting);
464
465 QString newText(m_tspans[i]->text());
466 newText.replace(QLatin1Char('\t'), QLatin1Char(' '));
467 newText.replace(QLatin1Char('\n'), QLatin1Char(' '));
468
469 bool prependSpace = !appendSpace && !m_tspans[i]->isTspan() && (mode == Default) && !paragraphs.back().isEmpty() && newText.startsWith(QLatin1Char(' '));
470 if (appendSpace || prependSpace)
471 paragraphs.back().append(QLatin1Char(' '));
472
473 bool appendSpaceNext = (!m_tspans[i]->isTspan() && (mode == Default) && newText.endsWith(QLatin1Char(' ')));
474
475 if (mode == Default) {
476 newText = newText.simplified();
477 if (newText.isEmpty())
478 appendSpaceNext = false;
479 }
480
481 QTextLayout::FormatRange range;
482 range.start = paragraphs.back().size();
483 range.length = newText.size();
484 range.format.setFont(font);
485 if (p->pen().style() != Qt::NoPen && p->pen().brush() != Qt::NoBrush)
486 range.format.setTextOutline(p->pen());
487 // work around QTBUG-136696: NoBrush fills the foreground with the outline's pen
488 range.format.setForeground(p->brush().style() == Qt::NoBrush
489 ? QColor(Qt::transparent) : p->brush());
490
491 if (appendSpace) {
492 Q_ASSERT(!formatRanges.back().isEmpty());
493 ++formatRanges.back().back().length;
494 } else if (prependSpace) {
495 --range.start;
496 ++range.length;
497 }
498 formatRanges.back().append(range);
499
500 appendSpace = appendSpaceNext;
501 paragraphs.back() += newText;
502
503 m_tspans[i]->revertStyle(p, states);
504 }
505 }
506
507 if (states.svgFont) {
508 // SVG fonts not fully supported...
509 if (!m_glyphsToDraw)
510 m_glyphsToDraw = states.svgFont->toGlyphs(paragraphs.join(QLatin1Char('\n')));
511 if (isPainting) {
512 states.svgFont->draw(p, m_coord, m_glyphsToDraw.value(),
513 p->font().pointSizeF(), states.textAnchor);
514 } else {
515 *boundingRect = states.svgFont->boundingRect(p, m_coord, m_glyphsToDraw.value(),
516 p->font().pointSizeF(), states.textAnchor);
517 }
518 } else {
519 QRectF brect;
520 for (int i = 0; i < paragraphs.size(); ++i) {
521 QTextLayout tl(paragraphs[i]);
522 QTextOption op = tl.textOption();
523 op.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
524 tl.setTextOption(op);
525 tl.setFormats(formatRanges[i]);
526 tl.beginLayout();
527
528 forever {
529 QTextLine line = tl.createLine();
530 if (!line.isValid())
531 break;
532 if (m_size.width() != 0)
533 line.setLineWidth(m_size.width());
534 }
535 tl.endLayout();
536
537 bool endOfBoundsReached = false;
538 for (int i = 0; i < tl.lineCount(); ++i) {
539 QTextLine line = tl.lineAt(i);
540
541 qreal x = 0;
542 if (alignment == Qt::AlignHCenter)
543 x -= 0.5 * line.naturalTextWidth();
544 else if (alignment == Qt::AlignRight)
545 x -= line.naturalTextWidth();
546
547 if (initial && m_type == Text)
548 y -= line.ascent();
549 initial = false;
550
551 line.setPosition(QPointF(x, y));
552 brect |= line.naturalTextRect();
553
554 // Check if the current line fits into the bounding rectangle.
555 if ((m_size.width() != 0 && line.naturalTextWidth() > m_size.width())
556 || (m_size.height() != 0 && y + line.height() > m_size.height())) {
557 // I need to set the bounds height to 'y-epsilon' to avoid drawing the current
558 // line. Since the font is scaled to 100 units, 1 should be a safe epsilon.
559 bounds.setHeight(y - 1);
560 endOfBoundsReached = true;
561 break;
562 }
563
564 y += 1.1 * line.height();
565 }
566 if (isPainting)
567 tl.draw(p, QPointF(px, py), QList<QTextLayout::FormatRange>(), bounds);
568
569 if (endOfBoundsReached)
570 break;
571 }
572 if (boundingRect) {
573 brect.translate(m_coord);
574 if (bounds.height() > 0)
575 brect.setBottom(qMin(brect.bottom(), bounds.bottom()));
576 *boundingRect = brect;
577 }
578 }
579 }
580}
581
582void QSvgText::addText(QStringView text)
583{
584 m_tspans.append(new QSvgTspan(this, false));
585 m_tspans.back()->setWhitespaceMode(m_mode);
586 m_tspans.back()->addText(text);
587}
588
589QSvgTspan::~QSvgTspan()
590 = default;
591
592QSvgUse::QSvgUse(const QPointF &start, QSvgNode *parent, QSvgNode *node)
593 : QSvgNode(parent), m_link(node), m_start(start), m_recursing(false)
594{
595
596}
597
599 = default;
600
601void QSvgUse::drawCommand(QPainter *p, QSvgExtraStates &states)
602{
603 if (Q_UNLIKELY(!m_link || isDescendantOf(m_link) || m_recursing))
604 return;
605
606 Q_ASSERT(states.nestedUseCount == 0 || states.nestedUseLevel > 0);
607 if (states.nestedUseLevel > 3 && states.nestedUseCount > (256 + states.nestedUseLevel * 2)) {
608 qCDebug(lcSvgDraw, "Too many nested use nodes at #%s!", qPrintable(m_linkId));
609 return;
610 }
611
612 QScopedValueRollback<bool> inUseGuard(states.inUse, true);
613
614 if (!m_start.isNull()) {
615 p->translate(m_start);
616 }
617 if (states.nestedUseLevel > 0)
618 ++states.nestedUseCount;
619 {
620 QScopedValueRollback<int> useLevelGuard(states.nestedUseLevel, states.nestedUseLevel + 1);
621 QScopedValueRollback<bool> recursingGuard(m_recursing, true);
622 m_link->draw(p, states);
623 }
624 if (states.nestedUseLevel == 0)
625 states.nestedUseCount = 0;
626
627 if (!m_start.isNull()) {
628 p->translate(-m_start);
629 }
630}
631
632QSvgNode::Type QSvgDummyNode::type() const
633{
634 return FeUnsupported;
635}
636
637
638QSvgCircle::~QSvgCircle()
639 = default;
640
641QSvgNode::Type QSvgCircle::type() const
642{
643 return Circle;
644}
645
646QSvgNode::Type QSvgEllipse::type() const
647{
648 return Ellipse;
649}
650
651QSvgNode::Type QSvgImage::type() const
652{
653 return Image;
654}
655
656QSvgNode::Type QSvgLine::type() const
657{
658 return Line;
659}
660
661QSvgNode::Type QSvgPath::type() const
662{
663 return Path;
664}
665
666QSvgNode::Type QSvgPolygon::type() const
667{
668 return Polygon;
669}
670
671QSvgNode::Type QSvgPolyline::type() const
672{
673 return Polyline;
674}
675
676QSvgNode::Type QSvgRect::type() const
677{
678 return Rect;
679}
680
681QSvgNode::Type QSvgText::type() const
682{
683 return m_type;
684}
685
687{
688 return Use;
689}
690
692 = default;
693
695{
696 return Video;
697}
698
699QRectF QSvgUse::internalBounds(QPainter *p, QSvgExtraStates &states) const
700{
701 QRectF bounds;
702 if (Q_LIKELY(m_link && !isDescendantOf(m_link) && !m_recursing)) {
703 QScopedValueRollback<bool> guard(m_recursing, true);
704 p->translate(m_start);
705 bounds = m_link->bounds(p, states);
706 p->translate(-m_start);
707 }
708 return bounds;
709}
710
711QRectF QSvgUse::decoratedInternalBounds(QPainter *p, QSvgExtraStates &states) const
712{
713 QRectF bounds;
714 if (Q_LIKELY(m_link && !isDescendantOf(m_link) && !m_recursing)) {
715 QScopedValueRollback<bool> guard(m_recursing, true);
716 p->translate(m_start);
717 bounds = m_link->decoratedBounds(p, states);
718 p->translate(-m_start);
719 }
720 return bounds;
721}
722
723QRectF QSvgPolyline::internalFastBounds(QPainter *p, QSvgExtraStates &) const
724{
725 return p->transform().mapRect(m_poly.boundingRect());
726}
727
728QRectF QSvgPolyline::internalBounds(QPainter *p, QSvgExtraStates &s) const
729{
730 return internalBounds(p, s, BoundsMode::Simplistic);
731}
732
733QRectF QSvgPolyline::decoratedInternalBounds(QPainter *p, QSvgExtraStates &s) const
734{
735 QRectF rect = internalBounds(p, s, BoundsMode::IncludeMiterLimit);
736 rect |= QSvgMarker::markersBoundsForNode(this, p, s);
737 return filterRegion(rect);
738}
739
740bool QSvgPolyline::requiresGroupRendering() const
741{
742 return hasAnyMarker();
743}
744
745QRectF QSvgPolyline::internalBounds(QPainter *p, QSvgExtraStates &, BoundsMode mode) const
746{
747 qreal sw = strokeWidth(p);
748 if (qFuzzyIsNull(sw)) {
749 return p->transform().map(m_poly).boundingRect();
750 } else {
751 QPainterPath path;
752 path.addPolygon(m_poly);
753 return boundsOnStroke(p, path, sw, mode);
754 }
755}
756
757QRectF QSvgImage::internalBounds(QPainter *p, QSvgExtraStates &) const
758{
759 return p->transform().mapRect(m_bounds);
760}
761
762QRectF QSvgLine::internalFastBounds(QPainter *p, QSvgExtraStates &) const
763{
764 QPointF p1 = p->transform().map(m_line.p1());
765 QPointF p2 = p->transform().map(m_line.p2());
766 qreal minX = qMin(p1.x(), p2.x());
767 qreal minY = qMin(p1.y(), p2.y());
768 qreal maxX = qMax(p1.x(), p2.x());
769 qreal maxY = qMax(p1.y(), p2.y());
770 return QRectF(minX, minY, maxX - minX, maxY - minY);
771}
772
773QRectF QSvgLine::internalBounds(QPainter *p, QSvgExtraStates &s) const
774{
775 return internalBounds(p, s, BoundsMode::Simplistic);
776}
777
778QRectF QSvgLine::decoratedInternalBounds(QPainter *p, QSvgExtraStates &s) const
779{
780 QRectF rect = internalBounds(p, s, BoundsMode::IncludeMiterLimit);
781 rect |= QSvgMarker::markersBoundsForNode(this, p, s);
782 return filterRegion(rect);
783}
784
785bool QSvgLine::requiresGroupRendering() const
786{
787 return hasAnyMarker();
788}
789
790QRectF QSvgLine::internalBounds(QPainter *p, QSvgExtraStates &s, BoundsMode mode) const
791{
792 qreal sw = strokeWidth(p);
793 if (qFuzzyIsNull(sw)) {
794 return internalFastBounds(p, s);
795 } else {
796 QPainterPath path;
797 path.moveTo(m_line.p1());
798 path.lineTo(m_line.p2());
799 return boundsOnStroke(p, path, sw, mode);
800 }
801}
802
803QT_END_NAMESPACE
friend class QPainter
QRectF decoratedInternalBounds(QPainter *p, QSvgExtraStates &states) const override
void drawCommand(QPainter *p, QSvgExtraStates &states) override
~QSvgUse() override
QRectF internalBounds(QPainter *p, QSvgExtraStates &states) const override
QSvgUse(const QPointF &start, QSvgNode *parent, QSvgNode *link)
Type type() const override
~QSvgVideo() override
Type type() const override
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
#define qCDebug(category,...)
#define qPrintable(string)
Definition qstring.h:1683
#define QT_SVG_MAX_LAYOUT_SIZE