public GlyphTypefaceImpl(Typeface typeface) { Typeface = TypefaceCache.Get(typeface.FontFamily, typeface.Weight, typeface.Style).SKTypeface; Face = new Face(GetTable) { UnitsPerEm = Typeface.UnitsPerEm }; Font = new Font(Face); Font.SetFunctionsOpenType(); Font.GetScale(out var xScale, out _); DesignEmHeight = (short)xScale; if (!Font.TryGetHorizontalFontExtents(out var fontExtents)) { Font.TryGetVerticalFontExtents(out fontExtents); } Ascent = -fontExtents.Ascender; Descent = -fontExtents.Descender; LineGap = fontExtents.LineGap; if (Font.OpenTypeMetrics.TryGetPosition(OpenTypeMetricsTag.UnderlineOffset, out var underlinePosition)) { UnderlinePosition = underlinePosition; } if (Font.OpenTypeMetrics.TryGetPosition(OpenTypeMetricsTag.UnderlineSize, out var underlineThickness)) { UnderlineThickness = underlineThickness; } if (Font.OpenTypeMetrics.TryGetPosition(OpenTypeMetricsTag.StrikeoutOffset, out var strikethroughPosition)) { StrikethroughPosition = strikethroughPosition; } if (Font.OpenTypeMetrics.TryGetPosition(OpenTypeMetricsTag.StrikeoutSize, out var strikethroughThickness)) { StrikethroughThickness = strikethroughThickness; } }
public FormattedTextImpl( string text, Typeface typeface, double fontSize, TextAlignment textAlignment, TextWrapping wrapping, Size constraint, IReadOnlyList <FormattedTextStyleSpan> spans) { Text = text ?? string.Empty; // Replace 0 characters with zero-width spaces (200B) Text = Text.Replace((char)0, (char)0x200B); var entry = TypefaceCache.Get(typeface.FontFamily, typeface.Weight, typeface.Style); _paint = new SKPaint { TextEncoding = SKTextEncoding.Utf16, IsStroke = false, IsAntialias = true, LcdRenderText = true, SubpixelText = true, Typeface = entry.SKTypeface, TextSize = (float)fontSize, TextAlign = textAlignment.ToSKTextAlign() }; //currently Skia does not measure properly with Utf8 !!! //Paint.TextEncoding = SKTextEncoding.Utf8; _wrapping = wrapping; _constraint = constraint; if (spans != null) { foreach (var span in spans) { if (span.ForegroundBrush != null) { SetForegroundBrush(span.ForegroundBrush, span.StartIndex, span.Length); } } } Rebuild(); }
public Typeface GetTypeface(FontFamily fontFamily, FontWeight fontWeight, FontStyle fontStyle) { return(TypefaceCache.Get(fontFamily.Name, fontWeight, fontStyle).Typeface); }