1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.opencastproject.metadata.mpeg7;
23
24 import org.w3c.dom.Document;
25 import org.w3c.dom.Element;
26 import org.w3c.dom.Node;
27
28 import java.awt.Rectangle;
29 import java.text.DecimalFormat;
30 import java.text.DecimalFormatSymbols;
31 import java.util.Locale;
32
33
34
35
36 public class VideoTextImpl implements VideoText {
37
38
39
40
41
42 private static DecimalFormatSymbols standardSymbols = new DecimalFormatSymbols(Locale.US);
43
44
45 protected Type type = Type.superimposed;
46
47
48 protected String id = null;
49
50
51 protected Textual text = null;
52
53
54 protected Rectangle boundary = null;
55
56
57 protected SpatioTemporalLocator locator = null;
58
59
60 protected String fontType = null;
61
62
63 protected int fontSize = -1;
64
65
66
67
68
69
70
71 public VideoTextImpl(String id) {
72 this(id, null, null, null);
73 }
74
75
76
77
78
79
80
81
82
83
84
85
86
87 public VideoTextImpl(String id, Textual text, Rectangle boundary, MediaTime time) {
88 this.id = id;
89 this.text = text;
90 this.boundary = boundary;
91 if (time != null) {
92 this.locator = new SpatioTemporalLocatorImpl(time);
93 }
94 }
95
96
97
98
99
100
101 @Override
102 public void setIdentifier(String id) {
103 this.id = id;
104 }
105
106
107
108
109
110
111 @Override
112 public String getIdentifier() {
113 return id;
114 }
115
116
117
118
119
120
121 @Override
122 public void setType(Type type) {
123 this.type = type;
124 }
125
126
127
128
129
130
131 @Override
132 public Type getType() {
133 return type;
134 }
135
136
137
138
139
140
141 @Override
142 public void setText(Textual text) {
143 this.text = text;
144 }
145
146
147
148
149
150
151 @Override
152 public Textual getText() {
153 return text;
154 }
155
156
157
158
159
160
161 @Override
162 public void setBoundary(Rectangle rectangle) {
163 this.boundary = rectangle;
164 }
165
166
167
168
169
170
171 @Override
172 public Rectangle getBoundary() {
173 return boundary;
174 }
175
176
177
178
179
180
181 @Override
182 public void setFontSize(int size) {
183 this.fontSize = size;
184 }
185
186
187
188
189
190
191 @Override
192 public int getFontSize() {
193 return fontSize;
194 }
195
196
197
198
199
200
201 @Override
202 public void setFontType(String fontType) {
203 this.fontType = fontType;
204 }
205
206
207
208
209
210
211 @Override
212 public String getFontType() {
213 return fontType;
214 }
215
216
217
218
219
220
221
222 @Override
223 public void setSpatioTemporalLocator(SpatioTemporalLocator locator) {
224 this.locator = locator;
225 }
226
227
228
229
230
231
232 @Override
233 public SpatioTemporalLocator getSpatioTemporalLocator() {
234 return locator;
235 }
236
237
238
239
240
241
242 @Override
243 public Node toXml(Document document) {
244 DecimalFormat format = new DecimalFormat();
245 format.setDecimalFormatSymbols(standardSymbols);
246
247 Element videoText = document.createElement("VideoText");
248 videoText.setAttribute("id", id);
249 videoText.setAttribute("textType", type.toString());
250 if (fontSize > 0) {
251 videoText.setAttribute("fontSize", Integer.toString(fontSize));
252 }
253 if (fontType != null) {
254 videoText.setAttribute("fontType", fontType);
255 }
256
257
258 if (locator != null) {
259 videoText.appendChild(locator.toXml(document));
260 }
261
262
263 if (boundary != null) {
264 Element temporalMask = document.createElement("SpatioTemporalMask");
265 videoText.appendChild(temporalMask);
266
267 Element subRegion = document.createElement("SubRegion");
268 temporalMask.appendChild(subRegion);
269 Element parameterTrajectory = document.createElement("ParameterTrajectory");
270 subRegion.appendChild(parameterTrajectory);
271
272 parameterTrajectory.appendChild(new MediaTimeImpl(new MediaTimePointImpl(), null).toXml(document));
273 Element initialRegion = document.createElement("InitialRegion");
274 parameterTrajectory.appendChild(initialRegion);
275
276 StringBuffer coordinates = new StringBuffer();
277 coordinates.append(format.format(boundary.getX())).append(" ");
278 coordinates.append(format.format(boundary.getY())).append(" ");
279 coordinates.append(format.format(boundary.getX() + boundary.getWidth())).append(" ");
280 coordinates.append(format.format(boundary.getY() + boundary.getHeight()));
281
282 Element box = document.createElement("Box");
283 box.setAttribute("dim", "2 2");
284 box.appendChild(document.createTextNode(coordinates.toString()));
285 initialRegion.appendChild(box);
286 }
287
288
289 videoText.appendChild(text.toXml(document));
290 return videoText;
291 }
292
293 }