summaryrefslogtreecommitdiffstats
path: root/kbarcode/barkode.h
blob: 9c4bfd925a18eeb41caf636513c9f299a8cf8914 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/* This file is part of the KDE project
   Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef BARKODE_H
#define BARKODE_H


#include <tqcolor.h>
#include <tqstring.h>

#include "barkodeengine.h"

/**
  * Enumeration values for sequence modes
  */
typedef enum { NUM, ALPHA, ALPHANUM } ESequence;

/** This values are used to indicate the feature supported by a 
  * certain barcode typedef
  */
enum { NOCUT = 0x00001, MULTILINE = 0x00002, NOTEXT = 0x00004, NOSCALE = 0x00008,
       /**
         * Different advanced option modes.
         */
       PDF417BARCODE = 0x00100, TBARCODEADV = 0x00200, PUREADV = 0x00400, DATAMATRIX = 0x00800, 
       COLORED = 0x00010,

       /**
         * Checksum ID's
         */
       POSTNETCHECK = 0x01000, CODE128CHECK = 0x02000, EAN8CHECK = 0x04000, EAN13CHECK = 0x08000,
       UPCACHECK = 0x10000, UPCECHECK = 0x20000, MODULOALLCHECK = 0x40000, MODULO10CHECK = 0x80000,

       /**
         * Short cut's
         */
       BARCODE2D =  NOCUT | MULTILINE | NOTEXT };

/** This structure holds information about a supported barcode encoding typedef
  */
typedef struct tBarcodeInfo 
{
    /** the name which is stored for identification in the xml file
      * and used as commandline parameter for external tools
      */
    TQString xml;
    /** the user visible name of this typedef
      */
    TQString name;
    /** the barcode engine to use
      */
    EEngine engine;
    /** features supported by this type orred together
      */
    unsigned int features;

    /** internal value (e.g. identifier of GNU Barcode)
      */
    int internal;

    /** A regular expression that validates
     *  a value for this barcode.
     */
    TQString validator;
    TQString validatorNot;
};

typedef TQValueList<tBarcodeInfo> TBarcodeInfoList;

class BarkodeEngine;
class TQPainter;
class TQPicture;
class TQSize;
class TQPaintDevice;
class TokenProvider;

class Barkode {
 public:
    Barkode();
    Barkode( const Barkode & barkode );
    virtual ~Barkode();

    /** set a TokenProvider for data field parsing
      */
    void setTokenProvider( TokenProvider* token );

    /** restore default values 
      */
    void defaults();

    /** call this method after you changed a property
      * to update the internal structures
      */
    void update( const TQPaintDevice* device );
    
    /** get the barcode value after all sequences and datafields have
      * been parsed
      */
    const TQString parsedValue();
 
    const TQPixmap pixmap( double scalex = 1.0, double scaley = 1.0 );
    const TQPicture picture();
    const TQSize size() const;
    bool isValid() const;

    const TQColor & background() const;
    const TQColor & foreground() const;
    const TQColor & textColor() const;
    const unsigned int fontsize() const;
    const unsigned int quietZone() const;
    const unsigned int barHeight() const;
    const TQString & type() const;
    const TQString & value() const;
    const bool sequenceEnabled() const;
    const ESequence sequenceMode() const;
    const int sequenceStart() const;
    const int sequenceStep() const;
    const TQString & databaseMode() const;
    const bool textVisible() const;
    const int rotation() const;
    const double scaling() const;
    const unsigned int index() const;
    const double cut() const;
    const int datamatrixSize() const;
    
    void setBackground( const TQColor & c );
    void setForeground( const TQColor & c );
    void setTextColor( const TQColor & c );
    void setFontsize ( unsigned int f );
    void setQuietZone( unsigned int q );
    void setBarHeight( unsigned int h );
    void setType( const TQString & type );
    void setValue( const TQString & value );
    void setTextVisible( const bool b );
    /** Set the index of the barcodes for barcode sequences.
      */
    void setIndex( unsigned int i );
    void setSequenceEnabled( bool b );
    void setSequenceMode( ESequence e );
    void setSequenceStart( int s );
    void setSequenceStep( int s );
    void setDatabaseMode( const TQString & mode );
    void setRotation( const int r );
    void setScaling( const double d );
    void setCut( const double c );
    void setDatamatrixSize( int s );
    
    /** Sets the barcodes data structures
      * the same as operator= 
      */
    void setData( const Barkode & barkode );
    void operator=( const Barkode & barkode );
    bool operator==( const Barkode & barkode ) const;

    inline BarkodeEngine* engine();
    inline const BarkodeEngine* engine() const;

    /** Test if the encodingType @p type has a certain 
      * @p feature, as defined in the codes TQValueList.
      */
    static bool hasFeature( const TQString & type, unsigned int feature );
    /** Returns the internal value for the encoding type @p typedef
      */
    static int internalType( const TQString & type );
    /** Returns all supported encoding types
      * ready for displaying them to the user
      */
    static const TQStringList* encodingTypes();
    /** Convert the uservisible encoding type @p name
      * to the internal identifier
      */
    static const char* typeFromName( const TQString & name );
    /** Convert the internal identifier @p type 
      * to the user visible encoding name
      */
    static const char* nameFromType( const TQString & type );

    static TQString* validatorFromType( const TQString & type );
    static TQString* validatorNotFromType( const TQString & type );

    /** return the barcode generation engine for type @p typedef
      */

    static EEngine engineForType( const TQString & type );
    /** Draw an invalid barcode sign to TQPainter @p painter
      */    
    void drawInvalid( TQPainter & painter, int x = 0, int y = 0 );
    
    /** returns whether barcode functionallity
      * is available
      */
    static bool haveBarcode() {
        Barkode::initInfo();
        return ( s_haveGnuBarcode || s_havePdfEncode || s_haveTBarcode || s_havePurePostscript );
    }
    static bool haveGNUBarcode() {
        Barkode::initInfo();
        return s_haveGnuBarcode;
    }
    static bool haveTBarcode() {
        Barkode::initInfo();
        return s_haveTBarcode;
    }
    static bool haveTBarcode2() {
        Barkode::initInfo();
        return s_haveTBarcode2;
    }
    static bool havePDFBarcode() {
        Barkode::initInfo();
        return s_havePdfEncode;
    }
    static bool havePurePostscriptBarcode() {
        Barkode::initInfo();
        return s_havePurePostscript;
    }

    static tBarcodeInfo createInfo( const char* xml, const TQString & name, const EEngine engine, 
                                    const unsigned int features = 0, const int internal = 0 );

 protected:
    void drawBarcode(  TQPainter & painter, int x = 0, int y = 0 );

 private:
    static void initInfo();
    static void initValidators();

    void updateEngine();

 protected:
    BarkodeEngine* m_engine;
    TokenProvider* m_token;

    bool m_valid;
    bool m_sequence;
    ESequence m_esequence;
    int m_sequence_start;
    int m_sequence_step;
    bool m_text_visible;
    
    TQColor m_background;
    TQColor m_foreground;
    TQColor m_textcolor;

    unsigned int m_quietzone;
    unsigned int m_bar_height;
    unsigned int m_fontsize;
    unsigned int m_index;
    int m_datamatrix_size;
    int m_rotation;
    
    double m_scaling;
    double m_cut; // temporarly used for the pixmap engines
                  // won't be needed for the Barkode engine
        
    TQString m_type;
    TQString m_value;
    TQString m_database_mode;
    
    static TBarcodeInfoList s_info;
    static TQStringList* s_encoding;

    static bool s_haveGnuBarcode;
    static bool s_haveTBarcode;
    static bool s_haveTBarcode2;
    static bool s_havePdfEncode;
    static bool s_havePurePostscript;
};

BarkodeEngine* Barkode::engine()
{
    return m_engine;
}

const BarkodeEngine* Barkode::engine() const
{
    return m_engine;
}

#endif // BARKODE_H