Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Extend Canvas TextMetrics for editing and text styling #11000
base: main
Are you sure you want to change the base?
Extend Canvas TextMetrics for editing and text styling #11000
Changes from 1 commit
20e36f8
370fb3c
1f94348
1b9e735
9cab38c
85c06f1
b6a2c7a
6e08c93
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the index one past the end? Range APIs seem to behave that way but I'm not sure how conventional it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is one past the end. I hadn't realized I didn't clarify it in the spec. I'll add it explicitly as I don't know how conventional it is either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a requirement that the drawing command uses the same parameters as the measurement? If so I would say that directly here, because right now it seems suggestive but not prescribed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is specified in the section for
fillTextCluster()
. The idea when I first wrote it was to just mention the behavior expected, even if the implementation would most likely be to store the parameters in the cluster (as is implemented right now in Chrome).But, following a suggestion by @Kaiido in another comment, I changed the phrasing of that requirement by using
TextCluster
as an opaque object that stores those parameters in cluster when they are created. Hopefully this is more clear. Let me know what you think!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disclaimer: I'm not an editor, so take this with a grain of salt.
I feel this would be a lot clearer if the
TextMetrics
interface had an internal value to store the original text for each instance and reuse it where needed, instead of this tedious "the text that was passed tomeasureText()
to obtain the cluster".See for instance how
CanvasPattern
objects have a transformation matrix that isn't exposed:It might even be needed to have a clear relationship established between the
TextCluster
and theTextMetrics
from where it's been created, so that you can do something like the cluster's textmetrics's text, or, given that when theTextCluster
is createdtext
is available, andTextMetrics
may not need it otherwise, you could maybe store it directly along theTextCluster
(still in an internal value).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hadn't noticed that objects like
CanvasPattern
were defined in this way as opaque. I like that concept and I feel it applies well to this use case. Thank you so much for the suggestion!I have updated it to reflect this. For now I went with the second approach you mentioned (storing the text and the
CanvasTextDrawingStyles
directly in the cluster as internal values). Hopefully this provides more clarity. Let me know what you think!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This object should probably be created explicitly sooner, in the
getTextClusters()
method. However I'm not sure how this should be done since we want the computed values at that time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the use of the internal values of the opaque object, hopefully the relationship is clearer now. Passing the exact object from the cluster won't always be possible due to the possibility of passing
align
andbaseline
to tofillTextCluster()
when rendering, but most of the values now come from the internally stored value.