Merge pull request #634 from fred-wang/bidi

Implement bidi on MathML token elements and fix incorrect rendering of RTL error messages
This commit is contained in:
Frédéric Wang 2013-10-21 04:49:55 -07:00
commit a259bcba88
9 changed files with 49 additions and 18 deletions

View File

@ -223,7 +223,19 @@ MathJax.ElementJax.mml.Augment({
"fontfamily", "fontsize", "fontweight", "fontstyle", "fontfamily", "fontsize", "fontweight", "fontstyle",
"color", "background", "color", "background",
"id", "class", "href", "style" "id", "class", "href", "style"
] ],
Error: function (message,def) {
var mml = this.merror(message),
dir = MathJax.Localization.fontDirection(),
font = MathJax.Localization.fontFamily();
if (def) {mml = mml.With(def)}
if (dir || font) {
mml = this.mstyle(mml);
if (dir) {mml.dir = dir}
if (font) {mml.style.fontFamily = "font-family: "+font}
}
return mml;
}
}); });
(function (MML) { (function (MML) {
@ -232,7 +244,8 @@ MathJax.ElementJax.mml.Augment({
type: "base", isToken: false, type: "base", isToken: false,
defaults: { defaults: {
mathbackground: MML.INHERIT, mathbackground: MML.INHERIT,
mathcolor: MML.INHERIT mathcolor: MML.INHERIT,
dir: MML.INHERIT,
}, },
noInherit: {}, noInherit: {},
noInheritAttribute: { noInheritAttribute: {
@ -428,7 +441,8 @@ MathJax.ElementJax.mml.Augment({
mathvariant: MML.AUTO, mathvariant: MML.AUTO,
mathsize: MML.INHERIT, mathsize: MML.INHERIT,
mathbackground: MML.INHERIT, mathbackground: MML.INHERIT,
mathcolor: MML.INHERIT mathcolor: MML.INHERIT,
dir: MML.INHERIT
}, },
autoDefault: function (name) { autoDefault: function (name) {
if (name === "mathvariant") { if (name === "mathvariant") {
@ -458,7 +472,8 @@ MathJax.ElementJax.mml.Augment({
mathvariant: MML.INHERIT, mathvariant: MML.INHERIT,
mathsize: MML.INHERIT, mathsize: MML.INHERIT,
mathbackground: MML.INHERIT, mathbackground: MML.INHERIT,
mathcolor: MML.INHERIT mathcolor: MML.INHERIT,
dir: MML.INHERIT
} }
}); });
@ -469,6 +484,7 @@ MathJax.ElementJax.mml.Augment({
mathsize: MML.INHERIT, mathsize: MML.INHERIT,
mathbackground: MML.INHERIT, mathbackground: MML.INHERIT,
mathcolor: MML.INHERIT, mathcolor: MML.INHERIT,
dir: MML.INHERIT,
form: MML.AUTO, form: MML.AUTO,
fence: MML.AUTO, fence: MML.AUTO,
separator: MML.AUTO, separator: MML.AUTO,
@ -630,7 +646,8 @@ MathJax.ElementJax.mml.Augment({
mathvariant: MML.INHERIT, mathvariant: MML.INHERIT,
mathsize: MML.INHERIT, mathsize: MML.INHERIT,
mathbackground: MML.INHERIT, mathbackground: MML.INHERIT,
mathcolor: MML.INHERIT mathcolor: MML.INHERIT,
dir: MML.INHERIT
} }
}); });
@ -665,6 +682,7 @@ MathJax.ElementJax.mml.Augment({
mathsize: MML.INHERIT, mathsize: MML.INHERIT,
mathbackground: MML.INHERIT, mathbackground: MML.INHERIT,
mathcolor: MML.INHERIT, mathcolor: MML.INHERIT,
dir: MML.INHERIT,
lquote: '"', lquote: '"',
rquote: '"' rquote: '"'
} }
@ -810,6 +828,7 @@ MathJax.ElementJax.mml.Augment({
scriptminsize: "8pt", scriptminsize: "8pt",
mathbackground: MML.INHERIT, mathbackground: MML.INHERIT,
mathcolor: MML.INHERIT, mathcolor: MML.INHERIT,
dir: MML.INHERIT,
infixlinebreakstyle: MML.LINEBREAKSTYLE.BEFORE, infixlinebreakstyle: MML.LINEBREAKSTYLE.BEFORE,
decimalseparator: "." decimalseparator: "."
}, },
@ -1226,6 +1245,7 @@ MathJax.ElementJax.mml.Augment({
mathsize: MML.SIZE.NORMAL, mathsize: MML.SIZE.NORMAL,
mathcolor: "", // should be "black", but allow it to inherit from surrounding text mathcolor: "", // should be "black", but allow it to inherit from surrounding text
mathbackground: MML.COLOR.TRANSPARENT, mathbackground: MML.COLOR.TRANSPARENT,
dir: "ltr",
scriptlevel: 0, scriptlevel: 0,
displaystyle: MML.AUTO, displaystyle: MML.AUTO,
display: "inline", display: "inline",

View File

@ -1292,7 +1292,7 @@ junk = null;
formatError: function (err,math,script) { formatError: function (err,math,script) {
var message = err.message.replace(/\n.*/,""); var message = err.message.replace(/\n.*/,"");
MathJax.Hub.signal.Post(["AsciiMath Jax - parse error",message,math,script]); MathJax.Hub.signal.Post(["AsciiMath Jax - parse error",message,math,script]);
return MML.merror(message); return MML.Error(message);
}, },
Error: function (message) { Error: function (message) {
throw MathJax.Hub.Insert(Error(message),{asciimathError: true}); throw MathJax.Hub.Insert(Error(message),{asciimathError: true});

View File

@ -77,7 +77,7 @@
mml = this.TeXAtom(match[2]); mml = this.TeXAtom(match[2]);
} else if (!(MML[type] && MML[type].isa && MML[type].isa(MML.mbase))) { } else if (!(MML[type] && MML[type].isa && MML[type].isa(MML.mbase))) {
MathJax.Hub.signal.Post(["MathML Jax - unknown node type",type]); MathJax.Hub.signal.Post(["MathML Jax - unknown node type",type]);
return MML.merror(_("UnknownNodeType","Unknown node type: %1",type)); return MML.Error(_("UnknownNodeType","Unknown node type: %1",type));
} else { } else {
mml = MML[type](); mml = MML[type]();
} }
@ -267,7 +267,7 @@
formatError: function (err,math,script) { formatError: function (err,math,script) {
var message = err.message.replace(/\n.*/,""); var message = err.message.replace(/\n.*/,"");
MathJax.Hub.signal.Post(["MathML Jax - parse error",message,math,script]); MathJax.Hub.signal.Post(["MathML Jax - parse error",message,math,script]);
return MML.merror(message); return MML.Error(message);
}, },
Error: function (message) { Error: function (message) {
// //

View File

@ -2099,7 +2099,7 @@
formatError: function (err,math,display,script) { formatError: function (err,math,display,script) {
var message = err.message.replace(/\n.*/,""); var message = err.message.replace(/\n.*/,"");
HUB.signal.Post(["TeX Jax - parse error",message,math,display,script]); HUB.signal.Post(["TeX Jax - parse error",message,math,display,script]);
return MML.merror(message); return MML.Error(message);
}, },
// //

View File

@ -45,7 +45,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
} else { } else {
if (values.alt === "") if (values.alt === "")
{values.alt = LOCALE._(["MathML","BadMglyphFont"],"Bad font: %1",font.family)} {values.alt = LOCALE._(["MathML","BadMglyphFont"],"Bad font: %1",font.family)}
err = MML.merror(values.alt).With({mathsize:"75%"}); err = MML.Error(values.alt,{mathsize:"75%"});
this.Append(err); err.toHTML(span); this.data.pop(); this.Append(err); err.toHTML(span); this.data.pop();
span.bbox = err.HTMLspanElement().bbox; span.bbox = err.HTMLspanElement().bbox;
} }
@ -62,9 +62,9 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
MathJax.Hub.RestartAfter(img.onload); MathJax.Hub.RestartAfter(img.onload);
} }
if (this.img.status !== "OK") { if (this.img.status !== "OK") {
err = MML.merror( err = MML.Error(
LOCALE._(["MathML","BadMglyph"],"Bad mglyph: %1",values.src) LOCALE._(["MathML","BadMglyph"],"Bad mglyph: %1",values.src),
).With({mathsize:"75%"}); {mathsize:"75%"});
this.Append(err); err.toHTML(span); this.data.pop(); this.Append(err); err.toHTML(span); this.data.pop();
span.bbox = err.HTMLspanElement().bbox; span.bbox = err.HTMLspanElement().bbox;
} else { } else {

View File

@ -41,6 +41,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
this.HTMLhandleVariant(span,this.HTMLgetVariant(),values.lquote+text+values.rquote); this.HTMLhandleVariant(span,this.HTMLgetVariant(),values.lquote+text+values.rquote);
this.HTMLhandleSpace(span); this.HTMLhandleSpace(span);
this.HTMLhandleColor(span); this.HTMLhandleColor(span);
this.HTMLhandleDir(span);
return span; return span;
}, },
HTMLquoteRegExp: function (string) { HTMLquoteRegExp: function (string) {

View File

@ -1723,6 +1723,12 @@
return span; return span;
}, },
HTMLhandleDir: function (span) {
var dir = this.Get("dir",true); // only get value if not the default
if (dir) {span.dir = dir}
return span;
},
HTMLhandleColor: function (span) { HTMLhandleColor: function (span) {
var values = this.getValues("mathcolor","color"); var values = this.getValues("mathcolor","color");
if (this.mathbackground) {values.mathbackground = this.mathbackground} if (this.mathbackground) {values.mathbackground = this.mathbackground}
@ -1973,6 +1979,7 @@
} }
this.HTMLhandleSpace(span); this.HTMLhandleSpace(span);
this.HTMLhandleColor(span); this.HTMLhandleColor(span);
this.HTMLhandleDir(span);
return span; return span;
} }
}); });
@ -1987,6 +1994,7 @@
if (this.data.join("").length !== 1) {delete span.bbox.skew} if (this.data.join("").length !== 1) {delete span.bbox.skew}
this.HTMLhandleSpace(span); this.HTMLhandleSpace(span);
this.HTMLhandleColor(span); this.HTMLhandleColor(span);
this.HTMLhandleDir(span);
return span; return span;
} }
}); });
@ -2061,6 +2069,7 @@
// //
this.HTMLhandleSpace(span); this.HTMLhandleSpace(span);
this.HTMLhandleColor(span); this.HTMLhandleColor(span);
this.HTMLhandleDir(span);
return span; return span;
}, },
CoreParent: function () { CoreParent: function () {
@ -2157,6 +2166,7 @@
if (this.data.join("").length !== 1) {delete span.bbox.skew} if (this.data.join("").length !== 1) {delete span.bbox.skew}
this.HTMLhandleSpace(span); this.HTMLhandleSpace(span);
this.HTMLhandleColor(span); this.HTMLhandleColor(span);
this.HTMLhandleDir(span);
return span; return span;
} }
}); });

View File

@ -74,9 +74,9 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
MathJax.Hub.RestartAfter(img.onload); MathJax.Hub.RestartAfter(img.onload);
} }
if (this.img.status !== "OK") { if (this.img.status !== "OK") {
err = MML.merror( err = MML.Error(
LOCALE._(["MathML","BadMglyph"],"Bad mglyph: %1",values.src) LOCALE._(["MathML","BadMglyph"],"Bad mglyph: %1",values.src),
).With({mathsize:"75%"}); {mathsize:"75%"});
this.Append(err); svg = err.toSVG(); this.data.pop(); this.Append(err); svg = err.toSVG(); this.data.pop();
} else { } else {
var mu = this.SVGgetMu(svg); var mu = this.SVGgetMu(svg);

View File

@ -1465,7 +1465,7 @@
if (this.Parent().type === "merror") { if (this.Parent().type === "merror") {
// *** FIXME: Make color, style, scale configurable // *** FIXME: Make color, style, scale configurable
svg = this.SVG(); this.SVGhandleSpace(svg); svg = this.SVG(); this.SVGhandleSpace(svg);
text = BBOX.G(); text.Add(BBOX.TEXT(.9*scale,this.data.join(""),{fill:"#C00"})); text = BBOX.G(); text.Add(BBOX.TEXT(.9*scale,this.data.join(""),{fill:"#C00",direction:this.Get("dir")}));
svg.Add(BBOX.RECT(text.h+100,text.d+100,text.w+200,{fill:"#FF8",stroke:"#C00","stroke-width":50}),0,0); svg.Add(BBOX.RECT(text.h+100,text.d+100,text.w+200,{fill:"#FF8",stroke:"#C00","stroke-width":50}),0,0);
svg.Add(text,150,0); svg.H += 150; svg.D += 50; svg.Add(text,150,0); svg.H += 150; svg.D += 50;
svg.Clean(); svg.Clean();
@ -1473,7 +1473,7 @@
return svg; return svg;
} else if (SVG.config.mtextFontInherit) { } else if (SVG.config.mtextFontInherit) {
svg = this.SVG(); this.SVGhandleSpace(svg); svg = this.SVG(); this.SVGhandleSpace(svg);
var variant = this.SVGgetVariant(), def = {}; var variant = this.SVGgetVariant(), def = {direction:this.Get("dir")};
if (variant.bold) {def["font-weight"] = "bold"} if (variant.bold) {def["font-weight"] = "bold"}
if (variant.italic) {def["font-style"] = "italic"} if (variant.italic) {def["font-style"] = "italic"}
svg.Add(BBOX.TEXT(scale,this.data.join(""),def)); svg.Clean(); svg.Add(BBOX.TEXT(scale,this.data.join(""),def)); svg.Clean();