/*
 * 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.word;

public class DocTableCell {

    public int gridNum;

    public int colSpan = 1;

    public int rowSpan = 1;

    public int mergeVert = 0;

    public String text;

    public com.pullenti.unitext.UnitextItem uni;

    public com.pullenti.unitext.UnitextStyledFragment frag;

    @Override
    public String toString() {
        String txt = text;
        if (com.pullenti.unisharp.Utils.isNullOrEmpty(txt) && uni != null) 
            txt = uni.getPlaintextString(null);
        return ("N=" + gridNum + ", PS=" + colSpan + "x" + rowSpan + ", V=" + mergeVert + " : " + ((txt != null ? txt : "")));
    }

    public void read(DocxToText own, com.pullenti.unitext.UnitextStyledFragment sfrag, java.util.ArrayList<org.w3c.dom.Node> stackNodes) {
        org.w3c.dom.Node xml = stackNodes.get(stackNodes.size() - 1);
        if (sfrag != null) {
            frag = com.pullenti.unitext.UnitextStyledFragment._new449(com.pullenti.unitext.UnitextStyledFragmentType.TABLECELL, sfrag);
            sfrag.children.add(frag);
        }
        for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(xml.getChildNodes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "tcPr")) {
                if (frag != null) {
                    com.pullenti.unitext.UnitextStyle st0 = new com.pullenti.unitext.UnitextStyle();
                    own.m_Styles.readUnitextStyle(x, st0, false);
                    st0.removeInheritAttrs(frag);
                    frag.setStyle(own.m_Styles.registerStyle(st0));
                }
                for (org.w3c.dom.Node xx : (new com.pullenti.unisharp.XmlNodeListWrapper(x.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xx), "gridSpan") && xx.getAttributes() != null && xx.getAttributes().getLength() == 1) {
                        int cou;
                        com.pullenti.unisharp.Outargwrapper<Integer> wrapcou456 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                        boolean inoutres457 = com.pullenti.unisharp.Utils.parseInteger(xx.getAttributes().item(0).getTextContent(), 0, null, wrapcou456);
                        cou = (wrapcou456.value != null ? wrapcou456.value : 0);
                        if (inoutres457) {
                            if (cou > 1) 
                                colSpan = cou;
                        }
                    }
                    else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xx), "vMerge")) {
                        mergeVert = 1;
                        if (xx.getAttributes().getLength() > 0 && xx.getAttributes() != null && com.pullenti.unisharp.Utils.stringsEq(xx.getAttributes().item(0).getNodeValue(), "restart")) 
                            mergeVert = 2;
                    }
                }
            }
        }
        com.pullenti.unitext.internal.uni.UnitextGen gen = new com.pullenti.unitext.internal.uni.UnitextGen();
        gen.setStyle(frag);
        stackNodes.add(xml);
        own.readNode(stackNodes, gen, frag, -1);
        stackNodes.remove(stackNodes.size() - 1);
        uni = gen.finish(true, null);
    }
    public DocTableCell() {
    }
}
