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: Ms.java,v 923658a2b249 2009/09/11 09:57:31 max $ */ 018 019 package net.sourceforge.jeuclid.elements.presentation.token; 020 021 import java.text.AttributedCharacterIterator; 022 023 import net.sourceforge.jeuclid.LayoutContext; 024 import net.sourceforge.jeuclid.elements.support.GraphicsSupport; 025 import net.sourceforge.jeuclid.elements.support.attributes.MathVariant; 026 import net.sourceforge.jeuclid.elements.support.text.MultiAttributedCharacterIterator; 027 import net.sourceforge.jeuclid.elements.support.text.StringUtil; 028 import net.sourceforge.jeuclid.elements.support.text.TextContentModifier; 029 030 import org.apache.batik.dom.AbstractDocument; 031 import org.w3c.dom.Node; 032 import org.w3c.dom.mathml.MathMLStringLitElement; 033 034 /** 035 * This class represents string in a equation. 036 * 037 * @version $Revision: 923658a2b249 $ 038 */ 039 public final class Ms extends AbstractTokenWithTextLayout implements 040 MathMLStringLitElement, TextContentModifier { 041 042 /** 043 * The XML element from this class. 044 */ 045 public static final String ELEMENT = "ms"; 046 047 /** Attribute for lquote. */ 048 public static final String ATTR_LQUOTE = "lquote"; 049 050 /** Attribute for rquote. */ 051 public static final String ATTR_RQUOTE = "rquote"; 052 053 private static final String VALUE_DOUBLEQUOTE = "\""; 054 055 private static final long serialVersionUID = 1L; 056 057 /** 058 * Default constructor. Sets MathML Namespace. 059 * 060 * @param qname 061 * Qualified name. 062 * @param odoc 063 * Owner Document. 064 */ 065 public Ms(final String qname, final AbstractDocument odoc) { 066 super(qname, odoc); 067 this.setDefaultMathAttribute(Ms.ATTR_LQUOTE, Ms.VALUE_DOUBLEQUOTE); 068 this.setDefaultMathAttribute(Ms.ATTR_RQUOTE, Ms.VALUE_DOUBLEQUOTE); 069 } 070 071 /** {@inheritDoc} */ 072 @Override 073 protected Node newNode() { 074 return new Ms(this.nodeName, this.ownerDocument); 075 } 076 077 /** 078 * @param lquote 079 * Left quote 080 */ 081 public void setLquote(final String lquote) { 082 this.setAttribute(Ms.ATTR_LQUOTE, lquote); 083 } 084 085 /** 086 * @return Left quote 087 */ 088 public String getLquote() { 089 return this.getMathAttribute(Ms.ATTR_LQUOTE); 090 } 091 092 /** 093 * @param rquote 094 * Right quota 095 */ 096 public void setRquote(final String rquote) { 097 this.setAttribute(Ms.ATTR_RQUOTE, rquote); 098 } 099 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 }