Exemple #1
0
        void print(string txt, string link, bool newline, Color color, bool strikeout)
        {
            if (txt == "")
                txt = " "; //blank line

            if (lastChunk == -1)
                lastChunk = 0;

            while (txt.Contains("<image="))
            {
                //split into chunks
                int lb = txt.IndexOf("<image=");

                if (lb != 0)
                    print(txt.Substring(0, lb), link, false, color, strikeout); //print text before image

                lb += 7;
                int ub = txt.IndexOf('>', lb);

                if (ub != -1)
                {
                    //print img
                    string imgLocation = txt.Substring(lb, ub - lb);

                    if (link == "")
                    {
                        link = imgLocation;

                        if (link.Contains("pbs.twimg.com"))
                            link += ":large"; //open large versions of Twitter images
                    }

                    Chunk imgChunk = new Chunk(imgLocation, link, newline && ub == txt.Length - 1, newline);

                    //can img fit in current line?
                    if (leftMargin + imgChunk.GetWidth(true) > this.Width && chunks.Count > 0)
                        chunks[chunks.Count - 1].InsertNewline(); //nope, send img to next line

                    chunks.Add(imgChunk);

                    if (newline && ub == txt.Length - 1)
                        leftMargin = 0;
                    else
                        leftMargin += imgChunk.GetWidth(true);

                    showNewChunks();

                    txt = txt.Substring(ub + 1);
                    if (txt == "")
                        return;
                }
                else
                    break;
            }

            if (timerPrint.Interval == ZERO_DELAY)
                txt = txt.Replace("<pause>", "");
            else
                txt = txt.Replace("<pause>", Environment.NewLine + "<pause>" + Environment.NewLine);

            string[] lines = txt.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < lines.Length; i++)
            {
                bool nLine = i == lines.Length - 1 ? newline : true;
                List<Chunk> newChunks = Chunk.Chunkify(lines[i], link, color, strikeout, leftMargin, nLine, nLine);

                chunks.AddRange(newChunks);

                if (nLine)
                    leftMargin = 0;
                else
                {
                    if (newChunks.Count > 1)
                        leftMargin = 0;

                    leftMargin += newChunks[newChunks.Count - 1].GetWidth();
                }
            }

            showNewChunks();
        }