Skip to content

Commit 50fe516

Browse files
authored
Merge pull request #699 from mathjax/safari-text-size
Force width of -explicitFont text (work around Safari bug)
2 parents 33d84d5 + 8d17694 commit 50fe516

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

ts/output/chtml.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ CommonOutputJax<N, T, D, CHTMLWrapper<N, T, D>, CHTMLWrapperFactory<N, T, D>, CH
215215
/**
216216
* @override
217217
*/
218-
public unknownText(text: string, variant: string) {
218+
public unknownText(text: string, variant: string, width: number = null) {
219219
const styles: StyleList = {};
220220
const scale = 100 / this.math.metrics.scale;
221221
if (scale !== 100) {
@@ -228,6 +228,16 @@ CommonOutputJax<N, T, D, CHTMLWrapper<N, T, D>, CHTMLWrapperFactory<N, T, D>, CH
228228
this.cssFontStyles(this.font.getCssFont(variant), styles);
229229
}
230230
}
231+
//
232+
// Work around Safari bug with the MJXZERO font by forcing the width.
233+
// (If MJXZERO can be made to work with Safari, then remove width parameter
234+
// and call to getBBox().w in TextNode.ts)
235+
//
236+
if (width !== null) {
237+
const metrics = this.math.metrics;
238+
styles.width = Math.round(width * metrics.em * metrics.scale) + 'px';
239+
}
240+
//
231241
return this.html('mjx-utext', {variant: variant, style: styles}, [this.text(text)]);
232242
}
233243

@@ -238,11 +248,16 @@ CommonOutputJax<N, T, D, CHTMLWrapper<N, T, D>, CHTMLWrapperFactory<N, T, D>, CH
238248
* @override
239249
*/
240250

241-
public measureTextNode(text: N) {
251+
public measureTextNode(textNode: N) {
242252
const adaptor = this.adaptor;
243-
text = adaptor.clone(text);
253+
const text = adaptor.clone(textNode);
254+
//
255+
// Work arround Safari bug with the MJXZERO font.
256+
//
257+
adaptor.setStyle(text, 'font-family', adaptor.getStyle(text, 'font-family').replace(/MJXZERO, /g, ''));
258+
//
244259
const style = {position: 'absolute', 'white-space': 'nowrap'};
245-
const node = this.html('mjx-measure-text', {style}, [ text]);
260+
const node = this.html('mjx-measure-text', {style}, [text]);
246261
adaptor.append(adaptor.parent(this.math.start.node), this.container);
247262
adaptor.append(this.container, node);
248263
let w = adaptor.nodeSize(text, this.math.metrics.em)[0] / this.math.metrics.scale;

ts/output/chtml/Wrappers/TextNode.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ CommonTextNodeMixin<CHTMLConstructor<any, any, any>>(CHTMLWrapper) {
7070
const variant = this.parent.variant;
7171
const text = (this.node as TextNode).getText();
7272
if (variant === '-explicitFont') {
73-
const font = this.jax.getFontData(this.parent.styles);
74-
adaptor.append(parent, this.jax.unknownText(text, variant, font));
73+
adaptor.append(parent, this.jax.unknownText(text, variant, this.getBBox().w));
7574
} else {
7675
const chars = this.remappedText(text, variant);
7776
for (const n of chars) {

0 commit comments

Comments
 (0)