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

// Word document model.
// See specification for explanations.
// [MS-DOC]: Word Binary File Format (.doc) Structure Specification
// Release: Thursday, August 27, 2009
public class WordDocument {

    public StringBuilder text = new StringBuilder();

    private FileCharacterPosition[] fileCharacterPositions;

    private java.util.ArrayList<Paragraph> m_Paragraphs = new java.util.ArrayList<Paragraph>();

    private CharacterFormatting[] m_Formattings;

    private java.util.HashMap<Short, StyleDefinition> m_StyleDefinitionsMap;

    private Prl[] defaultPrls;

    private java.util.HashMap<Integer, com.pullenti.unitext.internal.uni.UnitextGenNumStyle> m_NumStyles = new java.util.HashMap<Integer, com.pullenti.unitext.internal.uni.UnitextGenNumStyle>();

    public String comment;

    private boolean m_Error = false;

    public Iterable<Paragraph> getParagraphs() {
        return m_Paragraphs;
    }


    public Iterable<CharacterFormatting> getFormattings() {
        return java.util.Arrays.asList(m_Formattings);
    }


    public Iterable<StyleDefinition> getStyleDefinitions() {
        return m_StyleDefinitionsMap.values();
    }


    public java.util.Map<Short, StyleDefinition> getStyleDefinitionsMap() {
        return m_StyleDefinitionsMap;
    }


    public void load(CompoundFileSystem system, com.pullenti.unitext.UnitextDocument doc) throws Exception, java.io.IOException, IllegalArgumentException, UnsupportedOperationException {
        String wordDocumentStreamName = "WordDocument";
        CompoundFileStorage str = system.getRootStorage();
        CompoundFileStorage wordDocumentStorage = str.findStorage(ExtendedName.fromString(wordDocumentStreamName));
        try (com.pullenti.unisharp.Stream wordDocumentStream = wordDocumentStorage.createStream()) {
            Fib fib;
            fib = FibStructuresReader.readFib(wordDocumentStream);
            if (fib != null) {
                String tableStreamName = getTableStreamName(fib);
                CompoundFileStorage tableStorage = system.getRootStorage().findStorage(ExtendedName.fromString(tableStreamName));
                if (tableStorage != null) {
                    try (com.pullenti.unisharp.Stream tableStream = tableStorage.createStream()) {
                        this.loadContent(wordDocumentStream, tableStream, fib, doc);
                    }
                }
            }
            else {
                wordDocumentStream.setPosition(0L);
                byte[] buf = new byte[(int)wordDocumentStream.length()];
                int i = wordDocumentStream.read(buf, 0, buf.length);
                if (i < 0x20) 
                    return;
                com.pullenti.unitext.UnitextDocument ddd = MSOfficeHelper._uniFromWord6orEarly(buf);
                if (ddd != null) 
                    doc.content = ddd.content;
            }
        }
    }

    private static String getTableStreamName(Fib fib) {
        return (fib.get_base().getfWhichTblStm() ? "1Table" : "0Table");
    }

    private java.util.HashMap<Integer, com.pullenti.unitext.UnitextFootnote> m_Footnotes = new java.util.HashMap<Integer, com.pullenti.unitext.UnitextFootnote>();

    private java.util.HashMap<Integer, com.pullenti.unitext.UnitextComment> m_Comments = new java.util.HashMap<Integer, com.pullenti.unitext.UnitextComment>();

    private java.util.HashMap<Integer, String> m_SuperTexts = new java.util.HashMap<Integer, String>();

    private java.util.HashMap<Integer, String> m_SubTexts = new java.util.HashMap<Integer, String>();

    private java.util.HashMap<Integer, com.pullenti.unitext.UnitextContainer> m_Shapes = new java.util.HashMap<Integer, com.pullenti.unitext.UnitextContainer>();

    private byte[] m_Dels;

    private void loadContent(com.pullenti.unisharp.Stream wordDocumentStream, com.pullenti.unisharp.Stream tableStream, Fib fib, com.pullenti.unitext.UnitextDocument doc) throws java.io.IOException, Exception {
        FibRgLw97 fib97 = (FibRgLw97)com.pullenti.unisharp.Utils.cast(fib.getfibRgLw(), FibRgLw97.class);
        if (fib97 == null) 
            return;
        FibRbFcLcb97 fibLc97 = (FibRbFcLcb97)com.pullenti.unisharp.Utils.cast(fib.getfibRgFcLcbBlob(), FibRbFcLcb97.class);
        if (fibLc97 == null) 
            return;
        int pos = (int)fibLc97.getfcClx();
        tableStream.setPosition((long)pos);
        int iii = (int)fibLc97.getlcbClx();
        Clx clx = BasicTypesReader.readClx(tableStream, iii);
        this.loadCharacters(wordDocumentStream, clx);
        try {
            int plcfBtePapxOffset = ((FibRbFcLcb97)fib.getfibRgFcLcbBlob()).getfcPlcfBtePapx();
            tableStream.setPosition(Integer.toUnsignedLong(plcfBtePapxOffset));
            int plcfBtePapxLength = ((FibRbFcLcb97)fib.getfibRgFcLcbBlob()).getlcbPlcfBtePapx();
            PlcBtePapx plcfBtePapx = BasicTypesReader.readPlcfBtePapx(tableStream, plcfBtePapxLength);
            this.loadParagraphs(wordDocumentStream, clx, plcfBtePapx);
            int plcfBteChpxOffset = ((FibRbFcLcb97)fib.getfibRgFcLcbBlob()).getfcPlcfBteChpx();
            tableStream.setPosition(Integer.toUnsignedLong(plcfBteChpxOffset));
            int plcfBteChpxLength = ((FibRbFcLcb97)fib.getfibRgFcLcbBlob()).getlcbPlcfBteChpx();
            PlcBteChpx plcBteChpx = BasicTypesReader.readPlcBteChpx(tableStream, plcfBteChpxLength);
            this.loadCharacterFormatting(wordDocumentStream, plcBteChpx);
            int stshOffset = ((FibRbFcLcb97)fib.getfibRgFcLcbBlob()).getfcStshf();
            tableStream.setPosition(Integer.toUnsignedLong(stshOffset));
            int stshLength = ((FibRbFcLcb97)fib.getfibRgFcLcbBlob()).getlcbStshf();
            STSH stsh = BasicTypesReader.readStsh(tableStream, stshLength);
            this.loadStsh(wordDocumentStream, stsh);
            tableStream.setPosition(Integer.toUnsignedLong(fibLc97.getfcPlfLfo()));
            this.loadLFOS(tableStream, (int)fibLc97.getlcbPlfLfo());
            tableStream.setPosition(Integer.toUnsignedLong(fibLc97.getfcPlfLst()));
            this.loadLSTFs(tableStream, (int)fibLc97.getlcbPlfLst());
        } catch (Exception ex) {
        }
        if (doc != null) {
            m_Dels = new byte[text.length()];
            if (m_Formattings != null) {
                for (CharacterFormatting f : m_Formattings) {
                    if (f.getLength() == 1) {
                        byte[] dat = f.getProperty(SinglePropertyModifiers.sprmCSymbol);
                        if (dat != null && dat.length == 4) {
                            int nnn = Byte.toUnsignedInt(dat[3]);
                            nnn <<= ((int)8);
                            nnn |= (Byte.toUnsignedInt(dat[2]));
                            if (Integer.compareUnsigned(nnn, (int)0xF000) > 0) 
                                nnn -= ((int)0xF000);
                            if (f.getPos() >= 0 && (f.getPos() < text.length())) {
                                char ch0 = text.charAt(f.getPos());
                                text.setCharAt(f.getPos(), com.pullenti.unitext.internal.misc.WingdingsHelper.getUnicode((int)nnn));
                                if (text.charAt(f.getPos()) == ((char)0)) 
                                    text.setCharAt(f.getPos(), (char)nnn);
                            }
                        }
                    }
                    StyleCollection sty = f.getStyles(FormattingLevel.CHARACTER);
                    if (sty != null) {
                        if ((sty.toString().indexOf("CFRMarkDel") >= 0)) {
                            for (int ii = f.getPos(); ii < (f.getPos() + f.getLength()); ii++) {
                                m_Dels[ii] = (byte)1;
                            }
                        }
                    }
                }
            }
            String totalText = text.toString();
            com.pullenti.unitext.internal.uni.UnitextGen gen = new com.pullenti.unitext.internal.uni.UnitextGen();
            if (m_Paragraphs == null || m_Paragraphs.size() == 0) {
                gen.appendText(totalText, false);
                doc.content = gen.finish(true, null);
                return;
            }
            if (m_Formattings != null) {
                for (int i = 0; i < m_Formattings.length; i++) {
                    CharacterFormatting f = m_Formattings[i];
                    byte[] dat = f.getProperty(SinglePropertyModifiers.sprmCIss);
                    if (f.getPos() > (84223 - 10) && (f.getPos() < (84223 + 10))) {
                    }
                    if ((dat != null && dat.length == 1 && dat[0] == ((byte)1)) && (f.getLength() < 10)) {
                        String tmp = totalText.substring(f.getPos(), f.getPos() + f.getLength());
                        if (!m_SuperTexts.containsKey(f.getPos())) 
                            m_SuperTexts.put(f.getPos(), tmp);
                    }
                    if ((dat != null && dat.length == 1 && dat[0] == ((byte)2)) && (f.getLength() < 10)) {
                        String tmp = totalText.substring(f.getPos(), f.getPos() + f.getLength());
                        if (!m_SubTexts.containsKey(f.getPos())) 
                            m_SubTexts.put(f.getPos(), tmp);
                    }
                }
            }
            for (int k = 0; k < 2; k++) {
                tableStream.setPosition(Integer.toUnsignedLong((k == 0 ? fibLc97.getfcPlcffndRef() : fibLc97.getfcPlcfendRef())));
                java.util.ArrayList<Integer> cps = BasicTypesReader.readCPs(tableStream, (int)((k == 0 ? fibLc97.getlcbPlcffndRef() : fibLc97.getlcbPlcfendRef())));
                tableStream.setPosition(Integer.toUnsignedLong((k == 0 ? fibLc97.getfcPlcffndTxt() : fibLc97.getfcPlcfendTxt())));
                java.util.ArrayList<Integer> cps2 = BasicTypesReader.readCPs(tableStream, (int)((k == 0 ? fibLc97.getlcbPlcffndTxt() : fibLc97.getlcbPlcfendTxt())));
                if (cps.size() > 2 && gen != null) {
                    int pos0 = (int)fib97.getccpText();
                    int len = (int)fib97.getccpFtn();
                    if (k == 1) {
                        pos0 += ((((int)fib97.getccpFtn()) + ((int)fib97.getccpHdd()) + ((int)fib97.getccpAtn())));
                        len = (int)fib97.getccpEdn();
                    }
                    String ttt = totalText.substring(pos0, pos0 + len);
                    for (int i = 0; (i < (cps.size() - 2)) && (i < cps2.size()); i++) {
                        int cp = cps.get(i);
                        if ((cp < 0) || cp >= pos0) 
                            continue;
                        com.pullenti.unitext.internal.uni.UnitextGen ge = new com.pullenti.unitext.internal.uni.UnitextGen();
                        int max = ((i + 1) < (cps2.size() - 2) ? cps2.get(i + 1) : len);
                        this._createUni(ge, null, 0, pos0 + cps2.get(i), pos0 + max, totalText, 0);
                        if (!m_Footnotes.containsKey(cp)) {
                            com.pullenti.unitext.UnitextFootnote fn = com.pullenti.unitext.UnitextFootnote._new514(k == 1, ge.finish(true, null));
                            m_Footnotes.put(cp, fn);
                        }
                    }
                }
            }
            tableStream.setPosition(Integer.toUnsignedLong(fibLc97.getfcPlcfandTxt()));
            java.util.ArrayList<Integer> cpsat2 = BasicTypesReader.readCPs(tableStream, (int)fibLc97.getlcbPlcfandTxt());
            tableStream.setPosition(Integer.toUnsignedLong(fibLc97.getfcPlcfandRef()));
            java.util.ArrayList<Integer> cpsat = BasicTypesReader.readCPs(tableStream, cpsat2.size() * 4);
            if (cpsat.size() == cpsat2.size()) {
                int pos0 = (((int)fib97.getccpText()) + ((int)fib97.getccpFtn()) + ((int)fib97.getccpHdd()));
                int len = (int)fib97.getccpAtn();
                String ttt = totalText.substring(pos0, pos0 + len);
                for (int i = 0; i < (cpsat.size() - 2); i++) {
                    int cp = cpsat.get(i);
                    if ((cp < 0) || cp >= pos0) 
                        continue;
                    com.pullenti.unitext.internal.uni.UnitextGen ge = new com.pullenti.unitext.internal.uni.UnitextGen();
                    int max = ((i + 1) < (cpsat.size() - 2) ? cpsat2.get(i + 1) : len);
                    this._createUni(ge, null, 0, pos0 + cpsat2.get(i), pos0 + max, totalText, 0);
                    com.pullenti.unitext.UnitextItem cc = ge.finish(true, null);
                    if (cc == null) 
                        continue;
                    StringBuilder tmp = new StringBuilder();
                    cc.getPlaintext(tmp, null);
                    if (tmp.length() < 1) 
                        continue;
                    com.pullenti.unitext.UnitextComment cmt = com.pullenti.unitext.UnitextComment._new50(tmp.toString());
                    m_Comments.put(cp, cmt);
                }
            }
            if (Integer.compareUnsigned(fib97.getccpTxbx(), (int)0) > 0) {
                int pos0 = (((int)fib97.getccpText()) + ((int)fib97.getccpFtn()) + ((int)fib97.getccpHdd())) + ((int)fib97.getccpAtn()) + ((int)fib97.getccpEdn());
                int len = (int)fib97.getccpTxbx();
                String ttt = totalText.substring(pos0, pos0 + len);
                if (Integer.compareUnsigned(fibLc97.getlcbPlcfTxbxBkd(), (int)0) > 0 && Integer.compareUnsigned(fibLc97.getlcbPlcftxbxTxt(), (int)0) > 0) {
                    tableStream.setPosition(Integer.toUnsignedLong(fibLc97.getfcPlcftxbxTxt()));
                    int k2 = (((((int)fibLc97.getlcbPlcftxbxTxt()) - 4)) / 26);
                    java.util.ArrayList<Integer> cps2 = BasicTypesReader.readCPs(tableStream, ((k2 + 1)) * 4);
                    java.util.ArrayList<com.pullenti.unitext.UnitextContainer> texts2 = new java.util.ArrayList<com.pullenti.unitext.UnitextContainer>();
                    for (int ii = 0; ii < (cps2.size() - 2); ii++) {
                        com.pullenti.unitext.internal.uni.UnitextGen ge = new com.pullenti.unitext.internal.uni.UnitextGen();
                        int max = ((ii + 1) < (cps2.size() - 2) ? cps2.get(ii + 1) : len);
                        this._createUni(ge, null, 0, pos0 + cps2.get(ii), pos0 + max, totalText, 0);
                        com.pullenti.unitext.UnitextItem cc = ge.finish(true, null);
                        com.pullenti.unitext.UnitextContainer cnt = com.pullenti.unitext.UnitextContainer._new94(com.pullenti.unitext.UnitextContainerType.SHAPE);
                        if (cc != null) 
                            cnt.children.add(cc);
                        texts2.add(cnt);
                    }
                    java.util.ArrayList<Integer> lids = new java.util.ArrayList<Integer>();
                    for (int ii = 0; ii < k2; ii++) {
                        tableStream.setPosition(tableStream.getPosition() + (14L));
                        lids.add(ReadUtils.readInt(tableStream));
                        tableStream.setPosition(tableStream.getPosition() + (4L));
                    }
                    tableStream.setPosition(Integer.toUnsignedLong(fibLc97.getfcPlcSpaMom()));
                    int kk = (((((int)fibLc97.getlcbPlcSpaMom()) - 4)) / 30);
                    java.util.ArrayList<Integer> cps3 = BasicTypesReader.readCPs(tableStream, ((kk + 1)) * 4);
                    java.util.ArrayList<Integer> lids2 = new java.util.ArrayList<Integer>();
                    for (int ii = 0; ii < kk; ii++) {
                        lids2.add(ReadUtils.readInt(tableStream));
                        tableStream.setPosition(tableStream.getPosition() + (22L));
                    }
                    for (int ii = lids2.size() - 1; ii >= 0; ii--) {
                        int j = lids.indexOf(lids2.get(ii));
                        if (j >= 0) {
                            m_Shapes.put(cps3.get(ii), texts2.get(j));
                            texts2.remove(j);
                            lids.remove(j);
                            lids2.remove(ii);
                            cps3.remove(ii);
                        }
                    }
                    for (int ii = lids2.size() - 1; ii >= 0; ii--) {
                        com.pullenti.unitext.UnitextContainer cnt = new com.pullenti.unitext.UnitextContainer();
                        for (int j = lids.size() - 1; j >= 0; j--) {
                            if (lids.get(j) > lids2.get(ii)) {
                                cnt.children.add(0, texts2.get(j));
                                lids.remove(j);
                                texts2.remove(j);
                            }
                        }
                        if (cnt.children.size() > 0) 
                            m_Shapes.put(cps3.get(ii), cnt);
                    }
                }
            }
            this._createUni(gen, null, 0, 0, (int)fib97.getccpText(), totalText, 0);
            doc.content = gen.finish(true, null);
            if (Integer.compareUnsigned(fibLc97.getlcbPlcfHdd(), (int)0) != 0) {
                tableStream.setPosition(Integer.toUnsignedLong(fibLc97.getfcPlcfHdd()));
                java.util.ArrayList<Integer> strs = BasicTypesReader.readCPs(tableStream, (int)fibLc97.getlcbPlcfHdd());
                if (strs.size() > 7) {
                    int pos0 = ((int)fib97.getccpText()) + ((int)fib97.getccpFtn());
                    int len = (int)fib97.getccpHdd();
                    String sub = totalText.substring(pos0, pos0 + len);
                    com.pullenti.unitext.UnitextPagesection sect = new com.pullenti.unitext.UnitextPagesection();
                    for (int k = 0; k < 2; k++) {
                        com.pullenti.unitext.internal.uni.UnitextGen gg = new com.pullenti.unitext.internal.uni.UnitextGen();
                        for (int ii = 0; ii < 2; ii++) {
                            int jj = 7 + ii;
                            if (k > 0) 
                                jj += 2;
                            if ((jj < strs.size()) && (strs.get(jj) < strs.get(jj + 1))) 
                                this._createUni(gg, null, 0, pos0 + strs.get(jj), (pos0 + strs.get(jj + 1)) - 1, totalText, 0);
                        }
                        com.pullenti.unitext.UnitextItem fi = gg.finish(true, null);
                        if (fi != null) 
                            sect.items.add(com.pullenti.unitext.UnitextPagesectionItem._new277(fi, k > 0));
                    }
                    if (sect.items.size() > 0) 
                        doc.sections.add(sect);
                }
            }
            return;
        }
    }

    private void _createUni(com.pullenti.unitext.internal.uni.UnitextGen gen, com.pullenti.unitext.UnitextItem blk, int i0, int p0, int p1, String txt, int level) {
        if (level > 30) 
            return;
        if (i0 == 32) {
        }
        StringBuilder tmp = new StringBuilder();
        for (int i = i0; i < m_Paragraphs.size(); i++) {
            Paragraph p = m_Paragraphs.get(i);
            if (p.getPos() == 496) {
            }
            if (p.getPos() >= p1) 
                break;
            if ((p.getPos() < p0) || (p.getPos() + p.getLength()) > p1) 
                continue;
            if (gen != null) {
            }
            byte[] data;
            if (p.isInTable() && gen != null && blk == null) {
                com.pullenti.unitext.internal.uni.UnitextGenTable tab = new com.pullenti.unitext.internal.uni.UnitextGenTable();
                java.util.ArrayList<com.pullenti.unitext.internal.uni.UniTextGenCell> ro = new java.util.ArrayList<com.pullenti.unitext.internal.uni.UniTextGenCell>();
                java.util.ArrayList<Integer> allids = new java.util.ArrayList<Integer>();
                java.util.ArrayList<Integer> hasHugePapxRows = new java.util.ArrayList<Integer>();
                com.pullenti.unitext.internal.uni.UnitextGen cgen = new com.pullenti.unitext.internal.uni.UnitextGen();
                for (; i < m_Paragraphs.size(); i++) {
                    Paragraph pp = m_Paragraphs.get(i);
                    if (!pp.isInTable() && pp.isTableCellEnd() && pp.getLength() <= 2) {
                        if (ro.size() > 0) {
                            data = pp.getProperty(SinglePropertyModifiers.sprmPHugePapx);
                            if (data != null) 
                                hasHugePapxRows.add(tab.cells.size());
                            tab.cells.add(ro);
                        }
                        ro = new java.util.ArrayList<com.pullenti.unitext.internal.uni.UniTextGenCell>();
                        continue;
                    }
                    if (!pp.isInTable()) {{
                                i--;
                                break;
                            }
                    }
                    if (pp.getTableDepth() < p.getTableDepth()) {{
                                i--;
                                break;
                            }
                    }
                    if (pp.getTableDepth() > p.getTableDepth()) {
                        int i1;
                        for (i1 = i + 1; i1 < m_Paragraphs.size(); i1++) {
                            if (pp.getTableDepth() > m_Paragraphs.get(i1).getTableDepth() && m_Paragraphs.get(i1).getTableDepth() == p.getTableDepth()) 
                                break;
                        }
                        com.pullenti.unitext.internal.uni.UnitextGen gt = new com.pullenti.unitext.internal.uni.UnitextGen();
                        this._createUni(cgen, null, i, pp.getPos(), m_Paragraphs.get(i1 - 1).getPos() + m_Paragraphs.get(i1 - 1).getLength(), txt, level + 1);
                        i = i1;
                        if (i1 < m_Paragraphs.size()) 
                            pp = m_Paragraphs.get(i1);
                    }
                    if (pp.isTableRowEnd()) {
                        data = pp.getProperty(SinglePropertyModifiers.sprmTDefTable);
                        if (data != null && data.length > 0) {
                            int cou = Byte.toUnsignedInt(data[0]);
                            if (cou == ro.size()) {
                                for (int ii = 1, cc = 0; (ii < data.length) && (cc < ro.size()); ii += 2,cc++) {
                                    short iid = (short)Byte.toUnsignedInt(data[ii + 1]);
                                    iid <<= ((short)8);
                                    iid |= ((short)Byte.toUnsignedInt(data[ii]));
                                    ro.get(cc).tag = (int)iid;
                                    if (!allids.contains((int)iid)) 
                                        allids.add((int)iid);
                                }
                            }
                        }
                        if (ro.size() > 0) 
                            tab.cells.add(ro);
                        ro = new java.util.ArrayList<com.pullenti.unitext.internal.uni.UniTextGenCell>();
                        continue;
                    }
                    this._createUni(cgen, new com.pullenti.unitext.UnitextTable(), i, pp.getPos(), pp.getPos() + pp.getLength(), txt, level + 1);
                    if (pp.isTableCellEnd()) {
                        com.pullenti.unitext.internal.uni.UniTextGenCell cel = new com.pullenti.unitext.internal.uni.UniTextGenCell();
                        ro.add(cel);
                        cel.content = cgen.finish(true, null);
                        cgen = new com.pullenti.unitext.internal.uni.UnitextGen();
                    }
                }
                if (ro.size() > 0) 
                    tab.cells.add(ro);
                for (int ii = 0; ii < tab.cells.size(); ii++) {
                    boolean hasColSpan = false;
                    for (int jj = 0; jj < tab.cells.get(ii).size(); jj++) {
                        com.pullenti.unitext.internal.uni.UniTextGenCell cel = tab.cells.get(ii).get(jj);
                        int cid = allids.indexOf(cel.tag);
                        if (cid < 0) 
                            continue;
                        if ((jj + 1) == tab.cells.get(ii).size()) {
                            if (((cid + 1) < allids.size()) && !hasHugePapxRows.contains(cid)) {
                                hasColSpan = true;
                                cel.colSpan = allids.size() - cid;
                            }
                        }
                        else {
                            com.pullenti.unitext.internal.uni.UniTextGenCell cel2 = tab.cells.get(ii).get(jj + 1);
                            int cid2 = allids.indexOf(cel2.tag);
                            if (cid2 < 0) 
                                continue;
                            if ((cid + 1) < cid2) {
                                hasColSpan = true;
                                cel.colSpan = cid2 - cid;
                            }
                        }
                    }
                    if (hasColSpan || !hasHugePapxRows.contains(ii) || (ii + 1) == tab.cells.size()) 
                        continue;
                    java.util.ArrayList<com.pullenti.unitext.internal.uni.UniTextGenCell> row0 = tab.cells.get(ii);
                    java.util.ArrayList<com.pullenti.unitext.internal.uni.UniTextGenCell> row1 = tab.cells.get(ii + 1);
                    if (row0.size() < row1.size()) {
                        int emp = 0;
                        for (com.pullenti.unitext.internal.uni.UniTextGenCell vv : row1) {
                            if (vv.content == null) 
                                emp++;
                        }
                        if ((emp + 1) == row0.size()) {
                            int fne = 0;
                            for (; fne < row1.size(); fne++) {
                                if (row1.get(fne).content != null) 
                                    break;
                            }
                            row0.get(fne).colSpan = row1.size() - emp;
                        }
                        else 
                            tab.mayHasError = true;
                    }
                    else if (row0.size() > row1.size()) 
                        tab.mayHasError = true;
                }
                if (gen != null) {
                    com.pullenti.unitext.UnitextTable utab = tab.convert();
                    if (utab != null) {
                        gen.append(utab, null, -1, false);
                        gen.appendNewline(false, false);
                    }
                }
                continue;
            }
            if (p.isList() && gen != null && !(blk instanceof com.pullenti.unitext.UnitextList)) {
                data = p.getProperty(SinglePropertyModifiers.sprmPIlfo);
                com.pullenti.unitext.internal.uni.UnitextGenNumStyle num = null;
                if (data != null && data.length > 1) {
                    int ilfo = Byte.toUnsignedInt(data[1]);
                    ilfo <<= 8;
                    ilfo |= (Byte.toUnsignedInt(data[0]));
                    ilfo--;
                    if (ilfo >= 0 && (ilfo < lfos.size())) {
                        com.pullenti.unisharp.Outargwrapper<com.pullenti.unitext.internal.uni.UnitextGenNumStyle> wrapnum542 = new com.pullenti.unisharp.Outargwrapper<com.pullenti.unitext.internal.uni.UnitextGenNumStyle>();
                        com.pullenti.unisharp.Utils.tryGetValue(m_NumStyles, lfos.get(ilfo).lsid, wrapnum542);
                        num = wrapnum542.value;
                    }
                }
                if (m_Dels[p.getPos()] != ((byte)0)) 
                    continue;
                com.pullenti.unitext.internal.uni.UnitextGen gg = new com.pullenti.unitext.internal.uni.UnitextGen();
                this._createUni(gg, new com.pullenti.unitext.UnitextList(), i, p.getPos(), p.getPos() + p.getLength(), txt, level + 1);
                com.pullenti.unitext.UnitextItem gg1 = gg.finish(num != null, null);
                gen.append(gg1, num, p.getListLevel(), false);
                continue;
            }
            if (gen == null) 
                continue;
            tmp.setLength(0);
            tmp.append(txt.substring(p.getPos(), p.getPos() + p.getLength()));
            int cp = p.getPos();
            for (int ii = 0; ii < tmp.length(); ii++,cp++) {
                char ch = tmp.charAt(ii);
                if (m_Dels[cp] != ((byte)0)) {
                    if (ii > 0) 
                        gen.appendText(tmp.toString().substring(0, 0 + ii), false);
                    for (; ii < tmp.length(); ii++,cp++) {
                        if (m_Dels[cp] == ((byte)0)) 
                            break;
                    }
                    if (ii < tmp.length()) 
                        tmp.delete(0, 0 + ii);
                    else 
                        tmp.setLength(0);
                    ii = -1;
                    cp--;
                    continue;
                }
                String sup = null;
                boolean isSub = false;
                com.pullenti.unisharp.Outargwrapper<String> wrapsup548 = new com.pullenti.unisharp.Outargwrapper<String>();
                boolean inoutres549 = com.pullenti.unisharp.Utils.tryGetValue(m_SuperTexts, cp, wrapsup548);
                sup = wrapsup548.value;
                if (inoutres549) {
                }
                else {
                    com.pullenti.unisharp.Outargwrapper<String> wrapsup543 = new com.pullenti.unisharp.Outargwrapper<String>();
                    boolean inoutres544 = com.pullenti.unisharp.Utils.tryGetValue(m_SubTexts, cp, wrapsup543);
                    sup = wrapsup543.value;
                    if (inoutres544) 
                        isSub = true;
                }
                if (sup != null) {
                    if (cp == 84223) {
                    }
                    if (ii > 0) 
                        gen.appendText(tmp.toString().substring(0, 0 + ii), false);
                    String stxt = sup.trim();
                    if (!com.pullenti.unisharp.Utils.isNullOrEmpty(stxt)) 
                        gen.append(com.pullenti.unitext.UnitextPlaintext._new58(stxt, (isSub ? com.pullenti.unitext.UnitextPlaintextType.SUB : com.pullenti.unitext.UnitextPlaintextType.SUP)), null, -1, false);
                    else {
                    }
                    ii += sup.length();
                    if (sup.length() > 0) 
                        cp += (sup.length() - 1);
                    if (ii < tmp.length()) 
                        tmp.delete(0, 0 + ii);
                    else 
                        tmp.setLength(0);
                    ii = -1;
                    continue;
                }
                if (((int)ch) < 0x15) {
                }
                if (((int)ch) == 0x13) {
                    StringBuilder tmp2 = new StringBuilder();
                    StringBuilder tmp3 = null;
                    com.pullenti.unitext.UnitextContainer shape = null;
                    int lev = 1;
                    int ii0 = ii;
                    cp++;
                    ii++;
                    while (true) {
                        for (; ii < tmp.length(); ii++,cp++) {
                            ch = tmp.charAt(ii);
                            if (((int)ch) == 0x13) 
                                lev++;
                            else if (((int)ch) == 0x15) {
                                lev--;
                                if (lev <= 0) 
                                    break;
                            }
                            else if (((int)ch) == 0x14 && lev == 1) {
                                if (tmp3 == null) 
                                    tmp3 = new StringBuilder();
                            }{
                                    tmp2.append(ch);
                                    if (tmp3 != null && ((int)ch) != 0x14) 
                                        tmp3.append(ch);
                                }
                            if (m_Shapes.containsKey(cp)) 
                                shape = m_Shapes.get(cp);
                        }
                        if (lev == 0) 
                            break;
                        if (tmp2.toString().trim().startsWith("TOC")) 
                            break;
                        if ((i + 1) >= m_Paragraphs.size()) 
                            break;
                        i++;
                        p = m_Paragraphs.get(i);
                        cp = p.getPos() - 1;
                        tmp.append(txt.substring(p.getPos(), p.getPos() + p.getLength()));
                    }
                    String str0 = com.pullenti.unisharp.Utils.trimStart(tmp2.toString());
                    if (lev == 0 || ((lev == 1 && str0.startsWith("TOC")))) {
                        String str = MSOfficeHelper.extractSpecText(str0);
                        if (ii0 > 0) 
                            gen.appendText(tmp.toString().substring(0, 0 + ii0), false);
                        if (str != null) {
                            String hyperlink = null;
                            if (str0.startsWith("HYPERLINK") && (str0.indexOf("PAGEREF") < 0)) {
                                int jj0 = str0.indexOf('"');
                                int jj1 = str0.indexOf('"', jj0 + 1);
                                if (jj0 > 0 && jj1 > (jj0 + 1)) 
                                    hyperlink = str0.substring(jj0 + 1, jj0 + 1 + jj1 - jj0 - 1);
                            }
                            if (hyperlink != null) {
                                com.pullenti.unitext.UnitextHyperlink hr = com.pullenti.unitext.UnitextHyperlink._new59(hyperlink);
                                hr.content = com.pullenti.unitext.UnitextPlaintext._new57(str);
                                gen.append(hr, null, -1, false);
                            }
                            else 
                                gen.appendText(str, false);
                        }
                        else if (tmp3 != null) {
                            String tt = tmp3.toString();
                            if (!gen.getLastText().endsWith(tt)) 
                                gen.appendText(tt, false);
                        }
                        if (shape != null) 
                            gen.append(shape, null, -1, false);
                        if ((ii + 1) >= tmp.length()) 
                            tmp.setLength(0);
                        else 
                            tmp.delete(0, 0 + ii + 1);
                        ii = -1;
                        continue;
                    }
                }
                if (m_Footnotes != null) {
                    if (m_Footnotes.containsKey(cp)) {
                        if (((int)ch) != 0x2) 
                            m_Footnotes.get(cp).customMark = (String.valueOf(ch));
                        if (ii > 0) 
                            gen.appendText(tmp.toString().substring(0, 0 + ii), false);
                        gen.append(m_Footnotes.get(cp), null, -1, false);
                        tmp.delete(0, 0 + ii + 1);
                        ii = -1;
                        continue;
                    }
                }
                if (((int)ch) == 0xB) {
                    if (ii > 0) 
                        gen.appendText(tmp.toString().substring(0, 0 + ii), false);
                    gen.appendNewline(false, false);
                    tmp.delete(0, 0 + ii + 1);
                    ii = -1;
                    continue;
                }
                if (((int)ch) == 0xC) {
                    if (ii > 0) 
                        gen.appendText(tmp.toString().substring(0, 0 + ii), false);
                    gen.appendPagebreak();
                    tmp.delete(0, 0 + ii + 1);
                    ii = -1;
                    continue;
                }
                if (((int)ch) == 0xD || ((int)ch) == 0xA) {
                }
                if (((int)ch) == 5 && m_Comments != null && m_Comments.containsKey(cp)) {
                    if (ii > 0) 
                        gen.appendText(tmp.toString().substring(0, 0 + ii), false);
                    gen.append(m_Comments.get(cp), null, -1, false);
                    tmp.delete(0, 0 + ii + 1);
                    ii = -1;
                    continue;
                }
                if (((((int)ch) == 7 || ((int)ch) == 2 || ((int)ch) == 5) || ((int)ch) == 3 || ((int)ch) == 4) || ((int)ch) == 0x1F) {
                    tmp.delete(ii, ii + 1);
                    ii--;
                    continue;
                }
                if (((int)ch) == 1 || ((int)ch) == 8) {
                    if (ii > 0) 
                        gen.appendText(tmp.toString().substring(0, 0 + ii), false);
                    if (m_Shapes.containsKey(cp)) 
                        gen.append(m_Shapes.get(cp), null, -1, false);
                    else 
                        gen.append(new com.pullenti.unitext.UnitextImage(), null, -1, false);
                    tmp.delete(0, 0 + ii + 1);
                    ii = -1;
                    continue;
                }
                if (((int)ch) != 6 && ((int)ch) != 0xD && (((int)ch) < 0x20)) {
                    if (ii >= 0 && (ii < tmp.length())) 
                        tmp.setCharAt(ii, ' ');
                }
            }
            if (tmp.length() > 0) 
                gen.appendText(tmp.toString(), false);
        }
    }

    private void loadStsh(com.pullenti.unisharp.Stream wordDocumentStream, STSH stsh) {
        m_StyleDefinitionsMap = new java.util.HashMap<Short, StyleDefinition>();
        for (int istd = 0; istd < stsh.rglpstd.length; istd++) {
            STD std = stsh.rglpstd[istd];
            if (std == null) 
                continue;
            StyleDefinition def = new StyleDefinition(this, std);
            m_StyleDefinitionsMap.put((short)istd, def);
        }
        java.util.ArrayList<Prl> _defaultPrls = new java.util.ArrayList<Prl>();
        short ftcBi = stsh.stshi.ftcBi;
        _defaultPrls.add(new Prl(new Sprm(SinglePropertyModifiers.sprmCFtcBi), java.nio.ByteBuffer.allocate(2).order(java.nio.ByteOrder.LITTLE_ENDIAN).putShort(ftcBi).array()));
        short ftcAsci = stsh.stshi.stshif.ftcAsci;
        _defaultPrls.add(new Prl(new Sprm(SinglePropertyModifiers.sprmCRgFtc0), java.nio.ByteBuffer.allocate(2).order(java.nio.ByteOrder.LITTLE_ENDIAN).putShort(ftcAsci).array()));
        short ftcFE = stsh.stshi.stshif.ftcFE;
        _defaultPrls.add(new Prl(new Sprm(SinglePropertyModifiers.sprmCRgFtc1), java.nio.ByteBuffer.allocate(2).order(java.nio.ByteOrder.LITTLE_ENDIAN).putShort(ftcFE).array()));
        short ftcOther = stsh.stshi.stshif.ftcOther;
        _defaultPrls.add(new Prl(new Sprm(SinglePropertyModifiers.sprmCRgFtc2), java.nio.ByteBuffer.allocate(2).order(java.nio.ByteOrder.LITTLE_ENDIAN).putShort(ftcOther).array()));
        this.defaultPrls = _defaultPrls.toArray(new Prl[_defaultPrls.size()]);
    }

    private void loadCharacterFormatting(com.pullenti.unisharp.Stream wordDocumentStream, PlcBteChpx plcfBteChpx) throws java.io.IOException {
        java.util.ArrayList<CharacterFormatting> _formattings = new java.util.ArrayList<CharacterFormatting>();
        for (int i = 0; i < plcfBteChpx.aPnBteChpx.length; i++) {
            wordDocumentStream.setPosition((long)(((int)plcfBteChpx.aPnBteChpx[i]) * 512));
            try {
                ChpxFkp papxFkp = BasicTypesReader.readChpxFkp(wordDocumentStream);
                for (int j = 0; j < papxFkp.rgb.length; j++) {
                    int startFc = (int)papxFkp.rgfc[j];
                    int endFc = (int)papxFkp.rgfc[j + 1];
                    FileCharacterPosition fc = _findPos123(fileCharacterPositions, startFc, endFc);
                    if (fc == null) 
                        continue;
                    if (startFc < fc.offset) 
                        startFc = fc.offset;
                    if (endFc > (fc.offset + (fc.bytesPerCharacter * fc.length))) 
                        endFc = fc.offset + (fc.bytesPerCharacter * fc.length);
                    CharacterFormatting para = new CharacterFormatting(this, ((startFc - fc.offset)) / fc.bytesPerCharacter, ((endFc - startFc)) / fc.bytesPerCharacter, fc, papxFkp.rgb[j].getValue());
                    _formattings.add(para);
                }
            } catch (Exception ex550) {
            }
        }
        for (int ii = 0; ii < _formattings.size(); ii++) {
            boolean ch = false;
            for (int jj = 0; jj < (_formattings.size() - 1); jj++) {
                if (_formattings.get(jj).getOffset() > _formattings.get(jj + 1).getOffset()) {
                    CharacterFormatting f = _formattings.get(jj);
                    com.pullenti.unisharp.Utils.putArrayValue(_formattings, jj, _formattings.get(jj + 1));
                    com.pullenti.unisharp.Utils.putArrayValue(_formattings, jj + 1, f);
                    ch = true;
                }
            }
            if (!ch) 
                break;
        }
        this.m_Formattings = _formattings.toArray(new CharacterFormatting[_formattings.size()]);
    }

    private static FileCharacterPosition _findPos123(FileCharacterPosition[] arr, int startFc, int endFc) {
        for (FileCharacterPosition f : arr) {
            if (!((endFc <= f.offset || ((f.offset + (f.bytesPerCharacter * f.length)) < startFc)))) 
                return f;
        }
        return null;
    }

    private void loadParagraphs(com.pullenti.unisharp.Stream wordDocumentStream, Clx clx, PlcBtePapx plcfBtePapx) throws java.io.IOException, Exception {
        m_Paragraphs = new java.util.ArrayList<Paragraph>();
        for (int i = 0; i < plcfBtePapx.aPnBtePapx.length; i++) {
            wordDocumentStream.setPosition((long)(((int)plcfBtePapx.aPnBtePapx[i]) * 512));
            boolean er;
            com.pullenti.unisharp.Outargwrapper<Boolean> wraper551 = new com.pullenti.unisharp.Outargwrapper<Boolean>();
            PapxFkp papxFkp = BasicTypesReader.readPapxFkp(wordDocumentStream, wraper551);
            er = (wraper551.value != null ? wraper551.value : false);
            if (er) 
                m_Error = true;
            for (int j = 0; j < papxFkp.rgbx.length; j++) {
                int startFc = (int)papxFkp.rgfc[j];
                int endFc = (int)papxFkp.rgfc[j + 1];
                FileCharacterPosition fc = _findPos123(fileCharacterPositions, startFc, endFc);
                if (fc == null) 
                    continue;
                if (startFc < fc.offset) 
                    startFc = fc.offset;
                if (endFc > (fc.offset + (fc.bytesPerCharacter * fc.length))) 
                    endFc = fc.offset + (fc.bytesPerCharacter * fc.length);
                Paragraph para = new Paragraph(this, ((startFc - fc.offset)) / fc.bytesPerCharacter, ((endFc - startFc)) / fc.bytesPerCharacter, fc, papxFkp.rgbx[j].getValue());
                m_Paragraphs.add(para);
            }
        }
        for (int ii = 0; ii < m_Paragraphs.size(); ii++) {
            boolean ch = false;
            for (int jj = 0; jj < (m_Paragraphs.size() - 1); jj++) {
                if (m_Paragraphs.get(jj).compareTo(m_Paragraphs.get(jj + 1)) > 0) {
                    Paragraph p = m_Paragraphs.get(jj);
                    com.pullenti.unisharp.Utils.putArrayValue(m_Paragraphs, jj, m_Paragraphs.get(jj + 1));
                    com.pullenti.unisharp.Utils.putArrayValue(m_Paragraphs, jj + 1, p);
                    ch = true;
                }
            }
            if (!ch) 
                break;
        }
        for (int i = 0; i < (m_Paragraphs.size() - 1); i++) {
            if ((m_Paragraphs.get(i).getPos() + m_Paragraphs.get(i).getLength()) < m_Paragraphs.get(i + 1).getPos()) 
                m_Paragraphs.get(i).setLength((m_Paragraphs.get(i + 1).getPos() - m_Paragraphs.get(i).getPos()));
        }
    }

    private void loadCharacters(com.pullenti.unisharp.Stream wordDocumentStream, Clx clx) throws java.io.IOException, Exception {
        if (clx == null) 
            return;
        PlcPcd plcPcd = clx.pcdt.plcPcd;
        FileCharacterPosition[] fileCharacters = new FileCharacterPosition[plcPcd.pcds.length];
        int position = 0;
        for (int i = 0; i < plcPcd.pcds.length; i++) {
            int length = (((int)plcPcd.cPs[i + 1]) - ((int)plcPcd.cPs[i]));
            int offset = plcPcd.pcds[i].fc.fc;
            boolean compressed = plcPcd.pcds[i].fc.fCompressed;
            if (compressed) {
                char[] txt = new char[length];
                wordDocumentStream.setPosition((long)(offset / 2));
                byte[] data = ReadUtils.readExact(wordDocumentStream, length);
                FcCompressedMapping.getChars(data, 0, length, txt, 0);
                this.text.append(txt);
            }
            else {
                wordDocumentStream.setPosition((long)offset);
                byte[] data = ReadUtils.readExact(wordDocumentStream, length * 2);
                String txt = com.pullenti.util.MiscHelper.decodeStringUnicode(data, 0, -1);
                this.text.append(txt);
            }
            FileCharacterPosition fc = new FileCharacterPosition();
            fc.offset = (compressed ? offset / 2 : offset);
            fc.bytesPerCharacter = (compressed ? 1 : 2);
            fc.length = length;
            fc.characterIndex = position;
            fc.prls = this.expandPrm(plcPcd.pcds[i].prm, clx);
            fileCharacters[i] = fc;
            position += length;
        }
        java.util.ArrayList<FileCharacterPosition> li = new java.util.ArrayList<FileCharacterPosition>(java.util.Arrays.asList(fileCharacters));
        for (int ii = 0; ii < li.size(); ii++) {
            boolean ch = false;
            for (int jj = 0; jj < (li.size() - 1); jj++) {
                if (li.get(jj).offset > li.get(jj + 1).offset) {
                    FileCharacterPosition f = li.get(jj);
                    com.pullenti.unisharp.Utils.putArrayValue(li, jj, li.get(jj + 1));
                    com.pullenti.unisharp.Utils.putArrayValue(li, jj + 1, f);
                    ch = true;
                }
            }
            if (!ch) 
                break;
        }
        fileCharacters = li.toArray(new FileCharacterPosition[li.size()]);
        this.fileCharacterPositions = fileCharacters;
    }

    private Prl[] expandPrm(Prm prm, Clx clx) throws Exception {
        if (prm.getfComplex()) {
            int index = Byte.toUnsignedInt(prm.getigrpprl());
            return clx.rgPrc[index].grpPrl;
        }
        else if (Integer.compareUnsigned(prm.prm, (short)0x0000) != 0) {
            short sprm;
            com.pullenti.unisharp.Outargwrapper<Short> wrapsprm552 = new com.pullenti.unisharp.Outargwrapper<Short>();
            boolean inoutres553 = com.pullenti.unisharp.Utils.tryGetValue(SinglePropertyModifiers.prm0Map, prm.getisprm(), wrapsprm552);
            sprm = (wrapsprm552.value != null ? wrapsprm552.value : 0);
            if (!inoutres553) 
                throw new Exception("Invalid Prm: isprm");
            byte value = prm.getval();
            Prl prl = new Prl(new Sprm(sprm), new byte[] {value});
            return new Prl[] {prl};
        }
        else 
            return new Prl[0];
    }

    public StyleCollection getDefaults() {
        java.util.ArrayList<Prl[]> li = new java.util.ArrayList<Prl[]>();
        li.add(defaultPrls);
        return new StyleCollection(li);
    }

    public StyleCollection getStyle(int characterPosition, FormattingLevel level) {
        java.util.ArrayList<Prl[]> prls = new java.util.ArrayList<Prl[]>();
        if ((level.value()) >= (FormattingLevel.CHARACTER.value())) {
            for (CharacterFormatting formatting : m_Formattings) {
                if (formatting.getFileCharacterPosition().contains(characterPosition)) {
                    if ((level.value()) >= (FormattingLevel.CHARACTERSTYLE.value())) {
                        StyleDefinition definition = formatting.getStyle();
                        if (definition != null) 
                            definition.expandStyles(prls);
                    }
                }
            }
        }
        if ((level.value()) >= (FormattingLevel.PARAGRAPH.value())) {
            for (Paragraph paragraph : m_Paragraphs) {
                if (paragraph.getFileCharacterPosition().contains(characterPosition)) {
                    if ((level.value()) >= (FormattingLevel.PARAGRAPHSTYLE.value())) {
                        StyleDefinition definition = paragraph.getStyle();
                        definition.expandStyles(prls);
                    }
                }
            }
        }
        if ((level.value()) >= (FormattingLevel.PART.value())) {
            for (FileCharacterPosition fcp : fileCharacterPositions) {
                if (fcp.contains(characterPosition)) 
                    prls.add(fcp.prls);
            }
        }
        if ((level.value()) >= (FormattingLevel.GLOBAL.value())) 
            prls.add(defaultPrls);
        return new StyleCollection(prls);
    }

    public static class FileCharacterPosition {
    
        public int offset;
    
        public int length;
    
        public int characterIndex;
    
        public int bytesPerCharacter;
    
        public com.pullenti.unitext.internal.word.Prl[] prls;
    
        @Override
        public String toString() {
            StringBuilder res = new StringBuilder();
            res.append("CharIndex:").append(characterIndex).append(" Offset:").append(offset).append(" Len:").append(length);
            if (prls != null) {
                for (com.pullenti.unitext.internal.word.Prl prl : prls) {
                    res.append(" ").append(((String)com.pullenti.unisharp.Utils.notnull(com.pullenti.unitext.internal.word.SinglePropertyModifiers.getSprmName(prl.sprm.sprm), "?")));
                }
            }
            return res.toString();
        }
    
        public boolean contains(int position) {
            return characterIndex <= position && (position < (characterIndex + length));
        }
        public FileCharacterPosition() {
        }
    }


    public static class LFO {
    
        public int lsid;
    
        public int datCount;
    
        public byte ibstFltAutoNum;
    
        private java.util.ArrayList<com.pullenti.unitext.internal.word.WordDocument.LFOLVL> lvls = new java.util.ArrayList<com.pullenti.unitext.internal.word.WordDocument.LFOLVL>();
        public LFO() {
        }
    }


    public static class LFOData {
        public LFOData() {
        }
    }


    public static class LFOLVL {
    
        public int iStartAt;
        public LFOLVL() {
        }
    }


    private java.util.ArrayList<LFO> lfos = new java.util.ArrayList<LFO>();

    private void loadLFOS(com.pullenti.unisharp.Stream wordDocumentStream, int length) throws java.io.IOException {
        if (length < 10) 
            return;
        int cou = ReadUtils.readInt(wordDocumentStream);
        length -= 4;
        for (int i = 0; i < cou; i++) {
            LFO lfo = new LFO();
            lfos.add(lfo);
            lfo.lsid = ReadUtils.readInt(wordDocumentStream);
            length -= 4;
            wordDocumentStream.setPosition(wordDocumentStream.getPosition() + (8L));
            length -= 8;
            lfo.datCount = wordDocumentStream.read();
            length--;
            lfo.ibstFltAutoNum = (byte)wordDocumentStream.read();
            length--;
            wordDocumentStream.setPosition(wordDocumentStream.getPosition() + (2L));
            length -= 2;
        }
        for (int i = 0; i < cou; i++) {
            if (length < 4) 
                break;
            int cp = ReadUtils.readInt(wordDocumentStream);
            length -= 4;
            for (int j = 0; j < lfos.get(i).datCount; j++) {
                if (length < 10) 
                    break;
            }
        }
    }

    public static class LSTF {
    
        public int lsid;
    
        public byte[] istds = new byte[18];
    
        public boolean fSimpleList;
    
        public boolean fAutoNum;
    
        public java.util.ArrayList<com.pullenti.unitext.internal.word.WordDocument.LVL> lvls = new java.util.ArrayList<com.pullenti.unitext.internal.word.WordDocument.LVL>();
        public LSTF() {
        }
    }


    public static class LVL {
    
        public int iStartAt;
    
        public byte nfc;
    
        public byte[] rgbxchNums = new byte[9];
    
        public byte ixchFollow;
    
        public int dxaIndentSav;
    
        public byte cbGrpprlChpx;
    
        public byte cbGrpprlPapx;
    
        public byte ilvlRestartLim;
    
        public String xstname;
        public LVL() {
        }
    }


    private java.util.ArrayList<LSTF> lstfs = new java.util.ArrayList<LSTF>();

    private void loadLSTFs(com.pullenti.unisharp.Stream wordDocumentStream, int length) throws java.io.IOException {
        int cou = (int)ReadUtils.readShort(wordDocumentStream);
        length -= 2;
        for (int i = 0; i < cou; i++) {
            LSTF lstf = new LSTF();
            lstfs.add(lstf);
            lstf.lsid = ReadUtils.readInt(wordDocumentStream);
            length -= 4;
            com.pullenti.unitext.internal.uni.UnitextGenNumStyle num = new com.pullenti.unitext.internal.uni.UnitextGenNumStyle();
            num.setId(((Integer)lstf.lsid).toString());
            if (!m_NumStyles.containsKey(lstf.lsid)) 
                m_NumStyles.put(lstf.lsid, num);
            ReadUtils.readInt(wordDocumentStream);
            length -= 4;
            wordDocumentStream.read(lstf.istds, 0, 18);
            length -= 18;
            byte b = (byte)wordDocumentStream.read();
            wordDocumentStream.read();
            length -= 2;
            if ((((Byte.toUnsignedInt(b)) & 1)) != 0) 
                lstf.fSimpleList = true;
            if ((((Byte.toUnsignedInt(b)) & 4)) != 0) 
                lstf.fAutoNum = true;
        }
        for (int i = 0; i < cou; i++) {
            LSTF lstf = lstfs.get(i);
            com.pullenti.unitext.internal.uni.UnitextGenNumStyle num = m_NumStyles.get(lstf.lsid);
            for (int j = 0; j < ((lstf.fSimpleList ? 1 : 9)); j++) {
                LVL lvl = new LVL();
                lstf.lvls.add(lvl);
                lvl.iStartAt = ReadUtils.readInt(wordDocumentStream);
                length -= 4;
                lvl.nfc = (byte)wordDocumentStream.read();
                length--;
                byte bb = (byte)wordDocumentStream.read();
                length--;
                wordDocumentStream.read(lvl.rgbxchNums, 0, 9);
                length -= 9;
                lvl.ixchFollow = (byte)wordDocumentStream.read();
                length--;
                lvl.dxaIndentSav = ReadUtils.readInt(wordDocumentStream);
                length -= 4;
                ReadUtils.readInt(wordDocumentStream);
                length -= 4;
                lvl.cbGrpprlChpx = (byte)wordDocumentStream.read();
                length--;
                lvl.cbGrpprlPapx = (byte)wordDocumentStream.read();
                length--;
                lvl.ilvlRestartLim = (byte)wordDocumentStream.read();
                length--;
                wordDocumentStream.read();
                length--;
                wordDocumentStream.setPosition(wordDocumentStream.getPosition() + ((long)((Byte.toUnsignedInt(lvl.cbGrpprlChpx)) + (Byte.toUnsignedInt(lvl.cbGrpprlPapx)))));
                length -= ((Byte.toUnsignedInt(lvl.cbGrpprlChpx)) + (Byte.toUnsignedInt(lvl.cbGrpprlPapx)));
                StringBuilder tmp = new StringBuilder();
                int slen = (int)ReadUtils.readShort(wordDocumentStream);
                length -= 2;
                for (int k = 0; k < slen; k++) {
                    short cod = (short)ReadUtils.readShort(wordDocumentStream);
                    char ch = (char)cod;
                    if (Integer.compareUnsigned(cod, (short)0x20) >= 0) {
                        if (Integer.compareUnsigned(cod, (short)0xF000) >= 0) {
                            char chh = com.pullenti.unitext.internal.misc.WingdingsHelper.getUnicode((Short.toUnsignedInt(cod)) - 0xF000);
                            if (((int)chh) != 0) 
                                ch = chh;
                        }
                        tmp.append(ch);
                    }
                    else 
                        tmp.append("%").append(((((int)ch) + 1)));
                    length -= 2;
                }
                lvl.xstname = tmp.toString();
                com.pullenti.unitext.internal.uni.UniTextGenNumLevel nl = new com.pullenti.unitext.internal.uni.UniTextGenNumLevel();
                num.levels.add(nl);
                nl.format = lvl.xstname;
                nl.start = lvl.iStartAt;
                String mnem;
                com.pullenti.unisharp.Outargwrapper<String> wrapmnem554 = new com.pullenti.unisharp.Outargwrapper<String>();
                boolean inoutres555 = com.pullenti.unisharp.Utils.tryGetValue(M_NUMTYPESMAP, lvl.nfc, wrapmnem554);
                mnem = wrapmnem554.value;
                if (inoutres555) 
                    nl.type = DocNumStyles.getNumTyp(mnem);
                else 
                    nl.type = com.pullenti.unitext.internal.uni.UniTextGenNumType.DECIMAL;
            }
        }
    }


    public static java.util.HashMap<Byte, String> M_NUMTYPESMAP;
    public WordDocument() {
    }
    public static WordDocument _globalInstance;
    
    static {
        try { _globalInstance = new WordDocument(); } 
        catch(Exception e) { }
        M_NUMTYPESMAP = new java.util.HashMap<Byte, String>();
        M_NUMTYPESMAP.put((byte)0x00, "decimal msonfcUCRoman");
        M_NUMTYPESMAP.put((byte)0x01, "upperRoman");
        M_NUMTYPESMAP.put((byte)0x02, "lowerRoman");
        M_NUMTYPESMAP.put((byte)0x03, "upperLetter");
        M_NUMTYPESMAP.put((byte)0x04, "lowerLetter");
        M_NUMTYPESMAP.put((byte)0x05, "ordinal");
        M_NUMTYPESMAP.put((byte)0x06, "cardinalText");
        M_NUMTYPESMAP.put((byte)0x07, "ordinalText");
        M_NUMTYPESMAP.put((byte)0x08, "hex");
        M_NUMTYPESMAP.put((byte)0x09, "chicago");
        M_NUMTYPESMAP.put((byte)0x0A, "ideographDigital");
        M_NUMTYPESMAP.put((byte)0x0B, "japaneseCounting");
        M_NUMTYPESMAP.put((byte)0x0C, "Aiueo");
        M_NUMTYPESMAP.put((byte)0x0D, "Iroha");
        M_NUMTYPESMAP.put((byte)0x0E, "decimalFullWidth");
        M_NUMTYPESMAP.put((byte)0x0F, "decimalHalfWidth");
        M_NUMTYPESMAP.put((byte)0x10, "japaneseLegal");
        M_NUMTYPESMAP.put((byte)0x11, "japaneseDigitalTenThousand");
        M_NUMTYPESMAP.put((byte)0x12, "decimalEnclosedCircle");
        M_NUMTYPESMAP.put((byte)0x13, "decimalFullWidth2");
        M_NUMTYPESMAP.put((byte)0x14, "aiueoFullWidth");
        M_NUMTYPESMAP.put((byte)0x15, "irohaFullWidth");
        M_NUMTYPESMAP.put((byte)0x16, "decimalZero");
        M_NUMTYPESMAP.put((byte)0x17, "bullet");
        M_NUMTYPESMAP.put((byte)0x18, "ganada");
        M_NUMTYPESMAP.put((byte)0x19, "chosung");
        M_NUMTYPESMAP.put((byte)0x1A, "decimalEnclosedFullstop");
        M_NUMTYPESMAP.put((byte)0x1D, "ideographEnclosedCircle");
        M_NUMTYPESMAP.put((byte)0x1E, "ideographTraditional");
        M_NUMTYPESMAP.put((byte)0x1F, "ideographZodiac");
        M_NUMTYPESMAP.put((byte)0x20, "ideographZodiacTraditional");
        M_NUMTYPESMAP.put((byte)0x21, "taiwaneseCounting");
        M_NUMTYPESMAP.put((byte)0x22, "ideographLegalTraditional");
        M_NUMTYPESMAP.put((byte)0x23, "taiwaneseCountingThousand");
        M_NUMTYPESMAP.put((byte)0x24, "taiwaneseDigital");
        M_NUMTYPESMAP.put((byte)0x25, "chineseCounting");
        M_NUMTYPESMAP.put((byte)0x26, "chineseLegalSimplified");
        M_NUMTYPESMAP.put((byte)0x27, "chineseCountingThousand");
        M_NUMTYPESMAP.put((byte)0x28, "decimal");
        M_NUMTYPESMAP.put((byte)0x29, "koreanDigital");
        M_NUMTYPESMAP.put((byte)0x2A, "koreanCounting");
        M_NUMTYPESMAP.put((byte)0x2B, "koreanLegal");
        M_NUMTYPESMAP.put((byte)0x2C, "koreanDigital2");
        M_NUMTYPESMAP.put((byte)0x2D, "hebrew1");
        M_NUMTYPESMAP.put((byte)0x2E, "arabicAlpha");
        M_NUMTYPESMAP.put((byte)0x2F, "hebrew2");
        M_NUMTYPESMAP.put((byte)0x30, "arabicAbjad");
        M_NUMTYPESMAP.put((byte)0x31, "hindiVowels");
        M_NUMTYPESMAP.put((byte)0x32, "hindiConsonants");
        M_NUMTYPESMAP.put((byte)0x33, "hindiNumbers");
        M_NUMTYPESMAP.put((byte)0x34, "hindiCounting");
        M_NUMTYPESMAP.put((byte)0x35, "thaiLetters");
        M_NUMTYPESMAP.put((byte)0x36, "thaiNumbers");
        M_NUMTYPESMAP.put((byte)0x37, "thaiCounting");
        M_NUMTYPESMAP.put((byte)0x38, "vietnameseCounting");
        M_NUMTYPESMAP.put((byte)0x39, "numberInDash");
        M_NUMTYPESMAP.put((byte)0x3A, "russianLower");
        M_NUMTYPESMAP.put((byte)0x3B, "russianUpper");
    }
}
