Exemplo n.º 1
0
        public formatted_text copy()
        {
            formatted_text the_copy = new formatted_text(text)
            {
                bg_ = bg_, align = align, image = image, parts_ = parts_.Select(x => x.copy()).ToList()
            };

            the_copy.invariant_end();
            return(the_copy);
        }
Exemplo n.º 2
0
        // this updates text + infos, so that it will return a single line from a possible multi-line text
        // we want this, in case the text is multi-line, but we can only print A SINGLE LINE
        public formatted_text get_most_important_single_line()
        {
            string text  = text_;
            var    parts = parts_.ToList();

            if (!text.Contains('\r') && !text.Contains('\n'))
            {
                // text is single line
                return(new formatted_text(text, this));
            }


            char more  = '¶';
            var  lines = util.split_into_lines(text, util.split_into_lines_type.include_enter_chars_in_returned_lines).ToList();

            if (parts.Count == 0)
            {
                // in this case, we don't have any custom printing - just return the first non empty line
                text = lines.FirstOrDefault(x => x.Length > 0 && !util.any_enter_char.Contains(x[0]));
                if (text == null)
                {
                    // we only have empty lines
                    text = "";
                }
                else
                {
                    int line_idx = lines.IndexOf(text);
                    text = (line_idx > 0 && app.inst.show_paragraph_sign ? more + " " : "") + text.Trim() + (line_idx < lines.Count - 1 && app.inst.show_paragraph_sign ? " " + more : "");
                }
                return(new formatted_text(text, this));
            }

            // we have custom printing - first, see if we have typed search
            var relevant_print = parts.FirstOrDefault(x => x.is_typed_search || x.is_find_search);

            if (relevant_print == null)
            {
                relevant_print = parts[0];
            }

            // find the relevant line
            int    start         = 0;
            string relevant_line = null;

            foreach (var line in lines)
            {
                if (relevant_print.start < start + line.Length)
                {
                    relevant_line = line;
                    break;
                }
                else
                {
                    start += line.Length;
                }
            }
            Debug.Assert(relevant_line != null);
            bool line_before = start > 0;
            bool line_after  = start + relevant_line.Length < text.Length;

            // at this point, ignore enters
            relevant_line = relevant_line.Trim();
            int len = relevant_line.Length;

            // ... just take the print infos for the relevant line
            parts = parts.Where(x => (start <= x.start && x.start < start + len) || (start <= x.start + x.len && x.start + x.len < start + len)).ToList();
            if (parts.Count > 0)
            {
                // adjust first and last - they might be outside our line
                if (parts[0].start < start)
                {
                    parts[0] = new text_part(start, parts[0].len - (start - parts[0].start), parts[0]);
                }
                var last = parts[parts.Count - 1];
                if (last.start + last.len > start + len)
                {
                    parts[parts.Count - 1] = new text_part(last.start, start + len - last.start, last);
                }
            }

            if (!app.inst.show_paragraph_sign)
            {
                line_before = line_after = false;
            }

            // convert all the indexes into the relevant line
            for (int i = 0; i < parts.Count; ++i)
            {
                parts[i] = new text_part(parts[i].start - start + (line_before ? 2 : 0), parts[i].len, parts[i]);
            }

            text = (line_before ? more + " " : "") + relevant_line + (line_after ? " " + more : "");
            var result = new formatted_text(text, this, parts);

            result.invariant_end();
            return(result);
        }