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.documentinterchange.markedcontent;
19 import java.util.ArrayList;
20 import java.util.List;
22 import org.apache.pdfbox.cos.COSDictionary;
23 import org.apache.pdfbox.cos.COSName;
24 import org.apache.pdfbox.pdmodel.documentinterchange.taggedpdf.PDArtifactMarkedContent;
25 import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject;
26 import org.apache.pdfbox.util.TextPosition;
31 * @author <a href="mailto:Johannes%20Koch%20%3Ckoch@apache.org%3E">Johannes Koch</a>
32 * @version $Revision: $
34 public class PDMarkedContent
38 * Creates a marked-content sequence.
41 * @param properties the properties
42 * @return the marked-content sequence
44 public static PDMarkedContent create(COSName tag, COSDictionary properties)
46 if (COSName.ARTIFACT.equals(tag))
48 new PDArtifactMarkedContent(properties);
50 return new PDMarkedContent(tag, properties);
55 private COSDictionary properties;
56 private List<Object> contents;
60 * Creates a new marked content object.
63 * @param properties the properties
65 public PDMarkedContent(COSName tag, COSDictionary properties)
67 this.tag = tag == null ? null : tag.getName();
68 this.properties = properties;
69 this.contents = new ArrayList<Object>();
78 public String getTag()
84 * Gets the properties.
86 * @return the properties
88 public COSDictionary getProperties()
90 return this.properties;
94 * Gets the marked-content identifier.
96 * @return the marked-content identifier
100 return this.getProperties() == null ? null :
101 this.getProperties().getInt(COSName.MCID);
105 * Gets the language (Lang).
107 * @return the language
109 public String getLanguage()
111 return this.getProperties() == null ? null :
112 this.getProperties().getNameAsString(COSName.LANG);
116 * Gets the actual text (ActualText).
118 * @return the actual text
120 public String getActualText()
122 return this.getProperties() == null ? null :
123 this.getProperties().getString(COSName.ACTUAL_TEXT);
127 * Gets the alternate description (Alt).
129 * @return the alternate description
131 public String getAlternateDescription()
133 return this.getProperties() == null ? null :
134 this.getProperties().getString(COSName.ALT);
138 * Gets the expanded form (E).
140 * @return the expanded form
142 public String getExpandedForm()
144 return this.getProperties() == null ? null :
145 this.getProperties().getString(COSName.E);
149 * Gets the contents of the marked content sequence. Can be
151 * <li>{@link TextPosition},</li>
152 * <li>{@link PDMarkedContent}, or</li>
153 * <li>{@link PDXObject}.</li>
156 * @return the contents of the marked content sequence
158 public List<Object> getContents()
160 return this.contents;
164 * Adds a text position to the contents.
166 * @param text the text position
168 public void addText(TextPosition text)
170 this.getContents().add(text);
174 * Adds a marked content to the contents.
176 * @param markedContent the marked content
178 public void addMarkedContent(PDMarkedContent markedContent)
180 this.getContents().add(markedContent);
184 * Adds an XObject to the contents.
186 * @param xobject the XObject
188 public void addXObject(PDXObject xobject)
190 this.getContents().add(xobject);
195 public String toString()
197 StringBuilder sb = new StringBuilder("tag=").append(this.tag)
198 .append(", properties=").append(this.properties);
199 sb.append(", contents=").append(this.contents);
200 return sb.toString();