@@ -59,6 +59,12 @@ export const FONTSIZE: StringMap = {
5959 '249%' : 'HG'
6060} ;
6161
62+ export const SPACE : StringMap = {
63+ [ LENGTHS . em ( 3 / 18 ) ] : '1' ,
64+ [ LENGTHS . em ( 4 / 18 ) ] : '2' ,
65+ [ LENGTHS . em ( 5 / 18 ) ] : '3' ,
66+ } ;
67+
6268/*
6369 * Needed to access node.style[id] using variable id
6470 */
@@ -102,6 +108,8 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
102108 'mjx-box' : { display : 'inline-block' } ,
103109 'mjx-block' : { display : 'block' } ,
104110 'mjx-itable' : { display : 'inline-table' } ,
111+ 'mjx-row' : { display : 'table-row' } ,
112+ 'mjx-row > *' : { display : 'table-cell' } ,
105113
106114 //
107115 // These don't have Wrapper subclasses, so add their styles here
@@ -304,24 +312,21 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
304312 if ( this . bboxComputed ) {
305313 return this . bbox ;
306314 }
307- let bbox = this . computeBBox ( ) ;
308- if ( save ) {
309- this . bbox = bbox ;
310- this . bboxComputed = true ;
311- }
315+ const bbox = ( save ? this . bbox : BBox . zero ( ) ) ;
316+ this . computeBBox ( bbox ) ;
317+ this . bboxComputed = save ;
312318 return bbox ;
313319 }
314320
315321 /*
316- * @return {BBox } The computed bounding box for the wrapped node
322+ * @param {BBox } bbox The bounding box to modify (either this.bbox, or an empty one)
317323 */
318- protected computeBBox ( ) {
319- const bbox = this . bbox . empty ( ) ;
324+ protected computeBBox ( bbox : BBox ) {
325+ bbox . empty ( ) ;
320326 for ( const child of this . childNodes ) {
321327 bbox . append ( child . getBBox ( ) ) ;
322328 }
323329 bbox . clean ( ) ;
324- return bbox ;
325330 }
326331
327332 /*******************************************************************/
@@ -405,7 +410,8 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
405410 let attributes = this . node . attributes ;
406411 let scriptlevel = Math . min ( attributes . get ( 'scriptlevel' ) as number , 2 ) ;
407412 let fontsize = attributes . get ( 'fontsize' ) ;
408- let mathsize = ( parent && ! this . node . isToken ? parent : this ) . node . attributes . get ( 'mathsize' ) ;
413+ let mathsize = ( this . node . isToken || this . node . isKind ( 'mstyle' ) ?
414+ attributes . get ( 'mathsize' ) : attributes . getInherited ( 'mathsize' ) ) ;
409415 //
410416 // If scriptsize is non-zero, set scale based on scriptsizemultiplier
411417 //
@@ -507,15 +513,25 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
507513 * Set the (relative) scaling factor for the node
508514 */
509515 protected handleScale ( ) {
510- const scale = ( Math . abs ( this . bbox . rscale - 1 ) < .001 ? 1 : this . bbox . rscale ) ;
511- if ( this . chtml && scale !== 1 ) {
516+ this . setScale ( this . chtml , this . bbox . rscale ) ;
517+ }
518+
519+ /*
520+ * @param {HTMLElement } chtml The HTML node to scale
521+ * @param {number } rscale The relatie scale to apply
522+ * @return {HTMLElement } The HTML node (for chaining)
523+ */
524+ setScale ( chtml : HTMLElement , rscale : number ) {
525+ const scale = ( Math . abs ( rscale - 1 ) < .001 ? 1 : rscale ) ;
526+ if ( chtml && scale !== 1 ) {
512527 const size = this . percent ( scale ) ;
513528 if ( FONTSIZE [ size ] ) {
514- this . chtml . setAttribute ( 'size' , FONTSIZE [ size ] ) ;
529+ chtml . setAttribute ( 'size' , FONTSIZE [ size ] ) ;
515530 } else {
516- this . chtml . style . fontSize = size ;
531+ chtml . style . fontSize = size ;
517532 }
518533 }
534+ return chtml ;
519535 }
520536
521537 /*
@@ -524,7 +540,12 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
524540 */
525541 protected handleSpace ( ) {
526542 if ( this . bbox . L ) {
527- this . chtml . setAttribute ( 'space' , ( this . bbox . L * 18 - 2 ) . toString ( ) ) ;
543+ const space = this . em ( this . bbox . L ) ;
544+ if ( SPACE [ space ] ) {
545+ this . chtml . setAttribute ( 'space' , SPACE [ space ] ) ;
546+ } else {
547+ this . chtml . style . marginLeft = space ;
548+ }
528549 }
529550 }
530551
@@ -624,7 +645,7 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
624645 public drawBBox ( ) {
625646 const bbox = this . getBBox ( ) ;
626647 const box = this . html ( 'mjx-box' , { style : {
627- opacity : .25 , 'margin-left' : this . em ( - bbox . w )
648+ opacity : .25 , 'margin-left' : this . em ( - bbox . w - bbox . R )
628649 } } , [
629650 this . html ( 'mjx-box' , { style : {
630651 height : this . em ( bbox . h ) ,
@@ -640,7 +661,7 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
640661 } } )
641662 ] ) ;
642663 const node = this . chtml || this . parent . chtml ;
643- node . appendChild ( box ) ;
664+ node . parentNode . appendChild ( box ) ;
644665 node . style . backgroundColor = '#FFEE00' ;
645666 }
646667
0 commit comments