@@ -244,7 +244,7 @@ export const ChtmlMo = (function <N, T, D>(): ChtmlMoClass<N, T, D> {
244244 const delim = this . stretch ;
245245 const stretch = delim . stretch ;
246246 const stretchv = this . font . getStretchVariants ( c ) ;
247- const content : N [ ] = [ ] ;
247+ const dom : N [ ] = [ ] ;
248248
249249 //
250250 // Look up the characters to use
@@ -261,30 +261,27 @@ export const ChtmlMo = (function <N, T, D>(): ChtmlMoClass<N, T, D> {
261261 const { h, d, w } = this . bbox ;
262262 const styles : StringMap = { } ;
263263 if ( delim . dir === DIRECTION . Vertical ) {
264- this . createAssembly ( parts , stretch , stretchv , content , h + d , 0 , '\n' ) ;
264+ //
265+ // The ext parameter should be 0, but line-height in Safari
266+ // is not accurate, so this produces extra extenders to compensate
267+ //
268+ this . createAssembly ( parts , stretch , stretchv , dom , h + d , 0.05 , '\n' ) ;
265269 //
266270 // Vertical needs an extra (empty) element to get vertical position right
267271 // in some browsers (e.g., Safari)
268272 //
269- content . push ( this . html ( 'mjx-mark' ) ) ;
273+ dom . push ( this . html ( 'mjx-mark' ) ) ;
270274 styles . height = this . em ( h + d ) ;
271275 styles . verticalAlign = this . em ( - d ) ;
272276 } else {
273- this . createAssembly (
274- parts ,
275- stretch ,
276- stretchv ,
277- content ,
278- w ,
279- delim . ext || 0
280- ) ;
277+ this . createAssembly ( parts , stretch , stretchv , dom , w , delim . ext || 0 ) ;
281278 styles . width = this . em ( w ) ;
282279 }
283280 //
284281 // Make the main element and add it to the parent
285282 //
286283 const properties = { class : this . char ( delim . c || c ) , style : styles } ;
287- const html = this . html ( 'mjx-stretchy-' + delim . dir , properties , content ) ;
284+ const html = this . html ( 'mjx-stretchy-' + delim . dir , properties , dom ) ;
288285 const adaptor = this . adaptor ;
289286 if ( chtml [ 0 ] ) {
290287 adaptor . append ( chtml [ 0 ] , html ) ;
@@ -300,7 +297,7 @@ export const ChtmlMo = (function <N, T, D>(): ChtmlMoClass<N, T, D> {
300297 * @param {PartData[] } parts The extender parts character data array
301298 * @param {number[] } sn The extender parts character code points
302299 * @param {string[] } sv The extender parts variants
303- * @param {N[] } content The assembly DOM to build
300+ * @param {N[] } dom The assembly DOM to build
304301 * @param {number } wh The delimiter's full width/height
305302 * @param {number } ext The extender character's bearing whitspace
306303 * @param {string } nl The string to use between extender characters
@@ -309,9 +306,9 @@ export const ChtmlMo = (function <N, T, D>(): ChtmlMoClass<N, T, D> {
309306 parts : PartData [ ] ,
310307 sn : number [ ] ,
311308 sv : string [ ] ,
312- content : N [ ] ,
309+ dom : N [ ] ,
313310 wh : number ,
314- ext : number = 0 ,
311+ ext : number ,
315312 nl : string = ''
316313 ) {
317314 //
@@ -321,9 +318,10 @@ export const ChtmlMo = (function <N, T, D>(): ChtmlMoClass<N, T, D> {
321318 //
322319 // Get the part width/heights (beginning, extender, end, middle)
323320 //
324- const [ WHb , WHx , WHe , WHm ] = parts . map ( ( part ) =>
321+ let [ WHb , WHx , WHe , WHm ] = parts . map ( ( part ) =>
325322 part ? ( nl ? part [ 0 ] + part [ 1 ] : part [ 2 ] ) : 0
326323 ) ;
324+ WHx = Math . max ( 0 , WHx - ext ) ;
327325 //
328326 // Get the extension width/heights (two when there is a middle piece)
329327 //
@@ -333,31 +331,13 @@ export const ChtmlMo = (function <N, T, D>(): ChtmlMoClass<N, T, D> {
333331 //
334332 // Set up the beginning, extension, and end pieces
335333 //
336- this . createPart ( 'mjx-beg' , parts [ 0 ] , sn [ 0 ] , sv [ 0 ] , content ) ;
337- this . createPart (
338- 'mjx-ext' ,
339- parts [ 1 ] ,
340- sn [ 1 ] ,
341- sv [ 1 ] ,
342- content ,
343- WH1 ,
344- WHx - ext ,
345- nl
346- ) ;
334+ this . createPart ( 'mjx-beg' , parts [ 0 ] , sn [ 0 ] , sv [ 0 ] , dom ) ;
335+ this . createPart ( 'mjx-ext' , parts [ 1 ] , sn [ 1 ] , sv [ 1 ] , dom , WH1 , WHx , nl ) ;
347336 if ( parts [ 3 ] ) {
348- this . createPart ( 'mjx-mid' , parts [ 3 ] , sn [ 3 ] , sv [ 3 ] , content ) ;
349- this . createPart (
350- 'mjx-ext' ,
351- parts [ 1 ] ,
352- sn [ 1 ] ,
353- sv [ 1 ] ,
354- content ,
355- WH2 ,
356- WHx - ext ,
357- nl
358- ) ;
337+ this . createPart ( 'mjx-mid' , parts [ 3 ] , sn [ 3 ] , sv [ 3 ] , dom ) ;
338+ this . createPart ( 'mjx-ext' , parts [ 1 ] , sn [ 1 ] , sv [ 1 ] , dom , WH2 , WHx , nl ) ;
359339 }
360- this . createPart ( 'mjx-end' , parts [ 2 ] , sn [ 2 ] , sv [ 2 ] , content ) ;
340+ this . createPart ( 'mjx-end' , parts [ 2 ] , sn [ 2 ] , sv [ 2 ] , dom ) ;
361341 }
362342
363343 /**
@@ -367,7 +347,7 @@ export const ChtmlMo = (function <N, T, D>(): ChtmlMoClass<N, T, D> {
367347 * @param {PartData } data The character data for the part
368348 * @param {number } n The unicode character to use
369349 * @param {string } v The variant for the character
370- * @param {N[] } content The DOM assembly
350+ * @param {N[] } dom The DOM assembly
371351 * @param {number } W The extendion width
372352 * @param {number } Wx The width of the extender character
373353 * @param {string } nl Character to use between extenders
@@ -377,7 +357,7 @@ export const ChtmlMo = (function <N, T, D>(): ChtmlMoClass<N, T, D> {
377357 data : PartData ,
378358 n : number ,
379359 v : string ,
380- content : N [ ] ,
360+ dom : N [ ] ,
381361 W : number = 0 ,
382362 Wx : number = 0 ,
383363 nl : string = ''
@@ -391,8 +371,13 @@ export const ChtmlMo = (function <N, T, D>(): ChtmlMoClass<N, T, D> {
391371 const c = options . c || String . fromCodePoint ( n ) ;
392372 let nodes = [ ] as ( N | T ) [ ] ;
393373 if ( part === 'mjx-ext' && ( Wx || options . dx ) ) {
374+ //
375+ // Some combining characters are listed as width 0,
376+ // so get "real" width from dx and take off some
377+ // for the right bearing.
378+ //
394379 if ( ! Wx ) {
395- Wx = 2 * options . dx - 0.06 ;
380+ Wx = Math . max ( 0.06 , 2 * options . dx - 0.06 ) ;
396381 }
397382 const n = Math . min ( Math . ceil ( W / Wx ) + 1 , 500 ) ;
398383 if ( options . cmb ) {
@@ -403,18 +388,14 @@ export const ChtmlMo = (function <N, T, D>(): ChtmlMoClass<N, T, D> {
403388 } else {
404389 nodes = [
405390 this . html ( 'mjx-spacer' , { } , [
406- this . text (
407- Array ( n )
408- . fill ( c + nl )
409- . join ( '' )
410- ) ,
391+ this . text ( Array ( n ) . fill ( c ) . join ( nl ) ) ,
411392 ] ) ,
412393 ] ;
413394 }
414395 } else {
415396 nodes = [ this . text ( c ) ] ;
416397 }
417- content . push ( this . html ( part , font ? { class : font } : { } , nodes ) ) ;
398+ dom . push ( this . html ( part , font ? { class : font } : { } , nodes ) ) ;
418399 }
419400 }
420401 } ;
0 commit comments