Patch attached. This is part of the work leading up to SVG support.
Created attachment 14852 [details] Cairo graphics fixes and cleanups
Comment on attachment 14852 [details] Cairo graphics fixes and cleanups r=me
Landed in r21974.