raphael
raphael copied to clipboard
Chrome and tuneText()
In Chrome 19 and Raphael 2.1.0 I experienced a random problem with svg text. First in line 4308: fontSize = node.firstChild ? toInt(R._g.doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
fontSize sometimes is NaN.
Second, line 4337: dy attribute in
I've ran into this problem too when manipulating attributes on text elements that have multiple line breaks. The text renders fine at first but once you start adjusting attributes raphael will re-render the element and getComputedStyle returns "" which the toInt turns into a NaN
the font-size is needed to compute the dy attribute so my fix is to check to see if fontSize has gone NaN and if so attempt to set fontSize with font-size out of the attribute hash a
https://github.com/DmitryBaranovskiy/raphael/blob/master/dev/raphael.svg.js#L576
It seems that if the text element have detached from document,say you have a text element on paper,then you do papaer.clear(),now set the text element's attributes will cause this error.
@rcyrus explained the reason, e.g.
parseInt(document.defaultView.getComputedStyle(
document.createElement('div'),null).getPropertyValue("font-size"),10)
will get NaN.
Bump; I'm somewhat of a newbie with Raphael, but is there a solution (or proposed solution) to this problem?
@hbarudin It's been ages since i've worked with Raphael but if i recall correctly I created my own, rather inelegant patch, that simply chose a more appropriate value for fontSize once the value that Rapheal was tracking went NaN. I can't remember the exact case where fontSize went bad but it had something to do with resizing the text container.
My patch went around this particular line of code (no idea what line it is now, it probably has changed in the past couple years) and watched for the change and then once it went NaN I looked for a CSS value in font-size and set fontSize to that value.
Like i said, this was inelegant and was used in a pinch. I eventually switched from using rapheal to something else for this particular project.
Best of luck.
Hi, thank your for this thread and the suggestions. I've added
if(isNaN(fontSize)) {
fontSize = 10;
}
after the line
fontSize = node.firstChild ? toInt(R._g.doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
(6147 in Raphael 2.3.0) and this solved it.
Does this pr https://github.com/DmitryBaranovskiy/raphael/pull/1066 fix this problem? Why is it not merged?