Open Bug 1511675 Opened 6 years ago Updated 2 years ago

When lang changes without specifying a font-family, we incorrectly inherit the default generic family from the parent style.

Categories

(Core :: CSS Parsing and Computation, defect, P3)

defect

Tracking

()

People

(Reporter: emilio, Unassigned)

References

Details

Attachments

(1 file)

Attached file Testcase (deleted) —
Follow-up from bug 1511570, see the test-case.

This is a Stylo regression, and boils down to this code not making quite a lot of sense:

  https://searchfox.org/mozilla-central/rev/3564dfde3b125878dc5a04fe92629fc5195942df/servo/components/style/properties/cascade.rs#706

We need to come up with something sane for this font stuff :((
Summary: When lang changes without specifying a font-family, we incorrectly inherit the default generic family from the previous language. → When lang changes without specifying a font-family, we incorrectly inherit the default generic family from the parent style.
Jonathan, so I took a quick look at this, and this is really annoying to fix without a lot of complexity that the old style system did have.

Do we really need different generic families depending on language?

AIUI the expected behavior is something like (assuming lang="serif" is a language that has a default generic of "serif" and lang="sans" a default generic font of "sans-serif"):

 * I'm serif <div lang="sans">I'm sans-serif <div lang="serif">I'm serif</div></div>

 * I'm serif <div lang="sans" style="font-face: sans-serif">I'm sans-serif <div lang="serif">I'm sans-serif</div></div>

Right?
Flags: needinfo?(jfkthame)
ISTR Manish was looking into this during the stylo transition, maybe he remembers more details.

(In reply to Emilio Cobos Álvarez (:emilio) from comment #2)
> Jonathan, so I took a quick look at this, and this is really annoying to fix
> without a lot of complexity that the old style system did have.
> 
> Do we really need different generic families depending on language?

That's a good question. I'd love to simplify our font prefs setup and get rid of that, but I'm concerned about the break from existing behavior. Our default (on desktop) for Western (Latin-script & similar) languages has been serif for a very long time, and for CJK languages it has been sans-serif; changing either of those seems like it could affect a lot of content.

An example like

  data:text/html,<div lang="en">one <span lang="zh-cn">two

currently gives me "one" in a serif font and "two" in sans-serif on both Firefox and Chrome. While I'd be interested in trying to switch to a single default (I'd probably go for sans-serif), I'm not sure how much breakage or user pushback it would cause.

> 
> AIUI the expected behavior is something like (assuming lang="serif" is a
> language that has a default generic of "serif" and lang="sans" a default
> generic font of "sans-serif"):
> 
>  * I'm serif <div lang="sans">I'm sans-serif <div lang="serif">I'm
> serif</div></div>
> 
>  * I'm serif <div lang="sans" style="font-face: sans-serif">I'm sans-serif
> <div lang="serif">I'm sans-serif</div></div>
> 
> Right?

s/font-face/font-family/ there, but otherwise yes, I think so.
Flags: needinfo?(jfkthame)
NI Manish based on comment 3.

Anyone care to take a stab at setting this bug's priority?
Flags: needinfo?(manishearth)
(In reply to Jonathan Kew (:jfkthame) from comment #3)
> An example like
> 
>   data:text/html,<div lang="en">one <span lang="zh-cn">two
> 
> currently gives me "one" in a serif font and "two" in sans-serif on both
> Firefox and Chrome. While I'd be interested in trying to switch to a single
> default (I'd probably go for sans-serif), I'm not sure how much breakage or
> user pushback it would cause.

FWIW, that example gives me serif font in Chromium (on Linux), and also WebKit (also on Linux, via Epiphany).
I did a bit more testing via browserstack. All browsers agree on rendering serif by default for latin text, so that seems harder to change, but for others, looks like https://crisal.io/tmp/lang-default-font.html renders:

 * Firefox: sans-serif (with the caveat of this bug and such of course)
 * Chrome: sans-serif on Mac / Windows, serif on Linux
 * Edge: serif
 * Safari: serif

So I _think_ changing the default generic to be serif here independently of language would make sense here.

Jonathan, would you be fine with changing the prefs here (at least for Nightly / Beta) so that the default generic is serif everywhere? That'd allow us to eventually simplify this if it sticks.
Flags: needinfo?(jfkthame)
I guess we could give it a try and see how people react. I'd mostly be concerned whether such a change might upset some CJK users if they're accustomed to getting the "sans-serif" faces by default.

Maybe people like :m_kato or :masayuki or :timdream would have opinions on this: Would it be OK to change the browser default font for CJK content from sans-serif to serif? Obviously, this would only affect content that does not explicitly apply a font-family.
Flags: needinfo?(timdream)
Flags: needinfo?(masayuki)
Flags: needinfo?(m_kato)
Flags: needinfo?(jfkthame)
So, essentially, you want to remove bug 95227.

I personally don't have a strong opinion about it, in fact, I am all for simplicity in code and consistency across locales when we can.

AFAIK the feature is needed for CJK mostly because people feel differently on which Latin font -- serif or sans-serif -- look great if you put it alongside with the default CJK font. At the time, sans-serif looked better, mostly because the default font *looked* like sans-serif in content font sizes with their embedded bitmap glyphs.

Do we have good looking serif CJK font nowadays? This question is still very subjective and depends on the OSes.

For me on macOS with Retina screen I am more than happy to use serif as default. There will be people on Windows feel differently though.

Nonetheless, at the end of the day, we should probably acknowledge the fact there aren't many Geocities websites anymore and perhaps people will not notice the choice of default generic font.

Hope this helps.
Flags: needinfo?(timdream)
Hmm, although we have to support Windows 7, Windows 7 has no cleartype Japanese font for serif.  So if Windows 7 is discontinued, I don't have strong objection.

> * Firefox: sans-serif (with the caveat of this bug and such of course)
> * Chrome: sans-serif on Mac / Windows, serif on Linux
> * Edge: serif

As long as I test, I think that latin 1 is serif, but Japanese (Hiragana, Kanji and etc) is sans-serif (Meiryo).  Microsoft seems to change font-family by script.

My concern is that changing default font causes some site's layout is broken.  If Chrome is changed to serif, many developers will fix it.  But if this change is Firefox only, they might not fix it.
Flags: needinfo?(m_kato)
I don't agree with changing the default generic font-family from sans-serif to serif because:
- Win7 does not have good serif font for Japanese (I don't know about Chinese and Korean language) as Makoto-san said.
- I bet that not so many Windows users use HiDPI environment.  So, decorations in Chinese characters of serif font may not be rendered beautifully especially when font-size is not enough large.
- There are only a few websites which specify serif fonts to their main text in Japan (as far as I know). So, as Makoto-san said, if they think serif fonts are not readable but they ignore Firefox users due to the market share, only our users would get the inconvenience.

Sounds like the cause of this bug is, we don't resolve generic font-family at root element so that we have as like there is another font-faimily value, |font-family: language-default;|. (I probably commented this point in somewhere several years ago...)
Flags: needinfo?(masayuki)
Priority: -- → P3

Yeah so IIRC this boils down to the difference between what we do and what we used to do is that what we used to do was "recompute everything assuming the lang was always this lang" (which was expensive and complicated) and what we do now is "track font-size as a formula in addition to being a value". We do not do the same for font-family, however. We could, one possible fix is to store computed font-family as a (family, is_explicit) pair.

Flags: needinfo?(manishearth)
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: