/// <summary> /// read color table /// </summary> /// <param name="group"></param> private void ReadColorTable(RTFNodeGroup group) { myColorTable.Clear(); var r = -1; var g = -1; var b = -1; foreach (RTFNode node in group.Nodes) { if (node.Keyword == "red") { r = node.Parameter; } else if (node.Keyword == "green") { g = node.Parameter; } else if (node.Keyword == "blue") { b = node.Parameter; } if (node.Keyword == ";") { if (r >= 0 && g >= 0 && b >= 0) { var c = System.Drawing.Color.FromArgb(255, r, g, b); myColorTable.Add(c); r = -1; g = -1; b = -1; } } } if (r >= 0 && g >= 0 && b >= 0) { // read the last color var c = System.Drawing.Color.FromArgb(255, r, g, b); myColorTable.Add(c); } }
/// <summary> /// start write formatted text /// </summary> /// <param name="info">format</param> /// <remarks> /// This function must assort with WriteEndString strict /// </remarks> public void WriteStartString(DocumentFormatInfo info) { if (this.bolCollectionInfo) { myFontTable.Add(info.FontName); myColorTable.Add(info.TextColor); myColorTable.Add(info.BackColor); if (info.BorderColor.A != 0) { myColorTable.Add(info.BorderColor); } return; } if (info.Link != null && info.Link.Length > 0) { myWriter.WriteStartGroup(); myWriter.WriteKeyword("field"); myWriter.WriteStartGroup(); myWriter.WriteKeyword("fldinst", true); myWriter.WriteStartGroup(); myWriter.WriteKeyword("hich"); myWriter.WriteText(" HYPERLINK \"" + info.Link + "\""); myWriter.WriteEndGroup(); myWriter.WriteEndGroup(); myWriter.WriteStartGroup(); myWriter.WriteKeyword("fldrslt"); myWriter.WriteStartGroup(); } switch (info.Align) { case RTFAlignment.Left: myWriter.WriteKeyword("ql"); break; case RTFAlignment.Center: myWriter.WriteKeyword("qc"); break; case RTFAlignment.Right: myWriter.WriteKeyword("qr"); break; case RTFAlignment.Justify: myWriter.WriteKeyword("qj"); break; } myWriter.WriteKeyword("plain"); int index = 0; index = myFontTable.IndexOf(info.FontName); if (index >= 0) { myWriter.WriteKeyword("f" + index); } if (info.Bold) { myWriter.WriteKeyword("b"); } if (info.Italic) { myWriter.WriteKeyword("i"); } if (info.Underline) { myWriter.WriteKeyword("ul"); } if (info.Strikeout) { myWriter.WriteKeyword("strike"); } myWriter.WriteKeyword("fs" + Convert.ToInt32(info.FontSize * 2)); // back color index = myColorTable.IndexOf(info.BackColor); if (index >= 0) { myWriter.WriteKeyword("chcbpat" + Convert.ToString(index + 1)); } index = myColorTable.IndexOf(info.TextColor); if (index >= 0) { myWriter.WriteKeyword("cf" + Convert.ToString(index + 1)); } if (info.Subscript) { myWriter.WriteKeyword("sub"); } if (info.Superscript) { myWriter.WriteKeyword("super"); } if (info.NoWwrap) { myWriter.WriteKeyword("nowwrap"); } if (info.LeftBorder || info.TopBorder || info.RightBorder || info.BottomBorder) { // border color if (info.BorderColor.A != 0) { myWriter.WriteKeyword("chbrdr"); myWriter.WriteKeyword("brdrs"); myWriter.WriteKeyword("brdrw10"); index = myColorTable.IndexOf(info.BorderColor); if (index >= 0) { myWriter.WriteKeyword("brdrcf" + Convert.ToString(index + 1)); } } } }