Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CODE-39, allow cards with no detected code #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/qml/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function stringToBarcode (type, str)
return "(" + getI2of5(str) + ")";

case 'CODE-39':
case 'libre-CODE-39':
return "*" + str.toUpperCase().replace (/[^A-Z\s\d-$%./+]/g, "") + "*";

case 'PICTURE':
Expand Down
16 changes: 14 additions & 2 deletions app/qml/ubcards.qml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ MainView {
ListElement { name: "CODE-128" ; font: "../fonts/cardwallet/Code128_new.ttf" }
ListElement { name: "CODE-128-mini" ; font: "../fonts/librebarcode/LibreBarcode128-Regular.ttf" }
ListElement { name: "CODE-39" ; font: "../fonts/cardwallet/Free3of9.ttf" }
ListElement { name: "libre-CODE-39" ; font: "../fonts/librebarcode/LibreBarcode39-Regular.ttf" }
ListElement { name: "DataBar" ; font: "../fonts/cardwallet/Free3of9.ttf" }
ListElement { name: "EAN-13" ; font: "../fonts/cardwallet/ean13_new.ttf" }
ListElement { name: "EAN-8" ; font: "../fonts/cardwallet/ean13_new.ttf" }
Expand Down Expand Up @@ -184,6 +185,14 @@ MainView {
}
return codeTypeModel.get(0).font
}

function getFontYScale(name) {
const result = {
"CODE-128-mini": 2,
"libre-CODE-39": 3,
}[name];
return result ? result : 1;
}

PageStack {
id: pageStack
Expand Down Expand Up @@ -923,19 +932,21 @@ MainView {
id: encodedCodeField
Layout.fillWidth: true
width: parent.width - units.gu(5)
height: units.gu(15)
visible: hasCodeFont(editPage.type)
text: (editPage.type === "CODE-128-mini") ? Code128.encode(editPage.text) : Encoder.stringToBarcode(editPage.type, editPage.text)
font.family: loadedFont.name
textFormat: Text.PlainText
fontSizeMode: Text.HorizontalFit
minimumPointSize: units.gu(2)
// This causes, that the actual height is units.gu(20), which is bigger on small display ... it affects spacing between barcode and text ... unable to resolve now
font.pointSize: units.gu(20)
// This causes, that the actual height is units.gu(20), which is bigger on small display ... it affects spacing between barcode and text ... unable to resolve now
font.pointSize: units.gu(20)
horizontalAlignment: Text.AlignHCenter
anchors.margins: units.gu(5)
anchors.centerIn: parent
anchors.verticalCenter: parent.verticalCenter
color: "black"
transform: Scale { yScale: getFontYScale(editPage.type)}
}
}

Expand Down Expand Up @@ -966,6 +977,7 @@ MainView {
width: parent.width - units.gu(5)
anchors.margins: units.gu(5)
anchors.centerIn: parent
fillMode: Image.PreserveAspectFit
visible: (editPage.type === "PICTURE")
source: (editPage.type === "PICTURE") ? editPage.imageSource : ""
}
Expand Down
16 changes: 11 additions & 5 deletions app/qrcodereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ QRCodeReader::QRCodeReader(QObject *parent) :

bool QRCodeReader::valid() const
{
return !m_type.isEmpty() && !m_text.isEmpty();
return (!m_type.isEmpty() && !m_text.isEmpty()) || m_type == "PICTURE";
}

QString QRCodeReader::type() const
Expand Down Expand Up @@ -129,7 +129,7 @@ void QRCodeReader::grab(const QString &name, const QString &category)
connect(reader, SIGNAL(resultReady(QString, QString, QString, QString, QImage)), this, SLOT(handleResults(QString, QString, QString, QString, QImage)));
m_readerThread.start();

QMetaObject::invokeMethod(reader, "doWork", Q_ARG(QImage, img), Q_ARG(QString, name), Q_ARG(QString, category), Q_ARG(bool, false));
QMetaObject::invokeMethod(reader, "doWork", Q_ARG(QImage, img), Q_ARG(QString, name), Q_ARG(QString, category), Q_ARG(bool, false), Q_ARG(bool, false));
}

void QRCodeReader::processImage(const QUrl &url, const QString &name, const QString &category)
Expand All @@ -151,7 +151,7 @@ void QRCodeReader::processImage(const QUrl &url, const QString &name, const QStr
connect(reader, SIGNAL(resultReady(QString, QString, QString, QString, QImage)), this, SLOT(handleResults(QString, QString, QString, QString, QImage)));
m_readerThread.start();

QMetaObject::invokeMethod(reader, "doWork", Q_ARG(QImage, image), Q_ARG(QString, name), Q_ARG(QString, category), Q_ARG(bool, false));
QMetaObject::invokeMethod(reader, "doWork", Q_ARG(QImage, image), Q_ARG(QString, name), Q_ARG(QString, category), Q_ARG(bool, false), Q_ARG(bool, true));
}


Expand All @@ -166,7 +166,7 @@ void QRCodeReader::handleResults(const QString &type, const QString &text, const
emit validChanged();
}

void Reader::doWork(const QImage &image, const QString &name, const QString &category, bool invert)
void Reader::doWork(const QImage &image, const QString &name, const QString &category, bool invert, bool pictureSource)
{
// Prepare image
QImage copy = image;
Expand All @@ -189,15 +189,17 @@ void Reader::doWork(const QImage &image, const QString &name, const QString &cat
// qDebug() << "scanned. have" << n << "symbols";
if (!invert && n == 0) {
// Nothing found... try again inverted
doWork(image, name, category, true);
doWork(image, name, category, true, pictureSource);
return;
}

img.set_symbols(tmp.get_symbols());

// extract results
bool result = false;
for(zbar::Image::SymbolIterator symbol = img.symbol_begin(); symbol != img.symbol_end(); ++symbol) {

result = true;
QString typeName = QString::fromStdString(symbol->get_type_name());
QString symbolString = QString::fromStdString(symbol->get_data());

Expand Down Expand Up @@ -237,6 +239,10 @@ void Reader::doWork(const QImage &image, const QString &name, const QString &cat
emit resultReady(typeName, symbolString, name, category, codeImage);
}

if (!result && pictureSource) {
emit resultReady("PICTURE", "", name, category, image);
}

tmp.set_data(NULL, 0);
img.set_data(NULL, 0);

Expand Down
2 changes: 1 addition & 1 deletion app/qrcodereader.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Reader : public QObject
Q_OBJECT

public slots:
void doWork(const QImage &image, const QString &name, const QString &category, bool invert);
void doWork(const QImage &image, const QString &name, const QString &category, bool invert, bool pictureSource);

signals:
void resultReady(const QString &type, const QString &text, const QString &name, const QString &category, const QImage &codeImage);
Expand Down