public static void Load(string font_name = null) { Typeface = new EmojiTypeface(font_name); ParseEmojiList(); }
public ColorGlyph(EmojiTypeface font, int codepoint) { m_font = font; m_codepoint = codepoint; }
static EmojiData() { Typeface = new EmojiTypeface(); ParseEmojiList(); }
private static void ParseEmojiList() { var font = new EmojiTypeface(); var modifiers = new string[] { "🏻", "🏼", "🏽", "🏾", "🏿" }; var match_group = new Regex(@"^# group: (.*)"); var match_subgroup = new Regex(@"^# subgroup: (.*)"); var match_sequence = new Regex(@"^([0-9a-fA-F ]+[0-9a-fA-F]).*; [-a-z]*fully-qualified.*# [^ ]* (.*)"); var match_modifier = new Regex("(" + string.Join("|", modifiers) + ")"); var list = new List <Group>(); var lookup = new Dictionary <string, Emoji>(); var alltext = new List <string>(); Group last_group = null; SubGroup last_subgroup = null; Emoji last_emoji = null; foreach (var line in EmojiDescriptionLines()) { var m = match_group.Match(line); if (m.Success) { last_group = new Group() { Name = m.Groups[1].ToString() }; list.Add(last_group); continue; } m = match_subgroup.Match(line); if (m.Success) { last_subgroup = new SubGroup() { Name = m.Groups[1].ToString(), Group = last_group }; last_group.SubGroups.Add(last_subgroup); continue; } m = match_sequence.Match(line); if (m.Success) { string sequence = m.Groups[1].ToString(); string name = m.Groups[2].ToString(); string text = ""; foreach (var item in sequence.Split(' ')) { int codepoint = Convert.ToInt32(item, 16); text += char.ConvertFromUtf32(codepoint); } // Only include emojis that we know how to render if (!font.CanRender(text)) { continue; } alltext.Add(text); // Only add fully-qualified characters to the groups, or we will // end with a lot of dupes. if (line.Contains("non-fully-qualified")) { continue; } var emoji = new Emoji() { Name = name, Text = text, SubGroup = last_subgroup }; lookup[text] = emoji; if (match_modifier.Match(text).Success) { // We assume this is a variation of the previous emoji if (last_emoji.VariationList.Count == 0) { last_emoji.VariationList.Add(last_emoji); } last_emoji.VariationList.Add(emoji); } else { last_emoji = emoji; last_subgroup.EmojiList.Add(emoji); } } } AllGroups = list; Lookup = lookup; // Build a regex that matches any Emoji var textarray = alltext.ToArray(); Array.Sort(textarray, (a, b) => b.Length - a.Length); var regextext = "(" + string.Join("|", textarray).Replace("*", "[*]") + ")"; MatchOne = new Regex(regextext); MatchMultiple = new Regex(regextext + "+"); }