-
Notifications
You must be signed in to change notification settings - Fork 647
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
Remove the 2 different font stacks. This was not fixing the webkit issue... #38
Conversation
…sue. What seems to be happening is that webkit is changing the font to the default browser font when downloading a font and not respecting the font stack. The new code requests a bogus font (sans-serif with quotes to avoid the css generic font name keyword). This has the effect of falling back to the default font for the default size. The word 'sans-serif' was chosen because it also seems to match what Chrome linux requests by default (the underlaying system library like pango, must match on sans-serif, whereas it doesn't match anythin on something like 'foo' and would fail for most cases).
Jeremie: I need to take a deeper look at this, but please don't merge it yet. The double font stacks weren't meant to solve the webkit issue of fonts changing size more than once. They were meant to prevent all browsers from giving a false negative when the font that's loaded has identical metrics to a single fallback font (such as Liberation Sans and Arial), which means that the width won't change at all. So, you should back out the change to remove the double font stacks, as those are still necessary (and necessary in more browsers than just webkit). It's good that you've gotten some more insight into the webkit issue, though. The part of webfontloader that's currently working around the webkit issue of size changing before the fonts are loaded is that we wait until we see a new width twice before saying that the fonts are active. That's the part that we would want to change in order to make a better workaround for the webkit early-positive issue. |
Hi, Sean! Thanks for the quick look. On Wed, Nov 16, 2011 at 3:57 PM, Sean McBride <
Jeremie |
Yeah, I'm pretty against removing the double stack, as it will cause a regression in all browsers for the case of loading a font with identical metrics to the fallback. I promise to look into this more deeply later today and see if we can suggest an alternative. It's good to know exactly what is causing Webkit's strange behavior (that it's ignoring the fallback stack while the web font is loading or rendering). The "wait to see the same size twice" thing was always a bit of a hack since it depends on timing. Now that we actually know what's going on, I think we can remove that "wait to see the size twice" thing and implement a better workaround. At the moment, though, I can't think of a way to workaround the case where the font we're loading has the same metrics as the browser's default font. Essentially, we need to ignore an observed width that matches the browser's default font in webkit, but if that's actually the final width of the successfully rendered font as well, then we'll never know the difference between the font loading and the browser's default font being rendered. I'm going to think about this some more and I'll get back to you today since it sounds like you guys would like to get a fix out soon. In the meantime, if you have any other ideas, chime in so we can brainstorm. |
…ebkit issue." This reverts commit 5dfe67f.
The case where the default font size is the same as the fallback is a On Thu, Nov 17, 2011 at 10:52 AM, Sean McBride
Jeremie |
Jeremie, Alright, I thought about it a bit more, and here's an outline of what I think we should do:
This means that we'll get no modifications for other browsers that don't need them, and in Webkit we'll usually get active notifications as quickly as possible, unless the font happens to have the same metrics as the browser default, which is relatively rare. Even in that case, we can tune the waiting period based on the inactive behavior so that we get an accurate active as quickly as possible. Does that all make sense? Do you want to alter this pull request to try to implement that approach and do some testing to see what the inactive behavior is like so we can tune how long to wait before marking a font that changes to |
Hey, Sean. That's pretty much what I've implemented this morning. What do you think? On Thu, Nov 17, 2011 at 2:55 PM, Sean McBride
Jeremie |
… same as the default font browser.
Nice, I think this approach will definitely work, but there are a few things we can do to optimize it further:
What about something like this within _check?
That way we can get rid of |
Ok, so I literrally went in the webkit code, and tried to figure which I've done my best to put the default value for each browser/OS combination. I've also been in touch with chrome developers and they are trying to I removed the lastObserved as you asked. And I mark the font as active I still need to fix the tests, but I've pushed the code if you wanted On Thu, Nov 17, 2011 at 3:35 PM, Sean McBride
Jeremie |
I might actually also try to simply have a set with all the possible On Thu, Nov 17, 2011 at 9:33 PM, Jeremie Lenfant-Engelmann
Jeremie |
We now check the size against that set to make sure that we do not report the font has loaded while the font is actually loading (since webkit changes the font to a last resort fallback font and is not respecting the CSS font stack). We're also marking the font as active when reaching the timeout (instead of marking it as inactive). This is needed in the case of a web font having the same size as any font in the last resort fallback font set.
I've pushed a change. I now create a set including the size of all the On Thu, Nov 17, 2011 at 11:55 PM, Jeremie Lenfant-Engelmann
Jeremie |
Hey, Sean. Do you think you'll have the time to take a look at the change before Thanks! On Fri, Nov 18, 2011 at 5:12 PM, Jeremie Lenfant-Engelmann
Jeremie |
// default browser font on a webkit browser, mark the font as active | ||
// after 5 seconds. | ||
this.finish_(this.webKitLastResortFontSizes_ ? | ||
this.activeCallback_ : this.inactiveCallback_); |
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 now means that the fonts can never be inactive on webkit browsers, which isn't right. If the sizeA and sizeB are equal to originalSizeA and originalSizeB, then we know for sure that the font is inactive, and we should mark it as such.
I think we only want to mark active if sizeA and sizeB are true in the webKitLastResortFontSizes map.
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.
On Tue, Nov 22, 2011 at 10:41 AM, Sean McBride
reply@reply.github.com
wrote:
this.finish_(this.activeCallback_);
} else if (this.getTime_() - this.started_ >= 5000) {
- this.finish_(this.inactiveCallback_);
+- // In order to handle the fact that a font could be the same size as the
- // default browser font on a webkit browser, mark the font as active
- // after 5 seconds.
- this.finish_(this.webKitLastResortFontSizes_ ?
- this.activeCallback_ : this.inactiveCallback_);
This now means that the fonts can never be inactive on webkit browsers, which isn't right. If the sizeA and sizeB are equal to originalSizeA and originalSizeB, then we know for sure that the font is inactive, and we should mark it as such.
I think we only want to mark active if sizeA and sizeB are true in the webKitLastResortFontSizes map.
Done.
Reply to this email directly or view it on GitHub:
https://github.com/typekit/webfontloader/pull/38/files#r245894
Jeremie
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.
Thanks, that part looks good now.
Jeremie, sorry, I was out of town unexpectedly for a funeral. Back now. I left a few more comments for you. I'll keep watching for your responses so we can turn it around quickly and hopefully get a new version out by Thanksgiving. |
…map. Updated tests.
Sorry about your loss :( It's fine if we push the new version next week. It would just be good Thanks for the comments! On Tue, Nov 22, 2011 at 10:54 AM, Sean McBride
Jeremie |
General question: Currently, your code finds all of the last resort fallback widths for each FontWatchRunner that gets instantiated, and one of these is instantiated for each font that we're loading. If we're loading a lot of fonts at once, this will be a lot of extra width measurements. Have you looked at how much this slows things down when loading fonts? I'm not sure how expensive taking all of these measurements repeatedly will be. |
This will have an impact on performances. This is why I'm creating On Tue, Nov 22, 2011 at 2:05 PM, Sean McBride
Jeremie |
A few numbers, done extremely unscientifically. Running the script and Without the new code: 16ms on average So on average we see an 11ms increase. As expected it does have an On Tue, Nov 22, 2011 at 3:22 PM, Jeremie Lenfant-Engelmann
Jeremie |
On Tue, Nov 22, 2011 at 3:50 PM, Jeremie Lenfant-Engelmann
3 entries in the WebFontConfig meaning, the Google Module with 3 WebFontConfig = {
Jeremie |
…has loaded. For now this is used by the Google Web Fonts module to use a specific strategy when on a webkit user agent.
Hey Jeremie, I think I prefer the style of your other webkit_fix_inheritance branch that uses straight inheritance on the FontWatchRunner. There are definitely some nice aspects to the way that the different pieces are separated in this branch, but I feel like it adds a little bit too much structure around the current way that we do font watching when we may not do that in the future. The webkit_fix_inheritance branch is a smaller, more straightforward change, and I think it puts us in a better place for exploring FontWatchRunners with totally different internals in the future. I think if you just move the comment over about the Webkit code near your font list (as you have in the other branch) and update the tests, then that other branch would be pretty much ready to go. What do you think? |
I've open a pull request for the new branch. I've added tests and We can continue the conversation on the other pull request on the other branch. On Tue, Nov 29, 2011 at 9:56 AM, Sean McBride
Jeremie |
This pull request is being closed in favor of the new work in #37. |
....
What seems to be happening is that webkit is changing the font to the
default browser font when downloading a font and not respecting the font
stack. The new code requests a bogus font (sans-serif with quotes to avoid
the css generic font name keyword). This has the effect of falling back
to the default font for the default size. The word 'sans-serif' was chosen
because it also seems to match what Chrome linux requests by default (the
underlaying system library like pango, must match on sans-serif, whereas
it doesn't match anythin on something like 'foo' and would fail for most
cases).