/// <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); }
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); }
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))); }
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)); }
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); } }
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); }
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))); }
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); }
/// <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(); }
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); }
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.ApplicationModel.Package.Current.InstalledLocation.Path, path.TrimStart('/').Replace('/', global::System.IO.Path.DirectorySeparatorChar)); var font = SKTypeface.FromFile(filePath); return(font); } else { return(SKTypeface.FromFamilyName(name, weight, width, slant)); } }
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.ApplicationModel.Package.Current.InstalledLocation.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); } }
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))); }
public static SKTypeface FromFamilyName(string familyName, int weight, int width, SKFontStyleSlant slant) { return(FromFamilyName(familyName, new SKFontStyle(weight, width, slant))); }
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)); }
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); }
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)
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);
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); }
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; }
/// <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)); }
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)); }
public SKFontStyle(int weight, int width, SKFontStyleSlant slant) : this(SkiaApi.sk_fontstyle_new(weight, width, slant), true) { }
public SKFontStyle(SKFontStyleWeight weight, SKFontStyleWidth width, SKFontStyleSlant slant) : this((int)weight, (int)width, slant) { }
internal SKFontStyleStatic(SKFontStyleWeight weight, SKFontStyleWidth width, SKFontStyleSlant slant) : base(weight, width, slant) { IgnorePublicDispose = true; }
public static SKTypeface FromFamilyName(string familyName, SKFontStyleWeight weight, SKFontStyleWidth width, SKFontStyleSlant slant) { return(FromFamilyName(familyName, (int)weight, (int)width, slant)); }
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)); }