After Raphael has rendered the path corresponding to your text, let's say printed
:
use
Raphael.pathBBox(printed.attr('path'))
(doc), compute the negative offset (-width/2 and -height/2)create a matrix with
var m = Raphael.matrix()
that you translate with your offset (m.translate(left, top)
) or put offset values directly in the matrix constructor arguments (5th and 6th args for left and top)then you have two ways to apply it:
use
Raphael.mapPath
to definitely apply the matrix (it computes a path string you have to set with:printed.attr( 'path', Raphael.mapPath(printed.attr('path'), m) );
or use it like a simple transform:
printed.transform( m.toTransformString() );
If there were other transforms on this element, use
'...' + m.toTransformString()
to make your transform happening before existing ones, and
m.toTransformString() + '...'
to make your transform happening after.