]> _ Git - cubeextranet.git/blob
20a200db400411a2b64fa7f5ae96e4128de6c389
[cubeextranet.git] /
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 package org.apache.pdfbox.pdmodel.interactive.annotation;
18
19 import org.apache.pdfbox.cos.COSDictionary;
20 import org.apache.pdfbox.cos.COSArray;
21 import org.apache.pdfbox.cos.COSName;
22
23 /**
24  * This is the abstract class that represents a text markup annotation
25  * Introduced in PDF 1.3 specification, except Squiggly lines in 1.4.
26  *
27  * @author Paul King
28  * @version $Revision: 1.1 $
29  */
30 public class PDAnnotationTextMarkup extends PDAnnotationMarkup
31 {
32
33     /**
34      * The types of annotation.
35      */
36     public static final String SUB_TYPE_HIGHLIGHT = "Highlight";
37     /**
38      * The types of annotation.
39      */
40     public static final String SUB_TYPE_UNDERLINE = "Underline";
41     /**
42      * The types of annotation.
43      */
44     public static final String SUB_TYPE_SQUIGGLY = "Squiggly";
45     /**
46      * The types of annotation.
47      */
48     public static final String SUB_TYPE_STRIKEOUT = "StrikeOut";
49
50
51     private PDAnnotationTextMarkup()
52     {
53         // Must be constructed with a subType or dictionary parameter
54     }
55
56     /**
57      * Creates a TextMarkup annotation of the specified sub type.
58      *
59      * @param subType the subtype the annotation represents
60      */
61     public PDAnnotationTextMarkup(String subType)
62     {
63         super();
64         setSubtype( subType );
65
66         // Quad points are required, set and empty array
67         setQuadPoints( new float[0] );
68     }
69
70     /**
71      * Creates a TextMarkup annotation from a COSDictionary, expected to be a
72      * correct object definition.
73      *
74      * @param field the PDF objet to represent as a field.
75      */
76     public PDAnnotationTextMarkup( COSDictionary field )
77     {
78         super( field );
79     }
80
81     /**
82      * This will set the set of quadpoints which encompass the areas of this
83      * annotation.
84      *
85      * @param quadPoints
86      *            an array representing the set of area covered
87      */
88     public void setQuadPoints( float[] quadPoints )
89     {
90         COSArray newQuadPoints = new COSArray();
91         newQuadPoints.setFloatArray( quadPoints );
92         getDictionary().setItem( "QuadPoints", newQuadPoints );
93     }
94
95     /**
96      * This will retrieve the set of quadpoints which encompass the areas of
97      * this annotation.
98      *
99      * @return An array of floats representing the quad points.
100      */
101     public float[] getQuadPoints()
102     {
103         COSArray quadPoints = (COSArray) getDictionary().getDictionaryObject( "QuadPoints" );
104         if (quadPoints != null)
105         {
106             return quadPoints.toFloatArray();
107         }
108         else
109         {
110             return null; // Should never happen as this is a required item
111         }
112     }
113
114     /**
115      * This will set the sub type (and hence appearance, AP taking precedence) For
116      * this annotation. See the SUB_TYPE_XXX constants for valid values.
117      *
118      * @param subType The subtype of the annotation
119      */
120     public void setSubtype( String subType )
121     {
122         getDictionary().setName( COSName.SUBTYPE, subType );
123     }
124
125     /**
126      * This will retrieve the sub type (and hence appearance, AP taking precedence)
127      * For this annotation.
128      *
129      * @return The subtype of this annotation, see the SUB_TYPE_XXX constants.
130      */
131     public String getSubtype()
132     {
133         return getDictionary().getNameAsString( COSName.SUBTYPE);
134     }
135
136
137 }