Back to index

lightning-sunbird  0.9+nobinonly
nsMathMLOperators.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla MathML Project.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * The University Of Queensland.
00018  * Portions created by the Initial Developer are Copyright (C) 1999
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Roger B. Sidje <rbs@maths.uq.edu.au>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsMathMLOperators_h___
00039 #define nsMathMLOperators_h___
00040 
00041 #include "nsCoord.h"
00042 
00043 typedef PRUint32 nsOperatorFlags;
00044 typedef PRInt32 nsStretchDirection;
00045 
00046 #define NS_STRETCH_DIRECTION_UNSUPPORTED  -1
00047 #define NS_STRETCH_DIRECTION_DEFAULT       0
00048 #define NS_STRETCH_DIRECTION_HORIZONTAL    1
00049 #define NS_STRETCH_DIRECTION_VERTICAL      2
00050 
00051 // define the bits used to handle the operator
00052 
00053 #define NS_MATHML_OPERATOR_MUTABLE            (1<<31)
00054 #define NS_MATHML_OPERATOR_EMBELLISH_ANCESTOR (1<<30)
00055 #define NS_MATHML_OPERATOR_EMBELLISH_ISOLATED (1<<29)
00056 #define NS_MATHML_OPERATOR_CENTERED           (1<<28)
00057 #define NS_MATHML_OPERATOR_INVISIBLE          (1<<27)
00058 
00059 // define the bits used in the Operator Dictionary
00060 
00061 #define NS_MATHML_OPERATOR_FORM  0x3 // the very last two bits tell us the form
00062 #define     NS_MATHML_OPERATOR_FORM_INFIX      1
00063 #define     NS_MATHML_OPERATOR_FORM_PREFIX     2
00064 #define     NS_MATHML_OPERATOR_FORM_POSTFIX    3
00065 #define NS_MATHML_OPERATOR_STRETCHY 0xC // the 2 penultimate last bits are used
00066 #define     NS_MATHML_OPERATOR_STRETCHY_VERT  (1<<2)
00067 #define     NS_MATHML_OPERATOR_STRETCHY_HORIZ (1<<3)
00068 #define NS_MATHML_OPERATOR_FENCE              (1<<4)
00069 #define NS_MATHML_OPERATOR_ACCENT             (1<<5)
00070 #define NS_MATHML_OPERATOR_LARGEOP            (1<<6)
00071 #define NS_MATHML_OPERATOR_SEPARATOR          (1<<7)
00072 #define NS_MATHML_OPERATOR_MOVABLELIMITS      (1<<8)
00073 #define NS_MATHML_OPERATOR_SYMMETRIC          (1<<9)
00074 
00075 // Additional bits not stored in the dictionary
00076 
00077 #define NS_MATHML_OPERATOR_MINSIZE_EXPLICIT   (1<<10)
00078 #define NS_MATHML_OPERATOR_MAXSIZE_EXPLICIT   (1<<11)
00079 #define NS_MATHML_OPERATOR_LEFTSPACE_ATTR     (1<<12)
00080 #define NS_MATHML_OPERATOR_RIGHTSPACE_ATTR    (1<<13)
00081 
00082 
00083 class nsMathMLOperators {
00084 public:
00085   static void AddRefTable(void);
00086   static void ReleaseTable(void);
00087 
00088   // LookupOperator:
00089   // Given the string value of an operator and its form (last two bits of flags),
00090   // this method returns true if the operator is found in the Operator Dictionary.
00091   // Attributes of the operator are returned in the output parameters.
00092   // If the operator is not found under the supplied form but is found under a 
00093   // different form, the method returns true as well. The caller can test the
00094   // output parameter aFlags to know exactly under which form the operator was
00095   // found in the Operator Dictionary.
00096   static PRBool
00097   LookupOperator(const nsString&       aOperator,
00098                  const nsOperatorFlags aForm,
00099                  nsOperatorFlags*      aFlags,
00100                  float*                aLeftSpace,
00101                  float*                aRightSpace);
00102 
00103    // LookupOperators:
00104    // Helper to return all the forms under which an operator is listed in the
00105    // Operator Dictionary. The caller must pass arrays of size 4, and use 
00106    // aFlags[NS_MATHML_OPERATOR_FORM_{INFIX|POSTFIX|PREFIX}], aLeftSpace[], etc,
00107    // to access the attributes of the operator under a particular form. If the
00108    // operator wasn't found under a form, its entry aFlags[form] is set to zero.
00109    static void
00110    LookupOperators(const nsString&       aOperator,
00111                    nsOperatorFlags*      aFlags,
00112                    float*                aLeftSpace,
00113                    float*                aRightSpace);
00114 
00115   // IsMutableOperator:
00116   // Return true if the operator exists and is stretchy or largeop
00117   static PRBool
00118   IsMutableOperator(const nsString& aOperator);
00119 
00120   // Helper functions for stretchy operators. These are used by the
00121   // nsMathMLChar class.
00122   static PRInt32 CountStretchyOperator();
00123   static PRInt32 FindStretchyOperator(PRUnichar aOperator);
00124   static nsStretchDirection GetStretchyDirectionAt(PRInt32 aIndex);
00125   static void DisableStretchyOperatorAt(PRInt32 aIndex);
00126 
00127 
00128   // Style invariant chararacters (chars have their own intrinsic predefined style)
00129   enum eMATHVARIANT {
00130     eMATHVARIANT_NONE = -1,
00131     eMATHVARIANT_normal = 0,
00132     eMATHVARIANT_bold,
00133     eMATHVARIANT_italic,
00134     eMATHVARIANT_bold_italic,
00135     eMATHVARIANT_sans_serif,
00136     eMATHVARIANT_bold_sans_serif,
00137     eMATHVARIANT_sans_serif_italic,
00138     eMATHVARIANT_sans_serif_bold_italic,
00139     eMATHVARIANT_monospace,
00140     eMATHVARIANT_script,
00141     eMATHVARIANT_bold_script,
00142     eMATHVARIANT_fraktur,
00143     eMATHVARIANT_bold_fraktur,
00144     eMATHVARIANT_double_struck,
00145     eMATHVARIANT_COUNT
00146   };
00147   static PRBool LookupInvariantChar(PRUnichar     aChar,
00148                                     eMATHVARIANT* aType = nsnull);
00149 };
00150 
00151 
00153 // Macros that retrieve the bits used to handle operators
00154 
00155 #define NS_MATHML_OPERATOR_IS_MUTABLE(_flags) \
00156   (NS_MATHML_OPERATOR_MUTABLE == ((_flags) & NS_MATHML_OPERATOR_MUTABLE))
00157 
00158 #define NS_MATHML_OPERATOR_HAS_EMBELLISH_ANCESTOR(_flags) \
00159   (NS_MATHML_OPERATOR_EMBELLISH_ANCESTOR == ((_flags) & NS_MATHML_OPERATOR_EMBELLISH_ANCESTOR))
00160 
00161 #define NS_MATHML_OPERATOR_EMBELLISH_IS_ISOLATED(_flags) \
00162   (NS_MATHML_OPERATOR_EMBELLISH_ISOLATED == ((_flags) & NS_MATHML_OPERATOR_EMBELLISH_ISOLATED))
00163 
00164 #define NS_MATHML_OPERATOR_IS_CENTERED(_flags) \
00165   (NS_MATHML_OPERATOR_CENTERED == ((_flags) & NS_MATHML_OPERATOR_CENTERED))
00166 
00167 #define NS_MATHML_OPERATOR_IS_INVISIBLE(_flags) \
00168   (NS_MATHML_OPERATOR_INVISIBLE == ((_flags) & NS_MATHML_OPERATOR_INVISIBLE))
00169 
00170 #define NS_MATHML_OPERATOR_GET_FORM(_flags) \
00171   ((_flags) & NS_MATHML_OPERATOR_FORM)
00172 
00173 #define NS_MATHML_OPERATOR_GET_STRETCHY_DIR(_flags) \
00174   ((_flags) & NS_MATHML_OPERATOR_STRETCHY)
00175 
00176 #define NS_MATHML_OPERATOR_FORM_IS_INFIX(_flags) \
00177   (NS_MATHML_OPERATOR_FORM_INFIX == ((_flags) & NS_MATHML_OPERATOR_FORM_INFIX))
00178 
00179 #define NS_MATHML_OPERATOR_FORM_IS_PREFIX(_flags) \
00180   (NS_MATHML_OPERATOR_FORM_PREFIX == ((_flags) & NS_MATHML_OPERATOR_FORM_PREFIX))
00181 
00182 #define NS_MATHML_OPERATOR_FORM_IS_POSTFIX(_flags) \
00183   (NS_MATHML_OPERATOR_FORM_POSTFIX == ((_flags) & NS_MATHML_OPERATOR_FORM_POSTFIX ))
00184 
00185 #define NS_MATHML_OPERATOR_IS_STRETCHY(_flags) \
00186   (0 != ((_flags) & NS_MATHML_OPERATOR_STRETCHY))
00187 
00188 #define NS_MATHML_OPERATOR_IS_STRETCHY_VERT(_flags) \
00189   (NS_MATHML_OPERATOR_STRETCHY_VERT == ((_flags) & NS_MATHML_OPERATOR_STRETCHY_VERT))
00190 
00191 #define NS_MATHML_OPERATOR_IS_STRETCHY_HORIZ(_flags) \
00192   (NS_MATHML_OPERATOR_STRETCHY_HORIZ == ((_flags) & NS_MATHML_OPERATOR_STRETCHY_HORIZ))
00193 
00194 #define NS_MATHML_OPERATOR_IS_FENCE(_flags) \
00195   (NS_MATHML_OPERATOR_FENCE == ((_flags) & NS_MATHML_OPERATOR_FENCE))
00196 
00197 #define NS_MATHML_OPERATOR_IS_ACCENT(_flags) \
00198   (NS_MATHML_OPERATOR_ACCENT == ((_flags) & NS_MATHML_OPERATOR_ACCENT))
00199 
00200 #define NS_MATHML_OPERATOR_IS_LARGEOP(_flags) \
00201   (NS_MATHML_OPERATOR_LARGEOP == ((_flags) & NS_MATHML_OPERATOR_LARGEOP))
00202 
00203 #define NS_MATHML_OPERATOR_IS_SEPARATOR(_flags) \
00204   (NS_MATHML_OPERATOR_SEPARATOR == ((_flags) & NS_MATHML_OPERATOR_SEPARATOR))
00205 
00206 #define NS_MATHML_OPERATOR_IS_MOVABLELIMITS(_flags) \
00207   (NS_MATHML_OPERATOR_MOVABLELIMITS == ((_flags) & NS_MATHML_OPERATOR_MOVABLELIMITS))
00208 
00209 #define NS_MATHML_OPERATOR_IS_SYMMETRIC(_flags) \
00210   (NS_MATHML_OPERATOR_SYMMETRIC == ((_flags) & NS_MATHML_OPERATOR_SYMMETRIC))
00211 
00212 #define NS_MATHML_OPERATOR_MINSIZE_IS_EXPLICIT(_flags) \
00213   (NS_MATHML_OPERATOR_MINSIZE_EXPLICIT == ((_flags) & NS_MATHML_OPERATOR_MINSIZE_EXPLICIT))
00214 
00215 #define NS_MATHML_OPERATOR_MAXSIZE_IS_EXPLICIT(_flags) \
00216   (NS_MATHML_OPERATOR_MAXSIZE_EXPLICIT == ((_flags) & NS_MATHML_OPERATOR_MAXSIZE_EXPLICIT))
00217 
00218 #define NS_MATHML_OPERATOR_HAS_LEFTSPACE_ATTR(_flags) \
00219   (NS_MATHML_OPERATOR_LEFTSPACE_ATTR == ((_flags) & NS_MATHML_OPERATOR_LEFTSPACE_ATTR))
00220 
00221 #define NS_MATHML_OPERATOR_HAS_RIGHTSPACE_ATTR(_flags) \
00222   (NS_MATHML_OPERATOR_RIGHTSPACE_ATTR == ((_flags) & NS_MATHML_OPERATOR_RIGHTSPACE_ATTR))
00223 
00224 #endif /* nsMathMLOperators_h___ */