2323
2424import { AbstractWrapper } from '../../core/Tree/Wrapper.js' ;
2525import { Node , PropertyList } from '../../core/Tree/Node.js' ;
26- import { MmlNode , TextNode , AbstractMmlNode , AttributeList } from '../../core/MmlTree/MmlNode.js' ;
26+ import { MmlNode , TextNode , AbstractMmlNode , AttributeList , indentAttributes } from '../../core/MmlTree/MmlNode.js' ;
2727import { Property } from '../../core/Tree/Node.js' ;
2828import { OptionList } from '../../util/Options.js' ;
2929import { unicodeChars } from '../../util/string.js' ;
@@ -277,7 +277,11 @@ export class CHTMLWrapper<N, T, D> extends AbstractWrapper<MmlNode, CHTMLWrapper
277277 this . getScale ( ) ;
278278 this . getSpace ( ) ;
279279 this . childNodes = node . childNodes . map ( ( child : Node ) => {
280- return this . wrap ( child as MmlNode ) ;
280+ const wrapped = this . wrap ( child as MmlNode ) ;
281+ if ( wrapped . bbox . pwidth ) {
282+ this . bbox . pwidth = BBox . fullWidth ;
283+ }
284+ return wrapped ;
281285 } ) ;
282286 }
283287
@@ -494,6 +498,7 @@ export class CHTMLWrapper<N, T, D> extends AbstractWrapper<MmlNode, CHTMLWrapper
494498 this . handleColor ( ) ;
495499 this . handleSpace ( ) ;
496500 this . handleAttributes ( ) ;
501+ this . handlePWidth ( ) ;
497502 return chtml ;
498503 }
499504
@@ -602,7 +607,8 @@ export class CHTMLWrapper<N, T, D> extends AbstractWrapper<MmlNode, CHTMLWrapper
602607 const defaults = attributes . getAllDefaults ( ) ;
603608 const skip = CHTMLWrapper . skipAttributes ;
604609 for ( const name of attributes . getExplicitNames ( ) ) {
605- if ( skip [ name ] === false || ( ! ( name in defaults ) && ! skip [ name ] && ! this . adaptor . hasAttribute ( this . chtml , name ) ) ) {
610+ if ( skip [ name ] === false || ( ! ( name in defaults ) && ! skip [ name ] &&
611+ ! this . adaptor . hasAttribute ( this . chtml , name ) ) ) {
606612 this . adaptor . setAttribute ( this . chtml , name , attributes . getExplicit ( name ) as string ) ;
607613 }
608614 }
@@ -611,6 +617,19 @@ export class CHTMLWrapper<N, T, D> extends AbstractWrapper<MmlNode, CHTMLWrapper
611617 }
612618 }
613619
620+ /*
621+ * Handle the attributes needed for percentage widths
622+ */
623+ protected handlePWidth ( ) {
624+ if ( this . bbox . pwidth ) {
625+ if ( this . bbox . pwidth === BBox . fullWidth ) {
626+ this . adaptor . setAttribute ( this . chtml , 'width' , 'full' ) ;
627+ } else {
628+ this . adaptor . setStyle ( this . chtml , 'width' , this . bbox . pwidth ) ;
629+ }
630+ }
631+ }
632+
614633 /*******************************************************************/
615634
616635 /*
@@ -659,6 +678,42 @@ export class CHTMLWrapper<N, T, D> extends AbstractWrapper<MmlNode, CHTMLWrapper
659678 return this . stretch . dir !== DIRECTION . None ;
660679 }
661680
681+ /*
682+ * @return {[string, number] } The alignment and indentation shift for the expression
683+ */
684+ protected getAlignShift ( ) {
685+ let { indentalign, indentshift, indentalignfirst, indentshiftfirst} =
686+ this . node . attributes . getList ( ...indentAttributes ) as StringMap ;
687+ if ( indentalignfirst !== 'indentalign' ) {
688+ indentalign = indentalignfirst ;
689+ }
690+ if ( indentalign === 'auto' ) {
691+ indentalign = 'center' ;
692+ }
693+ if ( indentshiftfirst !== 'indentshift' ) {
694+ indentshift = indentshiftfirst ;
695+ }
696+ if ( indentshift === 'auto' ) {
697+ indentshift = '0' ;
698+ }
699+ const shift = this . length2em ( indentshift , this . metrics . containerWidth ) ;
700+ return [ indentalign , shift ] as [ string , number ] ;
701+ }
702+
703+ /*
704+ * @param {N } chtml The HTML node whose indentation is to be adjusted
705+ * @param {string } align The alignment for the node
706+ * @param {number } shift The indent (positive or negative) for the node
707+ */
708+ protected setIndent ( chtml : N , align : string , shift : number ) {
709+ if ( align === 'center' || align === 'left' ) {
710+ this . adaptor . setStyle ( chtml , 'margin-left' , this . em ( shift ) ) ;
711+ }
712+ if ( align === 'center' || align === 'right' ) {
713+ this . adaptor . setStyle ( chtml , 'margin-right' , this . em ( - shift ) ) ;
714+ }
715+ }
716+
662717 /*******************************************************************/
663718 /*
664719 * For debugging
0 commit comments