001: /*
002: * $Id: PDFBorder.java,v 1.2 2001/11/16 15:26:04 ezb Exp $
003: *
004: * $Date: 2001/11/16 15:26:04 $
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020: package gnu.jpdf;
021:
022: import java.awt.*;
023: import java.io.*;
024: import java.util.*;
025:
026: /**
027: * <p>A border around an annotation </p>
028: *
029: *
030: * @author Peter T Mount, http://www.retep.org.uk/pdf/
031: * @author Eric Z. Beard, ericzbeard@hotmail.com
032: * @author $Author: ezb $
033: * @version $Revision: 1.2 $
034: */
035: public class PDFBorder extends PDFObject {
036: /*
037: * NOTE: The original class is the work of Peter T. Mount, who released it
038: * in the uk.org.retep.pdf package. It was modified by Eric Z. Beard as
039: * follows: the package name was changed to gnu.pdf. It is still
040: * licensed under the LGPL.
041: */
042:
043: /**
044: * The style of the border
045: */
046: private short style;
047:
048: /**
049: * The width of the border
050: */
051: private double width;
052:
053: /**
054: * This array allows the definition of a dotted line for the border
055: */
056: private double dash[];
057:
058: /**
059: * Creates a border using the predefined styles in PDFAnnot.
060: * <p>Note: Do not use PDFAnnot.DASHED with this method.
061: * Use the other constructor.
062: *
063: * @param style The style of the border
064: * @param width The width of the border
065: * @see PDFAnnot
066: */
067: public PDFBorder(short style, double width) {
068: super ("/Border");
069: this .style = style;
070: this .width = width;
071: }
072:
073: /**
074: * Creates a border of style PDFAnnot.DASHED
075: *
076: * @param width The width of the border
077: * @param dash The line pattern definition
078: */
079: public PDFBorder(double width, double dash[]) {
080: super ("/Border");
081: this .style = PDFAnnot.DASHED;
082: this .width = width;
083: this .dash = dash;
084: }
085:
086: /**
087: * @param os OutputStream to send the object to
088: * @exception IOException on error
089: */
090: public void write(OutputStream os) throws IOException {
091: //writeStart(os);
092: os.write(Integer.toString(objser).getBytes());
093: os.write(" 0 obj\n".getBytes());
094:
095: os.write("[/S /".getBytes());
096: os.write("SDBIU".substring(style, style + 1).getBytes());
097: os.write(" /W ".getBytes());
098: os.write(Double.toString(width).getBytes());
099: if (dash != null) {
100: os.write(" /D [".getBytes());
101: os.write(Double.toString(dash[0]).getBytes());
102: for (int i = 1; i < dash.length; i++) {
103: os.write(" ".getBytes());
104: os.write(Double.toString(dash[i]).getBytes());
105: }
106: os.write("] ".getBytes());
107: }
108: os.write("]\n".getBytes());
109:
110: //writeEnd(os);
111: os.write("endobj\n".getBytes());
112: }
113: } // end class PDFBorder
|