Hello,<br><br>I believe it starts to gets more complex when you get into globalization.&nbsp; (Not that I'm an expert on that, but....)&nbsp; More thought may be needed to be put into this to make this work in a global sense (and not just with roman-based alphabets like ours.)
<br><br><br>See ya<br><br><div><span class="gmail_quote">On 10/25/06, <b class="gmail_sendername">Stefan Haustein</b> &lt;<a href="mailto:sh@kobjects.org">sh@kobjects.org</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi David,<br><br>of course adding only textStyle and drawText() is much better than<br>nothing at all! :)<br><br>However, I would still prefer an API design that keeps it simple to add<br>those methods later. Perhaps they could be included and simply return
<br>null if the requested information is not available (e.g. for a dumb EPS<br>render target?). Also, if we do not have access to font metrics, I think<br>we need an additional parameter for drawText() that specifies the<br>
alignment of the text relative to the reference point, as illustrated in<br>the image below:<br><br><a href="http://www.developer.com/img/articles/2002/12/26/03fig12.jpg">http://www.developer.com/img/articles/2002/12/26/03fig12.jpg
</a><br><br>Best regards,<br>Stefan<br><br>David Hyatt wrote:<br>&gt; I'm very reluctant to expose font metrics and information (yet).&nbsp;&nbsp;I<br>&gt; think once you start getting into specifying fonts, you open up a can<br>&gt; of worms that would make this sort of API addition a lot harder.
<br>&gt;<br>&gt; dave<br>&gt;<br>&gt; On Oct 24, 2006, at 4:05 PM, Stefan Haustein wrote:<br>&gt;<br>&gt;&gt; Hi David,<br>&gt;&gt;<br>&gt;&gt; I think it is very important to be able to determine the rendered<br>&gt;&gt; size of the text. Otherwise, there is no reliable way to make sure
<br>&gt;&gt; things do not overlap. Also, some kinds of applications (flash-like<br>&gt;&gt; effects, labels expressing weight or distance, WYSIWYG text editors)<br>&gt;&gt; may require variable font sizes or styles.<br>&gt;&gt;
<br>&gt;&gt; What do you think about<br>&gt;&gt;<br>&gt;&gt; context.textStyle = &quot;barchart&quot;; // style by reference<br>&gt;&gt;<br>&gt;&gt; context.textStyle = {&nbsp;&nbsp;// set style directly<br>&gt;&gt;&nbsp;&nbsp;&quot;font-size&quot;: &quot;8px&quot;,
<br>&gt;&gt;&nbsp;&nbsp;&quot;font-family&quot;: &quot;Monaco, monospace&quot;<br>&gt;&gt; }<br>&gt;&gt;<br>&gt;&gt; context.drawText(x,y,string); context.getFontAscent();<br>&gt;&gt; context.getFontDescent();<br>&gt;&gt; context.getFontLeading
();<br>&gt;&gt; context.getTextWidth(string);<br>&gt;&gt;<br>&gt;&gt; Best regards,<br>&gt;&gt; Stefan<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; David Hyatt wrote:<br>&gt;&gt;&gt; I think a drawText method would be extremely useful.
<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; Rather than specifying stylistic information explicitly (via a font<br>&gt;&gt;&gt; object), I'd use a special parenthetical pseudo-element. thus<br>&gt;&gt;&gt; allowing the author to specify the style as for any other element on
<br>&gt;&gt;&gt; a page.... something like this...<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; canvas::canvas-text(barchart)<br>&gt;&gt;&gt; {<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; font-size: 8px;<br>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; font-family: Monaco, monospace;<br>
&gt;&gt;&gt; }<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; and then the API would be something like:<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; drawText(y-coord of baseline, &quot;barchart&quot;, myText)<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; and letter-spacing/word-spacing would work, small-caps would work,
<br>&gt;&gt;&gt; text-shadow would work, etc. etc.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; fitTextToPath might be an interesting API too.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; dave<br>&gt;&gt;&gt; (<a href="mailto:hyatt@apple.com">hyatt@apple.com
</a>)<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; On Oct 23, 2006, at 4:07 PM, Stefan Haustein wrote:<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Gervase Markham wrote:<br>&gt;&gt;&gt;&gt;&gt; Stefan Haustein wrote:<br>&gt;&gt;&gt;&gt;&gt;&gt; I think drawElement(elem) opens up a whole new can of worms:
<br>&gt;&gt;&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;&gt;&gt; - how would an application determine the size of the text box?<br>&gt;&gt;&gt;&gt;&gt;&gt; - where is the baseline position, needed for exact axis label<br>&gt;&gt;&gt;&gt;&gt;&gt; positioning?
<br>&gt;&gt;&gt;&gt;&gt;&gt; - there are probably issues with dynamically calculated text values<br>&gt;&gt;&gt;&gt;&gt;&gt; - code with lots of cross references to elements will be<br>&gt;&gt;&gt;&gt;&gt;&gt; difficult to read
<br>&gt;&gt;&gt;&gt;&gt;&gt; - it needs to be specified whether css properties are inherited<br>&gt;&gt;&gt;&gt;&gt;&gt; from the parent element of &quot;elem&quot;.<br>&gt;&gt;&gt;&gt;&gt;&gt; - how much horizontal/vertical space is drawElement permitted to
<br>&gt;&gt;&gt;&gt;&gt;&gt; use for rendering?<br>&gt;&gt;&gt;&gt;&gt; The answer to all of these things is that the browser renders all<br>&gt;&gt;&gt;&gt;&gt; the elements in the page as it would if the &lt;canvas&gt; were not
<br>&gt;&gt;&gt;&gt;&gt; supported and the alternate content were being used. It then<br>&gt;&gt;&gt;&gt;&gt; basically screenshots the area corresponding to the element (yes,<br>&gt;&gt;&gt;&gt;&gt; I know this needs careful definition) and draws that into the canvas.
<br>&gt;&gt;&gt;&gt; I do not see how your statement answers any of my questions except<br>&gt;&gt;&gt;&gt; from the last one. You can specify some CSS constraints, but how do<br>&gt;&gt;&gt;&gt; you determine the actual rendering height of a text box with a
<br>&gt;&gt;&gt;&gt; specific width? How do you determine the pixel position of the<br>&gt;&gt;&gt;&gt; baseline? The cross reference and the dynamic text issues are not<br>&gt;&gt;&gt;&gt; addressed at all.<br>&gt;&gt;&gt;&gt;&gt; Like I said, we want to leverage the browser's deep and complex
<br>&gt;&gt;&gt;&gt;&gt; knowledge of text rendering as much as possible, and just take the<br>&gt;&gt;&gt;&gt;&gt; resulting pixel output as it would be shown to the user.<br>&gt;&gt;&gt;&gt;&gt;&gt; - the implementation in actual browsers may be more complex than
<br>&gt;&gt;&gt;&gt;&gt;&gt; it seems because of problems with internal data structures for<br>&gt;&gt;&gt;&gt;&gt;&gt; rendering hints and implicitly introducing the ability to render<br>&gt;&gt;&gt;&gt;&gt;&gt; the same element twice.
<br>&gt;&gt;&gt;&gt;&gt;&gt; - what happens with contained plugins, canvas elements,<br>&gt;&gt;&gt;&gt;&gt;&gt; self-references... all this stuff needs to be well-defined<br>&gt;&gt;&gt;&gt;&gt; Indeed. I know it's easy to state and there are edge cases. But we
<br>&gt;&gt;&gt;&gt;&gt; could put limits on it like e.g. no plugins, no &lt;object&gt;, and<br>&gt;&gt;&gt;&gt;&gt; still have something very useful for rendering text.<br>&gt;&gt;&gt;&gt; So I assume we agree that the element rendering proposal would
<br>&gt;&gt;&gt;&gt; still need significant specification work and is probably much more<br>&gt;&gt;&gt;&gt; difficult to implement. The element rendering approach may make<br>&gt;&gt;&gt;&gt; working with bulk text simpler, but this case is already handled
<br>&gt;&gt;&gt;&gt; quite fine by HTML outside the Canvas element. By asking for too<br>&gt;&gt;&gt;&gt; much, we may end up with nothing at all.<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Andrew has provided a clear and simple proposal that can easily be
<br>&gt;&gt;&gt;&gt; implemented without too much consideration of side effects. Putting<br>&gt;&gt;&gt;&gt; labels on maps, precise text positioning, starwars-like 3d<br>&gt;&gt;&gt;&gt; scrolling text, labels for game characters or in physics
<br>&gt;&gt;&gt;&gt; simulations, all the stuff that could only be done in a canvas<br>&gt;&gt;&gt;&gt; element, is trivial to implement with the drawText() approach, but<br>&gt;&gt;&gt;&gt; seems much more complex or impossible with the element rendering
<br>&gt;&gt;&gt;&gt; approach.<br>&gt;&gt;&gt;&gt;&gt;&gt; Moreover, drawElement() would not solve the drawText problem for<br>&gt;&gt;&gt;&gt;&gt;&gt; non-browser environments such as Rhino.<br>&gt;&gt;&gt;&gt;&gt; How are we anticipating &lt;canvas&gt; might be used in a non-browser
<br>&gt;&gt;&gt;&gt;&gt; context?<br>&gt;&gt;&gt;&gt; Canvas and some other parts of the spec (e.g. connections) may make<br>&gt;&gt;&gt;&gt; a lot of sense for Javascript outside of the browser context.&nbsp;&nbsp;This<br>&gt;&gt;&gt;&gt; may be outside of the scope of WHATWG, but if we can take out some
<br>&gt;&gt;&gt;&gt; building blocks and use them somewhere else, this is at least a<br>&gt;&gt;&gt;&gt; sign of good and modular API design.<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Best regards,<br>&gt;&gt;&gt;&gt; Stefan
<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;<br>&gt;<br><br></blockquote></div><br><br clear="all"><br>-- <br>&nbsp;&nbsp;&nbsp;&nbsp;Charles Iliya Krempeaux, B.Sc.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;charles @ <a href="http://reptile.ca">
reptile.ca</a><br>&nbsp;&nbsp;&nbsp;&nbsp;supercanadian @ <a href="http://gmail.com">gmail.com</a><br><br>&nbsp;&nbsp;&nbsp;&nbsp;developer weblog: <a href="http://ChangeLog.ca/">http://ChangeLog.ca/</a><br><br>