Beispiel #1
0
        //-------------------------------------------------
        //  word_wrap
        //-------------------------------------------------
        void word_wrap()
        {
            // keep track of the last line and break
            line   last_line  = m_current_line;
            size_t last_break = m_last_break != 0 ? m_last_break : (last_line.character_count() - 1);

            // start a new line with the same justification
            start_new_line(last_line.character(last_line.character_count() - 1).style.size);

            // find the beginning of the word to wrap
            size_t position = last_break;

            while ((last_line.character_count() > position) && is_space_character(last_line.character(position).character))
            {
                position++;
            }

            // carry over justification
            if (last_line.right_justify_start() <= position)
            {
                m_current_line.set_justification(text_justify.RIGHT);
            }
            else if (last_line.center_justify_start() <= position)
            {
                m_current_line.set_justification(text_justify.CENTER);
            }

            // transcribe the characters
            for (size_t i = position; i < last_line.character_count(); i++)
            {
                if (last_line.right_justify_start() == i)
                {
                    m_current_line.set_justification(text_justify.RIGHT);
                }
                else if (last_line.center_justify_start() == i)
                {
                    m_current_line.set_justification(text_justify.CENTER);
                }

                var ch = last_line.character(i);
                m_current_line.add_character(this, ch.character, ch.style, ch.source);
            }

            // and finally, truncate the previous line and adjust spacing
            last_line.truncate(last_break);
            last_line.align_text(this);
        }