Re: [css2.1] [css3-fonts] <family-name> ambiguous - partially quoted names allowed?

On 03/24/2010 11:08 AM, Bert Bos wrote:
> A recapitulation of the thread from last year:
>
> Zack asked what tokens exactly were allowed in 'font-family'. I replied
> that I thought the intent was to allow either a string or a sequence of
> identifiers. Fantasai wondered if that wasn't too limited, seeing that
> the existing wording in the spec seemed to assume more.
>
> The thread was interrupted there, but I think she was right. CSS1 didn't
> restrict the tokens at all, except for commas and white space. And the
> 1998 version of CSS2 seems to only contain text that attempts to explain
> the syntax, rather than restrict it.
>
> Originally, the design goal was that as much as possible quoting should
> be avoided, so that a font name inside a STYLE attribute would not need
> a double pair of quotes. ...
>
> Names consisting of either a single string or a sequence of identifiers
> work in the sample of browsers and other programs I tested. But there
> doesn't seem to be much consistency in the handling of other tokens.
>
> Nevertheless, given that there are a number of fonts with names that
> include a number (Univers 55, 1942 Report, etc.), I'd like to allow at
> least those. (We unfortunately can't allow something like "Font No. 1"
> without quoting, because the dot would get detached from the "No.")

I think you have a good point: I think it would be surprising to authors
(it was to me when I was writing up the implications of Zack's grammar)
that digits at the start of a token would need quoting or escaping.

Here's an alternate proposal that allows numbers anywhere, but preserves
the other identifier restrictions:

Replace the paragraphs
   # If an unquoted font family name ... converted to a single space.
with the following text:

   | Font family names must either given quoted as strings_, or unquoted as
   | a sequence of one or more tokens composed of `identifier characters`_.
   | This means most punctuation characters must be escaped in unquoted font
   | family names.
   |
   | For example, the following declarations are invalid:
   |
   |   font-family: Red/Black, sans-serif;
   |   font-family: "Lucida" Grande, sans-serif;
   |   font-family: Ahem!, sans-serif;
   |   font-family: test@foo, sans-serif;
   |   font-family: #POUND, sans-serif;
   |
   | And the following declarations are valid:
   |
   |   font-family: Hawaii 5-0, sans-serif;
   |   font-family: Univers 55, sans-serif;
   |   font-family: 1942 Report, monospace;
   |   font-family: -3 Degrees, fantasy;
   |
   | If a sequence of unquoted tokens is given as a font family name, the
   | computed value is the name converted to a string by joining all the
   | identifiers in the sequence by single spaces.
   |
   | To avoid mistakes in escaping, is recommended to quote font family
   | names that contain white space or punctuation characters other than
   | hyphens:
   |
   | body { font-family: "New Century Schoolbook", serif }
   | <BODY STYLE="font-family: '3.14 Pie', fantasy">
   | h1 { font-family: 'Etc.', serif; }
   |
   | .. `strings`: http://www.w3.org/TR/CSS21/syndata.html#strings
   | .. `identifier characters`: http://www.w3.org/TR/CSS21/syndata.html#characters

Note that this imposes some tricky parse restrictions, since we don't have a token
representing {nmchar}+.

~fantasai

Received on Wednesday, 24 March 2010 21:32:00 UTC