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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.apache.pdfbox.pdmodel.interactive.annotation;
19 import org.apache.pdfbox.cos.COSDictionary;
20 import org.apache.pdfbox.cos.COSArray;
21 import org.apache.pdfbox.cos.COSName;
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.
28 * @version $Revision: 1.1 $
30 public class PDAnnotationTextMarkup extends PDAnnotationMarkup
34 * The types of annotation.
36 public static final String SUB_TYPE_HIGHLIGHT = "Highlight";
38 * The types of annotation.
40 public static final String SUB_TYPE_UNDERLINE = "Underline";
42 * The types of annotation.
44 public static final String SUB_TYPE_SQUIGGLY = "Squiggly";
46 * The types of annotation.
48 public static final String SUB_TYPE_STRIKEOUT = "StrikeOut";
51 private PDAnnotationTextMarkup()
53 // Must be constructed with a subType or dictionary parameter
57 * Creates a TextMarkup annotation of the specified sub type.
59 * @param subType the subtype the annotation represents
61 public PDAnnotationTextMarkup(String subType)
64 setSubtype( subType );
66 // Quad points are required, set and empty array
67 setQuadPoints( new float[0] );
71 * Creates a TextMarkup annotation from a COSDictionary, expected to be a
72 * correct object definition.
74 * @param field the PDF objet to represent as a field.
76 public PDAnnotationTextMarkup( COSDictionary field )
82 * This will set the set of quadpoints which encompass the areas of this
86 * an array representing the set of area covered
88 public void setQuadPoints( float[] quadPoints )
90 COSArray newQuadPoints = new COSArray();
91 newQuadPoints.setFloatArray( quadPoints );
92 getDictionary().setItem( "QuadPoints", newQuadPoints );
96 * This will retrieve the set of quadpoints which encompass the areas of
99 * @return An array of floats representing the quad points.
101 public float[] getQuadPoints()
103 COSArray quadPoints = (COSArray) getDictionary().getDictionaryObject( "QuadPoints" );
104 if (quadPoints != null)
106 return quadPoints.toFloatArray();
110 return null; // Should never happen as this is a required item
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.
118 * @param subType The subtype of the annotation
120 public void setSubtype( String subType )
122 getDictionary().setName( COSName.SUBTYPE, subType );
126 * This will retrieve the sub type (and hence appearance, AP taking precedence)
127 * For this annotation.
129 * @return The subtype of this annotation, see the SUB_TYPE_XXX constants.
131 public String getSubtype()
133 return getDictionary().getNameAsString( COSName.SUBTYPE);