public static text_part from_friendly_string(string str) {
text_part friendly = new text_part(0,0);
foreach (string word in str.Split('/').Select(x => x.ToLower())) {
if (friendly.font_name == "") {
var possible_font = util.font_families().FirstOrDefault(x => x.ToLower() == word);
if (possible_font != null) {
friendly.font_name = possible_font;
continue;
}
}
int possible_size = 0;
if ( int.TryParse(word, out possible_size))
// don't allow too huge sizes
if (possible_size > 5 && possible_size < 24) {
friendly.font_size = possible_size;
continue;
}
bool word_recognized = true;
switch (word) {
case "bold":
friendly.bold = true;
break;
case "italic":
friendly.italic = true;
break;
case "underline":
friendly.underline = true;
break;
case "darker":
friendly.modify_fg = modify_color_type.darker;
break;
case "lighter":
friendly.modify_fg = modify_color_type.lighter;
break;
case "darker-bg":
friendly.modify_bg = modify_color_type.darker;
break;
case "lighter-bg":
friendly.modify_bg = modify_color_type.lighter;
break;
default:
word_recognized = false;
break;
}
if (word_recognized)
continue;
bool force_bg = word.StartsWith("##");
Color col = util.str_to_color(force_bg ? word.Substring(1) : word);
if (col != util.transparent) {
bool is_bg = force_bg || friendly.fg != util.transparent;
if (is_bg)
friendly.bg = col;
else
friendly.fg = col;
continue;
}
}
return friendly;
}