31#include "KReportRenderObjects.h"
33static const int LEFTHAND_ODD = 0;
34static const int LEFTHAND_EVEN = 1;
35static const int RIGHTHAND = 2;
37static int const _encodings[10][3][7] = {
39 { { 0, 0, 0, 1, 1, 0, 1}, { 0, 1, 0, 0, 1, 1, 1 }, { 1, 1, 1, 0, 0, 1, 0 } },
40 { { 0, 0, 1, 1, 0, 0, 1}, { 0, 1, 1, 0, 0, 1, 1 }, { 1, 1, 0, 0, 1, 1, 0 } },
41 { { 0, 0, 1, 0, 0, 1, 1}, { 0, 0, 1, 1, 0, 1, 1 }, { 1, 1, 0, 1, 1, 0, 0 } },
42 { { 0, 1, 1, 1, 1, 0, 1}, { 0, 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 1, 0 } },
43 { { 0, 1, 0, 0, 0, 1, 1}, { 0, 0, 1, 1, 1, 0, 1 }, { 1, 0, 1, 1, 1, 0, 0 } },
44 { { 0, 1, 1, 0, 0, 0, 1}, { 0, 1, 1, 1, 0, 0, 1 }, { 1, 0, 0, 1, 1, 1, 0 } },
45 { { 0, 1, 0, 1, 1, 1, 1}, { 0, 0, 0, 0, 1, 0, 1 }, { 1, 0, 1, 0, 0, 0, 0 } },
46 { { 0, 1, 1, 1, 0, 1, 1}, { 0, 0, 1, 0, 0, 0, 1 }, { 1, 0, 0, 0, 1, 0, 0 } },
47 { { 0, 1, 1, 0, 1, 1, 1}, { 0, 0, 0, 1, 0, 0, 1 }, { 1, 0, 0, 1, 0, 0, 0 } },
48 { { 0, 0, 0, 1, 0, 1, 1}, { 0, 0, 1, 0, 1, 1, 1 }, { 1, 1, 1, 0, 1, 0, 0 } }
51static const int odd = LEFTHAND_ODD;
52static const int even = LEFTHAND_EVEN;
54static const int _parity[10][6] = {
55 { odd, odd, odd, odd, odd, odd },
56 { odd, odd, even, odd, even, even },
57 { odd, odd, even, even, odd, even },
58 { odd, odd, even, even, even, odd },
59 { odd, even, odd, odd, even, even },
60 { odd, even, even, odd, odd, even },
61 { odd, even, even, even, odd, odd },
62 { odd, even, odd, even, odd, even },
63 { odd, even, odd, even, even, odd },
64 { odd, even, even, odd, even, odd }
67static const int _upcparenc[10][2][6] = {
69 { { even, even, even, odd, odd, odd }, { odd, odd, odd, even, even, even } },
70 { { even, even, odd, even, odd, odd }, { odd, odd, even, odd, even, even } },
71 { { even, even, odd, odd, even, odd }, { odd, odd, even, even, odd, even } },
72 { { even, even, odd, odd, odd, even }, { odd, odd, even, even, even, odd } },
73 { { even, odd, even, even, odd, odd }, { odd, even, odd, odd, even, even } },
74 { { even, odd, odd, even, even, odd }, { odd, even, even, odd, odd, even } },
75 { { even, odd, odd, odd, even, even }, { odd, even, even, even, odd, odd } },
76 { { even, odd, even, odd, even, odd }, { odd, even, odd, even, odd, even } },
77 { { even, odd, even, odd, odd, even }, { odd, even, odd, even, even, odd } },
78 { { even, odd, odd, even, odd, even }, { odd, even, even, odd, even, odd } }
87 for (
int i = 0; i < 13; ++i) {
98 for (
int i = 0; i < _str.
length(); ++i) {
99 val[i] = ((
QChar) _str.
at(i)).digitValue();
100 if (val[i] == -1)
return;
104 int old_sum = val[12];
106 for (
int i = 0; i < 12; ++i) {
107 checksum += val[i] * ((i % 2) ? 3 : 1);
109 checksum = (checksum % 10);
110 if (checksum) checksum = 10 - checksum;
115 if (old_sum != -1 && old_sum != checksum)
return;
122 int quiet_zone = bar_width * 10;
126 int draw_width = r.
width();
127 int draw_height = r.
height() - 2;
148 int nqz = (draw_width - L) / 2;
149 if (nqz > quiet_zone) quiet_zone = nqz;
151 quiet_zone = draw_width - (L + quiet_zone);
155 int pos = r.
left() + quiet_zone;
166 pPainter->
setPen(oneWide);
176 for (
int i = 0; i < 6; ++i) {
178 for (
int w = 0; w < 7; ++w) {
179 if (_encodings[b][_parity[val[0]][i]][w]) {
194 for (
int i = 0; i < 6; ++i) {
196 for (
int w = 0; w < 7; ++w) {
197 if (_encodings[b][RIGHTHAND][w]) {
211 val[1], val[2], val[3], val[4], val[5], val[6]);
213 val[7], val[8], val[9], val[10], val[11], val[12]);
219 (r.
top() + draw_height) - 7,
223 (r.
top() + draw_height) - 7,
236 for (
int i = 0; i < 13; ++i) {
248 for (
int i = 0; i < _str.
length(); ++i) {
249 val[i+1] = ((
QChar) _str.
at(i)).digitValue();
250 if (val[i+1] == -1)
return;
254 int old_sum = val[12];
256 for (
int i = 0; i < 12; ++i) {
257 checksum += val[i] * ((i % 2) ? 3 : 1);
259 checksum = (checksum % 10);
260 if (checksum) checksum = 10 - checksum;
265 if (old_sum != -1 && old_sum != checksum)
return;
272 int quiet_zone = bar_width * 10;
276 int draw_width = r.
width();
277 int draw_height = r.
height() - 2;
298 int nqz = (draw_width - L) / 2;
299 if (nqz > quiet_zone) quiet_zone = nqz;
301 quiet_zone = draw_width - (L + quiet_zone);
305 int pos = r.
left() + quiet_zone;
316 pPainter->
setPen(oneWide);
326 for (
int i = 0; i < 6; ++i) {
328 for (
int w = 0; w < 7; ++w) {
329 if (_encodings[b][_parity[val[0]][i]][w]) {
330 pPainter->
fillRect(pos, top, 1, draw_height - (i == 0 ? 0 : 7), pPainter->
pen().
color());
344 for (
int i = 0; i < 6; ++i) {
346 for (
int w = 0; w < 7; ++w) {
347 if (_encodings[b][RIGHTHAND][w]) {
348 pPainter->
fillRect(pos, top, 1, draw_height - (i == 5 ? 0 : 7), pPainter->
pen().
color());
362 val[2], val[3], val[4], val[5], val[6]);
364 val[7], val[8], val[9], val[10], val[11]);
370 (r.
top() + draw_height) - 7,
374 (r.
top() + draw_height) - 7,
377 pPainter->
drawText(r.
left() + quiet_zone + L + 2, r.
top() + draw_height - 12,
390 for (
int i = 0; i < 8; ++i) {
401 for (
int i = 0; i < _str.
length(); ++i) {
402 val[i] = ((
QChar) _str.
at(i)).digitValue();
403 if (val[i] == -1)
return;
407 int old_sum = val[7];
409 for (
int i = 0; i < 7; ++i) {
410 checksum += val[i] * ((i % 2) ? 1 : 3);
412 checksum = (checksum % 10);
413 if (checksum) checksum = 10 - checksum;
418 if (old_sum != -1 && old_sum != checksum)
return;
425 int quiet_zone = bar_width * 10;
429 int draw_width = r.
width();
430 int draw_height = r.
height() - 2;
451 int nqz = (draw_width - L) / 2;
452 if (nqz > quiet_zone) quiet_zone = nqz;
454 quiet_zone = draw_width - (L + quiet_zone);
458 int pos = r.
left() + quiet_zone;
469 pPainter->
setPen(oneWide);
479 for (
int i = 0; i < 4; ++i) {
481 for (
int w = 0; w < 7; ++w) {
482 if (_encodings[b][LEFTHAND_ODD][w]) {
497 for (
int i = 0; i < 4; ++i) {
499 for (
int w = 0; w < 7; ++w) {
500 if (_encodings[b][RIGHTHAND][w]) {
513 val[0], val[1], val[2], val[3]);
515 val[4], val[5], val[6], val[7]);
518 (r.
top() + draw_height) - 6,
522 (r.
top() + draw_height) - 6,
535 for (
int i = 0; i < 8; ++i) {
542 if (_str.
length() != 8)
return;
546 for (
int i = 0; i < _str.
length(); ++i) {
547 val[i] = ((
QChar) _str.
at(i)).digitValue();
548 if (val[i] == -1)
return;
556 if (val[0] != 0 && val[0] != 1)
return;
562 int quiet_zone = bar_width * 10;
566 int draw_width = r.
width();
567 int draw_height = r.
height() - 2;
588 int nqz = (draw_width - L) / 2;
589 if (nqz > quiet_zone) quiet_zone = nqz;
591 quiet_zone = draw_width - (L + quiet_zone);
595 int pos = r.
left() + quiet_zone;
606 pPainter->
setPen(oneWide);
616 for (
int i = 0; i < 6; ++i) {
618 for (
int w = 0; w < 7; ++w) {
619 if (_encodings[b][_upcparenc[val[7]][val[0]][i]][w]) {
639 val[1], val[2], val[3], val[4], val[5], val[6]);
645 (r.
top() + draw_height) - 7,
648 pPainter->
drawText(r.
left() + quiet_zone + L + 2, r.
top() + draw_height - 12,
void drawText(const QPoint &position, const QString &text)
void fillRect(const QRect &rectangle, QGradient::Preset preset)
const QPen & pen() const const
void setBrush(Qt::BrushStyle style)
void setFont(const QFont &font)
void setPen(Qt::PenStyle style)
QColor color() const const
QString asprintf(const char *cformat,...)
const QChar at(qsizetype position) const const
qsizetype length() const const
QString number(double n, char format, int precision)