// Token: 0x060034B0 RID: 13488 RVA: 0x000EAA6C File Offset: 0x000E8C6C private void PreCoalesceRow(DocumentNode dn, ref bool fVMerged) { DocumentNodeArray rowsCells = dn.GetRowsCells(); RowFormat rowFormat = dn.FormatState.RowFormat; DocumentNode parentOfType = dn.GetParentOfType(DocumentNodeType.dnTable); ColumnStateArray columnStateArray = (parentOfType != null) ? parentOfType.ColumnStateArray : null; int num = (rowsCells.Count < rowFormat.CellCount) ? rowsCells.Count : rowFormat.CellCount; int i = 0; int j = 0; while (j < num) { DocumentNode documentNode = rowsCells.EntryAt(j); CellFormat cellFormat = rowFormat.NthCellFormat(j); long cellX = cellFormat.CellX; if (cellFormat.IsVMerge) { fVMerged = true; } if (cellFormat.IsHMergeFirst) { for (j++; j < num; j++) { cellFormat = rowFormat.NthCellFormat(j); if (cellFormat.IsVMerge) { fVMerged = true; } if (cellFormat.IsHMerge) { rowsCells.EntryAt(j).ColSpan = 0; } } } else { j++; } if (columnStateArray != null) { int num2 = i; while (i < columnStateArray.Count) { ColumnState columnState = columnStateArray.EntryAt(i); i++; if (columnState.CellX == cellX || columnState.CellX > cellX) { break; } } if (i - num2 > documentNode.ColSpan) { documentNode.ColSpan = i - num2; } } } }
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; } } } } }
// Helper for IXamlContentHandler.StartElement. private XamlToRtfError HandleAttributes(ConverterState converterState, IXamlAttributes attributes, DocumentNode documentNode, XamlTag xamlTag, DocumentNodeArray dna) { int nLen = 0; XamlToRtfError xamlToRtfError = attributes.GetLength(ref nLen); if (xamlToRtfError == XamlToRtfError.None) { string uri = string.Empty; string newLocalName = string.Empty; string newQName = string.Empty; string valueString = string.Empty; FormatState formatState = documentNode.FormatState; XamlAttribute attribute = XamlAttribute.XAUnknown; long valueData = 0; for (int i = 0; xamlToRtfError == XamlToRtfError.None && i < nLen; i++) { xamlToRtfError = attributes.GetName(i, ref uri, ref newLocalName, ref newQName); if (xamlToRtfError == XamlToRtfError.None) { xamlToRtfError = attributes.GetValue(i, ref valueString); if (xamlToRtfError == XamlToRtfError.None && XamlParserHelper.ConvertToAttribute(converterState, newLocalName, ref attribute)) { switch (attribute) { case XamlAttribute.XAUnknown: break; case XamlAttribute.XAFontWeight: if (string.Compare(valueString, "Normal", StringComparison.OrdinalIgnoreCase) == 0) { formatState.Bold = false; } else if (string.Compare(valueString, "Bold", StringComparison.OrdinalIgnoreCase) == 0) { formatState.Bold = true; } break; case XamlAttribute.XAFontSize: double fs = 0f; if (XamlParserHelper.ConvertToFontSize(converterState, valueString, ref fs)) { formatState.FontSize = (long)Math.Round(fs); } break; case XamlAttribute.XAFontStyle: if (string.Compare(valueString, "Italic", StringComparison.OrdinalIgnoreCase) == 0) { formatState.Italic = true; } break; case XamlAttribute.XAFontFamily: if (XamlParserHelper.ConvertToFont(converterState, valueString, ref valueData)) { formatState.Font = valueData; } break; case XamlAttribute.XAFontStretch: if (XamlParserHelper.ConvertToFontStretch(converterState, valueString, ref valueData)) { formatState.Expand = valueData; } break; case XamlAttribute.XABackground: if (XamlParserHelper.ConvertToColor(converterState, valueString, ref valueData)) { if (documentNode.IsInline) { formatState.CB = valueData; } else { formatState.CBPara = valueData; } } break; case XamlAttribute.XAForeground: if (XamlParserHelper.ConvertToColor(converterState, valueString, ref valueData)) { formatState.CF = valueData; } break; case XamlAttribute.XAFlowDirection: DirState dirState = DirState.DirDefault; if (XamlParserHelper.ConvertToDir(converterState, valueString, ref dirState)) { if (documentNode.IsInline) { formatState.DirChar = dirState; } else if (documentNode.Type == DocumentNodeType.dnTable) { formatState.RowFormat.Dir = dirState; } else { formatState.DirPara = dirState; // Set the default inline flow direction as the paragraph's flow direction formatState.DirChar = dirState; } if (documentNode.Type == DocumentNodeType.dnList) { // Reset the left/right margin for List as the default value(720) // on RTL flow direction. Actually LI is set as 720 as the default // CreateDocumentNode(). if (formatState.DirPara == DirState.DirRTL) { formatState.LI = 0; formatState.RI = 720; } } } break; case XamlAttribute.XATextDecorations: { ULState ulState = ULState.ULNormal; StrikeState strikeState = StrikeState.StrikeNormal; if (XamlParserHelper.ConvertToDecoration(converterState, valueString, ref ulState, ref strikeState)) { if (ulState != ULState.ULNone) { formatState.UL = ulState; } if (strikeState != StrikeState.StrikeNone) { formatState.Strike = strikeState; } } } break; case XamlAttribute.XALocation: { ULState ulState = ULState.ULNormal; StrikeState strikeState = StrikeState.StrikeNormal; if (XamlParserHelper.ConvertToDecoration(converterState, valueString, ref ulState, ref strikeState)) { if (ulState != ULState.ULNone) { formatState.UL = ulState; } if (strikeState != StrikeState.StrikeNone) { formatState.Strike = strikeState; } } } break; case XamlAttribute.XARowSpan: { int nRowSpan = 0; if (Converters.StringToInt(valueString, ref nRowSpan)) { if (documentNode.Type == DocumentNodeType.dnCell) { documentNode.RowSpan = nRowSpan; } } } break; case XamlAttribute.XAColumnSpan: { int nColSpan = 0; if (Converters.StringToInt(valueString, ref nColSpan)) { if (documentNode.Type == DocumentNodeType.dnCell) { documentNode.ColSpan = nColSpan; } } } break; case XamlAttribute.XACellSpacing: { double d = 0f; if (Converters.StringToDouble(valueString, ref d)) { if (documentNode.Type == DocumentNodeType.dnTable) { formatState.RowFormat.Trgaph = Converters.PxToTwipRounded(d); } } } break; case XamlAttribute.XANavigateUri: if (xamlTag == XamlTag.XTHyperlink && valueString.Length > 0) { StringBuilder sb = new StringBuilder(); XamlParserHelper.AppendRTFText(sb, valueString, 0); documentNode.NavigateUri = sb.ToString(); } break; case XamlAttribute.XAWidth: if (xamlTag == XamlTag.XTTableColumn) { double d = 0f; if (Converters.StringToDouble(valueString, ref d)) { int nTableAt = dna.FindPending(DocumentNodeType.dnTable); if (nTableAt >= 0) { DocumentNode dnTable = dna.EntryAt(nTableAt); RowFormat rf = dnTable.FormatState.RowFormat; CellFormat cf = rf.NextCellFormat(); cf.Width.Type = WidthType.WidthTwips; cf.Width.Value = Converters.PxToTwipRounded(d); } } } else if (xamlTag == XamlTag.XTImage) { double d = 0f; Converters.StringToDouble(valueString, ref d); documentNode.FormatState.ImageWidth = d; } break; case XamlAttribute.XAHeight: if (xamlTag == XamlTag.XTImage) { double d = 0f; Converters.StringToDouble(valueString, ref d); documentNode.FormatState.ImageHeight = d; } break; case XamlAttribute.XASource: if (xamlTag == XamlTag.XTImage) { documentNode.FormatState.ImageSource = valueString; } break; case XamlAttribute.XAUriSource: if (xamlTag == XamlTag.XTBitmapImage) { documentNode.FormatState.ImageSource = valueString; } break; case XamlAttribute.XAStretch: if (xamlTag == XamlTag.XTImage) { documentNode.FormatState.ImageStretch = valueString; } break; case XamlAttribute.XAStretchDirection: if (xamlTag == XamlTag.XTImage) { documentNode.FormatState.ImageStretchDirection = valueString; } break; case XamlAttribute.XATypographyVariants: RtfSuperSubscript ss = RtfSuperSubscript.None; if (XamlParserHelper.ConvertToSuperSub(converterState, valueString, ref ss)) { if (ss == RtfSuperSubscript.Super) { formatState.Super = true; } else if (ss == RtfSuperSubscript.Sub) { formatState.Sub = true; } else if (ss == RtfSuperSubscript.Normal) { formatState.Sub = false; formatState.Super = false; } } break; case XamlAttribute.XAMarkerStyle: MarkerStyle ms = MarkerStyle.MarkerBullet; if (XamlParserHelper.ConvertToMarkerStyle(converterState, valueString, ref ms)) { formatState.Marker = ms; } break; case XamlAttribute.XAStartIndex: int nStart = 0; if (XamlParserHelper.ConvertToStartIndex(converterState, valueString, ref nStart)) { formatState.StartIndex = nStart; } break; case XamlAttribute.XAMargin: { XamlThickness thickness = new XamlThickness(0f, 0f, 0f, 0f); if (XamlParserHelper.ConvertToThickness(converterState, valueString, ref thickness)) { formatState.LI = Converters.PxToTwipRounded(thickness.Left); formatState.RI = Converters.PxToTwipRounded(thickness.Right); formatState.SB = Converters.PxToTwipRounded(thickness.Top); formatState.SA = Converters.PxToTwipRounded(thickness.Bottom); } } break; case XamlAttribute.XAPadding: { XamlThickness t = new XamlThickness(0f, 0f, 0f, 0f); if (XamlParserHelper.ConvertToThickness(converterState, valueString, ref t)) { if (xamlTag == XamlTag.XTParagraph) { // RTF only supports a single border padding value. formatState.ParaBorder.Spacing = Converters.PxToTwipRounded(t.Left); } else { RowFormat rf = formatState.RowFormat; CellFormat cf = rf.RowCellFormat; cf.PaddingLeft = Converters.PxToTwipRounded(t.Left); cf.PaddingRight = Converters.PxToTwipRounded(t.Right); cf.PaddingTop = Converters.PxToTwipRounded(t.Top); cf.PaddingBottom = Converters.PxToTwipRounded(t.Bottom); } } } break; case XamlAttribute.XABorderThickness: { XamlThickness t = new XamlThickness(0f, 0f, 0f, 0f); if (XamlParserHelper.ConvertToThickness(converterState, valueString, ref t)) { if (xamlTag == XamlTag.XTParagraph) { ParaBorder pf = formatState.ParaBorder; pf.BorderLeft.Type = BorderType.BorderSingle; pf.BorderLeft.Width = Converters.PxToTwipRounded(t.Left); pf.BorderRight.Type = BorderType.BorderSingle; pf.BorderRight.Width = Converters.PxToTwipRounded(t.Right); pf.BorderTop.Type = BorderType.BorderSingle; pf.BorderTop.Width = Converters.PxToTwipRounded(t.Top); pf.BorderBottom.Type = BorderType.BorderSingle; pf.BorderBottom.Width = Converters.PxToTwipRounded(t.Bottom); } else { RowFormat rf = formatState.RowFormat; CellFormat cf = rf.RowCellFormat; cf.BorderLeft.Type = BorderType.BorderSingle; cf.BorderLeft.Width = Converters.PxToTwipRounded(t.Left); cf.BorderRight.Type = BorderType.BorderSingle; cf.BorderRight.Width = Converters.PxToTwipRounded(t.Right); cf.BorderTop.Type = BorderType.BorderSingle; cf.BorderTop.Width = Converters.PxToTwipRounded(t.Top); cf.BorderBottom.Type = BorderType.BorderSingle; cf.BorderBottom.Width = Converters.PxToTwipRounded(t.Bottom); } } } break; case XamlAttribute.XABorderBrush: if (XamlParserHelper.ConvertToColor(converterState, valueString, ref valueData)) { if (xamlTag == XamlTag.XTParagraph) { formatState.ParaBorder.CF = valueData; } else { RowFormat rf = formatState.RowFormat; CellFormat cf = rf.RowCellFormat; cf.BorderLeft.CF = valueData; cf.BorderRight.CF = valueData; cf.BorderTop.CF = valueData; cf.BorderBottom.CF = valueData; } } break; case XamlAttribute.XATextIndent: double ti = 0; if (XamlParserHelper.ConvertToTextIndent(converterState, valueString, ref ti)) { formatState.FI = Converters.PxToTwipRounded(ti); } break; case XamlAttribute.XALineHeight: double sl = 0; if (XamlParserHelper.ConvertToLineHeight(converterState, valueString, ref sl)) { formatState.SL = Converters.PxToTwipRounded(sl); formatState.SLMult = false; } break; case XamlAttribute.XALang: { try { CultureInfo ci = new CultureInfo(valueString); if (ci.LCID > 0) { // Extract LANGID from LCID formatState.Lang = (long)(ushort)ci.LCID; } } catch (System.ArgumentException) { // Just omit if this is not a legal language value } } break; case XamlAttribute.XATextAlignment: HAlign halign = HAlign.AlignDefault; if (XamlParserHelper.ConvertToHAlign(converterState, valueString, ref halign)) { formatState.HAlign = halign; } break; } } } } } return xamlToRtfError; }
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; } } }
// 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++; } } } } }