Prison

pdf417barcode.cpp
1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#include "pdf417barcode_p.h"
8#include "zxingutil_p.h"
9
10#include <ZXing/BitMatrix.h>
11#include <ZXing/MultiFormatWriter.h>
12
13#include <stdexcept>
14
15using namespace Prison;
16
17Pdf417Barcode::Pdf417Barcode()
18 : AbstractBarcodePrivate(Barcode::TwoDimensions)
19{
20}
21
22QImage Pdf417Barcode::paintImage()
23{
24 try {
25 ZXing::MultiFormatWriter writer(ZXing::BarcodeFormat::PDF417);
26 // ISO/IEC 15438:2006(E) ยง5.8.3 Quiet Zone
27 writer.setMargin(2);
28 if (m_data.userType() == QMetaType::QByteArray) {
29 writer.setEncoding(ZXing::CharacterSet::BINARY);
30 }
31 // aspect ratio 4 is hard-coded in ZXing
32 const auto matrix = writer.encode(ZXingUtil::toStdWString(m_data), 4, 1);
33 return ZXingUtil::toImage(matrix, m_foreground, m_background);
34 } catch (const std::invalid_argument &e) {
35 }; // input too large
36 return {};
37}
38
39QSizeF Pdf417Barcode::preferredSize(qreal devicePixelRatio) const
40{
41 return m_cache.size() * (devicePixelRatio < 2 ? 2 : 1);
42}
A barcode generator for a fixed barcode format.
Definition barcode.h:40
Provides classes and methods for generating barcodes.
Definition barcode.h:24
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 4 2024 11:57:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.