Giter VIP home page Giter VIP logo

svgs2fonts's Introduction

svgs2fonts

svg 图标转字体图标库(svgs -> svg,ttf,eot,woff,woff2)。English readme

版本

2.0.3

安装

1.全局安装(脚手架工具)

npm i -g svgs2fonts

验证

svgs2fonts -v

2.模块依赖安装

npm i --save svgs2fonts

使用

方式 1——模块引入(支持 TypeScript)

import Svgs2fonts from 'svgs2fonts';
// or
// const Svgs2fonts = require('svgs2fonts');

Svgs2fonts.init(options);

其中 options 参数:

字段 类型 默认值 描述
src string - svg 图标文件的目录路径
dist string ./dist 字体图标输出路径
fontName string iconfont 输出图标/字体名称
unicodeStart number 10000 unicode 起始数字(设置此指是需要避开正常 unicode 范围),(v2.0之前对应字段为startNumber
noDemo boolean true 是否需要输出 html Demo 文件
debug boolean false 是否开启 debug 模式以输出更多执行信息
demoUnicodeHTML string demo_unicode.html unicode 类型的示例 html 名称
demoFontClassHTML string demo_fontclass.html fontClass 类型的示例 html 名称

*V2 废弃字段:

  • timeoutv2.0废弃):{Number},执行超时时间,默认为 60s(60000
  • loggerv2.0废弃):{Object},日志记录。
demo
import Svgs2fonts from 'svgs2fonts';
import { join } from 'path';

Svgs2fonts.init({
  src: __dirname, // svg path
  dist: join(__dirname, 'dest'), // output path
  fontName: 'myIconfont', // font name
  noDemo: true, // no demo html files
  debug: true, // open debug
})
  .then(() => console.log('task success!'))
  .catch(err => console.log(`task failed(${err})`));

方式 2——控制台

svgs2fonts {srcpath} {distpath} {options}

其中参数:

  • srcpath: svg 源文件路径(相对当前窗口环境),传""时为当前窗口路径;
  • distpath: 导出路径,默认在源文件路径下;
  • options: 配置参数,见下文
example
svgs2fonts svg dist

options 配置参数

-n / --name

图标库的名字(default: "iconfont").

example
svgs2fonts svg dist -n myiconfont

--number

unicode 起始编码(default: 10000).

example
svgs2fonts svg dist --number 50000

--nodemo

不要 demo html(default: false).

example
svgs2fonts svg dist --nodemo

--debug

是否开启 debug 模式(default: false).

example
svgs2fonts svg dist --debug

Project build

安装依赖:

npm i

构建:

npm run build

单测:

npm run test

demo 测试:

npm run test:example

Author

Micheal Wayne

引导文章-《svg、ttf、woff、woff2 图标的研究及转换(svgs2fonts)》

Build time

2018.08.26

Last modified

  • 2023.12.16: v2.0.3 add some defensive handing;
  • 2023.06.03: v2.0.2 optimal variable control;
  • 2022.11.03: v2.0.1 split css & support svg size options;
  • 2022.10.07: code bug fixed;
  • 2022.03.20: v2 support for ts;
  • 2021.12.16: fix IE8 bug;

svgs2fonts's People

Contributors

dependabot[bot] avatar michealwayne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

svgs2fonts's Issues

关于四这个字的svg格式,在进行转换时,出现问题了,将四变成了口

svg格式如下

<svg xmlns="http://www.w3.org/2000/svg" width="866" height="404" viewBox="0 0 866 404" version="1.1">
	<path d="M 443.782 14.551 C 443.480 14.854, 433.617 15.500, 421.866 15.987 C 399.779 16.903, 385.060 18.673, 372.038 21.980 C 359.449 25.177, 349.805 25.900, 334 24.832 C 326.025 24.293, 318.150 23.803, 316.500 23.744 C 314.608 23.676, 311.468 24.964, 308 27.230 C 301.916 31.205, 290.658 34.897, 275.477 37.897 C 269.990 38.981, 262.232 40.998, 258.239 42.379 C 247.577 46.064, 232.515 47.601, 222.679 46.007 C 217.273 45.130, 209.860 44.938, 198.679 45.385 C 180.901 46.094, 184.058 46.676, 163.318 38.874 C 157.531 36.697, 156.829 36.639, 152.318 37.969 C 147.091 39.511, 143.109 39.635, 135.767 38.485 C 129.506 37.505, 126.063 39.024, 120.484 45.229 C 115.807 50.431, 113.365 56.533, 110.444 70.315 C 108.752 78.303, 108.567 89.058, 110.038 94.007 C 110.610 95.928, 111.508 102.606, 112.036 108.846 C 112.563 115.087, 113.869 125.212, 114.938 131.346 C 119.683 158.583, 121.221 166.851, 122.500 172 C 123.251 175.025, 124.374 183.800, 124.994 191.500 C 126.549 210.793, 129.690 235.440, 131.399 241.754 C 132.181 244.644, 133.127 250.944, 133.501 255.754 C 133.875 260.564, 135.230 270.350, 136.513 277.500 C 137.795 284.650, 139.351 295.675, 139.970 302 C 141.473 317.350, 143.648 329.628, 146.600 339.424 C 148.297 345.056, 149.334 351.888, 150.027 362 C 151.112 377.823, 152.314 383.800, 154.589 384.673 C 155.401 384.984, 158.618 383.545, 161.737 381.474 C 170.078 375.936, 174.067 375.778, 184.297 380.578 C 191.318 383.873, 193.866 384.524, 201.999 385.100 C 208.156 385.537, 213.436 386.556, 217 387.996 C 224.998 391.227, 237.431 390.249, 247.995 385.558 C 254.746 382.559, 256.705 382.170, 267.500 381.683 C 279.585 381.138, 284.563 379.951, 295 375.125 C 301.469 372.134, 316.239 372.175, 326.568 375.214 L 334.094 377.428 344.662 371.964 L 355.231 366.500 366.365 366.590 C 372.489 366.640, 381.419 367.247, 386.208 367.938 C 393.121 368.936, 396.411 368.943, 402.167 367.972 C 408.311 366.935, 433.801 366.485, 459 366.967 C 462.025 367.025, 478.900 366.655, 496.500 366.145 C 527.715 365.241, 545.996 365.823, 556 368.040 C 558.475 368.588, 567.337 369.883, 575.693 370.918 C 588.020 372.444, 592.407 372.604, 598.945 371.770 C 609.087 370.475, 613.964 371.700, 620.637 377.217 C 628.509 383.724, 632.553 384.422, 642.518 380.994 C 645.726 379.890, 651.014 378.558, 654.269 378.034 C 659.045 377.265, 662.103 375.806, 670.098 370.484 C 675.669 366.775, 680.630 362.682, 681.430 361.136 C 683.403 357.320, 689.099 332.786, 689.703 325.500 C 689.977 322.200, 691.505 315.332, 693.100 310.238 C 694.695 305.144, 696 299.848, 696 298.470 C 696 297.091, 697.533 291.134, 699.407 285.232 C 708.574 256.354, 712.038 243.298, 713.530 232 C 713.929 228.975, 715.285 223.062, 716.542 218.860 C 717.800 214.658, 719.150 208.583, 719.544 205.360 C 719.937 202.137, 722.229 193.356, 724.637 185.846 C 727.879 175.736, 729.279 169.377, 730.032 161.346 C 730.590 155.381, 731.989 145.550, 733.140 139.500 C 735.769 125.684, 735.759 118.494, 733.100 109.020 C 731.945 104.906, 731 100.273, 731 98.725 C 731 94.169, 727.021 91.001, 721.295 90.996 C 715.479 90.992, 711.524 88.772, 706.891 82.913 C 698.547 72.362, 685.183 60.909, 675.027 55.604 C 671.437 53.729, 662.107 50.368, 654.292 48.136 C 641.042 44.351, 639.323 44.091, 628.792 44.287 C 615.893 44.528, 609.499 43.143, 596.594 37.317 C 589.178 33.968, 587.730 33.667, 578.025 33.453 C 562.271 33.107, 554.454 32.065, 544.500 28.987 C 536.640 26.556, 532.840 26.070, 514.500 25.155 C 495.007 24.183, 492.617 23.850, 481.197 20.521 C 474.430 18.548, 463.630 16.278, 457.197 15.475 C 443.640 13.784, 444.491 13.843, 443.782 14.551 M 408.663 71.072 C 405.016 72.552, 401.941 72.969, 396.163 72.767 L 388.500 72.500 379 79.023 C 370.589 84.799, 369.156 86.231, 366.500 91.523 L 363.500 97.500 362.664 122.500 C 361.456 158.626, 361.383 175.160, 362.379 186.554 C 363.142 195.273, 362.981 197.795, 361.165 205.554 C 359.233 213.812, 358.490 228.315, 359.086 246.178 C 359.153 248.201, 358.439 252.173, 357.498 255.005 C 355.797 260.126, 355.803 260.194, 358.524 267.655 C 360.875 274.100, 361.168 276.061, 360.603 281.575 C 359.818 289.237, 361.004 292.135, 367.040 297.303 C 375.809 304.808, 389.181 307.180, 402.297 303.556 C 408.080 301.958, 409.843 301.851, 414.123 302.839 C 420.573 304.328, 439.130 304.341, 444.074 302.860 C 449.395 301.265, 452.970 297.069, 458.859 285.500 C 463.706 275.981, 464.007 274.921, 465.134 263.449 C 466.257 252.027, 466.206 251.065, 464.159 245.005 C 461.601 237.431, 461.477 234.002, 463.524 227.409 C 466.048 219.277, 466.471 207.588, 464.576 198.337 C 463.026 190.770, 463.022 189.590, 464.524 182.178 C 466.555 172.155, 466.109 138.566, 463.665 117.500 C 462.772 109.800, 462.032 99.180, 462.021 93.899 C 461.997 83.086, 460.904 78.793, 457.114 74.627 C 452.572 69.635, 449.218 68.797, 439.015 70.105 C 432.341 70.961, 428.142 70.967, 422.493 70.127 C 413.352 68.767, 414.543 68.686, 408.663 71.072 M 542.395 73.901 C 537.525 76.871, 535.216 81.422, 523.418 111.301 C 519.282 121.776, 515.434 139.039, 514.456 151.500 C 514.068 156.450, 512.923 163.200, 511.913 166.500 C 508.008 179.255, 504.774 198.813, 503.067 220 C 502.513 226.875, 501.352 234.750, 500.488 237.500 C 499.623 240.250, 498.482 245.875, 497.953 250 C 497.424 254.125, 496.036 260.373, 494.869 263.884 C 493.281 268.662, 492.904 271.554, 493.369 275.384 C 493.711 278.198, 494.394 283.794, 494.887 287.821 C 495.561 293.319, 496.371 295.770, 498.142 297.666 C 501.642 301.412, 505.345 303, 510.585 303 C 513.161 303, 518.021 303.440, 521.385 303.977 C 524.748 304.514, 532 305.406, 537.500 305.957 C 543 306.509, 553.125 308.341, 560 310.028 C 572.162 313.011, 606.794 318.004, 615.280 317.996 C 623.204 317.989, 628.097 312.837, 629.582 302.937 C 630.401 297.476, 635.747 280.042, 644.947 252.831 C 648.791 241.463, 652.421 229.123, 653.015 225.407 C 653.608 221.692, 654.968 216.593, 656.036 214.076 C 658.524 208.213, 663.457 191.475, 666.530 178.469 C 667.850 172.885, 669.376 167.142, 669.921 165.707 C 671.194 162.359, 674.696 140.744, 675.544 131 C 676.098 124.641, 675.858 122.601, 673.968 117.593 C 671.219 110.309, 665.512 104.376, 657.465 100.439 C 652.446 97.983, 649.931 97.457, 641.020 96.995 C 630.854 96.468, 630.115 96.268, 619.061 91.036 C 608.893 86.224, 606.669 85.551, 599.061 84.985 C 591.918 84.454, 589.547 83.807, 584.746 81.077 C 580.392 78.601, 576.332 77.357, 568.058 75.967 C 562.045 74.956, 555.409 73.652, 553.312 73.070 C 547.954 71.582, 545.947 71.735, 542.395 73.901 M 282.500 92.993 C 276.868 93.490, 271.836 94.770, 265.500 97.317 C 260.550 99.306, 252.900 101.646, 248.500 102.516 C 244.100 103.386, 238.312 104.804, 235.637 105.667 C 227.144 108.407, 213.817 115.955, 208.003 121.316 C 204.912 124.167, 199.041 128.300, 194.956 130.500 C 185.206 135.751, 179.844 141.157, 177.010 148.593 C 175.063 153.705, 174.753 156.452, 174.711 169 C 174.676 179.448, 175.153 185.596, 176.416 191 C 177.381 195.125, 178.761 203.225, 179.484 209 C 180.533 217.376, 181.560 221.089, 184.560 227.355 C 187.921 234.374, 188.393 236.342, 188.992 245.855 C 189.361 251.710, 190.377 259.200, 191.250 262.500 C 192.123 265.800, 193.347 271.650, 193.971 275.500 C 195.639 285.785, 200.504 300.827, 203.892 306.169 C 207.256 311.473, 215.476 318.396, 221.719 321.183 C 227.885 323.935, 249.185 325.309, 264.500 323.943 C 288.792 321.775, 292.683 321.244, 296.056 319.634 C 297.950 318.730, 303.594 314.055, 308.597 309.245 C 319.084 299.165, 321 295.193, 321 283.535 C 321 276.012, 314.911 224.979, 313.001 216.500 C 312.382 213.750, 311.507 204.907, 311.058 196.848 C 310.608 188.790, 310.006 181.815, 309.720 181.348 C 307.938 178.436, 306.652 158.162, 306.581 131.825 C 306.504 103.519, 306.405 102.020, 304.441 99.325 C 302.257 96.328, 294.615 91.903, 292.038 92.144 C 291.192 92.223, 286.900 92.605, 282.500 92.993" stroke="none" fill="black" fill-rule="evenodd"/>
</svg>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.