コード例 #1
0
        public Link(List <Formated> s, float emSize, FontStyle style)
        {
            int count = 1;

            for (int i = s.Count - 1; i >= 0; i--)
            {
                if (s[i].s == ']')
                {
                    count = i; break;
                }
            }
            ;
            List <Control> v = new List <Control>();
            bool           isLink = false;
            string         link = "", context = "";

            for (int k = s.Count - 2; k >= count + 2; k--)
            {
                if (s[k - 1].s == ' ' && s[k].s == '\"')
                {
                    isLink = true; k -= 2;
                }
                if (isLink)
                {
                    link = s[k].s + link;
                }
                else
                {
                    context = s[k].s + context;
                }
            }
            if (!isLink)
            {
                link = context; context = "";
            }
            else
            {
                try { context = context.Remove(context.Length - 1, 1); } catch { }
            }
            List <ImageText> imageTexts = new List <ImageText>();
            List <int>       q          = new List <int>();

            for (int i = 1; i < s.Count; i++)
            {
                int end;
                if (s[i].s == '!')
                {
                    if (LinesText.isImage(s.GetRange(i + 1, count - i), out end))
                    {
                        imageTexts.Add(new ImageText(s.GetRange(i, end + 2), link, Form1.emSize, style));
                        q.Add(i);
                        s.RemoveRange(i, end + 2);
                        count -= end + 2;
                        i--;
                    }
                }
            }
            int st = 0;

            for (int i = 1; i < count; i++)
            {
                string current = "";
                for (int j = i; true; j++)
                {
                    bool tr = false;
                    while (q.Count > st && j == q[st])
                    {
                        if (current != "")
                        {
                            tr = true;
                            v.Add(new LinkLabel());
                            v[v.Count - 1].AutoSize = true;
                            try { (v[v.Count - 1] as LinkLabel).Links.Add(0, v[v.Count - 1].Text.Length, link); } catch { }
                            v[v.Count - 1].ContextMenuStrip = new ContextMenuStrip();
                            try { v[v.Count - 1].ContextMenuStrip.Text = context; } catch { v[v.Count - 1].ContextMenuStrip.Text = ""; }
                            (v[v.Count - 1] as LinkLabel).LinkClicked += new LinkLabelLinkClickedEventHandler(LinkClicked);
                            v[v.Count - 1].MouseHover += new EventHandler(LinkMouseHover);
                            v[v.Count - 1].MouseLeave += new EventHandler(LinkMouseLeave);
                            current             = current.Replace((char)(65534), '*');
                            current             = current.Replace((char)(65533), '~');
                            current             = current.Replace((char)(65535), '_');
                            v[v.Count - 1].Text = current;
                            current             = "";
                            v[v.Count - 1].Font = new Font(Form1.baseFamilyName, emSize, style | Format(s[i].isItalic, s[i].isBolt, s[i].isStricedOut, s[i].isUnderLine), System.Drawing.GraphicsUnit.Point, ((byte)(204)));
                            i = j - 1;
                        }
                        v.Add(imageTexts[st].value);
                        st++;
                    }
                    if (tr)
                    {
                        break;
                    }
                    if (j < count && s[i].isBolt == s[j].isBolt && s[i].isItalic == s[j].isItalic && s[i].isStricedOut == s[j].isStricedOut && s[i].isUnderLine == s[j].isUnderLine)
                    {
                        current += s[j].s;
                    }
                    else
                    {
                        v.Add(new LinkLabel());
                        v[v.Count - 1].AutoSize = true;
                        try { (v[v.Count - 1] as LinkLabel).Links.Add(0, v[v.Count - 1].Text.Length, link); } catch { }
                        v[v.Count - 1].ContextMenuStrip = new ContextMenuStrip();
                        try { v[v.Count - 1].ContextMenuStrip.Text = context; } catch { v[v.Count - 1].ContextMenuStrip.Text = ""; }
                        (v[v.Count - 1] as LinkLabel).LinkClicked += new LinkLabelLinkClickedEventHandler(LinkClicked);
                        v[v.Count - 1].MouseHover += new EventHandler(LinkMouseHover);
                        v[v.Count - 1].MouseLeave += new EventHandler(LinkMouseLeave);
                        current             = current.Replace((char)(65534), '*');
                        current             = current.Replace((char)(65533), '~');
                        current             = current.Replace((char)(65535), '_');
                        v[v.Count - 1].Text = current;
                        current             = "";
                        v[v.Count - 1].Font = new Font(Form1.baseFamilyName, emSize, style | Format(s[i].isItalic, s[i].isBolt, s[i].isStricedOut, s[i].isUnderLine), System.Drawing.GraphicsUnit.Point, ((byte)(204)));
                        i = j - 1;
                        break;
                    }
                }
            }
            for (; st < imageTexts.Count; st++)
            {
                v.Add(imageTexts[st].value);
            }
            value = new LinkControl(v, (int)(emSize));
        }
コード例 #2
0
ファイル: ImageText.cs プロジェクト: igorek240101/MIND
        public ImageText(List <Formated> s, string l, float emSize, FontStyle style)
        {
            int count = 2;

            for (int i = s.Count - 1; i >= 2; i--)
            {
                if (s[i].s == ']')
                {
                    count = i; break;
                }
            }
            ;
            Image          image = null;
            string         link = "", context = "";
            List <Control> v      = new List <Control>();
            bool           isLink = true;

            for (int k = s.Count - 2; k >= count + 2; k--)
            {
                if (s[k - 1].s == ' ' && s[k].s == '\"')
                {
                    isLink = true; k -= 3;
                }
                if (isLink)
                {
                    link = s[k].s + link;
                }
                else
                {
                    context = s[k].s + context;
                }
            }
            if (!isLink)
            {
                link = context;
            }
            context = "";


            List <Link> links = new List <Link>();
            List <int>  q     = new List <int>();

            for (int i = 2; i < count; i++)
            {
                int end;
                if (s[i].s == '[')
                {
                    if (LinesText.isLink(s.GetRange(i + 1, count - i), out end))
                    {
                        links.Add(new Link(s.GetRange(i, end + 2), emSize, FontStyle.Regular));
                        q.Add(i);
                        s.RemoveRange(i, end + 2);
                        count -= end + 2;
                        i--;
                    }
                }
            }
            int st = 0;

            for (int i = 2; i < count; i++)
            {
                string current = "";
                for (int j = i; true; j++)
                {
                    bool tr = false;
                    while (q.Count > st && j == q[st])
                    {
                        if (current != "")
                        {
                            tr = true;
                            v.Add(new Label());
                            v[v.Count - 1].AutoSize = true;
                            current             = current.Replace((char)(65534), '*');
                            current             = current.Replace((char)(65533), '~');
                            current             = current.Replace((char)(65535), '_');
                            v[v.Count - 1].Text = current;
                            current             = "";
                            v[v.Count - 1].Font = new Font(Form1.baseFamilyName, emSize, style | Format(s[i].isItalic, s[i].isBolt, s[i].isStricedOut, s[i].isUnderLine), System.Drawing.GraphicsUnit.Point, ((byte)(204)));
                            i = j - 1;
                        }
                        v.Add(links[st].value);
                        st++;
                    }
                    if (tr)
                    {
                        break;
                    }
                    if (j < count && s[i].isBolt == s[j].isBolt && s[i].isItalic == s[j].isItalic && s[i].isStricedOut == s[j].isStricedOut && s[i].isUnderLine == s[j].isUnderLine)
                    {
                        current += s[j].s;
                    }
                    else
                    {
                        v.Add(new Label());
                        v[v.Count - 1].AutoSize = true;
                        current             = current.Replace((char)(65534), '*');
                        current             = current.Replace((char)(65533), '~');
                        current             = current.Replace((char)(65535), '_');
                        v[v.Count - 1].Text = current;
                        current             = "";
                        v[v.Count - 1].Font = new Font(Form1.baseFamilyName, emSize, style | Format(s[i].isItalic, s[i].isBolt, s[i].isStricedOut, s[i].isUnderLine), System.Drawing.GraphicsUnit.Point, ((byte)(204)));
                        i = j - 1;
                        break;
                    }
                }
            }
            try
            {
                image = Image.FromFile(link);
            }
            catch
            {
                try
                {
                    WebClient    webClient = new WebClient();
                    byte[]       data      = webClient.DownloadData(link);
                    MemoryStream mem       = new MemoryStream(data);
                    image = Image.FromStream(mem);
                }
                catch
                {
                    image   = Image.FromFile(Application.StartupPath + "\\Resourse\\defaultf.jpg");
                    context = "Извините, но я чайник, и я не могу загрузить ваше изображение:(";
                }
            }
            for (; st < links.Count; st++)
            {
                v.Add(links[st].value);
            }
            value = new ImageTextControl(v, image, context, l);
        }