// methods //------------------------------------------------- // add_text //------------------------------------------------- void add_text(string text, char_style style) { UInt32 position = 0; UInt32 text_length = (UInt32)text.Length; while (position < text_length) { // 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) { // get the current character char schar; //char32_t schar; int scharcount = unicode_global.uchar_from_utf8(out schar, text.Substring((int)position), (int)(text_length - position)); // &text[position] if (scharcount < 0) { break; } // if the line starts with a tab character, center it regardless text_justify line_justify = justify(); if (schar == '\t') { position += (UInt32)scharcount; line_justify = text_justify.CENTER; } // start a new line start_new_line(line_justify, style.size); } { // get the current character char ch; //char32_t ch; int scharcount = unicode_global.uchar_from_utf8(out ch, text.Substring((int)position), (int)(text_length - position)); // &text[position], text_length - position); if (scharcount < 0) { break; } position += (UInt32)scharcount; // set up source information source_info source; source.start = m_text_position; source.span = (UInt32)scharcount; m_text_position += (UInt32)scharcount; // is this an endline? if (ch == '\n') { // first, start a line if we have not already if (m_current_line == null) { start_new_line(text_justify.LEFT, style.size); } // and then close up the current line m_current_line = null; } else if (!m_truncating) { // if we hit a space, remember the location and width *without* the space if (is_space_character(ch)) { m_last_break = m_current_line.character_count(); } // append the character m_current_line.add_character(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; default: fatalerror("invalid word wrapping value"); break; } } else { // we didn't wrap - if we hit any non-space breakable character, remember the location and width // *with* the breakable character if (ch != ' ' && is_breakable_char(ch)) { m_last_break = m_current_line.character_count(); } } } } } }
//------------------------------------------------- // 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(); } } } } }