You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to get text-metrics to include every whitespace when computing the width of a string?
With strings that are all whitespace or mostly whitespace, the width that text-metrics produces seems to be computed after stripping out whitespaces. At the least, the width results are smaller than when I just compute the width of the string using canvas.measureText. Here's an example of the mismatch:
Am I just missing some CSS prop I need to pass to text-metrics to get it to understand how I want it to treat whitespaces?
I expected passing in pre or break-spaces to white-space would do this trick but it did not. Is it possible this "if block" should add whitespace to the line string before continue-ing if certain white-space values are present?
Also, I did see this issue but could not find the trim() culprit that was mentioned. The trim in normalizeWhitespace looks like it doesn't trim if white-space: pre is used, so I would think that should be fine.
Hey @CalvinLeGassick, thanks for the detailed issue :)
It looks like line 464 is causing this unexpected behavior. Good catch! I think maybe this if block could be removed at all as the whitespace already get's normalized in normalizeWhitespace.
Do you like to try and create a PR?
I'm not sure, but it looks looks like this should be a closed issue, as v2.0.9 contains a fix for it...
Anyway, I got to this issue because I'm having this problem with v4.0.1, therefore my question is do you think this issue became a regression in my version? thanks
Is there a way to get
text-metrics
to include every whitespace when computing the width of a string?With strings that are all whitespace or mostly whitespace, the width that
text-metrics
produces seems to be computed after stripping out whitespaces. At the least, the width results are smaller than when I just compute the width of the string using canvas.measureText. Here's an example of the mismatch:https://codesandbox.io/s/text-metrics-whitespaces-mzgh2?file=/src/index.js
Am I just missing some CSS prop I need to pass to
text-metrics
to get it to understand how I want it to treat whitespaces?I expected passing in
pre
orbreak-spaces
towhite-space
would do this trick but it did not. Is it possible this "if block" should add whitespace to theline
string beforecontinue
-ing if certainwhite-space
values are present?text-metrics/src/utils.js
Line 464 in 140bb54
Also, I did see this issue but could not find the
trim()
culprit that was mentioned. The trim innormalizeWhitespace
looks like it doesn't trim ifwhite-space: pre
is used, so I would think that should be fine.text-metrics/src/utils.js
Line 279 in 140bb54
The text was updated successfully, but these errors were encountered: