/// <summary> /// Indicate if <paramref name="TQText"/> has a color tag prefix. /// </summary> /// <param name="TQText"></param> /// <returns></returns> public static bool HasColorPrefix(this string TQText) { if (TQText is null) { return(false); } var t = TQColorHelper.GetColorFromTaggedString(TQText); return(t.HasValue); }
/// <summary> /// Wraps the words in a text description. /// </summary> /// <param name="TQText">Text to be word wrapped</param> /// <param name="Columns">maximum number of columns before wrapping</param> /// <returns>List of wrapped text</returns> public static Collection <string> WrapWords(string TQText, int Columns) { List <string> choppedLines = new List <string>(); // First split on NL tag choppedLines.AddRange(SplitOnTQNewLine(TQText)); // split on columns args length choppedLines = choppedLines.SelectMany(t => SplitOnColumns(t)).ToList(); IEnumerable <string> SplitOnColumns(string t) { if (t.Length > Columns) { // split on spaces var batch = Regex.Split(t, @"\s+"); string line = string.Empty; string currentColor = string.Empty; List <string> res = new List <string>(); foreach (var word in batch) { var foundColor = TQColorHelper.GetColorFromTaggedString(word); if (line != string.Empty // Not a ColorTag alone && !line.IsColorTagOnly() ) { line += ' '; } if (foundColor.HasValue) { currentColor = foundColor?.ColorTag(); } if (line.Length + word.Length > Columns) { res.Add(line); line = currentColor + string.Empty; } line += word; } res.Add(line); // remnant return(res); } else { return new string[] { t } }; } return(new Collection <string>(choppedLines)); } }
/// <summary> /// Gets a color tag for a line of text /// </summary> /// <param name="text">text containing the color tag</param> /// <returns>System.Drawing.Color of the embedded color code</returns> public static Color GetColor(this Item itm, string text) { if (string.IsNullOrEmpty(text)) { // Use the standard color code for the item return(itm.ItemStyle.Color()); } // Look for a formatting tag in the beginning of the string TQColor?colorCode = TQColorHelper.GetColorFromTaggedString(text); // We didn't find a code so use the standard color code for the item if (colorCode is null) { return(itm.ItemStyle.Color()); } // We found something so lets try to find the code return(colorCode.Value.Color()); }