Beispiel #1
0
        private static int EmitDialoguePage(string dialogue, int start, int linesPerPage, Font font, float maxWidth, List <string> o_results)
        {
            // Count the number of lines needed to emit the dialogue
            int endPos = start;
            int lines  = 0;

            while (endPos < dialogue.Length)
            {
                endPos += font.WordWrap(dialogue, endPos, true, maxWidth);
                endPos += Font.AdvanceWhitespace(dialogue, endPos);
                if ((++lines) == linesPerPage)
                {
                    break;
                }
            }

            if (endPos < dialogue.Length)
            {
                // Clip to the end of the previous sentence
                int sentenceStart = start;
                while (sentenceStart < endPos)
                {
                    int sentenceEnd = sentenceStart + Font.AdvanceSentence(dialogue, sentenceStart);
                    if (sentenceEnd > endPos)
                    {
                        break;
                    }
                    else
                    {
                        sentenceStart = sentenceEnd + Font.AdvanceWhitespace(dialogue, sentenceEnd);
                    }
                }
                if (sentenceStart > start)
                {
                    endPos = sentenceStart;
                }
            }

            // Emit the lines
            int pos  = start;
            int line = 0;

            while (pos < endPos && line < linesPerPage)
            {
                int lineLen = font.WordWrap(dialogue, pos, (endPos - pos), true, maxWidth);
                o_results.Add(dialogue.Substring(pos, lineLen));
                pos += lineLen;
                pos += Font.AdvanceWhitespace(dialogue, pos);
                ++line;
            }
            while (line < linesPerPage)
            {
                o_results.Add("");
                ++line;
            }
            return(endPos - start);
        }