コード例 #1
0
        public Font FindFont(string familyName, float fontSize, FontWeight fontWeight, bool italic)
        {
            var fd = new FontDesc
            {
                Typeface = new TypefaceDesc
                {
                    FamilyName = familyName,
                    Weight     = fontWeight,
                    Italic     = italic
                },
                Size = (int)(fontSize * 10)
            };

            if (!fonts.TryGetValue(fd, out var font))
            {
                if (!MatchTypeface(fd.Typeface, out SKTypeface typeface))
                {
                    typeface = SKTypeface.FromFamilyName(familyName, fontWeight.ToSkia(), SKFontStyleWidth.Normal, italic ? SKFontStyleSlant.Italic : SKFontStyleSlant.Upright);
                }

                var skFont = typeface.ToFont(fontSize);
                font = new SkiaFont(skFont);
                if (fontWeight == FontWeight.Bold && typeface.FontWeight < (int)SKFontStyleWeight.SemiBold)
                {
                    font.SKPaint.FakeBoldText = true;
                }

                fonts.Add(fd, font);
            }

            return(font);
        }