This commit is contained in:
Fabian Jakobs 2010-05-13 20:51:02 +02:00
Родитель 01ddab9597
Коммит 3ec57748a9
2 изменённых файлов: 19 добавлений и 5 удалений

Просмотреть файл

@ -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;
};

Просмотреть файл

@ -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];