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

Fix problem with detecting whether ex-height can be computed, and work around jsdom problems #691

Merged
merged 1 commit into from
May 18, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions ts/adaptors/jsdomAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class JsdomAdaptor extends HTMLAdaptor<HTMLElement, Text, Document> {
* The default options
*/
public static OPTIONS: OptionList = {
fontSize: 16, // We can't compute the font size, so always use this
fontFamily: 'Times', // We can't compute the font family, so always use this
cjkCharWidth: 1, // Width (in em units) of full width characters
unknownCharWidth: .6, // Width (in em units) of unknown (non-full-width) characters
unknownCharHeight: .8, // Height (in em units) of unknown characters
Expand Down Expand Up @@ -74,6 +76,32 @@ export class JsdomAdaptor extends HTMLAdaptor<HTMLElement, Text, Document> {
this.options = userOptions(defaultOptions({}, CLASS.OPTIONS), options);
}

/**
* JSDOM's getComputedStyle() implementation is badly broken, and only
* return the styles explicitly set on the given node, not the
* inherited values frmo the cascading style sheets (so it is pretty
* useless). This is somethig we can't really work around, so use
* the default value given in the options instead. Sigh
*
* @override
*/
public fontSize(_node: HTMLElement) {
return this.options.fontSize;
}

/**
* JSDOM's getComputedStyle() implementation is badly broken, and only
* return the styles explicitly set on the given node, not the
* inherited values frmo the cascading style sheets (so it is pretty
* useless). This is somethig we can't really work around, so use
* the default value given in the options instead. Sigh
*
* @override
*/
public fontFamily(_node: HTMLElement) {
return this.options.fontFamily;
}

/**
* @override
*/
Expand Down
5 changes: 3 additions & 2 deletions ts/output/common/OutputJax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,9 @@ export abstract class CommonOutputJax<
const adaptor = this.adaptor;
const family = (getFamily ? adaptor.fontFamily(node) : '');
const em = adaptor.fontSize(node);
const ex = (adaptor.nodeSize(adaptor.childNode(node, 1) as N)[1] / 60) || (em * this.options.exFactor);
const containerWidth = (adaptor.getStyle(node, 'display') === 'table' ?
const [w, h] = adaptor.nodeSize(adaptor.childNode(node, 1) as N);
const ex = (w ? h / 60 : em * this.options.exFactor);
const containerWidth = (!w ? 1000000 : adaptor.getStyle(node, 'display') === 'table' ?
adaptor.nodeSize(adaptor.lastChild(node) as N)[0] - 1 :
adaptor.nodeBBox(adaptor.lastChild(node) as N).left -
adaptor.nodeBBox(adaptor.firstChild(node) as N).left - 2);
Expand Down