Browse Source

Make HorizontalHeadTable.Load nullable so we can handle font that do not have that table (#16064)

pull/16129/head
Benedikt Stebner 2 years ago
committed by GitHub
parent
commit
1eb3a5c54b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      src/Avalonia.Base/Media/Fonts/Tables/HorizontalHeadTable.cs
  2. 17
      src/Skia/Avalonia.Skia/GlyphTypefaceImpl.cs

4
src/Avalonia.Base/Media/Fonts/Tables/HorizontalHeadTable.cs

@ -59,11 +59,11 @@ namespace Avalonia.Media.Fonts.Tables
public short XMaxExtent { get; } public short XMaxExtent { get; }
public static HorizontalHeadTable Load(IGlyphTypeface glyphTypeface) public static HorizontalHeadTable? Load(IGlyphTypeface glyphTypeface)
{ {
if (!glyphTypeface.TryGetTable(Tag, out var table)) if (!glyphTypeface.TryGetTable(Tag, out var table))
{ {
throw new MissingFontTableException("Could not load table", "name"); return null;
} }
using var stream = new MemoryStream(table); using var stream = new MemoryStream(table);

17
src/Skia/Avalonia.Skia/GlyphTypefaceImpl.cs

@ -19,7 +19,7 @@ namespace Avalonia.Skia
private readonly SKTypeface _typeface; private readonly SKTypeface _typeface;
private readonly NameTable _nameTable; private readonly NameTable _nameTable;
private readonly OS2Table? _os2Table; private readonly OS2Table? _os2Table;
private readonly HorizontalHeadTable _hhTable; private readonly HorizontalHeadTable? _hhTable;
private IReadOnlyList<OpenTypeTag>? _supportedFeatures; private IReadOnlyList<OpenTypeTag>? _supportedFeatures;
public GlyphTypefaceImpl(SKTypeface typeface, FontSimulations fontSimulations) public GlyphTypefaceImpl(SKTypeface typeface, FontSimulations fontSimulations)
@ -38,9 +38,9 @@ namespace Avalonia.Skia
_os2Table = OS2Table.Load(this); _os2Table = OS2Table.Load(this);
_hhTable = HorizontalHeadTable.Load(this); _hhTable = HorizontalHeadTable.Load(this);
int ascent; var ascent = 0;
int descent; var descent = 0;
int lineGap; var lineGap = 0;
if (_os2Table != null && (_os2Table.FontStyle & OS2Table.FontStyleSelection.USE_TYPO_METRICS) != 0) if (_os2Table != null && (_os2Table.FontStyle & OS2Table.FontStyleSelection.USE_TYPO_METRICS) != 0)
{ {
@ -50,9 +50,12 @@ namespace Avalonia.Skia
} }
else else
{ {
ascent = -_hhTable.Ascender; if (_hhTable != null)
descent = -_hhTable.Descender; {
lineGap = _hhTable.LineGap; ascent = -_hhTable.Ascender;
descent = -_hhTable.Descender;
lineGap = _hhTable.LineGap;
}
} }
if (_os2Table != null && (ascent == 0 || descent == 0)) if (_os2Table != null && (ascent == 0 || descent == 0))

Loading…
Cancel
Save