/// <summary>
        /// Paint text
        /// </summary>
        private void OnPaintText(SKPaintSurfaceEventArgs e)
        {
            SKPaint textPaint = new SKPaint();

            textPaint.Color       = AnimationUtils.ColorTransform(_toggledAnimationProcess, TextColor, ToggledTextColor).ToSKColor();
            textPaint.TextSize    = (float)FontSize * DeviceScale;
            textPaint.TextAlign   = SKTextAlign.Left;
            textPaint.IsAntialias = true;

            SKFontStyleSlant  slant      = SkiaUtils.ConvertToSKFontStyle(FontStyle);
            SKFontStyleWeight fontWeight = SkiaUtils.ConvertToSKFontWeight(FontWeight);

            textPaint.Typeface = SKTypeface.FromFamilyName(FontFamily, fontWeight, SKFontStyleWidth.Normal, slant);

            SKRect skTextBounds = new SKRect();

            textPaint.MeasureText(Text, ref skTextBounds);

            float skNegativePadding = (float)EllipseDiameter * DeviceScale;

            float xText = skNegativePadding - skTextBounds.Left + (float)(TextMargin.Left * DeviceScale);
            float yText = -skTextBounds.Top + (e.Info.Height - skTextBounds.Height) / 2;

            double checkBoxWidth = _selectionViewSize.Width;

            if (_selectionViewLocation == HorizontalLocations.Left)
            {
                xText += (float)(checkBoxWidth * DeviceScale);
            }

            float lineHeight       = (float)FontSize * DeviceScale;
            float skAvailableWidth = (float)(Width - checkBoxWidth - TextMargin.HorizontalThickness) * DeviceScale;

            SkiaUtils.DrawTextArea(e.Surface.Canvas, textPaint, xText, yText, skAvailableWidth, lineHeight, IsTextWrapping, Text);
        }
示例#2
0
        private static SKFontStyleSlant ReadFontStyle(Dictionary <string, string> fontStyle, SKFontStyleSlant defaultStyle = SKFontStyleSlant.Upright)
        {
            SKFontStyleSlant style = defaultStyle;

            string fstyle;

            if (fontStyle.TryGetValue("font-style", out fstyle) && !string.IsNullOrWhiteSpace(fstyle))
            {
                switch (fstyle)
                {
                case "italic":
                    style = SKFontStyleSlant.Italic;
                    break;

                case "oblique":
                    style = SKFontStyleSlant.Oblique;
                    break;

                case "normal":
                    style = SKFontStyleSlant.Upright;
                    break;

                default:
                    style = defaultStyle;
                    break;
                }
            }

            return(style);
        }
示例#3
0
 public static FontStyle ToAvalonia(this SKFontStyleSlant slant)
 {
     return(slant switch
     {
         SKFontStyleSlant.Upright => FontStyle.Normal,
         SKFontStyleSlant.Italic => FontStyle.Italic,
         SKFontStyleSlant.Oblique => FontStyle.Oblique,
         _ => throw new ArgumentOutOfRangeException(nameof(slant), slant, null)
     });
        public SKTypeface MatchCharacter(string familyName, int weight, int width, SKFontStyleSlant slant, string[] bcp47, int character)
        {
            // TODO: work around for https://bugs.chromium.org/p/skia/issues/detail?id=6196
            if (familyName == null)
            {
                familyName = string.Empty;
            }

            return(GetObject <SKTypeface> (SkiaApi.sk_fontmgr_match_family_style_character(Handle, familyName, weight, width, slant, bcp47, bcp47?.Length ?? 0, character)));
        }
示例#5
0
 public static SKTypeface FromFamilyName(
     string familyName,
     SKFontStyleWeight weight,
     SKFontStyleWidth width,
     SKFontStyleSlant slant)
 {
     return(new()
     {
         FamilyName = familyName,
         FontWeight = weight,
         FontWidth = width,
         Style = slant
     });
 }
        /// <summary>
        /// Measure total size
        /// </summary>
        protected Size MeasureTextSize(double widthConstraint, double heightConstraint)
        {
            SKPaint paint = new SKPaint();

            paint.TextSize = (float)FontSize;

            SKFontStyleSlant  slant      = SkiaUtils.ConvertToSKFontStyle(FontStyle);
            SKFontStyleWeight fontWeight = SkiaUtils.ConvertToSKFontWeight(FontWeight);

            paint.Typeface = SKTypeface.FromFamilyName(FontFamily, fontWeight, SKFontStyleWidth.Normal, slant);

            float lineHeight = (float)FontSize;

            return(SkiaUtils.MeasureText(paint, (float)widthConstraint, lineHeight, IsTextWrapping, Text));
        }
示例#7
0
        public static AM.FontStyle ToFontStyle(this SKFontStyleSlant fontStyleSlant)
        {
            switch (fontStyleSlant)
            {
            default:
            case SKFontStyleSlant.Upright:
                // TODO: FontStyleSlant.Upright
                return(AM.FontStyle.Normal);

            case SKFontStyleSlant.Italic:
                return(AM.FontStyle.Italic);

            case SKFontStyleSlant.Oblique:
                return(AM.FontStyle.Oblique);
            }
        }
示例#8
0
        private static SKPaint CreatePaint(SKColor color, string fontName, SKFontStyleWeight weight,
                                           SKFontStyleWidth width, SKFontStyleSlant slant)
        {
            SKTypeface font = SKTypeface.FromFamilyName(fontName, weight, width, slant);

            SKPaint paint = new SKPaint
            {
                IsAntialias = true,
                Color       = color,
                Typeface    = font,
                TextSize    = 18
            };


            return(paint);
        }
示例#9
0
        public override object Transform(EngineIntrinsics engineIntrinsics, object inputData)
        {
            switch (inputData)
            {
            case SKTypeface t:
                return(t);

            case string s:
                return(WCUtils.FontManager.MatchFamily(s, SKFontStyle.Normal));

            default:
                IEnumerable properties = null;
                if (inputData is Hashtable ht)
                {
                    properties = ht;
                }
                else
                {
                    properties = PSObject.AsPSObject(inputData).Properties;
                }

                SKFontStyle style;
                if (properties.GetValue("FontWeight") == null ||
                    properties.GetValue("FontSlant") == null ||
                    properties.GetValue("FontWidth") == null)
                {
                    SKFontStyleWeight weight = properties.GetValue("FontWeight") == null ?
                                               SKFontStyleWeight.Normal : LanguagePrimitives.ConvertTo <SKFontStyleWeight>(
                        properties.GetValue("FontWeight"));
                    SKFontStyleSlant slant = properties.GetValue("FontSlant") == null ?
                                             SKFontStyleSlant.Upright : LanguagePrimitives.ConvertTo <SKFontStyleSlant>(
                        properties.GetValue("FontSlant"));
                    SKFontStyleWidth width = properties.GetValue("FontWidth") == null ?
                                             SKFontStyleWidth.Normal : LanguagePrimitives.ConvertTo <SKFontStyleWidth>(
                        properties.GetValue("FontWidth"));
                    style = new SKFontStyle(weight, width, slant);
                }
                else
                {
                    var customStyle = properties.GetValue("FontStyle") as SKFontStyle;
                    style = customStyle == null ? SKFontStyle.Normal : customStyle;
                }

                string familyName = LanguagePrimitives.ConvertTo <string>(properties.GetValue("FamilyName"));
                return(WCUtils.FontManager.MatchFamily(familyName, style));
            }
        }
        public static SKTypeface GetTypeface(string name, FontStyle style, FontWeight weight)
        {
            SKFontStyleSlant skStyle = SKFontStyleSlant.Upright;

            switch (style)
            {
            case FontStyle.Italic:
                skStyle = SKFontStyleSlant.Italic;
                break;

            case FontStyle.Oblique:
                skStyle = SKFontStyleSlant.Oblique;
                break;
            }

            return(GetTypeface(name, new FontKey((SKFontStyleWeight)weight, skStyle)));
        }
示例#11
0
文件: Font.cs 项目: EYHN/Anything
        public SKTypeface?MatchCharacter(
            string familyName,
            int weight,
            int width,
            SKFontStyleSlant slant,
            string[] bcp47,
            int character)
        {
            foreach (var typeFace in _typeFaces)
            {
                if (typeFace.ContainsGlyph(character))
                {
                    return(typeFace);
                }
            }

            return(null);
        }
示例#12
0
        /// <summary>
        /// Draws the specified text.
        /// </summary>
        /// <param name="bounds">The bounds.</param>
        /// <param name="text">The text.</param>
        /// <param name="style">The style.</param>
        public void DrawText(Rect bounds, string text, DrawingStyle style)
        {
            _canvas.ApplyTransform(style.Transform, style.TransformOrigin, bounds);

            SKFontStyleSlant fontStyle = SKFontStyleSlant.Upright;

            if (style.FontStyle == FontStyles.Italic)
            {
                fontStyle = SKFontStyleSlant.Italic;
            }
            else if (style.FontStyle == FontStyles.Oblique)
            {
                fontStyle = SKFontStyleSlant.Oblique;
            }

            var typeFace = SKTypeface.FromFamilyName(style.FontFamily.ToString(), new SKFontStyle(style.FontWeight.ToOpenTypeWeight(), 1, fontStyle));

            SKPaint paint = new SKPaint();

            paint.Typeface    = typeFace;
            paint.TextSize    = style.FontSize.ToFloat();
            paint.IsAntialias = style.EdgeMode == EdgeMode.Unspecified;

            if (style.HasOpacity)
            {
                paint.ColorFilter = SKColorFilter.CreateBlendMode(SKColors.White.WithAlpha((byte)(style.Opacity * 255d)), SKBlendMode.DstIn);
            }

            if (style.Fill != null)
            {
                if (style.Fill is SolidColorBrush)
                {
                    paint.Color = style.Fill.ToSKColor();
                }
                else
                {
                    paint.Shader = style.Fill.ToSkiaShader(bounds.Width, bounds.Height);
                }
            }

            _canvas.DrawText(text, bounds.Left.ToFloat(), bounds.Bottom.ToFloat(), paint);

            _canvas.ResetMatrix();
        }
示例#13
0
        public SKTypeface GetTypeFace(Typeface typeface)
        {
            SKFontStyleSlant skStyle = SKFontStyleSlant.Upright;

            switch (typeface.Style)
            {
            case FontStyle.Italic:
                skStyle = SKFontStyleSlant.Italic;
                break;

            case FontStyle.Oblique:
                skStyle = SKFontStyleSlant.Oblique;
                break;
            }

            var key = new FontKey(typeface.FontFamily.Name, (SKFontStyleWeight)typeface.Weight, skStyle);

            return(_cachedTypefaces.TryGetValue(key, out var skTypeface) ? skTypeface : TypefaceCache.Default);
        }
示例#14
0
        private static SKTypeface FromFamilyName(
            string name,
            SKFontStyleWeight weight,
            SKFontStyleWidth width,
            SKFontStyleSlant slant)
        {
            if (name.StartsWith(XamlFilePathHelper.AppXIdentifier))
            {
                var path = new Uri(name).PathAndQuery;

                var filePath = global::System.IO.Path.Combine(Windows.Application­Model.Package.Current.Installed­Location.Path, path.TrimStart('/').Replace('/', global::System.IO.Path.DirectorySeparatorChar));

                var font = SKTypeface.FromFile(filePath);

                return(font);
            }
            else
            {
                return(SKTypeface.FromFamilyName(name, weight, width, slant));
            }
        }
示例#15
0
        private static SKTypeface FromFamilyName(
            string name,
            SKFontStyleWeight weight,
            SKFontStyleWidth width,
            SKFontStyleSlant slant)
        {
            if (name.StartsWith(XamlFilePathHelper.AppXIdentifier))
            {
                var path = new Uri(name).PathAndQuery;

                var filePath = global::System.IO.Path.Combine(Windows.Application­Model.Package.Current.Installed­Location.Path, path.TrimStart('/').Replace('/', global::System.IO.Path.DirectorySeparatorChar));

                var font = SKTypeface.FromFile(filePath);

                return(font);
            }
            else
            {
                if (string.Equals(name, "XamlAutoFontFamily", StringComparison.OrdinalIgnoreCase))
                {
                    return(SKTypeface.FromFamilyName(null, weight, width, slant));
                }

                var typeFace = SKTypeface.FromFamilyName(name, weight, width, slant);

                // FromFontFamilyName may return null: https://github.com/mono/SkiaSharp/issues/1058
                if (typeFace == null)
                {
                    if (typeof(TextVisual).Log().IsEnabled(LogLevel.Warning))
                    {
                        typeof(TextVisual).Log().LogWarning($"The font {name} could not be found, using system default");
                    }

                    typeFace = SKTypeface.FromFamilyName(null, weight, width, slant);
                }

                return(typeFace);
            }
        }
示例#16
0
 public static SKTypeface FromFamilyName(string familyName, int weight, int width, SKFontStyleSlant slant)
 {
     return(GetObject <SKTypeface> (SkiaApi.sk_typeface_create_from_name_with_font_style(familyName, weight, width, slant)));
 }
示例#17
0
 public static SKTypeface FromFamilyName(string familyName, int weight, int width, SKFontStyleSlant slant)
 {
     return(FromFamilyName(familyName, new SKFontStyle(weight, width, slant)));
 }
示例#18
0
 public SKTypeface MatchCharacter(string familyName, int weight, int width, SKFontStyleSlant slant, string[] bcp47, int character)
 {
     return(MatchCharacter(familyName, new SKFontStyle(weight, width, slant), bcp47, character));
 }
示例#19
0
        public SKTypeface?FromFamilyName(string fontFamily, SKFontStyleWeight fontWeight, SKFontStyleWidth fontWidth, SKFontStyleSlant fontStyle)
        {
            var skTypeface      = default(SKTypeface);
            var fontFamilyNames = fontFamily?.Split(',')?.Select(x => x.Trim().Trim(s_fontFamilyTrim))?.ToArray();

            if (fontFamilyNames != null && fontFamilyNames.Length > 0)
            {
                var defaultName   = SKTypeface.Default.FamilyName;
                var skFontManager = FontManager;
                var skFontStyle   = new SKFontStyle(fontWeight, fontWidth, fontStyle);

                foreach (var fontFamilyName in fontFamilyNames)
                {
                    var skFontStyleSet = skFontManager.GetFontStyles(fontFamilyName);
                    if (skFontStyleSet.Count > 0)
                    {
                        skTypeface = skFontManager.MatchFamily(fontFamilyName, skFontStyle);
                        if (skTypeface != null)
                        {
                            if (!defaultName.Equals(fontFamilyName, StringComparison.Ordinal) &&
                                defaultName.Equals(skTypeface.FamilyName, StringComparison.Ordinal))
                            {
                                skTypeface.Dispose();
                                skTypeface = null;
                                continue;
                            }
                            break;
                        }
                    }
                }
            }
            return(skTypeface);
        }
示例#20
0
        public SKTypeface?FromFamilyName(string fontFamily, SKFontStyleWeight fontWeight, SKFontStyleWidth fontWidth, SKFontStyleSlant fontStyle)
        {
            var skTypeface      = default(SKTypeface);
            var fontFamilyNames = fontFamily?.Split(',')?.Select(x => x.Trim().Trim(s_fontFamilyTrim))?.ToArray();

            if (fontFamilyNames is { } && fontFamilyNames.Length > 0)
示例#21
0
		public extern static sk_typeface_t sk_typeface_create_from_name_with_font_style([MarshalAs(UnmanagedType.LPStr)] string familyName, int weight, int width, SKFontStyleSlant slant);
示例#22
0
        public SKTypeface?FromFamilyName(string fontFamily, SKFontStyleWeight fontWeight, SKFontStyleWidth fontWidth, SKFontStyleSlant fontStyle)
        {
            var skTypeface      = default(SKTypeface);
            var fontFamilyNames = fontFamily?.Split(',')?.Select(x => x.Trim().Trim(s_fontFamilyTrim))?.ToArray();

            if (fontFamilyNames != null && fontFamilyNames.Length > 0)
            {
                foreach (var fontFamilyName in fontFamilyNames)
                {
                    if (fontFamily == FamilyName)
                    {
                        skTypeface = Typeface;
                        break;
                    }
                }
            }
            return(skTypeface);
        }
示例#23
0
		public static SKTypeface FromFamilyName (string familyName, SKFontStyleWeight weight, SKFontStyleWidth width, SKFontStyleSlant slant)
		{
			return FromFamilyName(familyName, (int)weight, (int)width, slant);
		}
 public FontKey(SKFontStyleWeight weight, SKFontStyleSlant slant)
 {
     Slant  = slant;
     Weight = weight;
 }
示例#25
0
 /// <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));
 }
示例#26
0
		public static SKTypeface FromFamilyName (string familyName, int weight, int width, SKFontStyleSlant slant)
		{
			return GetObject<SKTypeface> (SkiaApi.sk_typeface_create_from_name_with_font_style (familyName, weight, width, slant));
		}
示例#27
0
 public SKFontStyle(int weight, int width, SKFontStyleSlant slant)
     : this(SkiaApi.sk_fontstyle_new(weight, width, slant), true)
 {
 }
示例#28
0
 public SKFontStyle(SKFontStyleWeight weight, SKFontStyleWidth width, SKFontStyleSlant slant)
     : this((int)weight, (int)width, slant)
 {
 }
示例#29
0
 internal SKFontStyleStatic(SKFontStyleWeight weight, SKFontStyleWidth width, SKFontStyleSlant slant)
     : base(weight, width, slant)
 {
     IgnorePublicDispose = true;
 }
示例#30
0
 public static SKTypeface FromFamilyName(string familyName, SKFontStyleWeight weight, SKFontStyleWidth width, SKFontStyleSlant slant)
 {
     return(FromFamilyName(familyName, (int)weight, (int)width, slant));
 }
示例#31
0
 public FontKey(string name, SKFontStyleWeight weight, SKFontStyleSlant slant)
 {
     Name   = name;
     Slant  = slant;
     Weight = weight;
 }
 public SKTypeface MatchCharacter(string familyName, SKFontStyleWeight weight, SKFontStyleWidth width, SKFontStyleSlant slant, string[] bcp47, int character)
 {
     return(MatchCharacter(familyName, (int)weight, (int)width, slant, bcp47, character));
 }
示例#33
0
 public FontKey(SKFontStyleWeight weight, SKFontStyleSlant  slant)
 {
     Slant  = slant;
     Weight = weight;
 }