Exemple #1
0
        /// <summary>Return the next token in the stream</summary>
        public TokenClass GetToken()
        {
            if (pushed_class != TokenClass.None)
            {
                this.rtf_class    = this.pushed_class;
                this.major        = this.pushed_major;
                this.minor        = this.pushed_minor;
                this.param        = this.pushed_param;
                this.pushed_class = TokenClass.None;
                return(this.rtf_class);
            }

            GetToken2();

            if (this.rtf_class == TokenClass.Text)
            {
                this.minor = (Minor)this.cur_charset[(int)this.major];
            }

            if (this.cur_charset.Flags == CharsetFlags.None)
            {
                return(this.rtf_class);
            }

            if (((this.cur_charset.Flags & CharsetFlags.Read) != 0) && CheckCM(TokenClass.Control, Major.CharSet))
            {
                this.cur_charset.ReadMap();
            }
            else if (((this.cur_charset.Flags & CharsetFlags.Switch) != 0) && CheckCMM(TokenClass.Control, Major.CharAttr, Minor.FontNum))
            {
                Font fp;

                fp = Font.GetFont(this.font_list, this.param);

                if (fp != null)
                {
                    if (fp.Name.StartsWith("Symbol"))
                    {
                        this.cur_charset.ID = CharsetType.Symbol;
                    }
                    else
                    {
                        this.cur_charset.ID = CharsetType.General;
                    }
                }
                else if (((this.cur_charset.Flags & CharsetFlags.Switch) != 0) && (this.rtf_class == TokenClass.Group))
                {
                    switch (this.major)
                    {
                    case Major.BeginGroup: {
                        this.charset_stack.Push(this.cur_charset);
                        break;
                    }

                    case Major.EndGroup: {
                        this.cur_charset = (Charset)this.charset_stack.Pop();
                        break;
                    }
                    }
                }
            }

            return(this.rtf_class);
        }
Exemple #2
0
        /// <summary>Return the next token in the stream</summary>
        public TokenClass GetToken()
        {
            if (pushed_class != TokenClass.None)
            {
                this.rtf_class    = this.pushed_class;
                this.major        = this.pushed_major;
                this.minor        = this.pushed_minor;
                this.param        = this.pushed_param;
                this.pushed_class = TokenClass.None;
                return(this.rtf_class);
            }

            GetToken2();

            if (this.rtf_class == TokenClass.Text)
            {
                this.minor = (Minor)this.cur_charset[(int)this.major];
                if (encoding == null)
                {
                    encoding = Encoding.GetEncoding(encoding_code_page);
                }
                encoded_text = new String(encoding.GetChars(new byte [] { (byte)this.major }));
            }

            if (this.cur_charset.Flags == CharsetFlags.None)
            {
                return(this.rtf_class);
            }

            if (CheckCMM(TokenClass.Control, Major.Unicode, Minor.UnicodeAnsiCodepage))
            {
                encoding_code_page = param;

                // fallback to the default one in case we have an invalid value
                if (encoding_code_page < 0 || encoding_code_page > 65535)
                {
                    encoding_code_page = DefaultEncodingCodePage;
                }
            }

            if (((this.cur_charset.Flags & CharsetFlags.Read) != 0) && CheckCM(TokenClass.Control, Major.CharSet))
            {
                this.cur_charset.ReadMap();
            }
            else if (((this.cur_charset.Flags & CharsetFlags.Switch) != 0) && CheckCMM(TokenClass.Control, Major.CharAttr, Minor.FontNum))
            {
                Font fp;

                fp = Font.GetFont(this.font_list, this.param);

                if (fp != null)
                {
                    if (fp.Name.StartsWith("Symbol"))
                    {
                        this.cur_charset.ID = CharsetType.Symbol;
                    }
                    else
                    {
                        this.cur_charset.ID = CharsetType.General;
                    }
                }
                else if (((this.cur_charset.Flags & CharsetFlags.Switch) != 0) && (this.rtf_class == TokenClass.Group))
                {
                    switch (this.major)
                    {
                    case Major.BeginGroup: {
                        this.charset_stack.Push(this.cur_charset);
                        break;
                    }

                    case Major.EndGroup: {
                        this.cur_charset = (Charset)this.charset_stack.Pop();
                        break;
                    }
                    }
                }
            }

            return(this.rtf_class);
        }
Exemple #3
0
        /// <summary>Return the next token in the stream</summary>
        public TokenClass GetToken()
        {
            if (pushed_class != TokenClass.None)
            {
                this.rtf_class    = this.pushed_class;
                this.major        = this.pushed_major;
                this.minor        = this.pushed_minor;
                this.param        = this.pushed_param;
                this.pushed_class = TokenClass.None;
                return(this.rtf_class);
            }

            GetToken2();

            if (this.rtf_class == TokenClass.Text)
            {
                if (encoding == null)
                {
                    encoding = Encoding.GetEncoding(encoding_code_page);
                }
                encoded_text = new String(encoding.GetChars(new byte [] { (byte)this.major }));
            }
            else if (CheckCMM(TokenClass.Control, Major.Unicode, Minor.UnicodeAnsiCodepage))
            {
                encoding_code_page = param;

                // fallback to the default one in case we have an invalid value
                if (encoding_code_page < 0 || encoding_code_page > 65535)
                {
                    encoding_code_page = DefaultEncodingCodePage;
                }

                encoding = null;
            }
            else if (CheckCMM(TokenClass.Control, Major.CharAttr, Minor.FontNum))
            {
                Font fp;

                fp = Font.GetFont(this.fonts, this.param);

                if (fp != null)
                {
                    if (fp.Codepage != 0)
                    {
                        if (fp.Codepage != encoding_code_page)
                        {
                            encoding_code_page = fp.Codepage;
                            encoding           = null;
                        }
                    }
                    else
                    {
                        var cp = CharsetToCodepage.Translate(fp.Charset);
                        if (cp != 0 && cp != encoding_code_page)
                        {
                            encoding_code_page = cp;
                            encoding           = null;
                        }
                    }
                }
            }
            else if (this.rtf_class == TokenClass.Group)
            {
                switch (this.major)
                {
                case Major.BeginGroup: {
                    charset_stack.Push(encoding_code_page);
                    break;
                }

                case Major.EndGroup: {
                    if (charset_stack.Count > 0)
                    {
                        encoding_code_page = (int)this.charset_stack.Pop();
                    }
                    else
                    {
                        encoding_code_page = DefaultEncodingCodePage;
                    }
                    if (encoding != null && encoding.CodePage != encoding_code_page)
                    {
                        encoding = null;
                    }
                    break;
                }
                }
            }

            return(this.rtf_class);
        }