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