@@ -26,7 +26,7 @@ import {CHTMLWrapperFactory} from '../WrapperFactory.js';
2626import { CHTMLmo } from './mo.js' ;
2727import { BBox } from '../BBox.js' ;
2828import { MmlMsqrt } from '../../../core/MmlTree/MmlNodes/msqrt.js' ;
29- import { MmlNode , AbstractMmlNode , TextNode } from '../../../core/MmlTree/MmlNode.js' ;
29+ import { MmlNode , AbstractMmlNode , TextNode , AttributeList } from '../../../core/MmlTree/MmlNode.js' ;
3030import { StyleList } from '../CssStyles.js' ;
3131import { DIRECTION } from '../FontData.js' ;
3232
@@ -40,11 +40,19 @@ export class CHTMLmsqrt extends CHTMLWrapper {
4040
4141 public static styles : StyleList = {
4242 'mjx-root' : {
43- display : 'inline-block'
43+ display : 'inline-block' ,
44+ 'white-space' : 'nowrap'
4445 } ,
4546 'mjx-surd' : {
4647 display : 'inline-block' ,
4748 'vertical-align' : 'top'
49+ } ,
50+ 'mjx-sqrt' : {
51+ display : 'inline-block' ,
52+ 'padding-top' : '.07em'
53+ } ,
54+ 'mjx-sqrt > mjx-box' : {
55+ 'border-top' : '.07em solid'
4856 }
4957 } ;
5058
@@ -87,17 +95,28 @@ export class CHTMLmsqrt extends CHTMLWrapper {
8795 const t = this . font . params . rule_thickness ;
8896 const p = ( this . node . attributes . get ( 'displaystyle' ) ? this . font . params . x_height : t ) ;
8997 this . surdH = h + d + 2 * t + p / 4 ;
90- surd . getStretchedVariant ( [ this . surdH , 0 ] ) ;
98+ surd . getStretchedVariant ( [ this . surdH - d , d ] , true ) ;
9199 }
92100
93101 /*
94- * Create an mo wrapper with the given text;
102+ * Create an mo wrapper with the given text,
103+ * link it in, and give it the right defaults.
95104 *
96105 * @param {string } text The text for the wrapped element
97106 * @return {CHTMLWrapper } The wrapped MmlMo node
98107 */
99108 protected createMo ( text : string ) {
100- const node = this . wrap ( this . mmlNode ( 'mo' , { stretchy : true } , [ this . mmlText ( text ) ] ) ) as CHTMLmo ;
109+ const mmlFactory = ( this . node as AbstractMmlNode ) . factory ;
110+ const textNode = ( mmlFactory . create ( 'text' ) as TextNode ) . setText ( text ) ;
111+ const mml = mmlFactory . create ( 'mo' , { stretchy : true } , [ textNode ] ) ;
112+ const attributes = this . node . attributes ;
113+ const display = attributes . get ( 'display' ) as boolean ;
114+ const scriptlevel = attributes . get ( 'scriptlevel' ) as number ;
115+ const defaults : AttributeList = {
116+ mathsize : [ 'math' , attributes . get ( 'mathsize' ) ]
117+ } ;
118+ mml . setInheritedAttributes ( defaults , display , scriptlevel , false ) ;
119+ const node = this . wrap ( mml ) as CHTMLmo ;
101120 node . parent = this ;
102121 this . childNodes . push ( node ) ;
103122 return node ;
@@ -115,9 +134,6 @@ export class CHTMLmsqrt extends CHTMLWrapper {
115134 const sbox = surd . getBBox ( ) ;
116135 const bbox = base . getBBox ( ) ;
117136 const [ p , q ] = this . getPQ ( sbox ) ;
118- const [ x ] = this . getRootDimens ( sbox ) ;
119- const t = this . font . params . rule_thickness ;
120- const T = this . font . params . surd_height ;
121137 //
122138 // Create the HTML structure for the root
123139 //
@@ -127,14 +143,9 @@ export class CHTMLmsqrt extends CHTMLWrapper {
127143 ROOT = CHTML . appendChild ( this . html ( 'mjx-root' ) ) ;
128144 root = this . childNodes [ this . root ] ;
129145 }
130- const SQRT = CHTML . appendChild ( this . html ( 'mjx-box' , {
131- style : { paddingTop : this . px ( 2 * t - T , 1 ) }
132- } , [
146+ const SQRT = CHTML . appendChild ( this . html ( 'mjx-sqrt' , { } , [
133147 SURD = this . html ( 'mjx-surd' ) ,
134- BASE = this . html ( 'mjx-box' , { style : {
135- paddingTop : this . px ( q , 1 ) ,
136- borderTop : this . px ( T * bbox . scale , 1 ) + ' solid'
137- } } )
148+ BASE = this . html ( 'mjx-box' , { style : { paddingTop : this . em ( q ) } } )
138149 ] ) ) ;
139150 //
140151 // Add the child content
@@ -158,19 +169,19 @@ export class CHTMLmsqrt extends CHTMLWrapper {
158169 * @override
159170 */
160171 public computeBBox ( ) {
161- const box = BBox . empty ( ) ;
172+ const BBOX = this . bbox . empty ( ) ;
162173 const sbox = this . childNodes [ this . surd ] . getBBox ( ) ;
163174 const bbox = new BBox ( this . childNodes [ this . base ] . getBBox ( ) ) ;
164175 const [ p , q ] = this . getPQ ( sbox ) ;
165176 const [ x ] = this . getRootDimens ( sbox ) ;
166177 const t = this . font . params . rule_thickness ;
167178 const H = bbox . h + q + t ;
168- bbox . h += q + 2 * t ; // FIXME: should take into account minimums for this.px() used above
169- this . combineRootBBox ( box , sbox ) ;
170- box . combine ( sbox , x , H - sbox . h ) ;
171- box . combine ( bbox , x + sbox . w , 0 ) ;
172- box . clean ( ) ;
173- return box ;
179+ bbox . h = H + t ;
180+ this . combineRootBBox ( BBOX , sbox ) ;
181+ BBOX . combine ( sbox , x , H - sbox . h ) ;
182+ BBOX . combine ( bbox , x + sbox . w , 0 ) ;
183+ BBOX . clean ( ) ;
184+ return BBOX ;
174185 }
175186
176187 /*
@@ -183,7 +194,7 @@ export class CHTMLmsqrt extends CHTMLWrapper {
183194 }
184195
185196 /*
186- * @param {BBox } sbox The bounding box for the surd character
197+ * @param {BBox } sbox The bounding box for the surd character
187198 * @return {number[] } The p, q, and x values for the TeX layout computations
188199 */
189200 protected getPQ ( sbox : BBox ) {
0 commit comments