Beispiel #1
0
            // methods

            //-------------------------------------------------
            //  line::add_character
            //-------------------------------------------------
            public void add_character(char32_t ch, char_style style, source_info source)
            {
                // get the width of this character
                float chwidth = m_layout.get_char_width(ch, style.size);

                // create the positioned character
                positioned_char positioned_char;

                positioned_char.character = ch;
                positioned_char.xoffset   = m_width;
                positioned_char.xwidth    = chwidth;
                positioned_char.style     = style;
                positioned_char.source    = source;

                // append the character
                m_characters.push_back(positioned_char);
                m_width += chwidth;

                // we might be bigger
                m_height = Math.Max(m_height, style.size * m_layout.yscale());
            }
Beispiel #2
0
            // methods

            //-------------------------------------------------
            //  line::add_character
            //-------------------------------------------------
            public void add_character(text_layout layout, char32_t ch, char_style style, source_info source)
            {
                // get the width of this character
                float chwidth = layout.get_char_width(ch, style.size);

                // append the positioned character
                m_characters.emplace_back(new positioned_char()
                {
                    character = ch, style = style, source = source, xoffset = m_width, xwidth = chwidth
                });
                m_width += chwidth;

                // we might be bigger
                m_height = std.max(m_height, style.size * layout.yscale());
            }
Beispiel #3
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();
                        }
                    }
                }
            }
        }