Re: canvas text: ctx.font='inherit'

On Sat, 01 Aug 2009 10:16:07 +0200, Ian Hickson <ian@hixie.ch> wrote:

> On Sat, 1 Aug 2009, Simon Pieters wrote:
>> On Sat, 01 Aug 2009 03:13:09 +0200, Boris Zbarsky <bzbarsky@mit.edu>  
>> wrote:
>> > Ian Hickson wrote:
>> >
>> > So basically the behavior should be as Firefox now except:
>> >
>> > 1)  Treat inherit and initial as CSS syntax errors.
>> > 2)  Always use "font: 10px sans serif" as the parent's font, not
>> >      just when the <canvase> is outside of a DOM tree.
>> >
>> > Right?
>>
>> ...except when using a relative unit (em, ex, %) or using a relative
>> keyword (smaller, larger, bolder, lighter), in which case you inherit
>> from the canvas element.
>>
>> I think it's weird to sometimes inherit from the canvas element and
>> sometimes use 10px sans-serif. If we're going to use 10px sans-serif,
>> could we make the relative units relative to 10px sans-serif instead of
>> the canvas element?
>
> The spec never uses 10px sans-serif except as the default, unless I'm
> mistaken.

Well, it's the initial value.

Consider an author who uses the text API to write some text, and doesn't  
set the font. Then the author decides that the text is slightly too small,  
and adds this line to his code:

    ctx.font = '110% sans-serif';

It seems reasonable to expect that this will make the text 10% bigger than  
it was before.

I think this is the confusing part; it would be less confusing if the  
initial value was inherited from the canvas element, or if relative units  
and keywords are relative to 10px sans-serif.

Since you have explicitly made 10px sans-serif the initial value, and  
banned the 'inherit' keyword, it is surprising that relative keywords and  
units inherit from the element.


>> <canvas dir> (or rather the canvas element's 'direction') affects canvas
>> text rendering. Maybe direction should be an attribute on the 2d context
>> instead for consistency with .font?
>
> I considered that, but what would you make the default?

"ltr".


> The only logical
> answer seems to be "use the direction property on the <canvas>", at which
> point all you've really done is introduced a new attribute that adds yet
> another layer to something that already has far too many.

I agree that it would be pointless to introduce it if it'll use the  
direction of the canvas element.

-- 
Simon Pieters
Opera Software

Received on Saturday, 1 August 2009 09:00:03 UTC