Commit a1b4afc5 authored by David Schnur's avatar David Schnur

A better fix for the font-size 'smaller' problem.

This resolves #991, replacing the earlier temporary patch.  It takes
advantage of the fact that line-height can take the form of a unit-less
integer, in which case it mirrors the font-size, even when it is
something abstract, like 'smaller'.  We can then read the dummy
element's height to learn the effective font-size.
parent df0875e5
...@@ -217,21 +217,24 @@ browser, but needs to redraw with canvas text when exporting as an image. ...@@ -217,21 +217,24 @@ browser, but needs to redraw with canvas text when exporting as an image.
// If the font was provided as CSS, create a div with those // If the font was provided as CSS, create a div with those
// classes and examine it to generate a canvas font spec. // classes and examine it to generate a canvas font spec.
// Note the trick of using a line-height of 1, without units;
// this sets it equal to the font-size, even if the font-size
// is something abstract, like 'smaller'. This enables us to
// read the real font-size via the element's height, working
// around browsers that return the literal 'smaller' value.
if (typeof font !== "object") { if (typeof font !== "object") {
var element = $("<div></div>").html(text) var element = $("<div>&nbsp;</div>")
.addClass(typeof font === "string" ? font : null) .addClass(typeof font === "string" ? font : null)
.css({ .css({ position: "absolute", padding: 0, 'line-height': 1 })
position: "absolute",
top: -9999
})
.appendTo(this.getTextLayer(layer)); .appendTo(this.getTextLayer(layer));
font = { font = {
style: element.css("font-style"), style: element.css("font-style"),
variant: element.css("font-variant"), variant: element.css("font-variant"),
weight: element.css("font-weight"), weight: element.css("font-weight"),
size: parseInt(element.css("font-size"), 10) || 13, size: element.height(),
family: element.css("font-family"), family: element.css("font-family"),
color: element.css("color") color: element.css("color")
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment