private record Entry( FontWeight FontWeight, FontStyle FontStyle, FontFamily FontFamily, double FontSize, double CharacterSpacing, Windows.UI.Color Foreground, BaseLineAlignment BaseLineAlignment, TextDecorations TextDecorations) {
public Entry(FontWeight fontWeight, FontStyle fontStyle, FontFamily fontFamily, double fontSize, double characterSpacing, Windows.UI.Color foreground, BaseLineAlignment baselineAlignment, TextDecorations textDecorations) { FontWeight = fontWeight; FontStyle = fontStyle; FontFamily = fontFamily; FontSize = fontSize; CharacterSpacing = characterSpacing; Foreground = foreground; BaseLineAlignment = baselineAlignment; TextDecorations = textDecorations; }
/// <summary> /// Builds a TextPaint configuration. /// </summary> /// <remarks> /// This is required for some JNI related reason. /// At some point, the reference to a member field TextPaint gets collected if used /// in some of the StaticLayout methods, so we create a local copy of the /// paint to be used in this context. /// One solution could be to use a <see cref="Android.Runtime.JNIEnv.NewGlobalRef"/>, but the release of the reference /// can be tricky to place properly. /// </remarks> /// <returns>A <see cref="TextPaint"/> instance.</returns> public static TextPaint GetPaint(FontWeight fontWeight, FontStyle fontStyle, FontFamily fontFamily, double fontSize, double characterSpacing, Windows.UI.Color foreground, Shader shader, BaseLineAlignment baselineAlignment, TextDecorations textDecorations) { if (shader != null) { // The "Shader" native object can't be use as a cache key return(InnerBuildPaint(fontWeight, fontStyle, fontFamily, fontSize, characterSpacing, foreground, shader, baselineAlignment, textDecorations)); } var key = new Entry(fontWeight, fontStyle, fontFamily, fontSize, characterSpacing, foreground, baselineAlignment, textDecorations); if (!_entries.TryGetValue(key, out var paint)) { _entries.Add(key, paint = InnerBuildPaint(fontWeight, fontStyle, fontFamily, fontSize, characterSpacing, foreground, shader, baselineAlignment, textDecorations)); } return(paint); }