예제 #1
0
        /// <summary>
        /// Tries to match a specified character to a typeface that supports specified font properties.
        /// </summary>
        /// <param name="codepoint">The codepoint to match against.</param>
        /// <param name="fontStyle">The font style.</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <param name="fontFamily">The font family. This is optional and used for fallback lookup.</param>
        /// <param name="culture">The culture.</param>
        /// <param name="typeface">The matching typeface.</param>
        /// <returns><c>True</c>, if the <see cref="T:Avalonia.Platform.IFontManagerImpl" /> could match the character to specified parameters, <c>False</c> otherwise.</returns>
        public bool TryMatchCharacter(int codepoint, FontStyle fontStyle, FontWeight fontWeight, FontFamily fontFamily, CultureInfo culture, out Typeface typeface)
        {
            if (typefaces == null)
            {
                typefaces = new List <Typeface>();
                foreach (var item in fontFamilyManager.GetAllFontNames())
                {
                    typefaces.Add(new Typeface(fontFamilyManager.ResolveFontFamily(item).GetFontFamily()));
                }
            }
            foreach (var item in typefaces)
            {
                if (item.GlyphTypeface.GetGlyph((uint)codepoint) == 0)
                {
                    continue;
                }
                typeface = new Typeface(item.FontFamily.Name, fontStyle, fontWeight);
                return(true);
            }

            if (GetPlatformConfiguration().GetOptions().Fonts.UseInbuiltFontsOnly)
            {
                var fallback = SKFontManager.Default.MatchCharacter(fontFamily?.Name, (SKFontStyleWeight)fontWeight, SKFontStyleWidth.Normal, (SKFontStyleSlant)fontStyle, new string[] { culture.ThreeLetterISOLanguageName, culture.TwoLetterISOLanguageName }, codepoint);
                typeface = new Typeface(fallback?.FamilyName ?? fontFamilyManager.GetDefaultFontFamily().GetFontFamily(), fontStyle, fontWeight);
                return(true);
            }
            return(fontManager.TryMatchCharacter(codepoint, fontStyle, fontWeight, fontFamily, culture, out typeface));
        }