17#include <QLoggingCategory>
19#include <QtGui/qimageiohandler.h>
102 , m_pAspectRatios(pAspectRatios)
103 , m_overflow(overflow)
134 scaleX = scaleY =
qMin(scaleX, scaleY);
136 scaleX = scaleY =
qMax(scaleX, scaleY);
142 offsetX -= xOverflow / 2.;
144 offsetX -= xOverflow;
147 offsetY -= yOverflow / 2.;
149 offsetY -= yOverflow;
152 p->translate(offsetX -
m_refP.
x() * scaleX, offsetY -
m_refP.
y() * scaleY);
153 p->scale(scaleX, scaleY);
157 QSvgSymbol::PreserveAspectRatios pAspectRatios,
159 :
QSvgSymbolLike(parent, bounds, viewBox, refP, pAspectRatios, overflow)
189 :
QSvgSymbolLike(parent, bounds, viewBox, refP, pAspectRatios, overflow)
190 , m_orientation(orientation)
191 , m_orientationAngle(orientationAngle)
192 , m_markerUnits(markerUnits)
200 strokeProp->setMiterLimit(4);
201 strokeProp->setWidth(1);
212 , m_filterUnits(filterUnits)
213 , m_primitiveUnits(primitiveUnits)
231 QScopedValueRollback<bool> recursingGuard(
m_recursing,
true);
252 QScopedValueRollback<bool> inUseGuard(
states.inUse,
true);
268 return -atan2(tangent.
y(), tangent.
x()) /
M_PI * 180.;
272 QList<PositionMarkerPair> marks;
278 marks << PositionMarkerPair {
line->line().p1().x(),
line->line().p1().y(),
279 line->line().angle(),
line->markerStartId(),
282 marks << PositionMarkerPair {
line->line().p2().x(),
line->line().p2().y(),
283 line->line().angle(),
line->markerEndId() };
292 marks << PositionMarkerPair {
line.p1().x(),
299 for (
int i = 1;
i < polyData.size() - 1;
i++) {
304 marks << PositionMarkerPair {
p1.x(),
306 getMeanAngle(p0,
p1,
p2),
311 QLineF line(polyData.at(polyData.size()-1), polyData.last());
312 marks << PositionMarkerPair {
line.p2().x(),
317 }
else if (node->
type() == Path) {
323 path->path().pointAtPercent(0.).y(),
324 path->path().angleAtPercent(0.),
325 path->markerStartId(),
328 for (
int i = 1;
i <
path->path().elementCount() - 1;
i++) {
341 marks << PositionMarkerPair {
p1.x(),
343 getMeanAngle(p0,
p1,
p2),
344 path->markerMidId() };
349 marks << PositionMarkerPair {
path->path().pointAtPercent(1.).x(),
350 path->path().pointAtPercent(1.).y(),
351 path->path().angleAtPercent(1.),
352 path->markerEndId() };
354 for (
auto &
i : marks) {
360 p->translate(
i.x,
i.y);
362 p->rotate(markNode->orientationAngle());
368 QRectF oldRect = markNode->m_rect;
370 markNode->m_rect.
setWidth(markNode->m_rect.width() *
p->pen().widthF());
371 markNode->m_rect.setHeight(markNode->m_rect.height() *
p->pen().widthF());
374 markNode->m_rect = oldRect;
388 QRect filterBoundsGlob =
p->transform().mapRect(filterBounds).toRect();
391 if (filterBoundsGlobRel.isEmpty())
396 qCWarning(lcSvgDraw) <<
"The requested filter is too big, ignoring";
400 proxy.setOffset(filterBoundsGlob.topLeft());
408 bool requiresSourceAlpha =
false;
410 const QList<QSvgNode *> children =
renderers();
414 requiresSourceAlpha =
true;
419 if (requiresSourceAlpha) {
421 proxyAlpha.setOffset(
proxy.offset());
422 if (proxyAlpha.isNull())
460 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#Text"),
461 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#Shape"),
462 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#SVG"),
463 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#Structure"),
464 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#SolidColor"),
465 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#Hyperlinking"),
466 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#CoreAttribute"),
467 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#XlinkAttribute"),
468 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#SVG-static"),
469 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#OpacityAttribute"),
470 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#Gradient"),
471 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#Font"),
472 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#Image"),
473 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#ConditionalProcessing"),
474 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#Extensibility"),
475 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#GraphicsAttribute"),
476 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#Prefetch"),
477 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#PaintAttribute"),
478 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#ConditionalProcessingAttribute"),
479 QStringLiteral(
"http://www.w3.org/Graphics/SVG/feature/1.2/#ExternalResourcesRequiredAttribute")
510 bool okToRender =
true;
511 if (!features.isEmpty()) {
512 QStringList::const_iterator sitr = features.constBegin();
513 for (; sitr != features.constEnd(); ++sitr) {
521 if (okToRender && !extensions.isEmpty()) {
522 QStringList::const_iterator sitr = extensions.constBegin();
523 for (; sitr != extensions.constEnd(); ++sitr) {
531 if (okToRender && !languages.isEmpty()) {
532 QStringList::const_iterator sitr = languages.constBegin();
534 for (; sitr != languages.constEnd(); ++sitr) {
535 if ((*sitr).startsWith(m_systemLanguagePrefix)) {
542 if (okToRender && !
formats.isEmpty()) {
546 if (okToRender && !fonts.isEmpty()) {
564void QSvgSwitch::init()
569 m_systemLanguagePrefix = m_systemLanguage.
mid(0, idx);
576 QScopedValueRollback<bool> guard(
m_recursing,
true);
600 , m_contentUnits(contentUnits)
614 *globalRect =
t.mapRect(basicRect);
621 QRect imageBound = globalRect->toAlignedRect();
622 *globalRect = imageBound.
toRectF();
626 qCWarning(lcSvgDraw) <<
"The requested mask size is too big, ignoring";
632 QScopedValueRollback<bool> recursingGuard(
m_recursing,
true);
639 return maskNode->createMask(
p,
states, localRect, &boundsRect);
677 for (
int i=0;
i <
mask.height();
i++) {
679 for (
int j=0;
j <
mask.width();
j++) {
680 const qreal rC = 0.2125, gC = 0.7154, bC = 0.0721;
693 clipPath.
addRect(
mask.rect().adjusted(-10, -10, 20, 20));
711 m_contentUnits(contentUnits),
725 static QImage checkerPattern;
727 if (checkerPattern.isNull()) {
736 return checkerPattern;
743 QRectF peWorldBoundingBox;
748 peWorldBoundingBox =
t.mapRect(peBoundingBox);
758 qreal contentScaleFactorX = m_transform.
m11();
759 qreal contentScaleFactorY = m_transform.
m22();
761 contentScaleFactorX *=
t.m11();
762 contentScaleFactorY *=
t.m22();
764 contentScaleFactorX *= peWorldBoundingBox.width();
765 contentScaleFactorY *= peWorldBoundingBox.height();
773 imageSize.setHeight(
qCeil(patternBoundingBox.height() *
t.m22() * m_transform.
m22()));
775 calculateAppliedTransform(
t, peBoundingBox,
imageSize);
776 return renderPattern(
imageSize, contentScaleFactorX, contentScaleFactorY);
792 qCWarning(lcSvgDraw) <<
"The requested pattern size is too big, ignoring";
802 patternPainter.resetTransform();
807 patternPainter.scale(contentScaleX, contentScaleY);
809 patternPainter.setWindow(m_viewBox.
toRect());
814 node->
draw(&patternPainter, patternStates);
834 m_appliedTransform.
reset();
835 qreal imageDownScaleFactorX = 1 / worldTransform.
m11();
836 qreal imageDownScaleFactorY = 1 / worldTransform.
m22();
838 m_appliedTransform.
scale(
qIsFinite(imageDownScaleFactorX) ? imageDownScaleFactorX : 1.0,
839 qIsFinite(imageDownScaleFactorY) ? imageDownScaleFactorY : 1.0);
843 (
p.height() * worldTransform.
m22() * m_transform.
m22()) /
imageSize.height());
846 m_appliedTransform.
translate(translation.
x() * worldTransform.
m11(), translation.
y() * worldTransform.
m22());
849 scalelessTransform.
scale(1 / m_transform.
m11(), 1 / m_transform.
m22());
851 m_appliedTransform = m_appliedTransform * scalelessTransform;
static bool allocateImage(QSize size, QImage::Format format, QImage *image)
\inmodule QtCore\compares equality \compareswith equality QLine \endcompareswith
const_iterator constBegin() const noexcept
void append(parameter_type t)
const_iterator constEnd() const noexcept
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
void setFillRule(Qt::FillRule fillRule)
Sets the fill rule of the painter path to the given fillRule.
void addPolygon(const QPolygonF &polygon)
Adds the given polygon to the path as an (unclosed) subpath.
QPointF pointAtPercent(qreal t) const
Returns the point at at the percentage t of the current path.
The QPainter class performs low-level painting on widgets and other paint devices.
void scale(qreal sx, qreal sy)
Scales the coordinate system by ({sx}, {sy}).
void fillPath(const QPainterPath &path, const QBrush &brush)
Fills the given path using the given brush.
const QTransform & transform() const
Alias for worldTransform().
void resetTransform()
Resets any transformations that were made using translate(), scale(), shear(), rotate(),...
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
void setTransform(const QTransform &transform, bool combine=false)
\inmodule QtCore\reentrant
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
The QPolygonF class provides a list of points using floating point precision.
\inmodule QtCore\reentrant
constexpr qreal height() const noexcept
Returns the height of the rectangle.
constexpr qreal width() const noexcept
Returns the width of the rectangle.
constexpr qreal left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr void setWidth(qreal w) noexcept
Sets the width of the rectangle to the given finite width.
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
constexpr QRect toRect() const noexcept
Returns a QRect based on the values of this rectangle.
constexpr qreal top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
\inmodule QtCore\reentrant
constexpr QRectF toRectF() const noexcept
constexpr QRect translated(int dx, int dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
constexpr void setWidth(int w) noexcept
Sets the width to the given width.
\macro QT_RESTRICTED_CAST_FROM_ASCII
qsizetype indexOf(QLatin1StringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QString mid(qsizetype position, qsizetype n=-1) const &
QSvgDefs(QSvgNode *parent)
Type type() const override
bool shouldDrawNode(QPainter *p, QSvgExtraStates &states) const override
static const QSvgFeFilterPrimitive * castToFilterPrimitive(const QSvgNode *node)
void setSupported(bool supported)
bool shouldDrawNode(QPainter *, QSvgExtraStates &) const override
Type type() const override
QSvgFilterContainer(QSvgNode *parent, const QSvgRectF &bounds, QtSvg::UnitTypes filterUnits, QtSvg::UnitTypes primitiveUnits)
QImage applyFilter(QSvgNode *referenceNode, const QImage &buffer, QPainter *p, QRectF bounds) const
bool shouldDrawNode(QPainter *p, QSvgExtraStates &states) const override
void drawCommand(QPainter *, QSvgExtraStates &) override
Type type() const override
Type type() const override
QSvgMarker(QSvgNode *parent, QRectF bounds, QRectF viewBox, QPointF refP, QSvgSymbolLike::PreserveAspectRatios pAspectRatios, QSvgSymbolLike::Overflow overflow, Orientation orientation, qreal orientationAngle, MarkerUnits markerUnits)
static void drawMarkersForNode(QSvgNode *node, QPainter *p, QSvgExtraStates &states)
void drawCommand(QPainter *p, QSvgExtraStates &states) override
QSvgMask(QSvgNode *parent, QSvgRectF bounds, QtSvg::UnitTypes contentsUnits)
bool shouldDrawNode(QPainter *, QSvgExtraStates &) const override
QImage createMask(QPainter *p, QSvgExtraStates &states, QSvgNode *targetNode, QRectF *globalRect) const
Type type() const override
bool hasAnyMarker() const
QString markerStartId() const
void revertStyle(QPainter *p, QSvgExtraStates &states) const
bool hasMarkerMid() const
bool hasMarkerEnd() const
virtual QRectF bounds(QPainter *p, QSvgExtraStates &states) const
const QStringList & requiredLanguages() const
void applyStyle(QPainter *p, QSvgExtraStates &states) const
bool hasMarkerStart() const
const QStringList & requiredFonts() const
const QStringList & requiredFormats() const
void applyStyleRecursive(QPainter *p, QSvgExtraStates &states) const
DisplayMode displayMode() const
void appendStyleProperty(QSvgStyleProperty *prop, const QString &id)
void draw(QPainter *p, QSvgExtraStates &states)
QString markerEndId() const
static void initPainter(QPainter *p)
const QStringList & requiredFeatures() const
QSvgTinyDocument * document() const
virtual Type type() const =0
const QStringList & requiredExtensions() const
const QPainterPath & path() const
bool shouldDrawNode(QPainter *, QSvgExtraStates &) const override
QImage patternImage(QPainter *p, QSvgExtraStates &states, const QSvgNode *patternElement)
Type type() const override
QSvgPattern(QSvgNode *parent, QSvgRectF bounds, QRectF viewBox, QtSvg::UnitTypes contentUnits, QTransform transform)
const QPolygonF & polygon() const
QRectF combinedWithLocalRect(const QRectF &localRect) const
QPointF translationRelativeToBoundingBox(const QRectF &boundingBox) const
QRectF bounds(QPainter *p, QSvgExtraStates &states) const override
QSvgNode * previousSiblingNode(QSvgNode *n) const
void addChild(QSvgNode *child, const QString &id)
QSvgStructureNode(QSvgNode *parent)
QSvgNode * scopeNode(const QString &id) const
QList< QSvgNode * > renderers() const
QList< QSvgNode * > m_renderers
void drawCommand(QPainter *p, QSvgExtraStates &states) override
QSvgSwitch(QSvgNode *parent)
Type type() const override
PreserveAspectRatios m_pAspectRatios
void setPainterToRectAndAdjustment(QPainter *p) const
QSvgSymbolLike(QSvgNode *parent, QRectF bounds, QRectF viewBox, QPointF refP, QSvgSymbolLike::PreserveAspectRatios pAspectRatios, QSvgSymbolLike::Overflow overflow)
void drawCommand(QPainter *p, QSvgExtraStates &states) override
Type type() const override
QSvgSymbol(QSvgNode *parent, QRectF bounds, QRectF viewBox, QPointF refP, QSvgSymbolLike::PreserveAspectRatios pAspectRatios, QSvgSymbolLike::Overflow overflow)
QSvgNode * namedNode(const QString &id) const
void addNamedNode(const QString &id, QSvgNode *node)
qDeleteAll(list.begin(), list.end())
static const char defaultPattern[]
Combined button and popup list for selecting options.
bool qIsFinite(qfloat16 f) noexcept
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
#define qCWarning(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLuint const GLuint * buffers
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
[4]
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei imageSize
GLuint GLenum GLenum transform
GLsizei const GLchar *const * path
GLfloat GLfloat GLfloat alpha
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
constexpr int qRed(QRgb rgb)
constexpr int qGreen(QRgb rgb)
constexpr QRgb qRgba(int r, int g, int b, int a)
constexpr int qBlue(QRgb rgb)
constexpr int qAlpha(QRgb rgb)
#define QStringLiteral(str)
static QImage & defaultPattern()
static bool isSupportedSvgExtension(const QString &)
static bool isSupportedSvgFeature(const QString &str)
QSvgRenderer * renderer
[0]
\inmodule QtCore \reentrant