private int BuildListStyles(ListLevelTable[] levels, ArrayList openLists) { DocumentNodeArray dna = _converterState.DocumentNodeArray; int i; int j; // Tracks when the innermost list goes out of scope int nEndList = -1; // Tracks if this is the first list item in the list bool bFirst = false; int nListStyles = 0; for (i = 0; i < dna.Count; i++) { // Did the innermost list go out of scope? while (i == nEndList) { Debug.Assert(openLists.Count > 0); if (openLists.Count > 0) { openLists.RemoveRange(openLists.Count - 1, 1); if (openLists.Count > 0) { DocumentNode dn1 = (DocumentNode)openLists[openLists.Count - 1]; nEndList = dn1.Index + dn1.ChildCount + 1; } else { nEndList = -1; } } else { nEndList = -1; } } // OK, handle lists, listitems and paragraphs // At the end of this, paragraphs will have their ILVL and ILS properties set to // correspond to the entries in the list table. // I also store the nested depth of the lists in certain properties in the list node FormatState. // So: // list.FormatState.PNLVL will have the max list depth of any paragraph under the list. // list.FormatState.ILS is: // -1 when unset // 0 if there is a conflict for any set of paragraphs underneath // >0 (value of ILS) for paragraphs underneath it. // DocumentNode dn = dna.EntryAt(i); switch (dn.Type) { case DocumentNodeType.dnList: openLists.Add(dn); nEndList = dn.Index + dn.ChildCount + 1; bFirst = true; break; case DocumentNodeType.dnListItem: bFirst = true; break; case DocumentNodeType.dnParagraph: if (bFirst && openLists.Count > 0) { bFirst = false; DocumentNode dnList = (DocumentNode)openLists[openLists.Count - 1]; int iLevel = openLists.Count; MarkerStyle marker = dnList.FormatState.Marker; long nStartIndex = dnList.FormatState.StartIndex; if (nStartIndex < 0) { nStartIndex = 1; } if (iLevel > 9) { iLevel = 9; } ListLevelTable listLevelTable = levels[iLevel - 1]; ListLevel listLevel; for (j = 0; j < listLevelTable.Count; j++) { listLevel = listLevelTable.EntryAt(j); if (listLevel.Marker == marker && listLevel.StartIndex == nStartIndex) { break; } } if (j == listLevelTable.Count) { listLevel = listLevelTable.AddEntry(); listLevel.Marker = marker; listLevel.StartIndex = nStartIndex; // Remember max number of different styles used. if (listLevelTable.Count > nListStyles) { nListStyles = listLevelTable.Count; } } if (iLevel > 1) dn.FormatState.ILVL = iLevel - 1; dn.FormatState.ILS = j + 1; for (j = 0; j < openLists.Count; j++) { dnList = (DocumentNode)openLists[j]; if (dnList.FormatState.PNLVL < iLevel) { dnList.FormatState.PNLVL = iLevel; } if (dnList.FormatState.ILS == -1) { dnList.FormatState.ILS = dn.FormatState.ILS; } else if (dnList.FormatState.ILS != dn.FormatState.ILS) { dnList.FormatState.ILS = 0; } } } break; } } return nListStyles; }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ #region Constructors internal ListTableEntry() { _id = 0; _templateID = 0; _levels = new ListLevelTable(); }
// --------------------------------------------------------------------- // // Private Methods // // --------------------------------------------------------------------- #region Private Methods private void BuildListTable() { ListLevelTable[] levels = new ListLevelTable[9]; int i, j; for (i = 0; i < 9; i++) { levels[i] = new ListLevelTable(); } // Tracks current open list ArrayList openLists = new ArrayList(); // Find paragraphs in lists and build up the necessary list styles int nListStyles = BuildListStyles(levels, openLists); // Now build the actual list style and list override tables. Basic approach is that each list style has // a list override. ListOverrideTable listOverrideTable = _converterState.ListOverrideTable; for (i = 0; i < nListStyles; i++) { ListOverride listOverride = listOverrideTable.AddEntry(); listOverride.ID = i + 1; listOverride.Index = i + 1; } ListTable listTable = _converterState.ListTable; for (i = 0; i < nListStyles; i++) { ListTableEntry listTableEntry = listTable.AddEntry(); listTableEntry.ID = i + 1; ListLevelTable listLevelTable = listTableEntry.Levels; for (j = 0; j < 9; j++) { ListLevel listLevel = listLevelTable.AddEntry(); ListLevelTable lltComputed = levels[j]; if (lltComputed.Count > i) { ListLevel llComputed = lltComputed.EntryAt(i); listLevel.Marker = llComputed.Marker; listLevel.StartIndex = llComputed.StartIndex; } } } }