コード例 #1
0
ファイル: DocumentInfo.cs プロジェクト: nnuds/FIT.MsgReader
        public void Write(Writer writer)
        {
            writer.WriteStartGroup();
            writer.WriteKeyword("info");
            foreach (string strKey in _infoStringDictionary.Keys)
            {
                writer.WriteStartGroup();
                if (strKey == "edmins" ||
                    strKey == "vern" ||
                    strKey == "nofpages" ||
                    strKey == "nofwords" ||
                    strKey == "nofchars" ||
                    strKey == "nofcharsws" ||
                    strKey == "id")
                {
                    writer.WriteKeyword(strKey + _infoStringDictionary[strKey]);
                }
                else
                {
                    writer.WriteKeyword(strKey);
                    writer.WriteText(_infoStringDictionary[strKey]);
                }
                writer.WriteEndGroup();
            }
            writer.WriteStartGroup();

            WriteTime(writer, "creatim", _creationTime);
            WriteTime(writer, "revtim", _revisionTime);
            WriteTime(writer, "printim", _printTime);
            WriteTime(writer, "buptim", _backupTime);

            writer.WriteEndGroup();
        }
コード例 #2
0
 public void WriteStartGroup()
 {
     if (CollectionInfo == false)
     {
         Writer.WriteStartGroup();
     }
 }
コード例 #3
0
ファイル: FontTable.cs プロジェクト: nnuds/FIT.MsgReader
 /// <summary>
 /// Write font table rtf
 /// </summary>
 /// <param name="writer">rtf text writer</param>
 public void Write(Writer writer)
 {
     writer.WriteStartGroup();
     writer.WriteKeyword(Consts.Fonttbl);
     foreach (Font font in this)
     {
         writer.WriteStartGroup();
         writer.WriteKeyword("f" + font.Index);
         if (font.Charset != 0)
         {
             writer.WriteKeyword("fcharset" + font.Charset);
         }
         writer.WriteText(font.Name);
         writer.WriteEndGroup();
     }
     writer.WriteEndGroup();
 }
コード例 #4
0
 /// <summary>
 /// Write start from footer
 /// </summary>
 public void WriteStartFooter()
 {
     if (CollectionInfo == false)
     {
         Writer.WriteStartGroup();
         Writer.WriteKeyword("footer");
     }
 }
コード例 #5
0
ファイル: NodeGroup.cs プロジェクト: nnuds/FIT.MsgReader
        /// <summary>
        /// Write content to rtf document
        /// </summary>
        /// <param name="writer">RTF text writer</param>
        public override void Write(Writer writer)
        {
            writer.WriteStartGroup();

            foreach (Node node in InternalNodes)
            {
                node.Write(writer);
            }

            writer.WriteEndGroup();
        }
コード例 #6
0
ファイル: DocumentInfo.cs プロジェクト: nnuds/FIT.MsgReader
 private void WriteTime(Writer writer, string name, DateTime value)
 {
     writer.WriteStartGroup();
     writer.WriteKeyword(name);
     writer.WriteKeyword("yr" + value.Year);
     writer.WriteKeyword("mo" + value.Month);
     writer.WriteKeyword("dy" + value.Day);
     writer.WriteKeyword("hr" + value.Hour);
     writer.WriteKeyword("min" + value.Minute);
     writer.WriteKeyword("sec" + value.Second);
     writer.WriteEndGroup();
 }
コード例 #7
0
 /// <summary>
 /// Write
 /// </summary>
 /// <param name="writer"></param>
 public void Write(Writer writer)
 {
     writer.WriteStartGroup();
     writer.WriteKeyword(Consts.Colortbl);
     writer.WriteRaw(";");
     foreach (var item in _arrayList)
     {
         var c = (Color)item;
         writer.WriteKeyword("red" + c.R);
         writer.WriteKeyword("green" + c.G);
         writer.WriteKeyword("blue" + c.B);
         writer.WriteRaw(";");
     }
     writer.WriteEndGroup();
 }
コード例 #8
0
        /// <summary>
        /// Start write of bookmark
        /// </summary>
        /// <param name="strName">bookmark name</param>
        public void WriteStartBookmark(string strName)
        {
            if (CollectionInfo == false)
            {
                Writer.WriteStartGroup();
                Writer.WriteKeyword("bkmkstart", true);
                Writer.WriteKeyword("f0");
                Writer.WriteText(strName);
                Writer.WriteEndGroup();

                Writer.WriteStartGroup();
                Writer.WriteKeyword("bkmkend", true);
                Writer.WriteKeyword("f0");
                Writer.WriteText(strName);
                Writer.WriteEndGroup();
            }
        }
コード例 #9
0
        /// <summary>
        /// Write image
        /// </summary>
        /// <param name="image">Image</param>
        /// <param name="width">Pixel width</param>
        /// <param name="height">Pixel height</param>
        /// <param name="imageData">Image binary data</param>
        public void WriteImage(Image image, int width, int height, byte[] imageData)
        {
            if (imageData == null)
            {
                return;
            }

            var memoryStream = new MemoryStream();

            image.Save(memoryStream, ImageFormat.Jpeg);
            memoryStream.Close();
            var bs = memoryStream.ToArray();

            Writer.WriteStartGroup();

            Writer.WriteKeyword("pict");
            Writer.WriteKeyword("jpegblip");
            Writer.WriteKeyword("picscalex" + Convert.ToInt32(width * 100.0 / image.Size.Width));
            Writer.WriteKeyword("picscaley" + Convert.ToInt32(height * 100.0 / image.Size.Height));
            Writer.WriteKeyword("picwgoal" + Convert.ToString(image.Size.Width * 15));
            Writer.WriteKeyword("pichgoal" + Convert.ToString(image.Size.Height * 15));
            Writer.WriteBytes(bs);
            Writer.WriteEndGroup();
        }
コード例 #10
0
        /// <summary>
        /// Start write of formatted text
        /// </summary>
        /// <param name="info">format</param>
        /// <remarks>
        /// This function must assort with WriteEndString
        /// </remarks>
        // ReSharper disable once MemberCanBePrivate.Global
        public void WriteStartString(DocumentFormatInfo info)
        {
            if (CollectionInfo)
            {
                FontTable.Add(info.FontName);
                ColorTable.Add(info.TextColor);
                ColorTable.Add(info.BackColor);
                if (info.BorderColor.A != 0)
                {
                    ColorTable.Add(info.BorderColor);
                }
                return;
            }

            if (!string.IsNullOrEmpty(info.Link))
            {
                Writer.WriteStartGroup();
                Writer.WriteKeyword("field");
                Writer.WriteStartGroup();
                Writer.WriteKeyword("fldinst", true);
                Writer.WriteStartGroup();
                Writer.WriteKeyword("hich");
                Writer.WriteText(" HYPERLINK \"" + info.Link + "\"");
                Writer.WriteEndGroup();
                Writer.WriteEndGroup();
                Writer.WriteStartGroup();
                Writer.WriteKeyword("fldrslt");
                Writer.WriteStartGroup();
            }

            switch (info.Align)
            {
            case RtfAlignment.Left:
                Writer.WriteKeyword("ql");
                break;

            case RtfAlignment.Center:
                Writer.WriteKeyword("qc");
                break;

            case RtfAlignment.Right:
                Writer.WriteKeyword("qr");
                break;

            case RtfAlignment.Justify:
                Writer.WriteKeyword("qj");
                break;
            }

            Writer.WriteKeyword("plain");

            int index = FontTable.IndexOf(info.FontName);

            if (index >= 0)
            {
                Writer.WriteKeyword("f" + index);
            }

            if (info.Bold)
            {
                Writer.WriteKeyword("b");
            }

            if (info.Italic)
            {
                Writer.WriteKeyword("i");
            }

            if (info.Underline)
            {
                Writer.WriteKeyword("ul");
            }

            if (info.Strikeout)
            {
                Writer.WriteKeyword("strike");
            }

            Writer.WriteKeyword("fs" + Convert.ToInt32(info.FontSize * 2));

            // Back color
            index = ColorTable.IndexOf(info.BackColor);
            if (index >= 0)
            {
                Writer.WriteKeyword("chcbpat" + Convert.ToString(index + 1));
            }

            index = ColorTable.IndexOf(info.TextColor);

            if (index >= 0)
            {
                Writer.WriteKeyword("cf" + Convert.ToString(index + 1));
            }

            if (info.Subscript)
            {
                Writer.WriteKeyword("sub");
            }

            if (info.Superscript)
            {
                Writer.WriteKeyword("super");
            }

            if (info.NoWwrap)
            {
                Writer.WriteKeyword("nowwrap");
            }

            if (info.LeftBorder ||
                info.TopBorder ||
                info.RightBorder ||
                info.BottomBorder)
            {
                // Border color
                if (info.BorderColor.A != 0)
                {
                    Writer.WriteKeyword("chbrdr");
                    Writer.WriteKeyword("brdrs");
                    Writer.WriteKeyword("brdrw10");
                    index = ColorTable.IndexOf(info.BorderColor);
                    if (index >= 0)
                    {
                        Writer.WriteKeyword("brdrcf" + Convert.ToString(index + 1));
                    }
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// Write the start of the document
        /// </summary>
        public void WriteStartDocument()
        {
            _lastParagraphInfo = null;
            _firstParagraph    = true;
            if (CollectionInfo)
            {
                Info.Clear();
                FontTable.Clear();
                ColorTable.Clear();
                FontTable.Add(Control.DefaultFont.Name);
            }
            else
            {
                Writer.WriteStartGroup();
                Writer.WriteKeyword(Consts.Rtf);
                Writer.WriteKeyword("ansi");
                Writer.WriteKeyword("ansicpg" + Writer.Encoding.CodePage);

                // Write document information
                if (Info.Count > 0)
                {
                    Writer.WriteStartGroup();
                    Writer.WriteKeyword("info");
                    foreach (string key in Info.Keys)
                    {
                        Writer.WriteStartGroup();

                        var value = Info[key];
                        if (value is string)
                        {
                            Writer.WriteKeyword(key);
                            Writer.WriteText((string)value);
                        }
                        else if (value is int)
                        {
                            Writer.WriteKeyword(key + value);
                        }
                        else if (value is DateTime)
                        {
                            var dateTime = (DateTime)value;
                            Writer.WriteKeyword(key);
                            Writer.WriteKeyword("yr" + dateTime.Year);
                            Writer.WriteKeyword("mo" + dateTime.Month);
                            Writer.WriteKeyword("dy" + dateTime.Day);
                            Writer.WriteKeyword("hr" + dateTime.Hour);
                            Writer.WriteKeyword("min" + dateTime.Minute);
                            Writer.WriteKeyword("sec" + dateTime.Second);
                        }
                        else
                        {
                            Writer.WriteKeyword(key);
                        }

                        Writer.WriteEndGroup();
                    }
                    Writer.WriteEndGroup();
                }

                // Write font table
                Writer.WriteStartGroup();
                Writer.WriteKeyword(Consts.Fonttbl);
                for (var count = 0; count < FontTable.Count; count++)
                {
                    //string f = myFontTable[ count ] ;
                    Writer.WriteStartGroup();
                    Writer.WriteKeyword("f" + count);
                    var f = FontTable[count];
                    Writer.WriteText(f.Name);
                    if (f.Charset != 1)
                    {
                        Writer.WriteKeyword("fcharset" + f.Charset);
                    }
                    Writer.WriteEndGroup();
                }
                Writer.WriteEndGroup();

                // Write color table
                Writer.WriteStartGroup();
                Writer.WriteKeyword(Consts.Colortbl);
                Writer.WriteRaw(";");

                for (var count = 0; count < ColorTable.Count; count++)
                {
                    var colorTable = ColorTable[count];
                    Writer.WriteKeyword("red" + colorTable.R);
                    Writer.WriteKeyword("green" + colorTable.G);
                    Writer.WriteKeyword("blue" + colorTable.B);
                    Writer.WriteRaw(";");
                }
                Writer.WriteEndGroup();

                // Write list table
                if (ListTable != null && ListTable.Count > 0)
                {
                    if (DebugMode)
                    {
                        Writer.WriteRaw(Environment.NewLine);
                    }

                    Writer.WriteStartGroup();
                    Writer.WriteKeyword("listtable", true);

                    foreach (var list in ListTable)
                    {
                        if (DebugMode)
                        {
                            Writer.WriteRaw(Environment.NewLine);
                        }
                        Writer.WriteStartGroup();
                        Writer.WriteKeyword("list");
                        Writer.WriteKeyword("listtemplateid" + list.ListTemplateId);

                        if (list.ListHybrid)
                        {
                            Writer.WriteKeyword("listhybrid");
                        }

                        if (DebugMode)
                        {
                            Writer.WriteRaw(Environment.NewLine);
                        }

                        Writer.WriteStartGroup();
                        Writer.WriteKeyword("listlevel");
                        Writer.WriteKeyword("levelfollow" + list.LevelFollow);
                        Writer.WriteKeyword("leveljc" + list.LevelJc);
                        Writer.WriteKeyword("levelstartat" + list.LevelStartAt);
                        Writer.WriteKeyword("levelnfc" + Convert.ToInt32(list.LevelNfc));
                        Writer.WriteKeyword("levelnfcn" + Convert.ToInt32(list.LevelNfc));
                        Writer.WriteKeyword("leveljc" + list.LevelJc);

                        if (string.IsNullOrEmpty(list.LevelText) == false)
                        {
                            Writer.WriteStartGroup();
                            Writer.WriteKeyword("leveltext");
                            Writer.WriteKeyword("'0" + list.LevelText.Length);
                            if (list.LevelNfc == RtfLevelNumberType.Bullet)
                            {
                                Writer.WriteUnicodeText(list.LevelText);
                            }
                            else
                            {
                                Writer.WriteText(list.LevelText, false);
                            }

                            Writer.WriteEndGroup();
                            if (list.LevelNfc == RtfLevelNumberType.Bullet)
                            {
                                var f = FontTable["Wingdings"];
                                if (f != null)
                                {
                                    Writer.WriteKeyword("f" + f.Index);
                                }
                            }
                            else
                            {
                                Writer.WriteStartGroup();
                                Writer.WriteKeyword("levelnumbers");
                                Writer.WriteKeyword("'01");
                                Writer.WriteEndGroup();
                            }
                        }
                        Writer.WriteEndGroup();

                        Writer.WriteKeyword("listid" + list.ListId);
                        Writer.WriteEndGroup();
                    }
                    Writer.WriteEndGroup();
                }

                // Write list overried table
                if (ListOverrideTable != null && ListOverrideTable.Count > 0)
                {
                    if (DebugMode)
                    {
                        Writer.WriteRaw(Environment.NewLine);
                    }

                    Writer.WriteStartGroup();
                    Writer.WriteKeyword("listoverridetable");
                    foreach (var listOverride in ListOverrideTable)
                    {
                        if (DebugMode)
                        {
                            Writer.WriteRaw(Environment.NewLine);
                        }
                        Writer.WriteStartGroup();
                        Writer.WriteKeyword("listoverride");
                        Writer.WriteKeyword("listid" + listOverride.ListId);
                        Writer.WriteKeyword("listoverridecount" + listOverride.ListOverrideCount);
                        Writer.WriteKeyword("ls" + listOverride.Id);
                        Writer.WriteEndGroup();
                    }
                    Writer.WriteEndGroup();
                }

                if (DebugMode)
                {
                    Writer.WriteRaw(Environment.NewLine);
                }

                Writer.WriteKeyword("viewkind1");
            }
        }