[whatwg] are relative values of CanvasRenderingContext2D.font live to style changes?
L. David Baron
dbaron at dbaron.org
Thu Jun 12 14:58:46 PDT 2008
I'm looking at
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas.html#text
which currently says:
# When the 'font-size' component is set to lengths using
# percentages, 'em' or 'ex' units, or the 'larger' or 'smaller'
# keywords, these must be interpreted relative to the computed
# value of the 'font-size' property of the corresponding canvas
# element. When the 'font-weight' component is set to the relative
# values 'bolder' and 'lighter', these must be interpreted
# relative to the computed value of the 'font-weight' property of
# the corresponding canvas element. If the computed values are
# undefined for a particular case (e.g. because the canvas element
# is not in a document), then the relative keywords must be
# interpreted relative to the normal-weight 10px sans-serif
# default.
Suppose that the computed style of the corresponding canvas element
changes between when the font DOM attribute is set and text is
drawn. Based on the text above, it's not clear to me whether values
like '1em' or 'lighter' should be relative to the canvas's values at
the time the font is set or the time the text is drawn. In other
words:
var canvas = document.getElementById("mycanvaselement");
var ctx = canvas.getContext("2d");
canvas.style.fontSize = "16px";
ctx.font = "0.75em sans-serif"; // 12px, for now at least
canvas.style.fontSize = "32px";
ctx.fillText("hello world", 0, 0); // 12px text or 24px text?
The text above:
# The font DOM attribute, on setting, must be parsed the same way
# as the 'font' property of CSS (but without supporting
# property-independent stylesheet syntax like 'inherit'), and the
# resulting font must be assigned to the context, with the
# 'line-height' component forced to 'normal'. [CSS]
could *perhaps* be interpreted to mean that it doesn't dynamically
update, but it's not clear.
I'd prefer if it were static, because for Mozilla, we'd either have
to add new infrastructure to handle dynamic style changes for
elements inside something that's display:none or we'd have to
recompute the style for every text operation (probably the latter).
-David
--
L. David Baron http://dbaron.org/
Mozilla Corporation http://www.mozilla.com/
More information about the whatwg
mailing list