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, UnderlineStyle underlineStyle) { FontWeight = fontWeight; FontStyle = fontStyle; FontFamily = fontFamily; FontSize = fontSize; CharacterSpacing = characterSpacing; Foreground = foreground; BaseLineAlignment = baselineAlignment; UnderlineStyle = underlineStyle; }
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; }
private static TextPaint InnerBuildPaint(FontWeight fontWeight, FontStyle fontStyle, FontFamily fontFamily, double fontSize, double characterSpacing, Windows.UI.Color foreground, BaseLineAlignment baselineAlignment, UnderlineStyle underlineStyle) { var paint = new TextPaint(PaintFlags.AntiAlias); var paintSpecs = BuildPaintValueSpecs(fontSize, characterSpacing); paint.Density = paintSpecs.density; paint.TextSize = paintSpecs.textSize; paint.UnderlineText = underlineStyle == UnderlineStyle.Single; if (baselineAlignment == BaseLineAlignment.Superscript) { paint.BaselineShift += (int)(paint.Ascent() / 2); } if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { paint.LetterSpacing = paintSpecs.letterSpacing; } else { LogCharacterSpacingNotSupported(); } var typefaceStyle = TypefaceStyleHelper.GetTypefaceStyle(fontStyle, fontWeight); var typeface = FontHelper.FontFamilyToTypeFace(fontFamily, fontWeight, typefaceStyle); paint.SetTypeface(typeface); paint.Color = foreground; return(paint); }
/// <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, BaseLineAlignment baselineAlignment, UnderlineStyle underlineStyle) { var key = new Entry(fontWeight, fontStyle, fontFamily, fontSize, characterSpacing, foreground, baselineAlignment, underlineStyle); if (!_entries.TryGetValue(key, out var paint)) { _entries.Add(key, paint = InnerBuildPaint(fontWeight, fontStyle, fontFamily, fontSize, characterSpacing, foreground, baselineAlignment, underlineStyle)); } return(paint); }
/// <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); }