@@ -10,6 +10,7 @@ import fsSync, { promises as fs } from 'node:fs';
1010import path from 'node:path' ;
1111import punycode from 'punycode/punycode.js' ;
1212import * as simpleIcons from 'simple-icons/icons' ;
13+ import { svgPathBbox } from 'svg-path-bbox' ;
1314import svg2ttf from 'svg2ttf' ;
1415import SVGPath from 'svgpath' ;
1516import ttf2eot from 'ttf2eot' ;
@@ -46,6 +47,19 @@ const cssDecodeUnicode = (value) => {
4647 return value . replace ( '&#x' , '\\' ) . replace ( ';' , '' ) . toLowerCase ( ) ;
4748} ;
4849
50+ const convertToAspectRatioViewbox = ( path ) => {
51+ const pathInstance = SVGPath ( path ) ;
52+ const [ x0 , y0 , x1 , y1 ] = svgPathBbox ( pathInstance ) ;
53+ const width = x1 - x0 ;
54+ const height = y1 - y0 ;
55+ const scale = 24 / height ;
56+ const pathRescale = width > height ? pathInstance . scale ( scale ) : pathInstance ;
57+ const [ offsetX , offsetY ] = svgPathBbox ( pathRescale ) ;
58+ const pathReset = pathRescale . translate ( - offsetX , - offsetY ) ;
59+ const [ x0Reset , , x1Reset ] = svgPathBbox ( pathReset ) ;
60+ return { pathReset, horizAdvX : ( ( x1Reset - x0Reset ) / 24 ) * 1200 } ;
61+ } ;
62+
4963const buildSimpleIconsSvgFontFile = async ( ) => {
5064 const usedUnicodes = [ ] ;
5165 const unicodeHexBySlug = [ ] ;
@@ -64,13 +78,14 @@ const buildSimpleIconsSvgFontFile = async () => {
6478 }
6579
6680 const icon = simpleIcons [ si ] ;
67- const verticalTransformedPath = SVGPath ( icon . path )
81+ const { pathReset, horizAdvX } = convertToAspectRatioViewbox ( icon . path ) ;
82+ const verticalTransformedPath = pathReset
6883 . translate ( 0 , - 24 )
6984 . scale ( 50 , - 50 )
7085 . round ( 6 )
7186 . toString ( ) ;
7287
73- glyphsContent += `<glyph glyph-name="${ icon . slug } " unicode="${ unicodeString } " d="${ verticalTransformedPath } " horiz-adv-x="1200 "/>` ;
88+ glyphsContent += `<glyph glyph-name="${ icon . slug } " unicode="${ unicodeString } " d="${ verticalTransformedPath } " horiz-adv-x="${ horizAdvX } "/>` ;
7489 usedUnicodes . push ( unicodeString ) ;
7590
7691 unicodeHexBySlug [ icon . slug ] = {
0 commit comments