// Token: 0x06003493 RID: 13459 RVA: 0x000E9D64 File Offset: 0x000E7F64 internal void CoalesceAll(ConverterState converterState) { for (int i = 0; i < this.Count; i++) { this.CoalesceChildren(converterState, i); } }
// Token: 0x060033B9 RID: 13241 RVA: 0x000E696C File Offset: 0x000E4B6C internal string GetBorderAttributeString(ConverterState converterState) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(" BorderThickness=\""); stringBuilder.Append(Converters.TwipToPositiveVisiblePxString((double)this.BorderLeft.EffectiveWidth)); stringBuilder.Append(","); stringBuilder.Append(Converters.TwipToPositiveVisiblePxString((double)this.BorderTop.EffectiveWidth)); stringBuilder.Append(","); stringBuilder.Append(Converters.TwipToPositiveVisiblePxString((double)this.BorderRight.EffectiveWidth)); stringBuilder.Append(","); stringBuilder.Append(Converters.TwipToPositiveVisiblePxString((double)this.BorderBottom.EffectiveWidth)); stringBuilder.Append("\""); ColorTableEntry colorTableEntry = null; if (this.BorderLeft.CF >= 0L) { colorTableEntry = converterState.ColorTable.EntryAt((int)this.BorderLeft.CF); } if (colorTableEntry != null) { stringBuilder.Append(" BorderBrush=\""); stringBuilder.Append(colorTableEntry.Color.ToString(CultureInfo.InvariantCulture)); stringBuilder.Append("\""); } else { stringBuilder.Append(" BorderBrush=\"#FF000000\""); } return(stringBuilder.ToString()); }
// Token: 0x060032E1 RID: 13025 RVA: 0x000E5876 File Offset: 0x000E3A76 internal string GetBorderAttributeString(ConverterState converterState) { if (this.HasParaBorder) { return(this.ParaBorder.GetBorderAttributeString(converterState)); } return(string.Empty); }
// Token: 0x0600337C RID: 13180 RVA: 0x000E60E4 File Offset: 0x000E42E4 internal string GetBorderAttributeString(ConverterState converterState) { if (this.IsNone) { return(string.Empty); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(" BorderThickness=\""); if (!this.BorderAll.IsNone) { stringBuilder.Append(Converters.TwipToPositiveVisiblePxString((double)this.BorderAll.EffectiveWidth)); } else { stringBuilder.Append(Converters.TwipToPositiveVisiblePxString((double)this.BorderLeft.EffectiveWidth)); stringBuilder.Append(","); stringBuilder.Append(Converters.TwipToPositiveVisiblePxString((double)this.BorderTop.EffectiveWidth)); stringBuilder.Append(","); stringBuilder.Append(Converters.TwipToPositiveVisiblePxString((double)this.BorderRight.EffectiveWidth)); stringBuilder.Append(","); stringBuilder.Append(Converters.TwipToPositiveVisiblePxString((double)this.BorderBottom.EffectiveWidth)); } stringBuilder.Append("\""); ColorTableEntry colorTableEntry = null; if (this.CF >= 0L) { colorTableEntry = converterState.ColorTable.EntryAt((int)this.CF); } if (colorTableEntry != null) { stringBuilder.Append(" BorderBrush=\""); stringBuilder.Append(colorTableEntry.Color.ToString()); stringBuilder.Append("\""); } else { stringBuilder.Append(" BorderBrush=\"#FF000000\""); } if (this.Spacing != 0L) { stringBuilder.Append(" Padding=\""); stringBuilder.Append(Converters.TwipToPositivePxString((double)this.Spacing)); stringBuilder.Append("\""); } return(stringBuilder.ToString()); }
// Token: 0x06003492 RID: 13458 RVA: 0x000E9C4C File Offset: 0x000E7E4C internal void CoalesceOnlyChildren(ConverterState converterState, int nStart) { if (nStart >= this.Count || nStart < 0) { return; } this.PreCoalesceChildren(converterState, nStart, true); DocumentNode documentNode = this.EntryAt(nStart); int num = documentNode.ChildCount; if (nStart + num >= this.Count) { num = this.Count - nStart - 1; } int num2 = nStart + num; for (int i = num2; i >= nStart; i--) { DocumentNode documentNode2 = this.EntryAt(i); if (documentNode2.ChildCount == 0 && i != nStart) { documentNode2.Terminate(converterState); } else if (documentNode2.ChildCount > 0) { if (i != nStart) { documentNode2.AppendXamlPrefix(converterState); } StringBuilder stringBuilder = new StringBuilder(documentNode2.Xaml); int childCount = documentNode2.ChildCount; int num3 = i + childCount; for (int j = i + 1; j <= num3; j++) { DocumentNode documentNode3 = this.EntryAt(j); stringBuilder.Append(documentNode3.Xaml); } documentNode2.Xaml = stringBuilder.ToString(); if (i != nStart) { documentNode2.AppendXamlPostfix(converterState); documentNode2.IsTerminated = true; } this.Excise(i + 1, childCount); num2 -= childCount; } } }
//----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors /// <summary> /// /// </summary> internal XamlToRtfWriter(string xaml) { _xaml = xaml; _rtfBuilder = new StringBuilder(); _xamlIn = new XamlIn(this, xaml); _converterState = new ConverterState(); // Initialize the reader state with necessary colors and fonts for defaults ColorTable colorTable = _converterState.ColorTable; colorTable.AddColor(Color.FromArgb(0xff, 0, 0, 0)); colorTable.AddColor(Color.FromArgb(0xff, 0xff, 0xff, 0xff)); FontTable fontTable = _converterState.FontTable; FontTableEntry fontTableEntry = fontTable.DefineEntry(0); fontTableEntry.Name = "Times New Roman"; fontTableEntry.ComputePreferredCodePage(); }
// Token: 0x060032D0 RID: 13008 RVA: 0x000E4988 File Offset: 0x000E2B88 internal static bool ColorToUse(ConverterState converterState, long cb, long cf, long shade, ref Color c) { ColorTableEntry colorTableEntry = (cb >= 0L) ? converterState.ColorTable.EntryAt((int)cb) : null; ColorTableEntry colorTableEntry2 = (cf >= 0L) ? converterState.ColorTable.EntryAt((int)cf) : null; if (shade < 0L) { if (colorTableEntry == null) { return(false); } c = colorTableEntry.Color; return(true); } else { Color color = (colorTableEntry != null) ? colorTableEntry.Color : Color.FromArgb(byte.MaxValue, 0, 0, 0); Color color2 = (colorTableEntry2 != null) ? colorTableEntry2.Color : Color.FromArgb(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue); if (colorTableEntry2 == null && colorTableEntry == null) { c = Color.FromArgb(byte.MaxValue, (byte)(255L - 255L * shade / 10000L), (byte)(255L - 255L * shade / 10000L), (byte)(255L - 255L * shade / 10000L)); return(true); } if (colorTableEntry == null) { c = Color.FromArgb(byte.MaxValue, (byte)((ulong)color2.R + (ulong)((long)(byte.MaxValue - color2.R) * (10000L - shade) / 10000L)), (byte)((ulong)color2.G + (ulong)((long)(byte.MaxValue - color2.G) * (10000L - shade) / 10000L)), (byte)((ulong)color2.B + (ulong)((long)(byte.MaxValue - color2.B) * (10000L - shade) / 10000L))); return(true); } if (colorTableEntry2 == null) { c = Color.FromArgb(byte.MaxValue, (byte)((ulong)color.R - (ulong)color.R * (ulong)shade / 10000UL), (byte)((ulong)color.G - (ulong)color.G * (ulong)shade / 10000UL), (byte)((ulong)color.B - (ulong)color.B * (ulong)shade / 10000UL)); return(true); } c = Color.FromArgb(byte.MaxValue, (byte)((ulong)color.R * (ulong)(10000L - shade) / 10000UL + (ulong)color2.R * (ulong)shade / 10000UL), (byte)((ulong)color.G * (ulong)(10000L - shade) / 10000UL + (ulong)color2.G * (ulong)shade / 10000UL), (byte)((ulong)color.B * (ulong)(10000L - shade) / 10000UL + (ulong)color2.B * (ulong)shade / 10000UL)); return(true); } }
internal static bool ConvertToColor(ConverterState converterState, string brush, ref long colorIndex) { if (brush.Length == 0) { return false; } ColorTable colorTable = converterState.ColorTable; // Hex? if (brush[0] == '#') { // Move past # symbol int brushStringIndex = 1; // Now gather RGB uint colorValue = 0; for (; brushStringIndex < brush.Length && brushStringIndex < 9; brushStringIndex++) { char colorChar = brush[brushStringIndex]; if (colorChar >= '0' && colorChar <= '9') { colorValue = (uint)((colorValue << 4) + (colorChar - '0')); } else if (colorChar >= 'A' && colorChar <= 'F') { colorValue = (uint)((colorValue << 4) + (colorChar - 'A' + 10)); } else if (colorChar >= 'a' && colorChar <= 'f') { colorValue = (uint)((colorValue << 4) + (colorChar - 'a' + 10)); } else { break; } } // Computation above actually has r and b flipped. Color color = Color.FromRgb((byte)((colorValue & 0x00ff0000) >> 16), (byte)((colorValue & 0x0000ff00) >> 8), (byte)(colorValue & 0x000000ff)); colorIndex = colorTable.AddColor(color); return colorIndex >= 0; // -1 indicates failure, otherwise 0-based offset into colortable. } else { try { Color color = (Color)ColorConverter.ConvertFromString(brush); colorIndex = colorTable.AddColor(color); return colorIndex >= 0; // -1 indicates failure, otherwise 0-based offset into colortable. } catch (System.NotSupportedException) { return false; } catch (System.FormatException) { return false; } } }
internal static bool ConvertToFont(ConverterState converterState, string attributeName, ref long fontIndex) { if (attributeName.Length == 0) { return false; } FontTable fontTable = converterState.FontTable; FontTableEntry fontTableEntry = fontTable.FindEntryByName(attributeName); if (fontTableEntry == null) { fontTableEntry = fontTable.DefineEntry(fontTable.Count + 1); if (fontTableEntry != null) { fontTableEntry.Name = attributeName; fontTableEntry.ComputePreferredCodePage(); } } if (fontTableEntry == null) { return false; } fontIndex = fontTableEntry.Index; return true; }
// 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); } }
internal void CoalesceOnlyChildren(ConverterState converterState, int nStart) { Debug.Assert(Count == 0 || (nStart >= 0 && nStart < Count)); if (nStart >= Count || nStart < 0) { return; } // Do some fixups to match semantics for more complicated constructs PreCoalesceChildren(converterState, nStart, true); 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; for (int nAt = nEnd; nAt >= nStart; nAt--) { DocumentNode dn = EntryAt(nAt); if (dn.ChildCount == 0 && nAt != nStart) { dn.Terminate(converterState); } else if (dn.ChildCount > 0) { Debug.Assert(nAt + dn.ChildCount <= nEnd); Debug.Assert(!dn.IsTerminated); if (nAt != nStart) { dn.AppendXamlPrefix(converterState); } StringBuilder xamlBuilder = new StringBuilder(dn.Xaml); int nChildrenHere = dn.ChildCount; int nEndHere = nAt + nChildrenHere; for (int i = nAt + 1; i <= nEndHere; i++) { DocumentNode dnChild = EntryAt(i); Debug.Assert(dnChild.ChildCount == 0 && dnChild.IsTerminated); xamlBuilder.Append(dnChild.Xaml); } dn.Xaml = xamlBuilder.ToString(); if (nAt != nStart) { dn.AppendXamlPostfix(converterState); dn.IsTerminated = true; } Excise(nAt + 1, nChildrenHere); nEnd -= nChildrenHere; } } }
private void Initialize() { _lexer = new RtfToXamlLexer(_rtfBytes); _converterState = new ConverterState(); _converterState.RtfFormatStack.Push(); _outerXamlBuilder = new StringBuilder(); }
internal void AppendXamlPostfix(ConverterState converterState) { if (IsHidden) { return; } // Empty tag terminated above if (IsEmptyNode) { return; } if (Type == DocumentNodeType.dnImage) { // Append image xaml postfix AppendImageXamlPostfix(); return; } if (Type == DocumentNodeType.dnText || Type == DocumentNodeType.dnInline) { AppendInlineXamlPostfix(converterState); return; } StringBuilder xamlStringBuilder = new StringBuilder(Xaml); xamlStringBuilder.Append("</"); xamlStringBuilder.Append(GetTagName()); xamlStringBuilder.Append(">"); if (IsBlock) { xamlStringBuilder.Append("\r\n"); } Xaml = xamlStringBuilder.ToString(); }
internal void AppendInlineXamlPostfix(ConverterState converterState) { StringBuilder xamlStringBuilder = new StringBuilder(Xaml); xamlStringBuilder.Append("</Span>"); Xaml = xamlStringBuilder.ToString(); }
internal void AppendXamlFontProperties(ConverterState converterState, StringBuilder sb) { FormatState fsThis = FormatState; FormatState fsParent = ParentFormatStateForFont; bool bStrike = fsThis.Strike != fsParent.Strike; bool bUL = fsThis.UL != fsParent.UL; if (bStrike || bUL) { sb.Append(" TextDecorations=\""); if (bUL) { sb.Append("Underline"); } if (bUL && bStrike) { sb.Append(", "); } if (bStrike) { sb.Append("Strikethrough"); } sb.Append("\""); } if (fsThis.Font != fsParent.Font && fsThis.Font >= 0) { FontTableEntry entry = converterState.FontTable.FindEntryByIndex((int)fsThis.Font); if (entry != null && entry.Name != null && !(entry.Name.Equals(string.Empty))) { sb.Append(" FontFamily=\""); // FontFamily should be limited with LF_FACESIZE(32) characters, // because GDI doesn't support fonts that have the name with more than // LF_FACESIZE characters. if (entry.Name.Length > 32) { sb.Append(entry.Name, 0, 32); } else { sb.Append(entry.Name); } sb.Append("\""); } } if (fsThis.FontSize != fsParent.FontSize && fsThis.FontSize >= 0) { sb.Append(" FontSize=\""); double fs = (double)fsThis.FontSize; if (fs <= 1f) { fs = 2f; } sb.Append((fs / 2).ToString(CultureInfo.InvariantCulture)); sb.Append("pt\""); } if (fsThis.Bold != fsParent.Bold) { if (fsThis.Bold) { sb.Append(" FontWeight=\"Bold\""); } else { sb.Append(" FontWeight=\"Normal\""); } } if (fsThis.Italic != fsParent.Italic) { if (fsThis.Italic) { sb.Append(" FontStyle=\"Italic\""); } else { sb.Append(" FontStyle=\"Normal\""); } } if (fsThis.CF != fsParent.CF) { ColorTableEntry entry = converterState.ColorTable.EntryAt((int)fsThis.CF); if (entry != null && !entry.IsAuto) { sb.Append(" Foreground=\""); sb.Append(entry.Color.ToString()); sb.Append("\""); } } // NB: 0x400 (1024) is reserved value for "lidNoProof" - not a real language code. if (fsThis.LangCur != fsParent.LangCur && fsThis.LangCur > 0 && fsThis.LangCur != 0x400) { try { CultureInfo ci = new CultureInfo((int)fsThis.LangCur); sb.Append(" xml:lang=\""); sb.Append(ci.Name); sb.Append("\""); } catch (System.ArgumentException) { // Just omit xml:lang tag if this is not a valid value. } } }
private void AppendXamlPrefixCellProperties(StringBuilder xamlStringBuilder, DocumentNodeArray dna, ConverterState converterState) { Color cToUse = Color.FromArgb(0xff, 0, 0, 0); // Row stores cell properties. DocumentNode dnRow = GetParentOfType(DocumentNodeType.dnRow); Debug.Assert(dnRow != null); // Need row Debug.Assert(dnRow != null && !dnRow.IsPending); // Row props attached when row is closed Debug.Assert(dnRow != null && dnRow.FormatState.RowFormat != null); if (dnRow != null && dnRow.FormatState.HasRowFormat) { int nCol = GetCellColumn(); CellFormat cf = dnRow.FormatState.RowFormat.NthCellFormat(nCol); if (Converters.ColorToUse(converterState, cf.CB, cf.CF, cf.Shading, ref cToUse)) { xamlStringBuilder.Append(" Background=\""); xamlStringBuilder.Append(cToUse.ToString(CultureInfo.InvariantCulture)); xamlStringBuilder.Append("\""); } if (cf.HasBorder) { xamlStringBuilder.Append(cf.GetBorderAttributeString(converterState)); } xamlStringBuilder.Append(cf.GetPaddingAttributeString()); } else xamlStringBuilder.Append(" BorderBrush=\"#FF000000\" BorderThickness=\"1,1,1,1\""); if (ColSpan > 1) { xamlStringBuilder.Append(" ColumnSpan=\""); xamlStringBuilder.Append(ColSpan.ToString(CultureInfo.InvariantCulture)); xamlStringBuilder.Append("\""); } if (RowSpan > 1) { xamlStringBuilder.Append(" RowSpan=\""); xamlStringBuilder.Append(RowSpan.ToString(CultureInfo.InvariantCulture)); xamlStringBuilder.Append("\""); } }
// Convert FG, BG and shading to produce color to fill with. // Shading is in 100'ths of a percent (ie, 10000 is 100%) // A value of zero for shading means use all CB. // A value of 10000 for shading means use all CF. // Intermediate values mean some combination of internal static bool ColorToUse(ConverterState converterState, long cb, long cf, long shade, ref Color c) { ColorTableEntry entryCB = cb >= 0 ? converterState.ColorTable.EntryAt((int)cb) : null; ColorTableEntry entryCF = cf >= 0 ? converterState.ColorTable.EntryAt((int)cf) : null; // No shading if (shade < 0) { if (entryCB == null) { return false; } else { c = entryCB.Color; return true; } } // Shading else { Color cCB = entryCB != null ? entryCB.Color : Color.FromArgb(0xFF, 0, 0, 0); Color cCF = entryCF != null ? entryCF.Color : Color.FromArgb(0xFF, 255, 255, 255); // No color specifies means shading is treated as a grey intensity. if (entryCF == null && entryCB == null) { c = Color.FromArgb(0xff, (byte)(255 - (255 * shade / 10000)), (byte)(255 - (255 * shade / 10000)), (byte)(255 - (255 * shade / 10000))); return true; } // Only CF means CF fades as shading goes from 10,000 to 0 else if (entryCB == null) { c = Color.FromArgb(0xff, (byte)(cCF.R + ((255 - cCF.R) * (10000 - shade) / 10000)), (byte)(cCF.G + ((255 - cCF.G) * (10000 - shade) / 10000)), (byte)(cCF.B + ((255 - cCF.B) * (10000 - shade) / 10000))); return true; } // Only CB means CB gets larger impact (from black ) as shading goes from 10000 to 0 else if (entryCF == null) { c = Color.FromArgb(0xff, (byte)(cCB.R - (cCB.R * shade / 10000)), (byte)(cCB.G - (cCB.G * shade / 10000)), (byte)(cCB.B - (cCB.B * shade / 10000))); return true; } // Both - need to mix colors else { c = Color.FromArgb(0xff, (byte)((cCB.R * (10000 - shade) / 10000) + (cCF.R * shade / 10000)), (byte)((cCB.G * (10000 - shade) / 10000) + (cCF.G * shade / 10000)), (byte)((cCB.B * (10000 - shade) / 10000) + (cCF.B * shade / 10000))); return true; } } }
internal string GetBorderAttributeString(ConverterState converterState) { if (IsNone) { return string.Empty; } // Build the border attribute string based on border values StringBuilder sb = new StringBuilder(); // Left,Top,Right,Bottom sb.Append(" BorderThickness=\""); if (!BorderAll.IsNone) { sb.Append(Converters.TwipToPositiveVisiblePxString(BorderAll.EffectiveWidth)); } else { sb.Append(Converters.TwipToPositiveVisiblePxString(BorderLeft.EffectiveWidth)); sb.Append(","); sb.Append(Converters.TwipToPositiveVisiblePxString(BorderTop.EffectiveWidth)); sb.Append(","); sb.Append(Converters.TwipToPositiveVisiblePxString(BorderRight.EffectiveWidth)); sb.Append(","); sb.Append(Converters.TwipToPositiveVisiblePxString(BorderBottom.EffectiveWidth)); } sb.Append("\""); ColorTableEntry entry = null; if (CF >= 0) { entry = converterState.ColorTable.EntryAt((int)CF); } if (entry != null) { sb.Append(" BorderBrush=\""); sb.Append(entry.Color.ToString()); sb.Append("\""); } else { sb.Append(" BorderBrush=\"#FF000000\""); } if (Spacing != 0) { sb.Append(" Padding=\""); sb.Append(Converters.TwipToPositivePxString(Spacing)); sb.Append("\""); } return sb.ToString(); }
internal static bool ConvertToLineHeight(ConverterState converterState, string s, ref double d) { return Converters.StringToDouble(s, ref d); }
internal static bool ConvertToTextIndent(ConverterState converterState, string s, ref double d) { return Converters.StringToDouble(s, ref d); }
internal static bool ConvertToFontSize(ConverterState converterState, string s, ref double d) { if (s.Length == 0) { return false; } // Peel trailing units int n = s.Length - 1; while (n >= 0 && (s[n] < '0' || s[n] > '9') && s[n] != '.') { n--; } string units = null; if (n < s.Length - 1) { units = s.Substring(n + 1); s = s.Substring(0, n + 1); } // Now convert number part bool ret = Converters.StringToDouble(s, ref d); if (ret) { // No units mean pixels if (units == null || units.Length == 0) { d = Converters.PxToPt(d); } // else // Otherwise assume points - no conversion necessary. // Convert to half-points used by RTF d *= 2; } return ret && d > 0; }
internal string GetBorderAttributeString(ConverterState converterState) { Debug.Assert(HasBorder); // Build the border attribute string based on border values StringBuilder sb = new StringBuilder(); // Left,Top,Right,Bottom sb.Append(" BorderThickness=\""); sb.Append(Converters.TwipToPositiveVisiblePxString(BorderLeft.EffectiveWidth)); sb.Append(","); sb.Append(Converters.TwipToPositiveVisiblePxString(BorderTop.EffectiveWidth)); sb.Append(","); sb.Append(Converters.TwipToPositiveVisiblePxString(BorderRight.EffectiveWidth)); sb.Append(","); sb.Append(Converters.TwipToPositiveVisiblePxString(BorderBottom.EffectiveWidth)); sb.Append("\""); // Only grab one color ColorTableEntry entry = null; if (BorderLeft.CF >= 0) { entry = converterState.ColorTable.EntryAt((int)BorderLeft.CF); } if (entry != null) { sb.Append(" BorderBrush=\""); sb.Append(entry.Color.ToString(CultureInfo.InvariantCulture)); sb.Append("\""); } else { sb.Append(" BorderBrush=\"#FF000000\""); } return sb.ToString(); }
internal static bool ConvertToDecoration( ConverterState converterState, string decoration, ref ULState ulState, ref StrikeState strikeState ) { ulState = ULState.ULNone; strikeState = StrikeState.StrikeNone; if (decoration.IndexOf("Underline", StringComparison.OrdinalIgnoreCase) != -1) { ulState = ULState.ULNormal; } if (decoration.IndexOf("Strikethrough", StringComparison.OrdinalIgnoreCase) != -1) { strikeState = StrikeState.StrikeNormal; } return ulState != ULState.ULNone || strikeState != StrikeState.StrikeNone; }
internal void Terminate(ConverterState converterState) { if (!IsTerminated) { string plaintext = StripInvalidChars(Xaml); AppendXamlPrefix(converterState); StringBuilder xamlBuilder = new StringBuilder(Xaml); xamlBuilder.Append(plaintext); Xaml = xamlBuilder.ToString(); AppendXamlPostfix(converterState); IsTerminated = true; } }
internal static bool ConvertToDir(ConverterState converterState, string dirName, ref DirState dirState) { if (dirName.Length == 0) return false; if (string.Compare("RightToLeft", dirName, StringComparison.OrdinalIgnoreCase) == 0) { dirState = DirState.DirRTL; return true; } else if (string.Compare("LeftToRight", dirName, StringComparison.OrdinalIgnoreCase) == 0) { dirState = DirState.DirLTR; return true; } return false; }
internal void AppendXamlPrefix(ConverterState converterState) { DocumentNodeArray dna = converterState.DocumentNodeArray; if (IsHidden) { return; } if (Type == DocumentNodeType.dnImage) { // Append image xaml prefix AppendImageXamlPrefix(); return; } if (Type == DocumentNodeType.dnText || Type == DocumentNodeType.dnInline) { AppendInlineXamlPrefix(converterState); return; } StringBuilder xamlStringBuilder = new StringBuilder(); // Do I need to wrap a font around this? if (IsEmptyNode && RequiresXamlFontProperties()) { xamlStringBuilder.Append("<"); xamlStringBuilder.Append(XamlNames[(int)DocumentNodeType.dnInline]); AppendXamlFontProperties(converterState, xamlStringBuilder); xamlStringBuilder.Append(">"); } xamlStringBuilder.Append("<"); xamlStringBuilder.Append(GetTagName()); switch (Type) { case DocumentNodeType.dnTable: // See below for writing out table column information AppendXamlPrefixTableProperties(xamlStringBuilder); break; case DocumentNodeType.dnCell: // Row stores cell properties. AppendXamlPrefixCellProperties(xamlStringBuilder, dna, converterState); break; case DocumentNodeType.dnParagraph: AppendXamlPrefixParagraphProperties(xamlStringBuilder, converterState); break; case DocumentNodeType.dnListItem: // List margins are handled at the paragraph level AppendXamlPrefixListItemProperties(xamlStringBuilder); break; case DocumentNodeType.dnList: // List margins are handled at the listitem level AppendXamlPrefixListProperties(xamlStringBuilder); break; case DocumentNodeType.dnHyperlink: AppendXamlPrefixHyperlinkProperties(xamlStringBuilder); break; } if (IsEmptyNode) { xamlStringBuilder.Append(" /"); } xamlStringBuilder.Append(">"); // Do I need to wrap a font around this? if (IsEmptyNode && RequiresXamlFontProperties()) { xamlStringBuilder.Append("</"); xamlStringBuilder.Append(XamlNames[(int)DocumentNodeType.dnInline]); xamlStringBuilder.Append(">"); } // Anything after the start tag? switch (Type) { case DocumentNodeType.dnTable: AppendXamlTableColumnsAfterStartTag(xamlStringBuilder); break; } Xaml = xamlStringBuilder.ToString(); }
internal static bool ConvertToMarkerStyle(ConverterState converterState, string styleName, ref MarkerStyle ms) { ms = MarkerStyle.MarkerBullet; if (styleName.Length == 0) { return false; } ms = (MarkerStyle)BasicLookup(MarkerStyleTable, styleName); return true; }
private void AppendXamlPrefixParagraphProperties(StringBuilder xamlStringBuilder, ConverterState converterState) { Color cToUse = Color.FromArgb(0xff, 0, 0, 0); FormatState fsThis = FormatState; if (Converters.ColorToUse(converterState, fsThis.CBPara, fsThis.CFPara, fsThis.ParaShading, ref cToUse)) { xamlStringBuilder.Append(" Background=\""); xamlStringBuilder.Append(cToUse.ToString(CultureInfo.InvariantCulture)); xamlStringBuilder.Append("\""); } // Handle paragraph direction AppendXamlDir(xamlStringBuilder); // Handle paragraph margins xamlStringBuilder.Append(" Margin=\""); xamlStringBuilder.Append(Converters.TwipToPositivePxString(NearMargin)); xamlStringBuilder.Append(","); xamlStringBuilder.Append(Converters.TwipToPositivePxString(fsThis.SB)); xamlStringBuilder.Append(","); xamlStringBuilder.Append(Converters.TwipToPositivePxString(FarMargin)); xamlStringBuilder.Append(","); xamlStringBuilder.Append(Converters.TwipToPositivePxString(fsThis.SA)); xamlStringBuilder.Append("\""); // FontFamily, Size, Bold, Italic AppendXamlFontProperties(converterState, xamlStringBuilder); // Lineheight // NB: Avalon only supports "lineheight exact" - we're just not going to output it. //if (fsThis.SL != 0) //{ // double px = (float)fsThis.SL; // if (px < 0) px = -px; // Whether SLMult is on or not is really moot. The value is always defined in twips, // the UI is the only thing that then interprets this as "multiple", probably when the // paragraph font is reset. // xamlStringBuilder.Append(" LineHeight=\""); // xamlStringBuilder.Append(Converters.TwipToPxString(px)); // xamlStringBuilder.Append("\""); //} // Indent if (fsThis.FI != 0) { xamlStringBuilder.Append(" TextIndent=\""); xamlStringBuilder.Append(Converters.TwipToPxString(fsThis.FI)); xamlStringBuilder.Append("\""); } // Handle paragraph alignment if (fsThis.HAlign != HAlign.AlignDefault) { xamlStringBuilder.Append(" TextAlignment=\""); xamlStringBuilder.Append(Converters.AlignmentToString(fsThis.HAlign, fsThis.DirPara)); xamlStringBuilder.Append("\""); } // Handle paragraph borders if (fsThis.HasParaBorder) { xamlStringBuilder.Append(fsThis.GetBorderAttributeString(converterState)); } }
internal static bool ConvertToStartIndex(ConverterState converterState, string s, ref int i) { bool ret = true; try { i = System.Convert.ToInt32(s, CultureInfo.InvariantCulture); } catch (System.OverflowException) { ret = false; } catch (System.FormatException) { ret = false; } return ret; }
internal void AppendInlineXamlPrefix(ConverterState converterState) { StringBuilder xamlStringBuilder = new StringBuilder(); FormatState fsThis = this.FormatState; FormatState fsParent = ParentFormatStateForFont; // Wrap any text with formatting tags. xamlStringBuilder.Append("<Span"); AppendXamlDir(xamlStringBuilder); if (fsThis.CB != fsParent.CB) { ColorTableEntry entry = converterState.ColorTable.EntryAt((int)fsThis.CB); if (entry != null && !entry.IsAuto) { xamlStringBuilder.Append(" Background=\""); xamlStringBuilder.Append(entry.Color.ToString()); xamlStringBuilder.Append("\""); } } AppendXamlFontProperties(converterState, xamlStringBuilder); // NB: Avalon does not support the RTF notion of Expand //if (fsThis.Expand != fsParent.Expand) //{ // if (fsThis.Expand > 0) // { // xamlStringBuilder.Append(" FontStretch=\"Expanded\""); // } // else // { // xamlStringBuilder.Append(" FontStretch=\"Condensed\""); // } //} if (fsThis.Super != fsParent.Super) { xamlStringBuilder.Append(" Typography.Variants=\"Superscript\""); } if (fsThis.Sub != fsParent.Sub) { xamlStringBuilder.Append(" Typography.Variants=\"Subscript\""); } xamlStringBuilder.Append(">"); Xaml = xamlStringBuilder.ToString(); }
internal static bool ConvertToThickness(ConverterState converterState, string thickness, ref XamlThickness xthickness) { int numints = 0; int s = 0; while (s < thickness.Length) { int e = s; while (e < thickness.Length && thickness[e] != ',') { e++; } string onenum = thickness.Substring(s, e - s); if (onenum.Length > 0) { double d = 0.0f; if (!Converters.StringToDouble(onenum, ref d)) { return false; } switch (numints) { case 0: xthickness.Left = (float)d; break; case 1: xthickness.Top = (float)d; break; case 2: xthickness.Right = (float)d; break; case 3: xthickness.Bottom = (float)d; break; default: return false; } numints++; } s = e + 1; } // One value means same value for all sides. if (numints == 1) { xthickness.Top = xthickness.Left; xthickness.Right = xthickness.Left; xthickness.Bottom = xthickness.Left; numints = 4; } return (numints == 4); }
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); } }
internal static bool ConvertToHAlign(ConverterState converterState, string alignName, ref HAlign align) { if (alignName.Length == 0) { return false; } align = (HAlign)BasicLookup(HAlignTable, alignName); return true; }
internal void CoalesceAll(ConverterState converterState) { for (int nAt = 0; nAt < Count; nAt++) { CoalesceChildren(converterState, nAt); } }
internal static bool ConvertToFontStretch(ConverterState converterState, string stretchName, ref long twips) { if (stretchName.Length == 0) { return false; } twips = (long)BasicLookup(HAlignTable, stretchName); return true; }
internal string GetBorderAttributeString(ConverterState converterState) { if (HasParaBorder) { return ParaBorder.GetBorderAttributeString(converterState); } else { return string.Empty; } }
internal static void EnsureParagraphClosed(ConverterState converterState) { DocumentNodeArray dna = converterState.DocumentNodeArray; int paragraphIndex = dna.FindPending(DocumentNodeType.dnParagraph); if (paragraphIndex >= 0) { DocumentNode documentNodeParagraph = dna.EntryAt(paragraphIndex); dna.CloseAt(paragraphIndex); } }