In order to align text vertically in SVG one has to use the dominant-baseline
attribute.
This has already been discussed on SO (Aligning text in SVG) and is par
This is a giant hack, but we can approximate the vertical middle position by taking the font size into account.
The specification defines central
like that:
central
This identifies a computed baseline that is at the center of the EM box.
We can take an EM box
of known font size and measure its bounding box to compute the center.
Obviously, the code can be much cleaner, but this is just a proof-of-concept.