@@ -11,10 +11,6 @@ var LINE_SPACING = require('../constants/alignment').LINE_SPACING;
1111
1212// text converter
1313
14- function getSize ( _selection , _dimension ) {
15- return _selection . node ( ) . getBoundingClientRect ( ) [ _dimension ] ;
16- }
17-
1814var FIND_TEX = / ( [ ^ $ ] * ) ( [ $ ] + [ ^ $ ] * [ $ ] + ) ( [ ^ $ ] * ) / ;
1915
2016exports . convertToTspans = function ( _context , gd , _callback ) {
@@ -109,26 +105,31 @@ exports.convertToTspans = function(_context, gd, _callback) {
109105 var g = newSvg . select ( 'g' ) ;
110106 g . attr ( { fill : fill , stroke : fill } ) ;
111107
112- var newSvgW = getSize ( g , 'width' ) ;
113- var newSvgH = getSize ( g , 'height' ) ;
114- var newX = + _context . attr ( 'x' ) - newSvgW *
108+ var gBB = g . node ( ) . getBoundingClientRect ( ) ;
109+ var newSvgW = gBB . width ;
110+ var newSvgH = gBB . height ;
111+
112+ var x = + _context . attr ( 'x' ) ;
113+ var y = + _context . attr ( 'y' ) ;
114+
115+ var newX = x - newSvgW *
115116 { start : 0 , middle : 0.5 , end : 1 } [ _context . attr ( 'text-anchor' ) || 'start' ] ;
116117 // font baseline is about 1/4 fontSize below centerline
117- var textHeight = fontSize || getSize ( _context , 'height' ) ;
118+ var textHeight = fontSize || _context . node ( ) . getBoundingClientRect ( ) . height ;
118119 var dy = - textHeight / 4 ;
119120
120121 if ( svgClass [ 0 ] === 'y' ) {
121122 mathjaxGroup . attr ( {
122- transform : 'rotate(' + [ - 90 , + _context . attr ( 'x' ) , + _context . attr ( 'y' ) ] +
123+ transform : 'rotate(' + [ - 90 , x , y ] +
123124 ')' + strTranslate ( - newSvgW / 2 , dy - newSvgH / 2 )
124125 } ) ;
125- newSvg . attr ( { x : + _context . attr ( 'x' ) , y : + _context . attr ( 'y' ) } ) ;
126+ newSvg . attr ( { x : x , y : y } ) ;
126127 } else if ( svgClass [ 0 ] === 'l' ) {
127- newSvg . attr ( { x : _context . attr ( 'x' ) , y : dy - ( newSvgH / 2 ) } ) ;
128+ newSvg . attr ( { x : x , y : dy - ( newSvgH / 2 ) } ) ;
128129 } else if ( svgClass [ 0 ] === 'a' && svgClass . indexOf ( 'atitle' ) !== 0 ) {
129130 newSvg . attr ( { x : 0 , y : dy } ) ;
130131 } else {
131- newSvg . attr ( { x : newX , y : ( + _context . attr ( 'y' ) + dy - newSvgH / 2 ) } ) ;
132+ newSvg . attr ( { x : newX , y : ( y + dy - newSvgH / 2 ) } ) ;
132133 }
133134
134135 if ( _callback ) _callback . call ( _context , mathjaxGroup ) ;
0 commit comments