diff options
Diffstat (limited to 'src/svg/qsvgstyle.cpp')
-rw-r--r-- | src/svg/qsvgstyle.cpp | 96 |
1 files changed, 46 insertions, 50 deletions
diff --git a/src/svg/qsvgstyle.cpp b/src/svg/qsvgstyle.cpp index d425923..604b4e4 100644 --- a/src/svg/qsvgstyle.cpp +++ b/src/svg/qsvgstyle.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt SVG module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qsvgstyle_p.h" @@ -61,7 +25,8 @@ QSvgExtraStates::QSvgExtraStates() fontWeight(QFont::Normal), fillRule(Qt::WindingFill), strokeDashOffset(0), - vectorEffect(false) + vectorEffect(false), + imageRendering(QSvgQualityStyle::ImageRenderingAuto) { } @@ -81,16 +46,46 @@ void QSvgFillStyleProperty::revert(QPainter *, QSvgExtraStates &) QSvgQualityStyle::QSvgQualityStyle(int color) + : m_imageRendering(QSvgQualityStyle::ImageRenderingAuto) + , m_oldImageRendering(QSvgQualityStyle::ImageRenderingAuto) + , m_imageRenderingSet(0) { Q_UNUSED(color); } -void QSvgQualityStyle::apply(QPainter *, const QSvgNode *, QSvgExtraStates &) -{ +void QSvgQualityStyle::setImageRendering(ImageRendering hint) { + m_imageRendering = hint; + m_imageRenderingSet = 1; } -void QSvgQualityStyle::revert(QPainter *, QSvgExtraStates &) + +void QSvgQualityStyle::apply(QPainter *p, const QSvgNode *, QSvgExtraStates &states) { + m_oldImageRendering = states.imageRendering; + if (m_imageRenderingSet) { + states.imageRendering = m_imageRendering; + } + if (m_imageRenderingSet) { + bool smooth = false; + if (m_imageRendering == ImageRenderingAuto) + // auto (the spec says to prefer quality) + smooth = true; + else + smooth = (m_imageRendering == ImageRenderingOptimizeQuality); + p->setRenderHint(QPainter::SmoothPixmapTransform, smooth); + } +} +void QSvgQualityStyle::revert(QPainter *p, QSvgExtraStates &states) +{ + if (m_imageRenderingSet) { + states.imageRendering = m_oldImageRendering; + bool smooth = false; + if (m_oldImageRendering == ImageRenderingAuto) + smooth = true; + else + smooth = (m_oldImageRendering == ImageRenderingOptimizeQuality); + p->setRenderHint(QPainter::SmoothPixmapTransform, smooth); + } } QSvgFillStyle::QSvgFillStyle() @@ -127,7 +122,7 @@ void QSvgFillStyle::setFillStyle(QSvgFillStyleProperty* style) void QSvgFillStyle::setBrush(QBrush brush) { m_fill = std::move(brush); - m_style = 0; + m_style = nullptr; m_fillSet = 1; } @@ -232,7 +227,9 @@ void QSvgFontStyle::apply(QPainter *p, const QSvgNode *, QSvgExtraStates &states } else { states.fontWeight = m_weight; } - font.setWeight(QFont::Weight(states.fontWeight)); + font.setWeight(QFont::Weight(qBound(static_cast<int>(QFont::Weight::Thin), + states.fontWeight, + static_cast<int>(QFont::Weight::Black)))); } p->setFont(font); @@ -633,8 +630,8 @@ void QSvgAnimateTransform::setArgs(TransformType type, Additive additive, const m_type = type; m_args = args; m_additive = additive; - Q_ASSERT(!(args.count()%3)); - m_count = args.count() / 3; + Q_ASSERT(!(args.size()%3)); + m_count = args.size() / 3; } void QSvgAnimateTransform::apply(QPainter *p, const QSvgNode *node, QSvgExtraStates &) @@ -653,7 +650,6 @@ void QSvgAnimateTransform::revert(QPainter *p, QSvgExtraStates &) void QSvgAnimateTransform::resolveMatrix(const QSvgNode *node) { - static const qreal deg2rad = qreal(0.017453292519943295769); qreal totalTimeElapsed = node->document()->currentElapsed(); if (totalTimeElapsed < m_from || m_finished) return; @@ -753,7 +749,7 @@ void QSvgAnimateTransform::resolveMatrix(const QSvgNode *node) qreal transXDiff = (to1-from1) * percentOfAnimation; qreal transX = from1 + transXDiff; m_transform = QTransform(); - m_transform.shear(qTan(transX * deg2rad), 0); + m_transform.shear(qTan(qDegreesToRadians(transX)), 0); break; } case SkewY: { @@ -768,7 +764,7 @@ void QSvgAnimateTransform::resolveMatrix(const QSvgNode *node) qreal transYDiff = (to1 - from1) * percentOfAnimation; qreal transY = from1 + transYDiff; m_transform = QTransform(); - m_transform.shear(0, qTan(transY * deg2rad)); + m_transform.shear(0, qTan(qDegreesToRadians(transY))); break; } default: @@ -840,7 +836,7 @@ void QSvgAnimateColor::apply(QPainter *p, const QSvgNode *node, QSvgExtraStates percentOfAnimation -= ((int)percentOfAnimation); } - qreal currentPosition = percentOfAnimation * (m_colors.count() - 1); + qreal currentPosition = percentOfAnimation * (m_colors.size() - 1); int startElem = qFloor(currentPosition); int endElem = qCeil(currentPosition); |