Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmake/FindWrapCPDB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Create an empty interface library for WrapCPDB when CPDB is not available
add_library(WrapCPDB::WrapCPDB INTERFACE IMPORTED GLOBAL)
set(WrapCPDB_FOUND TRUE)
23 changes: 23 additions & 0 deletions src/gui/painting/qpagesize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ class QPageSizePrivate : public QSharedData
const QString &name,
QPageSize::SizeMatchPolicy matchPolicy);
QPageSizePrivate(const QString &key, const QSize &size, const QString &name);
QPageSizePrivate(const QString &key, const QSizeF &size,
QPageSize::Unit units, const QString &name);
QPageSizePrivate(int windowsId, const QSize &pointSize, const QString &name);
~QPageSizePrivate();

Expand Down Expand Up @@ -773,6 +775,15 @@ QPageSizePrivate::QPageSizePrivate(const QString &key, const QSize &pointSize, c
}
}

QPageSizePrivate::QPageSizePrivate(const QString &key, const QSizeF &size,
QPageSize::Unit units, const QString &name)
: m_id(QPageSize::Custom),
m_windowsId(0)
{
init(size, units, name);
m_key = key;
}

QPageSizePrivate::QPageSizePrivate(int windowsId, const QSize &pointSize, const QString &name)
: m_id(QPageSize::Custom),
m_windowsId(0),
Expand Down Expand Up @@ -1156,6 +1167,18 @@ QPageSize::QPageSize(const QString &key, const QSize &pointSize, const QString &
{
}

/*!
\internal

Create page with given key, size, units and name, for use by printer plugin.
*/

QPageSize::QPageSize(const QString &key, const QSizeF &size,
QPageSize::Unit units, const QString &name)
: d(new QPageSizePrivate(key, size, units, name))
{
}

/*!
\internal

Expand Down
2 changes: 2 additions & 0 deletions src/gui/painting/qpagesize.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ class Q_GUI_EXPORT QPageSize
{ return !(lhs == rhs); }

QPageSize(const QString &key, const QSize &pointSize, const QString &name);
QPageSize(const QString &key, const QSizeF &size,
QPageSize::Unit units, const QString &name);
QPageSize(int windowsId, const QSize &pointSize, const QString &name);
QPageSize(QPageSizePrivate &dd);
QSharedDataPointer<QPageSizePrivate> d;
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/printsupport/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause

if(QT_FEATURE_cups AND UNIX AND NOT APPLE)
# Generated from printsupport.pro.

if(QT_FEATURE_cpdb AND UNIX AND NOT APPLE)
add_subdirectory(cpdb)
endif()
if (QT_FEATURE_cups AND UNIX AND NOT APPLE)
add_subdirectory(cups)
endif()
24 changes: 24 additions & 0 deletions src/plugins/printsupport/cpdb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

qt_find_package(WrapCPDB
PROVIDED_TARGETS WrapCPDB::WrapCPDB MODULE_NAME printsupport QMAKE_LIB cpdb)

qt_internal_add_plugin(QCpdbPrinterSupportPlugin
OUTPUT_NAME cpdbprintersupport
PLUGIN_TYPE printsupport
SOURCES
main.cpp
qcpdb.cpp qcpdb_p.h
qcpdbprintengine.cpp qcpdbprintengine_p.h
qcpdbprintersupport.cpp qcpdbprintersupport_p.h
qcpdbprintdevice.cpp qcpdbprintdevice.h
INCLUDE_DIRECTORIES
../../../printsupport/kernel
LIBRARIES
WrapCPDB::WrapCPDB
Qt::Core
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
Qt::PrintSupport
Qt::PrintSupportPrivate
)
4 changes: 4 additions & 0 deletions src/plugins/printsupport/cpdb/cpdb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Keys": [ "cpdbprintersupport" ],
"Priority": 80
}
37 changes: 37 additions & 0 deletions src/plugins/printsupport/cpdb/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (C) 2022-2023 Gaurav Guleria <[email protected]>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qcpdbprintersupport_p.h"

#include <qpa/qplatformprintplugin.h>
#include <QtCore/QStringList>

QT_BEGIN_NAMESPACE

using namespace Qt::StringLiterals;

class QCpdbPrinterSupportPlugin : public QPlatformPrinterSupportPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QPlatformPrinterSupportFactoryInterface_iid FILE "cpdb.json")

public:
QStringList keys() const;
QPlatformPrinterSupport *create(const QString &) override;
};

QStringList QCpdbPrinterSupportPlugin::keys() const
{
return QStringList(QStringLiteral("cpdbprintersupport"));
}

QPlatformPrinterSupport *QCpdbPrinterSupportPlugin::create(const QString &key)
{
if (key.compare(key, "cpdbprintersupport"_L1, Qt::CaseInsensitive) == 0)
return new QCpdbPrinterSupport;
return 0;
}

QT_END_NAMESPACE

#include "main.moc"
27 changes: 27 additions & 0 deletions src/plugins/printsupport/cpdb/qcpdb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2022-2023 Gaurav Guleria <[email protected]>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qcpdb_p.h"

QT_BEGIN_NAMESPACE

const char *QCPDBSupport::translateOption(cpdb_printer_obj_t * printerObj, const char *optionName)
{

QByteArray locale = QLocale().bcp47Name().toLocal8Bit().replace('-', '_');
return cpdbGetOptionTranslation(printerObj, optionName, locale.constData());
}

const char *QCPDBSupport::translateChoice(cpdb_printer_obj_t *printerObj, const char *optionName, const char *choiceName)
{
QByteArray locale = QLocale().bcp47Name().toLocal8Bit().replace('-', '_');
return cpdbGetChoiceTranslation(printerObj, optionName, choiceName, locale.constData());
}

const char *QCPDBSupport::translateGroup(cpdb_printer_obj_t *printerObj, const char *groupName)
{
QByteArray locale = QLocale().bcp47Name().toLocal8Bit().replace('-', '_');
return cpdbGetOptionTranslation(printerObj, groupName, locale.constData());
}

QT_END_NAMESPACE
75 changes: 75 additions & 0 deletions src/plugins/printsupport/cpdb/qcpdb_p.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (C) 2022-2023 Gaurav Guleria <[email protected]>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QCPDBSUPPORT_H
#define QCPDBSUPPORT_H

//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// to version without notice, or even be removed.
//
// We mean it.
//
//

#include <QtPrintSupport/private/qtprintsupportglobal_p.h>
#include <QtPrintSupport/private/qprint_p.h>
#include <QHash>
#include <QLocale>

#include <cpdb/frontend.h>

QT_REQUIRE_CONFIG(cpdb);

QT_BEGIN_NAMESPACE

class QPrintDevice;

#define PDPK_CpdbPrinterObj QPrintDevice::PrintDevicePropertyKey(QPrintDevice::PDPK_CustomBase + 0x10)

class QCPDBSupport
{
public:
constexpr static qreal pointsMultiplier = 2.83464566929; // 1mm to points

static const char *translateOption(cpdb_printer_obj_t *printerObj, const char *optionName);
static const char *translateChoice(cpdb_printer_obj_t *printerObj, const char *optionName, const char *choiceName);
static const char *translateGroup(cpdb_printer_obj_t *printerObj, const char *groupName);

const static inline QHash<QByteArray,QByteArray> numUpDist = {
{"1", "1x1"},
{"2", "2x1"},
{"4", "2x2"},
{"6", "2x3"},
{"9", "3x3"},
{"16", "4x4"},

{"1x1", "1"},
{"2x1", "2"},
{"2x2", "4"},
{"2x3", "6"},
{"3x3", "9"},
{"4x4", "16"},
};

const static inline QHash<QByteArray,QPrint::DuplexMode> duplexMap = {
{CPDB_SIDES_ONE_SIDED, QPrint::DuplexNone},
{CPDB_SIDES_TWO_SIDED_SHORT, QPrint::DuplexShortSide},
{CPDB_SIDES_TWO_SIDED_LONG, QPrint::DuplexLongSide}
};

const static inline QHash<QPrint::DuplexMode,QByteArray> qDuplexMap = {
{QPrint::DuplexNone, CPDB_SIDES_ONE_SIDED},
{QPrint::DuplexShortSide, CPDB_SIDES_TWO_SIDED_SHORT},
{QPrint::DuplexLongSide, CPDB_SIDES_TWO_SIDED_LONG}
};
};


QT_END_NAMESPACE

#endif // QCPDBSUPPORT_H
Loading