001: /*
002: * Copyright 2002 by Paulo Soares.
003: *
004: * The contents of this file are subject to the Mozilla Public License Version 1.1
005: * (the "License"); you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
007: *
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
010: * for the specific language governing rights and limitations under the License.
011: *
012: * The Original Code is 'iText, a free JAVA-PDF library'.
013: *
014: * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
015: * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
016: * All Rights Reserved.
017: * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
018: * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
019: *
020: * Contributor(s): all the names of the contributors are added in the source code
021: * where applicable.
022: *
023: * Alternatively, the contents of this file may be used under the terms of the
024: * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
025: * provisions of LGPL are applicable instead of those above. If you wish to
026: * allow use of your version of this file only under the terms of the LGPL
027: * License and not to allow others to use your version of this file under
028: * the MPL, indicate your decision by deleting the provisions above and
029: * replace them with the notice and other provisions required by the LGPL.
030: * If you do not delete the provisions above, a recipient may use your version
031: * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
032: *
033: * This library is free software; you can redistribute it and/or modify it
034: * under the terms of the MPL as stated above or under the terms of the GNU
035: * Library General Public License as published by the Free Software Foundation;
036: * either version 2 of the License, or any later version.
037: *
038: * This library is distributed in the hope that it will be useful, but WITHOUT
039: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
040: * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
041: * details.
042: *
043: * If you didn't download this code from the following link, you should check if
044: * you aren't using an obsolete version:
045: * http://www.lowagie.com/iText/
046: */
047: package com.lowagie.text.pdf;
048:
049: import java.awt.Color;
050:
051: import com.lowagie.text.Rectangle;
052:
053: /** This class takes 2 barcodes, an EAN/UPC and a supplemental
054: * and creates a single barcode with both combined in the
055: * expected layout. The UPC/EAN should have a positive text
056: * baseline and the supplemental a negative one (in the supplemental
057: * the text is on the top of the barcode.<p>
058: * The default parameters are:
059: * <pre>
060: *n = 8; // horizontal distance between the two barcodes
061: * </pre>
062: *
063: * @author Paulo Soares (psoares@consiste.pt)
064: */
065: public class BarcodeEANSUPP extends Barcode {
066:
067: /** The barcode with the EAN/UPC.
068: */
069: protected Barcode ean;
070: /** The barcode with the supplemental.
071: */
072: protected Barcode supp;
073:
074: /** Creates new combined barcode.
075: * @param ean the EAN/UPC barcode
076: * @param supp the supplemental barcode
077: */
078: public BarcodeEANSUPP(Barcode ean, Barcode supp) {
079: n = 8; // horizontal distance between the two barcodes
080: this .ean = ean;
081: this .supp = supp;
082: }
083:
084: /** Gets the maximum area that the barcode and the text, if
085: * any, will occupy. The lower left corner is always (0, 0).
086: * @return the size the barcode occupies.
087: */
088: public Rectangle getBarcodeSize() {
089: Rectangle rect = ean.getBarcodeSize();
090: rect.setRight(rect.getWidth()
091: + supp.getBarcodeSize().getWidth() + n);
092: return rect;
093: }
094:
095: /** Places the barcode in a <CODE>PdfContentByte</CODE>. The
096: * barcode is always placed at coodinates (0, 0). Use the
097: * translation matrix to move it elsewhere.<p>
098: * The bars and text are written in the following colors:<p>
099: * <P><TABLE BORDER=1>
100: * <TR>
101: * <TH><P><CODE>barColor</CODE></TH>
102: * <TH><P><CODE>textColor</CODE></TH>
103: * <TH><P>Result</TH>
104: * </TR>
105: * <TR>
106: * <TD><P><CODE>null</CODE></TD>
107: * <TD><P><CODE>null</CODE></TD>
108: * <TD><P>bars and text painted with current fill color</TD>
109: * </TR>
110: * <TR>
111: * <TD><P><CODE>barColor</CODE></TD>
112: * <TD><P><CODE>null</CODE></TD>
113: * <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
114: * </TR>
115: * <TR>
116: * <TD><P><CODE>null</CODE></TD>
117: * <TD><P><CODE>textColor</CODE></TD>
118: * <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
119: * </TR>
120: * <TR>
121: * <TD><P><CODE>barColor</CODE></TD>
122: * <TD><P><CODE>textColor</CODE></TD>
123: * <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
124: * </TR>
125: * </TABLE>
126: * @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
127: * @param barColor the color of the bars. It can be <CODE>null</CODE>
128: * @param textColor the color of the text. It can be <CODE>null</CODE>
129: * @return the dimensions the barcode occupies
130: */
131: public Rectangle placeBarcode(PdfContentByte cb, Color barColor,
132: Color textColor) {
133: if (supp.getFont() != null)
134: supp.setBarHeight(ean.getBarHeight()
135: + supp.getBaseline()
136: - supp.getFont().getFontDescriptor(
137: BaseFont.CAPHEIGHT, supp.getSize()));
138: else
139: supp.setBarHeight(ean.getBarHeight());
140: Rectangle eanR = ean.getBarcodeSize();
141: cb.saveState();
142: ean.placeBarcode(cb, barColor, textColor);
143: cb.restoreState();
144: cb.saveState();
145: cb.concatCTM(1, 0, 0, 1, eanR.getWidth() + n, eanR.getHeight()
146: - ean.getBarHeight());
147: supp.placeBarcode(cb, barColor, textColor);
148: cb.restoreState();
149: return getBarcodeSize();
150: }
151:
152: /** Creates a <CODE>java.awt.Image</CODE>. This image only
153: * contains the bars without any text.
154: * @param foreground the color of the bars
155: * @param background the color of the background
156: * @return the image
157: */
158: public java.awt.Image createAwtImage(Color foreground,
159: Color background) {
160: throw new UnsupportedOperationException(
161: "The two barcodes must be composed externally.");
162: }
163: }
|