File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ var fs = require('fs');
3131var path = require ( 'path' ) ;
3232var url = require ( 'url' ) ;
3333var jsdom = require ( 'jsdom' ) . jsdom ;
34+ var isFullwidthCodePoint = require ( 'is-fullwidth-code-point' ) ;
3435
3536require ( './patch/jsdom.js' ) . patch ( jsdom ) ; // Fix some bugs in jsdom
3637
@@ -309,7 +310,10 @@ function ConfigureMathJax() {
309310 if ( def [ "font-weight" ] === "" ) delete def [ "font-weight" ] ;
310311 this . SUPER ( arguments ) . Init . call ( this , def ) ;
311312 SVG . addText ( this . element , text ) ;
312- var bbox = { width : text . length * 8.5 , height : 18 , y : - 12 } ;
313+ var textWidth = text . split ( '' )
314+ . map ( function ( c ) { return isFullwidthCodePoint ( c . codePointAt ( ) ) ? 13 : 8.5 } )
315+ . reduce ( function ( a , b ) { return a + b } , 0 ) ;
316+ var bbox = { width : textWidth , height : 18 , y : - 12 } ;
313317 scale *= 1000 / SVG . em ;
314318 this . element . setAttribute ( "font-family" , "monospace" ) ;
315319 this . element . setAttribute ( "transform" , "scale(" + scale + ") matrix(1 0 0 -1 0 0)" ) ;
Original file line number Diff line number Diff line change 2323 "url" : " git://github.com/mathjax/MathJax-node.git"
2424 },
2525 "dependencies" : {
26+ "is-fullwidth-code-point" : " ^2.0.0" ,
2627 "jsdom" : " 7.0 - 9.12" ,
2728 "mathjax" : " *"
2829 },
Original file line number Diff line number Diff line change 1+ var tape = require ( 'tape' ) ;
2+ var mjAPI = require ( "../lib/main.js" ) ;
3+
4+ tape ( 'the SVG output should renders full-width characters correctly' , function ( t ) {
5+ t . plan ( 1 ) ;
6+
7+ mjAPI . start ( ) ;
8+ var tex = '\\text{拾零}^i' ;
9+
10+ mjAPI . typeset ( {
11+ math : tex ,
12+ format : "TeX" ,
13+ svg : true
14+ } , function ( data ) {
15+ t . ok ( data . width , '5.133ex' , 'Width is correct' ) ;
16+ } ) ;
17+ } ) ;
You can’t perform that action at this time.
0 commit comments