/*
 * 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 DocTextStyles {

    public java.util.HashMap<String, DocTextStyle> m_TextStyles = new java.util.HashMap<String, DocTextStyle>();

    public com.pullenti.unitext.UnitextStyle defStyle;

    public java.util.HashMap<String, com.pullenti.unitext.UnitextStyle> defStyles = new java.util.HashMap<String, com.pullenti.unitext.UnitextStyle>();

    public java.util.ArrayList<com.pullenti.unitext.UnitextStyle> uStyles = new java.util.ArrayList<com.pullenti.unitext.UnitextStyle>();

    private java.util.HashMap<String, com.pullenti.unitext.UnitextStyle> m_UStyles = new java.util.HashMap<String, com.pullenti.unitext.UnitextStyle>();

    public boolean ignore;

    public com.pullenti.unitext.UnitextStyle registerStyle(com.pullenti.unitext.UnitextStyle st) {
        if (ignore) 
            return st;
        String key = st.toString();
        if (com.pullenti.unisharp.Utils.isNullOrEmpty(key)) 
            return null;
        com.pullenti.unitext.UnitextStyle res;
        com.pullenti.unisharp.Outargwrapper<com.pullenti.unitext.UnitextStyle> wrapres472 = new com.pullenti.unisharp.Outargwrapper<com.pullenti.unitext.UnitextStyle>();
        boolean inoutres473 = com.pullenti.unisharp.Utils.tryGetValue(m_UStyles, key, wrapres472);
        res = wrapres472.value;
        if (inoutres473) 
            return res;
        m_UStyles.put(key, st);
        st.id = uStyles.size();
        uStyles.add(st);
        return st;
    }

    public DocTextStyle getStyle(org.w3c.dom.Node x, String nam) {
        String id = _readAttrVal(x, nam, null);
        if (id == null) 
            return null;
        DocTextStyle res;
        com.pullenti.unisharp.Outargwrapper<DocTextStyle> wrapres474 = new com.pullenti.unisharp.Outargwrapper<DocTextStyle>();
        boolean inoutres475 = com.pullenti.unisharp.Utils.tryGetValue(m_TextStyles, id, wrapres474);
        res = wrapres474.value;
        if (!inoutres475) 
            return null;
        return res;
    }

    public DocTextStyle getStyleById(String id) {
        DocTextStyle res;
        com.pullenti.unisharp.Outargwrapper<DocTextStyle> wrapres476 = new com.pullenti.unisharp.Outargwrapper<DocTextStyle>();
        boolean inoutres477 = com.pullenti.unisharp.Utils.tryGetValue(m_TextStyles, id, wrapres476);
        res = wrapres476.value;
        if (!inoutres477) 
            return null;
        return res;
    }

    private String m_MajorFont;

    private String m_MinorFont;

    private static String _readAttrVal(org.w3c.dom.Node x, String nam, String nam2) {
        if (x.getAttributes() != null) {
            for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(x.getAttributes())).arr) {
                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), nam)) 
                    return a.getNodeValue();
                else if (nam2 != null && com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), nam2)) 
                    return a.getNodeValue();
            }
        }
        return null;
    }

    private static String _getSizeVal(String val, boolean outCm) {
        if (val == null) 
            return null;
        for (char ch : val.toCharArray()) {
            if (Character.isLetter(ch)) 
                return val;
        }
        double d;
        com.pullenti.unisharp.Outargwrapper<Double> wrapd478 = new com.pullenti.unisharp.Outargwrapper<Double>();
        boolean inoutres479 = com.pullenti.util.MiscHelper.tryParseDouble(val, wrapd478);
        d = (wrapd478.value != null ? wrapd478.value : 0);
        if (!inoutres479) 
            return val;
        if (outCm) {
            d = com.pullenti.unisharp.Utils.mathRound(d / (((20.0) * 28.35)), 2);
            return (com.pullenti.util.MiscHelper.outDouble(d) + "cm");
        }
        d = com.pullenti.unisharp.Utils.mathRound(d / (20.0), 2);
        return (com.pullenti.util.MiscHelper.outDouble(d) + "pt");
    }

    private static String _corrColor(String val) {
        if (val == null) 
            return null;
        if (val.length() != 6) 
            return val;
        for (char ch : val.toCharArray()) {
            if (Character.isDigit(ch)) {
            }
            else if (ch >= 'A' && ch <= 'F') {
            }
            else if (ch >= 'a' && ch <= 'f') {
            }
            else 
                return val;
        }
        return val = "#" + val.toUpperCase();
    }

    public void readUnitextStyle(org.w3c.dom.Node node, com.pullenti.unitext.UnitextStyle st, boolean ignoreFontName) {
        for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(node.getChildNodes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "pStyle") || com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "rStyle")) {
                String id = _readAttrVal(x, "val", null);
                if (m_TextStyles.containsKey(id)) 
                    m_TextStyles.get(id).uStyle.copyTo(st);
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "rFonts") && !ignoreFontName) {
                String nam = _readAttrVal(x, "cs", "ansii");
                if (nam == null) 
                    nam = _readAttrVal(x, "ascii", "hAnsii");
                if (nam == null) 
                    nam = st.getAttr("font-name");
                boolean isBidi = false;
                if (nam == null) {
                    for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(x.getAttributes())).arr) {
                        if (com.pullenti.unisharp.Utils.endsWithString(com.pullenti.unisharp.Utils.getXmlLocalName(a), "cstheme", true) && com.pullenti.unisharp.Utils.endsWithString(a.getNodeValue(), "bidi", true)) 
                            isBidi = true;
                    }
                    for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(x.getAttributes())).arr) {
                        if (com.pullenti.unisharp.Utils.endsWithString(com.pullenti.unisharp.Utils.getXmlLocalName(a), "theme", true) && !com.pullenti.unisharp.Utils.endsWithString(com.pullenti.unisharp.Utils.getXmlLocalName(a), "asiatheme", true)) {
                            if (isBidi) 
                                break;
                            if (com.pullenti.unisharp.Utils.startsWithString(a.getNodeValue(), "major", true)) 
                                nam = m_MajorFont;
                            else if (com.pullenti.unisharp.Utils.startsWithString(a.getNodeValue(), "minor", true)) 
                                nam = m_MinorFont;
                        }
                    }
                }
                if (nam == null) {
                    for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(x.getAttributes())).arr) {
                        if (!com.pullenti.unisharp.Utils.endsWithString(com.pullenti.unisharp.Utils.getXmlLocalName(a), "theme", true) && !com.pullenti.unisharp.Utils.endsWithString(com.pullenti.unisharp.Utils.getXmlLocalName(a), "asia", true)) {
                            nam = a.getNodeValue();
                            break;
                        }
                    }
                }
                if (!com.pullenti.unisharp.Utils.isNullOrEmpty(nam)) 
                    st.addAttr("font-name", nam, false);
            }
        }
        readUnitextStyleExt(node, st, true, false);
    }

    public static void readUnitextStyleExt(org.w3c.dom.Node node, com.pullenti.unitext.UnitextStyle st, boolean ignoreFontName, boolean numRegime) {
        for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(node.getChildNodes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "b") && !numRegime) {
                String val = _readAttrVal(x, "val", null);
                if (com.pullenti.unisharp.Utils.stringsEq(val, "0")) 
                    val = "normal";
                else 
                    val = "bold";
                st.addAttr("font-weight", val, false);
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "i") && !numRegime) {
                String val = _readAttrVal(x, "val", null);
                if (com.pullenti.unisharp.Utils.stringsEq(val, "0")) 
                    st.addAttr("font-style", "none", false);
                else 
                    st.addAttr("font-style", "italic", false);
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "u") && !numRegime) {
                String val = _readAttrVal(x, "val", null);
                if (com.pullenti.unisharp.Utils.stringsEq(val, "none")) 
                    st.addAttr("text-decoration", "none", false);
                else 
                    st.addAttr("text-decoration", "underline", false);
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "strike") && !numRegime) {
                String val = _readAttrVal(x, "val", null);
                if (com.pullenti.unisharp.Utils.stringsNe(val, "0")) 
                    st.addAttr("text-decoration", "line-through", false);
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "caps") && !numRegime) 
                st.addAttr("upper-case", "true", false);
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "rFonts") && !ignoreFontName) {
                String nam = _readAttrVal(x, "cs", "ansii");
                if (nam == null) 
                    nam = _readAttrVal(x, "ascii", "hAnsii");
                if (nam == null) 
                    nam = st.getAttr("font-name");
                if (!com.pullenti.unisharp.Utils.isNullOrEmpty(nam)) 
                    st.addAttr("font-name", nam, false);
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "sz") && !numRegime) {
                double d;
                com.pullenti.unisharp.Outargwrapper<Double> wrapd480 = new com.pullenti.unisharp.Outargwrapper<Double>();
                boolean inoutres481 = com.pullenti.util.MiscHelper.tryParseDouble(_readAttrVal(x, "val", null), wrapd480);
                d = (wrapd480.value != null ? wrapd480.value : 0);
                if (inoutres481) 
                    st.addAttr("font-size", (com.pullenti.util.MiscHelper.outDouble(d / (2.0)) + "pt"), false);
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "highlight") || com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "color")) {
                String val = _corrColor(_readAttrVal(x, "val", null));
                if (val == null || com.pullenti.unisharp.Utils.stringsEq(val, "auto")) 
                    continue;
                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "color")) 
                    st.addAttr("color", val, false);
                else 
                    st.addAttr("background-color", val, false);
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "shd")) {
                String val = _readAttrVal(x, "color", null);
                if (com.pullenti.unisharp.Utils.stringsEq(val, "auto") || com.pullenti.unisharp.Utils.stringsEq(_readAttrVal(x, "val", null), "clear")) 
                    val = _corrColor(_readAttrVal(x, "fill", null));
                else 
                    val = _corrColor(val);
                if (val != null && com.pullenti.unisharp.Utils.stringsNe(val, "auto")) 
                    st.addAttr("background-color", val, false);
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "rPr")) {
                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(node), "pPr")) {
                }
                else 
                    readUnitextStyleExt(x, st, ignoreFontName, numRegime);
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "jc") && !numRegime) {
                String val = _readAttrVal(x, "val", null);
                if (com.pullenti.unisharp.Utils.stringsEq(val, "start")) 
                    val = "left";
                else if (com.pullenti.unisharp.Utils.stringsEq(val, "end")) 
                    val = "right";
                else if (com.pullenti.unisharp.Utils.stringsEq(val, "both")) 
                    val = "justify";
                st.addAttr("text-align", val, false);
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "vAlign") && !numRegime) {
                String val = _readAttrVal(x, "val", null);
                st.addAttr("vertical-align", val, false);
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "spacing") && !numRegime) {
                String tempVal = _readAttrVal(x, "val", null);
                if (tempVal != null) 
                    st.addAttr("letter-spacing", _getSizeVal(tempVal, false), false);
                double d;
                String rule = _readAttrVal(x, "lineRule", null);
                for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(x.getAttributes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "before") || com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "top")) 
                        st.addAttr("margin-top", _getSizeVal(a.getNodeValue(), false), false);
                    else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "after") || com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "bottom")) 
                        st.addAttr("margin-bottom", _getSizeVal(a.getNodeValue(), false), false);
                    else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "line")) {
                        com.pullenti.unisharp.Outargwrapper<Double> wrapd482 = new com.pullenti.unisharp.Outargwrapper<Double>();
                        boolean inoutres483 = com.pullenti.util.MiscHelper.tryParseDouble(a.getNodeValue(), wrapd482);
                        d = (wrapd482.value != null ? wrapd482.value : 0);
                        if (inoutres483) {
                            String val = null;
                            if (com.pullenti.unisharp.Utils.stringsEq(rule, "auto")) {
                                d = com.pullenti.unisharp.Utils.mathRound(d / (240.0), 2);
                                val = (com.pullenti.util.MiscHelper.outDouble(d));
                            }
                            else if (com.pullenti.unisharp.Utils.stringsEq(rule, "exact")) {
                                d = com.pullenti.unisharp.Utils.mathRound(d / (20.0), 2);
                                val = (com.pullenti.util.MiscHelper.outDouble(d) + "pt");
                                Double pt = com.pullenti.util.SizeunitConverter.convert(st.getAttr("font-size"), "pt");
                                if (pt != null && pt > 0) 
                                    val = com.pullenti.util.MiscHelper.outDouble(com.pullenti.unisharp.Utils.mathRound(d / pt, 2));
                            }
                            else {
                            }
                            if (val != null) 
                                st.addAttr("line-height", val, false);
                        }
                    }
                }
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "tcW")) {
                String val = _readAttrVal(x, "w", null);
                if (val != null) 
                    st.addAttr("width", _getSizeVal(val, false), false);
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "ind")) {
                for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(x.getAttributes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "left") || com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "start")) 
                        st.addAttr("margin-left", _getSizeVal(a.getNodeValue(), true), false);
                    else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "right") || com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "end")) 
                        st.addAttr("margin-right", _getSizeVal(a.getNodeValue(), true), false);
                    else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "firstLine")) 
                        st.addAttr("text-indent", _getSizeVal(a.getNodeValue(), true), false);
                    else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "hanging")) 
                        st.addAttr("text-indent", "-" + _getSizeVal(a.getNodeValue(), true), false);
                }
            }
        }
    }

    public void readTheme(org.w3c.dom.Node node) {
        for (org.w3c.dom.Node x1 : (new com.pullenti.unisharp.XmlNodeListWrapper(node.getChildNodes())).arr) {
            for (org.w3c.dom.Node x2 : (new com.pullenti.unisharp.XmlNodeListWrapper(x1.getChildNodes())).arr) {
                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x2), "fontScheme")) {
                    for (org.w3c.dom.Node x3 : (new com.pullenti.unisharp.XmlNodeListWrapper(x2.getChildNodes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x3), "majorFont") || com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x3), "minorFont")) {
                            for (org.w3c.dom.Node x4 : (new com.pullenti.unisharp.XmlNodeListWrapper(x3.getChildNodes())).arr) {
                                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x4), "latin")) {
                                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x3), "majorFont")) 
                                        m_MajorFont = _readAttrVal(x4, "typeface", null);
                                    else 
                                        m_MinorFont = _readAttrVal(x4, "typeface", null);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    public void readAllStyles(org.w3c.dom.Node node, DocNumStyles nums) throws NumberFormatException {
        for (org.w3c.dom.Node xnum : (new com.pullenti.unisharp.XmlNodeListWrapper(node.getChildNodes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xnum), "style")) {
                boolean isNormal = false;
                for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(xnum.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "name")) {
                        for (org.w3c.dom.Node xAttr : (new com.pullenti.unisharp.XmlAttrListWrapper(x.getAttributes())).arr) {
                            if (com.pullenti.unisharp.Utils.stringsEq(xAttr.getNodeValue(), "Normal")) 
                                isNormal = true;
                            break;
                        }
                    }
                }
                if (!isNormal) 
                    continue;
                for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(xnum.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "rPr")) {
                        defStyle = new com.pullenti.unitext.UnitextStyle();
                        this.readUnitextStyle(x, defStyle, false);
                    }
                }
                if (isNormal) 
                    break;
            }
        }
        if (defStyle != null) {
            if (!defStyle.attrs.containsKey("font-name")) {
                for (org.w3c.dom.Node xnum : (new com.pullenti.unisharp.XmlNodeListWrapper(node.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xnum), "docDefaults")) {
                        for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(xnum.getChildNodes())).arr) {
                            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "rPrDefault")) {
                                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), "rPr")) 
                                        this.readUnitextStyle(xx, defStyle, false);
                                }
                            }
                        }
                    }
                }
            }
        }
        if (defStyle == null) {
            for (org.w3c.dom.Node xnum : (new com.pullenti.unisharp.XmlNodeListWrapper(node.getChildNodes())).arr) {
                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xnum), "docDefaults")) {
                    for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(xnum.getChildNodes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "rPrDefault")) {
                            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), "rPr")) {
                                    defStyle = new com.pullenti.unitext.UnitextStyle();
                                    this.readUnitextStyle(xx, defStyle, false);
                                }
                            }
                        }
                    }
                }
            }
        }
        for (org.w3c.dom.Node xnum : (new com.pullenti.unisharp.XmlNodeListWrapper(node.getChildNodes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xnum), "style") && xnum.getAttributes() != null && xnum.getAttributes().getLength() >= 1) {
                String id = _readAttrVal(xnum, "styleId", null);
                if (id == null || m_TextStyles.containsKey(id)) 
                    continue;
                DocTextStyle sty = new DocTextStyle();
                sty.xml = xnum;
                String typ = _readAttrVal(xnum, "type", null);
                if (defStyle != null) 
                    defStyle.copyTo(sty.uStyle);
                if (typ != null && defStyles.containsKey(typ)) 
                    defStyles.get(typ).copyTo(sty.uStyle);
                m_TextStyles.put(id, sty);
                for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(xnum.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "name")) {
                        if (x.getAttributes() != null && x.getAttributes().getLength() > 0) 
                            sty.name = x.getAttributes().item(0).getNodeValue();
                        if (sty.name != null && com.pullenti.unisharp.Utils.stringsEq(sty.name, "Body Text Indent")) {
                        }
                    }
                    else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "aliases")) {
                        if (x.getAttributes() != null && x.getAttributes().getLength() > 0) 
                            sty.aliases = x.getAttributes().item(0).getNodeValue();
                    }
                    else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "basedOn")) 
                        sty.basedOn = _readAttrVal(x, "val", null);
                }
            }
        }
        for (java.util.Map.Entry<String, DocTextStyle> kp : m_TextStyles.entrySet()) {
            DocTextStyle sty = kp.getValue();
            if (sty.loaded) 
                continue;
            if (com.pullenti.unisharp.Utils.stringsEq(kp.getKey(), "XX")) {
            }
            if (sty.basedOn != null && m_TextStyles.containsKey(sty.basedOn)) {
                DocTextStyle sty0 = m_TextStyles.get(sty.basedOn);
                if (!sty0.loaded) {
                    if (sty0.basedOn != null && m_TextStyles.containsKey(sty0.basedOn)) {
                        DocTextStyle sty00 = m_TextStyles.get(sty0.basedOn);
                        if (!sty00.loaded) 
                            this._readSingleStyle(sty00);
                        sty0.numId = sty00.numId;
                        sty0.numLvl = sty00.numLvl;
                        sty00.uStyle.copyTo(sty0.uStyle);
                    }
                    this._readSingleStyle(sty0);
                }
                sty.numId = sty0.numId;
                sty.numLvl = sty0.numLvl;
                sty0.uStyle.copyTo(sty.uStyle);
            }
            this._readSingleStyle(sty);
            if (sty.numId != null && nums != null) {
                com.pullenti.unitext.internal.uni.UnitextGenNumStyleEx num = nums.getStyle(sty.numId);
                if (num != null) {
                    com.pullenti.unitext.internal.uni.UniTextGenNumLevel lvl = num.getLevel(sty.numLvl);
                    if (lvl != null && lvl.style != null) {
                        for (java.util.Map.Entry<String, String> a : lvl.style.attrs.entrySet()) {
                            if (!sty.uStyle.attrs.containsKey(a.getKey())) 
                                sty.uStyle.attrs.put(a.getKey(), a.getValue());
                        }
                    }
                }
            }
        }
    }

    private void _readSingleStyle(DocTextStyle sty) throws NumberFormatException {
        String typ = _readAttrVal(sty.xml, "type", null);
        for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(sty.xml.getChildNodes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "rPr")) {
                this.readUnitextStyle(x, sty.uStyle, sty.isHeading());
                if (com.pullenti.unisharp.Utils.stringsEq(_readAttrVal(sty.xml, "default", null), "1")) {
                    if (!defStyles.containsKey(typ)) 
                        defStyles.put(typ, sty.uStyle);
                }
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "pPr")) {
                this.readUnitextStyle(x, sty.uStyle, false);
                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), "numPr")) {
                        for (org.w3c.dom.Node xxx : (new com.pullenti.unisharp.XmlNodeListWrapper(xx.getChildNodes())).arr) {
                            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "numId") && xxx.getAttributes() != null) {
                                for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(xxx.getAttributes())).arr) {
                                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "val")) 
                                        sty.numId = a.getNodeValue();
                                }
                            }
                            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "ilvl") && xxx.getAttributes() != null) {
                                for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(xxx.getAttributes())).arr) {
                                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "val")) {
                                        int ll;
                                        com.pullenti.unisharp.Outargwrapper<Integer> wrapll484 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                                        boolean inoutres485 = com.pullenti.unisharp.Utils.parseInteger(a.getNodeValue(), 0, null, wrapll484);
                                        ll = (wrapll484.value != null ? wrapll484.value : 0);
                                        if (inoutres485) 
                                            sty.numLvl = ll;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (sty.isHeading()) 
            sty.uStyle.addAttr("heading-level", ((Integer)sty.calcHeadingLevel()).toString(), false);
        sty.loaded = true;
    }

    public void readAllExcelStyles(org.w3c.dom.Node node) {
        java.util.ArrayList<com.pullenti.unitext.internal.misc.BorderInfo> brdr = new java.util.ArrayList<com.pullenti.unitext.internal.misc.BorderInfo>();
        java.util.HashMap<String, String> specFrms = new java.util.HashMap<String, String>();
        for (org.w3c.dom.Node xx : (new com.pullenti.unisharp.XmlNodeListWrapper(node.getChildNodes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xx), "borders")) {
                for (org.w3c.dom.Node xxx : (new com.pullenti.unisharp.XmlNodeListWrapper(xx.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "border")) {
                        com.pullenti.unitext.internal.misc.BorderInfo brd = new com.pullenti.unitext.internal.misc.BorderInfo();
                        brdr.add(brd);
                        for (org.w3c.dom.Node y : (new com.pullenti.unisharp.XmlNodeListWrapper(xxx.getChildNodes())).arr) {
                            if (y.getAttributes() != null && ((y.getAttributes().getLength() > 0 || y.getChildNodes().getLength() > 0))) {
                                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(y), "left")) 
                                    brd.left = true;
                                else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(y), "right")) 
                                    brd.right = true;
                                else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(y), "top")) 
                                    brd.top = true;
                                else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(y), "bottom")) 
                                    brd.bottom = true;
                            }
                        }
                    }
                }
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xx), "numFmts")) {
                for (org.w3c.dom.Node xxx : (new com.pullenti.unisharp.XmlNodeListWrapper(xx.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "numFmt")) {
                        String cod = null;
                        String frm = null;
                        for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(xxx.getAttributes())).arr) {
                            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "numFmtId")) 
                                cod = a.getNodeValue();
                            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "formatCode")) 
                                frm = a.getNodeValue();
                        }
                        if (cod != null && frm != null && !specFrms.containsKey(cod)) 
                            specFrms.put(cod, frm);
                    }
                }
            }
        }
        for (org.w3c.dom.Node x1 : (new com.pullenti.unisharp.XmlNodeListWrapper(node.getChildNodes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x1), "cellXfs")) {
                int id = 0;
                for (org.w3c.dom.Node xx : (new com.pullenti.unisharp.XmlNodeListWrapper(x1.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xx), "xf")) {
                        DocTextStyle st = new DocTextStyle();
                        st.name = ((Integer)id).toString();
                        id++;
                        m_TextStyles.put(st.name, st);
                        for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(xx.getAttributes())).arr) {
                            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "numFmtId")) {
                                st.xlsFormat = a.getNodeValue();
                                if (specFrms.containsKey(a.getNodeValue())) 
                                    st.xlsFormat = specFrms.get(a.getNodeValue());
                            }
                            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "borderId")) {
                                int n;
                                com.pullenti.unisharp.Outargwrapper<Integer> wrapn486 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                                boolean inoutres487 = com.pullenti.unisharp.Utils.parseInteger(a.getNodeValue(), 0, null, wrapn486);
                                n = (wrapn486.value != null ? wrapn486.value : 0);
                                if (inoutres487) {
                                    if (n >= 0 && (n < brdr.size())) 
                                        st.xlsBorder = brdr.get(n);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    public DocTextStyles() {
    }
}
