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 QFont font = m_style.font ? m_style.font->qfont() : p->font();
344 QFontMetricsF fm(font);
345
346 int charCount = 0;
347 for (int i = 0; i < m_tspans.size(); ++i) {
348 if (m_tspans.at(i) != LINEBREAK)
349 charCount += m_tspans.at(i)->text().size();
350 }
351
352 QRectF approxMaximumBrect(m_coord.x(),
353 m_coord.y(),
354 charCount * fm.averageCharWidth(),
355 -m_tspans.size() * fm.height());
356 return p->transform().mapRect(approxMaximumBrect);
357}
358
359QRectF QSvgText::internalBounds(QPainter *p, QSvgExtraStates &states) const
360{
361 QRectF boundingRect;
362 if (shouldDrawNode(p, states))
363 draw_helper(p, states, &boundingRect);
364 return p->transform().mapRect(boundingRect);
365}
366
367void QSvgText::drawCommand(QPainter *p, QSvgExtraStates &states)
368{
369 draw_helper(p, states);
370}
371
372bool QSvgText::shouldDrawNode(QPainter *p, QSvgExtraStates &) const
373{
374 qsizetype numChars = 0;
375 qreal originalFontSize = p->font().pointSizeF();
376 qreal maxFontSize = originalFontSize;
377 for (const QSvgTspan *span : std::as_const(m_tspans)) {
378 if (span == LINEBREAK)
379 continue;
380
381 numChars += span->text().size();
382
383 QSvgFontStyle *style = static_cast<QSvgFontStyle *>(span->styleProperty(QSvgStyleProperty::FONT));
384 if (style != nullptr && style->qfont().pointSizeF() > maxFontSize)
385 maxFontSize = style->qfont().pointSizeF();
386 }
387
388 QFont font = p->font();
389 font.setPixelSize(maxFontSize);
390 QFontMetricsF fm(font);
391 if (m_tspans.size() * fm.height() >= QT_SVG_MAX_LAYOUT_SIZE) {
392 qCWarning(lcSvgDraw) << "Text element too high to lay out, ignoring";
393 return false;
394 }
395
396 if (numChars * fm.maxWidth() >= QT_SVG_MAX_LAYOUT_SIZE) {
397 qCWarning(lcSvgDraw) << "Text element too wide to lay out, ignoring";
398 return false;
399 }
400
401 return true;
402}
403
404bool QSvgText::separateFillStroke(const QPainter *, const QSvgExtraStates &) const
405{
406 return true;
407}
408
409void QSvgText::draw_helper(QPainter *p, QSvgExtraStates &states, QRectF *boundingRect) const
410{
411 const bool isPainting = (boundingRect == nullptr);
412 if (!isPainting || shouldDrawNode(p, states)) {
413 QFont font = p->font();
414 Qt::Alignment alignment = states.textAnchor;
415
416 qreal y = 0;
417 bool initial = true;
418 qreal px = m_coord.x();
419 qreal py = m_coord.y();
420
421 if (m_type == Textarea) {
422 if (alignment == Qt::AlignHCenter)
423 px += m_size.width() / 2;
424 else if (alignment == Qt::AlignRight)
425 px += m_size.width();
426 }
427
428 QRectF bounds;
429 if (m_size.height() != 0)
430 bounds = QRectF(0, py, 1, m_size.height()); // x and width are not used.
431
432 bool appendSpace = false;
433 QStringList paragraphs;
434 QList<QList<QTextLayout::FormatRange> > formatRanges(1);
435 paragraphs.push_back(QString());
436
437 for (int i = 0; i < m_tspans.size(); ++i) {
438 if (m_tspans[i] == LINEBREAK) {
439 if (m_type == Textarea) {
440 if (paragraphs.back().isEmpty()) {
441 font.setPixelSize(font.pointSizeF());
442 font.setHintingPreference(QFont::PreferNoHinting);
443
444 QTextLayout::FormatRange range;
445 range.start = 0;
446 range.length = 1;
447 range.format.setFont(font);
448 formatRanges.back().append(range);
449
450 paragraphs.back().append(QLatin1Char(' '));;
451 }
452 appendSpace = false;
453 paragraphs.push_back(QString());
454 formatRanges.resize(formatRanges.size() + 1);
455 }
456 } else {
457 WhitespaceMode mode = m_tspans[i]->whitespaceMode();
458 m_tspans[i]->applyStyle(p, states);
459
460 font = p->font();
461 font.setPixelSize(font.pointSizeF());
462 font.setHintingPreference(QFont::PreferNoHinting);
463
464 QString newText(m_tspans[i]->text());
465 newText.replace(QLatin1Char('\t'), QLatin1Char(' '));
466 newText.replace(QLatin1Char('\n'), QLatin1Char(' '));
467
468 bool prependSpace = !appendSpace && !m_tspans[i]->isTspan() && (mode == Default) && !paragraphs.back().isEmpty() && newText.startsWith(QLatin1Char(' '));
469 if (appendSpace || prependSpace)
470 paragraphs.back().append(QLatin1Char(' '));
471
472 bool appendSpaceNext = (!m_tspans[i]->isTspan() && (mode == Default) && newText.endsWith(QLatin1Char(' ')));
473
474 if (mode == Default) {
475 newText = newText.simplified();
476 if (newText.isEmpty())
477 appendSpaceNext = false;
478 }
479
480 QTextLayout::FormatRange range;
481 range.start = paragraphs.back().size();
482 range.length = newText.size();
483 range.format.setFont(font);
484 if (p->pen().style() != Qt::NoPen && p->pen().brush() != Qt::NoBrush)
485 range.format.setTextOutline(p->pen());
486 // work around QTBUG-136696: NoBrush fills the foreground with the outline's pen
487 range.format.setForeground(p->brush().style() == Qt::NoBrush
488 ? QColor(Qt::transparent) : p->brush());
489
490 if (appendSpace) {
491 Q_ASSERT(!formatRanges.back().isEmpty());
492 ++formatRanges.back().back().length;
493 } else if (prependSpace) {
494 --range.start;
495 ++range.length;
496 }
497 formatRanges.back().append(range);
498
499 appendSpace = appendSpaceNext;
500 paragraphs.back() += newText;
501
502 m_tspans[i]->revertStyle(p, states);
503 }
504 }
505
506 if (states.svgFont) {
507 // SVG fonts not fully supported...
508 if (!m_glyphsToDraw)
509 m_glyphsToDraw = states.svgFont->toGlyphs(paragraphs.join(QLatin1Char('\n')));
510 if (isPainting) {
511 states.svgFont->draw(p, m_coord, m_glyphsToDraw.value(),
512 p->font().pointSizeF(), states.textAnchor);
513 } else {
514 *boundingRect = states.svgFont->boundingRect(p, m_coord, m_glyphsToDraw.value(),
515 p->font().pointSizeF(), states.textAnchor);
516 }
517 } else {
518 QRectF brect;
519 for (int i = 0; i < paragraphs.size(); ++i) {
520 QTextLayout tl(paragraphs[i]);
521 QTextOption op = tl.textOption();
522 op.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
523 tl.setTextOption(op);
524 tl.setFormats(formatRanges[i]);
525 tl.beginLayout();
526
527 forever {
528 QTextLine line = tl.createLine();
529 if (!line.isValid())
530 break;
531 if (m_size.width() != 0)
532 line.setLineWidth(m_size.width());
533 }
534 tl.endLayout();
535
536 bool endOfBoundsReached = false;
537 for (int i = 0; i < tl.lineCount(); ++i) {
538 QTextLine line = tl.lineAt(i);
539
540 qreal x = 0;
541 if (alignment == Qt::AlignHCenter)
542 x -= 0.5 * line.naturalTextWidth();
543 else if (alignment == Qt::AlignRight)
544 x -= line.naturalTextWidth();
545
546 if (initial && m_type == Text)
547 y -= line.ascent();
548 initial = false;
549
550 line.setPosition(QPointF(x, y));
551 brect |= line.naturalTextRect();
552
553 // Check if the current line fits into the bounding rectangle.
554 if ((m_size.width() != 0 && line.naturalTextWidth() > m_size.width())
555 || (m_size.height() != 0 && y + line.height() > m_size.height())) {
556 // I need to set the bounds height to 'y-epsilon' to avoid drawing the current
557 // line. Since the font is scaled to 100 units, 1 should be a safe epsilon.
558 bounds.setHeight(y - 1);
559 endOfBoundsReached = true;
560 break;
561 }
562
563 y += 1.1 * line.height();
564 }
565 if (isPainting)
566 tl.draw(p, QPointF(px, py), QList<QTextLayout::FormatRange>(), bounds);
567
568 if (endOfBoundsReached)
569 break;
570 }
571 if (boundingRect) {
572 brect.translate(m_coord);
573 if (bounds.height() > 0)
574 brect.setBottom(qMin(brect.bottom(), bounds.bottom()));
575 *boundingRect = brect;
576 }
577 }
578 }
579}
580
581void QSvgText::addText(QStringView text)
582{
583 m_tspans.append(new QSvgTspan(this, false));
584 m_tspans.back()->setWhitespaceMode(m_mode);
585 m_tspans.back()->addText(text);
586}
587
588QSvgTspan::~QSvgTspan()
589 = default;
590
591QSvgUse::QSvgUse(const QPointF &start, QSvgNode *parent, QSvgNode *node)
592 : QSvgNode(parent), m_link(node), m_start(start), m_recursing(false)
593{
594
595}
596
598 = default;
599
600void QSvgUse::drawCommand(QPainter *p, QSvgExtraStates &states)
601{
602 if (Q_UNLIKELY(!m_link || isDescendantOf(m_link) || m_recursing))
603 return;
604
605 Q_ASSERT(states.nestedUseCount == 0 || states.nestedUseLevel > 0);
606 if (states.nestedUseLevel > 3 && states.nestedUseCount > (256 + states.nestedUseLevel * 2)) {
607 qCDebug(lcSvgDraw, "Too many nested use nodes at #%s!", qPrintable(m_linkId));
608 return;
609 }
610
611 QScopedValueRollback<bool> inUseGuard(states.inUse, true);
612
613 if (!m_start.isNull()) {
614 p->translate(m_start);
615 }
616 if (states.nestedUseLevel > 0)
617 ++states.nestedUseCount;
618 {
619 QScopedValueRollback<int> useLevelGuard(states.nestedUseLevel, states.nestedUseLevel + 1);
620 QScopedValueRollback<bool> recursingGuard(m_recursing, true);
621 m_link->draw(p, states);
622 }
623 if (states.nestedUseLevel == 0)
624 states.nestedUseCount = 0;
625
626 if (!m_start.isNull()) {
627 p->translate(-m_start);
628 }
629}
630
631QSvgNode::Type QSvgDummyNode::type() const
632{
633 return FeUnsupported;
634}
635
636
637QSvgCircle::~QSvgCircle()
638 = default;
639
640QSvgNode::Type QSvgCircle::type() const
641{
642 return Circle;
643}
644
645QSvgNode::Type QSvgEllipse::type() const
646{
647 return Ellipse;
648}
649
650QSvgNode::Type QSvgImage::type() const
651{
652 return Image;
653}
654
655QSvgNode::Type QSvgLine::type() const
656{
657 return Line;
658}
659
660QSvgNode::Type QSvgPath::type() const
661{
662 return Path;
663}
664
665QSvgNode::Type QSvgPolygon::type() const
666{
667 return Polygon;
668}
669
670QSvgNode::Type QSvgPolyline::type() const
671{
672 return Polyline;
673}
674
675QSvgNode::Type QSvgRect::type() const
676{
677 return Rect;
678}
679
680QSvgNode::Type QSvgText::type() const
681{
682 return m_type;
683}
684
686{
687 return Use;
688}
689
691 = default;
692
694{
695 return Video;
696}
697
698QRectF QSvgUse::internalBounds(QPainter *p, QSvgExtraStates &states) const
699{
700 QRectF bounds;
701 if (Q_LIKELY(m_link && !isDescendantOf(m_link) && !m_recursing)) {
702 QScopedValueRollback<bool> guard(m_recursing, true);
703 p->translate(m_start);
704 bounds = m_link->bounds(p, states);
705 p->translate(-m_start);
706 }
707 return bounds;
708}
709
710QRectF QSvgUse::decoratedInternalBounds(QPainter *p, QSvgExtraStates &states) const
711{
712 QRectF bounds;
713 if (Q_LIKELY(m_link && !isDescendantOf(m_link) && !m_recursing)) {
714 QScopedValueRollback<bool> guard(m_recursing, true);
715 p->translate(m_start);
716 bounds = m_link->decoratedBounds(p, states);
717 p->translate(-m_start);
718 }
719 return bounds;
720}
721
722QRectF QSvgPolyline::internalFastBounds(QPainter *p, QSvgExtraStates &) const
723{
724 return p->transform().mapRect(m_poly.boundingRect());
725}
726
727QRectF QSvgPolyline::internalBounds(QPainter *p, QSvgExtraStates &s) const
728{
729 return internalBounds(p, s, BoundsMode::Simplistic);
730}
731
732QRectF QSvgPolyline::decoratedInternalBounds(QPainter *p, QSvgExtraStates &s) const
733{
734 QRectF rect = internalBounds(p, s, BoundsMode::IncludeMiterLimit);
735 rect |= QSvgMarker::markersBoundsForNode(this, p, s);
736 return filterRegion(rect);
737}
738
739bool QSvgPolyline::requiresGroupRendering() const
740{
741 return hasAnyMarker();
742}
743
744QRectF QSvgPolyline::internalBounds(QPainter *p, QSvgExtraStates &, BoundsMode mode) const
745{
746 qreal sw = strokeWidth(p);
747 if (qFuzzyIsNull(sw)) {
748 return p->transform().map(m_poly).boundingRect();
749 } else {
750 QPainterPath path;
751 path.addPolygon(m_poly);
752 return boundsOnStroke(p, path, sw, mode);
753 }
754}
755
756QRectF QSvgImage::internalBounds(QPainter *p, QSvgExtraStates &) const
757{
758 return p->transform().mapRect(m_bounds);
759}
760
761QRectF QSvgLine::internalFastBounds(QPainter *p, QSvgExtraStates &) const
762{
763 QPointF p1 = p->transform().map(m_line.p1());
764 QPointF p2 = p->transform().map(m_line.p2());
765 qreal minX = qMin(p1.x(), p2.x());
766 qreal minY = qMin(p1.y(), p2.y());
767 qreal maxX = qMax(p1.x(), p2.x());
768 qreal maxY = qMax(p1.y(), p2.y());
769 return QRectF(minX, minY, maxX - minX, maxY - minY);
770}
771
772QRectF QSvgLine::internalBounds(QPainter *p, QSvgExtraStates &s) const
773{
774 return internalBounds(p, s, BoundsMode::Simplistic);
775}
776
777QRectF QSvgLine::decoratedInternalBounds(QPainter *p, QSvgExtraStates &s) const
778{
779 QRectF rect = internalBounds(p, s, BoundsMode::IncludeMiterLimit);
780 rect |= QSvgMarker::markersBoundsForNode(this, p, s);
781 return filterRegion(rect);
782}
783
784bool QSvgLine::requiresGroupRendering() const
785{
786 return hasAnyMarker();
787}
788
789QRectF QSvgLine::internalBounds(QPainter *p, QSvgExtraStates &s, BoundsMode mode) const
790{
791 qreal sw = strokeWidth(p);
792 if (qFuzzyIsNull(sw)) {
793 return internalFastBounds(p, s);
794 } else {
795 QPainterPath path;
796 path.moveTo(m_line.p1());
797 path.lineTo(m_line.p2());
798 return boundsOnStroke(p, path, sw, mode);
799 }
800}
801
802QT_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