@@ -243,7 +243,6 @@ export interface CommonMtable<
243243 * @param {number[] } D The maximum depth for each of the rows
244244 * @param {number[] } W The maximum width for each column
245245 * @param {number } M The current height for items aligned top and bottom
246- * @returns {number } The updated value for M
247246 */
248247 updateHDW (
249248 cell : WW ,
@@ -254,17 +253,7 @@ export interface CommonMtable<
254253 D : number [ ] ,
255254 W : number [ ] ,
256255 M : number
257- ) : number ;
258-
259- /**
260- * Extend the H and D of a row to cover the maximum height needed by top/bottom aligned items
261- *
262- * @param {number } i The row whose hight and depth should be adjusted
263- * @param {number[] } H The row heights
264- * @param {number[] } D The row depths
265- * @param {number } M The maximum height of top/bottom aligned items
266- */
267- extendHD ( i : number , H : number [ ] , D : number [ ] , M : number ) : void ;
256+ ) : void ;
268257
269258 /**
270259 * @param {WW } cell The cell to check for percentage widths
@@ -744,21 +733,29 @@ export function CommonMtableMixin<
744733 if (
745734 this . jax . math . root . attributes . get ( 'overflow' ) !== 'linebreak' ||
746735 ! this . jax . math . display
747- )
736+ ) {
748737 return ;
749- const { D } = this . getTableData ( ) ;
738+ }
739+ const { H, D } = this . getTableData ( ) ;
750740 let j = 0 ;
751741 let w = 0 ;
752742 for ( const row of this . tableRows ) {
753743 const cell = row . getChild ( i ) ;
754- if ( cell && cell . getBBox ( ) . w > W ) {
755- cell . childNodes [ 0 ] . breakToWidth ( W ) ;
744+ if ( cell ) {
745+ const r = row . getBBox ( ) . rscale ;
756746 const bbox = cell . getBBox ( ) ;
757- D [ j ] = Math . max ( D [ j ] , bbox . d ) ;
758- if ( bbox . w > w ) {
759- w = bbox . w ;
747+ if ( cell && bbox . w * r > W ) {
748+ cell . childNodes [ 0 ] . breakToWidth ( W ) ;
749+ const align = row . node . attributes . get ( 'rowalign' ) as string ;
750+ this . updateHDW ( cell , i , j , align , H , D ) ;
751+ }
752+ if ( bbox . w * r > w ) {
753+ w = bbox . w * r ;
760754 }
761755 }
756+ const bbox = row . getBBox ( ) ;
757+ bbox . h = H [ j ] ;
758+ bbox . d = D [ j ] ;
762759 j ++ ;
763760 }
764761 //
@@ -791,27 +788,72 @@ export function CommonMtableMixin<
791788 const LW = [ 0 ] ;
792789 const rows = this . tableRows ;
793790 for ( let j = 0 ; j < rows . length ; j ++ ) {
794- let M = 0 ;
795791 const row = rows [ j ] ;
796792 const align = row . node . attributes . get ( 'rowalign' ) as string ;
797793 for ( let i = 0 ; i < row . numCells ; i ++ ) {
798794 const cell = row . getChild ( i ) ;
799- M = this . updateHDW ( cell , i , j , align , H , D , W , M ) ;
795+ this . updateHDW ( cell , i , j , align , H , D , W ) ;
800796 this . recordPWidthCell ( cell , i ) ;
801797 }
802798 NH [ j ] = H [ j ] ;
803799 ND [ j ] = D [ j ] ;
804800 if ( row . labeled ) {
805- M = this . updateHDW ( row . childNodes [ 0 ] , 0 , j , align , H , D , LW , M ) ;
801+ this . updateHDW ( row . childNodes [ 0 ] , 0 , j , align , H , D , LW ) ;
806802 }
807- this . extendHD ( j , H , D , M ) ;
808- this . extendHD ( j , NH , ND , M ) ;
803+ row . bbox . h = H [ j ] ;
804+ row . bbox . d = D [ j ] ;
809805 }
810806 const L = LW [ 0 ] ;
811807 this . data = { H, D, W, NH , ND , L } ;
812808 return this . data ;
813809 }
814810
811+ /**
812+ * Functions for adjusting the H and D values for cells
813+ * that are aligned by top, bottom, center, axis, and baseline.
814+ */
815+ protected adjustHD : {
816+ [ name : string ] : (
817+ h : number ,
818+ d : number ,
819+ H : number [ ] ,
820+ D : number [ ] ,
821+ j : number
822+ ) => void ;
823+ } = {
824+ top : ( h , d , H , D , j ) => {
825+ if ( h > H [ j ] ) {
826+ D [ j ] -= h - H [ j ] ;
827+ H [ j ] = h ;
828+ }
829+ if ( h + d > H [ j ] + D [ j ] ) {
830+ D [ j ] = h + d - H [ j ] ;
831+ }
832+ } ,
833+ bottom : ( h , d , H , D , j ) => {
834+ if ( d > D [ j ] ) {
835+ H [ j ] -= d - D [ j ] ;
836+ D [ j ] = d ;
837+ }
838+ if ( h + d > H [ j ] + D [ j ] ) {
839+ H [ j ] = h + d - D [ j ] ;
840+ }
841+ } ,
842+ center : ( h , d , H , D , j ) => {
843+ if ( h + d > H [ j ] + D [ j ] ) {
844+ H [ j ] = D [ j ] = ( h + d ) / 2 ;
845+ }
846+ } ,
847+ other : ( h , d , H , D , j ) => {
848+ if ( h > H [ j ] ) {
849+ H [ j ] = h ;
850+ }
851+ if ( d > D [ j ] ) {
852+ D [ j ] = d ;
853+ }
854+ } ,
855+ } ;
856+
815857 /**
816858 * @override
817859 */
@@ -822,9 +864,8 @@ export function CommonMtableMixin<
822864 align : string ,
823865 H : number [ ] ,
824866 D : number [ ] ,
825- W : number [ ] ,
826- M : number
827- ) : number {
867+ W : number [ ] = null
868+ ) {
828869 let { h, d, w } = cell . getBBox ( ) ;
829870 const scale = cell . parent . bbox . rscale ;
830871 if ( cell . parent . bbox . rscale !== 1 ) {
@@ -836,27 +877,12 @@ export function CommonMtableMixin<
836877 if ( h < 0.75 ) h = 0.75 ;
837878 if ( d < 0.25 ) d = 0.25 ;
838879 }
839- let m = 0 ;
840880 align = ( cell . node . attributes . get ( 'rowalign' ) as string ) || align ;
841- if ( align !== 'baseline' && align !== 'axis' ) {
842- m = h + d ;
843- h = d = 0 ;
881+ if ( ! Object . hasOwn ( this . adjustHD , align ) ) {
882+ align = 'other' ;
844883 }
845- if ( h > H [ j ] ) H [ j ] = h ;
846- if ( d > D [ j ] ) D [ j ] = d ;
847- if ( m > M ) M = m ;
884+ this . adjustHD [ align ] ( h , d , H , D , j ) ;
848885 if ( W && w > W [ i ] ) W [ i ] = w ;
849- return M ;
850- }
851-
852- /**
853- * @override
854- */
855- public extendHD ( i : number , H : number [ ] , D : number [ ] , M : number ) {
856- const d = ( M - ( H [ i ] + D [ i ] ) ) / 2 ;
857- if ( d < 0.00001 ) return ;
858- H [ i ] += d ;
859- D [ i ] += d ;
860886 }
861887
862888 /**
0 commit comments