From 9daffeb76475ce73c6bc92351b1a5b42bc850d85 Mon Sep 17 00:00:00 2001 From: taipanromania Date: Fri, 18 Jul 2008 14:48:31 +0000 Subject: [PATCH] qt4 backend --- backend_qt4/backend_qt4.pro | 99 ++++++++++ backend_qt4/barcoderender.cpp | 334 ++++++++++++++++++++++++++++++++++ backend_qt4/barcoderender.h | 76 ++++++++ backend_qt4/compile_n_config | 8 + backend_qt4/readme | 9 + 5 files changed, 526 insertions(+) create mode 100644 backend_qt4/backend_qt4.pro create mode 100644 backend_qt4/barcoderender.cpp create mode 100644 backend_qt4/barcoderender.h create mode 100755 backend_qt4/compile_n_config create mode 100644 backend_qt4/readme diff --git a/backend_qt4/backend_qt4.pro b/backend_qt4/backend_qt4.pro new file mode 100644 index 00000000..6867a37d --- /dev/null +++ b/backend_qt4/backend_qt4.pro @@ -0,0 +1,99 @@ +TEMPLATE = lib + +CONFIG += dll + +macx{ + CONFIG -= dll + CONFIG += lib_bundle +} + +TARGET = QtZint + +INCLUDEPATH += ../backend + +#EDIT THIS !!!! +DEFINES += NO_PNG NO_QR + +!contains(DEFINES, NO_PNG) { + SOURCES += ../backend/png.c + LIBS += -lpng +} + +contains(DEFINES, NO_QR){ + SOURCES += ../backend/no_qr.c +}else{ + SOURCES += ../backend/qr.c + +contains(DEFINES, QR_SYSTEM){ + LIBS += -lqrencode +}else{ + +INCLUDEPATH += qrencode + +HEADERS += qrencode/bitstream.h \ + qrencode/mask.h \ + qrencode/qrencode.h \ + qrencode/qrencode_inner.h \ + qrencode/qrinput.h \ + qrencode/qrspec.h \ + qrencode/rscode.h \ + qrencode/split.h + +SOURCES += qrencode/bitstream.c \ + qrencode/mask.c \ + qrencode/qrencode.c \ + qrencode/qrinput.c \ + qrencode/qrspec.c \ + qrencode/rscode.c \ + qrencode/split.c +} + +} + +HEADERS += ../backend/common.h \ + ../backend/composite.h \ + ../backend/dm200.h \ + ../backend/large.h \ + ../backend/maxicode.h \ + ../backend/maxipng.h \ + ../backend/pdf417.h \ + ../backend/reedsol.h \ + ../backend/rss.h \ + ../backend/zint.h \ + barcoderender.h + +SOURCES += ../backend/2of5.c \ + ../backend/auspost.c \ + ../backend/code.c \ + ../backend/code128.c \ + ../backend/code16k.c \ + ../backend/common.c \ + ../backend/composite.c \ + ../backend/dm200.c \ + ../backend/dmatrix.c \ + ../backend/imail.c \ + ../backend/large.c \ + ../backend/library.c \ + ../backend/maxicode.c \ + ../backend/medical.c \ + ../backend/pdf417.c \ + ../backend/plessey.c \ + ../backend/postal.c \ + ../backend/ps.c \ + ../backend/reedsol.c \ + ../backend/rss.c \ + ../backend/telepen.c \ + ../backend/upcean.c \ + barcoderender.cpp + +VERSION = 1.6.0 + +#DESTDIR = . + +include.path = $$[ZINT_INSTALL_HEADERS] +include.files = ../backend/zint.h barcoderender.h + +target.path = $$[ZINT_INSTALL_LIBS] + +INSTALLS += target include + diff --git a/backend_qt4/barcoderender.cpp b/backend_qt4/barcoderender.cpp new file mode 100644 index 00000000..f8ea4f11 --- /dev/null +++ b/backend_qt4/barcoderender.cpp @@ -0,0 +1,334 @@ +/*************************************************************************** + * Copyright (C) 2008 by BogDan Vatra * + * bogdan@licentia.eu * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * This program 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 General Public License for more details. * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ +#include +#include + +#include "barcoderender.h" + +namespace Zint +{ + +BareCode::BareCode() +{ + m_symbol=BARCODE_CODE128; + m_height=50; + m_border=NO_BORDER; + m_boderWidth=0; + m_width=0; + m_securityLevel=-1; + m_pdf417CodeWords=928; + m_fgColor=Qt::black; + m_bgColor=Qt::white; + m_zintSymbol=0; +} + +BareCode::~BareCode() +{ + if (m_zintSymbol) + ZBarcode_Delete(m_zintSymbol); +} + +void BareCode::encode() +{ + if (m_zintSymbol) + ZBarcode_Delete(m_zintSymbol); + + m_lastError.clear(); + m_zintSymbol = ZBarcode_Create(); + m_zintSymbol->symbology=m_symbol; + m_zintSymbol->height=m_height; + m_zintSymbol->output_options=0; + m_zintSymbol->whitespace_width=0; + m_zintSymbol->border_width=0; + m_zintSymbol->option_1=m_securityLevel; + m_zintSymbol->option_2=m_width; + m_zintSymbol->option_3=m_pdf417CodeWords; + QByteArray bstr=m_text.toAscii(); + QByteArray pstr=m_primaryMessage.left(99).toAscii(); + strcpy(m_zintSymbol->primary,pstr.data()); + int error = ZBarcode_Encode(m_zintSymbol, (unsigned char*)bstr.data()); + if (error > WARN_INVALID_OPTION) + m_lastError=m_zintSymbol->errtxt; + else + { + if (m_zintSymbol->symbology != BARCODE_MAXICODE) + { + int preset_height = 0; + + for (int i = 0; i < m_zintSymbol->rows; i++) + preset_height += m_zintSymbol->row_height[i]; + + if (preset_height) + m_zintSymbol->height = preset_height; + } + else + m_zintSymbol->height = 33; + } +} + +void BareCode::setSymbol(int symbol) +{ + m_symbol=symbol; +} + +void BareCode::setText(const QString & text) +{ + m_text=text; +} + +void BareCode::setPrimaryMessage(const QString & primaryMessage) +{ + m_primaryMessage=primaryMessage; +} + +void BareCode::setHeight(int height) +{ + m_height=height; +} + +int BareCode::height() +{ + encode(); + return m_zintSymbol->height+(m_border==BOX)?m_boderWidth*2:0; +} + +void BareCode::setBorder(BorderType border) +{ + m_border=border; +} + +void BareCode::setBorderWidth(int boderWidth) +{ + m_boderWidth=boderWidth; +} + +void BareCode::setWidth(int width) +{ + m_width=width; +} + +int BareCode::width() +{ + encode(); + return m_zintSymbol->width+(m_border!=NO_BORDER)?m_boderWidth*2:0; +} + +void BareCode::setSecurityLevel(int securityLevel) +{ + m_securityLevel=securityLevel; +} + +void BareCode::setPdf417CodeWords(int pdf417CodeWords) +{ + m_pdf417CodeWords=pdf417CodeWords; +} + +void BareCode::setFgColor(const QColor & fgColor) +{ + m_fgColor=fgColor; +} + +void BareCode::setBgColor(const QColor & bgColor) +{ + m_bgColor=bgColor; +} + +const QString & BareCode::lastError() +{ + return m_lastError; +} + +bool BareCode::hasErrors() +{ + return m_lastError.length(); +} + +void BareCode::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode, qreal scaleFactor) +{ + encode(); + if (m_lastError.length()) + { + painter.drawText(paintRect,Qt::AlignCenter,m_lastError); + return; + } + + painter.save(); + painter.setClipRect(paintRect,Qt::IntersectClip); + qreal xtr=paintRect.x(); + qreal ytr=paintRect.y(); + + qreal xsf=scaleFactor; + qreal ysf=scaleFactor; + + qreal gwidth=scaleFactor*m_zintSymbol->width; + qreal gheight=scaleFactor*m_zintSymbol->height; + if (m_zintSymbol->symbology == BARCODE_MAXICODE) + { + gheight*=12; + gwidth*=12; + } + + gwidth+=scaleFactor*((m_border==BOX)?m_boderWidth*2:0); + gheight+=scaleFactor*((m_border!=NO_BORDER)?m_boderWidth*2:0); + + switch(mode) + { + case IgnoreAspectRatio: + xsf=(qreal)paintRect.width()/gwidth; + ysf=(qreal)paintRect.height()/gheight; + break; + + case KeepAspectRatio: + if (paintRect.width()-gwidthrows && !m_zintSymbol->row_height[0]) + m_zintSymbol->row_height[0]=m_zintSymbol->height; + + if (m_zintSymbol->symbology == BARCODE_MAXICODE) + { + painter.save(); + painter.setRenderHint(QPainter::Antialiasing); + + for (int row=0;rowrows;row++) + for (int i=0;iwidth;i++) + if (m_zintSymbol->encoded_data[row][i]=='1') + { + QPainterPath pt; + pt.moveTo(i*12+4, row*12); + pt.lineTo(i*12+4+4, row*12); + pt.lineTo(i*12+12, row*12+4); + pt.lineTo(i*12+12, row*12+4+4); + pt.lineTo(i*12+4+4, row*12+12); + pt.lineTo(i*12+4, row*12+12); + pt.lineTo(i*12, row*12+4+4); + pt.lineTo(i*12, row*12+4); + pt.lineTo(i*12+4, row*12); + painter.fillPath(pt,QBrush(m_fgColor)); + } + + p.setWidth(8); + painter.setPen(p); + painter.drawEllipse(QPointF((qreal)m_zintSymbol->width/2*12,m_zintSymbol->height/2*12),12+4,12+4); + painter.drawEllipse(QPointF((qreal)m_zintSymbol->width/2*12,m_zintSymbol->height/2*12),12+8+8+4,12+8+8+4); + painter.drawEllipse(QPointF((qreal)m_zintSymbol->width/2*12,m_zintSymbol->height/2*12),12+8+8+8+8+4,12+8+8+8+8+4); + painter.restore(); + } + else + { + int y=0; + for (int row=0;rowrows;row++) + { + for (int i=0;iwidth;i++) + if (m_zintSymbol->encoded_data[row][i]!='0') + { + int ed=m_zintSymbol->encoded_data[row][i]; + int linewidth=0; + for (int j=i;jwidth;j++,linewidth++) + if (ed!=m_zintSymbol->encoded_data[row][j]) + break; + QColor color; + switch(ed) + { + case 'R': + color=qRgb(0xff,0x00,0x00); + break; + + case 'G': + color=qRgb(0x00,0xff,0x00); + break; + + case 'B': + color=qRgb(0x00,0x00,0xff); + break; + + case 'C': + color=qRgb(0x00,0xff,0xff); + break; + + case 'M': + color=qRgb(0xff,0x00,0xff); + break; + + case 'Y': + color=qRgb(0xff,0xff,0x00); + break; + + default: + color=m_fgColor; + break; + } + painter.fillRect(i,y,linewidth,m_zintSymbol->row_height[row],QBrush(color)); + } + y+=m_zintSymbol->row_height[row]; + } + } + painter.restore(); +} + +} + diff --git a/backend_qt4/barcoderender.h b/backend_qt4/barcoderender.h new file mode 100644 index 00000000..59fcc141 --- /dev/null +++ b/backend_qt4/barcoderender.h @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (C) 2008 by BogDan Vatra * + * bogdan@licentia.eu * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * This program 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 General Public License for more details. * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +#ifndef BARCODERENDER_H +#define BARCODERENDER_H +#include +#include + +#include "zint.h" + +namespace Zint +{ + +class BareCode +{ +public: + +enum BorderType{NO_BORDER=0, BIND=1, BOX=2}; +enum AspectRatioMode{IgnoreAspectRatio=0, KeepAspectRatio=1, CenterBarCode=2}; + +public: + BareCode(); + ~BareCode(); + + void setSymbol(int symbol); + void setText(const QString & text); + void setPrimaryMessage(const QString & primaryMessage); + void setHeight(int height); + int height(); + void setBorder(BorderType border); + void setBorderWidth(int boderWidth); + void setWidth(int width); + int width(); + void setSecurityLevel(int securityLevel); + void setPdf417CodeWords(int pdf417CodeWords); + void setFgColor(const QColor & fgColor); + void setBgColor(const QColor & bgColor); + + void render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode=IgnoreAspectRatio, qreal scaleFactor=1); + + const QString & lastError(); + bool hasErrors(); + +private: + void encode(); + +private: + int m_symbol; + QString m_text; + QString m_primaryMessage; + int m_height; + BorderType m_border; + int m_boderWidth; + int m_width; + int m_securityLevel; + int m_pdf417CodeWords; + QColor m_fgColor; + QColor m_bgColor; + QString m_lastError; + zint_symbol * m_zintSymbol; +}; +} +#endif diff --git a/backend_qt4/compile_n_config b/backend_qt4/compile_n_config new file mode 100755 index 00000000..f2feb4c1 --- /dev/null +++ b/backend_qt4/compile_n_config @@ -0,0 +1,8 @@ +#!/bin/sh + +qmake -set ZINT_INSTALL_LIBS /usr/local/lib +qmake -set ZINT_INSTALL_HEADERS /usr/local/include + +qmake && make && make install + +ldconfig diff --git a/backend_qt4/readme b/backend_qt4/readme new file mode 100644 index 00000000..2ec3a7db --- /dev/null +++ b/backend_qt4/readme @@ -0,0 +1,9 @@ +Edit zint-1.6.pro and edit the 'DEFINES' section + NO_PNG -> compile zint without png support + NO_QR -> compile zint without QR support + QR_SYSTEM -> if you have QT installed in your system, zint will be compiled with QT support + QR -> compile zint with QR support static (you must have qrencode in the current folder) + +Edit compile_n_config and set the paths. + +Exec compile_n_config