24#include "KReportRenderObjects.h"
30#include "kreportplugin_debug.h"
37const struct code3of9 _3of9codes[] = {
38 {
'0', { 0, 0, 0, 1, 1, 0, 1, 0, 0 } },
39 {
'1', { 1, 0, 0, 1, 0, 0, 0, 0, 1 } },
40 {
'2', { 0, 0, 1, 1, 0, 0, 0, 0, 1 } },
41 {
'3', { 1, 0, 1, 1, 0, 0, 0, 0, 0 } },
42 {
'4', { 0, 0, 0, 1, 1, 0, 0, 0, 1 } },
43 {
'5', { 1, 0, 0, 1, 1, 0, 0, 0, 0 } },
44 {
'6', { 0, 0, 1, 1, 1, 0, 0, 0, 0 } },
45 {
'7', { 0, 0, 0, 1, 0, 0, 1, 0, 1 } },
46 {
'8', { 1, 0, 0, 1, 0, 0, 1, 0, 0 } },
47 {
'9', { 0, 0, 1, 1, 0, 0, 1, 0, 0 } },
49 {
'A', { 1, 0, 0, 0, 0, 1, 0, 0, 1 } },
50 {
'B', { 0, 0, 1, 0, 0, 1, 0, 0, 1 } },
51 {
'C', { 1, 0, 1, 0, 0, 1, 0, 0, 0 } },
52 {
'D', { 0, 0, 0, 0, 1, 1, 0, 0, 1 } },
53 {
'E', { 1, 0, 0, 0, 1, 1, 0, 0, 0 } },
54 {
'F', { 0, 0, 1, 0, 1, 1, 0, 0, 0 } },
55 {
'G', { 0, 0, 0, 0, 0, 1, 1, 0, 1 } },
56 {
'H', { 1, 0, 0, 0, 0, 1, 1, 0, 0 } },
57 {
'I', { 0, 0, 1, 0, 0, 1, 1, 0, 0 } },
58 {
'J', { 0, 0, 0, 0, 1, 1, 1, 0, 0 } },
59 {
'K', { 1, 0, 0, 0, 0, 0, 0, 1, 1 } },
60 {
'L', { 0, 0, 1, 0, 0, 0, 0, 1, 1 } },
61 {
'M', { 1, 0, 1, 0, 0, 0, 0, 1, 0 } },
62 {
'N', { 0, 0, 0, 0, 1, 0, 0, 1, 1 } },
63 {
'O', { 1, 0, 0, 0, 1, 0, 0, 1, 0 } },
64 {
'P', { 0, 0, 1, 0, 1, 0, 0, 1, 0 } },
65 {
'Q', { 0, 0, 0, 0, 0, 0, 1, 1, 1 } },
66 {
'R', { 1, 0, 0, 0, 0, 0, 1, 1, 0 } },
67 {
'S', { 0, 0, 1, 0, 0, 0, 1, 1, 0 } },
68 {
'T', { 0, 0, 0, 0, 1, 0, 1, 1, 0 } },
69 {
'U', { 1, 1, 0, 0, 0, 0, 0, 0, 1 } },
70 {
'V', { 0, 1, 1, 0, 0, 0, 0, 0, 1 } },
71 {
'W', { 1, 1, 1, 0, 0, 0, 0, 0, 0 } },
72 {
'X', { 0, 1, 0, 0, 1, 0, 0, 0, 1 } },
73 {
'Y', { 1, 1, 0, 0, 1, 0, 0, 0, 0 } },
74 {
'Z', { 0, 1, 1, 0, 1, 0, 0, 0, 0 } },
76 {
'-', { 0, 1, 0, 0, 0, 0, 1, 0, 1 } },
77 {
'.', { 1, 1, 0, 0, 0, 0, 1, 0, 0 } },
78 {
' ', { 0, 1, 1, 0, 0, 0, 1, 0, 0 } },
79 {
'$', { 0, 1, 0, 1, 0, 1, 0, 0, 0 } },
80 {
'/', { 0, 1, 0, 1, 0, 0, 0, 1, 0 } },
81 {
'+', { 0, 1, 0, 0, 0, 1, 0, 1, 0 } },
82 {
'%', { 0, 0, 0, 1, 0, 1, 0, 1, 0 } },
84 {
'*', { 0, 1, 0, 0, 1, 0, 1, 0, 0 } },
86 {
'\0', { 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
89int codeIndex(
QChar code)
92 const char latin1Code = code.
toUpper().toLatin1();
93 for (
int idx = 0; _3of9codes[idx].code !=
'\0'; idx++) {
94 if (_3of9codes[idx].code == latin1Code)
return idx;
104 qreal narrow_bar = 1;
105 qreal interchange_gap = narrow_bar;
106 int bar_width_mult = 2;
109 qreal quiet_zone = narrow_bar * 10;
110 if (quiet_zone < 0.1)
114 qreal draw_width = r.
width();
115 qreal draw_height = r.
height();
118 int val_length = str.
length();
128 qreal C = val_length;
129 qreal N = bar_width_mult;
130 qreal X = narrow_bar;
131 qreal I = interchange_gap;
133 L = ((C + 2.0) * (3.0 * N + 6.0) * X) + ((C + 1.0) * I);
145 qreal nqz = (draw_width - L) / 2.0;
146 if (nqz > quiet_zone)
149 quiet_zone = draw_width - (L + quiet_zone);
153 qreal pos = r.
left() + quiet_zone;
162 for (
int i = 0; i < str.
length(); i++) {
165 int idx = codeIndex(c);
168 kreportpluginWarning() <<
"Encountered a non-compliant character while rendering a 3of9 barcode -- skipping";
173 for (
int b = 0; b < 9; b++, space = !space) {
174 qreal w = (_3of9codes[idx].values[b] == 1 ? narrow_bar * bar_width_mult : narrow_bar);
179 rect->setBrush(brush);
180 rect->setRect(
QRectF(pos, top, w, draw_height));
181 page->insertPrimitive(rect);
185 pos += interchange_gap;
Represents a single page in a document and may contain zero or more OROPrimitive objects all of which...
char32_t toUpper(char32_t ucs4)
qreal height() const const
qreal width() const const
const QChar at(qsizetype position) const const
qsizetype length() const const