7.4 Fill Rows

<..fill rows..>
 if (node.hasChildNodes()) {
    mtr = node.getFirstChild();
    while( mtr != null){
       if( mtr.getNodeType() == Node.ELEMENT_NODE ){
          int count = 0;
          if (mtr.hasChildNodes()) {
            mtd = mtr.getFirstChild();
            while( mtd != null){
              if( mtd.getNodeType() == Node.ELEMENT_NODE ){
                 <.insert new line text node.>
                 count++;
              }
              mtd = mtd.getNextSibling();
            }
          }
          if( count < cols ){
             <.fill with empty mtd nodes.>
       }  }
       mtr = mtr.getNextSibling();
 }  }
-_-_-

<..fill with empty mtd nodes..>
 for(int i = count; i < cols; i++){
   mtr.appendChild( ((Document) dom).createElement("math:mtd") );
 }
-_-_-

<..insert new line text node..>
 mtr.insertBefore( ((Document) dom).createTextNode("\n"), mtd );
-_-_-