From 48dd7c0e78e770d8399e08c439371ff6fea13434 Mon Sep 17 00:00:00 2001 From: "rbs%maths.uq.edu.au" Date: Fri, 10 Dec 1999 12:47:24 +0000 Subject: [PATCH] [NOT PART OF THE DEFAULT BUILD]. *Postfixed all atoms with underscore to avoid conflicts with predefined names in C++ and math.h. *Changed MathML namescape to the new officially published namespace. git-svn-id: svn://10.0.0.236/trunk@55847 18797224-902f-48f8-a5cc-f745e15eee43 --- .../mathml/content/src/nsMathMLAtomList.h | 277 +++++++++--------- .../mathml/content/src/nsMathMLAtoms.cpp | 2 +- .../mathml/content/src/nsMathMLOperators.cpp | 49 +++- .../mathml/content/src/nsMathMLOperators.h | 18 +- 4 files changed, 201 insertions(+), 145 deletions(-) diff --git a/mozilla/layout/mathml/content/src/nsMathMLAtomList.h b/mozilla/layout/mathml/content/src/nsMathMLAtomList.h index 8f8ce9dc77c..c250984733f 100644 --- a/mozilla/layout/mathml/content/src/nsMathMLAtomList.h +++ b/mozilla/layout/mathml/content/src/nsMathMLAtomList.h @@ -38,141 +38,142 @@ ******/ -MATHML_ATOM(abs, "abs") -MATHML_ATOM(accent, "accent") -MATHML_ATOM(and, "and") -MATHML_ATOM(annotation, "annotation") -MATHML_ATOM(apply, "apply") -MATHML_ATOM(arccos, "arccos") -MATHML_ATOM(arcsin, "arcsin") -MATHML_ATOM(arctan, "arctan") -MATHML_ATOM(bvar, "bvar") -MATHML_ATOM(ci, "ci") -MATHML_ATOM(close, "close") -MATHML_ATOM(cn, "cn") -MATHML_ATOM(compose, "compose") -MATHML_ATOM(condition, "condition") -MATHML_ATOM(conjugate, "conjugate") -MATHML_ATOM(cos, "cos") -MATHML_ATOM(cosh, "cosh") -MATHML_ATOM(cot, "cot") -MATHML_ATOM(coth, "coth") -MATHML_ATOM(csc, "csc") -MATHML_ATOM(csch, "csch") -MATHML_ATOM(declare, "declare") -MATHML_ATOM(degree, "degree") -MATHML_ATOM(determinant, "determinant") -MATHML_ATOM(diff, "diff") -MATHML_ATOM(displaystyle, "displaystyle") -MATHML_ATOM(divide, "divide") -MATHML_ATOM(eq, "eq") -MATHML_ATOM(exists, "exists") -MATHML_ATOM(exp, "exp") -MATHML_ATOM(factorial, "factorial") -MATHML_ATOM(fence, "fence") -MATHML_ATOM(fn, "fn") -MATHML_ATOM(forall, "forall") -MATHML_ATOM(form, "form") -MATHML_ATOM(geq, "geq") -MATHML_ATOM(gt, "gt") -MATHML_ATOM(ident, "ident") -MATHML_ATOM(implies, "implies") -MATHML_ATOM(in, "in") -MATHML_ATOM(_int, "int") -MATHML_ATOM(intersect, "intersect") -MATHML_ATOM(interval, "interval") -MATHML_ATOM(inverse, "inverse") -MATHML_ATOM(lambda, "lambda") -MATHML_ATOM(largeop, "largeop") -MATHML_ATOM(leq, "leq") -MATHML_ATOM(limit, "limit") -MATHML_ATOM(linethickness, "linethickness") -MATHML_ATOM(list, "list") -MATHML_ATOM(ln, "ln") -MATHML_ATOM(log, "log") -MATHML_ATOM(logbase, "logbase") -MATHML_ATOM(lowlimit, "lowlimit") -MATHML_ATOM(lt, "lt") -MATHML_ATOM(maction, "maction") -MATHML_ATOM(maligngroup, "maligngroup") -MATHML_ATOM(malignmark, "malignmark") -MATHML_ATOM(math, "math") -MATHML_ATOM(matrix, "matrix") -MATHML_ATOM(matrixrow, "matrixrow") -MATHML_ATOM(max, "max") -MATHML_ATOM(mean, "mean") -MATHML_ATOM(median, "median") -MATHML_ATOM(merror, "merror") -MATHML_ATOM(mfenced, "mfenced") -MATHML_ATOM(mfrac, "mfrac") -MATHML_ATOM(mi, "mi") -MATHML_ATOM(min, "min") -MATHML_ATOM(minus, "minus") -MATHML_ATOM(mmultiscripts, "mmultiscripts") -MATHML_ATOM(mn, "mn") -MATHML_ATOM(mo, "mo") -MATHML_ATOM(mode, "mode") -MATHML_ATOM(moment, "moment") -MATHML_ATOM(movablelimits, "movablelimits") -MATHML_ATOM(mover, "mover") -MATHML_ATOM(mpadded, "mpadded") -MATHML_ATOM(mphantom, "mphantom") -MATHML_ATOM(mprescripts, "mprescripts") -MATHML_ATOM(mroot, "mroot") -MATHML_ATOM(mrow, "mrow") -MATHML_ATOM(ms, "ms") -MATHML_ATOM(mspace, "mspace") -MATHML_ATOM(msqrt, "msqrt") -MATHML_ATOM(mstyle, "mstyle") -MATHML_ATOM(msub, "msub") -MATHML_ATOM(msubsup, "msubsup") -MATHML_ATOM(msup, "msup") -MATHML_ATOM(mtable, "mtable") -MATHML_ATOM(mtd, "mtd") -MATHML_ATOM(mtext, "mtext") -MATHML_ATOM(mtr, "mtr") -MATHML_ATOM(munder, "munder") -MATHML_ATOM(munderover, "munderover") -MATHML_ATOM(neq, "neq") -MATHML_ATOM(none, "none") -MATHML_ATOM(not, "not") -MATHML_ATOM(notin, "notin") -MATHML_ATOM(notprsubset, "notprsubset") -MATHML_ATOM(notsubset, "notsubset") -MATHML_ATOM(open, "open") -MATHML_ATOM(or, "or") -MATHML_ATOM(partialdiff, "partialdiff") -MATHML_ATOM(plus, "plus") -MATHML_ATOM(power, "power") -MATHML_ATOM(product, "product") -MATHML_ATOM(prsubset, "prsubset") -MATHML_ATOM(quotient, "quotient") -MATHML_ATOM(reln, "reln") -MATHML_ATOM(rem, "rem") -MATHML_ATOM(root, "root") -MATHML_ATOM(scriptlevel, "scriptlevel") -MATHML_ATOM(sdev, "sdev") -MATHML_ATOM(sec, "sec") -MATHML_ATOM(sech, "sech") -MATHML_ATOM(select, "select") -MATHML_ATOM(semantics, "semantics") -MATHML_ATOM(sep, "sep") -MATHML_ATOM(separator, "separator") -MATHML_ATOM(separators, "separators") -MATHML_ATOM(set, "set") -MATHML_ATOM(setdiff, "setdiff") -MATHML_ATOM(sin, "sin") -MATHML_ATOM(sinh, "sinh") -MATHML_ATOM(stretchy, "stretchy") -MATHML_ATOM(subset, "subset") -MATHML_ATOM(sum, "sum") -MATHML_ATOM(tan, "tan") -MATHML_ATOM(tanh, "tanh") -MATHML_ATOM(tendsto, "tendsto") -MATHML_ATOM(times, "times") -MATHML_ATOM(transpose, "transpose") -MATHML_ATOM(_union, "union") -MATHML_ATOM(uplimit, "uplimit") -MATHML_ATOM(var, "var") -MATHML_ATOM(vector, "vector") -MATHML_ATOM(xor, "xor") +MATHML_ATOM(abs_, "abs") +MATHML_ATOM(accent_, "accent") +MATHML_ATOM(and_, "and") +MATHML_ATOM(annotation_, "annotation") +MATHML_ATOM(apply_, "apply") +MATHML_ATOM(arccos_, "arccos") +MATHML_ATOM(arcsin_, "arcsin") +MATHML_ATOM(arctan_, "arctan") +MATHML_ATOM(bvar_, "bvar") +MATHML_ATOM(ci_, "ci") +MATHML_ATOM(close_, "close") +MATHML_ATOM(cn_, "cn") +MATHML_ATOM(compose_, "compose") +MATHML_ATOM(condition_, "condition") +MATHML_ATOM(conjugate_, "conjugate") +MATHML_ATOM(cos_, "cos") +MATHML_ATOM(cosh_, "cosh") +MATHML_ATOM(cot_, "cot") +MATHML_ATOM(coth_, "coth") +MATHML_ATOM(csc_, "csc") +MATHML_ATOM(csch_, "csch") +MATHML_ATOM(declare_, "declare") +MATHML_ATOM(degree_, "degree") +MATHML_ATOM(determinant_, "determinant") +MATHML_ATOM(diff_, "diff") +MATHML_ATOM(displaystyle_, "displaystyle") +MATHML_ATOM(divide_, "divide") +MATHML_ATOM(eq_, "eq") +MATHML_ATOM(exists_, "exists") +MATHML_ATOM(exp_, "exp") +MATHML_ATOM(factorial_, "factorial") +MATHML_ATOM(fence_, "fence") +MATHML_ATOM(fn_, "fn") +MATHML_ATOM(forall_, "forall") +MATHML_ATOM(form_, "form") +MATHML_ATOM(geq_, "geq") +MATHML_ATOM(gt_, "gt") +MATHML_ATOM(ident_, "ident") +MATHML_ATOM(implies_, "implies") +MATHML_ATOM(in_, "in") +MATHML_ATOM(int_, "int") +MATHML_ATOM(intersect_, "intersect") +MATHML_ATOM(interval_, "interval") +MATHML_ATOM(inverse_, "inverse") +MATHML_ATOM(lambda_, "lambda") +MATHML_ATOM(largeop_, "largeop") +MATHML_ATOM(leq_, "leq") +MATHML_ATOM(limit_, "limit") +MATHML_ATOM(linethickness_, "linethickness") +MATHML_ATOM(list_, "list") +MATHML_ATOM(ln_, "ln") +MATHML_ATOM(log_, "log") +MATHML_ATOM(logbase_, "logbase") +MATHML_ATOM(lowlimit_, "lowlimit") +MATHML_ATOM(lt_, "lt") +MATHML_ATOM(maction_, "maction") +MATHML_ATOM(maligngroup_, "maligngroup") +MATHML_ATOM(malignmark_, "malignmark") +MATHML_ATOM(math, "math") // only one without an underscore +MATHML_ATOM(matrix_, "matrix") +MATHML_ATOM(matrixrow_, "matrixrow") +MATHML_ATOM(max_, "max") +MATHML_ATOM(mean_, "mean") +MATHML_ATOM(median_, "median") +MATHML_ATOM(merror_, "merror") +MATHML_ATOM(mfenced_, "mfenced") +MATHML_ATOM(mfrac_, "mfrac") +MATHML_ATOM(mi_, "mi") +MATHML_ATOM(min_, "min") +MATHML_ATOM(minus_, "minus") +MATHML_ATOM(mmultiscripts_, "mmultiscripts") +MATHML_ATOM(mn_, "mn") +MATHML_ATOM(mo_, "mo") +MATHML_ATOM(mode_, "mode") +MATHML_ATOM(moment_, "moment") +MATHML_ATOM(movablelimits_, "movablelimits") +MATHML_ATOM(mover_, "mover") +MATHML_ATOM(mpadded_, "mpadded") +MATHML_ATOM(mphantom_, "mphantom") +MATHML_ATOM(mprescripts_, "mprescripts") +MATHML_ATOM(mroot_, "mroot") +MATHML_ATOM(mrow_, "mrow") +MATHML_ATOM(ms_, "ms") +MATHML_ATOM(mspace_, "mspace") +MATHML_ATOM(msqrt_, "msqrt") +MATHML_ATOM(mstyle_, "mstyle") +MATHML_ATOM(msub_, "msub") +MATHML_ATOM(msubsup_, "msubsup") +MATHML_ATOM(msup_, "msup") +MATHML_ATOM(mtable_, "mtable") +MATHML_ATOM(mtd_, "mtd") +MATHML_ATOM(mtext_, "mtext") +MATHML_ATOM(mtr_, "mtr") +MATHML_ATOM(munder_, "munder") +MATHML_ATOM(munderover_, "munderover") +MATHML_ATOM(neq_, "neq") +MATHML_ATOM(none_, "none") +MATHML_ATOM(not_, "not") +MATHML_ATOM(notin_, "notin") +MATHML_ATOM(notprsubset_, "notprsubset") +MATHML_ATOM(notsubset_, "notsubset") +MATHML_ATOM(open_, "open") +MATHML_ATOM(or_, "or") +MATHML_ATOM(partialdiff_, "partialdiff") +MATHML_ATOM(plus_, "plus") +MATHML_ATOM(power_, "power") +MATHML_ATOM(product_, "product") +MATHML_ATOM(prsubset_, "prsubset") +MATHML_ATOM(quotient_, "quotient") +MATHML_ATOM(reln_, "reln") +MATHML_ATOM(rem_, "rem") +MATHML_ATOM(root_, "root") +MATHML_ATOM(scriptlevel_, "scriptlevel") +MATHML_ATOM(sdev_, "sdev") +MATHML_ATOM(sec_, "sec") +MATHML_ATOM(sech_, "sech") +MATHML_ATOM(select_, "select") +MATHML_ATOM(semantics_, "semantics") +MATHML_ATOM(sep_, "sep") +MATHML_ATOM(separator_, "separator") +MATHML_ATOM(separators_, "separators") +MATHML_ATOM(set_, "set") +MATHML_ATOM(setdiff_, "setdiff") +MATHML_ATOM(sin_, "sin") +MATHML_ATOM(sinh_, "sinh") +MATHML_ATOM(stretchy_, "stretchy") +MATHML_ATOM(subset_, "subset") +MATHML_ATOM(sum_, "sum") +MATHML_ATOM(symmetric_, "symmetric") +MATHML_ATOM(tan_, "tan") +MATHML_ATOM(tanh_, "tanh") +MATHML_ATOM(tendsto_, "tendsto") +MATHML_ATOM(times_, "times") +MATHML_ATOM(transpose_, "transpose") +MATHML_ATOM(union_, "union") +MATHML_ATOM(uplimit_, "uplimit") +MATHML_ATOM(var_, "var") +MATHML_ATOM(vector_, "vector") +MATHML_ATOM(xor_, "xor") diff --git a/mozilla/layout/mathml/content/src/nsMathMLAtoms.cpp b/mozilla/layout/mathml/content/src/nsMathMLAtoms.cpp index b87421d2132..b25f1763bb9 100644 --- a/mozilla/layout/mathml/content/src/nsMathMLAtoms.cpp +++ b/mozilla/layout/mathml/content/src/nsMathMLAtoms.cpp @@ -24,7 +24,7 @@ #include "nsINameSpaceManager.h" #include "nsMathMLAtoms.h" -static const char kMathMLNameSpace[] = "http://www.w3.org/Math/MathML"; +static const char kMathMLNameSpace[] = "http://www.w3.org/1998/Math/MathML"; PRInt32 nsMathMLAtoms::nameSpaceID; diff --git a/mozilla/layout/mathml/content/src/nsMathMLOperators.cpp b/mozilla/layout/mathml/content/src/nsMathMLOperators.cpp index f2eab38977e..fc0f515b03b 100644 --- a/mozilla/layout/mathml/content/src/nsMathMLOperators.cpp +++ b/mozilla/layout/mathml/content/src/nsMathMLOperators.cpp @@ -78,6 +78,19 @@ struct OperatorNode { float mRightSpace; // unit is em }; +/* + The MathML REC says: + "If the operator does not occur in the dictionary with the specified form, + the renderer should use one of the forms which is available there, in the + order of preference: infix, postfix, prefix." + + The following variable will be used to keep track of all possible forms + encountered in the Operator Dictionary. +*/ +#ifndef NS_MATHML_STRICT_LOOKUP +static OperatorNode* gOperatorFound[4]; +#endif + // index comparitor: based on the string of the operator and its form bits class OperatorComparitor: public nsAVLNodeComparitor { public: @@ -88,18 +101,27 @@ public: PRInt32 rv; rv = one->mStr.Compare(two->mStr, PR_FALSE); - if (rv == 0) { + if (0 == rv) { nsOperatorFlags form1 = NS_MATHML_OPERATOR_GET_FORM(one->mFlags); nsOperatorFlags form2 = NS_MATHML_OPERATOR_GET_FORM(two->mFlags); - if (form1 < form2) rv = -1; - else if (form1 > form2) rv = 1; + if (form1 == form2) return 0; + else { + rv = (form1 < form2) ? -1 : 1; + +#ifndef NS_MATHML_STRICT_LOOKUP + // Record that the operator was found in a different form. + // We don't know which is the input, we grab both of them and check later + gOperatorFound[form1] = one; + gOperatorFound[form2] = two; +#endif + } } return rv; } }; -static PRInt32 gTableRefCount; +static PRInt32 gTableRefCount = 0; static OperatorNode* gOperatorArray; static nsAVLTree* gOperatorTree; static OperatorComparitor* gComparitor; @@ -162,8 +184,27 @@ nsMathMLOperators::LookupOperator(const nsStr& aOperator, { NS_ASSERTION(gOperatorTree, "no lookup table, needs addref"); if (gOperatorTree) { + +#ifndef NS_MATHML_STRICT_LOOKUP + gOperatorFound[NS_MATHML_OPERATOR_FORM_INFIX] = nsnull; + gOperatorFound[NS_MATHML_OPERATOR_FORM_POSTFIX] = nsnull; + gOperatorFound[NS_MATHML_OPERATOR_FORM_PREFIX] = nsnull; +#endif + OperatorNode node(aOperator, aForm); OperatorNode* found = (OperatorNode*)gOperatorTree->FindItem(&node); + +#ifndef NS_MATHML_STRICT_LOOKUP + // Check if the operator was perhaps found in a different form + // Here we check that we are not referring to the input itself + if (!found) found = gOperatorFound[NS_MATHML_OPERATOR_FORM_INFIX]; + if (found == &node) found = nsnull; + if (!found) found = gOperatorFound[NS_MATHML_OPERATOR_FORM_POSTFIX]; + if (found == &node) found = nsnull; + if (!found) found = gOperatorFound[NS_MATHML_OPERATOR_FORM_PREFIX]; + if (found == &node) found = nsnull; +#endif + if (found) { NS_ASSERTION(found->mStr.Equals(aOperator), "bad tree"); *aFlags = found->mFlags; diff --git a/mozilla/layout/mathml/content/src/nsMathMLOperators.h b/mozilla/layout/mathml/content/src/nsMathMLOperators.h index 619cde5bf8d..859a405b5d1 100644 --- a/mozilla/layout/mathml/content/src/nsMathMLOperators.h +++ b/mozilla/layout/mathml/content/src/nsMathMLOperators.h @@ -25,12 +25,14 @@ #include "nslayout.h" #include "nsCoord.h" +// #define NS_MATHML_STRICT_LOOKUP 1 // see documentation of LookupOperator() below + typedef PRUint32 nsOperatorFlags; // define the bits used to handle the operator -#define NS_MATHML_OPERATOR_MUTABLE 0x80000000 // the very first bit - +#define NS_MATHML_OPERATOR_MUTABLE 0x80000000 // the very first bit +#define NS_MATHML_OPERATOR_EMBELLISH_ANCESTOR 0x40000000 // the second bit // define the bits used in the operator dictionary @@ -45,11 +47,16 @@ typedef PRUint32 nsOperatorFlags; #define NS_MATHML_OPERATOR_SEPARATOR (1<<6) #define NS_MATHML_OPERATOR_MOVABLELIMITS (1<<7) +#define NS_MATHML_OPERATOR_SYMMETRIC (1<<8) + // Macros that retrieve those bits #define NS_MATHML_OPERATOR_IS_MUTABLE(_flags) \ (NS_MATHML_OPERATOR_MUTABLE == ((_flags) & NS_MATHML_OPERATOR_MUTABLE)) +#define NS_MATHML_OPERATOR_HAS_EMBELLISH_ANCESTOR(_flags) \ + (NS_MATHML_OPERATOR_EMBELLISH_ANCESTOR == ((_flags) & NS_MATHML_OPERATOR_EMBELLISH_ANCESTOR)) + #define NS_MATHML_OPERATOR_GET_FORM(_flags) \ ((_flags) & NS_MATHML_OPERATOR_FORM) @@ -80,6 +87,8 @@ typedef PRUint32 nsOperatorFlags; #define NS_MATHML_OPERATOR_IS_MOVABLELIMITS(_flags) \ (NS_MATHML_OPERATOR_MOVABLELIMITS == ((_flags) & NS_MATHML_OPERATOR_MOVABLELIMITS)) +#define NS_MATHML_OPERATOR_IS_SYMMETRIC(_flags) \ + (NS_MATHML_OPERATOR_SYMMETRIC == ((_flags) & NS_MATHML_OPERATOR_SYMMETRIC)) class nsMathMLOperators { public: @@ -89,6 +98,11 @@ public: // Given the string value of an operator and its form (last two bits of flags), // this method returns true if the operator is found in the operator dictionary. // Attributes of the operator are returned in the output parameters. + // If the operator is not found under the supplied form but is found under a + // different form, the method returns true as well (it is possible to set + // NS_MATHML_STRICT_LOOKUP to disable this feature). The caller can test the + // output parameter aFlags to know exactly under which form the operator was + // found in the operator dictionary. static PRBool LookupOperator(const nsStr& aOperator, const nsOperatorFlags aForm,