[whatwg] Remove maxWidth from fillText and strokeText

Ian Hickson ian at hixie.ch
Wed May 11 22:00:11 PDT 2011


On Sun, 13 Feb 2011, Charles Pritchard wrote:
>
> Could we remove the optional maxWidth parameter from fillText and strokeText
> of CanvasRenderingContext2D.
> I don't see them in use anywhere, they're not widely implemented, and I don't
> see them fitting any particular common purpose.

Their intent is to ensure that when you have a specific amount of space in 
which text has to fit, and you don't know exactly what that space is or 
you don't know exactly what the text is, you can easily work around minor 
cases of limited space. For example, I use it on the issues chart:

   http://www.whatwg.org/issues/data.html

The labels on the bottom have to fit in a variable amount of space 
depending on how many months are showing, and the labels on the left have 
to fit in a fixed amount of space but their length varies on the peak of 
the graph in the current view.


> fillText("this very long strong", maxWidth) does not ensure any kind of 
> readability of the text.

Sure, it's limited to cases where the amount of space varies only a little 
from the original expectation, or for where the strings to be drawn vary 
only a little from the original expectation, but that's actually a pretty 
common situation. For example, in the example above the strings are only 
going to be in the range of 1 to, at most, 5 digits (let's hope it never 
gets there). When the variance is much bigger, you can't rely on just 
squeezing the text, you need something more clever.


> Authors can use measureText to achieve the same effect, with more 
> flexibility and better exposure to the actual size of the font that will 
> be used.

Yes, you can do it manually if your needs aren't met by the API.


> They can use clip() if they need to ensure glyphs stay within a bounding 
> box (something which maxWidth does not provide, despite its intent.

It's not intended for clipping.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


More information about the whatwg mailing list