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

TextMetrics Properties Do Not Get Set #11

Closed
schwarmau opened this issue Sep 12, 2018 · 4 comments · Fixed by #37
Closed

TextMetrics Properties Do Not Get Set #11

schwarmau opened this issue Sep 12, 2018 · 4 comments · Fixed by #37
Assignees
Labels
bug Something isn't working

Comments

@schwarmau
Copy link

schwarmau commented Sep 12, 2018

Issue
TextMetrics properties are not set after a call to MeasureText()

Code

protected BECanvasComponent Canvas;
private Canvas2dContext Context;
Context = Canvas.CreateCanvas2d();
double length = 282.84;
TextMetrics lengthTextMetrics = Context.MeasureText(length.ToString());

lengthTextMetrics.Width always reports 0. I tried the equivalent of this in javascript directly and it reports 282.84.

Even in javascript, though, the other properties appear undefined. This seems to be because they are not supported by all browsers yet. Perhaps this is related to the reason Width will not work as well.

@galvesribeiro galvesribeiro self-assigned this Sep 13, 2018
@galvesribeiro
Copy link
Member

Hello @schwarmau, thanks for the report.

I'll investigate the issue as soon as I get home.

Perhaps this is related to the reason Width will not work as well.

Idk which width are you referring to but, if that is the width of the component, you need to specify it as there is no default.

Will get back to you asap.

@schwarmau
Copy link
Author

schwarmau commented Sep 17, 2018

Idk which width are you referring to but, if that is the width of the component, you need to specify it as there is no default.

I think I worded my sentence poorly. I meant to say: Perhaps the lack of support for other properties of TextMetrics (such as actualBoundingBoxLeft, see: https://developer.mozilla.org/en-US/docs/Web/API/TextMetrics) might be affecting the supported property of TextMetrics (width). I haven't done much testing of this, though, so I'm not sure.

@galvesribeiro
Copy link
Member

Hello @schwarmau

Yes, some properties are not being set and that affect the precision of TextMetrics.

I'll mark this issue as a bug and will make sure it goes in on the next release.

If you want it faster, please feel free to submit a PR and I'll review/merge it right away.

Thanks!

@galvesribeiro galvesribeiro added the bug Something isn't working label Sep 26, 2018
@WilStead
Copy link
Contributor

I looked into this. TextMetrics.width is not an enumerable property (in the current spec, it has no enumerable properties at all; don't ask me why). As a result, it is always serialized to JSON as an empty object ("{}").

I'll look into writing up a PR that converts the native TextMetrics object to a DTO with a standard, enumerable width property that can be properly serialized.

@WilStead WilStead mentioned this issue Aug 22, 2019
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants