Demonstrates the effect of dominant baseline for each of its possible values on text positioning in an SVG.
Each browser/ mobile browser seems to handle these a bit differently. Here are some issues:
- Retrieving bounding boxes only works correctly after the font is loaded (and there is no easy way to find out when this happens)
- The bounding box width does not reflect the actual extent of a text, but how far it advances the cursor. That means that in an italic letter 'f' in many fonts, part of the f will actually lie outside of the bounding box
- The baseline-shift style does not work in FF
- dominant-baseline values are interpreted different among browsers
All in all its best just use 'alphabetical' (which is consistent across browsers) and do any further vertical positioning by manually by using the
dx,dy or the
transform attributes. Also, if one needs to find out about the actual bounds of a text, one cannot rely on the getBBox() or the getBoundingClientRect() DOM methods, but has to use a library like Font.js for accurate results. There is a huge performance cost to consider, though.