@@ -299,14 +299,65 @@ public SKStreamAsset OpenStream (out int ttcIndex)
299
299
300
300
// GetKerningPairAdjustments
301
301
302
+ /// <summary>
303
+ /// If false, then <see cref="GetKerningPairAdjustments"/> will never return nonzero
304
+ /// adjustments for any possible pair of glyphs.
305
+ /// </summary>
306
+ public bool HasGetKerningPairAdjustments =>
307
+ SkiaApi . sk_typeface_get_kerning_pair_adjustments ( Handle , null , 0 , null ) ;
308
+
309
+ /// <summary>
310
+ /// Gets a kerning adjustment for each sequential pair of glyph indices in <paramref name="glyphs"/>.
311
+ /// </summary>
312
+ /// <param name="glyphs">The sequence of glyph indices to get kerning adjustments for.</param>
313
+ /// <returns>
314
+ /// Adjustments are returned in design units, relative to <see cref="UnitsPerEm"/>.
315
+ /// </returns>
316
+ /// <remarks>
317
+ /// For backwards-compatibility reasons, an additional zero entry is present at the end of the array.
318
+ /// </remarks>
302
319
public int [ ] GetKerningPairAdjustments ( ReadOnlySpan < ushort > glyphs )
303
320
{
304
321
var adjustments = new int [ glyphs . Length ] ;
322
+ GetKerningPairAdjustments ( glyphs , adjustments ) ;
323
+ return adjustments ;
324
+ }
325
+
326
+ /// <summary>
327
+ /// Gets a kerning adjustment for each sequential pair of glyph indices in <paramref name="glyphs"/>.
328
+ /// </summary>
329
+ /// <param name="glyphs">The sequence of glyph indices to get kerning adjustments for.</param>
330
+ /// <param name="adjustments">
331
+ /// The span that will hold the output adjustments, one per adjacent pari of <paramref name="glyphs"/>.
332
+ /// Adjustments are returned in design units, relative to <see cref="UnitsPerEm"/>.
333
+ /// This must contain a minimum of glyphs.Length - 1 elements.
334
+ /// </param>
335
+ /// <returns>
336
+ /// True if any kerning pair adjustments were written to <paramref name="adjustments"/>.
337
+ /// False if the typeface does not contain adjustments for any of the given pairs of glyphs.
338
+ /// </returns>
339
+ /// <remarks>
340
+ /// If this function returns false, then the first <paramref name="glyphs"/>.Length - 1 elements of <paramref name="adjustments"/> will be zero.
341
+ /// Elements of <paramref name="adjustments"/> beyond <paramref name="glyphs"/>.Length - 1 will not be modified.
342
+ /// </remarks>
343
+ public bool GetKerningPairAdjustments ( ReadOnlySpan < ushort > glyphs , Span < int > adjustments )
344
+ {
345
+ if ( adjustments . Length < glyphs . Length - 1 )
346
+ throw new ArgumentException ( "Length of adjustments must be large enough to hold one adjustment per pair of glyphs (or, glyphs.Length - 1)." ) ;
347
+
348
+ bool res ;
305
349
fixed ( ushort * gp = glyphs )
306
350
fixed ( int * ap = adjustments ) {
307
- SkiaApi . sk_typeface_get_kerning_pair_adjustments ( Handle , gp , glyphs . Length , ap ) ;
351
+ res = SkiaApi . sk_typeface_get_kerning_pair_adjustments ( Handle , gp , glyphs . Length , ap ) ;
308
352
}
309
- return adjustments ;
353
+
354
+ if ( ! res && glyphs . Length > 1 )
355
+ //Per SkTypeface::GetKerningPairAdjustments documentation, the method may have written
356
+ //nonsense into the array before bailing. Don't return it to the caller, the doc says
357
+ //such values must be ignored.
358
+ adjustments . Slice ( 0 , glyphs . Length - 1 ) . Clear ( ) ;
359
+
360
+ return res ;
310
361
}
311
362
312
363
//
0 commit comments