[whatwg] Still beating the drawString() dead horse...
Stefan Haustein
sh at kobjects.org
Tue Nov 14 06:36:54 PST 2006
Arve Bersvendsen wrote:
> Let's see. CSS and an element interface provides:
>
> 1) Specified and predictable white-space handling
> 2) Specified and predictable font and font-size handling (fallbacks,
> relative and absolute sizes)
> 3) Specified and predictable line-height handling
> 4) Inline formatting
> 5) Color handling
>
> A drawString would have to support all of these to be useful, and by
> that time you'll have reinvented more of CSS than you'd want to.
It is not necessary to reinvent any CSS, CSS can be used for 2), so the
predictability is the same. The remainder is out of scope for
drawString() or handled by existing canvas mechanisms, and it is simply
not true that drawString() is not usable without those features. I have
provided several use cases for drawString() in earlier posts (labels in
graph/map/data visualization), and I still do not see any use case that
would justify the added weight and complexity of drawElement().
> var myEle = document.createElement('p');
> myEle.textContent("Hello \nWorld");
> // Or choose any other method of attaching style attributes to
> elements.
> myEle.style = "color: blue; white-space: pre; font-size: 12px;
> line-height: 2; width: 100px; height: 100px;"
> // ...
> myCanvas2dContext.drawImage(myEle.drawElement(),0,0)
>
> Not too complicated.
The implied overhead makes me feel extremely uncomfortable with this
approach.
Also, what happens if the text does not fit in 100x100 px? How do I
figure out how much space the text actually occupies without starting to
look at Image pixel values -- I may e.g. want to reduce the map detail
level when the user increases the text size...
If you have drawElement() already implemented in Opera, and
drawElement() is sufficient powerful, it should be easy enough to
provide a simple drawString() for those who like to keep simple things
simple...
Best regards,
Stefan
More information about the whatwg
mailing list