@@ -369,10 +369,43 @@ function arrayifyAttribute(values, step) {
369369
370370function getTextFont ( trace ) {
371371 var font = trace . textfont ;
372+ var family = font . family ;
373+ var style = font . style ;
374+ var weight = font . weight ;
372375 var str = '' ;
373- if ( font . weight === 'bold' ) str += ' Bold' ;
374- if ( font . style === 'italic' ) str += ' Italic' ;
375- var textFont = font . family ;
376+
377+ if ( weight === 'bold' ) {
378+ str += ' Bold' ;
379+ } else if ( weight <= 1000 ) { // numeric font-weight
380+ // See supportedFonts
381+ if ( family . slice ( 10 ) === 'Metropolis' ) {
382+ if ( weight > 850 ) str += ' Black' ;
383+ else if ( weight > 750 ) str += ' Extra Bold' ;
384+ else if ( weight > 650 ) str += ' Bold' ;
385+ else if ( weight > 550 ) str += ' Semi Bold' ;
386+ else if ( weight > 450 ) str += ' Medium' ;
387+ else if ( weight > 350 ) str += ' Regular' ;
388+ else if ( weight > 250 ) str += ' Light' ;
389+ else if ( weight > 150 ) str += ' Extra Light' ;
390+ str += ' Thin' ;
391+ } else if ( family . slice ( 9 ) === 'Open Sans' ) {
392+ if ( weight > 750 ) str += ' Extra Bold' ;
393+ else if ( weight > 650 ) str += ' Bold' ;
394+ else if ( weight > 550 ) str += ' Semibold' ;
395+ else if ( weight > 450 ) str += ' Medium' ;
396+ else if ( weight > 350 ) str += ' Regular' ;
397+ else if ( weight > 250 ) str += ' Light' ;
398+ else if ( weight > 150 ) str += ' Extra Light' ;
399+ str += ' Thin' ;
400+ } else { // Other families
401+ if ( weight > 500 ) str += ' Bold' ;
402+ str += ' Regular' ;
403+ }
404+ }
405+
406+ if ( style === 'italic' ) str += ' Italic' ;
407+
408+ var textFont = family ;
376409 if ( str ) textFont = textFont . replace ( ' Regular' , str ) ;
377410 textFont = textFont . split ( ', ' ) ;
378411 return textFont ;
0 commit comments