Ejemplo n.º 1
0
        private static Dictionary <string, string> HandleWebFont(GlyphTypeface glyphTypeface, BundledFont bundledFont, string basePath)
        {
            var glyphs = new Dictionary <string, string>();
            var styles = new CssParser(File.ReadAllText(Path.Combine(basePath, "Resources", bundledFont.CssFile))).Styles;

            foreach (var ctg in glyphTypeface.CharacterToGlyphMap)
            {
                var unicode      = $"\\{ctg.Key:x}";
                var locatedStyle = styles.FirstOrDefault(x => x.Styles.Any(s => s.Key == "content" && s.Value.Contains(unicode)));
                if (locatedStyle is null)
                {
                    Console.WriteLine($"Could not locate resource for glyph {unicode}");
                    System.Diagnostics.Debugger.Break();
                }

                var mappedValue  = Regex.Replace(locatedStyle.SelectorText, @"^(\.)", string.Empty).Split(':').First();
                var propertyName = Regex.Replace(mappedValue, $@"^{bundledFont.Prefix}(-)?", string.Empty).Replace('-', '_').Pascalize();
                mappedValue = $"{bundledFont.Alias} {mappedValue}".Trim();

                if (char.IsDigit(propertyName[0]))
                {
                    var numeric = string.Empty;
                    for (var i = 0; i < propertyName.Length; i++)
                    {
                        var c = propertyName[i];
                        if (char.IsDigit(c))
                        {
                            numeric += c;
                        }
                        else
                        {
                            break;
                        }
                    }

                    var value = int.Parse(numeric);
                    propertyName = $"{value.ToWords()}{propertyName.Substring(numeric.Length).Pascalize()}".Humanize(LetterCasing.Title).Replace(" ", string.Empty);
                }

                glyphs.Add(propertyName, mappedValue);
            }

            return(glyphs);
        }