Issue489 svg

I've extracted these changes and verified that the rendering issues are fixed on my test case.