diff options
Diffstat (limited to 'src/gui/painting/qpagesize.cpp')
-rw-r--r-- | src/gui/painting/qpagesize.cpp | 69 |
1 files changed, 20 insertions, 49 deletions
diff --git a/src/gui/painting/qpagesize.cpp b/src/gui/painting/qpagesize.cpp index fb7eb45b93..37f66fe63d 100644 --- a/src/gui/painting/qpagesize.cpp +++ b/src/gui/painting/qpagesize.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2014 John Layt <jlayt@kde.org> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui 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) 2014 John Layt <jlayt@kde.org> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qpagesize.h" @@ -48,6 +12,12 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + +QT_IMPL_METATYPE_EXTERN(QPageSize) +QT_IMPL_METATYPE_EXTERN_TAGGED(QPageSize::PageSizeId, QPageSize__PageSizeId) +QT_IMPL_METATYPE_EXTERN_TAGGED(QPageSize::Unit, QPageSize__Unit) + // Define the Windows DMPAPER sizes for use in the look-up table // See http://msdn.microsoft.com/en-us/library/windows/desktop/dd319099.aspx @@ -224,16 +194,16 @@ static const int qt_windowsConversion[][2] = { // Standard sizes data struct StandardPageSize { - QPageSize::PageSizeId id; - int windowsId; // Windows DMPAPER value - QPageSize::Unit definitionUnits; // Standard definition size, e.g. ISO uses mm, ANSI uses inches - int widthPoints; - int heightPoints; + QPageSize::PageSizeId id : 8; + int windowsId : 16; // Windows DMPAPER value + QPageSize::Unit definitionUnits : 8; // Standard definition size, e.g. ISO uses mm, ANSI uses inches + int widthPoints : 16; + int heightPoints : 16; qreal widthMillimeters; qreal heightMillimeters; qreal widthInches; qreal heightInches; - const char *mediaOption; // PPD standard mediaOption ID + const char mediaOption[20]; // PPD standard mediaOption ID }; // Standard page sizes taken from the Postscript PPD Standard v4.3 @@ -386,6 +356,7 @@ static const StandardPageSize qt_pageSizes[] = { static const int pageSizesCount = int(sizeof(qt_pageSizes) / sizeof(qt_pageSizes[0])); static_assert(pageSizesCount == QPageSize::LastPageSize + 1); +static_assert(QPageSize::LastPageSize < 256); // Return key name for PageSize static QString qt_keyForPageSizeId(QPageSize::PageSizeId id) @@ -400,12 +371,12 @@ static QPageSize::PageSizeId qt_idForPpdKey(const QString &ppdKey, QSize *match return QPageSize::Custom; QStringView key(ppdKey); // Remove any Rotated or Tranverse modifiers - if (key.endsWith(QLatin1String("Rotated"))) + if (key.endsWith("Rotated"_L1)) key.chop(7); - else if (key.endsWith(QLatin1String(".Transverse"))) + else if (key.endsWith(".Transverse"_L1)) key.chop(11); for (int i = 0; i <= int(QPageSize::LastPageSize); ++i) { - if (QLatin1String(qt_pageSizes[i].mediaOption) == key) { + if (QLatin1StringView(qt_pageSizes[i].mediaOption) == key) { if (match) *match = QSize(qt_pageSizes[i].widthPoints, qt_pageSizes[i].heightPoints); return qt_pageSizes[i].id; @@ -572,7 +543,7 @@ static QSize qt_convertPointsToPixels(const QSize &size, int resolution) if (!size.isValid() || resolution <= 0) return QSize(); const qreal multiplier = qt_pixelMultiplier(resolution); - return QSize(qRound(size.width() / multiplier), qRound(size.height() / multiplier)); + return QSize(qFloor(size.width() / multiplier), qFloor(size.height() / multiplier)); } static QSizeF qt_convertPointsToUnits(const QSize &size, QPageSize::Unit units) @@ -898,7 +869,7 @@ QSizeF QPageSizePrivate::size(QPageSize::Unit units) const QSize QPageSizePrivate::sizePixels(int resolution) const { - return qt_convertPointsToPixels(m_pointSize, resolution);; + return qt_convertPointsToPixels(m_pointSize, resolution); } |