How to determine dominant baseline

From SVG

If dominant-baseline can't be extracted from the font properties use a built in table to look up what script the glyph belongs and from that determine which baseline is appropriate for the script.

The script type for a character can be determined by its Unicode range. Ranges for Unicode characters can be found in the Unicode Data File. The Unicode annex about scripts is UAX#24.

Further reading material:



The baseline table should look something like this:

Ideographic

The ideographic baseline should be at the bottom of the EM square (ie at 0) but it doesn't look very good. Setting it to half of the descent matches adobe's output, but 3/4 produces a better looking baseline across font size changes.

Alphabetic

The alphabetic baseline should be at the bottom of the EM square (ie at 0)

Mathematical

The mathematical baseline is half of the font height

Hanging

The hanging baseline used by adobe is just the top of the EM square, but a hanging baseline is lower than that. It is generally supplied by the font. A value of 0.8 times the font height produces a reasonable baseline across font size changes.

Auto

For value of Auto the SVG spec says: If this property occurs on a 'text' element, then the computed value depends on the value of the 'writing-mode' property. If the 'writing-mode' is horizontal, then the value of the dominant-baseline component is 'alphabetic', else if the 'writing-mode' is vertical, then the value of the dominant-baseline component is 'central'.