/*
 * SDK Pullenti Unitext, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved. 
 * Non-Commercial Freeware and Commercial Software. 
 * This class is generated using the converter Unisharping (www.unisharping.ru) from Pullenti C# project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */

package com.pullenti.unitext.internal.uni;

/**
 * Это для поддержки генерации таблиц из модели COLSPAN + ROWSPAN
 */
public class UnitextGenTable {

    public java.util.ArrayList<java.util.ArrayList<UniTextGenCell>> cells = new java.util.ArrayList<java.util.ArrayList<UniTextGenCell>>();

    public java.util.ArrayList<String> m_ColWidth = new java.util.ArrayList<String>();

    public com.pullenti.unitext.UnitextTable convert() {
        com.pullenti.unitext.UnitextTable res = new com.pullenti.unitext.UnitextTable();
        res.mayHasError = mayHasError;
        for (int c = 0; c < m_ColWidth.size(); c++) {
            res.setColWidth(c, m_ColWidth.get(c));
        }
        for (int r = 0; r < cells.size(); r++) {
            int cn = 0;
            for (UniTextGenCell cc : cells.get(r)) {
                for (; ; cn++) {
                    if (res.getCell(r, cn) == null) 
                        break;
                }
                res.addCell(r, (r + cc.rowSpan) - 1, cn, (cn + cc.colSpan) - 1, cc.content, false);
                if (cc.width != null && cc.colSpan <= 1 && res.getColWidth(cn) == null) {
                    if (cc.width != null) 
                        res.setColWidth(cn, cc.width);
                    else if ((cc.content instanceof com.pullenti.unitext.UnitextTable) && ((com.pullenti.unitext.UnitextTable)com.pullenti.unisharp.Utils.cast(cc.content, com.pullenti.unitext.UnitextTable.class)).width != null) 
                        res.setColWidth(cn, ((com.pullenti.unitext.UnitextTable)com.pullenti.unisharp.Utils.cast(cc.content, com.pullenti.unitext.UnitextTable.class)).width);
                }
                cn += cc.colSpan;
            }
        }
        return res;
    }

    public boolean mayHasError;
    public UnitextGenTable() {
    }
}
