mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
parent
59eec1f27b
commit
eb8c5b4a3e
1 changed files with 20 additions and 7 deletions
|
@ -84,15 +84,28 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the provide size in any of the units allowed in the browser to
|
* Converts the provide size in any of the units allowed in the browser to
|
||||||
* pixels, by the use of the context.font property.
|
* pixels.
|
||||||
*/
|
*/
|
||||||
getPixelSize: function(size) {
|
getPixelSize: function(size) {
|
||||||
var ctx = this._context,
|
var browser = paper.browser,
|
||||||
prevFont = ctx.font;
|
pixels;
|
||||||
ctx.font = size + ' serif';
|
if (browser && browser.firefox) {
|
||||||
size = parseFloat(ctx.font);
|
// Firefox doesn't appear to convert context.font sizes to pixels,
|
||||||
ctx.font = prevFont;
|
// while other browsers do. Workaround:
|
||||||
return size;
|
var parent = this._element.parentNode,
|
||||||
|
temp = document.createElement('div');
|
||||||
|
temp.style.fontSize = size;
|
||||||
|
parent.appendChild(temp);
|
||||||
|
pixels = parseFloat(DomElement.getStyles(temp).fontSize);
|
||||||
|
parent.removeChild(temp);
|
||||||
|
} else {
|
||||||
|
var ctx = this._context,
|
||||||
|
prevFont = ctx.font;
|
||||||
|
ctx.font = size + ' serif';
|
||||||
|
pixels = parseFloat(ctx.font);
|
||||||
|
ctx.font = prevFont;
|
||||||
|
}
|
||||||
|
return pixels;
|
||||||
},
|
},
|
||||||
|
|
||||||
getTextWidth: function(font, lines) {
|
getTextWidth: function(font, lines) {
|
||||||
|
|
Loading…
Reference in a new issue