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

measureText resulting integer in CentOS 6 #472

Closed
i2joseph opened this issue Sep 24, 2014 · 6 comments
Closed

measureText resulting integer in CentOS 6 #472

i2joseph opened this issue Sep 24, 2014 · 6 comments
Labels

Comments

@i2joseph
Copy link

Hi,
The measureText method is resulting integer in CentOS 6. Is there a way to solve this problem? THANKS.

Here is the comparison result between CentOS and Mac OS X 10.8

Result from CentOS:
{ width: 25,
actualBoundingBoxLeft: 1,
actualBoundingBoxRight: 24,
actualBoundingBoxAscent: 8,
actualBoundingBoxDescent: 0,
emHeightAscent: 11,
emHeightDescent: 3,
alphabeticBaseline: 0 }

Result from Mac OS X 10.8:
{ width: 24.005859375,
actualBoundingBoxLeft: 0.017578125,
actualBoundingBoxRight: 23.162109375,
actualBoundingBoxAscent: 8.58984375,
actualBoundingBoxDescent: 0.140625,
emHeightAscent: 10.86328125,
emHeightDescent: 2.54296875,
alphabeticBaseline: 0 }

@rvagg
Copy link
Contributor

rvagg commented Sep 25, 2014

@i2joseph it'd be great if you could boil this down into a test case that passes on the correct behaviour, then it'd be easier to verify and fix and protect against regressions.

@rvagg
Copy link
Contributor

rvagg commented Sep 25, 2014

@i2joseph have a look in canvas.test.js, search for measureText and start with that test case. Copy and paste it, change the name, then throw in some asserts that check if the numbers returned aren't integers. Perhaps something like assert.notEqual(ctx.measureText('foo').width, Math.round(ctx.measureText('foo').width)), do the same for all of the properties that should not be integers.

@kangax do you have any input on the proper way to assert that the values coming out of here are appropriate?

@kangax
Copy link
Collaborator

kangax commented Sep 27, 2014

@rvagg I haven't found a good way yet. Same issue in Fabric; values could be slightly different depending on a system.

@jakeg
Copy link
Contributor

jakeg commented Dec 8, 2014

Looking at src/CanvasRenderingContext2d.cc I think this is more likely due to whether you have Pango enabled or not (rather than OSX vs Linux/CentOS). For Pango the following is used:
obj->Set(NanNew("width"), NanNew(logical_rect.width));
... and logical_rect.width always seems to be an integer.

Reading the Pango docs (https://developer.gnome.org/pango/stable/pango-Glyph-Storage.html#PangoRectangle) I can't see how to get this to be more precise :(

@jakeg
Copy link
Contributor

jakeg commented Feb 19, 2015

Tried this:

// We use get_extents not get_pixel_extents because the latter rounds (we want more precision)
  // pango_layout_get_pixel_extents(layout, &ink_rect, &logical_rect); // will round, which we don't want
  pango_layout_get_extents(layout, &ink_rect, &logical_rect); // pango_layout_get_pixel_extents will round which we don't want
  double precision_width = (double) logical_rect.width/PANGO_UNITS; // PANGO_UNITS is 1024

... but even when using get_extents instead of get_pixel_extents the logical_rect.width is still divisible by PANGO_UNITS (which is 1024).

@zbjornson
Copy link
Collaborator

Should be fixed in 2.x since Pango is required (and in 2bbfec5)?

@zbjornson zbjornson added the Bug label Nov 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants