示例#1
0
        //-------------------------------------------------
        //  add_text
        //-------------------------------------------------
        void add_text(string text, text_justify line_justify, char_style style)
        {
            while (!text.empty())
            {
                // adding a character - we might change the width
                invalidate_calculated_actual_width();

                // do we need to create a new line?
                if (m_current_line == null)
                {
                    start_new_line(style.size);
                }

                m_current_line.set_justification(line_justify);

                // get the current character
                char ch;  //char32_t ch;
                int  scharcount = uchar_from_utf8(out ch, text);
                if (scharcount < 0)
                {
                    break;
                }

                text = text.remove_prefix_((size_t)scharcount);

                // set up source information
                source_info source = new source_info()
                {
                    start = 0, span = 0
                };
                source.start     = m_text_position;
                source.span      = (size_t)scharcount;
                m_text_position += (size_t)scharcount;

                // is this an endline?
                if (ch == '\n')
                {
                    // close up the current line
                    m_current_line.align_text(this);
                    m_current_line = null;
                }
                else if (!m_truncating)
                {
                    // if we hit a space, remember the location and width *without* the space
                    bool is_space = is_space_character(ch);
                    if (is_space)
                    {
                        m_last_break = m_current_line.character_count();
                    }

                    // append the character
                    m_current_line.add_character(this, ch, style, source);

                    // do we have to wrap?
                    if ((wrap() != word_wrapping.NEVER) && (m_current_line.width() > m_width))
                    {
                        switch (wrap())
                        {
                        case word_wrapping.TRUNCATE:
                            truncate_wrap();
                            break;

                        case word_wrapping.WORD:
                            word_wrap();
                            break;

                        case word_wrapping.NEVER:
                            // can't happen due to if condition, but compile warns about it
                            break;
                        }
                    }
                    else
                    {
                        // we didn't wrap - if we hit any non-space breakable character,
                        // remember the location and width *with* the breakable character
                        if (!is_space && is_breakable_char(ch))
                        {
                            m_last_break = m_current_line.character_count();
                        }
                    }
                }
            }
        }