Revision: 498
Author:
ryandesign.com
Date: Wed Sep 18 01:53:47 2013 UTC
Log: fix Y-coordinate of dom text for some scripts (e.g. font4.gv
test) and at random times in Firefox depending on zoom level
http://code.google.com/p/canviz/source/detail?r=498
Modified:
/canviz/trunk/src/Entity.js
/canviz/trunk/src/getBaseline.js
=======================================
--- /canviz/trunk/src/Entity.js Wed Sep 18 00:19:44 2013 UTC
+++ /canviz/trunk/src/Entity.js Wed Sep 18 01:53:47 2013 UTC
@@ -277,6 +277,7 @@
style.fontStyle = textStyle &
TEXT_ITALIC ? 'italic' : 'normal';
style.fontWeight = textStyle &
TEXT_BOLD ? 'bold' : 'normal';
style.left = ctxScale * (this.canviz.marginX +
bbScale * (this.canviz.paddingX + x - textAlignIndex * textWidth)) + 'px';
+ style.lineHeight = 1;
style.position = 'absolute';
style.textAlign = textAlign;
style.textDecoration = decorations.length ?
decorations.join(' ') : 'none';
=======================================
--- /canviz/trunk/src/getBaseline.js Wed Sep 18 01:37:14 2013 UTC
+++ /canviz/trunk/src/getBaseline.js Wed Sep 18 01:53:47 2013 UTC
@@ -3,6 +3,7 @@
var cache = {};
+// Returns the distance between Y-coordinate 0 and the Y-coordinate of the
text's baseline.
function getBaseline(fontFamily, fontSize, fontWeight, fontStyle) {
fontWeight = fontWeight || 'normal';
fontStyle = fontStyle || 'normal';
@@ -23,13 +24,14 @@
span2Style.fontSize = SIZE + 'px';
span1Style.fontStyle = span2Style.fontStyle = fontStyle;
span1Style.fontWeight = span2Style.fontWeight = fontWeight;
+ span1Style.lineHeight = span2Style.lineHeight = 1;
span1Style.padding = span2Style.padding = 0;
span1Style.verticalAlign = span2Style.verticalAlign = 'baseline';
divStyle.visibility = span1Style.visibility = span2Style.visibility
= 'hidden';
span1.appendChild(doc.createTextNode('a'));
span2.appendChild(doc.createTextNode('a'));
body.appendChild(div);
- baseline = cache[fontFamily][fontWeight][fontStyle] = (span2.offsetTop
- span1.offsetTop) / SIZE;
+ baseline = cache[fontFamily][fontWeight][fontStyle] = (span2.offsetTop
- span1.offsetTop / 2) / SIZE;
body.removeChild(div);
}
return baseline * fontSize;