public GlyphTypefaceImpl(Typeface typeface) { DWFont = Direct2D1FontCollectionCache.GetFont(typeface); FontFace = new FontFace(DWFont).QueryInterface <FontFace1>(); Face = new Face(GetTable); Font = new HarfBuzzSharp.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; } IsFixedPitch = FontFace.IsMonospacedFont; }
public FormattedTextImpl( string text, Typeface typeface, double fontSize, TextAlignment textAlignment, TextWrapping wrapping, Size constraint, IReadOnlyList <FormattedTextStyleSpan> spans) { Text = text; using (var font = Direct2D1FontCollectionCache.GetFont(typeface)) using (var textFormat = new DWrite.TextFormat(Direct2D1Platform.DirectWriteFactory, typeface.FontFamily.Name, font.FontFamily.FontCollection, (DWrite.FontWeight)typeface.Weight, (DWrite.FontStyle)typeface.Style, DWrite.FontStretch.Normal, (float)fontSize)) { textFormat.WordWrapping = wrapping == TextWrapping.Wrap ? DWrite.WordWrapping.Wrap : DWrite.WordWrapping.NoWrap; TextLayout = new DWrite.TextLayout( Direct2D1Platform.DirectWriteFactory, Text ?? string.Empty, textFormat, (float)constraint.Width, (float)constraint.Height) { TextAlignment = textAlignment.ToDirect2D() }; } if (spans != null) { foreach (var span in spans) { ApplySpan(span); } } Bounds = Measure(); }