OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
181 ilm 1
/*
2
 * Copyright 2014 Robin Stuart
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
 * in compliance with the License. You may obtain a copy of the License at
6
 *
7
 * http://www.apache.org/licenses/LICENSE-2.0
8
 *
9
 * Unless required by applicable law or agreed to in writing, software distributed under the License
10
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
 * or implied. See the License for the specific language governing permissions and limitations under
12
 * the License.
13
 */
14
 
15
package uk.org.okapibarcode.backend;
16
 
17
import java.awt.geom.Rectangle2D;
18
 
19
/**
20
 * Implements the Two-Track Pharmacode bar code symbology. <br>
21
 * Pharmacode Two-Track is an alternative system to Pharmacode One-Track used for the identification
22
 * of pharmaceuticals. The symbology is able to encode whole numbers between 4 and 64570080.
23
 *
24
 * @author <a href="mailto:rstuart114@gmail.com">Robin Stuart</a>
25
 */
26
public class Pharmacode2Track extends Symbol {
27
 
28
    @Override
29
    protected void encode() {
30
        int i, tester = 0;
31
        String inter, dest;
32
 
33
        if (this.content.length() > 8) {
34
            throw new OkapiException("Input too long");
35
        }
36
 
37
        if (!this.content.matches("[0-9]+")) {
38
            throw new OkapiException("Invalid characters in data");
39
        }
40
 
41
        for (i = 0; i < this.content.length(); i++) {
42
            tester *= 10;
43
            tester += Character.getNumericValue(this.content.charAt(i));
44
        }
45
 
46
        if (tester < 4 || tester > 64570080) {
47
            throw new OkapiException("Data out of range");
48
        }
49
 
50
        inter = "";
51
        do {
52
            switch (tester % 3) {
53
            case 0:
54
                inter += "F";
55
                tester = (tester - 3) / 3;
56
                break;
57
            case 1:
58
                inter += "D";
59
                tester = (tester - 1) / 3;
60
                break;
61
            case 2:
62
                inter += "A";
63
                tester = (tester - 2) / 3;
64
                break;
65
            }
66
        } while (tester != 0);
67
 
68
        dest = "";
69
        for (i = inter.length() - 1; i >= 0; i--) {
70
            dest += inter.charAt(i);
71
        }
72
 
73
        infoLine("Encoding: " + dest);
74
 
75
        this.readable = "";
76
        this.pattern = new String[1];
77
        this.pattern[0] = dest;
78
        this.row_count = 1;
79
        this.row_height = new int[1];
80
        this.row_height[0] = -1;
81
    }
82
 
83
    @Override
84
    protected void plotSymbol() {
85
        int xBlock;
86
        int x, y, w, h;
87
 
88
        this.rectangles.clear();
89
        x = 0;
90
        w = 1;
91
        y = 0;
92
        h = 0;
93
        for (xBlock = 0; xBlock < this.pattern[0].length(); xBlock++) {
94
            switch (this.pattern[0].charAt(xBlock)) {
95
            case 'A':
96
                y = 0;
97
                h = this.default_height / 2;
98
                break;
99
            case 'D':
100
                y = this.default_height / 2;
101
                h = this.default_height / 2;
102
                break;
103
            case 'F':
104
                y = 0;
105
                h = this.default_height;
106
                break;
107
            }
108
 
109
            final Rectangle2D.Double rect = new Rectangle2D.Double(x, y, w, h);
110
            this.rectangles.add(rect);
111
 
112
            x += 2;
113
        }
114
        this.symbol_width = this.pattern[0].length() * 2;
115
        this.symbol_height = this.default_height;
116
    }
117
}