@@ -243,7 +243,6 @@ export interface CommonMtable<
243
243
* @param {number[] } D The maximum depth for each of the rows
244
244
* @param {number[] } W The maximum width for each column
245
245
* @param {number } M The current height for items aligned top and bottom
246
- * @returns {number } The updated value for M
247
246
*/
248
247
updateHDW (
249
248
cell : WW ,
@@ -254,17 +253,7 @@ export interface CommonMtable<
254
253
D : number [ ] ,
255
254
W : number [ ] ,
256
255
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 ;
268
257
269
258
/**
270
259
* @param {WW } cell The cell to check for percentage widths
@@ -744,21 +733,29 @@ export function CommonMtableMixin<
744
733
if (
745
734
this . jax . math . root . attributes . get ( 'overflow' ) !== 'linebreak' ||
746
735
! this . jax . math . display
747
- )
736
+ ) {
748
737
return ;
749
- const { D } = this . getTableData ( ) ;
738
+ }
739
+ const { H, D } = this . getTableData ( ) ;
750
740
let j = 0 ;
751
741
let w = 0 ;
752
742
for ( const row of this . tableRows ) {
753
743
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 ;
756
746
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 ;
760
754
}
761
755
}
756
+ const bbox = row . getBBox ( ) ;
757
+ bbox . h = H [ j ] ;
758
+ bbox . d = D [ j ] ;
762
759
j ++ ;
763
760
}
764
761
//
@@ -791,27 +788,72 @@ export function CommonMtableMixin<
791
788
const LW = [ 0 ] ;
792
789
const rows = this . tableRows ;
793
790
for ( let j = 0 ; j < rows . length ; j ++ ) {
794
- let M = 0 ;
795
791
const row = rows [ j ] ;
796
792
const align = row . node . attributes . get ( 'rowalign' ) as string ;
797
793
for ( let i = 0 ; i < row . numCells ; i ++ ) {
798
794
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 ) ;
800
796
this . recordPWidthCell ( cell , i ) ;
801
797
}
802
798
NH [ j ] = H [ j ] ;
803
799
ND [ j ] = D [ j ] ;
804
800
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 ) ;
806
802
}
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 ] ;
809
805
}
810
806
const L = LW [ 0 ] ;
811
807
this . data = { H, D, W, NH , ND , L } ;
812
808
return this . data ;
813
809
}
814
810
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
+
815
857
/**
816
858
* @override
817
859
*/
@@ -822,9 +864,8 @@ export function CommonMtableMixin<
822
864
align : string ,
823
865
H : number [ ] ,
824
866
D : number [ ] ,
825
- W : number [ ] ,
826
- M : number
827
- ) : number {
867
+ W : number [ ] = null
868
+ ) {
828
869
let { h, d, w } = cell . getBBox ( ) ;
829
870
const scale = cell . parent . bbox . rscale ;
830
871
if ( cell . parent . bbox . rscale !== 1 ) {
@@ -836,27 +877,12 @@ export function CommonMtableMixin<
836
877
if ( h < 0.75 ) h = 0.75 ;
837
878
if ( d < 0.25 ) d = 0.25 ;
838
879
}
839
- let m = 0 ;
840
880
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' ;
844
883
}
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 ) ;
848
885
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 ;
860
886
}
861
887
862
888
/**
0 commit comments