001: /**
002: * Copyright (c) 2003, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.pdmodel.interactive.annotation;
031:
032: import org.pdfbox.cos.COSArray;
033: import org.pdfbox.cos.COSDictionary;
034: import org.pdfbox.cos.COSName;
035: import org.pdfbox.pdmodel.graphics.color.PDGamma;
036:
037: /**
038: * This is the class that represents a line annotation.
039: * Introduced in PDF 1.3 specification
040: *
041: * @author Paul King
042: * @version $Revision: 1.1 $
043: */
044: public class PDAnnotationLine extends PDAnnotationMarkup {
045:
046: /*
047: * The various values for intent (get/setIT, see the PDF 1.6 reference Table
048: * 8.22
049: */
050:
051: /**
052: * Constant for annotation intent of Arrow.
053: */
054: public static final String IT_LINE_ARROW = "LineArrow";
055:
056: /**
057: * Constant for annotation intent of a dimension line.
058: */
059: public static final String IT_LINE_DIMENSION = "LineDimension";
060:
061: /*
062: * The various values for line ending styles, see the PDF 1.6 reference
063: * Table 8.23
064: */
065:
066: /**
067: * Constant for a square line ending.
068: */
069: public static final String LE_SQUARE = "Square";
070:
071: /**
072: * Constant for a circle line ending.
073: */
074: public static final String LE_CIRCLE = "Circle";
075:
076: /**
077: * Constant for a diamond line ending.
078: */
079: public static final String LE_DIAMOND = "Diamond";
080:
081: /**
082: * Constant for a open arrow line ending.
083: */
084: public static final String LE_OPEN_ARROW = "OpenArrow";
085:
086: /**
087: * Constant for a closed arrow line ending.
088: */
089: public static final String LE_CLOSED_ARROW = "ClosedArrow";
090:
091: /**
092: * Constant for no line ending.
093: */
094: public static final String LE_NONE = "None";
095:
096: /**
097: * Constant for a butt line ending.
098: */
099: public static final String LE_BUTT = "Butt";
100:
101: /**
102: * Constant for a reversed open arrow line ending.
103: */
104: public static final String LE_R_OPEN_ARROW = "ROpenArrow";
105:
106: /**
107: * Constant for a revered closed arrow line ending.
108: */
109: public static final String LE_R_CLOSED_ARROW = "RClosedArrow";
110:
111: /**
112: * Constant for a slash line ending.
113: */
114: public static final String LE_SLASH = "Slash";
115:
116: /**
117: * The type of annotation.
118: */
119: public static final String SUB_TYPE = "Line";
120:
121: /**
122: * Constructor.
123: */
124: public PDAnnotationLine() {
125: super ();
126: getDictionary().setItem(COSName.SUBTYPE,
127: COSName.getPDFName(SUB_TYPE));
128: // Dictionary value L is mandatory, fill in with arbitary value
129: setLine(new float[] { 0, 0, 0, 0 });
130:
131: }
132:
133: /**
134: * Creates a Line annotation from a COSDictionary, expected to be a correct
135: * object definition.
136: *
137: * @param field
138: * the PDF objet to represent as a field.
139: */
140: public PDAnnotationLine(COSDictionary field) {
141: super (field);
142: }
143:
144: /**
145: * This will set start and end coordinates of the line (or leader line if LL
146: * entry is set).
147: *
148: * @param l
149: * array of 4 floats [x1, y1, x2, y2] line start and end points
150: * in default user space.
151: */
152: public void setLine(float[] l) {
153: COSArray newL = new COSArray();
154: newL.setFloatArray(l);
155: getDictionary().setItem("L", newL);
156: }
157:
158: /**
159: * This will retrieve the start and end coordinates of the line (or leader
160: * line if LL entry is set).
161: *
162: * @return array of floats [x1, y1, x2, y2] line start and end points in
163: * default user space.
164: */
165: public float[] getLine() {
166: COSArray l = (COSArray) getDictionary()
167: .getDictionaryObject("L");
168: return l.toFloatArray();
169: }
170:
171: /**
172: * This will set the line ending style for the start point,
173: * see the LE_ constants for the possible values.
174: *
175: * @param style The new style.
176: */
177: public void setStartPointEndingStyle(String style) {
178: if (style == null) {
179: style = LE_NONE;
180: }
181: COSArray array = (COSArray) getDictionary()
182: .getDictionaryObject("LE");
183: if (array == null) {
184: array = new COSArray();
185: array.add(COSName.getPDFName(style));
186: array.add(COSName.getPDFName(LE_NONE));
187: getDictionary().setItem("LE", array);
188: } else {
189: array.setName(0, style);
190: }
191: }
192:
193: /**
194: * This will retrieve the line ending style for the start point,
195: * possible values shown in the LE_ constants section.
196: *
197: * @return The ending style for the start point.
198: */
199: public String getStartPointEndingStyle() {
200: String retval = LE_NONE;
201: COSArray array = (COSArray) getDictionary()
202: .getDictionaryObject("LE");
203: if (array != null) {
204: retval = array.getName(0);
205: }
206:
207: return retval;
208: }
209:
210: /**
211: * This will set the line ending style for the end point,
212: * see the LE_ constants for the possible values.
213: *
214: * @param style The new style.
215: */
216: public void setEndPointEndingStyle(String style) {
217: if (style == null) {
218: style = LE_NONE;
219: }
220: COSArray array = (COSArray) getDictionary()
221: .getDictionaryObject("LE");
222: if (array == null) {
223: array = new COSArray();
224: array.add(COSName.getPDFName(LE_NONE));
225: array.add(COSName.getPDFName(style));
226: getDictionary().setItem("LE", array);
227: } else {
228: array.setName(1, style);
229: }
230: }
231:
232: /**
233: * This will retrieve the line ending style for the end point,
234: * possible values shown in the LE_ constants section.
235: *
236: * @return The ending style for the end point.
237: */
238: public String getEndPointEndingStyle() {
239: String retval = LE_NONE;
240: COSArray array = (COSArray) getDictionary()
241: .getDictionaryObject("LE");
242: if (array != null) {
243: retval = array.getName(1);
244: }
245:
246: return retval;
247: }
248:
249: /**
250: * This will set interior colour of the line endings defined in the LE
251: * entry. Colour is in DeviceRGB colourspace.
252: *
253: * @param ic
254: * colour in the DeviceRGB colourspace.
255: *
256: */
257: public void setInteriorColour(PDGamma ic) {
258: getDictionary().setItem("IC", ic);
259: }
260:
261: /**
262: * This will retrieve the interior colour of the line endings defined in the
263: * LE entry. Colour is in DeviceRGB colourspace.
264: *
265: *
266: * @return PDGamma object representing the colour.
267: *
268: */
269: public PDGamma getInteriorColour() {
270:
271: COSArray ic = (COSArray) getDictionary().getDictionaryObject(
272: "IC");
273: if (ic != null) {
274: return new PDGamma(ic);
275: } else {
276: return null;
277: }
278: }
279:
280: /**
281: * This will set if the contents are shown as a caption to the line.
282: *
283: * @param cap
284: * Boolean value.
285: */
286: public void setCaption(boolean cap) {
287: getDictionary().setBoolean("Cap", cap);
288: }
289:
290: /**
291: * This will retrieve if the contents are shown as a caption or not.
292: *
293: * @return boolean if the content is shown as a caption.
294: */
295: public boolean getCaption() {
296: return getDictionary().getBoolean("Cap", false);
297: }
298:
299: }
|