1 | /* | |
2 | * Copyright 2002 by Paulo Soares. | |
3 | * | |
4 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
5 | * (the "License"); you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
7 | * | |
8 | * Software distributed under the License is distributed on an "AS IS" basis, | |
9 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
10 | * for the specific language governing rights and limitations under the License. | |
11 | * | |
12 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
13 | * | |
14 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
15 | * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. | |
16 | * All Rights Reserved. | |
17 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
18 | * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. | |
19 | * | |
20 | * Contributor(s): all the names of the contributors are added in the source code | |
21 | * where applicable. | |
22 | * | |
23 | * Alternatively, the contents of this file may be used under the terms of the | |
24 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
25 | * provisions of LGPL are applicable instead of those above. If you wish to | |
26 | * allow use of your version of this file only under the terms of the LGPL | |
27 | * License and not to allow others to use your version of this file under | |
28 | * the MPL, indicate your decision by deleting the provisions above and | |
29 | * replace them with the notice and other provisions required by the LGPL. | |
30 | * If you do not delete the provisions above, a recipient may use your version | |
31 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
32 | * | |
33 | * This library is free software; you can redistribute it and/or modify it | |
34 | * under the terms of the MPL as stated above or under the terms of the GNU | |
35 | * Library General Public License as published by the Free Software Foundation; | |
36 | * either version 2 of the License, or any later version. | |
37 | * | |
38 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
39 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
40 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
41 | * details. | |
42 | * | |
43 | * If you didn't download this code from the following link, you should check if | |
44 | * you aren't using an obsolete version: | |
45 | * http://www.lowagie.com/iText/ | |
46 | */ | |
47 | package com.lowagie.text.pdf; | |
48 | import java.awt.Color; | |
49 | import com.lowagie.text.error_messages.MessageLocalization; | |
50 | ||
51 | import com.lowagie.text.Rectangle; | |
52 | ||
53 | /** This class takes 2 barcodes, an EAN/UPC and a supplemental | |
54 | * and creates a single barcode with both combined in the | |
55 | * expected layout. The UPC/EAN should have a positive text | |
56 | * baseline and the supplemental a negative one (in the supplemental | |
57 | * the text is on the top of the barcode.<p> | |
58 | * The default parameters are: | |
59 | * <pre> | |
60 | *n = 8; // horizontal distance between the two barcodes | |
61 | * </pre> | |
62 | * | |
63 | * @author Paulo Soares (psoares@consiste.pt) | |
64 | */ | |
65 | public class BarcodeEANSUPP extends Barcode{ | |
66 | | |
67 | /** The barcode with the EAN/UPC. | |
68 | */ | |
69 | protected Barcode ean; | |
70 | /** The barcode with the supplemental. | |
71 | */ | |
72 | protected Barcode supp; | |
73 | | |
74 | /** Creates new combined barcode. | |
75 | * @param ean the EAN/UPC barcode | |
76 | * @param supp the supplemental barcode | |
77 | */ | |
78 | public BarcodeEANSUPP(Barcode ean, Barcode supp) { | |
79 | n = 8; // horizontal distance between the two barcodes | |
80 | this.ean = ean; | |
81 | this.supp = supp; | |
82 | } | |
83 | | |
84 | /** Gets the maximum area that the barcode and the text, if | |
85 | * any, will occupy. The lower left corner is always (0, 0). | |
86 | * @return the size the barcode occupies. | |
87 | */ | |
88 | public Rectangle getBarcodeSize() { | |
89 | Rectangle rect = ean.getBarcodeSize(); | |
90 |
3
1. getBarcodeSize : Replaced float addition with subtraction → NO_COVERAGE 2. getBarcodeSize : Replaced float addition with subtraction → NO_COVERAGE 3. getBarcodeSize : removed call to com/lowagie/text/Rectangle::setRight → NO_COVERAGE |
rect.setRight(rect.getWidth() + supp.getBarcodeSize().getWidth() + n); |
91 |
1
1. getBarcodeSize : mutated return of Object value for com/lowagie/text/pdf/BarcodeEANSUPP::getBarcodeSize to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return rect; |
92 | } | |
93 | | |
94 | /** Places the barcode in a <CODE>PdfContentByte</CODE>. The | |
95 | * barcode is always placed at coordinates (0, 0). Use the | |
96 | * translation matrix to move it elsewhere.<p> | |
97 | * The bars and text are written in the following colors:<p> | |
98 | * <P><TABLE BORDER=1> | |
99 | * <TR> | |
100 | * <TH><P><CODE>barColor</CODE></TH> | |
101 | * <TH><P><CODE>textColor</CODE></TH> | |
102 | * <TH><P>Result</TH> | |
103 | * </TR> | |
104 | * <TR> | |
105 | * <TD><P><CODE>null</CODE></TD> | |
106 | * <TD><P><CODE>null</CODE></TD> | |
107 | * <TD><P>bars and text painted with current fill color</TD> | |
108 | * </TR> | |
109 | * <TR> | |
110 | * <TD><P><CODE>barColor</CODE></TD> | |
111 | * <TD><P><CODE>null</CODE></TD> | |
112 | * <TD><P>bars and text painted with <CODE>barColor</CODE></TD> | |
113 | * </TR> | |
114 | * <TR> | |
115 | * <TD><P><CODE>null</CODE></TD> | |
116 | * <TD><P><CODE>textColor</CODE></TD> | |
117 | * <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD> | |
118 | * </TR> | |
119 | * <TR> | |
120 | * <TD><P><CODE>barColor</CODE></TD> | |
121 | * <TD><P><CODE>textColor</CODE></TD> | |
122 | * <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD> | |
123 | * </TR> | |
124 | * </TABLE> | |
125 | * @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed | |
126 | * @param barColor the color of the bars. It can be <CODE>null</CODE> | |
127 | * @param textColor the color of the text. It can be <CODE>null</CODE> | |
128 | * @return the dimensions the barcode occupies | |
129 | */ | |
130 | public Rectangle placeBarcode(PdfContentByte cb, Color barColor, Color textColor) { | |
131 |
1
1. placeBarcode : negated conditional → NO_COVERAGE |
if (supp.getFont() != null) |
132 |
3
1. placeBarcode : Replaced float addition with subtraction → NO_COVERAGE 2. placeBarcode : Replaced float subtraction with addition → NO_COVERAGE 3. placeBarcode : removed call to com/lowagie/text/pdf/Barcode::setBarHeight → NO_COVERAGE |
supp.setBarHeight(ean.getBarHeight() + supp.getBaseline() - supp.getFont().getFontDescriptor(BaseFont.CAPHEIGHT, supp.getSize())); |
133 | else | |
134 |
1
1. placeBarcode : removed call to com/lowagie/text/pdf/Barcode::setBarHeight → NO_COVERAGE |
supp.setBarHeight(ean.getBarHeight()); |
135 | Rectangle eanR = ean.getBarcodeSize(); | |
136 |
1
1. placeBarcode : removed call to com/lowagie/text/pdf/PdfContentByte::saveState → NO_COVERAGE |
cb.saveState(); |
137 | ean.placeBarcode(cb, barColor, textColor); | |
138 |
1
1. placeBarcode : removed call to com/lowagie/text/pdf/PdfContentByte::restoreState → NO_COVERAGE |
cb.restoreState(); |
139 |
1
1. placeBarcode : removed call to com/lowagie/text/pdf/PdfContentByte::saveState → NO_COVERAGE |
cb.saveState(); |
140 |
3
1. placeBarcode : Replaced float addition with subtraction → NO_COVERAGE 2. placeBarcode : Replaced float subtraction with addition → NO_COVERAGE 3. placeBarcode : removed call to com/lowagie/text/pdf/PdfContentByte::concatCTM → NO_COVERAGE |
cb.concatCTM(1, 0, 0, 1, eanR.getWidth() + n, eanR.getHeight() - ean.getBarHeight()); |
141 | supp.placeBarcode(cb, barColor, textColor); | |
142 |
1
1. placeBarcode : removed call to com/lowagie/text/pdf/PdfContentByte::restoreState → NO_COVERAGE |
cb.restoreState(); |
143 |
1
1. placeBarcode : mutated return of Object value for com/lowagie/text/pdf/BarcodeEANSUPP::placeBarcode to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return getBarcodeSize(); |
144 | } | |
145 | | |
146 | /** Creates a <CODE>java.awt.Image</CODE>. This image only | |
147 | * contains the bars without any text. | |
148 | * @param foreground the color of the bars | |
149 | * @param background the color of the background | |
150 | * @return the image | |
151 | */ | |
152 | public java.awt.Image createAwtImage(Color foreground, Color background) { | |
153 | throw new UnsupportedOperationException(MessageLocalization.getComposedMessage("the.two.barcodes.must.be.composed.externally")); | |
154 | } | |
155 | } | |
Mutations | ||
90 |
1.1 2.2 3.3 |
|
91 |
1.1 |
|
131 |
1.1 |
|
132 |
1.1 2.2 3.3 |
|
134 |
1.1 |
|
136 |
1.1 |
|
138 |
1.1 |
|
139 |
1.1 |
|
140 |
1.1 2.2 3.3 |
|
142 |
1.1 |
|
143 |
1.1 |