public bool TryMatchCharacter(int codepoint, FontWeight fontWeight, FontStyle fontStyle, FontFamily fontFamily, CultureInfo culture, out FontKey fontKey) { if (culture == null) { culture = CultureInfo.CurrentUICulture; } if (t_languageTagBuffer == null) { t_languageTagBuffer = new string[2]; } t_languageTagBuffer[0] = culture.TwoLetterISOLanguageName; t_languageTagBuffer[1] = culture.ThreeLetterISOLanguageName; if (fontFamily != null) { foreach (var familyName in fontFamily.FamilyNames) { var skTypeface = _skFontManager.MatchCharacter(familyName, (SKFontStyleWeight)fontWeight, SKFontStyleWidth.Normal, (SKFontStyleSlant)fontStyle, t_languageTagBuffer, codepoint); if (skTypeface == null) { continue; } fontKey = new FontKey(new FontFamily(familyName), fontWeight, fontStyle); return(true); } } else { var skTypeface = _skFontManager.MatchCharacter(null, (SKFontStyleWeight)fontWeight, SKFontStyleWidth.Normal, (SKFontStyleSlant)fontStyle, t_languageTagBuffer, codepoint); if (skTypeface != null) { fontKey = new FontKey(new FontFamily(skTypeface.FamilyName), fontWeight, fontStyle); return(true); } } fontKey = default; return(false); }
public Typeface MatchCharacter(int codepoint, FontWeight fontWeight = default, FontStyle fontStyle = default, FontFamily fontFamily = null, CultureInfo culture = null) { var fontFamilyName = FontFamily.Default.Name; if (culture == null) { culture = CultureInfo.CurrentUICulture; } if (fontFamily != null) { foreach (var familyName in fontFamily.FamilyNames) { var skTypeface = _skFontManager.MatchCharacter(familyName, (SKFontStyleWeight)fontWeight, SKFontStyleWidth.Normal, (SKFontStyleSlant)fontStyle, new[] { culture.TwoLetterISOLanguageName, culture.ThreeLetterISOLanguageName }, codepoint); if (skTypeface == null) { continue; } fontFamilyName = familyName; break; } } else { var skTypeface = _skFontManager.MatchCharacter(null, (SKFontStyleWeight)fontWeight, SKFontStyleWidth.Normal, (SKFontStyleSlant)fontStyle, new[] { culture.TwoLetterISOLanguageName, culture.ThreeLetterISOLanguageName }, codepoint); if (skTypeface != null) { fontFamilyName = skTypeface.FamilyName; } } return(GetTypeface(fontFamilyName, fontWeight, fontStyle)); }
public bool TryMatchCharacter(int codepoint, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch, FontFamily fontFamily, CultureInfo culture, out Typeface fontKey) { SKFontStyle skFontStyle; switch (fontWeight) { case FontWeight.Normal when fontStyle == FontStyle.Normal && fontStretch == FontStretch.Normal: skFontStyle = SKFontStyle.Normal; break; case FontWeight.Normal when fontStyle == FontStyle.Italic && fontStretch == FontStretch.Normal: skFontStyle = SKFontStyle.Italic; break; case FontWeight.Bold when fontStyle == FontStyle.Normal && fontStretch == FontStretch.Normal: skFontStyle = SKFontStyle.Bold; break; case FontWeight.Bold when fontStyle == FontStyle.Italic && fontStretch == FontStretch.Normal: skFontStyle = SKFontStyle.BoldItalic; break; default: skFontStyle = new SKFontStyle((SKFontStyleWeight)fontWeight, (SKFontStyleWidth)fontStretch, (SKFontStyleSlant)fontStyle); break; } if (culture == null) { culture = CultureInfo.CurrentUICulture; } if (t_languageTagBuffer == null) { t_languageTagBuffer = new string[2]; } t_languageTagBuffer[0] = culture.TwoLetterISOLanguageName; t_languageTagBuffer[1] = culture.ThreeLetterISOLanguageName; if (fontFamily != null && fontFamily.FamilyNames.HasFallbacks) { var familyNames = fontFamily.FamilyNames; for (var i = 1; i < familyNames.Count; i++) { var skTypeface = _skFontManager.MatchCharacter(familyNames[i], skFontStyle, t_languageTagBuffer, codepoint); if (skTypeface == null) { continue; } fontKey = new Typeface(skTypeface.FamilyName, fontStyle, fontWeight, fontStretch); return(true); } } else { var skTypeface = _skFontManager.MatchCharacter(null, skFontStyle, t_languageTagBuffer, codepoint); if (skTypeface != null) { fontKey = new Typeface(skTypeface.FamilyName, fontStyle, fontWeight, fontStretch); return(true); } } fontKey = default; return(false); }
/// <inheritdoc /> public SKTypeface MatchCharacter(string familyName, int weight, int width, SKFontStyleSlant slant, string[] bcp47, int character) { return(_fontManager.MatchCharacter(familyName, weight, width, slant, bcp47, character)); }