diff --git a/src/plugins/barcode/3of9.cpp b/src/plugins/barcode/3of9.cpp
index 598f9337..70064f4e 100644
--- a/src/plugins/barcode/3of9.cpp
+++ b/src/plugins/barcode/3of9.cpp
@@ -1,186 +1,187 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
/*
* This file contains the implementation of the 3of9 barcode renderer.
* All this code assumes a 100dpi rendering surface for it's calculations.
*/
#include "KReportRenderObjects.h"
#include
#include
#include
#include
#include "kreportplugin_debug.h"
struct code3of9 {
char code;
int values[9];
};
const struct code3of9 _3of9codes[] = {
{ '0', { 0, 0, 0, 1, 1, 0, 1, 0, 0 } },
{ '1', { 1, 0, 0, 1, 0, 0, 0, 0, 1 } },
{ '2', { 0, 0, 1, 1, 0, 0, 0, 0, 1 } },
{ '3', { 1, 0, 1, 1, 0, 0, 0, 0, 0 } },
{ '4', { 0, 0, 0, 1, 1, 0, 0, 0, 1 } },
{ '5', { 1, 0, 0, 1, 1, 0, 0, 0, 0 } },
{ '6', { 0, 0, 1, 1, 1, 0, 0, 0, 0 } },
{ '7', { 0, 0, 0, 1, 0, 0, 1, 0, 1 } },
{ '8', { 1, 0, 0, 1, 0, 0, 1, 0, 0 } },
{ '9', { 0, 0, 1, 1, 0, 0, 1, 0, 0 } },
{ 'A', { 1, 0, 0, 0, 0, 1, 0, 0, 1 } },
{ 'B', { 0, 0, 1, 0, 0, 1, 0, 0, 1 } },
{ 'C', { 1, 0, 1, 0, 0, 1, 0, 0, 0 } },
{ 'D', { 0, 0, 0, 0, 1, 1, 0, 0, 1 } },
{ 'E', { 1, 0, 0, 0, 1, 1, 0, 0, 0 } },
{ 'F', { 0, 0, 1, 0, 1, 1, 0, 0, 0 } },
{ 'G', { 0, 0, 0, 0, 0, 1, 1, 0, 1 } },
{ 'H', { 1, 0, 0, 0, 0, 1, 1, 0, 0 } },
{ 'I', { 0, 0, 1, 0, 0, 1, 1, 0, 0 } },
{ 'J', { 0, 0, 0, 0, 1, 1, 1, 0, 0 } },
{ 'K', { 1, 0, 0, 0, 0, 0, 0, 1, 1 } },
{ 'L', { 0, 0, 1, 0, 0, 0, 0, 1, 1 } },
{ 'M', { 1, 0, 1, 0, 0, 0, 0, 1, 0 } },
{ 'N', { 0, 0, 0, 0, 1, 0, 0, 1, 1 } },
{ 'O', { 1, 0, 0, 0, 1, 0, 0, 1, 0 } },
{ 'P', { 0, 0, 1, 0, 1, 0, 0, 1, 0 } },
{ 'Q', { 0, 0, 0, 0, 0, 0, 1, 1, 1 } },
{ 'R', { 1, 0, 0, 0, 0, 0, 1, 1, 0 } },
{ 'S', { 0, 0, 1, 0, 0, 0, 1, 1, 0 } },
{ 'T', { 0, 0, 0, 0, 1, 0, 1, 1, 0 } },
{ 'U', { 1, 1, 0, 0, 0, 0, 0, 0, 1 } },
{ 'V', { 0, 1, 1, 0, 0, 0, 0, 0, 1 } },
{ 'W', { 1, 1, 1, 0, 0, 0, 0, 0, 0 } },
{ 'X', { 0, 1, 0, 0, 1, 0, 0, 0, 1 } },
{ 'Y', { 1, 1, 0, 0, 1, 0, 0, 0, 0 } },
{ 'Z', { 0, 1, 1, 0, 1, 0, 0, 0, 0 } },
{ '-', { 0, 1, 0, 0, 0, 0, 1, 0, 1 } },
{ '.', { 1, 1, 0, 0, 0, 0, 1, 0, 0 } },
{ ' ', { 0, 1, 1, 0, 0, 0, 1, 0, 0 } },
{ '$', { 0, 1, 0, 1, 0, 1, 0, 0, 0 } },
{ '/', { 0, 1, 0, 1, 0, 0, 0, 1, 0 } },
{ '+', { 0, 1, 0, 0, 0, 1, 0, 1, 0 } },
{ '%', { 0, 0, 0, 1, 0, 1, 0, 1, 0 } },
{ '*', { 0, 1, 0, 0, 1, 0, 1, 0, 0 } }, // this is a special start/stop character
{ '\0', { 0, 0, 0, 0, 0, 0, 0, 0, 0 } } // null termininator of list
};
int codeIndex(QChar code)
{
// we are a case insensitive search
const char latin1Code = code.toUpper().toLatin1();
for (int idx = 0; _3of9codes[idx].code != '\0'; idx++) {
if (_3of9codes[idx].code == latin1Code) return idx;
}
return -1; // couldn't find it
}
-void render3of9(OROPage * page, const QRectF & r, const QString & _str, int align)
+void render3of9(OROPage * page, const QRectF & r, const QString & _str, Qt::Alignment align)
{
QString str = _str;
// lets determine some core attributes about this barcode
qreal narrow_bar = 1; // a narrow bar is 1/100th inch wide
qreal interchange_gap = narrow_bar; // the space between each 'set' of bars
int bar_width_mult = 2; // the wide bar width multiple of the narrow bar
// this is our mandatory minimum quiet zone
qreal quiet_zone = narrow_bar * 10;
if (quiet_zone < 0.1)
quiet_zone = 0.1;
// what kind of area do we have to work with
qreal draw_width = r.width();
qreal draw_height = r.height();
// how long is the value we need to encode?
int val_length = str.length();
// L = (C + 2)(3N + 6)X + (C + 1)I
// L length of barcode (excluding quite zone) in units same as X and I
// C the number of characters in the value excluding the start/stop
// N the bar width multiple for wide bars
// X the width of a bar (pixels in our case)
// I the interchange gap in the same units as X (value is same as X for our case)
qreal L;
qreal C = val_length;
qreal N = bar_width_mult;
qreal X = narrow_bar;
qreal I = interchange_gap;
L = ((C + 2.0) * (3.0 * N + 6.0) * X) + ((C + 1.0) * I);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
- if (align == 1) { // center
+ if (align == Qt::AlignHCenter) {
qreal nqz = (draw_width - L) / 2.0;
if (nqz > quiet_zone)
quiet_zone = nqz;
- } else if (align > 1) // right
+ } else if (align == Qt::AlignRight) {
quiet_zone = draw_width - (L + quiet_zone);
+ }
//else if(align < 1) {} // left : do nothing
qreal pos = r.left() + quiet_zone;
qreal top = r.top();
// ok we need to prepend and append the str with a *
//str = QString().sprintf("*%s*",(const char*)str);
str = QLatin1Char('*') + str + QLatin1Char('*');
QPen pen(Qt::NoPen);
QBrush brush(QColor("black"));
for (int i = 0; i < str.length(); i++) {
// loop through each char and render the barcode
QChar c = str.at(i);
int idx = codeIndex(c);
//kreportpluginDebug() << idx;
if (idx == -1) {
kreportpluginWarning() << "Encountered a non-compliant character while rendering a 3of9 barcode -- skipping";
continue;
}
bool space = false;
for (int b = 0; b < 9; b++, space = !space) {
qreal w = (_3of9codes[idx].values[b] == 1 ? narrow_bar * bar_width_mult : narrow_bar);
//kreportpluginDebug() << w << space;
if (!space) {
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, w, draw_height));
page->insertPrimitive(rect);
}
pos += w;
}
pos += interchange_gap;
}
}
diff --git a/src/plugins/barcode/3of9paint.cpp b/src/plugins/barcode/3of9paint.cpp
index d1dbd314..b7282784 100644
--- a/src/plugins/barcode/3of9paint.cpp
+++ b/src/plugins/barcode/3of9paint.cpp
@@ -1,187 +1,188 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
/*
* This file contains the implementation of the 3of9 barcode renderer.
* All this code assumes a 100dpi rendering surface for it's calculations.
*/
#include
#include
#include
#include
#include "kreportplugin_debug.h"
struct code3of9 {
char code;
int values[9];
};
const struct code3of9 _3of9codes[] = {
{ '0', { 0, 0, 0, 1, 1, 0, 1, 0, 0 } },
{ '1', { 1, 0, 0, 1, 0, 0, 0, 0, 1 } },
{ '2', { 0, 0, 1, 1, 0, 0, 0, 0, 1 } },
{ '3', { 1, 0, 1, 1, 0, 0, 0, 0, 0 } },
{ '4', { 0, 0, 0, 1, 1, 0, 0, 0, 1 } },
{ '5', { 1, 0, 0, 1, 1, 0, 0, 0, 0 } },
{ '6', { 0, 0, 1, 1, 1, 0, 0, 0, 0 } },
{ '7', { 0, 0, 0, 1, 0, 0, 1, 0, 1 } },
{ '8', { 1, 0, 0, 1, 0, 0, 1, 0, 0 } },
{ '9', { 0, 0, 1, 1, 0, 0, 1, 0, 0 } },
{ 'A', { 1, 0, 0, 0, 0, 1, 0, 0, 1 } },
{ 'B', { 0, 0, 1, 0, 0, 1, 0, 0, 1 } },
{ 'C', { 1, 0, 1, 0, 0, 1, 0, 0, 0 } },
{ 'D', { 0, 0, 0, 0, 1, 1, 0, 0, 1 } },
{ 'E', { 1, 0, 0, 0, 1, 1, 0, 0, 0 } },
{ 'F', { 0, 0, 1, 0, 1, 1, 0, 0, 0 } },
{ 'G', { 0, 0, 0, 0, 0, 1, 1, 0, 1 } },
{ 'H', { 1, 0, 0, 0, 0, 1, 1, 0, 0 } },
{ 'I', { 0, 0, 1, 0, 0, 1, 1, 0, 0 } },
{ 'J', { 0, 0, 0, 0, 1, 1, 1, 0, 0 } },
{ 'K', { 1, 0, 0, 0, 0, 0, 0, 1, 1 } },
{ 'L', { 0, 0, 1, 0, 0, 0, 0, 1, 1 } },
{ 'M', { 1, 0, 1, 0, 0, 0, 0, 1, 0 } },
{ 'N', { 0, 0, 0, 0, 1, 0, 0, 1, 1 } },
{ 'O', { 1, 0, 0, 0, 1, 0, 0, 1, 0 } },
{ 'P', { 0, 0, 1, 0, 1, 0, 0, 1, 0 } },
{ 'Q', { 0, 0, 0, 0, 0, 0, 1, 1, 1 } },
{ 'R', { 1, 0, 0, 0, 0, 0, 1, 1, 0 } },
{ 'S', { 0, 0, 1, 0, 0, 0, 1, 1, 0 } },
{ 'T', { 0, 0, 0, 0, 1, 0, 1, 1, 0 } },
{ 'U', { 1, 1, 0, 0, 0, 0, 0, 0, 1 } },
{ 'V', { 0, 1, 1, 0, 0, 0, 0, 0, 1 } },
{ 'W', { 1, 1, 1, 0, 0, 0, 0, 0, 0 } },
{ 'X', { 0, 1, 0, 0, 1, 0, 0, 0, 1 } },
{ 'Y', { 1, 1, 0, 0, 1, 0, 0, 0, 0 } },
{ 'Z', { 0, 1, 1, 0, 1, 0, 0, 0, 0 } },
{ '-', { 0, 1, 0, 0, 0, 0, 1, 0, 1 } },
{ '.', { 1, 1, 0, 0, 0, 0, 1, 0, 0 } },
{ ' ', { 0, 1, 1, 0, 0, 0, 1, 0, 0 } },
{ '$', { 0, 1, 0, 1, 0, 1, 0, 0, 0 } },
{ '/', { 0, 1, 0, 1, 0, 0, 0, 1, 0 } },
{ '+', { 0, 1, 0, 0, 0, 1, 0, 1, 0 } },
{ '%', { 0, 0, 0, 1, 0, 1, 0, 1, 0 } },
{ '*', { 0, 1, 0, 0, 1, 0, 1, 0, 0 } }, // this is a special start/stop character
{ '\0', { 0, 0, 0, 0, 0, 0, 0, 0, 0 } } // null termininator of list
};
int codeIndexP(QChar code)
{
// we are a case insensitive search
const char latin1Code = code.toUpper().toLatin1();
for (int idx = 0; _3of9codes[idx].code != '\0'; idx++) {
if (_3of9codes[idx].code == latin1Code) return idx;
}
return -1; // couldn't find it
}
-void render3of9(const QRect & r, const QString & _str, int align, QPainter * pPainter)
+void render3of9(const QRect & r, const QString & _str, Qt::Alignment align, QPainter * pPainter)
{
QString str = _str;
// lets determine some core attributes about this barcode
int narrow_bar = 1; // a narrow bar is 1px wide
int interchange_gap = narrow_bar; // the space between each 'set' of bars
int bar_width_mult = 2; // the wide bar width multiple of the narrow bar
// this is are mandatory minimum quiet zone
int quiet_zone = narrow_bar * 10;
//if (quiet_zone < 10) quiet_zone = 10;
// what kind of area do we have to work with
int draw_width = r.width();
int draw_height = r.height();
// how long is the value we need to encode?
int val_length = str.length();
// L = (C + 2)(3N + 6)X + (C + 1)I
// L length of barcode (excluding quite zone) in units same as X and I
// C the number of characters in the value excluding the start/stop
// N the bar width multiple for wide bars
// X the width of a bar (pixels in our case)
// I the interchange gap in the same units as X (value is same as X for our case)
int L;
int C = val_length;
int N = bar_width_mult;
int X = narrow_bar;
int I = interchange_gap;
L = ((C + 2) * (3 * N + 6) * X) + ((C + 1) * I);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
- if (align == 1) { // center
+ if (align == Qt::AlignHCenter) {
int nqz = (draw_width - L) / 2;
if (nqz > quiet_zone) quiet_zone = nqz;
- } else if (align > 1) { // right
+ } else if (align == Qt::AlignRight) {
quiet_zone = draw_width - (L + quiet_zone);
- } // else if(align < 1) {} // left : do nothing
+ }
+ // left : do nothing
int pos = r.left() + quiet_zone;
int top = r.top();
// ok we need to prepend and append the str with a *
str = QLatin1Char('*') + str + QLatin1Char('*');
if (pPainter) {
pPainter->save();
QPen oneWide(pPainter->pen());
oneWide.setWidth(1);
#ifndef Q_OS_WIN32
oneWide.setJoinStyle(Qt::MiterJoin);
#endif
pPainter->setPen(oneWide);
pPainter->setBrush(pPainter->pen().color());
}
for (int i = 0; i < str.length(); i++) {
// loop through each char and render the barcode
QChar c = str.at(i);
int idx = codeIndexP(c);
if (idx == -1) {
kreportpluginWarning() << "Encountered a non-compliant character while rendering a 3of9 barcode -- skipping";
continue;
}
bool space = false;
for (int b = 0; b < 9; b++, space = !space) {
int w = (_3of9codes[idx].values[b] == 1 ? narrow_bar * bar_width_mult : narrow_bar);
if (!space && pPainter) {
pPainter->fillRect(pos, top, w, draw_height, pPainter->pen().color());
}
pos += w;
}
pos += interchange_gap;
}
if (pPainter) {
pPainter->restore();
}
}
diff --git a/src/plugins/barcode/KReportDesignerItemBarcode.cpp b/src/plugins/barcode/KReportDesignerItemBarcode.cpp
index 15cd3ba8..d3b7cd72 100644
--- a/src/plugins/barcode/KReportDesignerItemBarcode.cpp
+++ b/src/plugins/barcode/KReportDesignerItemBarcode.cpp
@@ -1,173 +1,173 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "KReportDesignerItemBarcode.h"
#include "KReportDesignerItemBase.h"
#include "KReportDesigner.h"
#include "barcodepaint.h"
#include
#include
#include
#include
#include
#include
#include "kreportplugin_debug.h"
void KReportDesignerItemBarcode::init(QGraphicsScene *scene)
{
if (scene)
scene->addItem(this);
connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)),
this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&)));
setMaxLength(5);
setZ(z());
updateRenderText(m_itemValue->value().toString().isEmpty() ? m_format->value().toString() : QString(), m_itemValue->value().toString(), QString());
}
// methods (constructors)
KReportDesignerItemBarcode::KReportDesignerItemBarcode(KReportDesigner * rw, QGraphicsScene* scene, const QPointF &pos)
: KReportDesignerItemRectBase(rw, this)
{
Q_UNUSED(pos);
init(scene);
setSceneRect(properRect(*rw, m_minWidthTotal*dpiX(), m_minHeight*dpiY()));
nameProperty()->setValue(designer()->suggestEntityName(typeName()));
}
KReportDesignerItemBarcode::KReportDesignerItemBarcode(const QDomNode & element, KReportDesigner * rw, QGraphicsScene* scene)
: KReportItemBarcode(element), KReportDesignerItemRectBase(rw, this)
{
init(scene);
setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size()));
}
KReportDesignerItemBarcode* KReportDesignerItemBarcode::clone()
{
QDomDocument d;
QDomElement e = d.createElement(QLatin1String("clone"));
QDomNode n;
buildXML(&d, &e);
n = e.firstChild();
return new KReportDesignerItemBarcode(n, designer(), nullptr);
}
// methods (deconstructor)
KReportDesignerItemBarcode::~KReportDesignerItemBarcode()
{}
QRect KReportDesignerItemBarcode::getTextRect()
{
QFont fnt = QFont();
return QFontMetrics(fnt)
.boundingRect(int (x()), int (y()), 0, 0, 0,
dataSourceAndObjectTypeName(itemDataSource(), QLatin1String("barcode")));
}
void KReportDesignerItemBarcode::paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
// store any values we plan on changing so we can restore them
QPen p = painter->pen();
painter->setBackground(Qt::white);
//Draw a border so user knows the object edge
painter->setPen(QPen(QColor(224, 224, 224)));
painter->drawRect(rect());
drawHandles(painter);
QByteArray fmt = m_format->value().toByteArray();
if (fmt == "i2of5") {
- renderI2of5(rect().toRect(), renderText(), alignment(), painter);
+ renderI2of5(rect().toRect(), renderText(), horizontalAlignment(), painter);
} else if (fmt == "3of9") {
- render3of9(rect().toRect(), renderText(), alignment(), painter);
+ render3of9(rect().toRect(), renderText(), horizontalAlignment(), painter);
} else if (fmt == "3of9+") {
- renderExtended3of9(rect().toRect(), renderText(), alignment(), painter);
+ renderExtended3of9(rect().toRect(), renderText(), horizontalAlignment(), painter);
} else if (fmt == "128") {
- renderCode128(rect().toRect(), renderText(), alignment(), painter);
+ renderCode128(rect().toRect(), renderText(), horizontalAlignment(), painter);
} else if (fmt == "upc-a") {
- renderCodeUPCA(rect().toRect(), renderText(), alignment(), painter);
+ renderCodeUPCA(rect().toRect(), renderText(), horizontalAlignment(), painter);
} else if (fmt == "upc-e") {
- renderCodeUPCE(rect().toRect(), renderText(), alignment(), painter);
+ renderCodeUPCE(rect().toRect(), renderText(), horizontalAlignment(), painter);
} else if (fmt == "ean13") {
- renderCodeEAN13(rect().toRect(), renderText(), alignment(), painter);
+ renderCodeEAN13(rect().toRect(), renderText(), horizontalAlignment(), painter);
} else if (fmt == "ean8") {
- renderCodeEAN8(rect().toRect(), renderText(), alignment(), painter);
+ renderCodeEAN8(rect().toRect(), renderText(), horizontalAlignment(), painter);
}
painter->setPen(Qt::black);
painter->drawText(rect(), 0, dataSourceAndObjectTypeName(itemDataSource(),
QLatin1String("barcode")));
// restore an values before we started just in case
painter->setPen(p);
}
void KReportDesignerItemBarcode::buildXML(QDomDocument *doc, QDomElement *parent)
{
//kreportpluginDebug();
QDomElement entity = doc->createElement(QLatin1String("report:") + typeName());
// properties
addPropertyAsAttribute(&entity, nameProperty());
addPropertyAsAttribute(&entity, m_controlSource);
addPropertyAsAttribute(&entity, m_horizontalAlignment);
addPropertyAsAttribute(&entity, m_format);
addPropertyAsAttribute(&entity, m_maxLength);
entity.setAttribute(QLatin1String("report:z-index"), zValue());
addPropertyAsAttribute(&entity, m_itemValue);
// bounding rect
buildXMLRect(doc, &entity, this);
parent->appendChild(entity);
}
void KReportDesignerItemBarcode::slotPropertyChanged(KPropertySet &s, KProperty &p)
{
if (p.name() == "name") {
//For some reason p.oldValue returns an empty string
if (!designer()->isEntityNameUnique(p.value().toString(), this)) {
p.setValue(oldName());
} else {
setOldName(p.value().toString());
}
}
updateRenderText(m_itemValue->value().toString().isEmpty() ? m_format->value().toString() : QString(), m_itemValue->value().toString(), QString());
KReportDesignerItemRectBase::propertyChanged(s, p);
if (designer()) designer()->setModified(true);
}
void KReportDesignerItemBarcode::mousePressEvent(QGraphicsSceneMouseEvent * event)
{
m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames());
KReportDesignerItemRectBase::mousePressEvent(event);
}
diff --git a/src/plugins/barcode/KReportItemBarcode.cpp b/src/plugins/barcode/KReportItemBarcode.cpp
index 4020380f..1c127ad1 100644
--- a/src/plugins/barcode/KReportItemBarcode.cpp
+++ b/src/plugins/barcode/KReportItemBarcode.cpp
@@ -1,251 +1,244 @@
/* This file is part of the KDE project
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "KReportItemBarcode.h"
+#include "KReportUtils.h"
#include
#include
#include
#include
#include "kreportplugin_debug.h"
#include "barcodes.h"
KReportItemBarcode::KReportItemBarcode()
: m_minWidthData(0), m_minWidthTotal(0), m_minHeight(0)
{
createProperties();
}
KReportItemBarcode::KReportItemBarcode(const QDomNode & element)
: KReportItemBarcode()
{
nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name")));
m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source")));
m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value")));
setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble());
m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align")));
m_maxLength->setValue(element.toElement().attribute(QLatin1String("report:barcode-max-length")).toInt());
m_format->setValue(element.toElement().attribute(QLatin1String("report:barcode-format")));
parseReportRect(element.toElement());
}
void KReportItemBarcode::setMaxLength(int i)
{
if (i > 0) {
if (m_maxLength->value().toInt() != i) {
m_maxLength->setValue(i);
}
if (m_format->value().toString() == QLatin1String("3of9")) {
int C = i; // number of characters
int N = 2; // narrow mult for wide line
int X = 1; // narrow line width
int I = 1; // interchange line width
m_minWidthData = (((C + 2) * ((3 * N) + 6) * X) + ((C + 1) * I)) / 100.0;
//m_minHeight = m_minWidthData * 0.15;
/*if(min_height < 0.25)*/
m_minHeight = 0.25;
m_minWidthTotal = m_minWidthData + 0.22; // added a little buffer to make sure we don't loose any
// of our required quiet zone in conversions
} else if (m_format->value().toString() == QLatin1String("3of9+")) {
int C = i * 2; // number of characters
int N = 2; // narrow mult for wide line
int X = 1; // 1px narrow line
int I = 1; // 1px narrow line interchange
m_minWidthData = (((C + 2) * ((3 * N) + 6) * X) + ((C + 1) * I)) / 100.0;
//m_minHeight = m_minWidthData * 0.15;
/*if(min_height < 0.25)*/
m_minHeight = 0.25;
m_minWidthTotal = m_minWidthData + 0.22; // added a little buffer to make sure we don't loose any
// of our required quiet zone in conversions
} else if (m_format->value().toString() == QLatin1String("i2of5")) {
int C = i * 2; // number of characters
int N = 2; // narrow mult for wide line
int X = 1; // 1px narrow line
m_minWidthTotal = ((C * (2.0*N + 3.0) + 6.0 + N) * X);
m_minHeight = 0.25;
m_minWidthTotal = m_minWidthData + 0.22;
} else if (m_format->value().toString() == QLatin1String("128")) {
int C = i; // assuming 1:1 ratio of data passed in to data actually used in encoding
int X = 1; // 1px wide
m_minWidthData = (((11 * C) + 35) * X) / 100.0; // assuming CODE A or CODE B
//m_minHeight = m_minWidthData * 0.15;
/*if(min_height < 0.25)*/
m_minHeight = 0.25;
m_minWidthTotal = m_minWidthData + 0.22; // added a little bugger to make sure we don't loose any
// of our required quiet zone in conversions
} else if (m_format->value().toString() == QLatin1String("upc-a")) {
m_minWidthData = 0.95;
m_minWidthTotal = 1.15;
m_minHeight = 0.25;
} else if (m_format->value().toString() == QLatin1String("upc-e")) {
m_minWidthData = 0.52;
m_minWidthTotal = 0.70;
m_minHeight = 0.25;
} else if (m_format->value().toString() == QLatin1String("ean13")) {
m_minWidthData = 0.95;
m_minWidthTotal = 1.15;
m_minHeight = 0.25;
} else if (m_format->value().toString() == QLatin1String("ean8")) {
m_minWidthData = 0.67;
m_minWidthTotal = 0.90;
m_minHeight = 0.25;
} else {
kreportpluginWarning() << "Unknown format encountered: " << m_format->value().toString();
}
}
}
void KReportItemBarcode::createProperties()
{
m_controlSource
= new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source"));
m_itemValue = new KProperty("value", QString(), tr("Value"),
tr("Value used if not bound to a field"));
KPropertyListData *listData = new KPropertyListData(
{ QLatin1String("left"), QLatin1String("center"), QLatin1String("right") },
QVariantList{ tr("Left"), tr("Center"), tr("Right") });
m_horizontalAlignment = new KProperty("horizontal-align", listData, QLatin1String("left"),
tr("Horizontal Alignment"));
listData = new KPropertyListData(
QStringList()
<< QLatin1String("3of9") << QLatin1String("3of9+") << QLatin1String("128")
<< QLatin1String("ean8") << QLatin1String("ean13") << QLatin1String("i2of5")
<< QLatin1String("upc-a") << QLatin1String("upc-e"),
QStringList()
<< tr("Code 3 of 9", "Barcode symbology, keep short")
<< tr("Code 3 of 9 Ext.", "3 of 3 Extended: Barcode symbology, keep short")
<< tr("Code 128", "Barcode symbology, keep short")
<< tr("EAN-8", "Barcode symbology, keep short")
<< tr("EAN-13", "Barcode symbology, keep short")
<< tr("Interleaved 2 of 5", "Interleaved barcode 2 of 5: barcode symbology, keep short")
<< tr("UPC-A", "Barcode symbology, keep short")
<< tr("UPC-E", "Barcode symbology, keep short")
);
m_format = new KProperty("barcode-format", listData, QLatin1String("3of9"),
tr("Barcode Format"));
m_maxLength = new KProperty("barcode-max-length", 5, tr("Max Length"),
tr("Maximum Barcode Length"));
propertySet()->addProperty(m_controlSource);
propertySet()->addProperty(m_itemValue);
propertySet()->addProperty(m_format);
propertySet()->addProperty(m_horizontalAlignment);
propertySet()->addProperty(m_maxLength);
}
KReportItemBarcode::~KReportItemBarcode()
{
}
-int KReportItemBarcode::alignment()
+Qt::Alignment KReportItemBarcode::horizontalAlignment() const
{
- QByteArray a = m_horizontalAlignment->value().toByteArray();
-
- if (a == "left")
- return 0;
- else if (a == "center")
- return 1;
- else if (a == "right")
- return 2;
- else
- return 0;
+ return KReportUtils::horizontalAlignment(m_horizontalAlignment->value().toString(),
+ Qt::AlignLeft);
}
QString KReportItemBarcode::itemDataSource() const
{
return m_controlSource->value().toString();
}
-QString KReportItemBarcode::format()
+QString KReportItemBarcode::format() const
{
return m_format->value().toString();
}
-int KReportItemBarcode::maxLength()
+int KReportItemBarcode::maxLength() const
{
return m_maxLength->value().toInt();
}
void KReportItemBarcode::setFormat(const QString& f)
{
m_format->setValue(f);
}
-void KReportItemBarcode::setAlignment(int)
+void KReportItemBarcode::setHorizontalAlignment(Qt::Alignment value)
{
- //! @todo Barcode alignment
+ m_horizontalAlignment->setValue(KReportUtils::horizontalToString(value));
}
//RTTI
QString KReportItemBarcode::typeName() const
{
return QLatin1String("barcode");
}
int KReportItemBarcode::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset,
const QVariant &data, KReportScriptHandler *script)
{
Q_UNUSED(section);
Q_UNUSED(script);
QPointF pos = scenePosition(position());
QSizeF siz = sceneSize(size());
pos += offset;
QRectF rect = QRectF(pos, siz);
QString val;
if (m_controlSource->value().toString().isEmpty()) {
val = m_itemValue->value().toString();
} else {
val = data.toString();
}
if (page) {
QByteArray fmt = m_format->value().toByteArray();
- int align = alignment();
+ Qt::Alignment align = horizontalAlignment();
if (fmt == "3of9")
render3of9(page, rect, val, align);
else if (fmt == "3of9+")
renderExtended3of9(page, rect, val, align);
else if (fmt == "i2of5")
renderI2of5(page, rect, val, align);
else if (fmt == "128")
renderCode128(page, rect, val, align);
else if (fmt == "ean13")
renderCodeEAN13(page, rect, val, align);
else if (fmt == "ean8")
renderCodeEAN8(page, rect, val, align);
else if (fmt == "upc-a")
renderCodeUPCA(page, rect, val, align);
else if (fmt == "upc-e")
renderCodeUPCE(page, rect, val, align);
else {
kreportpluginWarning() << "Unknown barcode format:" << fmt;
}
}
return 0;
}
diff --git a/src/plugins/barcode/KReportItemBarcode.h b/src/plugins/barcode/KReportItemBarcode.h
index c55ee1c5..f04185e8 100644
--- a/src/plugins/barcode/KReportItemBarcode.h
+++ b/src/plugins/barcode/KReportItemBarcode.h
@@ -1,72 +1,72 @@
/* This file is part of the KDE project
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef KREPORTITEMBRCODE_H
#define KREPORTITEMBRCODE_H
#include "KReportItemBase.h"
class QDomNode;
namespace Scripting
{
class Barcode;
}
/**
*/
class KReportItemBarcode : public KReportItemBase
{
Q_OBJECT
public:
KReportItemBarcode();
explicit KReportItemBarcode(const QDomNode &element);
~KReportItemBarcode() override;
QString typeName() const override;
int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) override;
QString itemDataSource() const override;
protected:
KProperty * m_controlSource;
KProperty * m_horizontalAlignment;
KProperty * m_format;
KProperty * m_maxLength;
KProperty* m_itemValue;
- int alignment();
- void setAlignment(int);
- int maxLength();
+ Qt::Alignment horizontalAlignment() const;
+ void setHorizontalAlignment(Qt::Alignment value);
+ int maxLength() const;
void setMaxLength(int i);
- QString format();
+ QString format() const;
void setFormat(const QString&);
// all these values are in inches and
// are for internal use only
qreal m_minWidthData;
qreal m_minWidthTotal;
qreal m_minHeight;
private:
void createProperties() override;
friend class Scripting::Barcode;
};
#endif
diff --git a/src/plugins/barcode/KReportScriptBarcode.cpp b/src/plugins/barcode/KReportScriptBarcode.cpp
index eb65ec7b..5c9c0789 100644
--- a/src/plugins/barcode/KReportScriptBarcode.cpp
+++ b/src/plugins/barcode/KReportScriptBarcode.cpp
@@ -1,106 +1,85 @@
/* This file is part of the KDE project
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "KReportScriptBarcode.h"
#include
#include
#include
namespace Scripting
{
Barcode::Barcode(KReportItemBarcode *b)
{
m_barcode = b;
}
Barcode::~Barcode()
{
}
-QPointF Barcode::position()
+QPointF Barcode::position() const
{
return m_barcode->position();
}
+
void Barcode::setPosition(const QPointF& p)
{
m_barcode->setPosition(p);
}
-QSizeF Barcode::size()
+QSizeF Barcode::size() const
{
return m_barcode->size();
}
+
void Barcode::setSize(const QSizeF& s)
{
m_barcode->setSize(s);
}
-int Barcode::horizontalAlignment()
+Qt::Alignment Barcode::horizontalAlignment() const
{
- const QString a = m_barcode->m_horizontalAlignment->value().toString().toLower();
-
- if (a == QLatin1String("left")) {
- return -1;
- }
- if (a == QLatin1String("center")) {
- return 0;
- }
- if (a == QLatin1String("right")) {
- return 1;
- }
- return -1;
+ return m_barcode->horizontalAlignment();
}
-void Barcode::setHorizonalAlignment(int a)
+
+void Barcode::setHorizonalAlignment(Qt::Alignment value)
{
- switch (a) {
- case -1:
- m_barcode->m_horizontalAlignment->setValue(QLatin1String("left"));
- break;
- case 0:
- m_barcode->m_horizontalAlignment->setValue(QLatin1String("center"));
- break;
- case 1:
- m_barcode->m_horizontalAlignment->setValue(QLatin1String("right"));
- break;
- default:
- m_barcode->m_horizontalAlignment->setValue(QLatin1String("left"));
- break;
- }
+ m_barcode->setHorizontalAlignment(value);
}
QString Barcode::source()
{
return m_barcode->m_controlSource->value().toString();
}
void Barcode::setSource(const QString& s)
{
m_barcode->m_controlSource->setValue(s);
}
QString Barcode::format()
{
return m_barcode->m_format->value().toString();
}
void Barcode::setFormat(const QString& s)
{
m_barcode->m_format->setValue(s);
}
}
diff --git a/src/plugins/barcode/KReportScriptBarcode.h b/src/plugins/barcode/KReportScriptBarcode.h
index 48289df0..19b35e32 100644
--- a/src/plugins/barcode/KReportScriptBarcode.h
+++ b/src/plugins/barcode/KReportScriptBarcode.h
@@ -1,115 +1,114 @@
/* This file is part of the KDE project
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef SCRIPTINGKRSCRIPTBARCODE_H
#define SCRIPTINGKRSCRIPTBARCODE_H
#include
#include "KReportItemBarcode.h"
namespace Scripting
{
/**
*/
class Barcode : public QObject
{
Q_OBJECT
public:
explicit Barcode(KReportItemBarcode *f);
~Barcode() override;
public Q_SLOTS:
/**
* Get the position of the barcode
* @return position in points
*/
- QPointF position();
-
+ QPointF position() const;
/**
* Sets the position of the barcode in points
* @param Position
*/
void setPosition(const QPointF&);
/**
* Get the size of the barcode
* @return size in points
*/
- QSizeF size();
+ QSizeF size() const;
/**
* Set the size of the barcode in points
* @param Size
*/
void setSize(const QSizeF&);
/**
* Get the horizontal alignment
- * -1 Left
- * 0 Center
- * +1 Right
+ * Qt::AlignLeft Left
+ * Qt::AlignHCenter Center
+ * Qt::AlignRight Right
* @return alignment
*/
- int horizontalAlignment();
+ Qt::Alignment horizontalAlignment() const;
/**
* Sets the horizontal alignment
* @param Alignemnt
*/
- void setHorizonalAlignment(int);
+ void setHorizonalAlignment(Qt::Alignment value);
/**
* Get the control source (field name) of the barcode
* @return control source
*/
QString source();
/**
* Set the control source (field name) of the barcode
* @param controlsource
*/
void setSource(const QString&);
/**
* Get the barcode format
* @return format as string
*/
QString format();
/**
* Set the barcode format
* @param format
*/
void setFormat(const QString&);
private:
KReportItemBarcode *m_barcode;
};
}
#endif
diff --git a/src/plugins/barcode/barcodepaint.h b/src/plugins/barcode/barcodepaint.h
index 3774e15b..8b64f85c 100644
--- a/src/plugins/barcode/barcodepaint.h
+++ b/src/plugins/barcode/barcodepaint.h
@@ -1,54 +1,54 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef BARCODEPAINT_H
#define BARCODEPAINT_H
#include
#include
//
// i2of5
//
-void renderI2of5(const QRectF &, const QString &, int align, QPainter *);
+void renderI2of5(const QRectF &, const QString &, Qt::Alignment align, QPainter *);
//
// 3of9
//
-void render3of9(const QRect &, const QString &, int align, QPainter *);
+void render3of9(const QRect &, const QString &, Qt::Alignment align, QPainter *);
//
// 3of9+
//
-void renderExtended3of9(const QRect &, const QString &, int align, QPainter *);
+void renderExtended3of9(const QRect &, const QString &, Qt::Alignment align, QPainter *);
//
// Code 128
//
-void renderCode128(const QRect &, const QString &, int align, QPainter *);
+void renderCode128(const QRect &, const QString &, Qt::Alignment align, QPainter *);
//
// Code EAN/UPC
//
-void renderCodeEAN13(const QRect &, const QString &, int align, QPainter *);
-void renderCodeEAN8(const QRect &, const QString &, int align, QPainter *);
-void renderCodeUPCA(const QRect &, const QString &, int align, QPainter *);
-void renderCodeUPCE(const QRect &, const QString &, int align, QPainter *);
+void renderCodeEAN13(const QRect &, const QString &, Qt::Alignment align, QPainter *);
+void renderCodeEAN8(const QRect &, const QString &, Qt::Alignment align, QPainter *);
+void renderCodeUPCA(const QRect &, const QString &, Qt::Alignment align, QPainter *);
+void renderCodeUPCE(const QRect &, const QString &, Qt::Alignment align, QPainter *);
#endif
diff --git a/src/plugins/barcode/barcodes.h b/src/plugins/barcode/barcodes.h
index ae70530a..f1f2a31f 100644
--- a/src/plugins/barcode/barcodes.h
+++ b/src/plugins/barcode/barcodes.h
@@ -1,56 +1,56 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#ifndef __BARCODES_H__
#define __BARCODES_H__
#include
#include
class OROPage;
//
// i2of5
//
-void renderI2of5(OROPage *, const QRectF &, const QString &, int align);
+void renderI2of5(OROPage *, const QRectF &, const QString &, Qt::Alignment align);
//
// 3of9
//
-void render3of9(OROPage *, const QRectF &, const QString &, int align);
+void render3of9(OROPage *, const QRectF &, const QString &, Qt::Alignment align);
//
// 3of9+
//
-void renderExtended3of9(OROPage *, const QRectF &, const QString &, int align);
+void renderExtended3of9(OROPage *, const QRectF &, const QString &, Qt::Alignment align);
//
// Code 128
//
-void renderCode128(OROPage *, const QRectF &, const QString &, int align);
+void renderCode128(OROPage *, const QRectF &, const QString &, Qt::Alignment align);
//
// Code EAN/UPC
//
-void renderCodeEAN13(OROPage *, const QRectF &, const QString &, int align);
-void renderCodeEAN8(OROPage *, const QRectF &, const QString &, int align);
-void renderCodeUPCA(OROPage *, const QRectF &, const QString &, int align);
-void renderCodeUPCE(OROPage *, const QRectF &, const QString &, int align);
+void renderCodeEAN13(OROPage *, const QRectF &, const QString &, Qt::Alignment align);
+void renderCodeEAN8(OROPage *, const QRectF &, const QString &, Qt::Alignment align);
+void renderCodeUPCA(OROPage *, const QRectF &, const QString &, Qt::Alignment align);
+void renderCodeUPCE(OROPage *, const QRectF &, const QString &, Qt::Alignment align);
#endif
diff --git a/src/plugins/barcode/code128.cpp b/src/plugins/barcode/code128.cpp
index 5ca017f5..09313aef 100644
--- a/src/plugins/barcode/code128.cpp
+++ b/src/plugins/barcode/code128.cpp
@@ -1,345 +1,346 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
/*
* This file contains the implementation of the Code 128 barcode renderer.
* All this code assumes a 100dpi rendering surface for it's calculations.
*/
#include
#include
#include
#include
#include
#include "KReportRenderObjects.h"
#include "kreportplugin_debug.h"
static const int SETA = 0;
static const int SETB = 1;
static const int SETC = 2;
static const char FNC1 = (char)130;
static const char FNC2 = (char)131;
static const char FNC3 = (char)132;
static const char FNC4 = (char)133;
static const char SHIFT = (char)134;
static const char CODEA = (char)135;
static const char CODEB = (char)136;
static const char CODEC = (char)137;
static const char STARTA = (char)138;
static const char STARTB = (char)139;
static const char STARTC = (char)140;
struct code128 {
char codea;
char codeb;
char codec;
int values[6];
bool _null;
};
static const struct code128 _128codes[] = {
// A , B , C , { B S B S B S }, NULL? },
{ ' ', ' ', 0, { 2, 1, 2, 2, 2, 2 }, false },
{ '!', '!', 1, { 2, 2, 2, 1, 2, 2 }, false },
{ '"', '"', 2, { 2, 2, 2, 2, 2, 1 }, false },
{ '#', '#', 3, { 1, 2, 1, 2, 2, 3 }, false },
{ '$', '$', 4, { 1, 2, 1, 3, 2, 2 }, false },
{ '%', '%', 5, { 1, 3, 1, 2, 2, 2 }, false },
{ '&', '&', 6, { 1, 2, 2, 2, 1, 3 }, false },
{ '\'', '\'', 7, { 1, 2, 2, 3, 1, 2 }, false },
{ '(', '(', 8, { 1, 3, 2, 2, 1, 2 }, false },
{ ')', ')', 9, { 2, 2, 1, 2, 1, 3 }, false },
{ '*', '*', 10, { 2, 2, 1, 3, 1, 2 }, false },
{ '+', '+', 11, { 2, 3, 1, 2, 1, 2 }, false },
{ ',', ',', 12, { 1, 1, 2, 2, 3, 2 }, false },
{ '-', '-', 13, { 1, 2, 2, 1, 3, 2 }, false },
{ '.', '.', 14, { 1, 2, 2, 2, 3, 1 }, false },
{ '/', '/', 15, { 1, 1, 3, 2, 2, 2 }, false },
{ '0', '0', 16, { 1, 2, 3, 1, 2, 2 }, false },
{ '1', '1', 17, { 1, 2, 3, 2, 2, 1 }, false },
{ '2', '2', 18, { 2, 2, 3, 2, 1, 1 }, false },
{ '3', '3', 19, { 2, 2, 1, 1, 3, 2 }, false },
{ '4', '4', 20, { 2, 2, 1, 2, 3, 1 }, false },
{ '5', '5', 21, { 2, 1, 3, 2, 1, 2 }, false },
{ '6', '6', 22, { 2, 2, 3, 1, 1, 2 }, false },
{ '7', '7', 23, { 3, 1, 2, 1, 3, 1 }, false },
{ '8', '8', 24, { 3, 1, 1, 2, 2, 2 }, false },
{ '9', '9', 25, { 3, 2, 1, 1, 2, 2 }, false },
{ ':', ':', 26, { 3, 2, 1, 2, 2, 1 }, false },
{ ';', ';', 27, { 3, 1, 2, 2, 1, 2 }, false },
{ '<', '<', 28, { 3, 2, 2, 1, 1, 2 }, false },
{ '=', '=', 29, { 3, 2, 2, 2, 1, 1 }, false },
{ '>', '>', 30, { 2, 1, 2, 1, 2, 3 }, false },
{ '?', '?', 31, { 2, 1, 2, 3, 2, 1 }, false },
{ '@', '@', 32, { 2, 3, 2, 1, 2, 1 }, false },
{ 'A', 'A', 33, { 1, 1, 1, 3, 2, 3 }, false },
{ 'B', 'B', 34, { 1, 3, 1, 1, 2, 3 }, false },
{ 'C', 'C', 35, { 1, 3, 1, 3, 2, 1 }, false },
{ 'D', 'D', 36, { 1, 1, 2, 3, 1, 3 }, false },
{ 'E', 'E', 37, { 1, 3, 2, 1, 1, 3 }, false },
{ 'F', 'F', 38, { 1, 3, 2, 3, 1, 1 }, false },
{ 'G', 'G', 39, { 2, 1, 1, 3, 1, 3 }, false },
{ 'H', 'H', 40, { 2, 3, 1, 1, 1, 3 }, false },
{ 'I', 'I', 41, { 2, 3, 1, 3, 1, 1 }, false },
{ 'J', 'J', 42, { 1, 1, 2, 1, 3, 3 }, false },
{ 'K', 'K', 43, { 1, 1, 2, 3, 3, 1 }, false },
{ 'L', 'L', 44, { 1, 3, 2, 1, 3, 1 }, false },
{ 'M', 'M', 45, { 1, 1, 3, 1, 2, 3 }, false },
{ 'N', 'N', 46, { 1, 1, 3, 3, 2, 1 }, false },
{ 'O', 'O', 47, { 1, 3, 3, 1, 2, 1 }, false },
{ 'P', 'P', 48, { 3, 1, 3, 1, 2, 1 }, false },
{ 'Q', 'Q', 49, { 2, 1, 1, 3, 3, 1 }, false },
{ 'R', 'R', 50, { 2, 3, 1, 1, 3, 1 }, false },
{ 'S', 'S', 51, { 2, 1, 3, 1, 1, 3 }, false },
{ 'T', 'T', 52, { 2, 1, 3, 3, 1, 1 }, false },
{ 'U', 'U', 53, { 2, 1, 3, 1, 3, 1 }, false },
{ 'V', 'V', 54, { 3, 1, 1, 1, 2, 3 }, false },
{ 'W', 'W', 55, { 3, 1, 1, 3, 2, 1 }, false },
{ 'X', 'X', 56, { 3, 3, 1, 1, 2, 1 }, false },
{ 'Y', 'Y', 57, { 3, 1, 2, 1, 1, 3 }, false },
{ 'Z', 'Z', 58, { 3, 1, 2, 3, 1, 1 }, false },
{ '[', '[', 59, { 3, 3, 2, 1, 1, 1 }, false },
{ '\\', '\\', 60, { 3, 1, 4, 1, 1, 1 }, false },
{ ']', ']', 61, { 2, 2, 1, 4, 1, 1 }, false },
{ '^', '^', 62, { 4, 3, 1, 1, 1, 1 }, false },
{ '_', '_', 63, { 1, 1, 1, 2, 2, 4 }, false },
{ 0x00, '`', 64, { 1, 1, 1, 4, 2, 2 }, false }, // NUL
{ 0x01, 'a', 65, { 1, 2, 1, 1, 2, 4 }, false }, // SOH
{ 0x02, 'b', 66, { 1, 2, 1, 4, 2, 1 }, false }, // STX
{ 0x03, 'c', 67, { 1, 4, 1, 1, 2, 2 }, false }, // ETX
{ 0x04, 'd', 68, { 1, 4, 1, 2, 2, 1 }, false }, // EOT
{ 0x05, 'e', 69, { 1, 1, 2, 2, 1, 4 }, false }, // ENQ
{ 0x06, 'f', 70, { 1, 1, 2, 4, 1, 2 }, false }, // ACK
{ 0x07, 'g', 71, { 1, 2, 2, 1, 1, 4 }, false }, // BEL
{ 0x08, 'h', 72, { 1, 2, 2, 4, 1, 1 }, false }, // BS
{ 0x09, 'i', 73, { 1, 4, 2, 1, 1, 2 }, false }, // HT
{ 0x0A, 'j', 74, { 1, 4, 2, 2, 1, 1 }, false }, // LF
{ 0x0B, 'k', 75, { 2, 4, 1, 2, 1, 1 }, false }, // VT
{ 0x0C, 'l', 76, { 2, 2, 1, 1, 1, 4 }, false }, // FF
{ 0x0D, 'm', 77, { 4, 1, 3, 1, 1, 1 }, false }, // CR
{ 0x0E, 'n', 78, { 2, 4, 1, 1, 1, 2 }, false }, // SO
{ 0x0F, 'o', 79, { 1, 3, 4, 1, 1, 1 }, false }, // SI
{ 0x10, 'p', 80, { 1, 1, 1, 2, 4, 2 }, false }, // DLE
{ 0x11, 'q', 81, { 1, 2, 1, 1, 4, 2 }, false }, // DC1
{ 0x12, 'r', 82, { 1, 2, 1, 2, 4, 1 }, false }, // DC2
{ 0x13, 's', 83, { 1, 1, 4, 2, 1, 2 }, false }, // DC3
{ 0x14, 't', 84, { 1, 2, 4, 1, 1, 2 }, false }, // DC4
{ 0x15, 'u', 85, { 1, 2, 4, 2, 1, 1 }, false }, // NAK
{ 0x16, 'v', 86, { 4, 1, 1, 2, 1, 2 }, false }, // SYN
{ 0x17, 'w', 87, { 4, 2, 1, 1, 1, 2 }, false }, // ETB
{ 0x18, 'x', 88, { 4, 2, 1, 2, 1, 1 }, false }, // CAN
{ 0x19, 'y', 89, { 2, 1, 2, 1, 4, 1 }, false }, // EM
{ 0x1A, 'z', 90, { 2, 1, 4, 1, 2, 1 }, false }, // SUB
{ 0x1B, '{', 91, { 4, 1, 2, 1, 2, 1 }, false }, // ESC
{ 0x1C, '|', 92, { 1, 1, 1, 1, 4, 3 }, false }, // FS
{ 0x1D, '}', 93, { 1, 1, 1, 3, 4, 1 }, false }, // GS
{ 0x1E, '~', 94, { 1, 3, 1, 1, 4, 1 }, false }, // RS
{ 0x1F, 0x7F, 95, { 1, 1, 4, 1, 1, 3 }, false }, // US DEL
{ FNC3, FNC3, 96, { 1, 1, 4, 3, 1, 1 }, false }, // FNC3 FNC3
{ FNC2, FNC2, 97, { 4, 1, 1, 1, 1, 3 }, false }, // FNC2 FNC2
{ SHIFT, SHIFT, 98, { 4, 1, 1, 3, 1, 1 }, false }, // SHIFT SHIFT
{ CODEC, CODEC, 99, { 1, 1, 3, 1, 4, 1 }, false }, // CODEC CODEC
{ CODEB, FNC4, CODEB, { 1, 1, 4, 1, 3, 1 }, false }, // CODEB FNC4 CODEB
{ FNC4, CODEA, CODEA, { 3, 1, 1, 1, 4, 1 }, false }, // FNC4 CODEA CODEA
{ FNC1, FNC1, FNC1, { 4, 1, 1, 1, 3, 1 }, false }, // FNC1 FNC1 FNC1
{ STARTA, STARTA, STARTA, { 2, 1, 1, 4, 1, 2 }, false }, // STARTA
{ STARTB, STARTB, STARTB, { 2, 1, 1, 2, 1, 4 }, false }, // STARTB
{ STARTC, STARTC, STARTC, { 2, 1, 1, 2, 3, 2 }, false }, // STARTC
{ '\0', '\0', '\0', { 0, 0, 0, 0, 0, 0 }, true } // null termininator of list
};
// STOP CHARACTER { 2 3 3 1 1 1 2 }
int code128Index(QChar code, int set)
{
const char latin1Code = code.toLatin1();
for (int idx = 0; _128codes[idx]._null == false; ++idx) {
if (set == SETA && _128codes[idx].codea == latin1Code) return idx;
if (set == SETB && _128codes[idx].codeb == latin1Code) return idx;
if (set == SETC && _128codes[idx].codec == latin1Code) return idx;
}
return -1; // couldn't find it
}
-void renderCode128(OROPage * page, const QRectF & r, const QString & _str, int align)
+void renderCode128(OROPage * page, const QRectF & r, const QString & _str, Qt::Alignment align)
{
QVector str;
// create the list.. if the list is empty then just set a start code and move on
if (_str.isEmpty())
str.push_back(104);
else {
int rank_a = 0;
int rank_b = 0;
int rank_c = 0;
QChar c;
for (int i = 0; i < _str.length(); ++i) {
c = _str.at(i);
rank_a += (code128Index(c, SETA) != -1 ? 1 : 0);
rank_b += (code128Index(c, SETB) != -1 ? 1 : 0);
rank_c += (c >= QLatin1Char('0') && c <= QLatin1Char('9') ? 1 : 0);
}
if (rank_c == _str.length() && ((rank_c % 2) == 0 || rank_c > 4)) {
// every value in the is a digit so we are going to go with mode C
// and we have an even number or we have more than 4 values
int i;
if ((rank_c % 2) == 1) {
str.push_back(104); // START B
c = _str.at(0);
str.push_back(code128Index(c, SETB));
str.push_back(99); // MODE C
i = 1;
} else {
str.push_back(105); // START C
i = 0;
}
for (; i < _str.length(); i += 2) {
char a, b;
c = _str.at(i);
a = c.toLatin1();
a -= 48;
c = _str.at(i + 1);
b = c.toLatin1();
b -= 48;
str.push_back(int((a * 10) + b));
}
} else {
// start in the mode that had the higher number of hits and then
// just shift into the opposite mode as needed
int set = (rank_a > rank_b ? SETA : SETB);
str.push_back((rank_a > rank_b ? 103 : 104));
for (int i = 0; i < _str.length(); ++i) {
c = _str.at(i);
int v = code128Index(c, set);
if (v == -1) {
v = code128Index(c, (set == SETA ? SETB : SETA));
if (v != -1) {
str.push_back(98); // SHIFT
str.push_back(v);
}
} else
str.push_back(v);
}
}
}
// calculate and append the checksum value to the list
int checksum = str.at(0);
for (int i = 1; i < str.size(); ++i)
checksum += (str.at(i) * i);
checksum = checksum % 103;
str.push_back(checksum);
// lets determine some core attributes about this barcode
qreal bar_width = 1; // the width of the base unit bar 1/100 inch
// this is are mandatory minimum quiet zone
qreal quiet_zone = bar_width * 10;
if (quiet_zone < 0.1)
quiet_zone = 0.1;
// what kind of area do we have to work with
qreal draw_width = r.width();
qreal draw_height = r.height();
// how long is the value we need to encode?
int val_length = str.size() - 2; // we include start and checksum in are list so
// subtract them out for our calculations
// L = (11C + 35)X
// L length of barcode (excluding quite zone) in units same as X and I
// C the number of characters in the value excluding the start/stop and checksum characters
// X the width of a bar (pixels in our case)
qreal L;
qreal C = val_length;
qreal X = bar_width;
L = (((11.0 * C) + 35.0) * X);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
- if (align == 1) { // center
+ if (align == Qt::AlignHCenter) {
qreal nqz = (draw_width - L) / 2.0;
if (nqz > quiet_zone)
quiet_zone = nqz;
- } else if (align > 1) // right
+ } else if (align == Qt::AlignRight) {
quiet_zone = draw_width - (L + quiet_zone);
- // else if(align < 1) {} // left : do nothing
+ }
+ // left : do nothing
qreal pos = r.left() + quiet_zone;
qreal top = r.top();
QPen pen(Qt::NoPen);
QBrush brush(QColor("black"));
bool space = false;
for (int i = 0; i < str.size(); ++i) {
// loop through each value and render the barcode
const int idx = str.at(i);
if (idx < 0 || idx > 105) {
kreportpluginWarning() << "Encountered a non-compliant element while rendering a 3of9 barcode -- skipping";
continue;
}
space = false;
for (int b = 0; b < 6; ++b, space = !space) {
qreal w = _128codes[idx].values[b] * bar_width;
if (!space) {
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, w, draw_height));
page->insertPrimitive(rect);
}
pos += w;
}
}
// we have to do the stop character separately like this because it has
// 7 elements in it's bar sequence rather than 6 like the others
int STOP_CHARACTER[] = { 2, 3, 3, 1, 1, 1, 2 };
space = false;
for (int b = 0; b < 7; ++b, space = !space) {
qreal w = STOP_CHARACTER[b] * bar_width;
if (!space) {
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, w, draw_height));
page->insertPrimitive(rect);
}
pos += w;
}
}
diff --git a/src/plugins/barcode/code128paint.cpp b/src/plugins/barcode/code128paint.cpp
index 7fbfb0d6..601db615 100644
--- a/src/plugins/barcode/code128paint.cpp
+++ b/src/plugins/barcode/code128paint.cpp
@@ -1,349 +1,350 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
/*
* This file contains the implementation of the Code 128 barcode renderer.
* All this code assumes a 100dpi rendering surface for it's calculations.
*/
#include
#include
#include
#include
#include
#include
#include "KReportRenderObjects.h"
#include "kreportplugin_debug.h"
static const int SETA = 0;
static const int SETB = 1;
static const int SETC = 2;
static const char FNC1 = (char)130;
static const char FNC2 = (char)131;
static const char FNC3 = (char)132;
static const char FNC4 = (char)133;
static const char SHIFT = (char)134;
static const char CODEA = (char)135;
static const char CODEB = (char)136;
static const char CODEC = (char)137;
static const char STARTA = (char)138;
static const char STARTB = (char)139;
static const char STARTC = (char)140;
struct code128 {
char codea;
char codeb;
char codec;
int values[6];
bool _null;
};
static const struct code128 _128codes[] = {
// A , B , C , { B S B S B S }, NULL? },
{ ' ', ' ', 0, { 2, 1, 2, 2, 2, 2 }, false },
{ '!', '!', 1, { 2, 2, 2, 1, 2, 2 }, false },
{ '"', '"', 2, { 2, 2, 2, 2, 2, 1 }, false },
{ '#', '#', 3, { 1, 2, 1, 2, 2, 3 }, false },
{ '$', '$', 4, { 1, 2, 1, 3, 2, 2 }, false },
{ '%', '%', 5, { 1, 3, 1, 2, 2, 2 }, false },
{ '&', '&', 6, { 1, 2, 2, 2, 1, 3 }, false },
{ '\'', '\'', 7, { 1, 2, 2, 3, 1, 2 }, false },
{ '(', '(', 8, { 1, 3, 2, 2, 1, 2 }, false },
{ ')', ')', 9, { 2, 2, 1, 2, 1, 3 }, false },
{ '*', '*', 10, { 2, 2, 1, 3, 1, 2 }, false },
{ '+', '+', 11, { 2, 3, 1, 2, 1, 2 }, false },
{ ',', ',', 12, { 1, 1, 2, 2, 3, 2 }, false },
{ '-', '-', 13, { 1, 2, 2, 1, 3, 2 }, false },
{ '.', '.', 14, { 1, 2, 2, 2, 3, 1 }, false },
{ '/', '/', 15, { 1, 1, 3, 2, 2, 2 }, false },
{ '0', '0', 16, { 1, 2, 3, 1, 2, 2 }, false },
{ '1', '1', 17, { 1, 2, 3, 2, 2, 1 }, false },
{ '2', '2', 18, { 2, 2, 3, 2, 1, 1 }, false },
{ '3', '3', 19, { 2, 2, 1, 1, 3, 2 }, false },
{ '4', '4', 20, { 2, 2, 1, 2, 3, 1 }, false },
{ '5', '5', 21, { 2, 1, 3, 2, 1, 2 }, false },
{ '6', '6', 22, { 2, 2, 3, 1, 1, 2 }, false },
{ '7', '7', 23, { 3, 1, 2, 1, 3, 1 }, false },
{ '8', '8', 24, { 3, 1, 1, 2, 2, 2 }, false },
{ '9', '9', 25, { 3, 2, 1, 1, 2, 2 }, false },
{ ':', ':', 26, { 3, 2, 1, 2, 2, 1 }, false },
{ ';', ';', 27, { 3, 1, 2, 2, 1, 2 }, false },
{ '<', '<', 28, { 3, 2, 2, 1, 1, 2 }, false },
{ '=', '=', 29, { 3, 2, 2, 2, 1, 1 }, false },
{ '>', '>', 30, { 2, 1, 2, 1, 2, 3 }, false },
{ '?', '?', 31, { 2, 1, 2, 3, 2, 1 }, false },
{ '@', '@', 32, { 2, 3, 2, 1, 2, 1 }, false },
{ 'A', 'A', 33, { 1, 1, 1, 3, 2, 3 }, false },
{ 'B', 'B', 34, { 1, 3, 1, 1, 2, 3 }, false },
{ 'C', 'C', 35, { 1, 3, 1, 3, 2, 1 }, false },
{ 'D', 'D', 36, { 1, 1, 2, 3, 1, 3 }, false },
{ 'E', 'E', 37, { 1, 3, 2, 1, 1, 3 }, false },
{ 'F', 'F', 38, { 1, 3, 2, 3, 1, 1 }, false },
{ 'G', 'G', 39, { 2, 1, 1, 3, 1, 3 }, false },
{ 'H', 'H', 40, { 2, 3, 1, 1, 1, 3 }, false },
{ 'I', 'I', 41, { 2, 3, 1, 3, 1, 1 }, false },
{ 'J', 'J', 42, { 1, 1, 2, 1, 3, 3 }, false },
{ 'K', 'K', 43, { 1, 1, 2, 3, 3, 1 }, false },
{ 'L', 'L', 44, { 1, 3, 2, 1, 3, 1 }, false },
{ 'M', 'M', 45, { 1, 1, 3, 1, 2, 3 }, false },
{ 'N', 'N', 46, { 1, 1, 3, 3, 2, 1 }, false },
{ 'O', 'O', 47, { 1, 3, 3, 1, 2, 1 }, false },
{ 'P', 'P', 48, { 3, 1, 3, 1, 2, 1 }, false },
{ 'Q', 'Q', 49, { 2, 1, 1, 3, 3, 1 }, false },
{ 'R', 'R', 50, { 2, 3, 1, 1, 3, 1 }, false },
{ 'S', 'S', 51, { 2, 1, 3, 1, 1, 3 }, false },
{ 'T', 'T', 52, { 2, 1, 3, 3, 1, 1 }, false },
{ 'U', 'U', 53, { 2, 1, 3, 1, 3, 1 }, false },
{ 'V', 'V', 54, { 3, 1, 1, 1, 2, 3 }, false },
{ 'W', 'W', 55, { 3, 1, 1, 3, 2, 1 }, false },
{ 'X', 'X', 56, { 3, 3, 1, 1, 2, 1 }, false },
{ 'Y', 'Y', 57, { 3, 1, 2, 1, 1, 3 }, false },
{ 'Z', 'Z', 58, { 3, 1, 2, 3, 1, 1 }, false },
{ '[', '[', 59, { 3, 3, 2, 1, 1, 1 }, false },
{ '\\', '\\', 60, { 3, 1, 4, 1, 1, 1 }, false },
{ ']', ']', 61, { 2, 2, 1, 4, 1, 1 }, false },
{ '^', '^', 62, { 4, 3, 1, 1, 1, 1 }, false },
{ '_', '_', 63, { 1, 1, 1, 2, 2, 4 }, false },
{ 0x00, '`', 64, { 1, 1, 1, 4, 2, 2 }, false }, // NUL
{ 0x01, 'a', 65, { 1, 2, 1, 1, 2, 4 }, false }, // SOH
{ 0x02, 'b', 66, { 1, 2, 1, 4, 2, 1 }, false }, // STX
{ 0x03, 'c', 67, { 1, 4, 1, 1, 2, 2 }, false }, // ETX
{ 0x04, 'd', 68, { 1, 4, 1, 2, 2, 1 }, false }, // EOT
{ 0x05, 'e', 69, { 1, 1, 2, 2, 1, 4 }, false }, // ENQ
{ 0x06, 'f', 70, { 1, 1, 2, 4, 1, 2 }, false }, // ACK
{ 0x07, 'g', 71, { 1, 2, 2, 1, 1, 4 }, false }, // BEL
{ 0x08, 'h', 72, { 1, 2, 2, 4, 1, 1 }, false }, // BS
{ 0x09, 'i', 73, { 1, 4, 2, 1, 1, 2 }, false }, // HT
{ 0x0A, 'j', 74, { 1, 4, 2, 2, 1, 1 }, false }, // LF
{ 0x0B, 'k', 75, { 2, 4, 1, 2, 1, 1 }, false }, // VT
{ 0x0C, 'l', 76, { 2, 2, 1, 1, 1, 4 }, false }, // FF
{ 0x0D, 'm', 77, { 4, 1, 3, 1, 1, 1 }, false }, // CR
{ 0x0E, 'n', 78, { 2, 4, 1, 1, 1, 2 }, false }, // SO
{ 0x0F, 'o', 79, { 1, 3, 4, 1, 1, 1 }, false }, // SI
{ 0x10, 'p', 80, { 1, 1, 1, 2, 4, 2 }, false }, // DLE
{ 0x11, 'q', 81, { 1, 2, 1, 1, 4, 2 }, false }, // DC1
{ 0x12, 'r', 82, { 1, 2, 1, 2, 4, 1 }, false }, // DC2
{ 0x13, 's', 83, { 1, 1, 4, 2, 1, 2 }, false }, // DC3
{ 0x14, 't', 84, { 1, 2, 4, 1, 1, 2 }, false }, // DC4
{ 0x15, 'u', 85, { 1, 2, 4, 2, 1, 1 }, false }, // NAK
{ 0x16, 'v', 86, { 4, 1, 1, 2, 1, 2 }, false }, // SYN
{ 0x17, 'w', 87, { 4, 2, 1, 1, 1, 2 }, false }, // ETB
{ 0x18, 'x', 88, { 4, 2, 1, 2, 1, 1 }, false }, // CAN
{ 0x19, 'y', 89, { 2, 1, 2, 1, 4, 1 }, false }, // EM
{ 0x1A, 'z', 90, { 2, 1, 4, 1, 2, 1 }, false }, // SUB
{ 0x1B, '{', 91, { 4, 1, 2, 1, 2, 1 }, false }, // ESC
{ 0x1C, '|', 92, { 1, 1, 1, 1, 4, 3 }, false }, // FS
{ 0x1D, '}', 93, { 1, 1, 1, 3, 4, 1 }, false }, // GS
{ 0x1E, '~', 94, { 1, 3, 1, 1, 4, 1 }, false }, // RS
{ 0x1F, 0x7F, 95, { 1, 1, 4, 1, 1, 3 }, false }, // US DEL
{ FNC3, FNC3, 96, { 1, 1, 4, 3, 1, 1 }, false }, // FNC3 FNC3
{ FNC2, FNC2, 97, { 4, 1, 1, 1, 1, 3 }, false }, // FNC2 FNC2
{ SHIFT, SHIFT, 98, { 4, 1, 1, 3, 1, 1 }, false }, // SHIFT SHIFT
{ CODEC, CODEC, 99, { 1, 1, 3, 1, 4, 1 }, false }, // CODEC CODEC
{ CODEB, FNC4, CODEB, { 1, 1, 4, 1, 3, 1 }, false }, // CODEB FNC4 CODEB
{ FNC4, CODEA, CODEA, { 3, 1, 1, 1, 4, 1 }, false }, // FNC4 CODEA CODEA
{ FNC1, FNC1, FNC1, { 4, 1, 1, 1, 3, 1 }, false }, // FNC1 FNC1 FNC1
{ STARTA, STARTA, STARTA, { 2, 1, 1, 4, 1, 2 }, false }, // STARTA
{ STARTB, STARTB, STARTB, { 2, 1, 1, 2, 1, 4 }, false }, // STARTB
{ STARTC, STARTC, STARTC, { 2, 1, 1, 2, 3, 2 }, false }, // STARTC
{ '\0', '\0', '\0', { 0, 0, 0, 0, 0, 0 }, true } // null termininator of list
};
// STOP CHARACTER { 2 3 3 1 1 1 2 }
int code128IndexP(QChar code, int set)
{
const char latin1Code = code.toLatin1();
for (int idx = 0; _128codes[idx]._null == false; idx++) {
if (set == SETA && _128codes[idx].codea == latin1Code) return idx;
if (set == SETB && _128codes[idx].codeb == latin1Code) return idx;
if (set == SETC && _128codes[idx].codec == latin1Code) return idx;
}
return -1; // couldn't find it
}
-void renderCode128(const QRect & r, const QString & _str, int align, QPainter * pPainter)
+void renderCode128(const QRect & r, const QString & _str, Qt::Alignment align, QPainter * pPainter)
{
QVector str;
// create the list.. if the list is empty then just set a start code and move on
if (_str.isEmpty()) {
str.push_back(104);
} else {
int rank_a = 0;
int rank_b = 0;
int rank_c = 0;
QChar c;
for (int i = 0; i < _str.length(); ++i) {
c = _str.at(i);
rank_a += (code128IndexP(c, SETA) != -1 ? 1 : 0);
rank_b += (code128IndexP(c, SETB) != -1 ? 1 : 0);
rank_c += (c >= QLatin1Char('0') && c <= QLatin1Char('9') ? 1 : 0);
}
if (rank_c == _str.length() && ((rank_c % 2) == 0 || rank_c > 4)) {
// every value in the is a digit so we are going to go with mode C
// and we have an even number or we have more than 4 values
int i;
if ((rank_c % 2) == 1) {
str.push_back(104); // START B
c = _str.at(0);
str.push_back(code128IndexP(c, SETB));
str.push_back(99); // MODE C
i = 1;
} else {
str.push_back(105); // START C
i = 0;
}
for (; i < _str.length(); i += 2) {
char a, b;
c = _str.at(i);
a = c.toLatin1();
a -= 48;
c = _str.at(i + 1);
b = c.toLatin1();
b -= 48;
str.push_back(int((a * 10) + b));
}
} else {
// start in the mode that had the higher number of hits and then
// just shift into the opposite mode as needed
int set = (rank_a > rank_b ? SETA : SETB);
str.push_back((rank_a > rank_b ? 103 : 104));
for (int i = 0; i < _str.length(); ++i) {
c = _str.at(i);
int v = code128IndexP(c, set);
if (v == -1) {
v = code128IndexP(c, (set == SETA ? SETB : SETA));
if (v != -1) {
str.push_back(98); // SHIFT
str.push_back(v);
}
} else {
str.push_back(v);
}
}
}
}
// calculate and append the checksum value to the list
int checksum = str.at(0);
for (int i = 1; i < str.size(); ++i) {
checksum += (str.at(i) * i);
}
checksum = checksum % 103;
str.push_back(checksum);
// lets determine some core attributes about this barcode
int bar_width = 1; // the width of the base unit bar
// this is are mandatory minimum quiet zone
int quiet_zone = bar_width * 10;
//if (quiet_zone < 10) quiet_zone = 10;
// what kind of area do we have to work with
int draw_width = r.width();
int draw_height = r.height();
// how long is the value we need to encode?
int val_length = str.size() - 2; // we include start and checksum in are list so
// subtract them out for our calculations
// L = (11C + 35)X
// L length of barcode (excluding quite zone) in units same as X and I
// C the number of characters in the value excluding the start/stop and checksum characters
// X the width of a bar (pixels in our case)
int L;
int C = val_length;
int X = bar_width;
L = (((11 * C) + 35) * X);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
- if (align == 1) { // center
+ if (align == Qt::AlignHCenter) {
int nqz = (draw_width - L) / 2;
if (nqz > quiet_zone) quiet_zone = nqz;
- } else if (align > 1) { // right
+ } else if (align == Qt::AlignRight) {
quiet_zone = draw_width - (L + quiet_zone);
- } // else if(align < 1) {} // left : do nothing
+ }
+ // left : do nothing
int pos = r.left() + quiet_zone;
int top = r.top();
if (pPainter) {
pPainter->save();
QPen oneWide(pPainter->pen());
oneWide.setWidth(1);
#ifndef Q_OS_WIN32
oneWide.setJoinStyle(Qt::MiterJoin);
#endif
pPainter->setPen(oneWide);
pPainter->setBrush(pPainter->pen().color());
}
bool space = false;
for (int i = 0; i < str.size(); ++i) {
// loop through each value and render the barcode
int idx = str.at(i);
if (idx < 0 || idx > 105) {
kreportpluginWarning() << "Encountered a non-compliant element while rendering a 3of9 barcode -- skipping";
continue;
}
space = false;
for (int b = 0; b < 6; b++, space = !space) {
int w = _128codes[idx].values[b] * bar_width;
if (!space && pPainter) {
pPainter->fillRect(pos, top, w, draw_height, pPainter->pen().color());
}
pos += w;
}
}
// we have to do the stop character separately like this because it has
// 7 elements in it's bar sequence rather than 6 like the others
int STOP_CHARACTER[] = { 2, 3, 3, 1, 1, 1, 2 };
space = false;
for (int b = 0; b < 7; b++, space = !space) {
int w = STOP_CHARACTER[b] * bar_width;
if (!space && pPainter) {
pPainter->fillRect(pos, top, w, draw_height, pPainter->pen().color());
}
pos += w;
}
if (pPainter) {
pPainter->restore();
}
}
diff --git a/src/plugins/barcode/codeean.cpp b/src/plugins/barcode/codeean.cpp
index 58f5e9f3..0c52edb8 100644
--- a/src/plugins/barcode/codeean.cpp
+++ b/src/plugins/barcode/codeean.cpp
@@ -1,842 +1,846 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
/*
* This file contains the implementation of the Code EAN and similar
* formats for rendering purposes. All this code assumes a 100dpi
* rendering surface for it's calculations.
*/
#include
#include
#include
#include
#include "KReportRenderObjects.h"
static const int LEFTHAND_ODD = 0;
static const int LEFTHAND_EVEN = 1;
static const int RIGHTHAND = 2;
static const int _encodings[10][3][7] = {
/* LEFTHAND_ODD */ /* LEFTHAND_EVEN */ /* RIGHTHAND */
{ { 0, 0, 0, 1, 1, 0, 1}, { 0, 1, 0, 0, 1, 1, 1 }, { 1, 1, 1, 0, 0, 1, 0 } }, // 0
{ { 0, 0, 1, 1, 0, 0, 1}, { 0, 1, 1, 0, 0, 1, 1 }, { 1, 1, 0, 0, 1, 1, 0 } }, // 1
{ { 0, 0, 1, 0, 0, 1, 1}, { 0, 0, 1, 1, 0, 1, 1 }, { 1, 1, 0, 1, 1, 0, 0 } }, // 2
{ { 0, 1, 1, 1, 1, 0, 1}, { 0, 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 1, 0 } }, // 3
{ { 0, 1, 0, 0, 0, 1, 1}, { 0, 0, 1, 1, 1, 0, 1 }, { 1, 0, 1, 1, 1, 0, 0 } }, // 4
{ { 0, 1, 1, 0, 0, 0, 1}, { 0, 1, 1, 1, 0, 0, 1 }, { 1, 0, 0, 1, 1, 1, 0 } }, // 5
{ { 0, 1, 0, 1, 1, 1, 1}, { 0, 0, 0, 0, 1, 0, 1 }, { 1, 0, 1, 0, 0, 0, 0 } }, // 6
{ { 0, 1, 1, 1, 0, 1, 1}, { 0, 0, 1, 0, 0, 0, 1 }, { 1, 0, 0, 0, 1, 0, 0 } }, // 7
{ { 0, 1, 1, 0, 1, 1, 1}, { 0, 0, 0, 1, 0, 0, 1 }, { 1, 0, 0, 1, 0, 0, 0 } }, // 8
{ { 0, 0, 0, 1, 0, 1, 1}, { 0, 0, 1, 0, 1, 1, 1 }, { 1, 1, 1, 0, 1, 0, 0 } } // 9
};
static const int odd = LEFTHAND_ODD;
static const int even = LEFTHAND_EVEN;
static const int _parity[10][6] = {
{ odd, odd, odd, odd, odd, odd }, // 0
{ odd, odd, even, odd, even, even }, // 1
{ odd, odd, even, even, odd, even }, // 2
{ odd, odd, even, even, even, odd }, // 3
{ odd, even, odd, odd, even, even }, // 4
{ odd, even, even, odd, odd, even }, // 5
{ odd, even, even, even, odd, odd }, // 6
{ odd, even, odd, even, odd, even }, // 7
{ odd, even, odd, even, even, odd }, // 8
{ odd, even, even, odd, even, odd } // 9
};
static const int _upcparenc[10][2][6] = {
/* PARITY 0 */ /* PARITY 1 */
{ { even, even, even, odd, odd, odd }, { odd, odd, odd, even, even, even } }, // 0
{ { even, even, odd, even, odd, odd }, { odd, odd, even, odd, even, even } }, // 1
{ { even, even, odd, odd, even, odd }, { odd, odd, even, even, odd, even } }, // 2
{ { even, even, odd, odd, odd, even }, { odd, odd, even, even, even, odd } }, // 3
{ { even, odd, even, even, odd, odd }, { odd, even, odd, odd, even, even } }, // 4
{ { even, odd, odd, even, even, odd }, { odd, even, even, odd, odd, even } }, // 5
{ { even, odd, odd, odd, even, even }, { odd, even, even, even, odd, odd } }, // 6
{ { even, odd, even, odd, even, odd }, { odd, even, odd, even, odd, even } }, // 7
{ { even, odd, even, odd, odd, even }, { odd, even, odd, even, even, odd } }, // 8
{ { even, odd, odd, even, odd, even }, { odd, even, even, odd, even, odd } } // 9
};
//
//! @todo New Renderer Functions
////////////////////////////////////////////////////////
-void renderCodeEAN13(OROPage * page, const QRectF & r, const QString & _str, int align)
+void renderCodeEAN13(OROPage * page, const QRectF & r, const QString & _str, Qt::Alignment align)
{
int val[13];
// initialize all the values just so we can be predictable
for (int i = 0; i < 13; ++i)
val[i] = -1;
// verify that the passed in string is valid
// if it's not either twelve or thirteen characters
// then it must be invalid to begin with
if (_str.length() != 12 && _str.length() != 13)
return;
// loop through and convert each char to a digit.
// if we can't convert all characters then this is
// an invalid number
for (int i = 0; i < _str.length(); ++i) {
val[i] = ((QChar)_str.at(i)).digitValue();
if (val[i] == -1)
return;
}
// calculate and append the checksum value
int old_sum = val[12]; // get the old check sum value (-1 if none was set)
int checksum = 0;
for (int i = 0; i < 12; ++i) {
checksum += val[i] * ((i % 2) ? 3 : 1);
}
checksum = (checksum % 10);
if (checksum) checksum = 10 - checksum;
val[12] = checksum;
// if we had an old checksum value and if it doesn't match what we came
// up with then the string must be invalid so we will bail
if (old_sum != -1 && old_sum != checksum)
return;
// lets determine some core attributes about this barcode
qreal bar_width = 1; // the width of the base unit bar 1/100 inch
// this is are mandatory minimum quiet zone
qreal quiet_zone = bar_width * 10;
if (quiet_zone < 10)
quiet_zone = 10;
// what kind of area do we have to work with
qreal draw_width = r.width();
qreal draw_height = r.height() - 2;
// L = 95X
// L length of barcode (excluding quite zone) in units same as X and I
// X the width of a bar (pixels in our case)
qreal L;
qreal X = bar_width;
L = (95.0 * X);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
- if (align == 1) { // center
+ if (align == Qt::AlignHCenter) {
qreal nqz = (draw_width - L) / 2;
if (nqz > quiet_zone)
quiet_zone = nqz;
- } else if (align > 1) // right
+ } else if (align == Qt::AlignRight) {
quiet_zone = draw_width - (L + quiet_zone);
- // else if(align < 1) {} // left : do nothing
+ }
+ // left : do nothing
qreal pos = r.left() + quiet_zone;
qreal top = r.top();
QPen pen(Qt::NoPen);
QBrush brush(QColor("black"));
// render open guard
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += bar_width;
// render first set
for (int i = 0; i < 6; ++i) {
int b = val[i+1];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][_parity[val[0]][i]][w]) {
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height - 0.07));
page->insertPrimitive(rect);
}
pos += bar_width;
}
}
// render center guard
pos += bar_width;
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
// render last set
for (int i = 0; i < 6; ++i) {
int b = val[i+7];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][RIGHTHAND][w]) {
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height - 0.07));
page->insertPrimitive(rect);
}
pos += bar_width;
}
}
// render close guard
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
QString parstr = QString::fromLatin1("%1").arg(val[0]);
QString leftstr = QString().sprintf("%d%d%d%d%d%d",
val[1], val[2], val[3], val[4], val[5], val[6]);
QString rightstr = QString().sprintf("%d%d%d%d%d%d",
val[7], val[8], val[9], val[10], val[11], val[12]);
QFont font(QLatin1String("Arial"), 6);
OROTextBox * tb = new OROTextBox();
tb->setPosition(QPointF(r.left(), r.top() + draw_height - 0.12));
tb->setSize(QSizeF(quiet_zone - 0.02, 0.12));
tb->setFont(font);
tb->setText(parstr);
tb->setFlags(Qt::AlignRight | Qt::AlignTop);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + 0.03, (r.top() + draw_height) - 0.07));
tb->setSize(QSizeF(0.42, 0.1));
tb->setFont(font);
tb->setText(leftstr);
tb->setFlags(Qt::AlignHCenter | Qt::AlignTop);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + 0.5, (r.top() + draw_height) - 0.07));
tb->setSize(QSizeF(0.42, 0.1));
tb->setFont(font);
tb->setText(rightstr);
tb->setFlags(Qt::AlignHCenter | Qt::AlignTop);
page->insertPrimitive(tb);
}
-void renderCodeUPCA(OROPage * page, const QRectF & r, const QString & _str, int align)
+void renderCodeUPCA(OROPage * page, const QRectF & r, const QString & _str, Qt::Alignment align)
{
int val[13];
// initialize all the values just so we can be predictable
for (int i = 0; i < 13; ++i) {
val[i] = -1;
}
// verify that the passed in string is valid
// if it's not either twelve or thirteen characters
// then it must be invalid to begin with
if (_str.length() != 11 && _str.length() != 12)
return;
// loop through and convert each char to a digit.
// if we can't convert all characters then this is
// an invalid number
val[0] = 0;
for (int i = 0; i < _str.length(); ++i) {
val[i+1] = ((QChar)_str.at(i)).digitValue();
if (val[i+1] == -1)
return;
}
// calculate and append the checksum value
int old_sum = val[12]; // get the old check sum value (-1 if none was set)
int checksum = 0;
for (int i = 0; i < 12; ++i) {
checksum += val[i] * ((i % 2) ? 3 : 1);
}
checksum = (checksum % 10);
if (checksum) checksum = 10 - checksum;
val[12] = checksum;
// if we had an old checksum value and if it doesn't match what we came
// up with then the string must be invalid so we will bail
if (old_sum != -1 && old_sum != checksum)
return;
// lets determine some core attributes about this barcode
qreal bar_width = 1; // the width of the base unit bar
// this is are mandatory minimum quiet zone
qreal quiet_zone = bar_width * 10;
//if (quiet_zone < 10) quiet_zone = 10;
// what kind of area do we have to work with
qreal draw_width = r.width();
qreal draw_height = r.height() - 2;
// L = 95X
// L length of barcode (excluding quite zone) in units same as X and I
// X the width of a bar (pixels in our case)
qreal L;
qreal X = bar_width;
L = (95.0 * X);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
- if (align == 1) { // center
+ if (align == Qt::AlignHCenter) {
qreal nqz = (draw_width - L) / 2;
if (nqz > quiet_zone)
quiet_zone = nqz;
- } else if (align > 1) // right
+ } else if (align == Qt::AlignRight) {
quiet_zone = draw_width - (L + quiet_zone);
- // else if(align < 1) {} // left : do nothing
+ }
+ // left : do nothing
qreal pos = r.left() + quiet_zone;
qreal top = r.top();
QPen pen(Qt::NoPen);
QBrush brush(QColor("black"));
// render open guard
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += bar_width;
// render first set
for (int i = 0; i < 6; ++i) {
int b = val[i+1];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][_parity[val[0]][i]][w]) {
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height - (i == 0 ? 0 : 0.07)));
page->insertPrimitive(rect);
}
pos += bar_width;
}
}
// render center guard
pos += bar_width;
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
// render last set
for (int i = 0; i < 6; ++i) {
int b = val[i+7];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][RIGHTHAND][w]) {
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height - (i == 5 ? 0 : 0.07)));
page->insertPrimitive(rect);
}
pos += bar_width;
}
}
// render close guard
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
QString parstr = QString::number(val[1]);
QString chkstr = QString::number(val[12]);
QString leftstr = QString().sprintf("%d%d%d%d%d",
val[2], val[3], val[4], val[5], val[6]);
QString rightstr = QString().sprintf("%d%d%d%d%d",
val[7], val[8], val[9], val[10], val[11]);
QFont font(QLatin1String("Arial"), 6);
KReportTextStyleData ts;
ts.backgroundColor = Qt::white;
ts.font = font;
ts.foregroundColor = Qt::black;
ts.backgroundOpacity = 100;
ts.alignment = Qt::AlignRight | Qt::AlignTop;
OROTextBox * tb = new OROTextBox();
tb->setPosition(QPointF(r.left(), r.top() + draw_height - 12));
tb->setSize(QSizeF(quiet_zone - 2, 12));
tb->setTextStyle(ts);
tb->setText(parstr);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + 10, (r.top() + draw_height) - 7));
tb->setSize(QSizeF(35, 10));
tb->setTextStyle(ts);
tb->setText(leftstr);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + 50, (r.top() + draw_height) - 7));
tb->setSize(QSizeF(35, 10));
tb->setTextStyle(ts);
tb->setText(rightstr);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + L + 2, (r.top() + draw_height) - 12));
tb->setSize(QSizeF(8, 12));
tb->setTextStyle(ts);
tb->setText(chkstr);
page->insertPrimitive(tb);
}
-void renderCodeEAN8(OROPage * page, const QRectF & r, const QString & _str, int align)
+void renderCodeEAN8(OROPage * page, const QRectF & r, const QString & _str, Qt::Alignment align)
{
int val[8];
// initialize all the values just so we can be predictable
for (int i = 0; i < 8; ++i) {
val[i] = -1;
}
// verify that the passed in string is valid
// if it's not either twelve or thirteen characters
// then it must be invalid to begin with
if (_str.length() != 7 && _str.length() != 8)
return;
// loop through and convert each char to a digit.
// if we can't convert all characters then this is
// an invalid number
for (int i = 0; i < _str.length(); ++i) {
val[i] = ((QChar)_str.at(i)).digitValue();
if (val[i] == -1)
return;
}
// calculate and append the checksum value
int old_sum = val[7]; // get the old check sum value (-1 if none was set)
int checksum = 0;
for (int i = 0; i < 7; ++i) {
checksum += val[i] * ((i % 2) ? 1 : 3);
}
checksum = (checksum % 10);
if (checksum) checksum = 10 - checksum;
val[7] = checksum;
// if we had an old checksum value and if it doesn't match what we came
// up with then the string must be invalid so we will bail
if (old_sum != -1 && old_sum != checksum)
return;
// lets determine some core attributes about this barcode
qreal bar_width = 1; // the width of the base unit bar
// this is are mandatory minimum quiet zone
qreal quiet_zone = bar_width * 10;
if (quiet_zone < 10)
quiet_zone = 10;
// what kind of area do we have to work with
qreal draw_width = r.width();
qreal draw_height = r.height() - 0.02;
// L = 60X
// L length of barcode (excluding quite zone) in units same as X and I
// X the width of a bar (pixels in our case)
qreal L;
qreal X = bar_width;
L = (67.0 * X);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
- if (align == 1) { // center
+ if (align == Qt::AlignHCenter) {
qreal nqz = (draw_width - L) / 2;
if (nqz > quiet_zone)
quiet_zone = nqz;
- } else if (align > 1) // right
+ } else if (align == Qt::AlignRight) {
quiet_zone = draw_width - (L + quiet_zone);
- // else if(align < 1) {} // left : do nothing
+ }
+ // left : do nothing
qreal pos = r.left() + quiet_zone;
qreal top = r.top();
QPen pen(Qt::NoPen);
QBrush brush(QColor("black"));
// render open guard
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += bar_width;
// render first set
for (int i = 0; i < 4; ++i) {
int b = val[i];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][LEFTHAND_ODD][w]) {
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height - 0.06));
page->insertPrimitive(rect);
}
pos += bar_width;
}
}
// render center guard
pos += bar_width;
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
// render last set
for (int i = 0; i < 4; ++i) {
int b = val[i+4];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][RIGHTHAND][w]) {
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height - 0.06));
page->insertPrimitive(rect);
}
pos += bar_width;
}
}
// render close guard
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
QString leftstr = QString().sprintf("%d%d%d%d",
val[0], val[1], val[2], val[3]);
QString rightstr = QString().sprintf("%d%d%d%d",
val[4], val[5], val[6], val[7]);
QFont font(QLatin1String("Arial"), 6);
OROTextBox * tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + 0.03, (r.top() + draw_height) - 0.06));
tb->setSize(QSizeF(0.28, 0.10));
tb->setFont(font);
tb->setText(leftstr);
tb->setFlags(Qt::AlignHCenter | Qt::AlignTop);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + 0.36, (r.top() + draw_height) - 0.06));
tb->setSize(QSizeF(0.28, 0.10));
tb->setFont(font);
tb->setText(rightstr);
tb->setFlags(Qt::AlignHCenter | Qt::AlignTop);
page->insertPrimitive(tb);
}
-void renderCodeUPCE(OROPage * page, const QRectF & r, const QString & _str, int align)
+void renderCodeUPCE(OROPage * page, const QRectF & r, const QString & _str, Qt::Alignment align)
{
int val[8];
// initialize all the values just so we can be predictable
for (int i = 0; i < 8; ++i) {
val[i] = -1;
}
// verify that the passed in string is valid
// if it's not either twelve or thirteen characters
// then it must be invalid to begin with
if (_str.length() != 8)
return;
// loop through and convert each char to a digit.
// if we can't convert all characters then this is
// an invalid number
for (int i = 0; i < _str.length(); ++i) {
val[i] = ((QChar)_str.at(i)).digitValue();
if (val[i] == -1)
return;
}
// calculate and append the checksum value
// because everything is so messed up we don't calculate
// the checksum and require that it be passed in already
// however we do have to verify that the first digit is
// either 0 or 1 as that is our parity
if (val[0] != 0 && val[0] != 1)
return;
// lets determine some core attributes about this barcode
qreal bar_width = 1; // the width of the base unit bar
// this is are mandatory minimum quiet zone
qreal quiet_zone = bar_width * 0.10;
if (quiet_zone < 0.10)
quiet_zone = 0.10;
// what kind of area do we have to work with
qreal draw_width = r.width();
qreal draw_height = r.height() - 2;
// L = 51X
// L length of barcode (excluding quite zone) in units same as X and I
// X the width of a bar (pixels in our case)
qreal L;
qreal X = bar_width;
L = (51.0 * X);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
- if (align == 1) { // center
+ if (align == Qt::AlignHCenter) {
qreal nqz = (draw_width - L) / 2;
if (nqz > quiet_zone)
quiet_zone = nqz;
- } else if (align > 1) // right
+ } else if (align == Qt::AlignRight) {
quiet_zone = draw_width - (L + quiet_zone);
- // else if(align < 1) {} // left : do nothing
+ }
+ // left : do nothing
qreal pos = r.left() + quiet_zone;
qreal top = r.top();
QPen pen(Qt::NoPen);
QBrush brush(QColor("black"));
// render open guard
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += bar_width;
// render first set
for (int i = 0; i < 6; ++i) {
int b = val[i+1];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][_upcparenc[val[7]][val[0]][i]][w]) {
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height - 7));
page->insertPrimitive(rect);
}
pos += bar_width;
}
}
// render center guard
pos += bar_width;
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
pos += (bar_width * 2.0);
// render close guard
rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(pos, top, bar_width, draw_height));
page->insertPrimitive(rect);
QString parstr = QString::number(val[0]);
QString chkstr = QString::number(val[7]);
QString leftstr = QString().sprintf("%d%d%d%d%d%d",
val[1], val[2], val[3], val[4], val[5], val[6]);
QFont font(QLatin1String("Arial"), 6);
KReportTextStyleData ts;
ts.backgroundColor = Qt::white;
ts.font = font;
ts.foregroundColor = Qt::black;
ts.backgroundOpacity = 100;
ts.alignment = Qt::AlignRight | Qt::AlignTop;
OROTextBox * tb = new OROTextBox();
tb->setPosition(QPointF(r.left(), r.top() + draw_height - 12));
tb->setSize(QSizeF(quiet_zone - 2, 12));
tb->setTextStyle(ts);
tb->setText(parstr);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + 3, (r.top() + draw_height) - 7));
tb->setSize(QSizeF(42, 10));
tb->setTextStyle(ts);
tb->setText(leftstr);
page->insertPrimitive(tb);
tb = new OROTextBox();
tb->setPosition(QPointF(r.left() + quiet_zone + L + 2, r.top() + draw_height - 12));
tb->setSize(QSizeF(8, 12));
tb->setTextStyle(ts);
tb->setText(chkstr);
page->insertPrimitive(tb);
}
diff --git a/src/plugins/barcode/codeeanpaint.cpp b/src/plugins/barcode/codeeanpaint.cpp
index 0e2163c2..511961b0 100644
--- a/src/plugins/barcode/codeeanpaint.cpp
+++ b/src/plugins/barcode/codeeanpaint.cpp
@@ -1,651 +1,655 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
/*
* This file contains the implementation of the Code EAN and similar
* formats for rendering purposes. All this code assumes a 100dpi
* rendering surface for it's calculations.
*/
#include
#include
#include
#include
#include
#include "KReportRenderObjects.h"
static const int LEFTHAND_ODD = 0;
static const int LEFTHAND_EVEN = 1;
static const int RIGHTHAND = 2;
static int const _encodings[10][3][7] = {
/* LEFTHAND_ODD */ /* LEFTHAND_EVEN */ /* RIGHTHAND */
{ { 0, 0, 0, 1, 1, 0, 1}, { 0, 1, 0, 0, 1, 1, 1 }, { 1, 1, 1, 0, 0, 1, 0 } }, // 0
{ { 0, 0, 1, 1, 0, 0, 1}, { 0, 1, 1, 0, 0, 1, 1 }, { 1, 1, 0, 0, 1, 1, 0 } }, // 1
{ { 0, 0, 1, 0, 0, 1, 1}, { 0, 0, 1, 1, 0, 1, 1 }, { 1, 1, 0, 1, 1, 0, 0 } }, // 2
{ { 0, 1, 1, 1, 1, 0, 1}, { 0, 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 1, 0 } }, // 3
{ { 0, 1, 0, 0, 0, 1, 1}, { 0, 0, 1, 1, 1, 0, 1 }, { 1, 0, 1, 1, 1, 0, 0 } }, // 4
{ { 0, 1, 1, 0, 0, 0, 1}, { 0, 1, 1, 1, 0, 0, 1 }, { 1, 0, 0, 1, 1, 1, 0 } }, // 5
{ { 0, 1, 0, 1, 1, 1, 1}, { 0, 0, 0, 0, 1, 0, 1 }, { 1, 0, 1, 0, 0, 0, 0 } }, // 6
{ { 0, 1, 1, 1, 0, 1, 1}, { 0, 0, 1, 0, 0, 0, 1 }, { 1, 0, 0, 0, 1, 0, 0 } }, // 7
{ { 0, 1, 1, 0, 1, 1, 1}, { 0, 0, 0, 1, 0, 0, 1 }, { 1, 0, 0, 1, 0, 0, 0 } }, // 8
{ { 0, 0, 0, 1, 0, 1, 1}, { 0, 0, 1, 0, 1, 1, 1 }, { 1, 1, 1, 0, 1, 0, 0 } } // 9
};
static const int odd = LEFTHAND_ODD;
static const int even = LEFTHAND_EVEN;
static const int _parity[10][6] = {
{ odd, odd, odd, odd, odd, odd }, // 0
{ odd, odd, even, odd, even, even }, // 1
{ odd, odd, even, even, odd, even }, // 2
{ odd, odd, even, even, even, odd }, // 3
{ odd, even, odd, odd, even, even }, // 4
{ odd, even, even, odd, odd, even }, // 5
{ odd, even, even, even, odd, odd }, // 6
{ odd, even, odd, even, odd, even }, // 7
{ odd, even, odd, even, even, odd }, // 8
{ odd, even, even, odd, even, odd } // 9
};
static const int _upcparenc[10][2][6] = {
/* PARITY 0 */ /* PARITY 1 */
{ { even, even, even, odd, odd, odd }, { odd, odd, odd, even, even, even } }, // 0
{ { even, even, odd, even, odd, odd }, { odd, odd, even, odd, even, even } }, // 1
{ { even, even, odd, odd, even, odd }, { odd, odd, even, even, odd, even } }, // 2
{ { even, even, odd, odd, odd, even }, { odd, odd, even, even, even, odd } }, // 3
{ { even, odd, even, even, odd, odd }, { odd, even, odd, odd, even, even } }, // 4
{ { even, odd, odd, even, even, odd }, { odd, even, even, odd, odd, even } }, // 5
{ { even, odd, odd, odd, even, even }, { odd, even, even, even, odd, odd } }, // 6
{ { even, odd, even, odd, even, odd }, { odd, even, odd, even, odd, even } }, // 7
{ { even, odd, even, odd, odd, even }, { odd, even, odd, even, even, odd } }, // 8
{ { even, odd, odd, even, odd, even }, { odd, even, even, odd, even, odd } } // 9
};
-void renderCodeEAN13(const QRect & r, const QString & _str, int align, QPainter * pPainter)
+void renderCodeEAN13(const QRect & r, const QString & _str, Qt::Alignment align, QPainter * pPainter)
{
int val[13];
// initialize all the values just so we can be predictable
for (int i = 0; i < 13; ++i) {
val[i] = -1;
}
// verify that the passed in string is valid
// if it's not either twelve or thirteen characters
// then it must be invalid to begin with
if (_str.length() != 12 && _str.length() != 13) return;
// loop through and convert each char to a digit.
// if we can't convert all characters then this is
// an invalid number
for (int i = 0; i < _str.length(); ++i) {
val[i] = ((QChar) _str.at(i)).digitValue();
if (val[i] == -1) return;
}
// calculate and append the checksum value
int old_sum = val[12]; // get the old check sum value (-1 if none was set)
int checksum = 0;
for (int i = 0; i < 12; ++i) {
checksum += val[i] * ((i % 2) ? 3 : 1);
}
checksum = (checksum % 10);
if (checksum) checksum = 10 - checksum;
val[12] = checksum;
// if we had an old checksum value and if it doesn't match what we came
// up with then the string must be invalid so we will bail
if (old_sum != -1 && old_sum != checksum) return;
// lets determine some core attributes about this barcode
int bar_width = 1; // the width of the base unit bar
// this is are mandatory minimum quiet zone
int quiet_zone = bar_width * 10;
//if (quiet_zone < 10) quiet_zone = 10;
// what kind of area do we have to work with
int draw_width = r.width();
int draw_height = r.height() - 2;
// L = 95X
// L length of barcode (excluding quite zone) in units same as X and I
// X the width of a bar (pixels in our case)
int L;
int X = bar_width;
L = (95 * X);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
- if (align == 1) { // center
+ if (align == Qt::AlignHCenter) {
int nqz = (draw_width - L) / 2;
if (nqz > quiet_zone) quiet_zone = nqz;
- } else if (align > 1) { // right
+ } else if (align == Qt::AlignRight) {
quiet_zone = draw_width - (L + quiet_zone);
- } // else if(align < 1) {} // left : do nothing
+ }
+ // left : do nothing
int pos = r.left() + quiet_zone;
int top = r.top();
if (pPainter) {
pPainter->save();
QPen oneWide(pPainter->pen());
oneWide.setWidth(1);
#ifndef Q_OS_WIN32
oneWide.setJoinStyle(Qt::MiterJoin);
#endif
pPainter->setPen(oneWide);
pPainter->setBrush(pPainter->pen().color());
// render open guard
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos += 2;
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos ++;
// render first set
for (int i = 0; i < 6; ++i) {
int b = val[i+1];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][_parity[val[0]][i]][w]) {
pPainter->fillRect(pos, top, 1, draw_height - 7, pPainter->pen().color());
}
pos++;
}
}
// render center guard
pos++;
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos += 2;
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos += 2;
// render last set
for (int i = 0; i < 6; ++i) {
int b = val[i+7];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][RIGHTHAND][w]) {
pPainter->fillRect(pos, top, 1, draw_height - 7, pPainter->pen().color());
}
pos++;
}
}
// render close guard
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos += 2;
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
QString parstr = QString::number(val[0]);
QString leftstr = QString().sprintf("%d%d%d%d%d%d",
val[1], val[2], val[3], val[4], val[5], val[6]);
QString rightstr = QString().sprintf("%d%d%d%d%d%d",
val[7], val[8], val[9], val[10], val[11], val[12]);
pPainter->setFont(QFont(QLatin1String("Arial"), 6));
pPainter->drawText(r.left(), r.top() + draw_height - 12,
quiet_zone - 2, 12, Qt::AlignRight | Qt::AlignTop,
parstr);
pPainter->drawText(r.left() + quiet_zone + 3,
(r.top() + draw_height) - 7,
42, 10, Qt::AlignHCenter | Qt::AlignTop,
leftstr);
pPainter->drawText(r.left() + quiet_zone + 50,
(r.top() + draw_height) - 7,
42, 10, Qt::AlignHCenter | Qt::AlignTop,
rightstr);
pPainter->restore();
}
}
-void renderCodeUPCA(const QRect & r, const QString & _str, int align, QPainter * pPainter)
+void renderCodeUPCA(const QRect & r, const QString & _str, Qt::Alignment align, QPainter * pPainter)
{
int val[13];
// initialize all the values just so we can be predictable
for (int i = 0; i < 13; ++i) {
val[i] = -1;
}
// verify that the passed in string is valid
// if it's not either twelve or thirteen characters
// then it must be invalid to begin with
if (_str.length() != 11 && _str.length() != 12) return;
// loop through and convert each char to a digit.
// if we can't convert all characters then this is
// an invalid number
val[0] = 0;
for (int i = 0; i < _str.length(); ++i) {
val[i+1] = ((QChar) _str.at(i)).digitValue();
if (val[i+1] == -1) return;
}
// calculate and append the checksum value
int old_sum = val[12]; // get the old check sum value (-1 if none was set)
int checksum = 0;
for (int i = 0; i < 12; ++i) {
checksum += val[i] * ((i % 2) ? 3 : 1);
}
checksum = (checksum % 10);
if (checksum) checksum = 10 - checksum;
val[12] = checksum;
// if we had an old checksum value and if it doesn't match what we came
// up with then the string must be invalid so we will bail
if (old_sum != -1 && old_sum != checksum) return;
// lets determine some core attributes about this barcode
int bar_width = 1; // the width of the base unit bar
// this is are mandatory minimum quiet zone
int quiet_zone = bar_width * 10;
//if (quiet_zone < 10) quiet_zone = 10;
// what kind of area do we have to work with
int draw_width = r.width();
int draw_height = r.height() - 2;
// L = 95X
// L length of barcode (excluding quite zone) in units same as X and I
// X the width of a bar (pixels in our case)
int L;
int X = bar_width;
L = (95 * X);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
- if (align == 1) { // center
+ if (align == Qt::AlignHCenter) {
int nqz = (draw_width - L) / 2;
if (nqz > quiet_zone) quiet_zone = nqz;
- } else if (align > 1) { // right
+ } else if (align == Qt::AlignRight) {
quiet_zone = draw_width - (L + quiet_zone);
- } // else if(align < 1) {} // left : do nothing
+ }
+ // left : do nothing
int pos = r.left() + quiet_zone;
int top = r.top();
if (pPainter) {
pPainter->save();
QPen oneWide(pPainter->pen());
oneWide.setWidth(1);
#ifndef Q_OS_WIN32
oneWide.setJoinStyle(Qt::MiterJoin);
#endif
pPainter->setPen(oneWide);
pPainter->setBrush(pPainter->pen().color());
// render open guard
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos += 2;
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos ++;
// render first set
for (int i = 0; i < 6; ++i) {
int b = val[i+1];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][_parity[val[0]][i]][w]) {
pPainter->fillRect(pos, top, 1, draw_height - (i == 0 ? 0 : 7), pPainter->pen().color());
}
pos++;
}
}
// render center guard
pos++;
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos += 2;
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos += 2;
// render last set
for (int i = 0; i < 6; ++i) {
int b = val[i+7];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][RIGHTHAND][w]) {
pPainter->fillRect(pos, top, 1, draw_height - (i == 5 ? 0 : 7), pPainter->pen().color());
}
pos++;
}
}
// render close guard
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos += 2;
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
QString parstr = QString::number(val[1]);
QString chkstr = QString::number(val[12]);
QString leftstr = QString().sprintf("%d%d%d%d%d",
val[2], val[3], val[4], val[5], val[6]);
QString rightstr = QString().sprintf("%d%d%d%d%d",
val[7], val[8], val[9], val[10], val[11]);
pPainter->setFont(QFont(QLatin1String("Arial"), 6));
pPainter->drawText(r.left(), r.top() + draw_height - 12,
quiet_zone - 2, 12, Qt::AlignRight | Qt::AlignTop,
parstr);
pPainter->drawText(r.left() + quiet_zone + 10,
(r.top() + draw_height) - 7,
35, 10, Qt::AlignHCenter | Qt::AlignTop,
leftstr);
pPainter->drawText(r.left() + quiet_zone + 50,
(r.top() + draw_height) - 7,
35, 10, Qt::AlignHCenter | Qt::AlignTop,
rightstr);
pPainter->drawText(r.left() + quiet_zone + L + 2, r.top() + draw_height - 12,
8, 12, Qt::AlignLeft | Qt::AlignTop,
chkstr);
pPainter->restore();
}
}
-void renderCodeEAN8(const QRect & r, const QString & _str, int align, QPainter * pPainter)
+void renderCodeEAN8(const QRect & r, const QString & _str, Qt::Alignment align, QPainter * pPainter)
{
int val[8];
// initialize all the values just so we can be predictable
for (int i = 0; i < 8; ++i) {
val[i] = -1;
}
// verify that the passed in string is valid
// if it's not either twelve or thirteen characters
// then it must be invalid to begin with
if (_str.length() != 7 && _str.length() != 8) return;
// loop through and convert each char to a digit.
// if we can't convert all characters then this is
// an invalid number
for (int i = 0; i < _str.length(); ++i) {
val[i] = ((QChar) _str.at(i)).digitValue();
if (val[i] == -1) return;
}
// calculate and append the checksum value
int old_sum = val[7]; // get the old check sum value (-1 if none was set)
int checksum = 0;
for (int i = 0; i < 7; ++i) {
checksum += val[i] * ((i % 2) ? 1 : 3);
}
checksum = (checksum % 10);
if (checksum) checksum = 10 - checksum;
val[7] = checksum;
// if we had an old checksum value and if it doesn't match what we came
// up with then the string must be invalid so we will bail
if (old_sum != -1 && old_sum != checksum) return;
// lets determine some core attributes about this barcode
int bar_width = 1; // the width of the base unit bar
// this is are mandatory minimum quiet zone
int quiet_zone = bar_width * 10;
//if (quiet_zone < 10) quiet_zone = 10;
// what kind of area do we have to work with
int draw_width = r.width();
int draw_height = r.height() - 2;
// L = 60X
// L length of barcode (excluding quite zone) in units same as X and I
// X the width of a bar (pixels in our case)
int L;
int X = bar_width;
L = (67 * X);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
- if (align == 1) { // center
+ if (align == Qt::AlignHCenter) {
int nqz = (draw_width - L) / 2;
if (nqz > quiet_zone) quiet_zone = nqz;
- } else if (align > 1) { // right
+ } else if (align == Qt::AlignRight) {
quiet_zone = draw_width - (L + quiet_zone);
- } // else if(align < 1) {} // left : do nothing
+ }
+ // left : do nothing
int pos = r.left() + quiet_zone;
int top = r.top();
if (pPainter) {
pPainter->save();
QPen oneWide(pPainter->pen());
oneWide.setWidth(1);
#ifndef Q_OS_WIN32
oneWide.setJoinStyle(Qt::MiterJoin);
#endif
pPainter->setPen(oneWide);
pPainter->setBrush(pPainter->pen().color());
// render open guard
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos += 2;
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos ++;
// render first set
for (int i = 0; i < 4; ++i) {
int b = val[i];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][LEFTHAND_ODD][w]) {
pPainter->fillRect(pos, top, 1, draw_height - 6, pPainter->pen().color());
}
pos++;
}
}
// render center guard
pos++;
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos += 2;
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos += 2;
// render last set
for (int i = 0; i < 4; ++i) {
int b = val[i+4];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][RIGHTHAND][w]) {
pPainter->fillRect(pos, top, 1, draw_height - 6, pPainter->pen().color());
}
pos++;
}
}
// render close guard
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos += 2;
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
QString leftstr = QString().sprintf("%d%d%d%d",
val[0], val[1], val[2], val[3]);
QString rightstr = QString().sprintf("%d%d%d%d",
val[4], val[5], val[6], val[7]);
pPainter->setFont(QFont(QLatin1String("Arial"), 6));
pPainter->drawText(r.left() + quiet_zone + 3,
(r.top() + draw_height) - 6,
28, 10, Qt::AlignHCenter | Qt::AlignTop,
leftstr);
pPainter->drawText(r.left() + quiet_zone + 36,
(r.top() + draw_height) - 6,
28, 10, Qt::AlignHCenter | Qt::AlignTop,
rightstr);
pPainter->restore();
}
}
-void renderCodeUPCE(const QRect & r, const QString & _str, int align, QPainter * pPainter)
+void renderCodeUPCE(const QRect & r, const QString & _str, Qt::Alignment align, QPainter * pPainter)
{
int val[8];
// initialize all the values just so we can be predictable
for (int i = 0; i < 8; ++i) {
val[i] = -1;
}
// verify that the passed in string is valid
// if it's not either twelve or thirteen characters
// then it must be invalid to begin with
if (_str.length() != 8) return;
// loop through and convert each char to a digit.
// if we can't convert all characters then this is
// an invalid number
for (int i = 0; i < _str.length(); ++i) {
val[i] = ((QChar) _str.at(i)).digitValue();
if (val[i] == -1) return;
}
// calculate and append the checksum value
// because everything is so messed up we don't calculate
// the checksum and require that it be passed in already
// however we do have to verify that the first digit is
// either 0 or 1 as that is our parity
if (val[0] != 0 && val[0] != 1) return;
// lets determine some core attributes about this barcode
int bar_width = 1; // the width of the base unit bar
// this is are mandatory minimum quiet zone
int quiet_zone = bar_width * 10;
//if (quiet_zone < 10) quiet_zone = 10;
// what kind of area do we have to work with
int draw_width = r.width();
int draw_height = r.height() - 2;
// L = 51X
// L length of barcode (excluding quite zone) in units same as X and I
// X the width of a bar (pixels in our case)
int L;
int X = bar_width;
L = (51 * X);
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area
// what should we do if the area is too small????
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
// for left align we don't need to do anything as the values are already setup for it
- if (align == 1) { // center
+ if (align == Qt::AlignHCenter) {
int nqz = (draw_width - L) / 2;
if (nqz > quiet_zone) quiet_zone = nqz;
- } else if (align > 1) { // right
+ } else if (align == Qt::AlignRight) {
quiet_zone = draw_width - (L + quiet_zone);
- } // else if(align < 1) {} // left : do nothing
+ }
+ // left : do nothing
int pos = r.left() + quiet_zone;
int top = r.top();
if (pPainter) {
pPainter->save();
QPen oneWide(pPainter->pen());
oneWide.setWidth(1);
#ifndef Q_OS_WIN32
oneWide.setJoinStyle(Qt::MiterJoin);
#endif
pPainter->setPen(oneWide);
pPainter->setBrush(pPainter->pen().color());
// render open guard
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos += 2;
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos ++;
// render first set
for (int i = 0; i < 6; ++i) {
int b = val[i+1];
for (int w = 0; w < 7; ++w) {
if (_encodings[b][_upcparenc[val[7]][val[0]][i]][w]) {
pPainter->fillRect(pos, top, 1, draw_height - 7, pPainter->pen().color());
}
pos++;
}
}
// render center guard
pos++;
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos += 2;
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
pos += 2;
// render close guard
pPainter->fillRect(pos, top, 1, draw_height, pPainter->pen().color());
QString parstr = QString::number(val[0]);
QString chkstr = QString::number(val[7]);
QString leftstr = QString().sprintf("%d%d%d%d%d%d",
val[1], val[2], val[3], val[4], val[5], val[6]);
pPainter->setFont(QFont(QLatin1String("Arial"), 6));
pPainter->drawText(r.left(), r.top() + draw_height - 12,
quiet_zone - 2, 12, Qt::AlignRight | Qt::AlignTop,
parstr);
pPainter->drawText(r.left() + quiet_zone + 3,
(r.top() + draw_height) - 7,
42, 10, Qt::AlignHCenter | Qt::AlignTop,
leftstr);
pPainter->drawText(r.left() + quiet_zone + L + 2, r.top() + draw_height - 12,
8, 12, Qt::AlignLeft | Qt::AlignTop,
chkstr);
pPainter->restore();
}
}
diff --git a/src/plugins/barcode/ext3of9.cpp b/src/plugins/barcode/ext3of9.cpp
index 586942be..c78b15fb 100644
--- a/src/plugins/barcode/ext3of9.cpp
+++ b/src/plugins/barcode/ext3of9.cpp
@@ -1,194 +1,194 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
* Copyright (C) 2015 Jarosław Staniek
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
/*
* This file contains the code that will render the extended 3of9 barcode.
* This code will parse a string and build a compliant 3of9 string and then
* call the 3of9 renderer to do the actual drawing.
*/
#include
#include
#include "barcodes.h"
class _ext3of9map
{
public:
_ext3of9map(const char c, const char *s)
: code(c), conversion(QLatin1String(s))
{
}
const char code;
const QString conversion;
};
const _ext3of9map ext3of9map[] = {
_ext3of9map('\0' , "%U"), // NUL
_ext3of9map('\001' , "$A"), // SOH
_ext3of9map('\002' , "$B"), // STX
_ext3of9map('\003' , "$C"), // ETX
_ext3of9map('\004' , "$D"), // EOT
_ext3of9map('\005' , "$E"), // ENQ
_ext3of9map('\006' , "$F"), // ACK
_ext3of9map('\007' , "$G"), // BEL
_ext3of9map('\010' , "$H"), // BS
_ext3of9map('\011' , "$I"), // HT
_ext3of9map('\012' , "$J"), // LF
_ext3of9map('\013' , "$K"), // VT
_ext3of9map('\014' , "$L"), // FF
_ext3of9map('\015' , "$M"), // CR
_ext3of9map('\016' , "$N"), // SO
_ext3of9map('\017' , "$O"), // SI
_ext3of9map('\020' , "$P"), // DLE
_ext3of9map('\021' , "$Q"), // DC1
_ext3of9map('\022' , "$R"), // DC2
_ext3of9map('\023' , "$S"), // DC3
_ext3of9map('\024' , "$T"), // DC4
_ext3of9map('\025' , "$U"), // NAK
_ext3of9map('\026' , "$V"), // SYN
_ext3of9map('\027' , "$W"), // ETB
_ext3of9map('\030' , "$X"), // CAN
_ext3of9map('\031' , "$Y"), // EM
_ext3of9map('\032' , "$Z"), // SUB
_ext3of9map('\033' , "%A"), // ESC
_ext3of9map('\034' , "%B"), // FS
_ext3of9map('\035' , "%C"), // GS
_ext3of9map('\036' , "%D"), // RS
_ext3of9map('\037' , "%E"), // US
_ext3of9map(' ' , " "), // SPACE
_ext3of9map('!' , "/A"),
_ext3of9map('"' , "/B"),
_ext3of9map('#' , "/C"),
_ext3of9map('$' , "/D"),
_ext3of9map('%' , "/E"),
_ext3of9map('&' , "/F"),
_ext3of9map('\'' , "/G"),
_ext3of9map('(' , "/H"),
_ext3of9map(')' , "/I"),
_ext3of9map('*' , "/J"),
_ext3of9map('+' , "/K"),
_ext3of9map(',' , "/L"),
_ext3of9map('-' , "-"), // /M
_ext3of9map('.' , "."), // /N
_ext3of9map('/' , "/O"),
_ext3of9map('0' , "0"), // /P
_ext3of9map('1' , "1"), // /Q
_ext3of9map('2' , "2"), // /R
_ext3of9map('3' , "3"), // /S
_ext3of9map('4' , "4"), // /T
_ext3of9map('5' , "5"), // /U
_ext3of9map('6' , "6"), // /V
_ext3of9map('7' , "7"), // /W
_ext3of9map('8' , "8"), // /X
_ext3of9map('9' , "9"), // /Y
_ext3of9map(':' , "/Z"),
_ext3of9map(';' , "%F"),
_ext3of9map('<' , "%G"),
_ext3of9map('=' , "%H"),
_ext3of9map('>' , "%I"),
_ext3of9map('?' , "%J"),
_ext3of9map('@' , "%V"),
_ext3of9map('A' , "A"),
_ext3of9map('B' , "B"),
_ext3of9map('C' , "C"),
_ext3of9map('D' , "D"),
_ext3of9map('E' , "E"),
_ext3of9map('F' , "F"),
_ext3of9map('G' , "G"),
_ext3of9map('H' , "H"),
_ext3of9map('I' , "I"),
_ext3of9map('J' , "J"),
_ext3of9map('K' , "K"),
_ext3of9map('L' , "L"),
_ext3of9map('M' , "M"),
_ext3of9map('N' , "N"),
_ext3of9map('O' , "O"),
_ext3of9map('P' , "P"),
_ext3of9map('Q' , "Q"),
_ext3of9map('R' , "R"),
_ext3of9map('S' , "S"),
_ext3of9map('T' , "T"),
_ext3of9map('U' , "U"),
_ext3of9map('V' , "V"),
_ext3of9map('W' , "W"),
_ext3of9map('X' , "X"),
_ext3of9map('Y' , "Y"),
_ext3of9map('Z' , "Z"),
_ext3of9map('[' , "%K"),
_ext3of9map('\\' , "%L"),
_ext3of9map(']' , "%M"),
_ext3of9map('^' , "%N"),
_ext3of9map('_' , "%O"),
_ext3of9map('`' , "%W"),
_ext3of9map('a' , "+A"),
_ext3of9map('b' , "+B"),
_ext3of9map('c' , "+C"),
_ext3of9map('d' , "+D"),
_ext3of9map('e' , "+E"),
_ext3of9map('f' , "+F"),
_ext3of9map('g' , "+G"),
_ext3of9map('h' , "+H"),
_ext3of9map('i' , "+I"),
_ext3of9map('j' , "+J"),
_ext3of9map('k' , "+K"),
_ext3of9map('l' , "+L"),
_ext3of9map('m' , "+M"),
_ext3of9map('n' , "+N"),
_ext3of9map('o' , "+O"),
_ext3of9map('p' , "+P"),
_ext3of9map('q' , "+Q"),
_ext3of9map('r' , "+R"),
_ext3of9map('s' , "+S"),
_ext3of9map('t' , "+T"),
_ext3of9map('u' , "+U"),
_ext3of9map('v' , "+V"),
_ext3of9map('w' , "+W"),
_ext3of9map('x' , "+X"),
_ext3of9map('y' , "+Y"),
_ext3of9map('z' , "+Z"),
_ext3of9map('{' , "%P"),
_ext3of9map('|' , "%Q"),
_ext3of9map('}' , "%R"),
_ext3of9map('~' , "%S"),
_ext3of9map('\177' , "%T"), // DEL
_ext3of9map(-1 , nullptr)
};
inline QString convertTo3of9(char code)
{
for (int i = 0; !ext3of9map[i].conversion.isEmpty(); i++)
if (ext3of9map[i].code == code)
return ext3of9map[i].conversion;
return QString();
}
QString convertTo3of9(const QString &str)
{
QString result;
for (int i = 0; i < str.length(); i++) {
result += convertTo3of9(str.at(i).toLatin1());
}
return result;
}
-void renderExtended3of9(OROPage * page, const QRectF & r, const QString & str, int align)
+void renderExtended3of9(OROPage * page, const QRectF & r, const QString & str, Qt::Alignment align)
{
render3of9(page, r, convertTo3of9(str), align);
}
diff --git a/src/plugins/barcode/ext3of9paint.cpp b/src/plugins/barcode/ext3of9paint.cpp
index 014c2f6e..ddeedfbb 100644
--- a/src/plugins/barcode/ext3of9paint.cpp
+++ b/src/plugins/barcode/ext3of9paint.cpp
@@ -1,37 +1,37 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
* Copyright (C) 2015 Jarosław Staniek
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
/*
* This file contains the code that will render the extended 3of9 barcode.
* This code will parse a string and build a compliant 3of9 string and then
* call the 3of9 renderer to do the actual drawing.
*/
#include
#include
#include
#include "barcodepaint.h"
QString convertTo3of9(const QString &str);
-void renderExtended3of9(const QRect & r, const QString & str, int align, QPainter * pPainter)
+void renderExtended3of9(const QRect & r, const QString & str, Qt::Alignment align, QPainter * pPainter)
{
render3of9(r, convertTo3of9(str), align, pPainter);
}
diff --git a/src/plugins/barcode/i2of5.cpp b/src/plugins/barcode/i2of5.cpp
index e1a7c50d..7072a6e0 100644
--- a/src/plugins/barcode/i2of5.cpp
+++ b/src/plugins/barcode/i2of5.cpp
@@ -1,152 +1,152 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2012 by OpenMFG, LLC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Please contact info@openmfg.com with any questions on this license.
*/
/*
* This file contains the implementation of the interleaved 2 of 5 barcode renderer.
* All this code assumes a 100dpi rendering surface for it's calculations.
*/
#include
#include
#include
#include
#include "KReportRenderObjects.h"
const char* _i2of5charmap[] = {
"NNWWN",
"WNNNW",
"NWNNW",
"WWNNN",
"NNWNW",
"WNWNN",
"NWWNN",
"NNNWW",
"WNNWN",
"NWNWN"
};
static QPointF addElement(OROPage * page, const QRectF &r, QPointF startPos, qreal width, bool isSpace)
{
QPen pen(Qt::NoPen);
QBrush brush(QColor("black"));
if (!isSpace) {
ORORect * rect = new ORORect();
rect->setPen(pen);
rect->setBrush(brush);
rect->setRect(QRectF(startPos.x(),startPos.y(), width, r.height()));
//rect->setRotationAxis(bc->rect.topLeft()); //!< @todo check this
page->insertPrimitive(rect);
}
return QPointF(startPos.x() + width, startPos.y());
}
static QPointF addBar(OROPage * page, const QRectF &r, QPointF startPos, qreal width)
{
return addElement(page, r, startPos, width, false);
}
static QPointF addSpace(OROPage * page, const QRectF &r, QPointF startPos, qreal width)
{
return addElement(page, r, startPos, width, true);
}
-void renderI2of5(OROPage * page, const QRectF &r, const QString & _str, int align)
+void renderI2of5(OROPage * page, const QRectF &r, const QString & _str, Qt::Alignment align)
{
QString str = _str;
qreal narrow_bar = 1; // a narrow bar is 1/100th inch wide
qreal bar_width_mult = 2.5; // the wide bar width multiple of the narrow bar
qreal wide_bar = narrow_bar * bar_width_mult;
if (str.length() % 2) {
str = QLatin1Char('0') + str; // padding zero if number of characters is not even
}
// this is our mandatory minimum quiet zone
qreal quiet_zone = narrow_bar * 10;
if (quiet_zone < 0.1) {
quiet_zone = 0.1;
}
// what kind of area do we have to work with
qreal draw_width = r.width();
// how long is the value we need to encode?
int val_length = str.length();
// L = (C(2N+3)+6+N)X
// L length of barcode (excluding quite zone
// C the number of characters in the value excluding the start/stop
// N the bar width multiple for wide bars
// X the width of a bar (pixels in our case)
qreal L;
qreal C = val_length;
qreal N = bar_width_mult;
qreal X = narrow_bar;
L = (C * (2.0*N + 3.0) + 6.0 + N) * X;
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area)
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
- if (align == 1) { // center
+ if (align == Qt::AlignHCenter) {
qreal nqz = (draw_width - L) / 2.0;
if (nqz > quiet_zone) {
quiet_zone = nqz;
}
}
- else if (align > 1) { // right
+ else if (align == Qt::AlignRight) {
quiet_zone = draw_width - (L + quiet_zone);
}
- //else if (align < 1) {} // left : do nothing
+ // left : do nothing
QPointF pos(r.left() + quiet_zone, r.top());
// start character
pos = addBar(page, r, pos, narrow_bar);
pos = addSpace(page, r, pos, narrow_bar);
pos = addBar(page, r, pos, narrow_bar);
pos = addSpace(page, r, pos, narrow_bar);
for (int i = 0; i < str.length()-1; i+=2) {
for (int iElt = 0; _i2of5charmap [0][iElt] != '\0'; iElt++) {
for (int offset=0; offset<=1; offset++) {
QChar c = str.at(i+offset);
if (!c.isDigit()) {
break; // invalid character
}
int iChar = c.digitValue();
qreal width = _i2of5charmap[iChar][iElt] == 'W' ? wide_bar : narrow_bar;
pos = addElement(page, r, pos, width, offset==1);
}
}
}
// stop character
pos = addBar(page, r, pos, wide_bar);
pos = addSpace(page, r, pos, narrow_bar);
pos = addBar(page, r, pos, narrow_bar);
}
diff --git a/src/plugins/barcode/i2of5paint.cpp b/src/plugins/barcode/i2of5paint.cpp
index c0caa4d8..57ce48ff 100644
--- a/src/plugins/barcode/i2of5paint.cpp
+++ b/src/plugins/barcode/i2of5paint.cpp
@@ -1,156 +1,156 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2012 by OpenMFG, LLC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Please contact info@openmfg.com with any questions on this license.
*/
/*
* This file contains the implementation of the interleaved 2 of 5 barcode renderer.
* All this code assumes a 100dpi rendering surface for it's calculations.
*/
#include
#include
#include
#include
#include
const char* __i2of5charmap[] = {
"NNWWN",
"WNNNW",
"NWNNW",
"WWNNN",
"NNWNW",
"WNWNN",
"NWWNN",
"NNNWW",
"WNNWN",
"NWNWN"
};
static QPointF addElement(const QRectF &r, QPointF startPos, qreal width, bool isSpace, QPainter * pPainter)
{
if (!isSpace && pPainter) {
pPainter->fillRect(startPos.x(),startPos.y(), width, r.height(), pPainter->pen().color());
}
return QPointF(startPos.x() + width, startPos.y());
}
static QPointF addBar(const QRectF &r, QPointF startPos, qreal width, QPainter * pPainter)
{
return addElement(r, startPos, width, false, pPainter);
}
static QPointF addSpace(const QRectF &r, QPointF startPos, qreal width, QPainter * pPainter)
{
return addElement(r, startPos, width, true, pPainter);
}
-void renderI2of5(const QRectF &r, const QString & _str, int align, QPainter * pPainter)
+void renderI2of5(const QRectF &r, const QString & _str, Qt::Alignment align, QPainter * pPainter)
{
QString str = _str;
qreal narrow_bar = 1; // a narrow bar is 1/100th inch wide
qreal bar_width_mult = 2.5; // the wide bar width multiple of the narrow bar
qreal wide_bar = narrow_bar * bar_width_mult;
if (str.length() % 2) {
str = QLatin1Char('0')+ str; // padding zero if number of characters is not even
}
// this is our mandatory minimum quiet zone
qreal quiet_zone = narrow_bar * 10;
if(quiet_zone < 0.1) {
quiet_zone = 0.1;
}
// what kind of area do we have to work with
int draw_width = r.width();
// how long is the value we need to encode?
int val_length = str.length();
// L = (C(2N+3)+6+N)X
// L length of barcode (excluding quite zone
// C the number of characters in the value excluding the start/stop
// N the bar width multiple for wide bars
// X the width of a bar (pixels in our case)
int L;
int C = val_length;
qreal N = bar_width_mult;
qreal X = narrow_bar;
L = (C * (2.0*N + 3.0) + 6.0 + N) * X;
// now we have the actual width the barcode will be so can determine the actual
// size of the quiet zone (we assume we center the barcode in the given area)
// At the moment the way the code is written is we will always start at the minimum
// required quiet zone if we don't have enough space.... I guess we'll just have over-run
// to the right
//
// calculate the starting position based on the alignment option
- if (align == 1) { // center
+ if (align == Qt::AlignHCenter) {
int nqz = (draw_width - L) / 2.0;
if (nqz > quiet_zone) {
quiet_zone = nqz;
}
}
- else if (align > 1) { // right
+ else if (align == Qt::AlignRight) {
quiet_zone = draw_width - (L + quiet_zone);
}
- //else if (align < 1) {} // left : do nothing
+ // left : do nothing
if (pPainter) {
pPainter->save();
QPen oneWide(pPainter->pen());
oneWide.setWidth(1);
#ifndef Q_OS_WIN32
oneWide.setJoinStyle(Qt::MiterJoin);
#endif
pPainter->setPen(oneWide);
pPainter->setBrush(pPainter->pen().color());
}
QPointF pos(r.left() + quiet_zone, r.top());
// start character
pos = addBar(r, pos, narrow_bar,pPainter);
pos = addSpace(r, pos, narrow_bar, pPainter);
pos = addBar(r, pos, narrow_bar, pPainter);
pos = addSpace(r, pos, narrow_bar, pPainter);
for (int i = 0; i < str.length()-1; i+=2) {
for (int iElt = 0; __i2of5charmap [0][iElt] != '\0'; iElt++) {
for (int offset=0; offset<=1; offset++) {
QChar c = str.at(i+offset);
if (!c.isDigit()) {
break; // invalid character
}
int iChar = c.digitValue();
int width = __i2of5charmap[iChar][iElt] == 'W' ? wide_bar : narrow_bar;
pos = addElement(r, pos, width, offset==1, pPainter);
}
}
}
// stop character
pos = addBar(r, pos, wide_bar, pPainter);
pos = addSpace(r, pos, narrow_bar, pPainter);
pos = addBar(r, pos, narrow_bar, pPainter);
}