/// <summary> /// Initializes a new instance of the <see cref="GlyphRun"/> class by specifying properties of the class. /// </summary> /// <param name="glyphTypeface">The glyph typeface.</param> /// <param name="fontRenderingEmSize">The rendering em size.</param> /// <param name="glyphIndices">The glyph indices.</param> /// <param name="glyphAdvances">The glyph advances.</param> /// <param name="glyphOffsets">The glyph offsets.</param> /// <param name="characters">The characters.</param> /// <param name="glyphClusters">The glyph clusters.</param> /// <param name="biDiLevel">The bidi level.</param> public GlyphRun( GlyphTypeface glyphTypeface, double fontRenderingEmSize, ReadOnlySlice <char> characters, IReadOnlyList <ushort> glyphIndices, IReadOnlyList <double>?glyphAdvances = null, IReadOnlyList <Vector>?glyphOffsets = null, IReadOnlyList <int>?glyphClusters = null, int biDiLevel = 0) { _glyphTypeface = glyphTypeface; FontRenderingEmSize = fontRenderingEmSize; Characters = characters; _glyphIndices = glyphIndices; GlyphAdvances = glyphAdvances; GlyphOffsets = glyphOffsets; GlyphClusters = glyphClusters; BiDiLevel = biDiLevel; }
/// <summary> /// Initializes a new instance of the <see cref="GlyphRun"/> class by specifying properties of the class. /// </summary> /// <param name="glyphTypeface">The glyph typeface.</param> /// <param name="fontRenderingEmSize">The rendering em size.</param> /// <param name="glyphIndices">The glyph indices.</param> /// <param name="glyphAdvances">The glyph advances.</param> /// <param name="glyphOffsets">The glyph offsets.</param> /// <param name="characters">The characters.</param> /// <param name="glyphClusters">The glyph clusters.</param> /// <param name="biDiLevel">The bidi level.</param> public GlyphRun( GlyphTypeface glyphTypeface, double fontRenderingEmSize, ReadOnlySlice <ushort> glyphIndices, ReadOnlySlice <double> glyphAdvances = default, ReadOnlySlice <Vector> glyphOffsets = default, ReadOnlySlice <char> characters = default, ReadOnlySlice <ushort> glyphClusters = default, int biDiLevel = 0) { GlyphTypeface = glyphTypeface; FontRenderingEmSize = fontRenderingEmSize; GlyphIndices = glyphIndices; GlyphAdvances = glyphAdvances; GlyphOffsets = glyphOffsets; Characters = characters; GlyphClusters = glyphClusters; BiDiLevel = biDiLevel; }
/// <summary> /// Returns a new <see cref="GlyphTypeface"/>, or an existing one if a matching <see cref="GlyphTypeface"/> exists. /// </summary> /// <param name="typeface">The typeface.</param> /// <returns> /// The <see cref="GlyphTypeface"/>. /// </returns> public GlyphTypeface GetOrAddGlyphTypeface(Typeface typeface) { while (true) { if (_glyphTypefaceCache.TryGetValue(typeface, out var glyphTypeface)) { return(glyphTypeface); } glyphTypeface = new GlyphTypeface(typeface); if (_glyphTypefaceCache.TryAdd(typeface, glyphTypeface)) { return(glyphTypeface); } if (typeface.FontFamily == _defaultFontFamily) { return(null); } typeface = new Typeface(_defaultFontFamily, typeface.Style, typeface.Weight); } }
/// <summary> /// Returns a new <see cref="GlyphTypeface"/>, or an existing one if a matching <see cref="GlyphTypeface"/> exists. /// </summary> /// <param name="typeface">The typeface.</param> /// <returns> /// The <see cref="GlyphTypeface"/>. /// </returns> public GlyphTypeface GetOrAddGlyphTypeface(Typeface typeface) { while (true) { if (_glyphTypefaceCache.TryGetValue(typeface, out var glyphTypeface)) { return(glyphTypeface); } glyphTypeface = new GlyphTypeface(typeface); if (_glyphTypefaceCache.TryAdd(typeface, glyphTypeface)) { return(glyphTypeface); } if (typeface.FontFamily == _defaultFontFamily) { throw new InvalidOperationException($"Could not create glyph typeface for: {typeface.FontFamily.Name}."); } typeface = new Typeface(_defaultFontFamily, typeface.Style, typeface.Weight); } }