Changeset View
Changeset View
Standalone View
Standalone View
src/lib/code128barcode.cpp
Show All 37 Lines | 30 | enum CodeSetOp : uint8_t { | |||
---|---|---|---|---|---|
38 | LatchC = 99 | 38 | LatchC = 99 | ||
39 | }; | 39 | }; | ||
40 | 40 | | |||
41 | Code128Barcode::Code128Barcode() : AbstractBarcode(AbstractBarcode::OneDimension) {} | 41 | Code128Barcode::Code128Barcode() : AbstractBarcode(AbstractBarcode::OneDimension) {} | ||
42 | Code128Barcode::~Code128Barcode() = default; | 42 | Code128Barcode::~Code128Barcode() = default; | ||
43 | 43 | | |||
44 | QImage Code128Barcode::paintImage(const QSizeF& size) | 44 | QImage Code128Barcode::paintImage(const QSizeF& size) | ||
45 | { | 45 | { | ||
46 | if (size.height() < 1) | 46 | Q_UNUSED(size); | ||
47 | return {}; | | |||
48 | 47 | | |||
49 | const auto bits = encode(data().toLatin1()); | 48 | const auto bits = encode(data().toLatin1()); | ||
50 | const auto width = bits.size() + 2 * QuietZone; | 49 | const auto width = bits.size() + 2 * QuietZone; | ||
51 | setMinimumSize(QSizeF(width, 10)); | 50 | setMinimumSize(QSizeF(width, 1)); | ||
52 | | ||||
53 | const auto moduleSize = size.width() / width; | | |||
54 | if (moduleSize < 1) // too small for this | | |||
55 | return {}; | | |||
56 | 51 | | |||
57 | QImage img(moduleSize * width, size.height(), QImage::Format_ARGB32); | 52 | QImage img(width, 1, QImage::Format_ARGB32); | ||
58 | img.fill(backgroundColor()); | 53 | img.fill(backgroundColor()); | ||
59 | QPainter p(&img); | 54 | QPainter p(&img); | ||
60 | for (int i = 0; i < bits.size(); ++i) { | 55 | for (int i = 0; i < bits.size(); ++i) { | ||
61 | if (bits.at(i)) | 56 | if (bits.at(i)) { | ||
62 | p.fillRect(QRectF((QuietZone + i) * moduleSize, 0, moduleSize, img.height()), foregroundColor()); | 57 | img.setPixel(QuietZone + i, 0, foregroundColor().rgb()); | ||
58 | } | ||||
63 | } | 59 | } | ||
64 | 60 | | |||
65 | return img; | 61 | return img; | ||
66 | } | 62 | } | ||
67 | 63 | | |||
68 | // Code 128 symbol table | 64 | // Code 128 symbol table | ||
69 | // ### this is the perfect use-case for binary literals (as the binary pattern | 65 | // ### this is the perfect use-case for binary literals (as the binary pattern | ||
70 | // corresponds to the line pattern), adjust this once KF5 moves to C++14 | 66 | // corresponds to the line pattern), adjust this once KF5 moves to C++14 | ||
▲ Show 20 Lines • Show All 266 Lines • Show Last 20 Lines |