public InsertFont(string tag) : this() { ELFont font = ELFont.Parse(tag); if (font.font != null) { ddFont.Text = font.font; } if (font.size > 0) { ddFontSize.Text = font.size.ToString(); } if (font.alpha > 0) { ddAlpha.Text = font.alpha.ToString(); } if (font.color != Color.Empty) { lblColor.BackColor = font.color; } if (font.bgcolor != Color.Empty) { lblBackcolor.BackColor = font.bgcolor; } chkColor.Checked = (font.color != Color.Empty); chkBackcolor.Checked = (font.bgcolor != Color.Empty); SelectedFont = font; }
string fixFont(string expression) { string text = expression; try { text = text.Replace("</font>", "</span>"); Regex re = new Regex("<font(.+?)>", RegexOptions.IgnoreCase); Match m = re.Match(text); int pos = 0; while (m.Success) { ELFont font = ELFont.Parse(m.Value); string html = font.ToHTML(); text = text.Remove(m.Index, m.Length); text = text.Insert(m.Index, html); pos = m.Index + html.Length; m = re.Match(text, pos); } } catch (Exception ex) { throw ex; } return(text); }
public static ELFont Parse(string tag) { ELFont font = new ELFont(); if (tag == null) { return(font); } var p = Regex.Match(tag, @"\bsize\s*=\s*""?(\d+)%?""?", RegexOptions.IgnoreCase); if (p.Success) { font.size = int.Parse(p.Groups[1].Value); } p = Regex.Match(tag, @"\bcolor\s*=\s*""?#?([a-f0-9]+)""?", RegexOptions.IgnoreCase); if (p.Success) { font.color = ParseColor(p.Groups[1].Value); } p = Regex.Match(tag, @"\bbgcolor\s*=\s*""?#?([a-f0-9]+)""?", RegexOptions.IgnoreCase); if (p.Success) { font.bgcolor = ParseColor(p.Groups[1].Value); } p = Regex.Match(tag, @"\bface\s*=\s*""?([\w\s]+)""?", RegexOptions.IgnoreCase); if (p.Success) { font.font = p.Groups[1].Value; } p = Regex.Match(tag, @"\balpha\s*=\s*""?(\d+)%?""?", RegexOptions.IgnoreCase); if (p.Success) { font.alpha = int.Parse(p.Groups[1].Value); } return(font); }