AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.79k stars 2.23k forks source link

Name table parsing is incorrect #16322

Open kekekeks opened 3 months ago

kekekeks commented 3 months ago

Describe the bug

Was looking at this PR and noticed that while LCIDs map nicely to platformID=3, we pretty much ignore other platform IDs. E. g. platformID = 1 has its own set of language codes.

While being generally safe to do when filtering language IDs we can't ignore the platformID when selecting the encoding here, since non-windows fonts have different encoding identifiers and it will cause exceptions.

@Gillibald

To Reproduce

Try loading some font with mac/unicode platform in its name table

Expected behavior

No response

Avalonia version

master

OS

No response

Additional context

No response

kekekeks commented 3 months ago

We should also probably fall back to using PostScript font names if name table is unavailable or unreadable.

Gillibald commented 3 months ago

Such ancient encodings require a reference to https://learn.microsoft.com/en-us/dotnet/api/system.text.codepagesencodingprovider?view=net-8.0 Modern fonts only use the Unicode encoding.

To make this work we need some feature flag to enable support for older platforms

kekekeks commented 3 months ago

We need to explicitly skip reading them and explicitly fall back to PS font name then. Right now we are simply ignoring the relevant encoding field.

MIRIMIRIM commented 3 months ago

I think correctly parsing old fonts' name record is a troublesome job, they may use different encoding from name record.

If you just want to get the correct language code when platformID=3, you can do a simple conversion, such as https://github.com/HinTak/Font-Validator/blob/aa6d6bc0f1b5eb257877a998f97dbb323f7ddabb/OTFontFile/Table_name.cs#L102

kekekeks commented 3 months ago

The thing is, we can't rely on all encodings to be available in the published app. So we still need to silently ignore the name table entries we can't decode properly.