﻿using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using BootstrapUI.Enums;

namespace BootstrapUI.Helper
{
    public static class SymbolHelper
    {
        public static string SegoeUiSymbol(Symbol symbol)
        {
            var unicode = @"\u" + ((int)symbol).ToString("x4");
            return System.Text.RegularExpressions.Regex.Unescape(unicode);
        }


        public static Geometry SymbolToGeometry(Symbol symbol)
        {
            var text = SegoeUiSymbol(symbol);

            var tb = Application.Current.Resources["TextBlockSegoeDynamic"] as TextBlock;
            return Text2Path(text, "en-US", true, tb.FontFamily, 14);
        }


        public static PathGeometry Text2Path(string text, string culture, bool leftToRight, FontFamily font, int fontSize)
        {
            if (culture == "") culture = "en-us";

            var ci = new CultureInfo(culture);
            var fd = leftToRight ? FlowDirection.LeftToRight : FlowDirection.RightToLeft;

            var tf = new Typeface(font, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
            var t = new FormattedText(text, ci, fd, tf, fontSize, Brushes.Black);
            var g = t.BuildGeometry(new Point(0, 0));
            var p = g.GetFlattenedPathGeometry();

            return p;
        }
    }
}
