Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explainer suggests iterating all the fonts in order to find Consolas #27

Closed
dbaron opened this issue May 27, 2020 · 4 comments · Fixed by #47
Closed

explainer suggests iterating all the fonts in order to find Consolas #27

dbaron opened this issue May 27, 2020 · 4 comments · Fixed by #47

Comments

@dbaron
Copy link
Contributor

dbaron commented May 27, 2020

The Accessing Font Tables section of the explainer has an example containing:

  for await (const metadata of navigator.fonts.query()) {
    // Looking for a specific font:
    if (metadata.postscriptName !== "Consolas")
      continue;

This seems like a bad example in two ways:

First, it seems inefficient to iterate all the fonts in order to find "Consolas", which is inefficient; it seems like the API should perhaps have a way to ask for the "Consolas" font.

Second, while it's using local font enumeration, it doesn't provide a particularly strong use case for the enumeration feature, since it's a use where enumeration isn't particularly a desirable feature. So showing this as an example rather weakens the argument that enumeration as a feature is worth the additional fingerprinting risk that it adds.

@jakearchibald
Copy link

jakearchibald commented Oct 8, 2020

This stood out to me too.

Elsewhere (clients api, cache api) we use .match(query) and .matchAll(query) to get one/multiple items respectively. Calling .matchAll() without a query returns all items.

(although matchAll() doesn't return an async iterator in other apis, which might warrant a new name)

@poiru
Copy link

poiru commented Nov 18, 2020

@oyiptong Doesn't seem like this was resolved in #47, could we re-open this?

Figma would also find it useful to be able to lookup font metadata based on the unique Postscript name. This would allow us to access the blob only when needed.

@jakearchibald
Copy link

I agree that this isn't resolved.

@inexorabletash
Copy link
Member

The example was removed, but more importantly the API shape was updated so that query() takes a property bad, including select which can be a list of names to match against. So to find Consolas: const array = await navigator.fonts.query({select: ['Consolas']});

Not sure why we didn't re-open this earlier, but I'd consider it resolved now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants