@@ -28,7 +28,7 @@ import {MmlNode} from '../../../core/MmlTree/MmlNode.js';
2828import { BBox } from '../BBox.js' ;
2929import { DelimiterData } from '../FontData.js' ;
3030import { StyleList } from '../CssStyles.js' ;
31- import { DIRECTION } from '../FontData.js' ;
31+ import { DIRECTION , NOSTRETCH } from '../FontData.js' ;
3232
3333/*
3434 * Convert direction to letter
@@ -68,8 +68,13 @@ export class CHTMLmo extends CHTMLWrapper {
6868 width : '100%'
6969 } ,
7070 'mjx-stretchy-h > mjx-ext > mjx-c' : {
71- transform : 'scalex(1000)' ,
72- margin : '0 -1em'
71+ transform : 'scalex(1000)'
72+ } ,
73+ 'mjx-stretchy-h > mjx-beg > mjx-c' : {
74+ 'margin-right' : '-.1em'
75+ } ,
76+ 'mjx-stretchy-h > mjx-end > mjx-c' : {
77+ 'margin-left' : '-.1em'
7378 } ,
7479
7580 'mjx-stretchy-v' : {
@@ -123,15 +128,16 @@ export class CHTMLmo extends CHTMLWrapper {
123128 public toCHTML ( parent : HTMLElement ) {
124129 // eventually handle centering, largop, etc.
125130 const attributes = this . node . attributes ;
126- const symmetric = attributes . get ( 'symmetric' ) as boolean ;
127- if ( this . stretch && this . size === null ) {
131+ const symmetric = ( attributes . get ( 'symmetric' ) as boolean ) && this . stretch . dir !== DIRECTION . Horizontal ;
132+ const stretchy = this . stretch . dir !== DIRECTION . None ;
133+ if ( stretchy && this . size === null ) {
128134 this . getStretchedVariant ( [ ] ) ;
129135 }
130136 let chtml = this . standardCHTMLnode ( parent ) ;
131137 if ( this . noIC ) {
132138 chtml . setAttribute ( 'noIC' , 'true' ) ;
133139 }
134- if ( this . stretch && this . size < 0 ) {
140+ if ( stretchy && this . size < 0 ) {
135141 this . stretchHTML ( chtml , symmetric ) ;
136142 } else {
137143 if ( symmetric || attributes . get ( 'largeop' ) ) {
@@ -151,16 +157,17 @@ export class CHTMLmo extends CHTMLWrapper {
151157 */
152158 protected stretchHTML ( chtml : HTMLElement , symmetric : boolean ) {
153159 const c = this . getText ( ) . charCodeAt ( 0 ) ;
154- const C = this . font . getDelimiter ( c ) . stretch ;
160+ const delim = this . stretch ;
161+ const stretch = delim . stretch ;
155162 const content : HTMLElement [ ] = [ ] ;
156163 //
157164 // Set up the beginning, extension, and end pieces
158165 //
159- if ( C [ 0 ] ) {
166+ if ( stretch [ 0 ] ) {
160167 content . push ( this . html ( 'mjx-beg' , { } , [ this . html ( 'mjx-c' ) ] ) ) ;
161168 }
162169 content . push ( this . html ( 'mjx-ext' , { } , [ this . html ( 'mjx-c' ) ] ) ) ;
163- if ( C . length === 4 ) {
170+ if ( stretch . length === 4 ) {
164171 //
165172 // Braces have a middle and second extensible piece
166173 //
@@ -169,15 +176,15 @@ export class CHTMLmo extends CHTMLWrapper {
169176 this . html ( 'mjx-ext' , { } , [ this . html ( 'mjx-c' ) ] )
170177 ) ;
171178 }
172- if ( C [ 2 ] ) {
179+ if ( stretch [ 2 ] ) {
173180 content . push ( this . html ( 'mjx-end' , { } , [ this . html ( 'mjx-c' ) ] ) ) ;
174181 }
175182 //
176183 // Set the styles needed
177184 //
178185 const styles : StringMap = { } ;
179186 const { h, d, w} = this . bbox ;
180- if ( this . stretch === DIRECTION . Vertical ) {
187+ if ( delim . dir === DIRECTION . Vertical ) {
181188 //
182189 // Vertical needs an extra (empty) element to get vertical position right
183190 // in some browsers (e.g., Safari)
@@ -191,27 +198,28 @@ export class CHTMLmo extends CHTMLWrapper {
191198 //
192199 // Make the main element and add it to the parent
193200 //
194- const dir = DirectionVH [ this . stretch ] ;
195- const html = this . html ( 'mjx-stretchy-' + dir , { c : this . char ( c ) , style : styles } , content ) ;
201+ const dir = DirectionVH [ delim . dir ] ;
202+ const properties = { c : this . char ( delim . c || c ) , style : styles } ;
203+ const html = this . html ( 'mjx-stretchy-' + dir , properties , content ) ;
196204 chtml . appendChild ( html ) ;
197205 }
198206
199207 /*
200208 * @override
201209 */
202210 public computeBBox ( bbox : BBox ) {
203- const symmetric = this . node . attributes . get ( 'symmetric' ) ;
204- if ( this . stretch && this . size === null ) {
211+ const stretchy = ( this . stretch . dir !== DIRECTION . None ) ;
212+ if ( stretchy && this . size === null ) {
205213 this . getStretchedVariant ( [ 0 ] ) ;
206214 }
207- if ( this . stretch && this . size < 0 ) return ;
215+ if ( stretchy && this . size < 0 ) return ;
208216 super . computeBBox ( bbox ) ;
209217 const child = this . childNodes [ this . childNodes . length - 1 ] ;
210218 if ( child && child . bbox . ic ) {
211219 bbox . ic = child . bbox . ic ;
212220 if ( ! this . noIC ) bbox . w += bbox . ic ;
213221 }
214- if ( symmetric ) {
222+ if ( this . node . attributes . get ( ' symmetric' ) && this . stretch . dir !== DIRECTION . Horizontal ) {
215223 const d = ( ( bbox . h + bbox . d ) / 2 + this . font . params . axis_height ) - bbox . h ;
216224 bbox . h += d ;
217225 bbox . d += d ;
@@ -238,8 +246,8 @@ export class CHTMLmo extends CHTMLWrapper {
238246 const c = this . getText ( ) ;
239247 if ( c . length !== 1 ) return false ;
240248 const delim = this . font . getDelimiter ( c . charCodeAt ( 0 ) ) ;
241- this . stretch = ( delim && delim . dir === direction ? delim . dir : DIRECTION . None ) ;
242- return this . stretch !== DIRECTION . None ;
249+ this . stretch = ( delim && delim . dir === direction ? delim : NOSTRETCH ) ;
250+ return this . stretch . dir !== DIRECTION . None ;
243251 }
244252
245253 /*
@@ -249,7 +257,7 @@ export class CHTMLmo extends CHTMLWrapper {
249257 * @param {boolean } exact True if not allowed to use delimiter factor and shortfall
250258 */
251259 public getStretchedVariant ( WH : number [ ] , exact : boolean = false ) {
252- if ( this . stretch ) {
260+ if ( this . stretch . dir !== DIRECTION . None ) {
253261 let D = this . getWH ( WH ) ;
254262 const min = this . getSize ( 'minsize' , 0 ) ;
255263 const max = this . getSize ( 'maxsize' , Infinity ) ;
@@ -263,16 +271,18 @@ export class CHTMLmo extends CHTMLWrapper {
263271 //
264272 // Look through the delimiter sizes for one that matches
265273 //
266- const c = this . getText ( ) . charCodeAt ( 0 ) ;
267- const delim = this . font . getDelimiter ( c ) ;
274+ const delim = this . stretch ;
275+ const c = delim . c || this . getText ( ) . charCodeAt ( 0 ) ;
268276 let i = 0 ;
269- for ( const d of delim . sizes ) {
270- if ( d >= m ) {
271- this . variant = this . font . getSizeVariant ( c , i ) ;
272- this . size = i ;
273- return ;
277+ if ( delim . sizes ) {
278+ for ( const d of delim . sizes ) {
279+ if ( d >= m ) {
280+ this . variant = this . font . getSizeVariant ( c , i ) ;
281+ this . size = i ;
282+ return ;
283+ }
284+ i ++ ;
274285 }
275- i ++ ;
276286 }
277287 //
278288 // No size matches, so if we can make multi-character delimiters,
@@ -289,8 +299,9 @@ export class CHTMLmo extends CHTMLWrapper {
289299 }
290300
291301 /*
292- * @param {string } name The name of the attribute to fix
302+ * @param {string } name The name of the attribute to get
293303 * @param {number } value The default value to use
304+ * @return {number } The size in em's of the attribute (or the default value)
294305 */
295306 protected getSize ( name : string , value : number ) {
296307 let attributes = this . node . attributes ;
@@ -302,6 +313,7 @@ export class CHTMLmo extends CHTMLWrapper {
302313
303314 /*
304315 * @param {number[] } WH Either [W] for width, [H, D] for height and depth, or [] for min/max size
316+ * @return {number } Either the width or the total height of the character
305317 */
306318 protected getWH ( WH : number [ ] ) {
307319 if ( WH . length === 0 ) return 0 ;
@@ -318,7 +330,7 @@ export class CHTMLmo extends CHTMLWrapper {
318330 */
319331 protected getStretchBBox ( WHD : number [ ] , D : number , C : DelimiterData ) {
320332 let [ h , d , w ] = C . HDW ;
321- if ( this . stretch === DIRECTION . Vertical ) {
333+ if ( this . stretch . dir === DIRECTION . Vertical ) {
322334 [ h , d ] = this . getBaseline ( WHD , D , C ) ;
323335 } else {
324336 w = D ;
@@ -332,7 +344,7 @@ export class CHTMLmo extends CHTMLWrapper {
332344 * @param {number[] } WHD The [H, D] being requested from the parent mrow
333345 * @param {number } HD The full height (including symmetry, etc)
334346 * @param {DelimiterData } C The delimiter data for the stretchy character
335- * @param {number[] } The height and depth for the vertically stretched delimiter
347+ * @return {number[] } The height and depth for the vertically stretched delimiter
336348 */
337349 protected getBaseline ( WHD : number [ ] , HD : number , C : DelimiterData ) {
338350 const hasWHD = ( WHD . length === 2 ) ;
0 commit comments