@@ -134,17 +134,39 @@ export class CHTMLmtable<N, T, D> extends CHTMLWrapper<N, T, D> {
134134 this . rLines = this . getColumnAttributes ( 'rowlines' ) . map ( x => ( x === 'none' ? 0 : .07 ) ) ;
135135 this . cWidths = this . getColumnWidths ( ) ;
136136 //
137- // Stretch the columns ( rows are already taken care of in the CHTMLmtr wrapper)
137+ // Stretch the rows and columns
138138 //
139+ this . stretchRows ( ) ;
140+ this . stretchColumns ( ) ;
141+ }
142+
143+ /*
144+ * Stretch the rows to the equal height or natural height
145+ */
146+ protected stretchRows ( ) {
147+ const equal = this . node . attributes . get ( 'equalrows' ) as boolean ;
148+ const HD = ( equal ? this . getEqualRowHeight ( ) : 0 ) ;
149+ const { H, D} = ( equal ? this . getTableData ( ) : { H : [ 0 ] , D : [ 0 ] } ) ;
150+ for ( let i = 0 ; i < this . numRows ; i ++ ) {
151+ const hd = ( equal ? [ ( HD + H [ i ] - D [ i ] ) / 2 , ( HD - H [ i ] + D [ i ] ) / 2 ] : null ) ;
152+ ( this . childNodes [ i ] as CHTMLmtr < N , T , D > ) . stretchChildren ( hd ) ;
153+ }
154+ }
155+
156+ /*
157+ * Stretch the columns to their proper widths
158+ */
159+ protected stretchColumns ( ) {
139160 for ( let i = 0 ; i < this . numCols ; i ++ ) {
140- this . stretchColumn ( i ) ;
161+ const width = ( typeof this . cWidths [ i ] === 'number' ? this . cWidths [ i ] as number : null ) ;
162+ this . stretchColumn ( i , width ) ;
141163 }
142164 }
143165
144166 /*
145167 * Handle horizontal stretching within the ith column
146168 */
147- protected stretchColumn ( i : number ) {
169+ protected stretchColumn ( i : number , W : number ) {
148170 let stretchy : CHTMLWrapper < N , T , D > [ ] = [ ] ;
149171 //
150172 // Locate and count the stretchy children
@@ -162,21 +184,23 @@ export class CHTMLmtable<N, T, D> extends CHTMLWrapper<N, T, D> {
162184 let count = stretchy . length ;
163185 let nodeCount = this . childNodes . length ;
164186 if ( count && nodeCount > 1 ) {
165- let W = 0 ;
166- //
167- // If all the children are stretchy, find the largest one,
168- // otherwise, find the width of the non-stretchy children.
169- //
170- let all = ( count > 1 && count === nodeCount ) ;
171- for ( const row of ( this . childNodes as CHTMLmtr < N , T , D > [ ] ) ) {
172- const cell = row . childNodes [ i + row . firstCell ] ;
173- if ( cell ) {
174- const child = cell . childNodes [ 0 ] ;
175- const noStretch = ( child . stretch . dir === DIRECTION . None ) ;
176- if ( all || noStretch ) {
177- const { w} = child . getBBox ( noStretch ) ;
178- if ( w > W ) {
179- W = w ;
187+ if ( W === null ) {
188+ W = 0 ;
189+ //
190+ // If all the children are stretchy, find the largest one,
191+ // otherwise, find the width of the non-stretchy children.
192+ //
193+ let all = ( count > 1 && count === nodeCount ) ;
194+ for ( const row of ( this . childNodes as CHTMLmtr < N , T , D > [ ] ) ) {
195+ const cell = row . childNodes [ i + row . firstCell ] ;
196+ if ( cell ) {
197+ const child = cell . childNodes [ 0 ] ;
198+ const noStretch = ( child . stretch . dir === DIRECTION . None ) ;
199+ if ( all || noStretch ) {
200+ const { w} = child . getBBox ( noStretch ) ;
201+ if ( w > W ) {
202+ W = w ;
203+ }
180204 }
181205 }
182206 }
0 commit comments