001: /**
002: * Copyright (c) 2005, 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.COSDictionary;
033: import org.pdfbox.cos.COSArray;
034: import org.pdfbox.cos.COSName;
035:
036: /**
037: * This is the abstract class that represents a text markup annotation
038: * Introduced in PDF 1.3 specification, except Squiggly lines in 1.4.
039: *
040: * @author Paul King
041: * @version $Revision: 1.1 $
042: */
043: public class PDAnnotationTextMarkup extends PDAnnotationMarkup {
044:
045: /**
046: * The types of annotation.
047: */
048: public static final String SUB_TYPE_HIGHLIGHT = "Highlight";
049: /**
050: * The types of annotation.
051: */
052: public static final String SUB_TYPE_UNDERLINE = "Underline";
053: /**
054: * The types of annotation.
055: */
056: public static final String SUB_TYPE_SQUIGGLY = "Squiggly";
057: /**
058: * The types of annotation.
059: */
060: public static final String SUB_TYPE_STRIKEOUT = "StrikeOut";
061:
062: private PDAnnotationTextMarkup() {
063: // Must be constructed with a subType or dictionary parameter
064: }
065:
066: /**
067: * Creates a TextMarkup annotation of the specified sub type.
068: *
069: * @param subType the subtype the annotation represents
070: */
071: public PDAnnotationTextMarkup(String subType) {
072: super ();
073: setSubtype(subType);
074:
075: // Quad points are required, set and empty array
076: setQuadPoints(new float[0]);
077: }
078:
079: /**
080: * Creates a TextMarkup annotation from a COSDictionary, expected to be a
081: * correct object definition.
082: *
083: * @param field the PDF objet to represent as a field.
084: */
085: public PDAnnotationTextMarkup(COSDictionary field) {
086: super (field);
087: }
088:
089: /**
090: * This will set the set of quadpoints which encompass the areas of this
091: * annotation.
092: *
093: * @param quadPoints
094: * an array representing the set of area covered
095: */
096: public void setQuadPoints(float[] quadPoints) {
097: COSArray newQuadPoints = new COSArray();
098: newQuadPoints.setFloatArray(quadPoints);
099: getDictionary().setItem("QuadPoints", newQuadPoints);
100: }
101:
102: /**
103: * This will retrieve the set of quadpoints which encompass the areas of
104: * this annotation.
105: *
106: * @return An array of floats representing the quad points.
107: */
108: public float[] getQuadPoints() {
109: COSArray quadPoints = (COSArray) getDictionary()
110: .getDictionaryObject("QuadPoints");
111: if (quadPoints != null) {
112: return quadPoints.toFloatArray();
113: } else {
114: return null; // Should never happen as this is a required item
115: }
116: }
117:
118: /**
119: * This will set the sub type (and hence appearance, AP taking precedence) For
120: * this annotation. See the SUB_TYPE_XXX constants for valid values.
121: *
122: * @param subType The subtype of the annotation
123: */
124: public void setSubtype(String subType) {
125: getDictionary().setName(COSName.SUBTYPE, subType);
126: }
127:
128: /**
129: * This will retrieve the sub type (and hence appearance, AP taking precedence)
130: * For this annotation.
131: *
132: * @return The subtype of this annotation, see the SUB_TYPE_XXX constants.
133: */
134: public String getSubtype() {
135: return getDictionary().getNameAsString(COSName.SUBTYPE);
136: }
137:
138: }
|