Skip to content

Commit cbb1fe2

Browse files
committed
Count multi-character glyphs properly in CHTML
1 parent f46952e commit cbb1fe2

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

unpacked/jax/output/CommonHTML/autoload/mmultiscripts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
7676
var u = bbox.h - q, v = bbox.d + r, delta = 0, p;
7777
var bmml = this.data[this.base];
7878
if (bmml && (bmml.type === "mi" || bmml.type === "mo")) {
79-
if (bmml.data.join("").length === 1 && bbox.rscale === 1 && !bbox.sH &&
79+
if (CHTML.isChar(bmml.data.join("")) && bbox.rscale === 1 && !bbox.sH &&
8080
!bmml.Get("largeop")) {u = v = 0}
8181
}
8282
values = this.getValues("displaystyle","subscriptshift","superscriptshift","texprimestyle");

unpacked/jax/output/CommonHTML/jax.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,15 @@
766766

767767
/********************************************************/
768768

769+
//
770+
// True if text holds a single (unicode) glyph
771+
//
772+
isChar: function (text) {
773+
if (text.length === 1) return true;
774+
if (text.length !== 2) return false;
775+
var n = text.charCodeAt(0);
776+
return (n >= 0xD800 && n < 0xDBFF);
777+
},
769778
//
770779
// Get a unicode character by number (even when it takes two character)
771780
//
@@ -1874,8 +1883,8 @@
18741883
toCommonHTML: function (node) {
18751884
node = this.CHTMLdefaultNode(node);
18761885
var bbox = this.CHTML, text = this.data.join("");
1877-
if (bbox.skew != null && text.length !== 1) delete bbox.skew;
1878-
if (bbox.r > bbox.w && text.length === 1 && !this.CHTMLvariant.noIC) {
1886+
if (bbox.skew != null && !CHTML.isChar(text)) delete bbox.skew;
1887+
if (bbox.r > bbox.w && CHTML.isChar(text) && !this.CHTMLvariant.noIC) {
18791888
bbox.ic = bbox.r - bbox.w; bbox.w = bbox.r;
18801889
node.lastChild.style.paddingRight = CHTML.Em(bbox.ic);
18811890
}
@@ -1890,8 +1899,8 @@
18901899
toCommonHTML: function (node) {
18911900
node = this.CHTMLdefaultNode(node,{childOptions:{remap:this.CHTMLremapMinus}});
18921901
var bbox = this.CHTML, text = this.data.join("");
1893-
if (bbox.skew != null && text.length !== 1) delete bbox.skew;
1894-
if (bbox.r > bbox.w && text.length === 1 && !this.CHTMLvariant.noIC) {
1902+
if (bbox.skew != null && !CHTML.isChar(text)) delete bbox.skew;
1903+
if (bbox.r > bbox.w && CHTML.isChar(text) && !this.CHTMLvariant.noIC) {
18951904
bbox.ic = bbox.r - bbox.w; bbox.w = bbox.r;
18961905
node.lastChild.style.paddingRight = CHTML.Em(bbox.ic);
18971906
}
@@ -1925,7 +1934,7 @@
19251934
remapchars: values.remapchars
19261935
}});
19271936
}
1928-
if (values.text.length !== 1) delete this.CHTML.skew;
1937+
if (!CHTML.isChar(values.text)) delete this.CHTML.skew;
19291938
else if (this.CHTML.w === 0 && this.CHTML.l < 0) this.CHTMLfixCombiningChar(node);
19301939
if (values.largeop) this.CHTMLcenterOp(node);
19311940
}
@@ -1958,7 +1967,7 @@
19581967
},
19591968
CHTMLadjustAccent: function (data) {
19601969
var parent = this.CoreParent(); data.parent = parent;
1961-
if (data.text.length === 1 && parent && parent.isa(MML.munderover)) {
1970+
if (CHTML.isChar(data.text) && parent && parent.isa(MML.munderover)) {
19621971
var over = parent.data[parent.over], under = parent.data[parent.under];
19631972
if (over && this === over.CoreMO() && parent.Get("accent")) {
19641973
data.remapchars = CHTML.FONTDATA.REMAPACCENT;
@@ -1998,7 +2007,7 @@
19982007
},
19992008
CHTMLcanStretch: function (direction,H,D) {
20002009
if (!this.Get("stretchy")) return false;
2001-
var c = this.data.join(""); if (c.length !== 1) return false;
2010+
var c = this.data.join(""); if (!CHTML.isChar(c)) return false;
20022011
var values = {text: c};
20032012
this.CHTMLadjustAccent(values);
20042013
if (values.remapchars) c = values.remapchars[c]||c;
@@ -2469,7 +2478,7 @@
24692478
if (bmml) {
24702479
if ((bmml.type === "mrow" || bmml.type === "mstyle") && bmml.data.length === 1) bmml = bmml.data[0];
24712480
if (bmml.type === "mi" || bmml.type === "mo") {
2472-
if (bmml.data.join("").length === 1 && bbox.rscale === 1 && !bbox.sH &&
2481+
if (CHTML.isChar(bmml.data.join("")) && bbox.rscale === 1 && !bbox.sH &&
24732482
!bmml.Get("largeop")) {u = v = 0}
24742483
}
24752484
}

0 commit comments

Comments
 (0)