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 @Override
101 public void setIdentifier(String id) {
102 this.id = id;
103 }
104
105
106
107
108
109
110 @Override
111 public String getIdentifier() {
112 return id;
113 }
114
115
116
117
118
119
120 @Override
121 public void setType(Type type) {
122 this.type = type;
123 }
124
125
126
127
128
129
130 @Override
131 public Type getType() {
132 return type;
133 }
134
135
136
137
138
139
140 @Override
141 public void setText(Textual text) {
142 this.text = text;
143 }
144
145
146
147
148
149
150 @Override
151 public Textual getText() {
152 return text;
153 }
154
155
156
157
158
159
160 @Override
161 public void setBoundary(Rectangle rectangle) {
162 this.boundary = rectangle;
163 }
164
165
166
167
168
169
170 @Override
171 public Rectangle getBoundary() {
172 return boundary;
173 }
174
175
176
177
178
179
180 @Override
181 public void setFontSize(int size) {
182 this.fontSize = size;
183 }
184
185
186
187
188
189
190 @Override
191 public int getFontSize() {
192 return fontSize;
193 }
194
195
196
197
198
199
200 @Override
201 public void setFontType(String fontType) {
202 this.fontType = fontType;
203 }
204
205
206
207
208
209
210 @Override
211 public String getFontType() {
212 return fontType;
213 }
214
215
216
217
218
219
220 @Override
221 public void setSpatioTemporalLocator(SpatioTemporalLocator locator) {
222 this.locator = locator;
223 }
224
225
226
227
228
229
230 @Override
231 public SpatioTemporalLocator getSpatioTemporalLocator() {
232 return locator;
233 }
234
235
236
237
238
239
240 @Override
241 public Node toXml(Document document) {
242 DecimalFormat format = new DecimalFormat();
243 format.setDecimalFormatSymbols(standardSymbols);
244
245 Element videoText = document.createElement("VideoText");
246 videoText.setAttribute("id", id);
247 videoText.setAttribute("textType", type.toString());
248 if (fontSize > 0)
249 videoText.setAttribute("fontSize", Integer.toString(fontSize));
250 if (fontType != null)
251 videoText.setAttribute("fontType", fontType);
252
253
254 if (locator != null)
255 videoText.appendChild(locator.toXml(document));
256
257
258 if (boundary != null) {
259 Element temporalMask = document.createElement("SpatioTemporalMask");
260 videoText.appendChild(temporalMask);
261
262 Element subRegion = document.createElement("SubRegion");
263 temporalMask.appendChild(subRegion);
264 Element parameterTrajectory = document.createElement("ParameterTrajectory");
265 subRegion.appendChild(parameterTrajectory);
266
267 parameterTrajectory.appendChild(new MediaTimeImpl(new MediaTimePointImpl(), null).toXml(document));
268 Element initialRegion = document.createElement("InitialRegion");
269 parameterTrajectory.appendChild(initialRegion);
270
271 StringBuffer coordinates = new StringBuffer();
272 coordinates.append(format.format(boundary.getX())).append(" ");
273 coordinates.append(format.format(boundary.getY())).append(" ");
274 coordinates.append(format.format(boundary.getX() + boundary.getWidth())).append(" ");
275 coordinates.append(format.format(boundary.getY() + boundary.getHeight()));
276
277 Element box = document.createElement("Box");
278 box.setAttribute("dim", "2 2");
279 box.appendChild(document.createTextNode(coordinates.toString()));
280 initialRegion.appendChild(box);
281 }
282
283
284 videoText.appendChild(text.toXml(document));
285 return videoText;
286 }
287
288 }