Пример #1
0
        private void WriteField(Stream outp)
        {
            // always hide the toc entry
            outp.WriteByte(RtfWriter.openGroup);
            outp.WriteByte(RtfWriter.escape);
            outp.WriteByte((byte)'v');

            // tc field entry
            outp.WriteByte(RtfWriter.openGroup);
            outp.WriteByte(RtfWriter.escape);
            byte[] t;
            if (!hidePageNumber)
            {
                t = DocWriter.GetISOBytes("tc");
                outp.Write(t, 0, t.Length);
            }
            else
            {
                t = DocWriter.GetISOBytes("tcn");
                outp.Write(t, 0, t.Length);
            }
            outp.WriteByte(RtfWriter.delimiter);
            t = DocWriter.GetISOBytes(RtfWriter.FilterSpecialChar(entryName, true));
            outp.Write(t, 0, t.Length);
            outp.WriteByte(RtfWriter.delimiter);
            outp.WriteByte(RtfWriter.closeGroup);

            outp.WriteByte(RtfWriter.closeGroup);
        }
Пример #2
0
        bool CopyTextToClipboard()
        {
            string str = textArea.SelectionManager.SelectedText;

            if (str.Length > 0)
            {
                // paste to clipboard
                // BIG HACK: STRANGE EXTERNAL EXCEPTION BUG WORKAROUND
                for (int i = 0; i < 5; ++i)
                {
                    try {
                        DataObject dataObject = new DataObject();
                        dataObject.SetData(DataFormats.UnicodeText, true, str);
                        // Default has no highlighting, therefore we don't need RTF output
                        if (textArea.Document.HighlightingStrategy.Name != "Default")
                        {
                            dataObject.SetData(DataFormats.Rtf, RtfWriter.GenerateRtf(textArea));
                        }
                        OnCopyText(new CopyTextEventArgs(str));
                        Clipboard.SetDataObject(dataObject, true);
                        return(true);
                    } catch (Exception e) {
                        Console.WriteLine("Got exception while Copy text to clipboard : " + e);
                    }
                    Thread.Sleep(100);
                }
            }
            return(false);
        }
Пример #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;

            Report      report    = new Report();
            RtfDocument rtf       = report.GetRtf();
            RtfWriter   rtfWriter = new RtfWriter();
            DateTime    start;
            TimeSpan    time;

            try
            {
                using (TextWriter writer = new StreamWriter("test.rtf"))
                {
                    start = DateTime.Now;

                    rtfWriter.Write(writer, rtf);

                    time = DateTime.Now - start;

                    label1.Text = String.Format("{0}.{1}", time.Seconds, time.Milliseconds.ToString().PadLeft(3, '0'));
                }
            }
            catch (IOException)
            {
                label1.Text = "I/O Exception";
            }

            button1.Enabled = true;
        }
Пример #4
0
        public Chap0801()
        {
            Console.WriteLine("Chapter 8 example 1: Hello World");

            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2:
                // we create a writer that listens to the document
                // and directs a RTF-stream to a file

                RtfWriter.GetInstance(document, new FileStream("Chap0801.rtf", FileMode.Create));

                // step 3: we open the document
                document.Open();

                // step 4: we add a paragraph to the document
                document.Add(new Paragraph("Hello World"));
            }
            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }

            // step 5: we close the document
            document.Close();
        }
Пример #5
0
        public Chap0702()
        {
            Console.WriteLine("Chapter 7 example 2: parsing the result of example 1");

            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2:
                // we create a writer that listens to the document
                // and directs a XML-stream to a file
                PdfWriter.GetInstance(document, new FileStream("Chap0702.pdf", FileMode.Create));
                HtmlWriter.GetInstance(document, new FileStream("Chap0702.htm", FileMode.Create));
                RtfWriter.GetInstance(document, new FileStream("Chap0702.rtf", FileMode.Create));
                // step 3: we create a parser

                ITextHandler h = new ITextHandler(document);

                // step 4: we parse the document
                h.Parse("Chap0701.xml");
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.StackTrace);
                Console.Error.WriteLine(e.Message);
            }
        }
Пример #6
0
        bool CopyTextToClipboard(string stringToCopy, bool asLine)
        {
            if (stringToCopy.Length > 0)
            {
                DataObject dataObject = new DataObject();
                dataObject.SetData(DataFormats.UnicodeText, true, stringToCopy);
                if (asLine)
                {
                    MemoryStream lineSelected = new MemoryStream(1);
                    lineSelected.WriteByte(1);
                    dataObject.SetData(LineSelectedType, false, lineSelected);
                }
                // Default has no highlighting, therefore we don't need RTF output
                if (_textArea.Document.HighlightingStrategy.Name != "Default")
                {
                    dataObject.SetData(DataFormats.Rtf, RtfWriter.GenerateRtf(_textArea));
                }
                OnCopyText(new CopyTextEventArgs(stringToCopy));

                SafeSetClipboard(dataObject);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #7
0
        private void writeField(Stream str)
        {
            // always hide the toc entry
            str.WriteByte(RtfWriter.openGroup);
            str.WriteByte(RtfWriter.escape);
            str.Write(ASCIIEncoding.ASCII.GetBytes("v"), 0, ASCIIEncoding.ASCII.GetBytes("v").Length);

            // tc field entry
            str.WriteByte(RtfWriter.openGroup);
            str.WriteByte(RtfWriter.escape);
            if (!hidePageNumber)
            {
                str.Write(ASCIIEncoding.ASCII.GetBytes("tc"), 0, ASCIIEncoding.ASCII.GetBytes("tc").Length);
            }
            else
            {
                str.Write(ASCIIEncoding.ASCII.GetBytes("tcn"), 0, ASCIIEncoding.ASCII.GetBytes("tcn").Length);
            }
            str.WriteByte(RtfWriter.delimiter);
            str.Write(ASCIIEncoding.ASCII.GetBytes(RtfWriter.filterSpecialChar(entryName)), 0,
                      ASCIIEncoding.ASCII.GetBytes(RtfWriter.filterSpecialChar(entryName)).Length);
            str.WriteByte(RtfWriter.delimiter);
            str.WriteByte(RtfWriter.closeGroup);

            str.WriteByte(RtfWriter.closeGroup);
        }
        private bool CopyTextToClipboard()
        {
            string selectedText = this.textArea.SelectionManager.SelectedText;

            if (selectedText.Length > 0)
            {
                for (int i = 0; i < 5; i++)
                {
                    try
                    {
                        DataObject dataObject = new DataObject();
                        dataObject.SetData(DataFormats.UnicodeText, true, selectedText);
                        if (this.textArea.Document.HighlightingStrategy.Name != "Default")
                        {
                            dataObject.SetData(DataFormats.Rtf, RtfWriter.GenerateRtf(this.textArea));
                        }
                        this.OnCopyText(new CopyTextEventArgs(selectedText));
                        Clipboard.SetDataObject(dataObject, true);
                        return(true);
                    }
                    catch (Exception arg)
                    {
                        Console.WriteLine("Got exception while Copy text to clipboard : " + arg);
                    }
                    Thread.Sleep(100);
                }
            }
            return(false);
        }
Пример #9
0
        public void TestXml()
        {
            if (Platform.IsWindows)
            {
                Assert.Inconclusive();
            }
            var data = Create(
                @"<foo
	attr1 = ""1""
	attr2 = ""2""
/>");
            //data.ColorStyle = SyntaxModeService.GetColorStyle ("Tango");
            //data.Document.SyntaxMode = SyntaxModeService.GetSyntaxMode (data.Document, "application/xml");

            string generatedRtf = RtfWriter.GenerateRtf(data);

            Assert.AreEqual(
                @"{\rtf1\ansi\deff0\adeflang1025
{\fonttbl
{\f0\fnil\fprq1\fcharset128 Mono;}
}
{\colortbl ;\red68\green68\blue68;\red51\green100\blue164;\red245\green125\blue0;}\viewkind4\uc1\pard
\f0
\fs20\cf1
\cf1 <\cf2 foo\line
\tab\cf1 attr1 =\cf2  \cf3 ""1""\line
\cf2\tab\cf1 attr2 =\cf2  \cf3 ""2""\line
\cf1 />\line
}"
                , generatedRtf);
        }
Пример #10
0
        public void Write(RtfWriter writer, Stream str)
        {
            writer.writeInitialFontSignature(str, this);
            byte[] tmp = System.Text.ASCIIEncoding.ASCII.GetBytes(content.ToString());
            str.Write(tmp, 0, tmp.Length);

            /*        str.write( RtfWriter.escape );
             *              str.write( pageControl );*/
            writer.writeFinishingFontSignature(str, this);
            //        str.write( RtfWriter.openGroup );
            //            str.write( RtfWriter.escape );
            //            str.write( RtfWriter.field );
            //            str.write( RtfWriter.openGroup );
            //                str.write( RtfWriter.extendedEscape );
            //                str.write( RtfWriter.fieldContent );
            //                str.write( RtfWriter.openGroup );
            //                    str.write( RtfWriter.delimiter );
            //                    str.write( RtfWriter.fieldPage );
            //                    str.write( RtfWriter.delimiter );
            //                str.write( RtfWriter.closeGroup );
            //            str.write( RtfWriter.closeGroup );
            //            str.write( RtfWriter.openGroup );
            //                str.write( RtfWriter.escape );
            //                str.write( RtfWriter.fieldDisplay );
            //                str.write( RtfWriter.openGroup );
            //                str.write( RtfWriter.closeGroup );
            //            str.write( RtfWriter.closeGroup );
            //        str.write( RtfWriter.closeGroup );
        }
Пример #11
0
 /**
  * write this RtfField into a stream using the writer given as
  * first argument.
  * @param writer the RtfWriter to use to write this RtfField
  * @param outp the Stream to write this RtfField into.
  * @throws IOException
  */
 public override void Write(RtfWriter writer, Stream outp)
 {
     writer.WriteInitialFontSignature(outp, this);
     byte[] t = DocWriter.GetISOBytes(content);
     outp.Write(t, 0, t.Length);
     writer.WriteFinishingFontSignature(outp, this);
     base.Write(writer, outp);
 }
Пример #12
0
        public void CloseFile()
        {
            CloseCurrentParagraph();
            RtfWriter  rtfWriter = new RtfWriter();
            TextWriter writer    = new StreamWriter(m_strFilepath);

            rtfWriter.Write(writer, m_doc);
            writer.Close();
        }
Пример #13
0
            public void SetData(SelectionData selection_data, uint info)
            {
                if (selection_data == null)
                {
                    return;
                }
                switch (info)
                {
                case TextType:
                    // Windows specific hack to work around bug: Bug 661973 - copy operation in TextEditor braks text lines with duplicate line endings when the file has CRLF
                    // Remove when https://bugzilla.gnome.org/show_bug.cgi?id=640439 is fixed.
                    if (Platform.IsWindows)
                    {
                        selection_data.Text = copiedDocument.Text.Replace("\r\n", "\n");
                    }
                    else
                    {
                        selection_data.Text = copiedDocument.Text;
                    }
                    break;

                case RichTextType:
                    var rtf = RtfWriter.GenerateRtf(copiedColoredChunks, docStyle, options);
                    selection_data.Set(RTF_ATOM, UTF8_FORMAT, Encoding.UTF8.GetBytes(rtf));
                    break;

                case HTMLTextType:
                    var html = HtmlWriter.GenerateHtml(copiedColoredChunks, docStyle, options);
//					Console.WriteLine ("html:" + html);
                    selection_data.Set(HTML_ATOM, UTF8_FORMAT, Encoding.UTF8.GetBytes(html));
                    break;

                case MonoTextType:
                    byte[] rawText        = Encoding.UTF8.GetBytes(monoDocument.Text);
                    var    copyDataLength = (byte)(copyData != null ? copyData.Length : 0);
                    var    dataOffset     = 1 + 1 + copyDataLength;
                    byte[] data           = new byte [rawText.Length + dataOffset];
                    data [1] = copyDataLength;
                    if (copyDataLength > 0)
                    {
                        copyData.CopyTo(data, 2);
                    }
                    rawText.CopyTo(data, dataOffset);
                    data [0] = 0;
                    if (isBlockMode)
                    {
                        data [0] |= 1;
                    }
                    if (isLineSelectionMode)
                    {
                        data [0] |= 2;
                    }
                    selection_data.Set(MD_ATOM, UTF8_FORMAT, data);
                    break;
                }
            }
Пример #14
0
        public void TestSimpleCSharpRtf()
        {
            var         data         = Create("class Foo {}");
            var         style        = SyntaxModeService.GetColorStyle(null, "TangoLight");
            ISyntaxMode mode         = SyntaxModeService.GetSyntaxMode(data.Document, "text/x-csharp");
            string      generatedRtf = RtfWriter.GenerateRtf(data.Document, mode, style, data.Options);

            Assert.AreEqual(
                @"{\rtf1\ansi\deff0\adeflang1025{\fonttbl{\f0\fnil\fprq1\fcharset128 Mono;}}{\colortbl ;\red92\green53\blue102;\red0\green0\blue0;}\viewkind4\uc1\pard\f0\fs20\cf1\b\cf1 class\b0\cf2  Foo \{\}\par" + Environment.NewLine + "}", generatedRtf);
        }
Пример #15
0
        public void TestBug5628()
        {
            var         data         = Create("class Foo {}");
            var         style        = SyntaxModeService.GetColorStyle(null, "TangoLight");
            ISyntaxMode mode         = null;
            string      generatedRtf = RtfWriter.GenerateRtf(data.Document, mode, style, data.Options);

            Assert.AreEqual(
                @"{\rtf1\ansi\deff0\adeflang1025{\fonttbl{\f0\fnil\fprq1\fcharset128 Mono;}}{\colortbl ;}\viewkind4\uc1\pard\f0\fs20\cf1class Foo \{\}}", generatedRtf);
        }
Пример #16
0
        public Chap0804()
        {
            Console.WriteLine("Chapter 8 example 4: Tables and RTF");
            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2:
                // we create a writer that listens to the document
                // and directs a PDF-stream to a file
                RtfWriter.GetInstance(document, new FileStream("Chap0804.rtf", FileMode.Create));
                // step 3: we open the document
                document.Open();
                // step 4: we create a table and add it to the document
                Table table = new Table(3);
                table.BorderWidth = 1;
                table.BorderColor = new Color(0, 0, 255);
                table.Padding     = 5;
                table.Spacing     = 5;
                Cell cell = new Cell("header");
                cell.Header  = true;
                cell.Colspan = 3;
                table.AddCell(cell);
                cell             = new Cell("example cell with colspan 1 and rowspan 2");
                cell.Rowspan     = 2;
                cell.BorderColor = new Color(255, 0, 0);
                table.AddCell(cell);
                table.AddCell("1.1");
                table.AddCell("2.1");
                table.AddCell("1.2");
                table.AddCell("2.2");
                table.AddCell("cell test1");
                cell                 = new Cell("big cell");
                cell.Rowspan         = 2;
                cell.Colspan         = 2;
                cell.BackgroundColor = new Color(0xC0, 0xC0, 0xC0);
                table.AddCell(cell);
                table.AddCell("cell test2");
                document.Add(table);
            }
            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }
            // step 5: we close the document
            document.Close();
        }
Пример #17
0
 /**
  * For Interface RtfField.
  * @param writer
  * @param outp
  * @throws IOException
  */
 public virtual void Write(RtfWriter writer, Stream outp)
 {
     WriteRtfFieldBegin(outp);
     WriteRtfFieldModifiers(outp);
     WriteRtfFieldInstBegin(outp);
     writer.WriteInitialFontSignature(outp, this);
     WriteRtfFieldInitializationStuff(outp);
     WriteRtfFieldInstEnd(outp);
     WriteRtfFieldResultBegin(outp);
     writer.WriteInitialFontSignature(outp, this);
     WriteRtfFieldResultStuff(outp);
     WriteRtfFieldResultEnd(outp);
     WriteRtfFieldEnd(outp);
 }
Пример #18
0
            public void SetData(SelectionData selection_data, uint info)
            {
                if (selection_data == null)
                {
                    return;
                }
                switch (info)
                {
                case TextType:
                    selection_data.Text = GetCopiedPlainText();
                    break;

                case RichTextType:
                    var rtf = RtfWriter.GenerateRtf(copiedColoredChunks, docStyle, options);
                    selection_data.Set(RTF_ATOM, UTF8_FORMAT, Encoding.UTF8.GetBytes(rtf));
                    break;

                case HTMLTextType:
                    var html = HtmlWriter.GenerateHtml(copiedColoredChunks, docStyle, options);
//					Console.WriteLine ("html:" + html);
                    selection_data.Set(HTML_ATOM, UTF8_FORMAT, Encoding.UTF8.GetBytes(html));
                    break;

                case MonoTextType:
                    byte[] rawText        = Encoding.UTF8.GetBytes(GetCopiedPlainText());
                    var    copyDataLength = (byte)(copyData != null ? copyData.Length : 0);
                    var    dataOffset     = 1 + 1 + copyDataLength;
                    byte[] data           = new byte [rawText.Length + dataOffset];
                    data [1] = copyDataLength;
                    if (copyDataLength > 0)
                    {
                        copyData.CopyTo(data, 2);
                    }
                    rawText.CopyTo(data, dataOffset);
                    data [0] = 0;
                    if (isBlockMode)
                    {
                        data [0] |= 1;
                    }
                    if (isLineSelectionMode)
                    {
                        data [0] |= 2;
                    }
                    selection_data.Set(MD_ATOM, UTF8_FORMAT, data);
                    break;
                }
            }
Пример #19
0
        public void TestBug7386()
        {
            var data = Create("✔");

            data.ColorStyle = SyntaxModeService.GetColorStyle("TangoLight");
            string generatedRtf = RtfWriter.GenerateRtf(data);

            Assert.AreEqual(
                @"{\rtf1\ansi\deff0\adeflang1025
{\fonttbl
{\f0\fnil\fprq1\fcharset128 Mono;}
}
{\colortbl ;}\viewkind4\uc1\pard
\f0
\fs20\cf1
\uc1\u10004*}", generatedRtf);
        }
Пример #20
0
        /// <summary>
        /// Gets the name of the exported file.
        /// </summary>
        /// <param name="appealLetter">The appeal letter container.</param>
        /// <param name="reportVirtualPath">The report virtual path.</param>
        /// <param name="fileBaseName">Name of the file base.</param>
        /// <returns></returns>
        public static string[] GetExportedFileName(AppealLetter appealLetter, string reportVirtualPath, string fileBaseName)
        {
            string fileName;

            if (appealLetter.ReportThreshold == Constants.ReportThreshold) // Exceeded threshold limit
            {
                fileName = Convert.ToString(Constants.ReportThreshold);
            }
            else if (appealLetter.AppealLetterClaims.Count == 0) //No Records Found
            {
                fileName = Constants.EmptyReportResult;
            }
            else
            {
                _appealLetter = appealLetter;
                string dateTimeStamp = DateTime.Now.ToString(Constants.DateTimeExtendedFormat);
                fileName  = string.Format("{0}{1}.{2}", fileBaseName, dateTimeStamp, Constants.AppealLetterFileExtension);
                _filePath = Path.Combine(reportVirtualPath, fileName);
                //Build rtf document object
                RtfDocument rtfDocument = GetRtfDocument();

                //Get rtf content String
                RtfWriter rtfWriter          = new RtfWriter();
                string    templateRtfContent = rtfWriter.GetRtfContent(rtfDocument);
                //loop through each claim data and replace claim text and merge rtf content
                string finalRtfContent = _appealLetter.AppealLetterClaims.Select(
                    appealLetterClaim => ReplaceClaimData(templateRtfContent, appealLetterClaim))
                                         .Aggregate(string.Empty,
                                                    (current, rtfClaimText) =>
                                                    !string.IsNullOrEmpty(current)
                                ? MergeRtfContent(current, rtfClaimText)
                                : rtfClaimText);

                //Write rtf content into file
                using (TextWriter writer = new StreamWriter(_filePath))
                {
                    rtfWriter.Write(writer, finalRtfContent);
                }
                if (appealLetter.IsPreview)
                {
                    return(new[] { appealLetter.LetterTemplaterText, fileName });
                }
            }
            return(new[] { fileName });
        }
Пример #21
0
        public void TestBug5628()
        {
            var data = Create("class Foo {}");

            data.ColorStyle = SyntaxModeService.GetColorStyle("TangoLight");
            string generatedRtf = RtfWriter.GenerateRtf(data);

            Assert.AreEqual(
                @"{\rtf1\ansi\deff0\adeflang1025
{\fonttbl
{\f0\fnil\fprq1\fcharset128 Mono;}
}
{\colortbl ;\red68\green68\blue68;}\viewkind4\uc1\pard
\f0
\fs20\cf1
\cf1 class Foo \{\}\line
}", generatedRtf);
        }
        private void createGlobalRtfReport()
        {
            int         maxPagesInReport  = AppSettings.Settings.Rtf.RtfNumberOfPagesInReport;
            RtfDocument globalDoc         = null;
            string      globalDocFilename = "";

            for (int idx = 0; idx < m_allDocuments.Count; idx++)
            {
                if ((idx % maxPagesInReport) == 0)
                {
                    // close the current document
                    if (globalDoc != null)
                    {
                        globalDocFilename = m_reportFolder + String.Format("{0}{1}-{2}.rtf", AppSettings.Settings.Rtf.RtfReportBaseFilename, idx - maxPagesInReport, idx - 1);
                        RtfWriter  rtfWriter = new RtfWriter();
                        TextWriter writer    = new StreamWriter(globalDocFilename);
                        rtfWriter.Write(writer, globalDoc);
                        writer.Close();
                    }

                    // start new document
                    globalDoc = new RtfDocument();
                }

                RtfDocument currDoc = m_allDocuments[idx];
                foreach (RtfDocumentContentBase item in currDoc.Contents)
                {
                    globalDoc.Contents.Add(item);
                }
            }

            // close the last file
            if (globalDoc != null)
            {
                int lastCount = (m_allDocuments.Count / maxPagesInReport) * maxPagesInReport;
                globalDocFilename = m_reportFolder + String.Format("{0}{1}-{2}.rtf", AppSettings.Settings.Rtf.RtfReportBaseFilename, lastCount, m_allDocuments.Count);
                RtfWriter  rtfWriter = new RtfWriter();
                TextWriter writer    = new StreamWriter(globalDocFilename);
                rtfWriter.Write(writer, globalDoc);
                writer.Close();
            }
        }
Пример #23
0
            public void SetData(uint info)
            {
                switch (info)
                {
                case TextType:
                    Clipboard.SetText(GetCopiedPlainText());
                    break;

                case RichTextType:
                    var rtf = RtfWriter.GenerateRtf(copiedColoredChunks, docStyle, options);
                    Clipboard.SetData(TransferDataType.Rtf, Encoding.UTF8.GetBytes(rtf));
                    break;

                case HTMLTextType:
                    var html = HtmlWriter.GenerateHtml(copiedColoredChunks, docStyle, options);
                    Clipboard.SetData(TransferDataType.Html, Encoding.UTF8.GetBytes(html));
                    break;

                case MonoTextType:
                    byte[] rawText        = Encoding.UTF8.GetBytes(GetCopiedPlainText());
                    var    copyDataLength = (byte)(copyData != null ? copyData.Length : 0);
                    var    dataOffset     = 1 + 1 + copyDataLength;
                    byte[] data           = new byte[rawText.Length + dataOffset];
                    data[1] = copyDataLength;
                    if (copyDataLength > 0)
                    {
                        copyData.CopyTo(data, 2);
                    }
                    rawText.CopyTo(data, dataOffset);
                    data[0] = 0;
                    if (isBlockMode)
                    {
                        data[0] |= 1;
                    }
                    if (isLineSelectionMode)
                    {
                        data[0] |= 2;
                    }
                    Clipboard.SetData(data);
                    break;
                }
            }
Пример #24
0
        public void TestBug7386()
        {
            if (Platform.IsWindows)
            {
                Assert.Inconclusive();
            }
            var data = Create("✔");
            //data.ColorStyle = SyntaxModeService.GetColorStyle ("Tango");
            string generatedRtf = RtfWriter.GenerateRtf(data);

            Assert.AreEqual(
                @"{\rtf1\ansi\deff0\adeflang1025
{\fonttbl
{\f0\fnil\fprq1\fcharset128 Mono;}
}
{\colortbl ;\red34\green34\blue34;}\viewkind4\uc1\pard
\f0
\fs20\cf1
\cf1 \uc1\u10004*\line
}", generatedRtf);
        }
Пример #25
0
        bool CopyTextToClipboard(string stringToCopy)
        {
            if (stringToCopy.Length > 0)
            {
                DataObject dataObject = new DataObject();
                dataObject.SetData(DataFormats.UnicodeText, true, stringToCopy);
                // Default has no highlighting, therefore we don't need RTF output
                if (textArea.Document.HighlightingStrategy.Name != "Default")
                {
                    dataObject.SetData(DataFormats.Rtf, RtfWriter.GenerateRtf(textArea));
                }
                OnCopyText(new CopyTextEventArgs(stringToCopy));

                // Work around ExternalException bug. (SD2-426)
                // Best reproducable inside Virtual PC.
                // SetDataObject has "retry" parameters, but apparently a call to "DoEvents"
                // is necessary for the workaround to work.
                int i = 0;
                while (true)
                {
                    try {
                        Clipboard.SetDataObject(dataObject, true, 5, 50);
                        return(true);
                    } catch (ExternalException) {
                        if (i++ > 5)
                        {
                            throw;
                        }
                    }
                    System.Threading.Thread.Sleep(50);
                    Application.DoEvents();
                    System.Threading.Thread.Sleep(50);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #26
0
        public void TestSimpleCSharpRtf()
        {
            if (Platform.IsWindows)
            {
                Assert.Inconclusive();
            }
            var data = Create("class Foo {}");
            //data.ColorStyle = SyntaxModeService.GetColorStyle ("Tango");
            //data.Document.SyntaxMode = SyntaxModeService.GetSyntaxMode (data.Document, "text/x-csharp");
            string generatedRtf = RtfWriter.GenerateRtf(data);

            Assert.AreEqual(
                @"{\rtf1\ansi\deff0\adeflang1025
{\fonttbl
{\f0\fnil\fprq1\fcharset128 Mono;}
}
{\colortbl ;\red51\green100\blue164;\red34\green34\blue34;}\viewkind4\uc1\pard
\f0
\fs20\cf1
\cf1 class\cf2  Foo \{\}\line
}", generatedRtf);
        }
Пример #27
0
        /**
         * @see com.lowagie.text.rtf.RtfField#write(com.lowagie.text.rtf.RtfWriter, java.io.Stream)
         */
        public void Write(RtfWriter writer, Stream outp)
        {
            if (!hideText)
            {
                writer.WriteInitialFontSignature(outp, new Chunk("", contentFont));
                byte[] t = DocWriter.GetISOBytes(RtfWriter.FilterSpecialChar(Content, true));
                outp.Write(t, 0, t.Length);
                writer.WriteFinishingFontSignature(outp, new Chunk("", contentFont));
            }

            if (!entryFont.Equals(contentFont))
            {
                writer.WriteInitialFontSignature(outp, new Chunk("", entryFont));
                WriteField(outp);
                writer.WriteFinishingFontSignature(outp, new Chunk("", entryFont));
            }
            else
            {
                writer.WriteInitialFontSignature(outp, new Chunk("", contentFont));
                WriteField(outp);
                writer.WriteFinishingFontSignature(outp, new Chunk("", contentFont));
            }
        }
Пример #28
0
        bool CopyTextToClipboard(string stringToCopy)
        {
            bool ret = false;

            if (stringToCopy.Length > 0)
            {
                DataObject dataObject = new DataObject();
                dataObject.SetData(DataFormats.UnicodeText, true, stringToCopy);

                // Default has no highlighting, therefore we don't need RTF output
                if (textArea.Document.HighlightingStrategy.Name != "Default")
                {
                    dataObject.SetData(DataFormats.Rtf, RtfWriter.GenerateRtf(textArea));
                }

                OnCopyText(new CopyTextEventArgs(stringToCopy));

                SafeSetClipboard(dataObject);
                ret = true;
            }

            return(ret);
        }
Пример #29
0
        public void Write(RtfWriter writer, Stream str)
        {
            if (!hideText)
            {
                writer.writeInitialFontSignature(str, new Chunk("", contentFont));
                str.Write(ASCIIEncoding.ASCII.GetBytes(RtfWriter.filterSpecialChar(content.ToString())), 0,
                          ASCIIEncoding.ASCII.GetBytes(RtfWriter.filterSpecialChar(content.ToString())).Length);
                writer.writeFinishingFontSignature(str, new Chunk("", contentFont));
            }

            if (!entryFont.Equals(contentFont))
            {
                writer.writeInitialFontSignature(str, new Chunk("", entryFont));
                writeField(str);
                writer.writeFinishingFontSignature(str, new Chunk("", entryFont));
            }
            else
            {
                writer.writeInitialFontSignature(str, new Chunk("", contentFont));
                writeField(str);
                writer.writeFinishingFontSignature(str, new Chunk("", contentFont));
            }
        }
        private bool CopyTextToClipboard(string stringToCopy, bool asLine)
        {
            if (stringToCopy.Length <= 0)
            {
                return(false);
            }
            DataObject dataObject = new DataObject();

            dataObject.SetData(DataFormats.UnicodeText, true, stringToCopy);
            if (asLine)
            {
                MemoryStream memoryStream = new MemoryStream(1);
                memoryStream.WriteByte(1);
                dataObject.SetData("MSDEVLineSelect", false, memoryStream);
            }
            if (this.textArea.Document.HighlightingStrategy.Name != "Default")
            {
                dataObject.SetData(DataFormats.Rtf, RtfWriter.GenerateRtf(this.textArea));
            }
            this.OnCopyText(new CopyTextEventArgs(stringToCopy));
            TextAreaClipboardHandler.SafeSetClipboard(dataObject);
            return(true);
        }