Example #1
0
        public Test()
        {
            MemoryStream stream;
            RTF          rtf;

            byte[] buffer;

            text = new TextMap();
            TextMap.SetupStandardTable(text.Table);

            buffer = new byte[rtf_string.Length];
            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i] = (byte)rtf_string[i];
            }
            stream = new MemoryStream(buffer);
            rtf    = new RTF(stream);

            skip_width = 0;
            skip_count = 0;

            rtf.ClassCallback[TokenClass.Text]    = new ClassDelegate(HandleText);
            rtf.ClassCallback[TokenClass.Control] = new ClassDelegate(HandleControl);

            rtf.Read();

            stream.Close();
        }
Example #2
0
        public Test(string[] args)
        {
            if (args.Length == 0)
            {
                throw new Exception("Program needs path to rtf file as argument");
            }

            FileStream stream;
            RTF        rtf;

            text = new TextMap();
            TextMap.SetupStandardTable(text.Table);

            stream = new FileStream(@"../test.rtf", FileMode.Open);
            rtf    = new RTF(stream);

            skip_width = 0;
            skip_count = 0;

            rtf.ClassCallback[TokenClass.Text]    = new ClassDelegate(HandleText);
            rtf.ClassCallback[TokenClass.Control] = new ClassDelegate(HandleControl);

            rtf.Read();

            stream.Close();
        }
Example #3
0
        private void InsertRtfFromStream(Stream data, int cursorX, int cursorY, out int toX, out int toY, out int charCount)
        {
            // Prepare
            rtfParser.ClassCallback[TokenClass.Text]    = HandleText;
            rtfParser.ClassCallback[TokenClass.Control] = HandleControl;
            rtfParser.ClassCallback[TokenClass.Group]   = HandleGroup;

            _skipCount              = 0;
            _line                   = new StringBuilder();
            _style.Color            = Xwt.Drawing.Colors.Black;
            _style.FontSize         = 10;
            _style.Align            = Alignment.Start;
            _style.SectionAttribute = SectionAttribute.Regular;
            _style.FontName         = null;
            _style.Visible          = true;
            _style.SkipWidth        = 1;
            _cursorX                = cursorX;
            _cursorY                = cursorY;
            _charCount              = 0;
            rtfParser.DefaultFont("Tahoma");

            _textMap = new TextMap();
            TextMap.SetupStandardTable(_textMap.Table);

            try {
                rtfParser.Read();       // That's it
                FlushText(rtfParser, false);
            } catch (RTFException e) {
#if DEBUG
                throw e;
#endif
                // Seems to be plain text or broken RTF
                Trace.WriteLine("RTF Parsing failure: {0}", e.Message);
            }

            toX       = _cursorX;
            toY       = _cursorY;
            charCount = _charCount;

            // clear the section stack if it was used
            if (_sectionStack != null)
            {
                _sectionStack.Clear();
            }
        }
Example #4
0
        void Init()
        {
            rtf = new RTF(Stream);

            if (text_map == null)
            {
                text_map = new TextMap();
                TextMap.SetupStandardTable(text_map.Table);
            }

            sb             = new StringBuilder();
            sb.Length      = 0;
            group_stack    = new Stack <bool> ();
            current_is_hot = false;

            skip_width = 0;
            skip_count = 0;
        }