public static void AddTo(SKTextRunLookup lookup) { if (lookup == null) { throw new ArgumentNullException(nameof(lookup)); } lookup.AddTypeface(GetTypeface(), Characters); }
public static IEnumerable <SKTextRun> Create(string text, SKTextRunLookup lookup) { var runs = new List <SKTextRun>(); if (string.IsNullOrEmpty(text)) { return(runs); } var start = 0; while (start < text.Length) { var startIndex = text.IndexOf(IconTemplateBegin, start, StringComparison.Ordinal); if (startIndex == -1) { break; } var endIndex = text.IndexOf(IconTemplateEnd, startIndex, StringComparison.Ordinal); if (endIndex == -1) { break; } var pre = text.Substring(start, startIndex - start); var post = text.Substring(endIndex + IconTemplateEnd.Length); var expression = text.Substring(startIndex + IconTemplateBegin.Length, endIndex - startIndex - IconTemplateEnd.Length); var segments = expression.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); expression = segments.FirstOrDefault(); SKColor?color = null; foreach (var item in segments) { var pair = item.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); switch (pair[0].ToLower()) { case "color": if (pair.Length > 1 && !string.IsNullOrWhiteSpace(pair[1])) { color = SKColor.Parse(pair[1]); } break; } } if (!string.IsNullOrEmpty(pre)) { runs.Add(new SKTextRun(pre)); } if (lookup.TryLookup(expression, out var typeface, out var character)) { runs.Add(new SKTextRun(character) { Typeface = typeface, Color = color }); }
public static void RemoveIonIcons(this SKTextRunLookup lookup) => lookup.RemoveTypeface(entry.Value);
public static void AddIonIcons(this SKTextRunLookup lookup) => lookup.AddTypeface(entry.Value);
public static void DrawIconifiedText(this SKCanvas canvas, string text, float x, float y, SKTextRunLookup lookup, SKPaint paint) { if (canvas == null) { throw new ArgumentNullException(nameof(canvas)); } if (text == null) { throw new ArgumentNullException(nameof(text)); } if (paint == null) { throw new ArgumentNullException(nameof(paint)); } var runs = SKTextRun.Create(text, lookup); canvas.DrawText(runs, x, y, paint); }
public static void AddMaterialDesignIcons(this SKTextRunLookup lookup) => lookup.AddTypeface(entry.Value);
public static void RemoveFontAwesome(this SKTextRunLookup lookup) => lookup.RemoveTypeface(entry.Value);
public static void AddFontAwesome(this SKTextRunLookup lookup) => lookup.AddTypeface(entry.Value);