Esempio n. 1
0
        // methods

        //-------------------------------------------------
        //  actual_left
        //-------------------------------------------------
        public float actual_left()
        {
            if (m_current_line != null)
            {
                // TODO: is there a sane way to allow an open line to be temporarily finalised and rolled back?
                m_current_line.align_text(this);
                m_current_line = null;
            }

            if (empty()) // degenerate scenario
            {
                return(0.0f);
            }

            float result = 1.0f;

            foreach (var line in m_lines)
            {
                if (line.width() != 0)
                {
                    result = std.min(result, line.xoffset(this));
                }
            }
            return(result);
        }
Esempio n. 2
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);
        }