001 /* 002 * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 /* $Id: Mspace.java,v b2e8c71e4a50 2009/09/10 14:00:50 max $ */ 018 019 package net.sourceforge.jeuclid.elements.presentation.token; 020 021 import net.sourceforge.jeuclid.Constants; 022 import net.sourceforge.jeuclid.LayoutContext; 023 import net.sourceforge.jeuclid.elements.AbstractJEuclidElement; 024 import net.sourceforge.jeuclid.elements.support.attributes.AttributesHelper; 025 import net.sourceforge.jeuclid.layout.LayoutInfo; 026 import net.sourceforge.jeuclid.layout.LayoutStage; 027 import net.sourceforge.jeuclid.layout.LayoutView; 028 029 import org.apache.batik.dom.AbstractDocument; 030 import org.w3c.dom.Node; 031 import org.w3c.dom.mathml.MathMLSpaceElement; 032 033 /** 034 * This class presents a mspace. 035 * 036 * <p> 037 * TODO: linebreak is unimplemented 038 * 039 * @version $Revision: b2e8c71e4a50 $ 040 */ 041 public final class Mspace extends AbstractJEuclidElement implements 042 MathMLSpaceElement { 043 044 /** 045 * The XML element from this class. 046 */ 047 public static final String ELEMENT = "mspace"; 048 049 /** Attribute for width. */ 050 public static final String ATTR_WIDTH = "width"; 051 052 /** Attribute for height. */ 053 public static final String ATTR_HEIGHT = "height"; 054 055 /** Attribute for depth. */ 056 public static final String ATTR_DEPTH = "depth"; 057 058 /** Attribute for linebreak. */ 059 public static final String ATTR_LINEBREAK = "linebreak"; 060 061 private static final long serialVersionUID = 1L; 062 063 /** 064 * Default constructor. Sets MathML Namespace. 065 * 066 * @param qname 067 * Qualified name. 068 * @param odoc 069 * Owner Document. 070 */ 071 public Mspace(final String qname, final AbstractDocument odoc) { 072 super(qname, odoc); 073 074 this.setDefaultMathAttribute(Mspace.ATTR_DEPTH, Constants.ZERO); 075 this.setDefaultMathAttribute(Mspace.ATTR_HEIGHT, Constants.ZERO); 076 this.setDefaultMathAttribute(Mspace.ATTR_WIDTH, Constants.ZERO); 077 this.setDefaultMathAttribute(Mspace.ATTR_LINEBREAK, "auto"); 078 } 079 080 /** {@inheritDoc} */ 081 @Override 082 protected Node newNode() { 083 return new Mspace(this.nodeName, this.ownerDocument); 084 } 085 086 /** 087 * @return Space width 088 */ 089 public String getWidth() { 090 return this.getMathAttribute(Mspace.ATTR_WIDTH); 091 } 092 093 /** 094 * @param width 095 * Space width 096 */ 097 public void setWidth(final String width) { 098 this.setAttribute(Mspace.ATTR_WIDTH, width); 099 } 100 101 /** 102 * @return Space height 103 */ 104 public String getHeight() { 105 return this.getMathAttribute(Mspace.ATTR_HEIGHT); 106 } 107 108 /** 109 * @param height 110 * Space height 111 */ 112 public void setHeight(final String height) { 113 this.setAttribute(Mspace.ATTR_HEIGHT, height); 114 } 115 116 /** 117 * @return Space depth 118 */ 119 public String getDepth() { 120 return this.getMathAttribute(Mspace.ATTR_DEPTH); 121 } 122 123 /** 124 * @param depth 125 * Space depth 126 */ 127 public void setDepth(final String depth) { 128 this.setAttribute(Mspace.ATTR_DEPTH, depth); 129 } 130 131 /** {@inheritDoc} */ 132 @Override 133 protected void layoutStageInvariant(final LayoutView view, 134 final LayoutInfo info, final LayoutStage stage, 135 final LayoutContext context) { 136 final LayoutContext now = this.applyLocalAttributesToContext(context); 137 info.setAscentHeight(AttributesHelper.convertSizeToPt(this.getHeight(), 138 now, AttributesHelper.PT), stage); 139 info.setDescentHeight(AttributesHelper.convertSizeToPt(this.getDepth(), 140 now, AttributesHelper.PT), stage); 141 info.setWidth(AttributesHelper.convertSizeToPt(this.getWidth(), now, 142 AttributesHelper.PT), stage); 143 } 144 145 /** {@inheritDoc} */ 146 public String getLinebreak() { 147 return this.getMathAttribute(Mspace.ATTR_LINEBREAK); 148 } 149 150 /** {@inheritDoc} */ 151 public void setLinebreak(final String linebreak) { 152 this.setAttribute(Mspace.ATTR_LINEBREAK, linebreak); 153 } 154 }