From 1eb3a5c54bec71ec909f5fbe5c6f6289531a15fa Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Tue, 25 Jun 2024 21:34:37 +0200 Subject: [PATCH] Make HorizontalHeadTable.Load nullable so we can handle font that do not have that table (#16064) --- .../Media/Fonts/Tables/HorizontalHeadTable.cs | 4 ++-- src/Skia/Avalonia.Skia/GlyphTypefaceImpl.cs | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Avalonia.Base/Media/Fonts/Tables/HorizontalHeadTable.cs b/src/Avalonia.Base/Media/Fonts/Tables/HorizontalHeadTable.cs index 10b831dd1e..0942296536 100644 --- a/src/Avalonia.Base/Media/Fonts/Tables/HorizontalHeadTable.cs +++ b/src/Avalonia.Base/Media/Fonts/Tables/HorizontalHeadTable.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); diff --git a/src/Skia/Avalonia.Skia/GlyphTypefaceImpl.cs b/src/Skia/Avalonia.Skia/GlyphTypefaceImpl.cs index f563143507..e1fe0251d2 100644 --- a/src/Skia/Avalonia.Skia/GlyphTypefaceImpl.cs +++ b/src/Skia/Avalonia.Skia/GlyphTypefaceImpl.cs @@ -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? _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))