Barcode39.java

1
/*
2
 * $Id: Barcode39.java 4065 2009-09-16 23:09:11Z psoares33 $
3
 *
4
 * Copyright 2002-2006 by Paulo Soares.
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * (the "License"); you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the License.
13
 *
14
 * The Original Code is 'iText, a free JAVA-PDF library'.
15
 *
16
 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
17
 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
18
 * All Rights Reserved.
19
 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
20
 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
21
 *
22
 * Contributor(s): all the names of the contributors are added in the source code
23
 * where applicable.
24
 *
25
 * Alternatively, the contents of this file may be used under the terms of the
26
 * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
27
 * provisions of LGPL are applicable instead of those above.  If you wish to
28
 * allow use of your version of this file only under the terms of the LGPL
29
 * License and not to allow others to use your version of this file under
30
 * the MPL, indicate your decision by deleting the provisions above and
31
 * replace them with the notice and other provisions required by the LGPL.
32
 * If you do not delete the provisions above, a recipient may use your version
33
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
34
 *
35
 * This library is free software; you can redistribute it and/or modify it
36
 * under the terms of the MPL as stated above or under the terms of the GNU
37
 * Library General Public License as published by the Free Software Foundation;
38
 * either version 2 of the License, or any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful, but WITHOUT
41
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
42
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
43
 * details.
44
 *
45
 * If you didn't download this code from the following link, you should check if
46
 * you aren't using an obsolete version:
47
 * http://www.lowagie.com/iText/
48
 */
49
package com.lowagie.text.pdf;
50
51
import java.awt.Canvas;
52
import java.awt.Color;
53
import java.awt.Image;
54
import java.awt.image.MemoryImageSource;
55
import com.lowagie.text.error_messages.MessageLocalization;
56
57
import com.lowagie.text.Element;
58
59
import com.lowagie.text.Rectangle;
60
import com.lowagie.text.ExceptionConverter;
61
62
/** Implements the code 39 and code 39 extended. The default parameters are:
63
 * <pre>
64
 *x = 0.8f;
65
 *n = 2;
66
 *font = BaseFont.createFont("Helvetica", "winansi", false);
67
 *size = 8;
68
 *baseline = size;
69
 *barHeight = size * 3;
70
 *textAlignment = Element.ALIGN_CENTER;
71
 *generateChecksum = false;
72
 *checksumText = false;
73
 *startStopText = true;
74
 *extended = false;
75
 * </pre>
76
 *
77
 * @author Paulo Soares (psoares@consiste.pt)
78
 */
79
public class Barcode39 extends Barcode{
80
81
    /**
82
     * The bars to generate the code.
83
     */
84
    private static final byte[][] BARS =
85
            {
86
                    {0, 0, 0, 1, 1, 0, 1, 0, 0},
87
                    {1, 0, 0, 1, 0, 0, 0, 0, 1},
88
                    {0, 0, 1, 1, 0, 0, 0, 0, 1},
89
                    {1, 0, 1, 1, 0, 0, 0, 0, 0},
90
                    {0, 0, 0, 1, 1, 0, 0, 0, 1},
91
                    {1, 0, 0, 1, 1, 0, 0, 0, 0},
92
                    {0, 0, 1, 1, 1, 0, 0, 0, 0},
93
                    {0, 0, 0, 1, 0, 0, 1, 0, 1},
94
                    {1, 0, 0, 1, 0, 0, 1, 0, 0},
95
                    {0, 0, 1, 1, 0, 0, 1, 0, 0},
96
                    {1, 0, 0, 0, 0, 1, 0, 0, 1},
97
                    {0, 0, 1, 0, 0, 1, 0, 0, 1},
98
                    {1, 0, 1, 0, 0, 1, 0, 0, 0},
99
                    {0, 0, 0, 0, 1, 1, 0, 0, 1},
100
                    {1, 0, 0, 0, 1, 1, 0, 0, 0},
101
                    {0, 0, 1, 0, 1, 1, 0, 0, 0},
102
                    {0, 0, 0, 0, 0, 1, 1, 0, 1},
103
                    {1, 0, 0, 0, 0, 1, 1, 0, 0},
104
                    {0, 0, 1, 0, 0, 1, 1, 0, 0},
105
                    {0, 0, 0, 0, 1, 1, 1, 0, 0},
106
                    {1, 0, 0, 0, 0, 0, 0, 1, 1},
107
                    {0, 0, 1, 0, 0, 0, 0, 1, 1},
108
                    {1, 0, 1, 0, 0, 0, 0, 1, 0},
109
                    {0, 0, 0, 0, 1, 0, 0, 1, 1},
110
                    {1, 0, 0, 0, 1, 0, 0, 1, 0},
111
                    {0, 0, 1, 0, 1, 0, 0, 1, 0},
112
                    {0, 0, 0, 0, 0, 0, 1, 1, 1},
113
                    {1, 0, 0, 0, 0, 0, 1, 1, 0},
114
                    {0, 0, 1, 0, 0, 0, 1, 1, 0},
115
                    {0, 0, 0, 0, 1, 0, 1, 1, 0},
116
                    {1, 1, 0, 0, 0, 0, 0, 0, 1},
117
                    {0, 1, 1, 0, 0, 0, 0, 0, 1},
118
                    {1, 1, 1, 0, 0, 0, 0, 0, 0},
119
                    {0, 1, 0, 0, 1, 0, 0, 0, 1},
120
                    {1, 1, 0, 0, 1, 0, 0, 0, 0},
121
                    {0, 1, 1, 0, 1, 0, 0, 0, 0},
122
                    {0, 1, 0, 0, 0, 0, 1, 0, 1},
123
                    {1, 1, 0, 0, 0, 0, 1, 0, 0},
124
                    {0, 1, 1, 0, 0, 0, 1, 0, 0},
125
                    {0, 1, 0, 1, 0, 1, 0, 0, 0},
126
                    {0, 1, 0, 1, 0, 0, 0, 1, 0},
127
                    {0, 1, 0, 0, 0, 1, 0, 1, 0},
128
                    {0, 0, 0, 1, 0, 1, 0, 1, 0},
129
                    {0, 1, 0, 0, 1, 0, 1, 0, 0}
130
            };
131
 
132
    /** The index chars to <CODE>BARS</CODE>.
133
     */    
134
    private static final String CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*";
135
    
136
    /** The character combinations to make the code 39 extended.
137
     */    
138
    private static final String EXTENDED = "%U" +
139
        "$A$B$C$D$E$F$G$H$I$J$K$L$M$N$O$P$Q$R$S$T$U$V$W$X$Y$Z" +
140
        "%A%B%C%D%E  /A/B/C/D/E/F/G/H/I/J/K/L - ./O" +
141
        " 0 1 2 3 4 5 6 7 8 9/Z%F%G%H%I%J%V" +
142
        " A B C D E F G H I J K L M N O P Q R S T U V W X Y Z" +
143
        "%K%L%M%N%O%W" +
144
        "+A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P+Q+R+S+T+U+V+W+X+Y+Z" +
145
        "%P%Q%R%S%T";
146
        
147
    /** Creates a new Barcode39.
148
     */    
149
    public Barcode39() {
150
        try {
151
            x = 0.8f;
152
            n = 2;
153
            font = BaseFont.createFont("Helvetica", "winansi", false);
154
            size = 8;
155
            baseline = size;
156 1 1. : Replaced float multiplication with division → NO_COVERAGE
            barHeight = size * 3;
157
            textAlignment = Element.ALIGN_CENTER;
158
            generateChecksum = false;
159
            checksumText = false;
160
            startStopText = true;
161
            extended = false;
162
        }
163
        catch (Exception e) {
164
            throw new ExceptionConverter(e);
165
        }
166
    }
167
    
168
    /** Creates the bars.
169
     * @param text the text to create the bars. This text does not include the start and
170
     * stop characters
171
     * @return the bars
172
     */    
173
    public static byte[] getBarsCode39(String text) {
174
        text = "*" + text + "*";
175 2 1. getBarsCode39 : Replaced integer multiplication with division → NO_COVERAGE
2. getBarsCode39 : Replaced integer subtraction with addition → NO_COVERAGE
        byte[] bars = new byte[text.length() * 10 - 1];
176 3 1. getBarsCode39 : changed conditional boundary → NO_COVERAGE
2. getBarsCode39 : Changed increment from 1 to -1 → NO_COVERAGE
3. getBarsCode39 : negated conditional → NO_COVERAGE
        for (int k = 0; k < text.length(); ++k) {
177
            int idx = CHARS.indexOf(text.charAt(k));
178 2 1. getBarsCode39 : changed conditional boundary → NO_COVERAGE
2. getBarsCode39 : negated conditional → NO_COVERAGE
            if (idx < 0)
179
                throw new IllegalArgumentException(MessageLocalization.getComposedMessage("the.character.1.is.illegal.in.code.39", text.charAt(k)));
180 2 1. getBarsCode39 : Replaced integer multiplication with division → NO_COVERAGE
2. getBarsCode39 : removed call to java/lang/System::arraycopy → NO_COVERAGE
            System.arraycopy(BARS[idx], 0, bars, k * 10, 9);
181
        }
182 1 1. getBarsCode39 : mutated return of Object value for com/lowagie/text/pdf/Barcode39::getBarsCode39 to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return bars;
183
    }
184
    
185
    /** Converts the extended text into a normal, escaped text,
186
     * ready to generate bars.
187
     * @param text the extended text
188
     * @return the escaped text
189
     */    
190
    public static String getCode39Ex(String text) {
191
        String out = "";
192 3 1. getCode39Ex : changed conditional boundary → NO_COVERAGE
2. getCode39Ex : Changed increment from 1 to -1 → NO_COVERAGE
3. getCode39Ex : negated conditional → NO_COVERAGE
        for (int k = 0; k < text.length(); ++k) {
193
            char c = text.charAt(k);
194 2 1. getCode39Ex : changed conditional boundary → NO_COVERAGE
2. getCode39Ex : negated conditional → NO_COVERAGE
            if (c > 127)
195
                throw new IllegalArgumentException(MessageLocalization.getComposedMessage("the.character.1.is.illegal.in.code.39.extended", c));
196 1 1. getCode39Ex : Replaced integer multiplication with division → NO_COVERAGE
            char c1 = EXTENDED.charAt(c * 2);
197 2 1. getCode39Ex : Replaced integer multiplication with division → NO_COVERAGE
2. getCode39Ex : Replaced integer addition with subtraction → NO_COVERAGE
            char c2 = EXTENDED.charAt(c * 2 + 1);
198 1 1. getCode39Ex : negated conditional → NO_COVERAGE
            if (c1 != ' ')
199
                out += c1;
200
            out += c2;
201
        }
202 1 1. getCode39Ex : mutated return of Object value for com/lowagie/text/pdf/Barcode39::getCode39Ex to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return out;
203
    }
204
    
205
    /** Calculates the checksum.
206
     * @param text the text
207
     * @return the checksum
208
     */    
209
    static char getChecksum(String text) {
210
        int chk = 0;
211 3 1. getChecksum : changed conditional boundary → NO_COVERAGE
2. getChecksum : Changed increment from 1 to -1 → NO_COVERAGE
3. getChecksum : negated conditional → NO_COVERAGE
        for (int k = 0; k < text.length(); ++k) {
212
            int idx = CHARS.indexOf(text.charAt(k));
213 2 1. getChecksum : changed conditional boundary → NO_COVERAGE
2. getChecksum : negated conditional → NO_COVERAGE
            if (idx < 0)
214
                throw new IllegalArgumentException(MessageLocalization.getComposedMessage("the.character.1.is.illegal.in.code.39", text.charAt(k)));
215 1 1. getChecksum : Replaced integer addition with subtraction → NO_COVERAGE
            chk += idx;
216
        }
217 2 1. getChecksum : Replaced integer modulus with multiplication → NO_COVERAGE
2. getChecksum : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return CHARS.charAt(chk % 43);
218
    }
219
    
220
    /** Gets the maximum area that the barcode and the text, if
221
     * any, will occupy. The lower left corner is always (0, 0).
222
     * @return the size the barcode occupies.
223
     */    
224
    public Rectangle getBarcodeSize() {
225
        float fontX = 0;
226
        float fontY = 0;
227
        String fCode = code;
228 1 1. getBarcodeSize : negated conditional → NO_COVERAGE
        if (extended)
229
            fCode = getCode39Ex(code);
230 1 1. getBarcodeSize : negated conditional → NO_COVERAGE
        if (font != null) {
231 2 1. getBarcodeSize : changed conditional boundary → NO_COVERAGE
2. getBarcodeSize : negated conditional → NO_COVERAGE
            if (baseline > 0)
232 1 1. getBarcodeSize : Replaced float subtraction with addition → NO_COVERAGE
                fontY = baseline - font.getFontDescriptor(BaseFont.DESCENT, size);
233
            else
234 2 1. getBarcodeSize : removed negation → NO_COVERAGE
2. getBarcodeSize : Replaced float addition with subtraction → NO_COVERAGE
                fontY = -baseline + size;
235
            String fullCode = code;
236 2 1. getBarcodeSize : negated conditional → NO_COVERAGE
2. getBarcodeSize : negated conditional → NO_COVERAGE
            if (generateChecksum && checksumText)
237
                fullCode += getChecksum(fCode);
238 1 1. getBarcodeSize : negated conditional → NO_COVERAGE
            if (startStopText)
239
                fullCode = "*" + fullCode + "*";
240 1 1. getBarcodeSize : negated conditional → NO_COVERAGE
            fontX = font.getWidthPoint(altText != null ? altText : fullCode, size);
241
        }
242 1 1. getBarcodeSize : Replaced integer addition with subtraction → NO_COVERAGE
        int len = fCode.length() + 2;
243 1 1. getBarcodeSize : negated conditional → NO_COVERAGE
        if (generateChecksum)
244 1 1. getBarcodeSize : Changed increment from 1 to -1 → NO_COVERAGE
            ++len;
245 8 1. getBarcodeSize : Replaced float multiplication with division → NO_COVERAGE
2. getBarcodeSize : Replaced float multiplication with division → NO_COVERAGE
3. getBarcodeSize : Replaced float multiplication with division → NO_COVERAGE
4. getBarcodeSize : Replaced float addition with subtraction → NO_COVERAGE
5. getBarcodeSize : Replaced float multiplication with division → NO_COVERAGE
6. getBarcodeSize : Replaced integer subtraction with addition → NO_COVERAGE
7. getBarcodeSize : Replaced float multiplication with division → NO_COVERAGE
8. getBarcodeSize : Replaced float addition with subtraction → NO_COVERAGE
        float fullWidth = len * (6 * x + 3 * x * n) + (len - 1) * x;
246
        fullWidth = Math.max(fullWidth, fontX);
247 1 1. getBarcodeSize : Replaced float addition with subtraction → NO_COVERAGE
        float fullHeight = barHeight + fontY;
248 1 1. getBarcodeSize : mutated return of Object value for com/lowagie/text/pdf/Barcode39::getBarcodeSize to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return new Rectangle(fullWidth, fullHeight);
249
    }
250
    
251
    /** Places the barcode in a <CODE>PdfContentByte</CODE>. The
252
     * barcode is always placed at coordinates (0, 0). Use the
253
     * translation matrix to move it elsewhere.<p>
254
     * The bars and text are written in the following colors:<p>
255
     * <P><TABLE BORDER=1>
256
     * <TR>
257
     *    <TH><P><CODE>barColor</CODE></TH>
258
     *    <TH><P><CODE>textColor</CODE></TH>
259
     *    <TH><P>Result</TH>
260
     *    </TR>
261
     * <TR>
262
     *    <TD><P><CODE>null</CODE></TD>
263
     *    <TD><P><CODE>null</CODE></TD>
264
     *    <TD><P>bars and text painted with current fill color</TD>
265
     *    </TR>
266
     * <TR>
267
     *    <TD><P><CODE>barColor</CODE></TD>
268
     *    <TD><P><CODE>null</CODE></TD>
269
     *    <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
270
     *    </TR>
271
     * <TR>
272
     *    <TD><P><CODE>null</CODE></TD>
273
     *    <TD><P><CODE>textColor</CODE></TD>
274
     *    <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
275
     *    </TR>
276
     * <TR>
277
     *    <TD><P><CODE>barColor</CODE></TD>
278
     *    <TD><P><CODE>textColor</CODE></TD>
279
     *    <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
280
     *    </TR>
281
     * </TABLE>
282
     * @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
283
     * @param barColor the color of the bars. It can be <CODE>null</CODE>
284
     * @param textColor the color of the text. It can be <CODE>null</CODE>
285
     * @return the dimensions the barcode occupies
286
     */    
287
    public Rectangle placeBarcode(PdfContentByte cb, Color barColor, Color textColor) {
288
        String fullCode = code;
289
        float fontX = 0;
290
        String bCode = code;
291 1 1. placeBarcode : negated conditional → NO_COVERAGE
        if (extended)
292
            bCode = getCode39Ex(code);
293 1 1. placeBarcode : negated conditional → NO_COVERAGE
        if (font != null) {
294 2 1. placeBarcode : negated conditional → NO_COVERAGE
2. placeBarcode : negated conditional → NO_COVERAGE
            if (generateChecksum && checksumText)
295
                fullCode += getChecksum(bCode);
296 1 1. placeBarcode : negated conditional → NO_COVERAGE
            if (startStopText)
297
                fullCode = "*" + fullCode + "*";
298 1 1. placeBarcode : negated conditional → NO_COVERAGE
            fontX = font.getWidthPoint(fullCode = altText != null ? altText : fullCode, size);
299
        }
300 1 1. placeBarcode : negated conditional → NO_COVERAGE
        if (generateChecksum)
301
            bCode += getChecksum(bCode);
302 1 1. placeBarcode : Replaced integer addition with subtraction → NO_COVERAGE
        int len = bCode.length() + 2;
303 8 1. placeBarcode : Replaced float multiplication with division → NO_COVERAGE
2. placeBarcode : Replaced float multiplication with division → NO_COVERAGE
3. placeBarcode : Replaced float multiplication with division → NO_COVERAGE
4. placeBarcode : Replaced float addition with subtraction → NO_COVERAGE
5. placeBarcode : Replaced float multiplication with division → NO_COVERAGE
6. placeBarcode : Replaced integer subtraction with addition → NO_COVERAGE
7. placeBarcode : Replaced float multiplication with division → NO_COVERAGE
8. placeBarcode : Replaced float addition with subtraction → NO_COVERAGE
        float fullWidth = len * (6 * x + 3 * x * n) + (len - 1) * x;
304
        float barStartX = 0;
305
        float textStartX = 0;
306
        switch (textAlignment) {
307
            case Element.ALIGN_LEFT:
308
                break;
309
            case Element.ALIGN_RIGHT:
310 2 1. placeBarcode : changed conditional boundary → NO_COVERAGE
2. placeBarcode : negated conditional → NO_COVERAGE
                if (fontX > fullWidth)
311 1 1. placeBarcode : Replaced float subtraction with addition → NO_COVERAGE
                    barStartX = fontX - fullWidth;
312
                else
313 1 1. placeBarcode : Replaced float subtraction with addition → NO_COVERAGE
                    textStartX = fullWidth - fontX;
314
                break;
315
            default:
316 2 1. placeBarcode : changed conditional boundary → NO_COVERAGE
2. placeBarcode : negated conditional → NO_COVERAGE
                if (fontX > fullWidth)
317 2 1. placeBarcode : Replaced float subtraction with addition → NO_COVERAGE
2. placeBarcode : Replaced float division with multiplication → NO_COVERAGE
                    barStartX = (fontX - fullWidth) / 2;
318
                else
319 2 1. placeBarcode : Replaced float subtraction with addition → NO_COVERAGE
2. placeBarcode : Replaced float division with multiplication → NO_COVERAGE
                    textStartX = (fullWidth - fontX) / 2;
320
                break;
321
        }
322
        float barStartY = 0;
323
        float textStartY = 0;
324 1 1. placeBarcode : negated conditional → NO_COVERAGE
        if (font != null) {
325 2 1. placeBarcode : changed conditional boundary → NO_COVERAGE
2. placeBarcode : negated conditional → NO_COVERAGE
            if (baseline <= 0)
326 1 1. placeBarcode : Replaced float subtraction with addition → NO_COVERAGE
                textStartY = barHeight - baseline;
327
            else {
328 1 1. placeBarcode : removed negation → NO_COVERAGE
                textStartY = -font.getFontDescriptor(BaseFont.DESCENT, size);
329 1 1. placeBarcode : Replaced float addition with subtraction → NO_COVERAGE
                barStartY = textStartY + baseline;
330
            }
331
        }
332
        byte[] bars = getBarsCode39(bCode);
333
        boolean print = true;
334 1 1. placeBarcode : negated conditional → NO_COVERAGE
        if (barColor != null)
335 1 1. placeBarcode : removed call to com/lowagie/text/pdf/PdfContentByte::setColorFill → NO_COVERAGE
            cb.setColorFill(barColor);
336
        for (byte bar : bars) {
337 2 1. placeBarcode : Replaced float multiplication with division → NO_COVERAGE
2. placeBarcode : negated conditional → NO_COVERAGE
            float w = (bar == 0 ? x : x * n);
338 1 1. placeBarcode : negated conditional → NO_COVERAGE
            if (print)
339 2 1. placeBarcode : Replaced float subtraction with addition → NO_COVERAGE
2. placeBarcode : removed call to com/lowagie/text/pdf/PdfContentByte::rectangle → NO_COVERAGE
                cb.rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
340 1 1. placeBarcode : negated conditional → NO_COVERAGE
            print = !print;
341 1 1. placeBarcode : Replaced float addition with subtraction → NO_COVERAGE
            barStartX += w;
342
        }
343 1 1. placeBarcode : removed call to com/lowagie/text/pdf/PdfContentByte::fill → NO_COVERAGE
        cb.fill();
344 1 1. placeBarcode : negated conditional → NO_COVERAGE
        if (font != null) {
345 1 1. placeBarcode : negated conditional → NO_COVERAGE
            if (textColor != null)
346 1 1. placeBarcode : removed call to com/lowagie/text/pdf/PdfContentByte::setColorFill → NO_COVERAGE
                cb.setColorFill(textColor);
347 1 1. placeBarcode : removed call to com/lowagie/text/pdf/PdfContentByte::beginText → NO_COVERAGE
            cb.beginText();
348 1 1. placeBarcode : removed call to com/lowagie/text/pdf/PdfContentByte::setFontAndSize → NO_COVERAGE
            cb.setFontAndSize(font, size);
349 1 1. placeBarcode : removed call to com/lowagie/text/pdf/PdfContentByte::setTextMatrix → NO_COVERAGE
            cb.setTextMatrix(textStartX, textStartY);
350 1 1. placeBarcode : removed call to com/lowagie/text/pdf/PdfContentByte::showText → NO_COVERAGE
            cb.showText(fullCode);
351 1 1. placeBarcode : removed call to com/lowagie/text/pdf/PdfContentByte::endText → NO_COVERAGE
            cb.endText();
352
        }
353 1 1. placeBarcode : mutated return of Object value for com/lowagie/text/pdf/Barcode39::placeBarcode to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getBarcodeSize();
354
    }
355
    
356
    /** Creates a <CODE>java.awt.Image</CODE>. This image only
357
     * contains the bars without any text.
358
     * @param foreground the color of the bars
359
     * @param background the color of the background
360
     * @return the image
361
     */    
362
    public java.awt.Image createAwtImage(Color foreground, Color background) {
363
        int f = foreground.getRGB();
364
        int g = background.getRGB();
365
        Canvas canvas = new Canvas();
366
367
        String bCode = code;
368 1 1. createAwtImage : negated conditional → NO_COVERAGE
        if (extended)
369
            bCode = getCode39Ex(code);
370 1 1. createAwtImage : negated conditional → NO_COVERAGE
        if (generateChecksum)
371
            bCode += getChecksum(bCode);
372 1 1. createAwtImage : Replaced integer addition with subtraction → NO_COVERAGE
        int len = bCode.length() + 2;
373
        int nn = (int)n;
374 5 1. createAwtImage : Replaced integer multiplication with division → NO_COVERAGE
2. createAwtImage : Replaced integer addition with subtraction → NO_COVERAGE
3. createAwtImage : Replaced integer multiplication with division → NO_COVERAGE
4. createAwtImage : Replaced integer subtraction with addition → NO_COVERAGE
5. createAwtImage : Replaced integer addition with subtraction → NO_COVERAGE
        int fullWidth = len * (6 + 3 * nn) + (len - 1);
375
        byte[] bars = getBarsCode39(bCode);
376
        boolean print = true;
377
        int ptr = 0;
378
        int height = (int)barHeight;
379 1 1. createAwtImage : Replaced integer multiplication with division → NO_COVERAGE
        int[] pix = new int[fullWidth * height];
380
        for (byte bar : bars) {
381 1 1. createAwtImage : negated conditional → NO_COVERAGE
            int w = (bar == 0 ? 1 : nn);
382
            int c = g;
383 1 1. createAwtImage : negated conditional → NO_COVERAGE
            if (print)
384
                c = f;
385 1 1. createAwtImage : negated conditional → NO_COVERAGE
            print = !print;
386 3 1. createAwtImage : changed conditional boundary → NO_COVERAGE
2. createAwtImage : Changed increment from 1 to -1 → NO_COVERAGE
3. createAwtImage : negated conditional → NO_COVERAGE
            for (int j = 0; j < w; ++j)
387 1 1. createAwtImage : Changed increment from 1 to -1 → NO_COVERAGE
                pix[ptr++] = c;
388
        }
389 3 1. createAwtImage : changed conditional boundary → NO_COVERAGE
2. createAwtImage : Replaced integer addition with subtraction → NO_COVERAGE
3. createAwtImage : negated conditional → NO_COVERAGE
        for (int k = fullWidth; k < pix.length; k += fullWidth) {
390 1 1. createAwtImage : removed call to java/lang/System::arraycopy → NO_COVERAGE
            System.arraycopy(pix, 0, pix, k, fullWidth); 
391
        }
392
        Image img = canvas.createImage(new MemoryImageSource(fullWidth, height, pix, 0, fullWidth));
393
        
394 1 1. createAwtImage : mutated return of Object value for com/lowagie/text/pdf/Barcode39::createAwtImage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return img;
395
    }    
396
}

Mutations

156

1.1
Location :
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

175

1.1
Location : getBarsCode39
Killed by : none
Replaced integer multiplication with division → NO_COVERAGE

2.2
Location : getBarsCode39
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

176

1.1
Location : getBarsCode39
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : getBarsCode39
Killed by : none
Changed increment from 1 to -1 → NO_COVERAGE

3.3
Location : getBarsCode39
Killed by : none
negated conditional → NO_COVERAGE

178

1.1
Location : getBarsCode39
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : getBarsCode39
Killed by : none
negated conditional → NO_COVERAGE

180

1.1
Location : getBarsCode39
Killed by : none
Replaced integer multiplication with division → NO_COVERAGE

2.2
Location : getBarsCode39
Killed by : none
removed call to java/lang/System::arraycopy → NO_COVERAGE

182

1.1
Location : getBarsCode39
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/Barcode39::getBarsCode39 to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

192

1.1
Location : getCode39Ex
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : getCode39Ex
Killed by : none
Changed increment from 1 to -1 → NO_COVERAGE

3.3
Location : getCode39Ex
Killed by : none
negated conditional → NO_COVERAGE

194

1.1
Location : getCode39Ex
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : getCode39Ex
Killed by : none
negated conditional → NO_COVERAGE

196

1.1
Location : getCode39Ex
Killed by : none
Replaced integer multiplication with division → NO_COVERAGE

197

1.1
Location : getCode39Ex
Killed by : none
Replaced integer multiplication with division → NO_COVERAGE

2.2
Location : getCode39Ex
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

198

1.1
Location : getCode39Ex
Killed by : none
negated conditional → NO_COVERAGE

202

1.1
Location : getCode39Ex
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/Barcode39::getCode39Ex to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

211

1.1
Location : getChecksum
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : getChecksum
Killed by : none
Changed increment from 1 to -1 → NO_COVERAGE

3.3
Location : getChecksum
Killed by : none
negated conditional → NO_COVERAGE

213

1.1
Location : getChecksum
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : getChecksum
Killed by : none
negated conditional → NO_COVERAGE

215

1.1
Location : getChecksum
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

217

1.1
Location : getChecksum
Killed by : none
Replaced integer modulus with multiplication → NO_COVERAGE

2.2
Location : getChecksum
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

228

1.1
Location : getBarcodeSize
Killed by : none
negated conditional → NO_COVERAGE

230

1.1
Location : getBarcodeSize
Killed by : none
negated conditional → NO_COVERAGE

231

1.1
Location : getBarcodeSize
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : getBarcodeSize
Killed by : none
negated conditional → NO_COVERAGE

232

1.1
Location : getBarcodeSize
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

234

1.1
Location : getBarcodeSize
Killed by : none
removed negation → NO_COVERAGE

2.2
Location : getBarcodeSize
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

236

1.1
Location : getBarcodeSize
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : getBarcodeSize
Killed by : none
negated conditional → NO_COVERAGE

238

1.1
Location : getBarcodeSize
Killed by : none
negated conditional → NO_COVERAGE

240

1.1
Location : getBarcodeSize
Killed by : none
negated conditional → NO_COVERAGE

242

1.1
Location : getBarcodeSize
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

243

1.1
Location : getBarcodeSize
Killed by : none
negated conditional → NO_COVERAGE

244

1.1
Location : getBarcodeSize
Killed by : none
Changed increment from 1 to -1 → NO_COVERAGE

245

1.1
Location : getBarcodeSize
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : getBarcodeSize
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

3.3
Location : getBarcodeSize
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

4.4
Location : getBarcodeSize
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

5.5
Location : getBarcodeSize
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

6.6
Location : getBarcodeSize
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

7.7
Location : getBarcodeSize
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

8.8
Location : getBarcodeSize
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

247

1.1
Location : getBarcodeSize
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

248

1.1
Location : getBarcodeSize
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/Barcode39::getBarcodeSize to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

291

1.1
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

293

1.1
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

294

1.1
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

296

1.1
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

298

1.1
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

300

1.1
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

302

1.1
Location : placeBarcode
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

303

1.1
Location : placeBarcode
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : placeBarcode
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

3.3
Location : placeBarcode
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

4.4
Location : placeBarcode
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

5.5
Location : placeBarcode
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

6.6
Location : placeBarcode
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

7.7
Location : placeBarcode
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

8.8
Location : placeBarcode
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

310

1.1
Location : placeBarcode
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

311

1.1
Location : placeBarcode
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

313

1.1
Location : placeBarcode
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

316

1.1
Location : placeBarcode
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

317

1.1
Location : placeBarcode
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

2.2
Location : placeBarcode
Killed by : none
Replaced float division with multiplication → NO_COVERAGE

319

1.1
Location : placeBarcode
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

2.2
Location : placeBarcode
Killed by : none
Replaced float division with multiplication → NO_COVERAGE

324

1.1
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

325

1.1
Location : placeBarcode
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

326

1.1
Location : placeBarcode
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

328

1.1
Location : placeBarcode
Killed by : none
removed negation → NO_COVERAGE

329

1.1
Location : placeBarcode
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

334

1.1
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

335

1.1
Location : placeBarcode
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::setColorFill → NO_COVERAGE

337

1.1
Location : placeBarcode
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

338

1.1
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

339

1.1
Location : placeBarcode
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

2.2
Location : placeBarcode
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::rectangle → NO_COVERAGE

340

1.1
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

341

1.1
Location : placeBarcode
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

343

1.1
Location : placeBarcode
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::fill → NO_COVERAGE

344

1.1
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

345

1.1
Location : placeBarcode
Killed by : none
negated conditional → NO_COVERAGE

346

1.1
Location : placeBarcode
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::setColorFill → NO_COVERAGE

347

1.1
Location : placeBarcode
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::beginText → NO_COVERAGE

348

1.1
Location : placeBarcode
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::setFontAndSize → NO_COVERAGE

349

1.1
Location : placeBarcode
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::setTextMatrix → NO_COVERAGE

350

1.1
Location : placeBarcode
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::showText → NO_COVERAGE

351

1.1
Location : placeBarcode
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::endText → NO_COVERAGE

353

1.1
Location : placeBarcode
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/Barcode39::placeBarcode to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

368

1.1
Location : createAwtImage
Killed by : none
negated conditional → NO_COVERAGE

370

1.1
Location : createAwtImage
Killed by : none
negated conditional → NO_COVERAGE

372

1.1
Location : createAwtImage
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

374

1.1
Location : createAwtImage
Killed by : none
Replaced integer multiplication with division → NO_COVERAGE

2.2
Location : createAwtImage
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

3.3
Location : createAwtImage
Killed by : none
Replaced integer multiplication with division → NO_COVERAGE

4.4
Location : createAwtImage
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

5.5
Location : createAwtImage
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

379

1.1
Location : createAwtImage
Killed by : none
Replaced integer multiplication with division → NO_COVERAGE

381

1.1
Location : createAwtImage
Killed by : none
negated conditional → NO_COVERAGE

383

1.1
Location : createAwtImage
Killed by : none
negated conditional → NO_COVERAGE

385

1.1
Location : createAwtImage
Killed by : none
negated conditional → NO_COVERAGE

386

1.1
Location : createAwtImage
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : createAwtImage
Killed by : none
Changed increment from 1 to -1 → NO_COVERAGE

3.3
Location : createAwtImage
Killed by : none
negated conditional → NO_COVERAGE

387

1.1
Location : createAwtImage
Killed by : none
Changed increment from 1 to -1 → NO_COVERAGE

389

1.1
Location : createAwtImage
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : createAwtImage
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

3.3
Location : createAwtImage
Killed by : none
negated conditional → NO_COVERAGE

390

1.1
Location : createAwtImage
Killed by : none
removed call to java/lang/System::arraycopy → NO_COVERAGE

394

1.1
Location : createAwtImage
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/Barcode39::createAwtImage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.4.2