private void ProcessTableRowSpan(DocumentNodeArray dnaTables)
        {
            for (int i = 0; i < dnaTables.Count; i++)
            {
                DocumentNode dnTable = dnaTables.EntryAt(i);
                ColumnStateArray csa = dnTable.ColumnStateArray;
                if (csa == null || csa.Count == 0)
                {
                    continue;
                }
                int nDim = csa.Count;

                DocumentNodeArray dnaRows = dnTable.GetTableRows();
                DocumentNodeArray dnaSpanCells = new DocumentNodeArray();
                for (int k = 0; k < nDim; k++)
                {
                    dnaSpanCells.Add(null);
                }

                for (int j = 0; j < dnaRows.Count; j++)
                {
                    DocumentNode dnRow = dnaRows.EntryAt(j);
                    RowFormat rf = dnRow.FormatState.RowFormat;
                    DocumentNodeArray dnaCells = dnRow.GetRowsCells();
                    int nCount = nDim;
                    if (rf.CellCount < nCount)
                    {
                        nCount = rf.CellCount;
                    }
                    if (dnaCells.Count < nCount)
                    {
                        nCount = dnaCells.Count;
                    }

                    // Nominally, the index into dnaSpanCells, dnaCells and RowFormat.NthCellFormat
                    // should all be the same.  But in some cases we have spanning cells that don't
                    // actually have an explicit cell associated with it (the span is implicit in the
                    // cellx/width values).  I can detect this case by finding a colspan > 1 that is
                    // not then followed by a HMerged format.  In this case, I need to apply a correction
                    // to my iteration, since the ColumnStateArray will have an entry for that field.

                    int kCSA = 0;   // this might advance faster
                    for (int k = 0; k < nCount && kCSA < dnaSpanCells.Count; k++)
                    {
                        DocumentNode dnCell = dnaCells.EntryAt(k);
                        CellFormat cf = rf.NthCellFormat(k);
                        if (cf.IsVMerge)
                        {
                            DocumentNode dnSpanningCell = dnaSpanCells.EntryAt(kCSA);
                            if (dnSpanningCell != null)
                            {
                                dnSpanningCell.RowSpan = dnSpanningCell.RowSpan + 1;
                            }
                            kCSA += dnCell.ColSpan;
                            dnCell.ColSpan = 0;
                        }
                        else
                        {
                            if (cf.IsVMergeFirst)
                            {
                                dnCell.RowSpan = 1;
                                dnaSpanCells[kCSA] = dnCell;
                            }
                            else
                            {
                                dnaSpanCells[kCSA] = null;
                            }
                            for (int l = kCSA + 1; l < kCSA + dnCell.ColSpan; l++)
                            {
                                dnaSpanCells[l] = null;
                            }
                            kCSA += dnCell.ColSpan;
                        }
                    }
                }
            }
        }
        internal void PreCoalesceChildren(ConverterState converterState, int nStart, bool bChild)
        {
            // We process tables twice to handle first colspan, then rowspan
            DocumentNodeArray dnaTables = new DocumentNodeArray();
            bool fVMerged = false;

            // Try to move paragraph margin to containing list items
            DocumentNode dnCoalesce = EntryAt(nStart);
            int nChild = dnCoalesce.ChildCount;
            Debug.Assert(nStart + nChild < Count);
            if (nStart + nChild >= Count)
            {
                nChild = Count - nStart - 1;
            }

            int nEnd = nStart + nChild;

            // If bChild specified, we don't process parent
            if (bChild)
            {
                nStart++;
            }

            // This is vaguely N^2 in the sense that for each list item, I process all containing paragraphs,
            // including ones contained in other list items.  But it's only a problem for very deep, very long
            // lists, so we can live with it.
            for (int nAt = nStart; nAt <= nEnd; nAt++)
            {
                DocumentNode dn = EntryAt(nAt);

                // Inline direction merging
                if (dn.IsInline && dn.RequiresXamlDir && dn.ClosedParent != null)
                {
                    int nnAt = nAt + 1;
                    for (; nnAt <= nEnd; nnAt++)
                    {
                        DocumentNode dnn = EntryAt(nnAt);

                        if (!dnn.IsInline
                            || dnn.Type == DocumentNodeType.dnHyperlink
                            || dnn.FormatState.DirChar != dn.FormatState.DirChar
                            || dnn.ClosedParent != dn.ClosedParent)
                        {
                            break;
                        }
                    }

                    int nChildHere = nnAt - nAt;
                    if (nChildHere > 1)
                    {

                        DocumentNode dnNewDir = new DocumentNode(DocumentNodeType.dnInline);
                        dnNewDir.FormatState = new FormatState(dn.Parent.FormatState);
                        dnNewDir.FormatState.DirChar = dn.FormatState.DirChar;

                        InsertChildAt(dn.ClosedParent, dnNewDir, nAt, nChildHere);

                        // Adjust the loop end to account for the newly inserted element
                        nEnd += 1;
                    }
                }

                else if (dn.Type == DocumentNodeType.dnListItem)
                {
                    PreCoalesceListItem(dn);
                }

                else if (dn.Type == DocumentNodeType.dnList)
                {
                    PreCoalesceList(dn);
                }

                else if (dn.Type == DocumentNodeType.dnTable)
                {
                    dnaTables.Add(dn);
                    nEnd += PreCoalesceTable(dn);
                }

                // Compute colspan
                else if (dn.Type == DocumentNodeType.dnRow)
                {
                    PreCoalesceRow(dn, ref fVMerged);
                }
            }

            // Process tables to examine rowspan
            if (fVMerged)
            {
                ProcessTableRowSpan(dnaTables);
            }
        }
Пример #3
0
 // Token: 0x060034B1 RID: 13489 RVA: 0x000EABA4 File Offset: 0x000E8DA4
 private void ProcessTableRowSpan(DocumentNodeArray dnaTables)
 {
     for (int i = 0; i < dnaTables.Count; i++)
     {
         DocumentNode     documentNode     = dnaTables.EntryAt(i);
         ColumnStateArray columnStateArray = documentNode.ColumnStateArray;
         if (columnStateArray != null && columnStateArray.Count != 0)
         {
             int count = columnStateArray.Count;
             DocumentNodeArray tableRows         = documentNode.GetTableRows();
             DocumentNodeArray documentNodeArray = new DocumentNodeArray();
             for (int j = 0; j < count; j++)
             {
                 documentNodeArray.Add(null);
             }
             for (int k = 0; k < tableRows.Count; k++)
             {
                 DocumentNode      documentNode2 = tableRows.EntryAt(k);
                 RowFormat         rowFormat     = documentNode2.FormatState.RowFormat;
                 DocumentNodeArray rowsCells     = documentNode2.GetRowsCells();
                 int num = count;
                 if (rowFormat.CellCount < num)
                 {
                     num = rowFormat.CellCount;
                 }
                 if (rowsCells.Count < num)
                 {
                     num = rowsCells.Count;
                 }
                 int num2 = 0;
                 int num3 = 0;
                 while (num3 < num && num2 < documentNodeArray.Count)
                 {
                     DocumentNode documentNode3 = rowsCells.EntryAt(num3);
                     CellFormat   cellFormat    = rowFormat.NthCellFormat(num3);
                     if (cellFormat.IsVMerge)
                     {
                         DocumentNode documentNode4 = documentNodeArray.EntryAt(num2);
                         if (documentNode4 != null)
                         {
                             documentNode4.RowSpan++;
                         }
                         num2 += documentNode3.ColSpan;
                         documentNode3.ColSpan = 0;
                     }
                     else
                     {
                         if (cellFormat.IsVMergeFirst)
                         {
                             documentNode3.RowSpan   = 1;
                             documentNodeArray[num2] = documentNode3;
                         }
                         else
                         {
                             documentNodeArray[num2] = null;
                         }
                         for (int l = num2 + 1; l < num2 + documentNode3.ColSpan; l++)
                         {
                             documentNodeArray[l] = null;
                         }
                         num2 += documentNode3.ColSpan;
                     }
                     num3++;
                 }
             }
         }
     }
 }
Пример #4
0
        private void PatchVerticallyMergedCells(DocumentNode dnThis) 
        {
            DocumentNodeArray dna = _converterState.DocumentNodeArray; 
            DocumentNodeArray dnaRows = dnThis.GetTableRows(); 
            DocumentNodeArray dnaSpanCells = new DocumentNodeArray();
            ArrayList spanCounts = new ArrayList(); 
            int nCol = 0;
            int nColExtra = 0;

            for (int i = 0; i < dnaRows.Count; i++) 
            {
                DocumentNode dnRow = dnaRows.EntryAt(i); 
 
                DocumentNodeArray dnaCells = dnRow.GetRowsCells();
                int nColHere = 0; 
                for (int j = 0; j < dnaCells.Count; j++)
                {
                    DocumentNode dnCell = dnaCells.EntryAt(j);
 
                    // Insert vmerged cell placeholder if necessary
                    nColExtra = nColHere; 
                    while (nColExtra < spanCounts.Count && ((int)spanCounts[nColExtra]) > 0) 
                    {
                        DocumentNode dnSpanningCell = dnaSpanCells.EntryAt(nColExtra); 
                        DocumentNode dnNew = new DocumentNode(DocumentNodeType.dnCell);
                        dna.InsertChildAt(dnRow, dnNew, dnCell.Index, 0);
                        dnNew.FormatState = new FormatState(dnSpanningCell.FormatState);
                        if (dnSpanningCell.FormatState.HasRowFormat) 
                        {
                            dnNew.FormatState.RowFormat = new RowFormat(dnSpanningCell.FormatState.RowFormat); 
                        } 
                        dnNew.FormatState.RowFormat.RowCellFormat.IsVMergeFirst = false;
                        dnNew.FormatState.RowFormat.RowCellFormat.IsVMerge = true; 
                        dnNew.ColSpan = dnSpanningCell.ColSpan;
                        nColExtra += dnNew.ColSpan;
                    }
 
                    // Take care of any cells hanging down from above.
                    while (nColHere < spanCounts.Count && ((int)spanCounts[nColHere]) > 0) 
                    { 
                        // Update span count for this row
                        spanCounts[nColHere] = ((int)spanCounts[nColHere]) - 1; 
                        if ((int)spanCounts[nColHere] == 0)
                        {
                            dnaSpanCells[nColHere] = null;
                        } 
                        nColHere++;
                    } 
 
                    // Now update colHere and spanCounts
                    for (int k = 0; k < dnCell.ColSpan; k++) 
                    {
                        if (nColHere < spanCounts.Count)
                        {
                            spanCounts[nColHere] = dnCell.RowSpan - 1; 
                            dnaSpanCells[nColHere] = (dnCell.RowSpan > 1) ? dnCell : null;
                        } 
                        else 
                        {
                            spanCounts.Add(dnCell.RowSpan - 1); 
                            dnaSpanCells.Add((dnCell.RowSpan > 1) ? dnCell : null);
                        }
                        nColHere++;
                    } 

                    // Mark this cell as first in vmerged list if necessary 
                    if (dnCell.RowSpan > 1) 
                    {
                        CellFormat cf = dnCell.FormatState.RowFormat.RowCellFormat; 

                        cf.IsVMergeFirst = true;
                    }
                } 

                // Insert vmerged cell placeholder if necessary 
                nColExtra = nColHere; 
                while (nColExtra < spanCounts.Count)
                { 
                    if (((int)spanCounts[nColExtra]) > 0)
                    {
                        // Insert vmerged cell here.
                        DocumentNode dnSpanningCell = dnaSpanCells.EntryAt(nColExtra); 
                        DocumentNode dnNew = new DocumentNode(DocumentNodeType.dnCell);
                        dna.InsertChildAt(dnRow, dnNew, dnRow.Index + dnRow.ChildCount + 1, 0); 
                        dnNew.FormatState = new FormatState(dnSpanningCell.FormatState); 
                        if (dnSpanningCell.FormatState.HasRowFormat)
                        { 
                            dnNew.FormatState.RowFormat = new RowFormat(dnSpanningCell.FormatState.RowFormat);
                        }
                        dnNew.FormatState.RowFormat.RowCellFormat.IsVMergeFirst = false;
                        dnNew.FormatState.RowFormat.RowCellFormat.IsVMerge = true; 
                        dnNew.ColSpan = dnSpanningCell.ColSpan;
                        nColExtra += dnNew.ColSpan; 
                    } 
                    else
                    { 
                        nColExtra++;
                    }
                }
 
                // Take care of remaining cells hanging down.
                while (nColHere < spanCounts.Count) 
                { 
                    if (((int)spanCounts[nColHere]) > 0)
                    { 
                        spanCounts[nColHere] = ((int)spanCounts[nColHere]) - 1;
                        if ((int)spanCounts[nColHere] == 0)
                        {
                            dnaSpanCells[nColHere] = null; 
                        }
                    } 
                    nColHere++; 
                }
 
                // Track max
                if (nColHere > nCol)
                {
                    nCol = nColHere; 
                }
            } 
        } 
Пример #5
0
        // Token: 0x06003490 RID: 13456 RVA: 0x000E997C File Offset: 0x000E7B7C
        internal void PreCoalesceChildren(ConverterState converterState, int nStart, bool bChild)
        {
            DocumentNodeArray documentNodeArray = new DocumentNodeArray();
            bool         flag         = false;
            DocumentNode documentNode = this.EntryAt(nStart);
            int          num          = documentNode.ChildCount;

            if (nStart + num >= this.Count)
            {
                num = this.Count - nStart - 1;
            }
            int num2 = nStart + num;

            if (bChild)
            {
                nStart++;
            }
            for (int i = nStart; i <= num2; i++)
            {
                DocumentNode documentNode2 = this.EntryAt(i);
                if (documentNode2.IsInline && documentNode2.RequiresXamlDir && documentNode2.ClosedParent != null)
                {
                    int j;
                    for (j = i + 1; j <= num2; j++)
                    {
                        DocumentNode documentNode3 = this.EntryAt(j);
                        if (!documentNode3.IsInline || documentNode3.Type == DocumentNodeType.dnHyperlink || documentNode3.FormatState.DirChar != documentNode2.FormatState.DirChar || documentNode3.ClosedParent != documentNode2.ClosedParent)
                        {
                            break;
                        }
                    }
                    int num3 = j - i;
                    if (num3 > 1)
                    {
                        DocumentNode documentNode4 = new DocumentNode(DocumentNodeType.dnInline);
                        documentNode4.FormatState         = new FormatState(documentNode2.Parent.FormatState);
                        documentNode4.FormatState.DirChar = documentNode2.FormatState.DirChar;
                        this.InsertChildAt(documentNode2.ClosedParent, documentNode4, i, num3);
                        num2++;
                    }
                }
                else if (documentNode2.Type == DocumentNodeType.dnListItem)
                {
                    this.PreCoalesceListItem(documentNode2);
                }
                else if (documentNode2.Type == DocumentNodeType.dnList)
                {
                    this.PreCoalesceList(documentNode2);
                }
                else if (documentNode2.Type == DocumentNodeType.dnTable)
                {
                    documentNodeArray.Add(documentNode2);
                    num2 += this.PreCoalesceTable(documentNode2);
                }
                else if (documentNode2.Type == DocumentNodeType.dnRow)
                {
                    this.PreCoalesceRow(documentNode2, ref flag);
                }
            }
            if (flag)
            {
                this.ProcessTableRowSpan(documentNodeArray);
            }
        }