KReport

codeeanpaint.cpp
1 /* This file is part of the KDE project
2  * Copyright (C) 2001-2007 by OpenMFG, LLC ([email protected])
3  * Copyright (C) 2007-2008 by Adam Pigg ([email protected])
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 /*
20  * This file contains the implementation of the Code EAN and similar
21  * formats for rendering purposes. All this code assumes a 100dpi
22  * rendering surface for it's calculations.
23  */
24 
25 #include <QString>
26 #include <QRect>
27 #include <QPainter>
28 #include <QPen>
29 #include <QBrush>
30 
31 #include "KReportRenderObjects.h"
32 
33 static const int LEFTHAND_ODD = 0;
34 static const int LEFTHAND_EVEN = 1;
35 static const int RIGHTHAND = 2;
36 
37 static int const _encodings[10][3][7] = {
38  /* LEFTHAND_ODD */ /* LEFTHAND_EVEN */ /* RIGHTHAND */
39  { { 0, 0, 0, 1, 1, 0, 1}, { 0, 1, 0, 0, 1, 1, 1 }, { 1, 1, 1, 0, 0, 1, 0 } }, // 0
40  { { 0, 0, 1, 1, 0, 0, 1}, { 0, 1, 1, 0, 0, 1, 1 }, { 1, 1, 0, 0, 1, 1, 0 } }, // 1
41  { { 0, 0, 1, 0, 0, 1, 1}, { 0, 0, 1, 1, 0, 1, 1 }, { 1, 1, 0, 1, 1, 0, 0 } }, // 2
42  { { 0, 1, 1, 1, 1, 0, 1}, { 0, 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 1, 0 } }, // 3
43  { { 0, 1, 0, 0, 0, 1, 1}, { 0, 0, 1, 1, 1, 0, 1 }, { 1, 0, 1, 1, 1, 0, 0 } }, // 4
44  { { 0, 1, 1, 0, 0, 0, 1}, { 0, 1, 1, 1, 0, 0, 1 }, { 1, 0, 0, 1, 1, 1, 0 } }, // 5
45  { { 0, 1, 0, 1, 1, 1, 1}, { 0, 0, 0, 0, 1, 0, 1 }, { 1, 0, 1, 0, 0, 0, 0 } }, // 6
46  { { 0, 1, 1, 1, 0, 1, 1}, { 0, 0, 1, 0, 0, 0, 1 }, { 1, 0, 0, 0, 1, 0, 0 } }, // 7
47  { { 0, 1, 1, 0, 1, 1, 1}, { 0, 0, 0, 1, 0, 0, 1 }, { 1, 0, 0, 1, 0, 0, 0 } }, // 8
48  { { 0, 0, 0, 1, 0, 1, 1}, { 0, 0, 1, 0, 1, 1, 1 }, { 1, 1, 1, 0, 1, 0, 0 } } // 9
49 };
50 
51 static const int odd = LEFTHAND_ODD;
52 static const int even = LEFTHAND_EVEN;
53 
54 static const int _parity[10][6] = {
55  { odd, odd, odd, odd, odd, odd }, // 0
56  { odd, odd, even, odd, even, even }, // 1
57  { odd, odd, even, even, odd, even }, // 2
58  { odd, odd, even, even, even, odd }, // 3
59  { odd, even, odd, odd, even, even }, // 4
60  { odd, even, even, odd, odd, even }, // 5
61  { odd, even, even, even, odd, odd }, // 6
62  { odd, even, odd, even, odd, even }, // 7
63  { odd, even, odd, even, even, odd }, // 8
64  { odd, even, even, odd, even, odd } // 9
65 };
66 
67 static const int _upcparenc[10][2][6] = {
68  /* PARITY 0 */ /* PARITY 1 */
69  { { even, even, even, odd, odd, odd }, { odd, odd, odd, even, even, even } }, // 0
70  { { even, even, odd, even, odd, odd }, { odd, odd, even, odd, even, even } }, // 1
71  { { even, even, odd, odd, even, odd }, { odd, odd, even, even, odd, even } }, // 2
72  { { even, even, odd, odd, odd, even }, { odd, odd, even, even, even, odd } }, // 3
73  { { even, odd, even, even, odd, odd }, { odd, even, odd, odd, even, even } }, // 4
74  { { even, odd, odd, even, even, odd }, { odd, even, even, odd, odd, even } }, // 5
75  { { even, odd, odd, odd, even, even }, { odd, even, even, even, odd, odd } }, // 6
76  { { even, odd, even, odd, even, odd }, { odd, even, odd, even, odd, even } }, // 7
77  { { even, odd, even, odd, odd, even }, { odd, even, odd, even, even, odd } }, // 8
78  { { even, odd, odd, even, odd, even }, { odd, even, even, odd, even, odd } } // 9
79 };
80 
81 
82 void renderCodeEAN13(const QRect & r, const QString & _str, Qt::Alignment align, QPainter * pPainter)
83 {
84  int val[13];
85 
86  // initialize all the values just so we can be predictable
87  for (int i = 0; i < 13; ++i) {
88  val[i] = -1;
89  }
90 
91  // verify that the passed in string is valid
92  // if it's not either twelve or thirteen characters
93  // then it must be invalid to begin with
94  if (_str.length() != 12 && _str.length() != 13) return;
95  // loop through and convert each char to a digit.
96  // if we can't convert all characters then this is
97  // an invalid number
98  for (int i = 0; i < _str.length(); ++i) {
99  val[i] = ((QChar) _str.at(i)).digitValue();
100  if (val[i] == -1) return;
101  }
102 
103  // calculate and append the checksum value
104  int old_sum = val[12]; // get the old check sum value (-1 if none was set)
105  int checksum = 0;
106  for (int i = 0; i < 12; ++i) {
107  checksum += val[i] * ((i % 2) ? 3 : 1);
108  }
109  checksum = (checksum % 10);
110  if (checksum) checksum = 10 - checksum;
111  val[12] = checksum;
112 
113  // if we had an old checksum value and if it doesn't match what we came
114  // up with then the string must be invalid so we will bail
115  if (old_sum != -1 && old_sum != checksum) return;
116 
117 
118  // lets determine some core attributes about this barcode
119  int bar_width = 1; // the width of the base unit bar
120 
121  // this is are mandatory minimum quiet zone
122  int quiet_zone = bar_width * 10;
123  //if (quiet_zone < 10) quiet_zone = 10;
124 
125  // what kind of area do we have to work with
126  int draw_width = r.width();
127  int draw_height = r.height() - 2;
128 
129  // L = 95X
130  // L length of barcode (excluding quite zone) in units same as X and I
131  // X the width of a bar (pixels in our case)
132  int L;
133 
134  int X = bar_width;
135 
136  L = (95 * X);
137 
138  // now we have the actual width the barcode will be so can determine the actual
139  // size of the quiet zone (we assume we center the barcode in the given area
140  // what should we do if the area is too small????
141  // At the moment the way the code is written is we will always start at the minimum
142  // required quiet zone if we don't have enough space.... I guess we'll just have over-run
143  // to the right
144  //
145  // calculate the starting position based on the alignment option
146  // for left align we don't need to do anything as the values are already setup for it
147  if (align == Qt::AlignHCenter) {
148  int nqz = (draw_width - L) / 2;
149  if (nqz > quiet_zone) quiet_zone = nqz;
150  } else if (align == Qt::AlignRight) {
151  quiet_zone = draw_width - (L + quiet_zone);
152  }
153  // left : do nothing
154 
155  int pos = r.left() + quiet_zone;
156  int top = r.top();
157 
158  if (pPainter) {
159  pPainter->save();
160 
161  QPen oneWide(pPainter->pen());
162  oneWide.setWidth(1);
163 #ifndef Q_OS_WIN32
164  oneWide.setJoinStyle(Qt::MiterJoin);
165 #endif
166  pPainter->setPen(oneWide);
167  pPainter->setBrush(pPainter->pen().color());
168 
169  // render open guard
170  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
171  pos += 2;
172  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
173  pos ++;
174 
175  // render first set
176  for (int i = 0; i < 6; ++i) {
177  int b = val[i+1];
178  for (int w = 0; w < 7; ++w) {
179  if (_encodings[b][_parity[val[0]][i]][w]) {
180  pPainter->fillRect(pos, top, 1, draw_height - 7, pPainter->pen().color());
181  }
182  pos++;
183  }
184  }
185 
186  // render center guard
187  pos++;
188  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
189  pos += 2;
190  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
191  pos += 2;
192 
193  // render last set
194  for (int i = 0; i < 6; ++i) {
195  int b = val[i+7];
196  for (int w = 0; w < 7; ++w) {
197  if (_encodings[b][RIGHTHAND][w]) {
198  pPainter->fillRect(pos, top, 1, draw_height - 7, pPainter->pen().color());
199  }
200  pos++;
201  }
202  }
203 
204  // render close guard
205  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
206  pos += 2;
207  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
208 
209  QString parstr = QString::number(val[0]);
210  QString leftstr = QString::asprintf("%d%d%d%d%d%d",
211  val[1], val[2], val[3], val[4], val[5], val[6]);
212  QString rightstr = QString::asprintf("%d%d%d%d%d%d",
213  val[7], val[8], val[9], val[10], val[11], val[12]);
214  pPainter->setFont(QFont(QLatin1String("Arial"), 6));
215  pPainter->drawText(r.left(), r.top() + draw_height - 12,
216  quiet_zone - 2, 12, Qt::AlignRight | Qt::AlignTop,
217  parstr);
218  pPainter->drawText(r.left() + quiet_zone + 3,
219  (r.top() + draw_height) - 7,
220  42, 10, Qt::AlignHCenter | Qt::AlignTop,
221  leftstr);
222  pPainter->drawText(r.left() + quiet_zone + 50,
223  (r.top() + draw_height) - 7,
224  42, 10, Qt::AlignHCenter | Qt::AlignTop,
225  rightstr);
226 
227  pPainter->restore();
228  }
229 }
230 
231 void renderCodeUPCA(const QRect & r, const QString & _str, Qt::Alignment align, QPainter * pPainter)
232 {
233  int val[13];
234 
235  // initialize all the values just so we can be predictable
236  for (int i = 0; i < 13; ++i) {
237  val[i] = -1;
238  }
239 
240  // verify that the passed in string is valid
241  // if it's not either twelve or thirteen characters
242  // then it must be invalid to begin with
243  if (_str.length() != 11 && _str.length() != 12) return;
244  // loop through and convert each char to a digit.
245  // if we can't convert all characters then this is
246  // an invalid number
247  val[0] = 0;
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;
251  }
252 
253  // calculate and append the checksum value
254  int old_sum = val[12]; // get the old check sum value (-1 if none was set)
255  int checksum = 0;
256  for (int i = 0; i < 12; ++i) {
257  checksum += val[i] * ((i % 2) ? 3 : 1);
258  }
259  checksum = (checksum % 10);
260  if (checksum) checksum = 10 - checksum;
261  val[12] = checksum;
262 
263  // if we had an old checksum value and if it doesn't match what we came
264  // up with then the string must be invalid so we will bail
265  if (old_sum != -1 && old_sum != checksum) return;
266 
267 
268  // lets determine some core attributes about this barcode
269  int bar_width = 1; // the width of the base unit bar
270 
271  // this is are mandatory minimum quiet zone
272  int quiet_zone = bar_width * 10;
273  //if (quiet_zone < 10) quiet_zone = 10;
274 
275  // what kind of area do we have to work with
276  int draw_width = r.width();
277  int draw_height = r.height() - 2;
278 
279  // L = 95X
280  // L length of barcode (excluding quite zone) in units same as X and I
281  // X the width of a bar (pixels in our case)
282  int L;
283 
284  int X = bar_width;
285 
286  L = (95 * X);
287 
288  // now we have the actual width the barcode will be so can determine the actual
289  // size of the quiet zone (we assume we center the barcode in the given area
290  // what should we do if the area is too small????
291  // At the moment the way the code is written is we will always start at the minimum
292  // required quiet zone if we don't have enough space.... I guess we'll just have over-run
293  // to the right
294  //
295  // calculate the starting position based on the alignment option
296  // for left align we don't need to do anything as the values are already setup for it
297  if (align == Qt::AlignHCenter) {
298  int nqz = (draw_width - L) / 2;
299  if (nqz > quiet_zone) quiet_zone = nqz;
300  } else if (align == Qt::AlignRight) {
301  quiet_zone = draw_width - (L + quiet_zone);
302  }
303  // left : do nothing
304 
305  int pos = r.left() + quiet_zone;
306  int top = r.top();
307 
308  if (pPainter) {
309  pPainter->save();
310 
311  QPen oneWide(pPainter->pen());
312  oneWide.setWidth(1);
313 #ifndef Q_OS_WIN32
314  oneWide.setJoinStyle(Qt::MiterJoin);
315 #endif
316  pPainter->setPen(oneWide);
317  pPainter->setBrush(pPainter->pen().color());
318 
319  // render open guard
320  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
321  pos += 2;
322  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
323  pos ++;
324 
325  // render first set
326  for (int i = 0; i < 6; ++i) {
327  int b = val[i+1];
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());
331  }
332  pos++;
333  }
334  }
335 
336  // render center guard
337  pos++;
338  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
339  pos += 2;
340  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
341  pos += 2;
342 
343  // render last set
344  for (int i = 0; i < 6; ++i) {
345  int b = val[i+7];
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());
349  }
350  pos++;
351  }
352  }
353 
354  // render close guard
355  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
356  pos += 2;
357  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
358 
359  QString parstr = QString::number(val[1]);
360  QString chkstr = QString::number(val[12]);
361  QString leftstr = QString().sprintf("%d%d%d%d%d",
362  val[2], val[3], val[4], val[5], val[6]);
363  QString rightstr = QString().sprintf("%d%d%d%d%d",
364  val[7], val[8], val[9], val[10], val[11]);
365  pPainter->setFont(QFont(QLatin1String("Arial"), 6));
366  pPainter->drawText(r.left(), r.top() + draw_height - 12,
367  quiet_zone - 2, 12, Qt::AlignRight | Qt::AlignTop,
368  parstr);
369  pPainter->drawText(r.left() + quiet_zone + 10,
370  (r.top() + draw_height) - 7,
371  35, 10, Qt::AlignHCenter | Qt::AlignTop,
372  leftstr);
373  pPainter->drawText(r.left() + quiet_zone + 50,
374  (r.top() + draw_height) - 7,
375  35, 10, Qt::AlignHCenter | Qt::AlignTop,
376  rightstr);
377  pPainter->drawText(r.left() + quiet_zone + L + 2, r.top() + draw_height - 12,
378  8, 12, Qt::AlignLeft | Qt::AlignTop,
379  chkstr);
380 
381  pPainter->restore();
382  }
383 }
384 
385 void renderCodeEAN8(const QRect & r, const QString & _str, Qt::Alignment align, QPainter * pPainter)
386 {
387  int val[8];
388 
389  // initialize all the values just so we can be predictable
390  for (int i = 0; i < 8; ++i) {
391  val[i] = -1;
392  }
393 
394  // verify that the passed in string is valid
395  // if it's not either twelve or thirteen characters
396  // then it must be invalid to begin with
397  if (_str.length() != 7 && _str.length() != 8) return;
398  // loop through and convert each char to a digit.
399  // if we can't convert all characters then this is
400  // an invalid number
401  for (int i = 0; i < _str.length(); ++i) {
402  val[i] = ((QChar) _str.at(i)).digitValue();
403  if (val[i] == -1) return;
404  }
405 
406  // calculate and append the checksum value
407  int old_sum = val[7]; // get the old check sum value (-1 if none was set)
408  int checksum = 0;
409  for (int i = 0; i < 7; ++i) {
410  checksum += val[i] * ((i % 2) ? 1 : 3);
411  }
412  checksum = (checksum % 10);
413  if (checksum) checksum = 10 - checksum;
414  val[7] = checksum;
415 
416  // if we had an old checksum value and if it doesn't match what we came
417  // up with then the string must be invalid so we will bail
418  if (old_sum != -1 && old_sum != checksum) return;
419 
420 
421  // lets determine some core attributes about this barcode
422  int bar_width = 1; // the width of the base unit bar
423 
424  // this is are mandatory minimum quiet zone
425  int quiet_zone = bar_width * 10;
426  //if (quiet_zone < 10) quiet_zone = 10;
427 
428  // what kind of area do we have to work with
429  int draw_width = r.width();
430  int draw_height = r.height() - 2;
431 
432  // L = 60X
433  // L length of barcode (excluding quite zone) in units same as X and I
434  // X the width of a bar (pixels in our case)
435  int L;
436 
437  int X = bar_width;
438 
439  L = (67 * X);
440 
441  // now we have the actual width the barcode will be so can determine the actual
442  // size of the quiet zone (we assume we center the barcode in the given area
443  // what should we do if the area is too small????
444  // At the moment the way the code is written is we will always start at the minimum
445  // required quiet zone if we don't have enough space.... I guess we'll just have over-run
446  // to the right
447  //
448  // calculate the starting position based on the alignment option
449  // for left align we don't need to do anything as the values are already setup for it
450  if (align == Qt::AlignHCenter) {
451  int nqz = (draw_width - L) / 2;
452  if (nqz > quiet_zone) quiet_zone = nqz;
453  } else if (align == Qt::AlignRight) {
454  quiet_zone = draw_width - (L + quiet_zone);
455  }
456  // left : do nothing
457 
458  int pos = r.left() + quiet_zone;
459  int top = r.top();
460 
461  if (pPainter) {
462  pPainter->save();
463 
464  QPen oneWide(pPainter->pen());
465  oneWide.setWidth(1);
466 #ifndef Q_OS_WIN32
467  oneWide.setJoinStyle(Qt::MiterJoin);
468 #endif
469  pPainter->setPen(oneWide);
470  pPainter->setBrush(pPainter->pen().color());
471 
472  // render open guard
473  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
474  pos += 2;
475  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
476  pos ++;
477 
478  // render first set
479  for (int i = 0; i < 4; ++i) {
480  int b = val[i];
481  for (int w = 0; w < 7; ++w) {
482  if (_encodings[b][LEFTHAND_ODD][w]) {
483  pPainter->fillRect(pos, top, 1, draw_height - 6, pPainter->pen().color());
484  }
485  pos++;
486  }
487  }
488 
489  // render center guard
490  pos++;
491  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
492  pos += 2;
493  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
494  pos += 2;
495 
496  // render last set
497  for (int i = 0; i < 4; ++i) {
498  int b = val[i+4];
499  for (int w = 0; w < 7; ++w) {
500  if (_encodings[b][RIGHTHAND][w]) {
501  pPainter->fillRect(pos, top, 1, draw_height - 6, pPainter->pen().color());
502  }
503  pos++;
504  }
505  }
506 
507  // render close guard
508  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
509  pos += 2;
510  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
511 
512  QString leftstr = QString().sprintf("%d%d%d%d",
513  val[0], val[1], val[2], val[3]);
514  QString rightstr = QString().sprintf("%d%d%d%d",
515  val[4], val[5], val[6], val[7]);
516  pPainter->setFont(QFont(QLatin1String("Arial"), 6));
517  pPainter->drawText(r.left() + quiet_zone + 3,
518  (r.top() + draw_height) - 6,
519  28, 10, Qt::AlignHCenter | Qt::AlignTop,
520  leftstr);
521  pPainter->drawText(r.left() + quiet_zone + 36,
522  (r.top() + draw_height) - 6,
523  28, 10, Qt::AlignHCenter | Qt::AlignTop,
524  rightstr);
525 
526  pPainter->restore();
527  }
528 }
529 
530 void renderCodeUPCE(const QRect & r, const QString & _str, Qt::Alignment align, QPainter * pPainter)
531 {
532  int val[8];
533 
534  // initialize all the values just so we can be predictable
535  for (int i = 0; i < 8; ++i) {
536  val[i] = -1;
537  }
538 
539  // verify that the passed in string is valid
540  // if it's not either twelve or thirteen characters
541  // then it must be invalid to begin with
542  if (_str.length() != 8) return;
543  // loop through and convert each char to a digit.
544  // if we can't convert all characters then this is
545  // an invalid number
546  for (int i = 0; i < _str.length(); ++i) {
547  val[i] = ((QChar) _str.at(i)).digitValue();
548  if (val[i] == -1) return;
549  }
550 
551  // calculate and append the checksum value
552  // because everything is so messed up we don't calculate
553  // the checksum and require that it be passed in already
554  // however we do have to verify that the first digit is
555  // either 0 or 1 as that is our parity
556  if (val[0] != 0 && val[0] != 1) return;
557 
558  // lets determine some core attributes about this barcode
559  int bar_width = 1; // the width of the base unit bar
560 
561  // this is are mandatory minimum quiet zone
562  int quiet_zone = bar_width * 10;
563  //if (quiet_zone < 10) quiet_zone = 10;
564 
565  // what kind of area do we have to work with
566  int draw_width = r.width();
567  int draw_height = r.height() - 2;
568 
569  // L = 51X
570  // L length of barcode (excluding quite zone) in units same as X and I
571  // X the width of a bar (pixels in our case)
572  int L;
573 
574  int X = bar_width;
575 
576  L = (51 * X);
577 
578  // now we have the actual width the barcode will be so can determine the actual
579  // size of the quiet zone (we assume we center the barcode in the given area
580  // what should we do if the area is too small????
581  // At the moment the way the code is written is we will always start at the minimum
582  // required quiet zone if we don't have enough space.... I guess we'll just have over-run
583  // to the right
584  //
585  // calculate the starting position based on the alignment option
586  // for left align we don't need to do anything as the values are already setup for it
587  if (align == Qt::AlignHCenter) {
588  int nqz = (draw_width - L) / 2;
589  if (nqz > quiet_zone) quiet_zone = nqz;
590  } else if (align == Qt::AlignRight) {
591  quiet_zone = draw_width - (L + quiet_zone);
592  }
593  // left : do nothing
594 
595  int pos = r.left() + quiet_zone;
596  int top = r.top();
597 
598  if (pPainter) {
599  pPainter->save();
600 
601  QPen oneWide(pPainter->pen());
602  oneWide.setWidth(1);
603 #ifndef Q_OS_WIN32
604  oneWide.setJoinStyle(Qt::MiterJoin);
605 #endif
606  pPainter->setPen(oneWide);
607  pPainter->setBrush(pPainter->pen().color());
608 
609  // render open guard
610  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
611  pos += 2;
612  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
613  pos ++;
614 
615  // render first set
616  for (int i = 0; i < 6; ++i) {
617  int b = val[i+1];
618  for (int w = 0; w < 7; ++w) {
619  if (_encodings[b][_upcparenc[val[7]][val[0]][i]][w]) {
620  pPainter->fillRect(pos, top, 1, draw_height - 7, pPainter->pen().color());
621  }
622  pos++;
623  }
624  }
625 
626  // render center guard
627  pos++;
628  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
629  pos += 2;
630  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
631  pos += 2;
632 
633  // render close guard
634  pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
635 
636  QString parstr = QString::number(val[0]);
637  QString chkstr = QString::number(val[7]);
638  QString leftstr = QString().sprintf("%d%d%d%d%d%d",
639  val[1], val[2], val[3], val[4], val[5], val[6]);
640  pPainter->setFont(QFont(QLatin1String("Arial"), 6));
641  pPainter->drawText(r.left(), r.top() + draw_height - 12,
642  quiet_zone - 2, 12, Qt::AlignRight | Qt::AlignTop,
643  parstr);
644  pPainter->drawText(r.left() + quiet_zone + 3,
645  (r.top() + draw_height) - 7,
646  42, 10, Qt::AlignHCenter | Qt::AlignTop,
647  leftstr);
648  pPainter->drawText(r.left() + quiet_zone + L + 2, r.top() + draw_height - 12,
649  8, 12, Qt::AlignLeft | Qt::AlignTop,
650  chkstr);
651 
652  pPainter->restore();
653  }
654 }
655 
typedef Alignment
void setPen(const QColor &color)
QString number(int n, int base)
MiterJoin
int width() const const
const QPen & pen() const const
void drawText(const QPointF &position, const QString &text)
void fillRect(const QRectF &rectangle, const QBrush &brush)
int left() const const
int top() const const
QString & sprintf(const char *cformat,...)
int length() const const
void setBrush(const QBrush &brush)
int height() const const
QColor color() const const
const QChar at(int position) const const
void restore()
void save()
QString asprintf(const char *cformat,...)
void setFont(const QFont &font)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Sep 27 2023 04:06:04 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.