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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
12 additions and
9 deletions
-
src/Avalonia.Base/Media/Fonts/Tables/HorizontalHeadTable.cs
-
src/Skia/Avalonia.Skia/GlyphTypefaceImpl.cs
|
|
|
@ -59,11 +59,11 @@ namespace Avalonia.Media.Fonts.Tables |
|
|
|
|
|
|
|
public short XMaxExtent { get; } |
|
|
|
|
|
|
|
public static HorizontalHeadTable Load(IGlyphTypeface glyphTypeface) |
|
|
|
public static HorizontalHeadTable? Load(IGlyphTypeface glyphTypeface) |
|
|
|
{ |
|
|
|
if (!glyphTypeface.TryGetTable(Tag, out var table)) |
|
|
|
{ |
|
|
|
throw new MissingFontTableException("Could not load table", "name"); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
using var stream = new MemoryStream(table); |
|
|
|
|
|
|
|
@ -19,7 +19,7 @@ namespace Avalonia.Skia |
|
|
|
private readonly SKTypeface _typeface; |
|
|
|
private readonly NameTable _nameTable; |
|
|
|
private readonly OS2Table? _os2Table; |
|
|
|
private readonly HorizontalHeadTable _hhTable; |
|
|
|
private readonly HorizontalHeadTable? _hhTable; |
|
|
|
private IReadOnlyList<OpenTypeTag>? _supportedFeatures; |
|
|
|
|
|
|
|
public GlyphTypefaceImpl(SKTypeface typeface, FontSimulations fontSimulations) |
|
|
|
@ -38,9 +38,9 @@ namespace Avalonia.Skia |
|
|
|
_os2Table = OS2Table.Load(this); |
|
|
|
_hhTable = HorizontalHeadTable.Load(this); |
|
|
|
|
|
|
|
int ascent; |
|
|
|
int descent; |
|
|
|
int lineGap; |
|
|
|
var ascent = 0; |
|
|
|
var descent = 0; |
|
|
|
var lineGap = 0; |
|
|
|
|
|
|
|
if (_os2Table != null && (_os2Table.FontStyle & OS2Table.FontStyleSelection.USE_TYPO_METRICS) != 0) |
|
|
|
{ |
|
|
|
@ -50,9 +50,12 @@ namespace Avalonia.Skia |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ascent = -_hhTable.Ascender; |
|
|
|
descent = -_hhTable.Descender; |
|
|
|
lineGap = _hhTable.LineGap; |
|
|
|
if (_hhTable != null) |
|
|
|
{ |
|
|
|
ascent = -_hhTable.Ascender; |
|
|
|
descent = -_hhTable.Descender; |
|
|
|
lineGap = _hhTable.LineGap; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (_os2Table != null && (ascent == 0 || descent == 0)) |
|
|
|
|