Re: [css2.1][css3-fonts] keywords in unquoted font family names

On May 18, 2012, at 08:34, John Daggett wrote:

> 
> I wanted to follow up on some of Bert's comments regarding reserved
> keywords and the syntax of font family names at the F2F and try again
> to propose more precise wording that will allow proper testing of this
> issue.
> 
> On the telcon a few weeks ago there was a discussion about situations
> like these:
> 
>  font-family: foo, inherit;
> 
> I don't actually see how the present wording explictly makes 'inherit, foo' 
> invalid but not 'foo, inherit'.  Specifically, I'm not sure I see an implicit
> priority in the grammar productions that distinguish 'foo, inherit' from
> 'inherit, foo'.

I agree, there is no ambiguity in the current wording. 'font-family: inherit' is the keyword inherit; and 'font-family: foo, inherit, bar' is invalid, because the font name "inherit" must be quoted.

But even if it is unambiguous, it is apparently not clear. Otherwise different implementers wouldn't have implemented it differently.

I propose to add a note in the last para of 15.3:

    Note that 'font-family: Times, inherit' is therefore an invalid
    declaration, because 'inherit' in that position can neither be a
    valid keyword nor a valid font family name.

But other wordings are possible, too. See below.

> Both Tab and Elika feel that any unquoted name that includes
> keywords like 'inherit' should be invalid, so declarations like
> the ones below would be invalid:
> 
>  font-family: foo inherit;
>  font-family: inherit foo;

I don't see any ambiguity in the spec about these. They are valid family names. Some real-world examples would be:

    font-family: Microsoft Sans Serif
    font-family: Schoolhouse Cursive B

> 
> I put together some tests for this (Javascript required):
> 
>  http://people.mozilla.org/~jdaggett/tests/font-family-parsing.html
> 
> As you can see, the results vary widely.  Webkit treats as invalid any
> declaration that includes a font name with 'inherit' or 'initial'. 
> Firefox only throws out declarations that begin with 'inherit' and not
> much else.  IE9 is simply bizarre, it almost never invalidates
> 'font-family' declarations but does invalidate, sometimes, within
> 'font' declarations.
> 
> I think the real problem is the wording below in CSS 2.1 (and in CSS3
> Fonts):
> 
>  Font family names that happen to be the same as a keyword value
>  ('inherit', 'serif', 'sans-serif', 'monospace', 'fantasy', and
>  'cursive') must be quoted to prevent confusion with the
>  keywords with the same names. The keywords 'initial' and
>  'default' are reserved for future use and must also be quoted
>  when used as font names. UAs must not consider these keywords
>  as matching the '<family-name>' type. 
> 
> This is written from the point of view of the author, it doesn't
> completely define which situations produce valid declarations and
> which ones don't.  The term "these keywords" in the last sentence
> needs to apply to 'inherit', 'default' and 'initial'.

Yes, that is why I think adding a note like the one above can help. It translates the sentence to the point of view of a reader.

> 
> I think the answer here is to come up with wording that explicitly
> defines as valid/invalid the rules below:
> 
>  /* valid */
>  font-family: inherit foo;
>  font-family: foo inherit;
>  font-family: initial foo;
>  font-family: foo initial;
>  font-family: default foo;
>  font-family: foo default;
> 
>  /* invalid */
>  font-family: inherit, foo;
>  font-family: foo, inherit;
>  font-family: initial, foo;
>  font-family: foo, initial;
>  font-family: default, foo;
>  font-family: foo, default;
> 
> In terms of CSS 2.1 errata, I would propose two changes:
> 
> 1. Correct the syntax to fix the placement of the comma:
> 
> Existing:
>   font-family: [[<family-name> | <generic-family>] [, <family-name>| <generic-family>]* ] | inherit
> 
> Proposed:
>   font-family: [[<family-name> | <generic-family>] [, [<family-name>| <generic-family>]]* ] | inherit

Interesting that nobody found that error before. It was correct in the first REC. The error was introduced in the first WD of the revised edition, in 2002...

> 
> 2. Make the wording less ambiguous:
> 
> Existing:
>  Font family names that happen to be the same as a keyword value
>  ('inherit', 'serif', 'sans-serif', 'monospace', 'fantasy', and
>  'cursive') must be quoted to prevent confusion with the
>  keywords with the same names. The keywords 'initial' and
>  'default' are reserved for future use and must also be quoted
>  when used as font names. UAs must not consider these keywords
>  as matching the '<family-name>' type. 
> 
> Proposed:
>  Font family names that happen to be the same as the keyword values
>  'inherit', 'default' and 'initial' are not allowed to match the
>  '<family-name>' type. These names or those that match generic font
>  keywords ('serif', 'sans-serif', 'monospace', 'fantasy', and
>  'cursive') must be quoted to prevent confusion with the keywords
>  with the same names.

Yes, that works, too.

> If this makes sense, I can align the wording in CSS3 Fonts to match
> this and provide more explanation and examples of valid/invalid usage.



Bert
-- 
  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/people/bos                               W3C/ERCIM
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 (0)4 92 38 76 92            06902 Sophia Antipolis Cedex, France

Received on Monday, 21 May 2012 15:18:30 UTC