[whatwg] 2D canvas feature proposal: text decoration
ian at hixie.ch
Fri Sep 27 14:05:47 PDT 2013
On Wed, 21 Aug 2013, Justin Novosad wrote:
> On Tue, Aug 20, 2013 at 6:32 PM, Ian Hickson <ian at hixie.ch> wrote:
> > On Thu, 18 Apr 2013, Justin Novosad wrote:
> > >
> > > This is a really simple proposal to add support for text decorations
> > > in 2D canvas contexts.
> > >
> > > IDL to add to interface CanvasDrawingStyles:
> > >
> > > attribute DOMString textDecoration;
> > >
> > > It would support all the same modes as the 'text-decoration' CSS
> > > property (except inherit), and default would be 'none'.
> > That's anything but simple. :-)
> > The CSS text-decoration model is actually quite complex. Also, there
> > have been many proposals to split 'text-decoration' into
> > sub-properties, so it is only going to get more complicated from
> > there.
> > What's your use case? That is, when do you need to underline text?
> Take a web app that presents a view of an arbitrarily large document (map,
> spreadsheet, word processor document, drawing, etc).
Well, which one? :-)
A word processor document definitely doesn't belong in <canvas>, as
Maps and drawings are obviously applicable to <canvas>. Spreadsheets
maybe, though probably only because we don't have a better solution.
So, let's assume we're talking about maps and drawings.
> Using the DOM to represent such documents for the purpose of rendering can
> be quite inefficient. The two basic approaches are:
> a) Put the entire document into the DOM and incur massive layout and style
> recalculation penalties.
> b) Put only the visible part of the document in the DOM and incur frequent
> layout and style recalculation penalties, as you scroll around
> With 2D canvas, the app can manage its own document model, often in ways
> that perform better by several orders of magnitude.
> There is increasing pressure from app developers for us to improve the text
> feature set in 2D canvas so that so that apps can be ported to 2D canvas.
What maps and drawings need underlines that are more elaborate than just
stroking a line under the text manually?
> Text decoration can theoretically be drawn directly by the application
> by using font metrics to compute decoration positions, but this is often
> very complex to do correctly in a truly portable way.
We could add underline metrics to TextMetrics if that would help.
I definitely do not think it makes sense to add APIs to <canvas> until
such time as it's possible to create a CSS-compliant text formatter in
<canvas>. That way lies madness, as text formatting is ludicrously
complicated. We already have CSS. If doing things with CSS and the DOM is
too slow, then we should fix that, we shouldn't just tell people to
rewrite their apps in <canvas>.
Ian Hickson U+1047E )\._.,--....,'``. fL
http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,.
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
More information about the whatwg