/// <param name="node">Where to append (add) results</param> public static void AddText(this RtfTreeNode node, string text) { foreach (char c in text) { uint cCode = (uint)c; if (c == '\n') { node.AddKeyword("line"); } else if (cCode <= 225) { node.AddKeyword(String.Format("\'{0:X}", cCode)); } else if (cCode <= 32768) { node.AddKeyword("uc", 1); node.AddKeyword(String.Format("u{0}*", cCode)); } else if (cCode <= 65535) { node.AddKeyword("uc", 1); node.AddKeyword(String.Format("u{0}*", cCode - 65536)); } else { throw new NotSupportedException("Char code more than 16535 is not supported"); } } }
/// <summary> /// Appends the definition of single table row /// </summary> /// <param name="node">Where to append the rtf elemenets (consider this as output)</param> /// <param name="cells">the definitions of the cells</param> public static void AddTableRow(this RtfTreeNode node, TextCell[] cells) { node.AddKeyword("trowd"); node.AddKeyword("trgaph", 400); int borderOffset = 0; foreach (var cell in cells) { borderOffset += cell.Width; node.AddSingleBorder(cell.BorderWidth); node.AddKeyword("cellx", borderOffset); } foreach (var cell in cells) { node.AddKeyword("pard"); switch (cell.TextAlignement) { case TextAlignement.Centered: node.AddCommand("qc"); break; case TextAlignement.Left: node.AddCommand("ql"); break; default: throw new NotSupportedException("Unexpected alignment"); } var grp = new RtfTreeNode(RtfNodeType.Group); if (cell.IsBold) { grp.AddCommand("b"); } node.AddKeyword("intbl"); grp.AddText(cell.Text); node.AppendChild(grp); node.AddKeyword("cell"); } node.AddKeyword("row"); }
/// <summary> /// Adds keywords that define single border /// </summary> /// <param name="width">border width in Twips</param> public static void AddSingleBorder(this RtfTreeNode node, int width) { node.AddKeyword("clbrdrt"); node.AddKeyword("brdrw", width); node.AddKeyword("brdrs"); node.AddKeyword("clbrdrl"); node.AddKeyword("brdrw", width); node.AddKeyword("brdrs"); node.AddKeyword("clbrdrb"); node.AddKeyword("brdrw", width); node.AddKeyword("brdrs"); node.AddKeyword("clbrdrr"); node.AddKeyword("brdrw", width); node.AddKeyword("brdrs"); }