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

/**
 * Информация о страницах и колонтитулах.
 * Сегменты страниц
 */
public class UnitextPagesection extends UnitextItem {

    /**
     * Ширина страницы (в см)
     */
    public double width;

    /**
     * Высота страницы (в см)
     */
    public double height;

    /**
     * Левый отступ (в см)
     */
    public double left;

    /**
     * Верхний отступ (в см)
     */
    public double top;

    /**
     * Правый отступ (в см)
     */
    public double right;

    /**
     * Нижний отступ (в см)
     */
    public double bottom;

    /**
     * Высота верхнего колонтитула (в см)
     */
    public double headerHeight;

    /**
     * Высота нижнего колонтитула (в см)
     */
    public double footerHeight;

    /**
     * Верхние и нижние колонтитулы (могут относиться к разным страницам - см. их тип)
     */
    public java.util.ArrayList<UnitextPagesectionItem> items = new java.util.ArrayList<UnitextPagesectionItem>();

    @Override
    public UnitextItem clone() {
        UnitextPagesection res = new UnitextPagesection();
        res._cloneFrom(this);
        res.width = width;
        res.height = height;
        res.left = left;
        res.right = right;
        res.top = top;
        res.bottom = bottom;
        res.headerHeight = headerHeight;
        res.footerHeight = footerHeight;
        for (UnitextPagesectionItem it : items) {
            res.items.add((UnitextPagesectionItem)com.pullenti.unisharp.Utils.cast(it.clone(), UnitextPagesectionItem.class));
        }
        for (UnitextPagesectionItem it : res.items) {
            it.parent = res;
        }
        if (m_StyledFrag != null) 
            res.m_StyledFrag = m_StyledFrag.clone();
        return res;
    }

    @Override
    public String toString() {
        return ("Section " + id + ": " + com.pullenti.util.MiscHelper.outDouble(width) + "x" + com.pullenti.util.MiscHelper.outDouble(height));
    }

    @Override
    public void getXml(com.pullenti.unisharp.XmlWriterWrapper xml) throws javax.xml.stream.XMLStreamException {
        xml.wr.writeStartElement("section");
        this._writeXmlAttrs(xml);
        if (width > 0) 
            xml.wr.writeAttribute("width", com.pullenti.util.MiscHelper.outDouble(width));
        if (height > 0) 
            xml.wr.writeAttribute("height", com.pullenti.util.MiscHelper.outDouble(height));
        if (left > 0) 
            xml.wr.writeAttribute("left", com.pullenti.util.MiscHelper.outDouble(left));
        if (top > 0) 
            xml.wr.writeAttribute("top", com.pullenti.util.MiscHelper.outDouble(top));
        if (right > 0) 
            xml.wr.writeAttribute("right", com.pullenti.util.MiscHelper.outDouble(right));
        if (bottom > 0) 
            xml.wr.writeAttribute("bottom", com.pullenti.util.MiscHelper.outDouble(bottom));
        if (headerHeight > 0) 
            xml.wr.writeAttribute("header", com.pullenti.util.MiscHelper.outDouble(headerHeight));
        if (footerHeight > 0) 
            xml.wr.writeAttribute("footer", com.pullenti.util.MiscHelper.outDouble(footerHeight));
        for (UnitextPagesectionItem it : items) {
            it.getXml(xml);
        }
        xml.wr.writeEndElement();
    }

    private double _parseDouble(String str) {
        double d;
        com.pullenti.unisharp.Outargwrapper<Double> wrapd619 = new com.pullenti.unisharp.Outargwrapper<Double>();
        boolean inoutres620 = com.pullenti.util.MiscHelper.tryParseDouble(str, wrapd619);
        d = (wrapd619.value != null ? wrapd619.value : 0);
        if (inoutres620) 
            return d;
        return 0.0;
    }

    @Override
    public void fromXml(org.w3c.dom.Node xml) throws NumberFormatException {
        super.fromXml(xml);
        for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(xml.getAttributes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "width")) 
                width = this._parseDouble(a.getNodeValue());
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "height")) 
                height = this._parseDouble(a.getNodeValue());
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "left")) 
                left = this._parseDouble(a.getNodeValue());
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "top")) 
                top = this._parseDouble(a.getNodeValue());
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "right")) 
                right = this._parseDouble(a.getNodeValue());
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "bottom")) 
                bottom = this._parseDouble(a.getNodeValue());
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "header")) 
                headerHeight = this._parseDouble(a.getNodeValue());
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "footer")) 
                footerHeight = this._parseDouble(a.getNodeValue());
        }
        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), "item")) {
                UnitextPagesectionItem it = new UnitextPagesectionItem();
                it.parent = this;
                it.fromXml(x);
                items.add(it);
            }
        }
    }

    @Override
    public void getAllItems(java.util.ArrayList<UnitextItem> res, int lev) {
        if (res != null) 
            res.add(this);
        for (UnitextPagesectionItem it : items) {
            it.parent = this;
            it.getAllItems(res, lev + 1);
        }
    }
    public UnitextPagesection() {
        super();
    }
}
