Skip to content

Commit e30f5f1

Browse files
committed
Count multi-character glyphs properly in HTML-CSS
1 parent 5d992bc commit e30f5f1

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

unpacked/jax/output/HTML-CSS/autoload/mmultiscripts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
6464
if (base.bbox.ic) {delta = base.bbox.ic}
6565
if (this.data[this.base] &&
6666
(this.data[this.base].type === "mi" || this.data[this.base].type === "mo")) {
67-
if (this.data[this.base].data.join("").length === 1 && base.bbox.scale === 1 &&
67+
if (HTMLCSS.isChar(this.data[this.base].data.join("")) && base.bbox.scale === 1 &&
6868
!this.data[this.base].Get("largeop")) {u = v = 0}
6969
}
7070
var min = this.getValues("subscriptshift","superscriptshift"), mu = this.HTMLgetMu(span);

unpacked/jax/output/HTML-CSS/jax.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,7 @@
16231623
span.bbox.h *= span.scale; span.bbox.d *= span.scale;
16241624
span.bbox.w *= span.scale; span.bbox.lw *= span.scale; span.bbox.rw *= span.scale;
16251625
}
1626-
if (text.length == 1 && font.skew && font.skew[n]) {span.bbox.skew = font.skew[n]}
1626+
if (HTMLCSS.isChar(text) && font.skew && font.skew[n]) {span.bbox.skew = font.skew[n]}
16271627
},
16281628
checkFont: function (font,style) {
16291629
var weight = (style.fontWeight||"normal");
@@ -1726,6 +1726,13 @@
17261726
HUB.signal.Post(["HTML-CSS Jax - unknown char",n,variant]);
17271727
return unknown;
17281728
},
1729+
1730+
isChar: function (text) {
1731+
if (text.length === 1) return true;
1732+
if (text.length !== 2) return false;
1733+
var n = text.charCodeAt(0);
1734+
return (n >= 0xD800 && n < 0xDBFF);
1735+
},
17291736

17301737
findBlock: function (font,c) {
17311738
if (font.Ranges) {
@@ -2293,8 +2300,8 @@
22932300
{if (this.data[i]) {this.data[i].toHTML(span,variant)}}
22942301
if (!span.bbox) {span.bbox = this.HTMLzeroBBox()}
22952302
var text = this.data.join(""), bbox = span.bbox;
2296-
if (bbox.skew && text.length !== 1) {delete bbox.skew}
2297-
if (bbox.rw > bbox.w && text.length === 1 && !variant.noIC) {
2303+
if (bbox.skew && !HTMLCSS.isChar(text)) {delete bbox.skew}
2304+
if (bbox.rw > bbox.w && HTMLCSS.isChar(text) && !variant.noIC) {
22982305
bbox.ic = bbox.rw - bbox.w;
22992306
HTMLCSS.createBlank(span,bbox.ic/this.mscale);
23002307
bbox.w = bbox.rw;
@@ -2319,7 +2326,7 @@
23192326
}
23202327
}
23212328
if (!span.bbox) {span.bbox = this.HTMLzeroBBox()}
2322-
if (this.data.join("").length !== 1) {delete span.bbox.skew}
2329+
if (!HTMLCSS.isChar(this.data.join(""))) {delete span.bbox.skew}
23232330
this.HTMLhandleSpace(span);
23242331
this.HTMLhandleColor(span);
23252332
this.HTMLhandleDir(span);
@@ -2345,8 +2352,8 @@
23452352
var parent = this.CoreParent(),
23462353
isScript = (parent && parent.isa(MML.msubsup) && this !== parent.data[parent.base]),
23472354
mapchars = (isScript?this.remapChars:null);
2348-
if (text.length === 1 && parent && parent.isa(MML.munderover) &&
2349-
this.CoreText(parent.data[parent.base]).length === 1) {
2355+
if (HTMLCSS.isChar(text) && parent && parent.isa(MML.munderover) &&
2356+
HTMLCSS.isChar(his.CoreText(parent.data[parent.base]))) {
23502357
var over = parent.data[parent.over], under = parent.data[parent.under];
23512358
if (over && this === over.CoreMO() && parent.Get("accent")) {mapchars = HTMLCSS.FONTDATA.REMAPACCENT}
23522359
else if (under && this === under.CoreMO() && parent.Get("accentunder")) {mapchars = HTMLCSS.FONTDATA.REMAPACCENTUNDER}
@@ -2362,12 +2369,12 @@
23622369
for (var i = 0, m = this.data.length; i < m; i++)
23632370
{if (this.data[i]) {this.data[i].toHTML(span,variant,this.remap,mapchars)}}
23642371
if (!span.bbox) {span.bbox = this.HTMLzeroBBox()}
2365-
if (text.length !== 1) {delete span.bbox.skew}
2372+
if (!HTMLCSS.isChar(text)) {delete span.bbox.skew}
23662373

23672374
//
23682375
// Handle combining character bugs
23692376
//
2370-
if (HTMLCSS.AccentBug && span.bbox.w === 0 && text.length === 1 && span.firstChild) {
2377+
if (HTMLCSS.AccentBug && span.bbox.w === 0 && HTMLCSS.isChar(text) && span.firstChild) {
23712378
//
23722379
// adding a non-breaking space and removing that width
23732380
//
@@ -2411,7 +2418,7 @@
24112418
if (c.length > 1) {return false}
24122419
var parent = this.CoreParent();
24132420
if (parent && parent.isa(MML.munderover) &&
2414-
this.CoreText(parent.data[parent.base]).length === 1) {
2421+
HTMLCSS.isChar(this.CoreText(parent.data[parent.base]))) {
24152422
var over = parent.data[parent.over], under = parent.data[parent.under];
24162423
if (over && this === over.CoreMO() && parent.Get("accent")) {c = HTMLCSS.FONTDATA.REMAPACCENT[c]||c}
24172424
else if (under && this === under.CoreMO() && parent.Get("accentunder")) {c = HTMLCSS.FONTDATA.REMAPACCENTUNDER[c]||c}
@@ -2473,7 +2480,7 @@
24732480
for (var i = 0, m = this.data.length; i < m; i++)
24742481
{if (this.data[i]) {this.data[i].toHTML(span,variant)}}
24752482
if (!span.bbox) {span.bbox = this.HTMLzeroBBox()}
2476-
if (this.data.join("").length !== 1) {delete span.bbox.skew}
2483+
if (!HTMLCSS.isChar(this.data.join(""))) {delete span.bbox.skew}
24772484
this.HTMLhandleSpace(span);
24782485
this.HTMLhandleColor(span);
24792486
this.HTMLhandleDir(span);
@@ -2939,7 +2946,7 @@
29392946
}
29402947
if (this.data[this.base] && HW == null && D == null &&
29412948
(this.data[this.base].type === "mi" || this.data[this.base].type === "mo")) {
2942-
if (this.data[this.base].data.join("").length === 1 && children[0].scale === 1 &&
2949+
if (HTMLCSS.isChar(this.data[this.base].data.join("")) && children[0].scale === 1 &&
29432950
!this.data[this.base].Get("largeop")) {u = v = 0}
29442951
}
29452952
var min = this.getValues("subscriptshift","superscriptshift");

0 commit comments

Comments
 (0)