-
Notifications
You must be signed in to change notification settings - Fork 66
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
Cross-browser shield text #1010
Conversation
top: r.options.bannerPadding, | ||
top: 0, |
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.
Removed because the padding is accomplished by placing a gap between successive layouts, not by buffering the layout itself.
bannerIndex * r.px(r.options.bannerHeight - r.options.bannerPadding) | ||
bannerIndex * r.px(r.options.bannerHeight + r.options.bannerPadding) |
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'm not even sure how this code worked with this bug.
var textWidth = metrics.width; | ||
var textHeight = metrics.actualBoundingBoxDescent; | ||
let textWidth: number = | ||
Math.abs(metrics.actualBoundingBoxLeft) + | ||
Math.abs(metrics.actualBoundingBoxRight); | ||
let textHeight: number = | ||
Math.abs(metrics.actualBoundingBoxDescent) + | ||
Math.abs(metrics.actualBoundingBoxAscent); | ||
|
||
var availHeight = bounds.height - padTop - padBot; | ||
var availWidth = bounds.width - padLeft - padRight; | ||
//Adjust for excess descender text height across browsers | ||
textHeight *= 0.9; | ||
|
||
var xBaseline = padLeft + availWidth / 2; | ||
//Adjust for excess text height measured in Webkit engine specifically | ||
if (isRunningInWebKit()) { | ||
textHeight *= 0.54; | ||
} | ||
|
||
let availHeight: number = bounds.height - padTop - padBot; | ||
let availWidth: number = bounds.width - padLeft - padRight; | ||
|
||
let xBaseline: number = padLeft + availWidth / 2; |
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 is the main fix. We check both ascent/descent and left/right to get height/width, and then we make empirical adjustments to account for how the different browsers actually handle these fonts.
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 makes me wonder if WebKit is reporting the full line height as the computer text height.
let textConstraint = textLayoutFunc( | ||
{ height: availHeight, width: availWidth }, | ||
{ height: textHeight, width: textWidth }, | ||
let spaceAvail: Dimension = { height: availHeight, width: availWidth }; | ||
let measuredTextBounds: Dimension = { height: textHeight, width: textWidth }; | ||
|
||
let textConstraint: TextTransform = textLayoutFunc( | ||
spaceAvail, | ||
measuredTextBounds, |
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.
Just a nicety to add typescript typing and make it clear what's happening.
ctx.textAlign = "left"; | ||
ctx.textBaseline = "top"; |
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.
top/left makes the positioning math a bit easier and more consistent.
I tested this out on Mac OS 13, Windows 11, iOS 17, and Android 14. Looks quite consistent across all the browsers I tested! Examples of the interstate shield only for a focused comparison: Definitely some vertical padding adjustment needed for this and other shields, but that can probably be a follow up PR. Another issue I'm seeing is Chrome on Windows getting the wide shield blank for 2 digit refs. On the plus side, Safari and Firefox on Windows get the narrow shield blank for 111. |
It looks like that only happens for the slightly wider 2-digit numbers, so I suspect I can just micro-adjust that threshold and achieve the intended effect. |
Reducing the threshold from 12 to 11.8 seems to be enough for the right 2-digit to 3-digit transition on Windows/Chrome. |
This appears to be affecting shields generated by draw functions. SVG shields look okay. |
755117b fixes the weirdness we were seeing with some shields. I simplified the code that draws shields when banners are present and removed an extra draw that wasn't supposed to be there. |
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.
var textWidth = metrics.width; | ||
var textHeight = metrics.actualBoundingBoxDescent; | ||
let textWidth: number = | ||
Math.abs(metrics.actualBoundingBoxLeft) + | ||
Math.abs(metrics.actualBoundingBoxRight); | ||
let textHeight: number = | ||
Math.abs(metrics.actualBoundingBoxDescent) + | ||
Math.abs(metrics.actualBoundingBoxAscent); | ||
|
||
var availHeight = bounds.height - padTop - padBot; | ||
var availWidth = bounds.width - padLeft - padRight; | ||
//Adjust for excess descender text height across browsers | ||
textHeight *= 0.9; | ||
|
||
var xBaseline = padLeft + availWidth / 2; | ||
//Adjust for excess text height measured in Webkit engine specifically | ||
if (isRunningInWebKit()) { | ||
textHeight *= 0.54; | ||
} | ||
|
||
let availHeight: number = bounds.height - padTop - padBot; | ||
let availWidth: number = bounds.width - padLeft - padRight; | ||
|
||
let xBaseline: number = padLeft + availWidth / 2; |
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 makes me wonder if WebKit is reporting the full line height as the computer text height.
Fixes #625
This PR fixes differences between chrome and webkit by using fudge factors.
It also fixes several "I don't know how this even worked before" bugs in the banner layout code, and does some related typescript cleanup in the affected routines.
They are not pixel-perfect between browsers but they're very close. Tested on Ubuntu.
Webkit

Chrome

Firefox
