prison-1.2~git20150223/0000775000175000017500000000000012472636351012232 5ustar jrjrprison-1.2~git20150223/lib/0000775000175000017500000000000012472634140012772 5ustar jrjrprison-1.2~git20150223/lib/CMakeLists.txt0000664000175000017500000000205312472634140015532 0ustar jrjr set(PRISON_VERSION "1.2.0") set(CMAKECONFIG_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/KF5Prison") ecm_setup_version(${PRISON_VERSION} VARIABLE_PREFIX PRISON VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/prison_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5PrisonConfigVersion.cmake" SOVERSION 1 ) ecm_configure_package_config_file( "${prison_SOURCE_DIR}/lib/KF5PrisonConfig.cmake.in" "${prison_BINARY_DIR}/lib/KF5PrisonConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${prison_BINARY_DIR}/lib/KF5PrisonConfig.cmake" "${prison_BINARY_DIR}/lib/KF5PrisonConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KF5PrisonTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5PrisonTargets.cmake NAMESPACE KF5:: ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/prison_version.h DESTINATION ${KF5_INCLUDE_INSTALL_DIR} COMPONENT Devel ) add_subdirectory(prison) prison-1.2~git20150223/lib/KF5PrisonConfig.cmake.in0000664000175000017500000000011412472634140017303 0ustar jrjr@PACKAGE_INIT@ include("${CMAKE_CURRENT_LIST_DIR}/KF5PrisonTargets.cmake") prison-1.2~git20150223/lib/prison/0000775000175000017500000000000012472634140014304 5ustar jrjrprison-1.2~git20150223/lib/prison/abstractbarcode.h0000664000175000017500000001034412472634140017602 0ustar jrjr/* Copyright (c) 2010-2014 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef PRISON_ABSTRACTBARCODE_H #define PRISON_ABSTRACTBARCODE_H #include #include #include #include "prison_export.h" class QColor; class QPainter; namespace prison { /** * base class for barcode generators * To add your own barcode generator, subclass this class * and reimplement toImage(const QSizeF&) to do the actual * work of generating the barcode. * * The barcode is cached in AbstractBarcode when painting and * the size and the data doesn't change. Using the same AbstractBarcode * to paint on several surfaces, if they aren't of the exact same size * will break the caching */ class PRISON_EXPORT AbstractBarcode { public: /** * creates a barcode generator without any data */ AbstractBarcode(); virtual ~AbstractBarcode(); /** * @return the QString encoded in this barcode. */ QString data() const; /** * sets the data to be drawn by this function * calling this function does not do any repaints of anything, they are * your own responsibility. If you are using the barcodes thru BarcodeWidget or BarcodeItem, you * should rather use their setData function, as they handle the relevant updates. * @param data QString containing the data */ void setData(const QString& data); /** * Creates a image with a barcode on * @return QImage with a barcode on, trying to match the requested \param size * * The image function is cached and painted on demand. * * if one of the dimensions of @param size is smaller than the matching dimension in \ref minimumSize, * a null QImage will be returned */ QImage toImage(const QSizeF& size) ; /** * Note! minimalSize() doesn't work as expected if this is not painting on something. * @return the minimal size for this barcode. */ QSizeF minimumSize() const; /** * @return the foreground color (by default black) to be used for the barcode. */ const QColor& foregroundColor() const; /** * @return the background color (by default white) to be used for the barcode. */ const QColor& backgroundColor() const; /** * sets the foreground color * @param foregroundcolor - the new foreground color */ void setForegroundColor(const QColor& foregroundcolor); /** * sets the background color * @param backgroundcolor - the new background color */ void setBackgroundColor(const QColor& backgroundcolor); protected: /** * Sets the minimum size for this barcode. * Some barcodes have minimum sizes for when they are readable and such * @param minimumSize QSizeF holding the minimum size for this barcode */ void setMinimumSize(const QSizeF& minimumSize); /** * Doing the actual painting of the image * @param size requested size of the miage * @return image with barcode, or null image */ virtual QImage paintImage(const QSizeF& size) = 0; private: class Private; /** * d-pointer */ Private* d; }; } //namespace #endif // PRISON_ABSTRACTBARCODE_H prison-1.2~git20150223/lib/prison/datamatrixbarcode.cpp0000664000175000017500000000754112472634140020475 0ustar jrjr/* Copyright (c) 2010-2014 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "datamatrixbarcode.h" #include #include using namespace prison; /** * @cond PRIVATE */ class DataMatrixBarcode::Private { public: }; /** * @endcond */ DataMatrixBarcode::DataMatrixBarcode() : d(0) { } DataMatrixBarcode::~DataMatrixBarcode() { delete d; } QImage DataMatrixBarcode::paintImage(const QSizeF& size) { const int width = qRound(qMin(size.width(),size.height())); if(data().size()==0 || width == 0 || data().size() > 1200) { return QImage(); } DmtxEncode * enc = dmtxEncodeCreate(); dmtxEncodeSetProp( enc, DmtxPropPixelPacking, DmtxPack32bppRGBX ); dmtxEncodeSetProp( enc, DmtxPropWidth, width ); dmtxEncodeSetProp( enc, DmtxPropHeight, width ); QByteArray trimmedData(data().trimmed().toUtf8()); DmtxPassFail result = dmtxEncodeDataMatrix(enc, trimmedData.length(), reinterpret_cast(trimmedData.data())); if(result == DmtxFail) { dmtxEncodeDestroy(&enc); return QImage(); } Q_ASSERT(enc->image->width == enc->image->height); setMinimumSize(QSizeF(enc->image->width,enc->image->height)); QImage ret; if(foregroundColor()==Qt::black && backgroundColor() == Qt::white) { QImage tmp(enc->image->pxl,enc->image->width,enc->image->height, QImage::Format_ARGB32); //we need to copy, because QImage generated from a char pointer requires the //char pointer to be kept around forever, and manually deleted. ret=tmp.copy(); } else { if(enc->image->width>0) { int size = enc->image->width*enc->image->height*4; uchar* img = new uchar[size]; QByteArray background; background[3] = qAlpha(backgroundColor().rgba()); background[2] = qRed(backgroundColor().rgba()); background[1] = qGreen(backgroundColor().rgba()); background[0] = qBlue(backgroundColor().rgba()); QByteArray foreground = new char[4]; foreground[3] = qAlpha(foregroundColor().rgba()); foreground[2] = qRed(foregroundColor().rgba()); foreground[1] = qGreen(foregroundColor().rgba()); foreground[0] = qBlue(foregroundColor().rgba()); for(int i = 1 ; i < size; i+=4) { QByteArray color; if(enc->image->pxl[i]==0x00) { color = foreground; } else { color = background; } for(int j = 0 ; j < 4 ; j++) { img[i-1+j] = color[j]; } } QImage tmp(img,enc->image->width,enc->image->height, QImage::Format_ARGB32); //we need to copy, because QImage generated from a char pointer requires the //char pointer to be kept around forever, and manually deleted. ret=tmp.copy(); delete[] img; } } if(!ret.isNull() && ret.width() < width) { ret = ret.scaled(width,width); } dmtxEncodeDestroy(&enc); return ret; } prison-1.2~git20150223/lib/prison/code39barcode.h0000664000175000017500000000364312472634140017071 0ustar jrjr/* Copyright (c) 2011 Geoffry Song Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef PRISON_CODE39BARCODE_H #define PRISON_CODE39BARCODE_H #include "abstractbarcode.h" namespace prison { /** * Code 39 Barcode generator */ class PRISON_EXPORT Code39Barcode : public prison::AbstractBarcode { public: /** * creates a Code 39 generator */ Code39Barcode(); virtual ~Code39Barcode(); protected: /** * This function generates the barcode * @return QImage containing a barcode, trying to approximate the requested sizes, or a null QImage if it can't be painted within requested size * @param size */ virtual QImage paintImage(const QSizeF& size ) Q_DECL_OVERRIDE; private: class Private; Private *d; }; }; // namespace #endif // PRISON_CODE39BARCODE_H prison-1.2~git20150223/lib/prison/code39barcode.cpp0000664000175000017500000001450112472634140017417 0ustar jrjr/* Copyright (c) 2011 Geoffry Song Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "code39barcode.h" #include #include using namespace prison; /** @cond PRIVATE */ class Code39Barcode::Private { public: static QList barSequence(const char* str) { Q_ASSERT(strlen(str)==9); // this is a internal helper tool, only called with fixed strings in here, all 9 chars long QList ret; for(int i = 0 ; i < 9 ; i++) { ret.append(str[i] == '1'); Q_ASSERT(str[i] == '0' || str[i] == '1'); } return ret; } static QList sequenceForChar(ushort c) { switch(QChar::toUpper(c)) { case '0': return barSequence("000110100"); case '1': return barSequence("100100001"); case '2': return barSequence("001100001"); case '3': return barSequence("101100000"); case '4': return barSequence("000110001"); case '5': return barSequence("100110000"); case '6': return barSequence("001110000"); case '7': return barSequence("000100101"); case '8': return barSequence("100100100"); case '9': return barSequence("001100100"); case 'A': return barSequence("100001001"); case 'B': return barSequence("001001001"); case 'C': return barSequence("101001000"); case 'D': return barSequence("000011001"); case 'E': return barSequence("100011000"); case 'F': return barSequence("001011000"); case 'G': return barSequence("000001101"); case 'H': return barSequence("100001100"); case 'I': return barSequence("001001100"); case 'J': return barSequence("000011100"); case 'K': return barSequence("100000011"); case 'L': return barSequence("001000011"); case 'M': return barSequence("101000010"); case 'N': return barSequence("000010011"); case 'O': return barSequence("100010010"); case 'P': return barSequence("001010010"); case 'Q': return barSequence("000000111"); case 'R': return barSequence("100000110"); case 'S': return barSequence("001000110"); case 'T': return barSequence("000010110"); case 'U': return barSequence("110000001"); case 'V': return barSequence("011000001"); case 'W': return barSequence("111000000"); case 'X': return barSequence("010010001"); case 'Y': return barSequence("110010000"); case 'Z': return barSequence("011010000"); case '-': return barSequence("010000101"); case '.': return barSequence("110000100"); case ' ': return barSequence("011000100"); case '$': return barSequence("010101000"); case '/': return barSequence("010100010"); case '+': return barSequence("010001010"); case '%': return barSequence("000101010"); default: return QList(); // unknown character } } }; /** @endcond */ Code39Barcode::Code39Barcode() : AbstractBarcode(), d(0){ } Code39Barcode::~Code39Barcode() { delete d; } QImage Code39Barcode::paintImage(const QSizeF& size) { if(size.height() == 0) return QImage(); QList barcode; // convert text into sequences of wide/narrow bars { // the guard sequence that goes on each end const QList endSequence = Private::barSequence("010010100"); barcode += endSequence; barcode += false; // translate the string const QString str = data(); for(int i = 0 ; i < str.size(); i++) { QList b = Private::sequenceForChar(str.at(i).unicode()); if(!b.empty()) { barcode += b; barcode += false; // add a narrow space between each character } } // ending guard barcode += endSequence; } /* calculate integer bar widths that fit inside `size' each character has 6 narrow bars and 3 wide bars and there is a narrow bar between characters restrictions: *) smallWidth * 2 <= largeWidth <= smallWidth * 3 - in other words, the ratio largeWidth:smallWidth is between 3:1 and 2:1 *) wide * largeWidth + narrow * smallWidth <= size.width() - the barcode has to fit within the given size */ const int w = size.width(); const int wide = barcode.count(true); const int narrow = barcode.count(false); // maximize wide bar width int largeWidth = 2*w / (2*wide + narrow); // then maximize narrow bar width int smallWidth = (w - largeWidth*wide) / narrow; // if the requested size was too small return a null image if(largeWidth<2) { return QImage(); } if(smallWidth<1) { return QImage(); } Q_ASSERT(largeWidth > smallWidth); // one line of the result image QVector line; line.reserve(wide * largeWidth + narrow * smallWidth); for(int i = 0 ; i < barcode.size() ; i++) { const QRgb color = (((i&1) == 0) ? foregroundColor() : backgroundColor()).rgba(); // alternate between foreground and background color const int width = barcode.at(i) ? largeWidth : smallWidth; for(int j = 0 ; j < width ; j++) { line.append(color); } } // build the complete barcode QImage ret(line.size(), size.height(), QImage::Format_ARGB32); // just repeat the line to make the image for(int y = 0 ; y < ret.height() ; y++) { memcpy(ret.scanLine(y), line.data(), line.size() * sizeof(QRgb)); } return ret; } prison-1.2~git20150223/lib/prison/code93barcode.cpp0000664000175000017500000003015212472634140017417 0ustar jrjr/* Copyright (c) 2011 Geoffry Song Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "code93barcode.h" #include #include using namespace prison; /** @cond PRIVATE */ class Code93Barcode::Private { public: static QList barSequence(const char* str) { Q_ASSERT(strlen(str)==9); // this is a internal helper tool, only called with fixed strings in here, all 9 chars long QList ret; for(int i = 0 ; i < 9 ; i++) { ret.append(str[i] == '1'); Q_ASSERT(str[i] == '0' || str[i] == '1'); } return ret; } // returns a list of 9 bar colors, where `true' means foreground and `false' means background color static QList sequenceForID(int id) { switch(id) { case 0: return barSequence("100010100"); // 0-9 case 1: return barSequence("101001000"); case 2: return barSequence("101000100"); case 3: return barSequence("101000010"); case 4: return barSequence("100101000"); case 5: return barSequence("100100100"); case 6: return barSequence("100100010"); case 7: return barSequence("101010000"); case 8: return barSequence("100010010"); case 9: return barSequence("100001010"); case 10: return barSequence("110101000"); // A-Z case 11: return barSequence("110100100"); case 12: return barSequence("110100010"); case 13: return barSequence("110010100"); case 14: return barSequence("110010010"); case 15: return barSequence("110001010"); case 16: return barSequence("101101000"); case 17: return barSequence("101100100"); case 18: return barSequence("101100010"); case 19: return barSequence("100110100"); case 20: return barSequence("100011010"); case 21: return barSequence("101011000"); case 22: return barSequence("101001100"); case 23: return barSequence("101000110"); case 24: return barSequence("100101100"); case 25: return barSequence("100010110"); case 26: return barSequence("110110100"); case 27: return barSequence("110110010"); case 28: return barSequence("110101100"); case 29: return barSequence("110100110"); case 30: return barSequence("110010110"); case 31: return barSequence("110011010"); case 32: return barSequence("101101100"); case 33: return barSequence("101100110"); case 34: return barSequence("100110110"); case 35: return barSequence("100111010"); case 36: return barSequence("100101110"); // - case 37: return barSequence("111010100"); // . case 38: return barSequence("111010010"); // space case 39: return barSequence("111001010"); // $ case 40: return barSequence("101101110"); // / case 41: return barSequence("101110110"); // + case 42: return barSequence("110101110"); // $ case 43: return barSequence("100100110"); // ($) case 44: return barSequence("111011010"); // (%) case 45: return barSequence("111010110"); // (/) case 46: return barSequence("100110010"); // (+) case 47: return barSequence("101011110"); // stop sequence default: // unknown ID... shouldn't happen qWarning("Code93Barcode::sequenceForID called with unknown ID"); return QList(); } } // returns the list of IDs that represent a character static QList codesForChar(uint c) { QList ret; switch(c) { case 0: ret += 44; ret += 30; break; case 1: ret += 43; ret += 10; break; case 2: ret += 43; ret += 11; break; case 3: ret += 43; ret += 12; break; case 4: ret += 43; ret += 13; break; case 5: ret += 43; ret += 14; break; case 6: ret += 43; ret += 15; break; case 7: ret += 43; ret += 16; break; case 8: ret += 43; ret += 17; break; case 9: ret += 43; ret += 18; break; case 10: ret += 43; ret += 19; break; case 11: ret += 43; ret += 20; break; case 12: ret += 43; ret += 21; break; case 13: ret += 43; ret += 22; break; case 14: ret += 43; ret += 23; break; case 15: ret += 43; ret += 24; break; case 16: ret += 43; ret += 25; break; case 17: ret += 43; ret += 26; break; case 18: ret += 43; ret += 27; break; case 19: ret += 43; ret += 28; break; case 20: ret += 43; ret += 29; break; case 21: ret += 43; ret += 30; break; case 22: ret += 43; ret += 31; break; case 23: ret += 43; ret += 32; break; case 24: ret += 43; ret += 33; break; case 25: ret += 43; ret += 34; break; case 26: ret += 43; ret += 35; break; case 27: ret += 44; ret += 10; break; case 28: ret += 44; ret += 11; break; case 29: ret += 44; ret += 12; break; case 30: ret += 44; ret += 13; break; case 31: ret += 44; ret += 14; break; case 32: ret += 38; break; case 33: ret += 45; ret += 10; break; case 34: ret += 45; ret += 11; break; case 35: ret += 45; ret += 12; break; case 36: ret += 39; break; case 37: ret += 42; break; case 38: ret += 45; ret += 15; break; case 39: ret += 45; ret += 16; break; case 40: ret += 45; ret += 17; break; case 41: ret += 45; ret += 18; break; case 42: ret += 45; ret += 19; break; case 43: ret += 41; break; case 44: ret += 45; ret += 21; break; case 45: ret += 36; break; case 46: ret += 37; break; case 47: ret += 40; break; case 48: ret += 0; break; case 49: ret += 1; break; case 50: ret += 2; break; case 51: ret += 3; break; case 52: ret += 4; break; case 53: ret += 5; break; case 54: ret += 6; break; case 55: ret += 7; break; case 56: ret += 8; break; case 57: ret += 9; break; case 58: ret += 45; ret += 35; break; case 59: ret += 44; ret += 15; break; case 60: ret += 44; ret += 16; break; case 61: ret += 44; ret += 17; break; case 62: ret += 44; ret += 18; break; case 63: ret += 44; ret += 19; break; case 64: ret += 44; ret += 31; break; case 65: ret += 10; break; case 66: ret += 11; break; case 67: ret += 12; break; case 68: ret += 13; break; case 69: ret += 14; break; case 70: ret += 15; break; case 71: ret += 16; break; case 72: ret += 17; break; case 73: ret += 18; break; case 74: ret += 19; break; case 75: ret += 20; break; case 76: ret += 21; break; case 77: ret += 22; break; case 78: ret += 23; break; case 79: ret += 24; break; case 80: ret += 25; break; case 81: ret += 26; break; case 82: ret += 27; break; case 83: ret += 28; break; case 84: ret += 29; break; case 85: ret += 30; break; case 86: ret += 31; break; case 87: ret += 32; break; case 88: ret += 33; break; case 89: ret += 34; break; case 90: ret += 35; break; case 91: ret += 44; ret += 20; break; case 92: ret += 44; ret += 21; break; case 93: ret += 44; ret += 22; break; case 94: ret += 44; ret += 23; break; case 95: ret += 44; ret += 24; break; case 96: ret += 44; ret += 32; break; case 97: ret += 46; ret += 10; break; case 98: ret += 46; ret += 11; break; case 99: ret += 46; ret += 12; break; case 100: ret += 46; ret += 13; break; case 101: ret += 46; ret += 14; break; case 102: ret += 46; ret += 15; break; case 103: ret += 46; ret += 16; break; case 104: ret += 46; ret += 17; break; case 105: ret += 46; ret += 18; break; case 106: ret += 46; ret += 19; break; case 107: ret += 46; ret += 20; break; case 108: ret += 46; ret += 21; break; case 109: ret += 46; ret += 22; break; case 110: ret += 46; ret += 23; break; case 111: ret += 46; ret += 24; break; case 112: ret += 46; ret += 25; break; case 113: ret += 46; ret += 26; break; case 114: ret += 46; ret += 27; break; case 115: ret += 46; ret += 28; break; case 116: ret += 46; ret += 29; break; case 117: ret += 46; ret += 30; break; case 118: ret += 46; ret += 31; break; case 119: ret += 46; ret += 32; break; case 120: ret += 46; ret += 33; break; case 121: ret += 46; ret += 34; break; case 122: ret += 46; ret += 35; break; case 123: ret += 44; ret += 25; break; case 124: ret += 44; ret += 26; break; case 125: ret += 44; ret += 27; break; case 126: ret += 44; ret += 28; break; case 127: ret += 44; ret += 29; break; } return ret; // return an empty list for a non-ascii character code } // calculate a checksum static int checksum(QList codes, int wrap) { int check = 0; for(int i = 0 ; i < codes.size() ; i++) { // weight goes from 1 to wrap, right-to-left, then repeats const int weight = (codes.size() - i - 1) % wrap + 1; check += codes.at(i) * weight; } return check % 47; } }; /** @endcond */ Code93Barcode::Code93Barcode() : AbstractBarcode(), d(0){ } Code93Barcode::~Code93Barcode() { delete d; } QImage Code93Barcode::paintImage(const QSizeF& size) { if(size.height() == 0) { return QImage(); } QList barcode; // convert text into sequences of fg/bg bars { // translate the string into a code sequence QList codes; const QString str = data(); for(int i = 0 ; i < str.size() ; i++) { codes += Private::codesForChar(str.at(i).unicode()); } // calculate checksums codes.append(Private::checksum(codes, 20)); // "C" checksum codes.append(Private::checksum(codes, 15)); // "K" checksum: includes previous checksum // now generate the barcode // the guard sequence that goes on each end const QList endSequence = Private::sequenceForID(47); barcode += endSequence; // translate codes into bars for(int i = 0 ; i < codes.size() ; i++) { barcode += Private::sequenceForID(codes.at(i)); } // ending guard barcode += endSequence; // termination bar barcode += true; } // try to fill the requested size const int barWidth = int(size.width() / barcode.size()); if(barWidth < 1 ) { // can't go below 1 pixel return QImage(); } // build one line of the result image QVector line; line.reserve(barWidth * barcode.size()); for(int i = 0 ; i < barcode.size() ; i++) { const QRgb color = (barcode.at(i) ? foregroundColor() : backgroundColor()).rgba(); for(int j = 0 ; j < barWidth ; j++) { line.append(color); } } // build the complete barcode QImage ret(line.size(), size.height(), QImage::Format_ARGB32); // just repeat the line to make the image for(int y = 0 ; y < ret.height() ; y++) { memcpy(ret.scanLine(y), line.data(), line.size() * sizeof(QRgb)); } return ret; } prison-1.2~git20150223/lib/prison/qrcodebarcode.h0000664000175000017500000000401412472634140017251 0ustar jrjr/* Copyright (c) 2010-2014 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef PRISON_QRCODEBARCODE_H #define PRISON_QRCODEBARCODE_H #include "abstractbarcode.h" namespace prison { /** * QRCode Barcode generator ; uses libqrencode to do the actual encoding * of the barcode. */ class PRISON_EXPORT QRCodeBarcode : public prison::AbstractBarcode { public: /** * creates a QRCode generator */ QRCodeBarcode(); virtual ~QRCodeBarcode(); /** * This is the function doing the actual work in generating the barcode * @return QImage containing a QRCode, trying to approximate the requested sizes * @param size The requested size of the barcode, approximate. if the barcode generator can't get the data to fit in there, it might be a null QImage */ virtual QImage paintImage(const QSizeF& size) Q_DECL_OVERRIDE; private: class Private; Private *d; }; } // namespace #endif // PRISON_QRCODEBARCODE_H prison-1.2~git20150223/lib/prison/datamatrixbarcode.h0000664000175000017500000000374612472634140020145 0ustar jrjr/* Copyright (c) 2010-2014 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef PRISON_DATAMATRIXBARCODE_H #define PRISON_DATAMATRIXBARCODE_H #include "abstractbarcode.h" #include "prison_export.h" namespace prison { /** * This is a Datamatrix barcode generator that uses libdmtx * for the actual generation of barcodes. */ class PRISON_EXPORT DataMatrixBarcode : public prison::AbstractBarcode { public: /** * creates a datamatrixbarcode generator */ DataMatrixBarcode(); virtual ~DataMatrixBarcode(); protected: /** * This is the function doing the actual work in generating the barcode * @return QImage containing a DataMatrix, trying to approximate the requested sizes */ virtual QImage paintImage(const QSizeF& size) Q_DECL_OVERRIDE; private: class Private; Private *d; }; } #endif // PRISON_DATAMATRIXBARCODE_H prison-1.2~git20150223/lib/prison/CMakeLists.txt0000664000175000017500000000302012472634140017037 0ustar jrjrinclude(CMakePackageConfigHelpers) include_directories(${QRENCODE_INCLUDE_DIR} ${DMTX_INCLUDE_DIR}) SET( prison_SRCS abstractbarcode.cpp code39barcode.cpp code93barcode.cpp datamatrixbarcode.cpp qrcodebarcode.cpp ) add_library(KF5Prison ${prison_SRCS}) generate_export_header(KF5Prison BASE_NAME prison) add_library(KF5::Prison ALIAS KF5Prison) target_include_directories(KF5Prison INTERFACE "$") target_link_libraries(KF5Prison PUBLIC Qt5::Gui PRIVATE ${DMTX_LIBRARIES} ${QRENCODE_LIBRARIES} ) set_target_properties(KF5Prison PROPERTIES VERSION ${PRISON_VERSION_STRING} SOVERSION ${PRISON_SOVERSION} EXPORT_NAME Prison ) install(TARGETS KF5Prison EXPORT KF5PrisonTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) ecm_generate_headers(Prison_CamelCase_HEADERS HEADER_NAMES AbstractBarcode Code39Barcode Code93Barcode DataMatrixBarcode QRCodeBarcode PREFIX PRISON/ REQUIRED_HEADERS Prison_HEADERS ) install(FILES ${Prison_CamelCase_HEADERS} DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/PRISON/prison COMPONENT Devel) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/prison_export.h ${Prison_HEADERS} DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/PRISON/prison COMPONENT Devel ) ecm_generate_pri_file(BASE_NAME Prison LIB_NAME KF5Prison DEPS "Qt5::Gui" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KF5_INCLUDE_INSTALL_DIR}/PRISON) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) prison-1.2~git20150223/lib/prison/qrcodebarcode.cpp0000664000175000017500000000705012472634140017607 0ustar jrjr/* Copyright (c) 2010-2014 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "qrcodebarcode.h" #include #include using namespace prison; /** @cond PRIVATE */ class QRCodeBarcode::Private { public: }; /** @endcond */ QRCodeBarcode::QRCodeBarcode() : AbstractBarcode(), d(0){ } QRCodeBarcode::~QRCodeBarcode() { delete d; } QImage QRCodeBarcode::paintImage(const QSizeF& size) { const int width = qRound(qMin(size.width(),size.height())); if(data().size()==0 || width==0) { return QImage(); } const QByteArray trimmedData(data().trimmed().toUtf8()); QRcode* code = QRcode_encodeString8bit(trimmedData.constData(), 0, QR_ECLEVEL_Q); if(!code) { return QImage(); } const int margin = 2; /*32 bit colors, 8 bit pr byte*/ uchar* img = new uchar[4 *sizeof(char*)*(2*margin + code->width)*(2*margin* + code->width)]; uchar* p = img; QByteArray background; background[3] = qAlpha(backgroundColor().rgba()); background[2] = qRed(backgroundColor().rgba()); background[1] = qGreen(backgroundColor().rgba()); background[0] = qBlue(backgroundColor().rgba()); QByteArray foreground; foreground[3] = qAlpha(foregroundColor().rgba()); foreground[2] = qRed(foregroundColor().rgba()); foreground[1] = qGreen(foregroundColor().rgba()); foreground[0] = qBlue(foregroundColor().rgba()); for(int row = 0 ; row < code->width+2*margin ; row++) { for(int col = 0 ; col < code->width+2*margin ; col++) { if(row < margin || row >= (code->width+margin) || col < margin || col >= (code->width+margin)) { /*4 bytes for color*/ for(int i =0 ; i<4 ; i++) { *p = background[i]; p++; } } else { int c= (row-margin)*code->width + (col-margin); /*it is bit 1 that is the interesting bit for us from libqrencode*/ if(code->data[c] & 1) { /*4 bytes for color*/ for(int i =0 ; i<4 ; i++) { *p = foreground[i]; p++; } } else { /*4 bytes for color*/ for(int i =0 ; i<4 ; i++) { *p = background[i]; p++; } } } } } QImage tmp(img,code->width+2*margin,code->width+2*margin,QImage::Format_ARGB32); setMinimumSize(QSizeF(tmp.width()*4,tmp.height()*4)); QImage ret = tmp.convertToFormat(QImage::Format_ARGB32).scaled(qMax(tmp.width()*4,width),qMax(tmp.height()*4,width)); //4 is determined by trial and error. delete[] img; QRcode_free(code); return ret; } prison-1.2~git20150223/lib/prison/abstractbarcode.cpp0000664000175000017500000000650012472634140020134 0ustar jrjr/* Copyright (c) 2010-2014 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "abstractbarcode.h" #include #include #include using namespace prison; /** * @cond private */ class AbstractBarcode::Private { public: QString m_data; QSizeF m_size; QImage m_cache; QColor m_foreground; QColor m_background; QSizeF m_minimum_size; AbstractBarcode* q; bool sizeTooSmall(const QSizeF& size) { if(m_minimum_size.width() > size.width()) { return true; } else if(m_minimum_size.height() > size.height()) { return true; } return false; } Private(AbstractBarcode* barcode) : m_foreground(Qt::black), m_background(Qt::white), m_minimum_size(10,10), q(barcode) { } }; /** * @endcond */ AbstractBarcode::AbstractBarcode() : d(new AbstractBarcode::Private(this)) { } QString AbstractBarcode::data() const { return d->m_data; } QImage AbstractBarcode::toImage(const QSizeF& size) { if(d->sizeTooSmall(size)) { d->m_cache = QImage(); return QImage(); } if(d->m_cache.isNull() || size != d->m_size) { d->m_size = size; d->m_cache = paintImage(size); return d->m_cache; } return d->m_cache; } void AbstractBarcode::setData(const QString& data) { d->m_data=data; d->m_cache=QImage(); } QSizeF AbstractBarcode::minimumSize() const { return d->m_minimum_size; } void AbstractBarcode::setMinimumSize(const QSizeF& minimumSize) { d->m_minimum_size = minimumSize; if(minimumSize.width() > d->m_size.width() || minimumSize.height() > d->m_size.height()) { d->m_cache = QImage(); } } const QColor& AbstractBarcode::backgroundColor() const { return d->m_background; } const QColor& AbstractBarcode::foregroundColor() const { return d->m_foreground; } void AbstractBarcode::setBackgroundColor(const QColor& backgroundcolor) { if(backgroundcolor!=backgroundColor()) { d->m_background=backgroundcolor; d->m_cache=QImage(); } } void AbstractBarcode::setForegroundColor(const QColor& foregroundcolor) { if(foregroundcolor!=foregroundColor()) { d->m_foreground=foregroundcolor; d->m_cache=QImage(); } } AbstractBarcode::~AbstractBarcode() { delete d; } prison-1.2~git20150223/lib/prison/code93barcode.h0000664000175000017500000000363212472634140017067 0ustar jrjr/* Copyright (c) 2011 Geoffry Song Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef PRISON_CODE93BARCODE_H #define PRISON_CODE93BARCODE_H #include "abstractbarcode.h" namespace prison { /** * Code 93 Barcode generator */ class PRISON_EXPORT Code93Barcode : public prison::AbstractBarcode { public: /** * creates a Code 93 generator */ Code93Barcode(); virtual ~Code93Barcode(); /** * This function generates the barcode * @return QImage containing a barcode, trying to approximate the requested sizes * @param size The requested size of the barcode, approximate. if the barcode generator can't generate it, it can return a null QImage */ virtual QImage paintImage(const QSizeF& size) Q_DECL_OVERRIDE; private: class Private; Private *d; }; }; // namespace #endif // PRISON_CODE39BARCODE_H prison-1.2~git20150223/tools/0000775000175000017500000000000012472634140013364 5ustar jrjrprison-1.2~git20150223/tools/prison-datamatrix.cpp0000664000175000017500000000452212472634140017541 0ustar jrjr#include #include #include #include #include #include #include void error(const QString& error, const QString& errormessage) { QTextStream str(stdout); str << error << ": " << errormessage << endl; exit(0); } int main(int argc, char* argv[]) { QCoreApplication app(argc,argv); QString size; QString outputfile; QString outputformat; QStringList arguments = app.arguments(); QString appname = arguments.takeFirst(); while(!arguments.isEmpty()) { QString argument = arguments.takeFirst(); if(argument==QLatin1String("--")) { break; //rest is data } else if(argument==QLatin1String("--size")||argument==QLatin1String("-s")) { size=arguments.takeFirst(); } else if(argument==QLatin1String("--outputfile") || argument==QLatin1String("--output-file") || argument==QLatin1String("-o")) { outputfile = arguments.takeFirst(); } else if(argument==QLatin1String("--output-format") || argument==QLatin1String("--output-format") || argument==QLatin1String("-f")) { outputformat = arguments.takeFirst(); } else if(argument.startsWith(QLatin1String("-"))) { error(QLatin1String("unknown argument"),argument); } else { break; } } if(outputformat.isEmpty()) { outputformat=QLatin1String("png"); } if(!QImageWriter::supportedImageFormats().contains(outputformat.toLocal8Bit())) { error(QLatin1String("unsupported output format"), outputformat); } if(outputfile.isEmpty()) { error(QLatin1String("outputfile is missing"),QString()); } bool ok=false; int intsize = size.toInt(&ok); if(!ok) { error(QLatin1String("size not a int"),size); } if(intsize < 10) { error(QLatin1String("needs a larger output size"),size); } QString data = arguments.join(QLatin1String(" ")); if(data.size()==0) { QTextStream in(stdin); data = in.readAll(); if(data.size()==0) { error(QLatin1String("No data, neither on commandline nor on stdin"),QString()); } } prison::DataMatrixBarcode barcode; barcode.setData(data); QImage result = barcode.toImage(QSizeF(intsize,intsize)); QImageWriter w(outputfile,outputformat.toLocal8Bit()); if(!w.write(result)) { error(QLatin1String("writing failed"),w.errorString()); } } prison-1.2~git20150223/tools/CMakeLists.txt0000664000175000017500000000015612472634140016126 0ustar jrjr add_executable(prison-datamatrix prison-datamatrix.cpp) target_link_libraries(prison-datamatrix KF5::Prison) prison-1.2~git20150223/cmake/0000775000175000017500000000000012472633673013316 5ustar jrjrprison-1.2~git20150223/cmake/modules/0000775000175000017500000000000012472634140014754 5ustar jrjrprison-1.2~git20150223/cmake/modules/FindQRencode.cmake0000664000175000017500000000210612472633673020270 0ustar jrjr# - Try to find the qrencode library # Once done this will define # # QRENCODE_FOUND - system has the qrencode library # QRENCODE_INCLUDE_DIR - the qrencode library include dir # QRENCODE_LIBRARIES - the libraries used to link qrencode # Copyright (C) 2010 Sune Vuorela # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (QRENCODE_INCLUDE_DIR AND QRENCODE_LIBRARIES) # in cache already set(QRENCODE_FOUND TRUE) else (QRENCODE_INCLUDE_DIR AND QRENCODE_LIBRARIES) find_path(QRENCODE_INCLUDE_DIR qrencode.h) find_library(QRENCODE_LIBRARIES NAMES qrencode) if (QRENCODE_INCLUDE_DIR AND QRENCODE_LIBRARIES) set(QRENCODE_FOUND TRUE) else (QRENCODE_INCLUDE_DIR AND QRENCODE_LIBRARIES) message("QRencode library not found, please see http://megaui.net/fukuchi/works/qrencode/index.en.html") endif (QRENCODE_INCLUDE_DIR AND QRENCODE_LIBRARIES) mark_as_advanced(QRENCODE_INCLUDE_DIR QRENCODE_LIBRARIES) endif (QRENCODE_INCLUDE_DIR AND QRENCODE_LIBRARIES) prison-1.2~git20150223/cmake/modules/FindDmtx.cmake0000664000175000017500000000171612472633673017512 0ustar jrjr# - Try to find the dmtx library # Once done this will define # # DMTX_FOUND - system has the datamatrix library # DMTX_INCLUDE_DIR - the datamatrix library include dir # DMTX_LIBRARIES - the libraries used to link datamatrix # Copyright (C) 2010 Sune Vuorela # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (DMTX_INCLUDE_DIR AND DMTX_LIBRARIES) # in cache already set(DTMX_FOUND TRUE) else (DMTX_INCLUDE_DIR AND DMTX_LIBRARIES) find_path(DMTX_INCLUDE_DIR dmtx.h) find_library(DMTX_LIBRARIES NAMES dmtx) if (DMTX_INCLUDE_DIR AND DMTX_LIBRARIES) set(DMTX_FOUND TRUE) else (DMTX_INCLUDE_DIR AND DMTX_LIBRARIES) message("Datamatrix library not found, please see http://www.libdmtx.org") endif (DMTX_INCLUDE_DIR AND DMTX_LIBRARIES) mark_as_advanced(DMTX_INCLUDE_DIR DMTX_LIBRARIES) endif (DMTX_INCLUDE_DIR AND DMTX_LIBRARIES) prison-1.2~git20150223/cmake/modules/COPYING-CMAKE-SCRIPTS0000664000175000017500000000245712472633673017774 0ustar jrjrRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. prison-1.2~git20150223/CMakeLists.txt0000664000175000017500000000173712472634140014774 0ustar jrjrproject(prison) cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") find_package(QRencode REQUIRED) find_package(Dmtx REQUIRED) find_package(ECM 1.2.0 CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) include(GenerateExportHeader) include(ECMGenerateHeaders) include(ECMGeneratePriFile) include(ECMPackageConfigHelpers) include(ECMSetupVersion) include(FeatureSummary) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings) set(QT_REQUIRED_VERSION "5.2.0") find_package(Qt5Core ${QT_REQUIRED_VERSION} CONFIG REQUIRED) find_package(Qt5Gui ${QT_REQUIRED_VERSION} CONFIG REQUIRED) find_package(Qt5Test ${QT_REQUIRED_VERSION} CONFIG REQUIRED) if (Qt5_POSITION_INDEPENDENT_CODE) set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif() add_subdirectory(lib) add_subdirectory(testapp) add_subdirectory(tools) prison-1.2~git20150223/LICENSE0000664000175000017500000000220312472634140013226 0ustar jrjr Copyright (c) 2010-2014 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. prison-1.2~git20150223/Mainpage.dox0000664000175000017500000000311312472633673014471 0ustar jrjr/** * \mainpage prison Prison barcode library * * %prison is a Qt-based barcode abstraction layer/library and provides uniform access * to generation of barcodes with data. * * \section overview Overview * * %prison has a prison::AbstractBarcode, which is the base class for the actual barcode generators, currently prison::QRCodeBarcode * and prison::DataMatrixBarcode is the two implemented barcode generators. * * %prison currently ships a BarcodeWidget, which is a QWidget with a barcode painted upon, as well as a BarcodeItem, which is a * QGraphicsItem with a barcode painted upon. * * \section supported Supported Barcode types * * There is basically two types of barcodes: * \li barcodes that carries the data * \li barcodes that carries a lookup number, and requires a specific server to look up the actual data. * * %prison isn't as such designed for the latter, it will probably work, but patches implementing barcode * support for such barcodes will not be accepted. A example is EZCode. * * %prison is currently using libdmtx for generation of DataMatrix barcodes * * %prison is currently using libqrencode for generation of QRCode barcodes * */ // DOXYGEN_NAME=Prison // DOXYGEN_COPYRIGHT=2010-2011 Sune Vuorela // DOXYGEN_EXCLUDE = testapp prison-1.2~git20150223/.gitignore0000664000175000017500000000000312472633673014217 0ustar jrjr*~ prison-1.2~git20150223/testapp/0000775000175000017500000000000012472634140013704 5ustar jrjrprison-1.2~git20150223/testapp/prison.h0000664000175000017500000000113312472634140015365 0ustar jrjr#ifndef prison_H #define prison_H #include class BarcodeExampleWidget; class QLineEdit; class main_window : public QWidget { Q_OBJECT public: main_window(); public Q_SLOTS: void data_changed(); private: QLineEdit* m_lineedit; BarcodeExampleWidget* m_dmw; BarcodeExampleWidget* m_qrw; BarcodeExampleWidget* m_39w; BarcodeExampleWidget* m_93w; BarcodeExampleWidget* m_dmcolor; BarcodeExampleWidget* m_qrcolor; BarcodeExampleWidget* m_39color; BarcodeExampleWidget* m_93color; BarcodeExampleWidget* m_nullw; }; #endif // prison_H prison-1.2~git20150223/testapp/main.cpp0000664000175000017500000000026012472633673015344 0ustar jrjr#include #include "prison.h" int main(int argc, char** argv) { QApplication app(argc, argv); main_window foo; foo.show(); return app.exec(); } prison-1.2~git20150223/testapp/CMakeLists.txt0000664000175000017500000000031312472634140016441 0ustar jrjr find_package(Qt5 COMPONENTS Widgets) set(prison_SRCS prison.cpp barcodeexamplewidget.cpp main.cpp) add_executable(test-prison ${prison_SRCS}) target_link_libraries(test-prison Qt5::Widgets KF5::Prison) prison-1.2~git20150223/testapp/barcodeexamplewidget.h0000664000175000017500000000476212472634140020245 0ustar jrjr/* Copyright (c) 2010-2014 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef PRISON_BARCODEWIDGET_H #define PRISON_BARCODEWIDGET_H #include namespace prison { class AbstractBarcode; } /** * QWidget with a barcode on */ class BarcodeExampleWidget : public QWidget { public: /** * Creates a barcode widget with 'barcode' as barcode generator * @param barcode The barcode generator for this widget. Takes ownership over the barcode generator * @param parent the parent in QWidget hierachy */ BarcodeExampleWidget(prison::AbstractBarcode* barcode, QWidget* parent=0); virtual ~BarcodeExampleWidget(); /** * sets the data shown to data, and triggers a repaint and resize if needed * @param data QString holding the data to be shown */ void setData(const QString &data); /** * Reimplementation * @return minimumSizeHint for this widget */ virtual QSize minimumSizeHint() const; protected: /** * paintEvent * @param event QPaintEvent */ virtual void paintEvent(QPaintEvent* event ); /** * resizeEvent * @param event QResizeEvent */ virtual void resizeEvent(QResizeEvent* event ); /** * enables drag from the barcodewidget * @param event QMouseEvent */ virtual void mousePressEvent(QMouseEvent* event); private: prison::AbstractBarcode* m_barcode; }; #endif // PRISON_BARCODEWIDGET_H prison-1.2~git20150223/testapp/prison.cpp0000664000175000017500000000525112472634140015725 0ustar jrjr#include "prison.h" #include #include #include #include #include #include #include #include #include "barcodeexamplewidget.h" void main_window::data_changed() { QString result = m_lineedit->text(); m_dmw->setData(result); m_qrw->setData(result); m_39w->setData(result); m_93w->setData(result); m_nullw->setData(result); m_dmcolor->setData(result); m_qrcolor->setData(result); m_39color->setData(result); m_93color->setData(result); } main_window::main_window() { QHBoxLayout* lay = new QHBoxLayout(); m_lineedit = new QLineEdit(this); QPushButton* but = new QPushButton(this); connect(but, &QPushButton::clicked, this, &main_window::data_changed); lay->addWidget(m_lineedit); lay->addWidget(but); QVBoxLayout* mainlay = new QVBoxLayout(); m_dmw = new BarcodeExampleWidget(new prison::DataMatrixBarcode(),this); m_qrw = new BarcodeExampleWidget(new prison::QRCodeBarcode(),this); m_39w = new BarcodeExampleWidget(new prison::Code39Barcode(),this); m_93w = new BarcodeExampleWidget(new prison::Code93Barcode(),this); { prison::DataMatrixBarcode* dmcolorcode = new prison::DataMatrixBarcode(); dmcolorcode->setForegroundColor(Qt::red); dmcolorcode->setBackgroundColor(Qt::darkBlue); m_dmcolor = new BarcodeExampleWidget(dmcolorcode,this); } { prison::QRCodeBarcode* qrcolorcode = new prison::QRCodeBarcode(); qrcolorcode->setForegroundColor(Qt::red); qrcolorcode->setBackgroundColor(Qt::darkBlue); m_qrcolor = new BarcodeExampleWidget(qrcolorcode,this); } { prison::Code39Barcode* c39colorcode = new prison::Code39Barcode(); c39colorcode->setForegroundColor(Qt::red); c39colorcode->setBackgroundColor(Qt::darkBlue); m_39color = new BarcodeExampleWidget(c39colorcode,this); } { prison::Code93Barcode* c93colorcode = new prison::Code93Barcode(); c93colorcode->setForegroundColor(Qt::red); c93colorcode->setBackgroundColor(Qt::darkBlue); m_93color = new BarcodeExampleWidget(c93colorcode,this); } m_nullw = new BarcodeExampleWidget(0,this); QSplitter* splitter = new QSplitter(Qt::Vertical); splitter->addWidget(m_dmw); splitter->addWidget(m_qrw); splitter->addWidget(m_39w); splitter->addWidget(m_93w); splitter->addWidget(m_dmcolor); splitter->addWidget(m_qrcolor); splitter->addWidget(m_39color); splitter->addWidget(m_93color); splitter->addWidget(m_nullw); mainlay->addLayout(lay); mainlay->addWidget(splitter); setLayout(mainlay); m_lineedit->setText(QLatin1String("AOEUIAOEUIAOEUI")); data_changed(); } prison-1.2~git20150223/testapp/barcodeexamplewidget.cpp0000664000175000017500000000614212472634140020572 0ustar jrjr/* Copyright (c) 2010-2014 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "barcodeexamplewidget.h" #include "prison/abstractbarcode.h" #include #include #include #include using namespace prison; BarcodeExampleWidget::BarcodeExampleWidget(AbstractBarcode* barcode, QWidget* parent): QWidget(parent), m_barcode(barcode) { } void BarcodeExampleWidget::setData(const QString &data) { if(m_barcode) m_barcode->setData(data); updateGeometry(); repaint(); } void BarcodeExampleWidget::paintEvent(QPaintEvent* event) { QPainter painter(this); if(m_barcode) { QRect targetrect = rect(); QImage image = m_barcode->toImage(targetrect.size()); if (!image.isNull()) { QRectF rect(targetrect.left() + targetrect.width() /2 - image.size().width() /2, targetrect.top() + targetrect.height()/2 - image.size().height()/2, targetrect.size().width(), targetrect.height()); painter.drawImage(rect.topLeft(), image, image.rect()); } else { painter.fillRect(QRectF(QPointF(0,0),size()),Qt::cyan); } } else { painter.fillRect(QRectF(QPointF(0,0),size()),Qt::black); } QWidget::paintEvent(event); } void BarcodeExampleWidget::resizeEvent(QResizeEvent* event) { if(m_barcode) { updateGeometry(); repaint(); } QWidget::resizeEvent(event); } void BarcodeExampleWidget::mousePressEvent(QMouseEvent* event) { if(m_barcode && event->buttons() & Qt::LeftButton) { QMimeData* data = new QMimeData(); data->setImageData(m_barcode->toImage(rect().size())); QDrag* drag = new QDrag(this); drag->setMimeData(data); drag->exec(); } else { QWidget::mousePressEvent(event); } } QSize BarcodeExampleWidget::minimumSizeHint() const { if(m_barcode) { return m_barcode->minimumSize().toSize(); } else { return QWidget::minimumSizeHint(); } } BarcodeExampleWidget::~BarcodeExampleWidget() { delete m_barcode; }