View Javadoc

1   /*
2    * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  /* $Id: Ms.java,v 923658a2b249 2009/09/11 09:57:31 max $ */
18  
19  package net.sourceforge.jeuclid.elements.presentation.token;
20  
21  import java.text.AttributedCharacterIterator;
22  
23  import net.sourceforge.jeuclid.LayoutContext;
24  import net.sourceforge.jeuclid.elements.support.GraphicsSupport;
25  import net.sourceforge.jeuclid.elements.support.attributes.MathVariant;
26  import net.sourceforge.jeuclid.elements.support.text.MultiAttributedCharacterIterator;
27  import net.sourceforge.jeuclid.elements.support.text.StringUtil;
28  import net.sourceforge.jeuclid.elements.support.text.TextContentModifier;
29  
30  import org.apache.batik.dom.AbstractDocument;
31  import org.w3c.dom.Node;
32  import org.w3c.dom.mathml.MathMLStringLitElement;
33  
34  /**
35   * This class represents string in a equation.
36   * 
37   * @version $Revision: 923658a2b249 $
38   */
39  public final class Ms extends AbstractTokenWithTextLayout implements
40          MathMLStringLitElement, TextContentModifier {
41  
42      /**
43       * The XML element from this class.
44       */
45      public static final String ELEMENT = "ms";
46  
47      /** Attribute for lquote. */
48      public static final String ATTR_LQUOTE = "lquote";
49  
50      /** Attribute for rquote. */
51      public static final String ATTR_RQUOTE = "rquote";
52  
53      private static final String VALUE_DOUBLEQUOTE = "\"";
54  
55      private static final long serialVersionUID = 1L;
56  
57      /**
58       * Default constructor. Sets MathML Namespace.
59       * 
60       * @param qname
61       *            Qualified name.
62       * @param odoc
63       *            Owner Document.
64       */
65      public Ms(final String qname, final AbstractDocument odoc) {
66          super(qname, odoc);
67          this.setDefaultMathAttribute(Ms.ATTR_LQUOTE, Ms.VALUE_DOUBLEQUOTE);
68          this.setDefaultMathAttribute(Ms.ATTR_RQUOTE, Ms.VALUE_DOUBLEQUOTE);
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      protected Node newNode() {
74          return new Ms(this.nodeName, this.ownerDocument);
75      }
76  
77      /**
78       * @param lquote
79       *            Left quote
80       */
81      public void setLquote(final String lquote) {
82          this.setAttribute(Ms.ATTR_LQUOTE, lquote);
83      }
84  
85      /**
86       * @return Left quote
87       */
88      public String getLquote() {
89          return this.getMathAttribute(Ms.ATTR_LQUOTE);
90      }
91  
92      /**
93       * @param rquote
94       *            Right quota
95       */
96      public void setRquote(final String rquote) {
97          this.setAttribute(Ms.ATTR_RQUOTE, rquote);
98      }
99  
100     /**
101      * @return Right quote
102      */
103     public String getRquote() {
104         return this.getMathAttribute(Ms.ATTR_RQUOTE);
105     }
106 
107     /** {@inheritDoc} */
108     public AttributedCharacterIterator modifyTextContent(
109             final AttributedCharacterIterator aci,
110             final LayoutContext layoutContext) {
111 
112         final float fontSizeInPoint = GraphicsSupport
113                 .getFontsizeInPoint(layoutContext);
114         final MathVariant variant = this.getMathvariantAsVariant();
115 
116         final MultiAttributedCharacterIterator maci = new MultiAttributedCharacterIterator();
117         maci.appendAttributedCharacterIterator(StringUtil
118                 .convertStringtoAttributedString(this.getLquote(), variant,
119                         fontSizeInPoint, layoutContext).getIterator());
120         maci.appendAttributedCharacterIterator(aci);
121         maci.appendAttributedCharacterIterator(StringUtil
122                 .convertStringtoAttributedString(this.getRquote(), variant,
123                         fontSizeInPoint, layoutContext).getIterator());
124         return maci;
125     }
126 
127 }