diff --git a/ts/adaptors/jsdomAdaptor.ts b/ts/adaptors/jsdomAdaptor.ts index d41e6d5b5..d22ca6ca4 100644 --- a/ts/adaptors/jsdomAdaptor.ts +++ b/ts/adaptors/jsdomAdaptor.ts @@ -30,6 +30,8 @@ export class JsdomAdaptor extends HTMLAdaptor { * 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 @@ -74,6 +76,32 @@ export class JsdomAdaptor extends HTMLAdaptor { 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 */ diff --git a/ts/output/common/OutputJax.ts b/ts/output/common/OutputJax.ts index 98ff83cb7..1900c49e3 100644 --- a/ts/output/common/OutputJax.ts +++ b/ts/output/common/OutputJax.ts @@ -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);