RazrFalcon / fontdb

A simple, in-memory font database with CSS-like queries.
MIT License
138 stars 30 forks source link

Windows system font loader loads older font when multiple version is present #69

Open RagibHasin opened 1 month ago

RagibHasin commented 1 month ago

As this crate loads every font from C:\Windows\Fonts directly, it loads a potentially older version of a font, if the older version comes first in the file list.

For example, in C:\Windows\Fonts

     LastWriteTime      Name
     -------------      ----
16 Mar 23  3:21 PM      iosevka-ahad-regular.ttf
17 Mar 23  8:59 PM      iosevka-ahad-regular_0.ttf

Here iosevka-ahad-regular_0.ttf is of a later date and is registered with the Windows registry. However, as iosevka-ahad-regular.ttf comes first, it gets loaded which leads to a deviation of behavior from other software.

RazrFalcon commented 1 month ago

fontdb isn't designed to replace the system API and not designed to replicate its edge cases.

Is this Windows behavior specified anywhere? Are you suggesting we're suppose to sort fonts by data/time as well?

RagibHasin commented 1 month ago

If we don't want to access Windows font management APIs, then I think there are two options:

  1. Read the font list from the registry
    • Benefit: almost the same thing the font management API internally does, so maximal compatibility
    • Drawback: still needs to access some platform-specific APIs
  2. Sort the fonts by date-time
    • Benefit: no need for any platform-specific API
    • Drawback: there may be some font that has an older timestamp but is registered with the registry
RazrFalcon commented 1 month ago

I will think about. Low priority.