1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.elements.presentation.general;
20
21 import net.sourceforge.jeuclid.LayoutContext;
22 import net.sourceforge.jeuclid.context.Display;
23 import net.sourceforge.jeuclid.context.Parameter;
24 import net.sourceforge.jeuclid.elements.presentation.AbstractContainer;
25 import net.sourceforge.jeuclid.elements.support.attributes.AttributesHelper;
26
27 import org.apache.batik.dom.AbstractDocument;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.w3c.dom.Node;
31 import org.w3c.dom.mathml.MathMLStyleElement;
32
33
34
35
36
37
38 public final class Mstyle extends AbstractContainer implements
39 MathMLStyleElement {
40
41
42 public static final String ATTR_SCRIPTMINSIZE = "scriptminsize";
43
44
45 public static final String ATTR_SCRIPTLEVEL = "scriptlevel";
46
47
48 public static final String ATTR_SCRIPTSIZEMULTIPLIER = "scriptsizemultiplier";
49
50
51 public static final String ATTR_DISPLAYSTYLE = "displaystyle";
52
53
54
55
56 public static final String ELEMENT = "mstyle";
57
58
59
60
61 private static final Log LOGGER = LogFactory.getLog(Mstyle.class);
62
63 private static final long serialVersionUID = 1L;
64
65
66
67
68
69
70
71
72
73 public Mstyle(final String qname, final AbstractDocument odoc) {
74 super(qname, odoc);
75
76 this.setDefaultMathAttribute(Mstyle.ATTR_DISPLAYSTYLE, "");
77 }
78
79
80 @Override
81 protected Node newNode() {
82 return new Mstyle(this.nodeName, this.ownerDocument);
83 }
84
85
86
87
88 public String getScriptlevel() {
89 return this.getMathAttribute(Mstyle.ATTR_SCRIPTLEVEL);
90 }
91
92
93
94
95
96 public void setScriptlevel(final String scriptlevel) {
97 this.setAttribute(Mstyle.ATTR_SCRIPTLEVEL, scriptlevel);
98 }
99
100
101
102
103 public String getScriptminsize() {
104 return this.getMathAttribute(Mstyle.ATTR_SCRIPTMINSIZE);
105 }
106
107
108
109
110
111 public void setScriptminsize(final String scriptminsize) {
112 this.setAttribute(Mstyle.ATTR_SCRIPTMINSIZE, scriptminsize);
113 }
114
115 private class StyleLayoutContext implements LayoutContext {
116
117 private final LayoutContext context;
118
119 protected StyleLayoutContext(final LayoutContext parentContext) {
120 this.context = parentContext;
121 }
122
123 public Object getParameter(final Parameter which) {
124 Object retVal = Mstyle.this.applyLocalAttributesToContext(
125 this.context).getParameter(which);
126 if (Parameter.DISPLAY.equals(which)) {
127 retVal = this.applyDisplay(retVal);
128 } else if (Parameter.SCRIPTLEVEL.equals(which)) {
129 retVal = this.applyScriptlevel(retVal);
130 } else if (Parameter.SCRIPTMINSIZE.equals(which)) {
131 retVal = this.applyScriptMinsize(retVal);
132 }
133 return retVal;
134 }
135
136 private Object applyScriptMinsize(final Object parentLevel) {
137 final String newMinsize = Mstyle.this.getScriptminsize();
138 if ((newMinsize != null) && (newMinsize.length() > 0)) {
139 return AttributesHelper.convertSizeToPt(newMinsize,
140 this.context, AttributesHelper.PT);
141 } else {
142 return parentLevel;
143 }
144 }
145
146 private Object applyScriptlevel(final Object parentLevel) {
147 Object retVal = parentLevel;
148 String attr = Mstyle.this.getScriptlevel();
149 if (attr == null) {
150 attr = "";
151 }
152 attr = attr.trim();
153 if (attr.length() > 0) {
154 final char firstchar = attr.charAt(0);
155 boolean relative = false;
156 if (firstchar == '+') {
157 relative = true;
158 attr = attr.substring(1);
159 } else if (firstchar == '-') {
160 relative = true;
161 }
162 try {
163 final int iValue = Integer.parseInt(attr);
164 if (relative) {
165 retVal = (Integer) retVal + iValue;
166 } else {
167 retVal = iValue;
168 }
169 } catch (final NumberFormatException e) {
170 Mstyle.LOGGER
171 .warn("Error in scriptlevel attribute for mstyle: "
172 + attr);
173 }
174
175 }
176 return retVal;
177 }
178
179 private Object applyDisplay(final Object parentDisplay) {
180 Object retVal = parentDisplay;
181 final String displayStyle = Mstyle.this.getDisplaystyle();
182 if ("true".equalsIgnoreCase(displayStyle)) {
183 retVal = Display.BLOCK;
184 }
185 if ("false".equalsIgnoreCase(displayStyle)) {
186 retVal = Display.INLINE;
187 }
188 return retVal;
189 }
190 }
191
192
193 @Override
194 public LayoutContext getChildLayoutContext(final int childNum,
195 final LayoutContext context) {
196 return new Mstyle.StyleLayoutContext(context);
197 }
198
199
200 public String getBackground() {
201 return this.getMathbackground();
202 }
203
204
205 public String getColor() {
206 return this.getMathcolor();
207 }
208
209
210 public String getDisplaystyle() {
211 return this.getMathAttribute(Mstyle.ATTR_DISPLAYSTYLE);
212 }
213
214
215 public String getScriptsizemultiplier() {
216 return this.getMathAttribute(Mstyle.ATTR_SCRIPTSIZEMULTIPLIER);
217 }
218
219
220 public void setBackground(final String background) {
221 this.setMathbackground(background);
222 }
223
224
225 public void setColor(final String color) {
226 this.setMathcolor(color);
227 }
228
229
230 public void setDisplaystyle(final String displaystyle) {
231 this.setAttribute(Mstyle.ATTR_DISPLAYSTYLE, displaystyle);
232 }
233
234
235 public void setScriptsizemultiplier(final String scriptsizemultiplier) {
236 this.setAttribute(Mstyle.ATTR_SCRIPTSIZEMULTIPLIER,
237 scriptsizemultiplier);
238 }
239
240
241 public String getMediummathspace() {
242 throw new UnsupportedOperationException();
243
244 }
245
246
247 public String getNegativemediummathspace() {
248 throw new UnsupportedOperationException();
249
250 }
251
252
253 public String getNegativethickmathspace() {
254 throw new UnsupportedOperationException();
255
256 }
257
258
259 public String getNegativethinmathspace() {
260 throw new UnsupportedOperationException();
261
262 }
263
264
265 public String getNegativeverythickmathspace() {
266 throw new UnsupportedOperationException();
267
268 }
269
270
271 public String getNegativeverythinmathspace() {
272 throw new UnsupportedOperationException();
273
274 }
275
276
277 public String getNegativeveryverythickmathspace() {
278 throw new UnsupportedOperationException();
279
280 }
281
282
283 public String getNegativeveryverythinmathspace() {
284 throw new UnsupportedOperationException();
285
286 }
287
288
289 public String getThickmathspace() {
290 throw new UnsupportedOperationException();
291
292 }
293
294
295 public String getThinmathspace() {
296 throw new UnsupportedOperationException();
297
298 }
299
300
301 public String getVerythickmathspace() {
302 throw new UnsupportedOperationException();
303
304 }
305
306
307 public String getVerythinmathspace() {
308 throw new UnsupportedOperationException();
309
310 }
311
312
313 public String getVeryverythickmathspace() {
314 throw new UnsupportedOperationException();
315
316 }
317
318
319 public String getVeryverythinmathspace() {
320 throw new UnsupportedOperationException();
321
322 }
323
324
325 public void setMediummathspace(final String mediummathspace) {
326 throw new UnsupportedOperationException();
327
328 }
329
330
331 public void setNegativemediummathspace(final String negativemediummathspace) {
332 throw new UnsupportedOperationException();
333
334 }
335
336
337 public void setNegativethickmathspace(final String negativethickmathspace) {
338 throw new UnsupportedOperationException();
339
340 }
341
342
343 public void setNegativethinmathspace(final String negativethinmathspace) {
344 throw new UnsupportedOperationException();
345
346 }
347
348
349 public void setNegativeverythickmathspace(
350 final String negativeverythickmathspace) {
351 throw new UnsupportedOperationException();
352
353 }
354
355
356 public void setNegativeverythinmathspace(
357 final String negativeverythinmathspace) {
358 throw new UnsupportedOperationException();
359
360 }
361
362
363 public void setNegativeveryverythickmathspace(
364 final String negativeveryverythickmathspace) {
365 throw new UnsupportedOperationException();
366
367 }
368
369
370 public void setNegativeveryverythinmathspace(
371 final String negativeveryverythinmathspace) {
372 throw new UnsupportedOperationException();
373
374 }
375
376
377 public void setThickmathspace(final String thickmathspace) {
378 throw new UnsupportedOperationException();
379
380 }
381
382
383 public void setThinmathspace(final String thinmathspace) {
384 throw new UnsupportedOperationException();
385
386 }
387
388
389 public void setVerythickmathspace(final String verythickmathspace) {
390 throw new UnsupportedOperationException();
391
392 }
393
394
395 public void setVerythinmathspace(final String verythinmathspace) {
396 throw new UnsupportedOperationException();
397
398 }
399
400
401 public void setVeryverythickmathspace(final String veryverythickmathspace) {
402 throw new UnsupportedOperationException();
403
404 }
405
406
407 public void setVeryverythinmathspace(final String veryverythinmathspace) {
408 throw new UnsupportedOperationException();
409
410 }
411
412 }