Ejemplo n.º 1
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();
            }
        }