-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Potential additions to the proposed TextCluster API #11141
Comments
Just to clarify. The use case is: how can the developer know that a particular TextCluster matches (rendering-wise) another TextCluster, for the purposes of caching (either calculations or a rendered version of the cluster, for example). This would be impossible with the current API, as one would need to use the font, the text and the character interval as key hashes, i.e., you could only cache a TextCluster for the same position and the same word. Ideally, users should be able to know "this TextCluster will render identically to this other TextCluster - of the same or another word" and ideally they could do this in a way that can be extended to It's not very clear from the use cases we collected if matching those across font-size matters. I'd assume no and assume that we want to match TextClusters if they are the same "resolved font" (with size) and list of glyphs. As Andres mentioned, one way to do this would be to expose a local id (or hash) that is unique for resolved-fonts(font + size):glyph list. But other ideas would be appreciated too. |
I wonder if a more natural API would be some kind of |
In the scenario of building a cache, I think this would require going over all existing clusters that match the substring. I feel it would still be preferable to expose some value that can directly be used as a map key for efficiency. But I do feel a methods like |
@annevk would something like this work for Maps or Sets? |
Sadly no; it is not current possible to customize the equality test used by Maps and Sets. (And relevant discussions in TC39 seem stalled.) Another possibility would be to always return the same Is that feasible in real-world implementations? I guess maybe it would require making |
That kind of internal map is certainly something we have precedent for, e.g., with live collections. |
The use cases we have in mind are more towards developers knowing that the Maybe the idea of memoization could be used to generate a simple unique identifier when the cluster doesn't match an existing one? It could be a simple counter that increases if the cluster is new.
The properties are immutable as currently proposed, but two clusters can be "equivalent" for this scenario and have different |
I don't think I follow. If you always return the same
#10677 lists |
The objects might be technically different but equivalent for the use cases we have in mind. For example, for the text
We updated the IDL to make it |
What is the issue with the HTML Standard?
The possibility to create and render
TextCluster
objects has been discussed in this issue, and the spec PR is currently being reviewed.After some discussions around potential use cases for these new capabilities, a couple of interesting points came up around how to make efficient use of the new API and what would be needed to improve its usefulness:
TextCluster
, indicating that the underlying glyph (or glyphs) are the same. This would enable the creation of an atlas to reuse the clusters as textures.We wanted to see what opinions people here have on adding these as read-only attributes to the
TextCluster
interface. Were not sure what would be the best way to spec a unique id like that, as it doesn't really need to be consistent across platforms, it just has to be unique within each user agent. I tried to look around in the spec for other examples of hashing or generating unique ids but I wasn't able to find a reference.cc: @whatwg/canvas
The text was updated successfully, but these errors were encountered: