internal static SKTextBlob CreatePathPositioned(void *text, int length, SKTextEncoding encoding, SKFont font, SKPath path, SKTextAlign textAlign = SKTextAlign.Left, SKPoint origin = default) { if (font == null) { throw new ArgumentNullException(nameof(font)); } var count = font.CountGlyphs(text, length, encoding); if (count <= 0) { return(null); } // we use temporary arrays because we might only use part of the text using var glyphs = Utils.RentArray <ushort> (count); using var glyphWidths = Utils.RentArray <float> (glyphs.Length); using var glyphOffsets = Utils.RentArray <SKPoint> (glyphs.Length); font.GetGlyphs(text, length, encoding, glyphs); font.GetGlyphWidths(glyphs, glyphWidths, Span <SKRect> .Empty); font.GetGlyphPositions(glyphs, glyphOffsets, origin); using var builder = new SKTextBlobBuilder(); builder.AddPathPositionedRun(glyphs, font, glyphWidths, glyphOffsets, path, textAlign); return(builder.Build()); }
internal static SKTextBlob CreateHorizontal(void *text, int length, SKTextEncoding encoding, SKFont font, ReadOnlySpan <float> positions, float y) { if (font == null) { throw new ArgumentNullException(nameof(font)); } var count = font.CountGlyphs(text, length, encoding); if (count <= 0) { return(null); } using var builder = new SKTextBlobBuilder(); var buffer = builder.AllocateHorizontalRun(font, count, y); font.GetGlyphs(text, length, encoding, buffer.GetGlyphSpan()); positions.CopyTo(buffer.GetPositionSpan()); return(builder.Build()); }
internal static SKTextBlob Create(void *text, int length, SKTextEncoding encoding, SKFont font, SKPoint origin) { if (font == null) { throw new ArgumentNullException(nameof(font)); } var count = font.CountGlyphs(text, length, encoding); if (count <= 0) { return(null); } using var builder = new SKTextBlobBuilder(); var buffer = builder.AllocatePositionedRun(font, count); font.GetGlyphs(text, length, encoding, buffer.GetGlyphSpan()); font.GetGlyphPositions(buffer.GetGlyphSpan(), buffer.GetPositionSpan(), origin); return(builder.Build()); }