summaryrefslogtreecommitdiffstats
path: root/kbarcode/pixmapbarcode.h
blob: 1683cb1b2482b51df217c84b1a413c08dcb02b02 (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
/***************************************************************************
                         pixmapbarcode.cpp  -  description
                             -------------------
    begin                : Mon Nov 22 2004
    copyright            : (C) 2004 by Dominik Seichter
    email                : domseichter@web.de
 ***************************************************************************/

/***************************************************************************
                                                                          
    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 2 of the License, or     
    (at your option) any later version.                                   
                                                                          
 ***************************************************************************/

#ifndef PIXMAPBARCODE_H
#define PIXMAPBARCODE_H

#include "barkodeengine.h"
#include <tqpixmap.h>

class KTempFile;
class TQPainter;

class PDF417Options : public BarkodeEngineOptions {
    public:
        PDF417Options();

        const PDF417Options& operator=( const BarkodeEngineOptions& rhs );
        void defaults();

        void load( const TQDomElement* tag );
        void save( TQDomElement* tag );

        inline int row() const { return m_row; }
        inline int col() const { return m_col; }
        inline int err() const { return m_err; }
        
        inline void setRow( int r ) { m_row = r; }
        inline void setCol( int r ) { m_col = r; }
        inline void setErr( int r ) { m_err = r; }
        
    private:
        int m_row;
        int m_col;
        int m_err;
};

/**
  * A pixmap based barcode engine which 
  * uses different commandline tools to 
  * generate barcodes.
  * This class is a port of the old BarCode
  * class to the new Barkode interface.
  *
  * @author Dominik Seichter
  */
class PixmapBarcode : public BarkodeEngine
{
    public:
        PixmapBarcode();
        ~PixmapBarcode();

        const PixmapBarcode & operator=( const BarkodeEngine & rhs );

        inline EEngine engine() const;
        const TQSize size() const;
        void update( const TQPaintDevice* device );
        void drawBarcode( TQPainter & painter, int x, int y );

        inline BarkodeEngineOptions* options();
        
    private:
        bool createPixmap( TQPixmap* target, int resx, int resy );
        void createBarcode( TQPixmap* target, const TQPaintDevice* device );
        bool createPdf417( KTempFile* output );
        //TQString createTBarcodeCmd();

        virtual bool createPostscript( char** postscript, long* postscript_size );

        /** Mage sure the temporaray file @p file 
          * gets closed and deleted properly
          */
        void cleanUp( KTempFile* file, TQPixmap* target );
        /**
          * Cut the barcode either on the top or
          * on the bottom, depending on the text position.
          *g
          * @param pic the TQPixmap that will be cutted
          * @param cut a value between 0.0 and 1.0. If cut = 1.0
          *        then no cut will happen, if cut = 0.5, half of
          *        the barcode is going to be cutted away.
          */
        TQPixmap cut( TQPixmap* pic, double cut );
        
        /**
          * Add a margin to the TQPixmap pic.
          * @param pic the TQPixmap pic which should get a margin
          */
        TQPixmap addMargin( TQPixmap* pic );

    protected:
        /** Creates a pipe and read the data returned by the command into a buffer.
         *  \param command the command to execute
         *  \param buffer pointer to a buffer, will be malloc'ed and has to be free'd
         *  \param buffer_size pointer to a long where the size of the buffer will be stored
         *  \returns true if all data could be read sucessfully otherwise false.
         */
        bool readFromPipe( const char* command, char** buffer, long* buffer_size );

        /**
         *  \param postscript a postscript program
         *  \param postscript_size length of the postscript program
         *  \returns the BoundingBox of the postscript or EPS file
         *           so that it can be cropped correctly
         */
        virtual TQRect bbox( const char* postscript, long postscript_size );

    private:
        TQPixmap p;
        PDF417Options m_pdf417_options;
};

EEngine PixmapBarcode::engine() const
{
    return PIXMAP;
}

BarkodeEngineOptions* PixmapBarcode::options()
{
    return &m_pdf417_options;
}

#endif