Skip to content

Commit

Permalink
Make the name table optional (#17306)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gillibald authored and maxkatz6 committed Oct 27, 2024
1 parent 4f79c1b commit f70cf39
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Avalonia.Base/Media/Fonts/Tables/Name/NameTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ public string GetNameById(ushort culture, KnownNameIds nameId)
public string GetNameById(ushort culture, ushort nameId)
=> GetNameById(culture, (KnownNameIds)nameId);

public static NameTable Load(IGlyphTypeface glyphTypeface)
public static NameTable? 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);
Expand Down
24 changes: 16 additions & 8 deletions src/Skia/Avalonia.Skia/GlyphTypefaceImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class GlyphTypefaceImpl : IGlyphTypeface2
{
private bool _isDisposed;
private readonly SKTypeface _typeface;
private readonly NameTable _nameTable;
private readonly NameTable? _nameTable;
private readonly OS2Table? _os2Table;
private readonly HorizontalHeadTable? _hhTable;
private IReadOnlyList<OpenTypeTag>? _supportedFeatures;
Expand Down Expand Up @@ -100,18 +100,26 @@ public GlyphTypefaceImpl(SKTypeface typeface, FontSimulations fontSimulations)

_nameTable = NameTable.Load(this);

TypographicFamilyName = _nameTable.GetNameById((ushort)CultureInfo.InvariantCulture.LCID, KnownNameIds.TypographicFamilyName);
//Rely on Skia if no name table is present
FamilyName = _nameTable?.FontFamilyName((ushort)CultureInfo.InvariantCulture.LCID) ?? typeface.FamilyName;

FamilyName = _nameTable.FontFamilyName((ushort)CultureInfo.InvariantCulture.LCID);
TypographicFamilyName = _nameTable?.GetNameById((ushort)CultureInfo.InvariantCulture.LCID, KnownNameIds.TypographicFamilyName) ?? FamilyName;

var familyNames = new Dictionary<ushort, string>(_nameTable.Languages.Count);
if(_nameTable != null)
{
var familyNames = new Dictionary<ushort, string>(_nameTable.Languages.Count);

foreach (var language in _nameTable.Languages)
{
familyNames.Add(language, _nameTable.FontFamilyName(language));
}

foreach (var language in _nameTable.Languages)
FamilyNames = familyNames;
}
else
{
familyNames.Add(language, _nameTable.FontFamilyName(language));
FamilyNames = new Dictionary<ushort, string> { { (ushort)CultureInfo.InvariantCulture.LCID, FamilyName } };
}

FamilyNames = familyNames;
}

public string TypographicFamilyName { get; }
Expand Down

0 comments on commit f70cf39

Please sign in to comment.