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
[css-fonts] Propose adding lang as a font-face descriptor #1744
Comments
Exposing an implementation detail of existing font selection facilities is not a sufficient use case to justify a new web-facing feature. |
Here's a specific use case: The Noto collection of fonts includes sans & serif fonts for most modern languages. For CJK, that means multiple fonts for the same code points, optimized for each language. They offer both subsetted font files (with just the glyphs for one language) and full CJK fonts, with the specified language as the default and the others available through OpenType features. Of course, the full fonts are much larger files. For a website that is primarily in one language, but wants to have compatible glyphs for occasional content in another language, it would be preferable to be able to use the subsetted font files, only downloading the additional language when it is required: @font-face {
font-family: Noto Sans;
src: url(.../noto-sans-jp.woff2);
lang: jp;
}
@font-face {
font-family: Noto Sans;
src: url(.../noto-sans-kr.woff2);
lang: kr;
}
@font-face {
src: url(.../noto-sans.woff2);
unicode-range: /* whatever would be the ascii/latin range */
} The last rule shows how we can currently use |
@AmeliaBR Thank you for the specific use case—it does seem to me that the CJK case is limited by the standard, rather than by existing implementations. Due to Han unification, rendering a character completely correctly requires both the codepoint and the I'll add the example from my post in #1736 of |
:shakes fist at Han unification again: @litherum Yeah, while this is definitely part of the built-ins, it's relevant for any page that wants to do high-quality rendering of both Chinese and Japanese text with a single combined font-family. |
I also think this is a good idea. Particularly if we define the "lang" property as a list of languages, and define the highest priority @font-face match as (assuming all other @font-face matching criteria are equal) the one with the longest common prefix. For example:
|
Han unification is a clear use case for language-specific font rendering, but not the only one. In Cyrillic, for example, there are differences between Russian, Serbian and Bulgarian rendering of the same Unicode code point. (A good explanation). As to whether we need a new descriptor though, things are less clear. OpenType already has a language feature, and Fonts 3 Language-specific display already states:
If that is not enough, there is also the I see the motivation for the proposed descriptor, but also see it re-inventing the OpenType language system with a combination of a new descriptor and a link to a (subsetted, single-language) font. This seems at odds with the direction the font industry seems to be headed, with multi-language fonts which can have quite careful and nuanced typography for different languages, depending of course on the effort and interest of the font designer. The matching scheme mentioned by @faceless2 looks the same as BCP 47 language tagging. On the other hand, OpenType language tagging uses a single level of 4-byte codes. So for example Traditional Chinese is |
Yes, assuming a suitably enabled font you can do all of this with |
I think it should be more clear what problem needs solving: Given a traditional Chinese document with a run of Japanese text, a property declaration such as Instead of using a language descriptor, a better approach may be to use a language exclusion descriptor. So, for the aforementioned "Traditional Chinese Font", one might declare something along the lines of This approach also avoids having to make a decision about how to label a font that contains characters from multiple languages. |
@svgeesus As mentioned by @faceless2, the intention is to skip loading the font if it doesn't apply. In @AmeliaBR's example with Noto fonts, subsetted, single-language fonts are already offered for use on the web because the full multi-language fonts are large. This somewhat accounts for the use of the BCP 47 language tags rather than OpenType language tags: the @patrickdark I think it's okay if a font contains characters from multiple languages. The author need only specify |
This looks like a good topic to f2f discussion at TPAC, perhaps together with I18n and also with Fonts WG |
For what it's worth, we've implemented this locally (with a prefix, naturally) and it's working well. Referencing the steps for font matching outlined at So for example: you have three matching fonts with languages of "zh-hant", "zh" and no language. If the font is requested by an element with a language of "zh-hans", it will match "zh". If the element language is "en", all of the fonts have equal priority based on the language match so are prioritised by the order they're defined in CSS, exactly as they are in the current spec. This approach is backwards compatible: with no languages on the @font-face rule, the matching algorithm runs as it is now. And, if a language is defined, it won't prevent it from matching an element with a different language: it will only change the priority they're matched on. I have one more argument in favour of this. In the PDF world where we're coming from, every font has to be embedded. So as well as time taken to download the font and better language-specific shapes for the glyphs, we need this to reduce the size of the final document. For example:
Without language matching (and presuming Noto Chinese has no hiragana glyphs for the sake of example), we'd embed two fonts: the first two glyphs would match the Chinese fonts as it has a higher priority, with the third matching the Japanese font. |
Just to put that one on the record: language tuning may be appropriate for Latin-script fonts as well. It appears that Polish and French use some of the same accents but with different angles, to give just one example that was widely discussed at one point in Unicode. The standard ended up "unifying" the two language versions of these characters, meaning that one either has to use some compromise font or be able to select a font variant by language. |
I think if the different glyph sets and language specific features are delivered in one font file, then lang attributes plus mapping to the OpenType mechanism is sufficient. If the font family is split into language specific fonts for bandwidth savings and language specific subsetting, then I believe this can already be implemented using If one of the divs is removed, the other font does not download.
Edit: Working in Chrome 70 and Safari TP, and FF 62. |
Your suggestion requires using a different font family per language - this proposal was about being able to do this within a single family. The original author was referring to mappings for the generic fonts (serif, sans-serif) which makes that a requirement. For non-generic fonts, having to artificially split Noto into "Noto-Japanese", "Noto-Chinese" etc. is (I believe) the problem this is trying to solve. |
The example works just as well for web font files that have the same family name in their For generic fonts, the user agent usually provides customisations to allow script/language specific generic font preferences. |
For IRG N 2074 “a proposal for a HK character set”. I recommend when mention to Chinese, use lang-script-region will be better for indicator right character set as zh-Hant-HK, zh-Hant-TW. http://appsrv.cse.cuhk.edu.hk/~irg/irg/irg45/IRG45.htm Also consider for support BCP 47 math language tag “Zmth”, I just dealt STIX font for mathematics... https://blogs.msdn.microsoft.com/murrays/2015/02/14/math-language-tag/ |
Yes, @drott's solution using |
The CSS Working Group just discussed The full IRC log of that discussion<emilio> Topic: Adding lang as a font-face descriptor<emilio> Github: https://github.com//issues/1744 <emilio> myles_: This issue is about the desire of making a font only used by elements that are on a particular language <emilio> myles_: So that each element with a particular language gets the right font attached to it <emilio> myles_: My particular feeling is that this is the latest step in a long sequence of changes to add more styling capabilities to elements <emilio> myles_: selectors already do that, in font-face we already have a bunch of other descriptor, and this moves into the model of adding more styling to font-face <emilio> myles_: I don't want to implement all of CSS in @font-face, there are examples on the issue on how to do it using style rules <addison> q+ <astearns> ack addison <gregwhitworth> +1 to myles_ <emilio> addison: If you were to put this in there's a bunch of interesting problems you need to specify, like how the lang tags match and stuff <emilio> addison: ??? <emilio> addison: If you name a language for a font-face, you don't render it anywhere else? How do you enforce that? <emilio> emilio: Isn't there a `:lang` selector you could use for that? <emilio> drott: that's the example of the issue, yeah <myles_> s/add more styling capabilities to elements/add more styling capabilities to @font-face/ <emilio> drott: I share myles_' concerns and conflicting semantics between `:lang` an this <emilio> drott: I think the intent is using the font in a more finegrained way than unicode-range and such, and I think the example also covers this, you can use css variables to use it as the same font, but not sure if I missed any part of the use case <emilio> addison: I think the idea is to affect how font-fallback works. <emilio> addison: that's pretty common for CJK <emilio> myles_: we already have facilities to do this with CSS <emilio> astearns: looks like preference is to use existing mechanisms for that, and not use descriptors, we should put the minutes in the issue and let people comment <emilio> florian: does a note / suggestion in the spec about how to solve this problem seem useful? <emilio> astearns: we should probably wait for more info from the proposers here <r12a> q+ <astearns> ack r12a <emilio> r12a: While seeking further info, one thing to ask is how would you treat with multiple languages as a single language <emilio> astearns: can that be handled by selectors? <emilio> nods |
For cases where language variants are within a font file, CSS already requires looking up the correct variant using the element's content language. In cases where the font should switch, the :lang() selector can do this already:
The CSSWG believes this should be an adequate solution, so the suggestion is to close this issue as wontfix. Let us know if there's anything we missed and should reconsider. |
I agree that the
Also, I think using CSS custom properties as a surrogate for font family is a little hacky, but perhaps that's fine. To include both serif and sans-serif Noto CJK fonts in a page we would have to something like this:
|
See https://drafts.csswg.org/css-fonts-3/#at-font-face-rule
Per the discussion in #1736, we note that generic fonts typically map to more than one system font with
lang
affecting the resultant font. Addinglang
as a@font-face
descriptor might be useful for similar reasons, for example with CJK:unicode-range
alone cannot specify fonts for each language. This can be an issue on pages containing text in more than onelang
.@font-face
) contains faces for all the characters in some text, that font may not be for the correctlang
everywhere. (A single codepoint can map to different variant glyphs depending onlang
, and this is reflected in fonts.)This addition would allow fonts to resolve
lang
-appropriately when a font family specified with@font-face
is applied to a page with multiplelang
s.The text was updated successfully, but these errors were encountered: