Ejemplo n.º 1
0
        private void ParseRtfString(string rtf)
        {
            Regex regex;

            if (rtf.StartsWith(@"{\rtf1"))
            {
                regex = new Regex(@"\\[a-z]+\s.");
            }
            else
            {
                regex = new Regex(@".");
            }
            MatchCollection matchs = regex.Matches(rtf);

            m_rtfFormatList.Clear();
            RtfFormat.count        = 0;
            RtfFormat.regularcount = 0;
            foreach (Match match in matchs)
            {
                RtfFormat format = new RtfFormat();
                string    str    = match.ToString();
                int       split  = str.IndexOf(" ");
                if (split == -1)
                {
                    format.prefix = str.Substring(0, split + 1);
                }
                else
                {
                    format.prefix = str.Substring(0, split);
                }
                format.content = str.Substring(split + 1, str.Length - split - 1);
                if (format.prefix == RtfEncoding.RtfNoSuperSub || format.prefix == string.Empty)
                {
                    RtfFormat.regularcount++;
                }
                RtfFormat.count++;
                m_rtfFormatList.Add(format);
            }
        }
Ejemplo n.º 2
0
        private void CalcRtfDrawingInfo(ArrayList rtfformats, Size size)
        {
            //ÊÊÓ¦ÐÔµ÷Õû»æ»­×ÖÌå,ÒÔʹͼÏñËõ·ÅÖÁÔ¤¶©´óС¡£
            AdjustDrawEnv(size);
            //¼ÆËãÊ××Ö·û»æ»­Î»ÖÃ
            float startx = (size.Width - RtfFormat.CalcRtfDrawingLen(m_font, m_superSubFont)) / 2;
            float starty = (size.Height - m_font.Size) / 2;

            //¼ÆËã¸÷×Ö·ûµÄ»æ»­ÐÅÏ¢
            for (int index = 0; index < m_rtfFormatList.Count; index++)
            {
                RtfFormat format = (RtfFormat)m_rtfFormatList[index];
                switch (format.prefix)
                {
                case RtfEncoding.RtfSuper:
                    format.font = m_superSubFont;
                    format.px   = startx;
                    format.py   = starty;
                    break;

                case RtfEncoding.RtfSub:
                    format.font = m_superSubFont;
                    format.px   = startx;
                    format.py   = starty + (m_font.Size - m_superSubFont.Size) + DrawPlus;
                    break;

                default:
                    format.font = m_font;
                    format.px   = startx;
                    format.py   = starty;
                    break;
                }
                m_rtfFormatList[index] = format;
                //¼ÆËãÏÂÒ»·ûºÅλÖÃ
                startx += format.font.Size - DrawPlus;
            }
        }