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

Fix text baselines and measureText #985

Merged
merged 1 commit into from Sep 2, 2017

Conversation

zbjornson
Copy link
Collaborator

@zbjornson zbjornson commented Sep 2, 2017

  • Fixes text baseline adjustment (fillText, strokeText, measureText), including when rotation and scale transforms are active. (Fixes Text baseline for rotated text is wrong in 2.0 #983)
  • Fixes measureText results. Some had the wrong signs and/or weren't adjusting for the baseline properly.

tl;dr: Fixes stuff, no regressions, still not perfect.


Baselines

The good - these are fixed:
image

The bad - this still doesn't work:
image
Known issue: all we have is the current transformation matrix, and it's impossible to uniquely decompose that matrix into the scale, rotation and skew matrices. (We need the scale matrix only to adjust the pango metrics.) See https://math.stackexchange.com/questions/1415854/decompose-affine-transformation-including-shear-in-x-and-y and the linked questions. Given that the Canvas spec defines context.transform(a, b, c, d, e, f) which thus lets you define a skew, scale and rotation simultaneously, I don't know what to do ... but I think skew is relatively rare, and this PR is an improvement over what it was. Haven't looked what browsers do; they might have tighter integration of their text and graphics libraries that avoids this problem.


measureText

Also tricky because there's nothing to compare against. Chrome is the only browser with any support right now, but I think some of their values and test assertions are wrong as I noted in my comment. (Definitions in the spec are here. There's also an older polyfill with visual tests -- the logic for drawing the bounding box in the new tests['measureText()'] test matches the logic from the polyfill's tests so I feel reasonably comfortable that the metrics are now correct.)

image
(left is node-canvas, right is Chrome with the experimental canvas flag enabled)

* Fixes text baseline adjustment (fillText, strokeText, measureText) when rotation transform is active.

* Fixes measureText results. Some where negative when they should have been positive and weren't adjusting for the baseline properly.

Fixes Automattic#983
@LinusU LinusU merged commit 28a063a into Automattic:master Sep 2, 2017
@zbjornson zbjornson deleted the 983-baselines branch September 2, 2017 16:55
@LinusU
Copy link
Collaborator

LinusU commented Sep 5, 2017

Published in 2.0.0-alpha.5

zbjornson added a commit to zbjornson/node-canvas that referenced this pull request Sep 7, 2017
LinusU added a commit that referenced this pull request Sep 8, 2017
Minimal backport of #985 (rotated text baselines) to v1.x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Text baseline for rotated text is wrong in 2.0
2 participants