29#include "kreportplugin_debug.h"
36const struct code3of9 _3of9codes[] = {
37 {
'0', { 0, 0, 0, 1, 1, 0, 1, 0, 0 } },
38 {
'1', { 1, 0, 0, 1, 0, 0, 0, 0, 1 } },
39 {
'2', { 0, 0, 1, 1, 0, 0, 0, 0, 1 } },
40 {
'3', { 1, 0, 1, 1, 0, 0, 0, 0, 0 } },
41 {
'4', { 0, 0, 0, 1, 1, 0, 0, 0, 1 } },
42 {
'5', { 1, 0, 0, 1, 1, 0, 0, 0, 0 } },
43 {
'6', { 0, 0, 1, 1, 1, 0, 0, 0, 0 } },
44 {
'7', { 0, 0, 0, 1, 0, 0, 1, 0, 1 } },
45 {
'8', { 1, 0, 0, 1, 0, 0, 1, 0, 0 } },
46 {
'9', { 0, 0, 1, 1, 0, 0, 1, 0, 0 } },
48 {
'A', { 1, 0, 0, 0, 0, 1, 0, 0, 1 } },
49 {
'B', { 0, 0, 1, 0, 0, 1, 0, 0, 1 } },
50 {
'C', { 1, 0, 1, 0, 0, 1, 0, 0, 0 } },
51 {
'D', { 0, 0, 0, 0, 1, 1, 0, 0, 1 } },
52 {
'E', { 1, 0, 0, 0, 1, 1, 0, 0, 0 } },
53 {
'F', { 0, 0, 1, 0, 1, 1, 0, 0, 0 } },
54 {
'G', { 0, 0, 0, 0, 0, 1, 1, 0, 1 } },
55 {
'H', { 1, 0, 0, 0, 0, 1, 1, 0, 0 } },
56 {
'I', { 0, 0, 1, 0, 0, 1, 1, 0, 0 } },
57 {
'J', { 0, 0, 0, 0, 1, 1, 1, 0, 0 } },
58 {
'K', { 1, 0, 0, 0, 0, 0, 0, 1, 1 } },
59 {
'L', { 0, 0, 1, 0, 0, 0, 0, 1, 1 } },
60 {
'M', { 1, 0, 1, 0, 0, 0, 0, 1, 0 } },
61 {
'N', { 0, 0, 0, 0, 1, 0, 0, 1, 1 } },
62 {
'O', { 1, 0, 0, 0, 1, 0, 0, 1, 0 } },
63 {
'P', { 0, 0, 1, 0, 1, 0, 0, 1, 0 } },
64 {
'Q', { 0, 0, 0, 0, 0, 0, 1, 1, 1 } },
65 {
'R', { 1, 0, 0, 0, 0, 0, 1, 1, 0 } },
66 {
'S', { 0, 0, 1, 0, 0, 0, 1, 1, 0 } },
67 {
'T', { 0, 0, 0, 0, 1, 0, 1, 1, 0 } },
68 {
'U', { 1, 1, 0, 0, 0, 0, 0, 0, 1 } },
69 {
'V', { 0, 1, 1, 0, 0, 0, 0, 0, 1 } },
70 {
'W', { 1, 1, 1, 0, 0, 0, 0, 0, 0 } },
71 {
'X', { 0, 1, 0, 0, 1, 0, 0, 0, 1 } },
72 {
'Y', { 1, 1, 0, 0, 1, 0, 0, 0, 0 } },
73 {
'Z', { 0, 1, 1, 0, 1, 0, 0, 0, 0 } },
75 {
'-', { 0, 1, 0, 0, 0, 0, 1, 0, 1 } },
76 {
'.', { 1, 1, 0, 0, 0, 0, 1, 0, 0 } },
77 {
' ', { 0, 1, 1, 0, 0, 0, 1, 0, 0 } },
78 {
'$', { 0, 1, 0, 1, 0, 1, 0, 0, 0 } },
79 {
'/', { 0, 1, 0, 1, 0, 0, 0, 1, 0 } },
80 {
'+', { 0, 1, 0, 0, 0, 1, 0, 1, 0 } },
81 {
'%', { 0, 0, 0, 1, 0, 1, 0, 1, 0 } },
83 {
'*', { 0, 1, 0, 0, 1, 0, 1, 0, 0 } },
85 {
'\0', { 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
88int codeIndexP(
QChar code)
91 const char latin1Code = code.
toUpper().toLatin1();
92 for (
int idx = 0; _3of9codes[idx].code !=
'\0'; idx++) {
93 if (_3of9codes[idx].code == latin1Code)
return idx;
103 int interchange_gap = narrow_bar;
104 int bar_width_mult = 2;
107 int quiet_zone = narrow_bar * 10;
111 int draw_width = r.
width();
112 int draw_height = r.
height();
115 int val_length = str.
length();
126 int N = bar_width_mult;
128 int I = interchange_gap;
130 L = ((C + 2) * (3 * N + 6) * X) + ((C + 1) * I);
142 int nqz = (draw_width - L) / 2;
143 if (nqz > quiet_zone) quiet_zone = nqz;
145 quiet_zone = draw_width - (L + quiet_zone);
149 int pos = r.
left() + quiet_zone;
163 pPainter->
setPen(oneWide);
166 for (
int i = 0; i < str.
length(); i++) {
169 int idx = codeIndexP(c);
171 kreportpluginWarning() <<
"Encountered a non-compliant character while rendering a 3of9 barcode -- skipping";
176 for (
int b = 0; b < 9; b++, space = !space) {
177 int w = (_3of9codes[idx].values[b] == 1 ? narrow_bar * bar_width_mult : narrow_bar);
178 if (!space && pPainter) {
183 pos += interchange_gap;
char32_t toUpper(char32_t ucs4)
void fillRect(const QRect &rectangle, QGradient::Preset preset)
const QPen & pen() const const
void setBrush(Qt::BrushStyle style)
void setPen(Qt::PenStyle style)
QColor color() const const
const QChar at(qsizetype position) const const
qsizetype length() const const