Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force width of -explicitFont text (work around Safari bug) #699

Merged
merged 1 commit into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions ts/output/chtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ CommonOutputJax<N, T, D, CHTMLWrapper<N, T, D>, CHTMLWrapperFactory<N, T, D>, CH
/**
* @override
*/
public unknownText(text: string, variant: string) {
public unknownText(text: string, variant: string, width: number = null) {
const styles: StyleList = {};
const scale = 100 / this.math.metrics.scale;
if (scale !== 100) {
Expand All @@ -221,6 +221,16 @@ CommonOutputJax<N, T, D, CHTMLWrapper<N, T, D>, CHTMLWrapperFactory<N, T, D>, CH
this.cssFontStyles(this.font.getCssFont(variant), styles);
}
}
//
// Work around Safari bug with the MJXZERO font by forcing the width.
// (If MJXZERO can be made to work with Safari, then remove width parameter
// and call to getBBox().w in TextNode.ts)
//
if (width !== null) {
const metrics = this.math.metrics;
styles.width = Math.round(width * metrics.em * metrics.scale) + 'px';
}
//
return this.html('mjx-utext', {variant: variant, style: styles}, [this.text(text)]);
}

Expand All @@ -231,11 +241,16 @@ CommonOutputJax<N, T, D, CHTMLWrapper<N, T, D>, CHTMLWrapperFactory<N, T, D>, CH
* @override
*/

public measureTextNode(text: N) {
public measureTextNode(textNode: N) {
const adaptor = this.adaptor;
text = adaptor.clone(text);
const text = adaptor.clone(textNode);
//
// Work arround Safari bug with the MJXZERO font.
//
adaptor.setStyle(text, 'font-family', adaptor.getStyle(text, 'font-family').replace(/MJXZERO, /g, ''));
//
const style = {position: 'absolute', 'white-space': 'nowrap'};
const node = this.html('mjx-measure-text', {style}, [ text]);
const node = this.html('mjx-measure-text', {style}, [text]);
adaptor.append(adaptor.parent(this.math.start.node), this.container);
adaptor.append(this.container, node);
let w = adaptor.nodeSize(text, this.math.metrics.em)[0] / this.math.metrics.scale;
Expand Down
3 changes: 1 addition & 2 deletions ts/output/chtml/Wrappers/TextNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ CommonTextNodeMixin<CHTMLConstructor<any, any, any>>(CHTMLWrapper) {
const variant = this.parent.variant;
const text = (this.node as TextNode).getText();
if (variant === '-explicitFont') {
const font = this.jax.getFontData(this.parent.styles);
adaptor.append(parent, this.jax.unknownText(text, variant, font));
adaptor.append(parent, this.jax.unknownText(text, variant, this.getBBox().w));
} else {
const chars = this.remappedText(text, variant);
for (const n of chars) {
Expand Down