OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
132 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.core.sales.pos.io;
15
 
16
import java.io.ByteArrayOutputStream;
17
 
18
public abstract class AbstractESCPrinter extends DefaultTicketPrinter {
19
    protected static final int GS = 0x1D;
20
    protected static final int ESC = 0x1B;
21
 
22
    public void addToBuffer(String t) {
23
        addToBuffer(t, NORMAL);
24
    }
25
 
26
    public void addToBuffer(String t, int mode) {
27
        this.strings.add(t);
28
        this.modes.add(mode);
29
    }
30
 
31
    protected byte[] getPrintBufferBytes() {
32
        final ByteArrayOutputStream bOut = new ByteArrayOutputStream();
33
        // Init
34
        bOut.write(ESC);
35
        bOut.write(0x40);
36
        // French characters
37
        bOut.write(ESC);
38
        bOut.write(0x52);
39
        bOut.write(0x01);
40
        //
41
 
42
        final int size = this.strings.size();
43
        for (int i = 0; i < size; i++) {
44
            String string = this.strings.get(i);
45
            int mode = modes.get(i);
46
 
47
            if (mode == BARCODE) {
48
                //
49
                bOut.write(GS);
50
                bOut.write(0x48);
51
                bOut.write(0x02); // en bas
52
 
53
                //
54
                bOut.write(GS);
55
                bOut.write(0x77);
56
                bOut.write(0x02); // Zoom 2
57
 
58
                //
59
                bOut.write(GS);
60
                bOut.write(0x68);
61
                bOut.write(60); // Hauteur
62
                // Code 39
63
                bOut.write(GS);
64
                bOut.write(0x6B);
65
                bOut.write(0x04); // Code 39
66
                for (int k = 0; k < string.length(); k++) {
67
                    char c = string.charAt(k);
68
 
69
                    bOut.write(c);
70
                }
71
                bOut.write(0x00); // End
72
            } else {
73
                if (mode == NORMAL) {
74
                    bOut.write(ESC);
75
                    bOut.write(0x21);
76
                    bOut.write(0);// Default
77
                } else if (mode == BOLD) {
78
                    bOut.write(ESC);
79
                    bOut.write(0x21);
80
                    bOut.write(8);// Emphasis
81
                } else if (mode == BOLD_LARGE) {
82
                    bOut.write(GS);
83
                    bOut.write(0x21);
84
                    bOut.write(0x11);//
85
                }
86
 
87
                for (int k = 0; k < string.length(); k++) {
88
                    char c = string.charAt(k);
89
                    if (c == 'é') {
90
                        c = 130;
91
                    } else if (c == 'è') {
92
                        c = 138;
93
                    } else if (c == 'ê') {
94
                        c = 136;
95
                    } else if (c == 'ù') {
96
                        c = 151;
97
                    } else if (c == 'à') {
98
                        c = 133;
99
                    } else if (c == 'ç') {
100
                        c = 135;
101
                    } else if (c == 'ô') {
102
                        c = 147;
103
                    }
104
                    bOut.write(c);
105
                }
106
            }
107
            bOut.write(0x0A);// Retour a la ligne
108
 
109
        }
110
        // Eject
111
        bOut.write(0x0A);
112
        bOut.write(0x0A);
113
        bOut.write(0x0A);
114
        bOut.write(0x0A);
115
        // Coupe
116
        bOut.write(GS);
117
        bOut.write(0x56); // V
118
        bOut.write(0x01);
119
        final byte[] byteArray = bOut.toByteArray();
120
        return byteArray;
121
    }
122
 
123
    @Override
124
    public abstract void printBuffer() throws Exception;
125
 
126
    @Override
127
    public abstract void openDrawer() throws Exception;
128
 
129
}