Re: [selectors] Selectors for writing scripts

On 23/05/2014 03:18, Andrew Thompson wrote:
> Apologies if this is an old topic but is there any way to specify
> different typefaces be used for content that's in different languages
> without marking it up?
>
> Obviously if one's underlying markup is nicely decorated with
> lang="en" attributes then one can select on those - I found the
> documentation for :lang().
>
> But what about runs of Japanese script inside English paragraphs? Is
> there any way to select based on the writing script a browser
> determines a piece of text? (I suppose the operative question is
> whether the browsers are doing any of this detection of simply
> passing text to the underlying OS for rendering?)

It is possible to do something similar, not with Selectors that select 
different elements, but with a "composite" family that uses a different 
font face depending on the Unicode code point being rendered.

Every @font-face rule can be restricted to some code points with the 
'unicode-range' descriptor, and multiple @font-face rules with the same 
'font-family' descriptor form a composite font.

http://dev.w3.org/csswg/css-fonts/#unicode-range-desc
http://dev.w3.org/csswg/css-fonts/#composite-fonts

In the spec, Example 13 says:
> This example shows how an author can override the glyphs used for
> Latin characters in a Japanese font with glyphs from a different
> font. The first rule specifies no range so it defaults to the entire
> range. The range specified in the second rule overlaps but takes
> precedence because it is defined later.
>
> @font-face {
>   font-family: JapaneseWithGentium;
>   src: local(MSMincho);
>   /* no range specified, defaults to entire range */
> }
>
> @font-face {
>   font-family: JapaneseWithGentium;
>   src: url(../fonts/Gentium.woff);
>   unicode-range: U+0-2FF;
> }

Of course, Unicode code point ranges can only indicate the writing 
script, not the language being used. For example, this will not help you 
distinguish Japanese and Chinese, you’ll need proper markup for that.


-- 
Simon Sapin

Received on Friday, 23 May 2014 08:54:31 UTC