|
| 1 | +using Android.App; |
| 2 | +using Android.Graphics; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Text; |
| 6 | +using Uno.Extensions; |
| 7 | +using Uno; |
| 8 | +using Uno.UI; |
| 9 | +using System.Linq; |
| 10 | +using Android.OS; |
| 11 | +using Windows.UI.Xaml.Media; |
| 12 | +using Windows.UI.Text; |
| 13 | +using Uno.Logging; |
| 14 | +using Microsoft.Extensions.Logging; |
| 15 | +using Uno.Collections; |
| 16 | + |
| 17 | +namespace Windows.UI.Xaml |
| 18 | +{ |
| 19 | + internal partial class FontHelper |
| 20 | + { |
| 21 | + private readonly static FontFamilyToTypeFaceDictionary _fontFamilyToTypeFaceDictionary = new FontFamilyToTypeFaceDictionary(); |
| 22 | + |
| 23 | + private class FontFamilyToTypeFaceDictionary |
| 24 | + { |
| 25 | + public class Entry |
| 26 | + { |
| 27 | + private readonly int _hashCode; |
| 28 | + |
| 29 | + public Entry(string fontFamily, FontWeight fontWeight, TypefaceStyle style) |
| 30 | + { |
| 31 | + FontFamily = fontFamily; |
| 32 | + FontWeight = fontWeight; |
| 33 | + Style = style; |
| 34 | + _hashCode = FontFamily.GetHashCode() ^ FontWeight.GetHashCode() ^ Style.GetHashCode(); |
| 35 | + } |
| 36 | + |
| 37 | + public string FontFamily { get; } |
| 38 | + public FontWeight FontWeight { get; } |
| 39 | + public TypefaceStyle Style { get; } |
| 40 | + |
| 41 | + public override bool Equals(object other) |
| 42 | + { |
| 43 | + if (other is Entry otherEntry) |
| 44 | + { |
| 45 | + return FontFamily == otherEntry.FontFamily |
| 46 | + && FontWeight == otherEntry.FontWeight |
| 47 | + && Style == otherEntry.Style; |
| 48 | + } |
| 49 | + |
| 50 | + return false; |
| 51 | + } |
| 52 | + |
| 53 | + public override int GetHashCode() => _hashCode; |
| 54 | + } |
| 55 | + |
| 56 | + private readonly HashtableEx _entries = new HashtableEx(); |
| 57 | + |
| 58 | + internal bool TryGetValue(Entry key, out Typeface result) |
| 59 | + { |
| 60 | + if (_entries.TryGetValue(key, out var value)) |
| 61 | + { |
| 62 | + result = (Typeface)value; |
| 63 | + return true; |
| 64 | + } |
| 65 | + |
| 66 | + result = null; |
| 67 | + return false; |
| 68 | + } |
| 69 | + |
| 70 | + internal void Add(Entry key, Typeface typeFace) |
| 71 | + => _entries.Add(key, typeFace); |
| 72 | + |
| 73 | + internal void Clear() |
| 74 | + => _entries.Clear(); |
| 75 | + } |
| 76 | + |
| 77 | + } |
| 78 | +} |
0 commit comments