diff --git a/src/ace/layer/Text.js b/src/ace/layer/Text.js index 651cec98..8b6989e4 100644 --- a/src/ace/layer/Text.js +++ b/src/ace/layer/Text.js @@ -6,7 +6,7 @@ ace.layer.Text = function(parentEl) { parentEl.appendChild(this.element); this.$characterSize = this.$measureSizes(); - this.$pollSizeChanges(); + //this.$pollSizeChanges(); }; (function() { @@ -41,27 +41,41 @@ ace.layer.Text = function(parentEl) { }, 500); }; + this.$fontStyles = { + fontFamily : 1, + fontSize : 1, + fontWeight : 1, + fontStyle : 1, + lineHeight : 1 + }, + this.$measureSizes = function() { var measureNode = document.createElement("div"); var style = measureNode.style; + style.width = style.height = "auto"; style.left = style.top = "-1000px"; style.visibility = "hidden"; style.position = "absolute"; style.overflow = "visible"; - measureNode.innerHTML = new Array(1000).join("Xy"); - this.element.appendChild(measureNode); + for (prop in this.$fontStyles) { + var value = ace.computedStyle(this.element, prop); + style[prop] = value; + } // in FF 3.6 monospace fonts can have a fixed sub pixel width. // that's why we have to measure many characters // Note: characterWidth can be a float! + measureNode.innerHTML = new Array(1000).join("Xy"); + document.body.insertBefore(measureNode, document.body.firstChild); + var size = { height: measureNode.offsetHeight, width: measureNode.offsetWidth / 2000 }; - this.element.removeChild(measureNode); + document.body.removeChild(measureNode); return size; }; diff --git a/src/ace/lib/dom.js b/src/ace/lib/dom.js index d42b4fb3..709eec97 100644 --- a/src/ace/lib/dom.js +++ b/src/ace/lib/dom.js @@ -47,7 +47,7 @@ this.computedStyle = function(element, style) { if (window.getComputedStyle) { - return (window.getComputedStyle(element, null))[style]; + return (window.getComputedStyle(element, "") || {})[style] || ""; } else { return element.currentStyle[style];