0.0.1 • Published 5 years ago

svg2fonts1 v0.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

svg2font

Converts SVG to TTF/EOT/WOFF/WOFF2/SVG format.

Note: svg -> svgfont -> ttf ttf -> EOT ttf -> WOFF ttf -> WOFF2 ttf -> svg,DominantBaselineProperty, FontElementAscentAttribute

Unicode字符平面映射

平面始末字符值中文名称英文名称
0号平面U+0000 - U+FFFF基本多文种平面Basic Multilingual Plane,简称BMP
1号平面U+10000 - U+1FFFF多文种补充平面Supplementary Multilingual Plane,简称SMP
2号平面U+20000 - U+2FFFF表意文字补充平面Supplementary Ideographic Plane,简称SIP
3号平面U+30000 - U+3FFFF表意文字第三平面(未正式使用[1]Tertiary Ideographic Plane,简称TIP
4号平面 至 13号平面U+40000 - U+DFFFF(尚未使用)
14号平面U+E0000 - U+EFFFF特别用途补充平面Supplementary Special-purpose Plane,简称SSP
15号平面U+F0000 - U+FFFFF保留作为私人使用区(A区)[2]Private Use Area-A,简称PUA-A
16号平面U+100000 - U+10FFFF保留作为私人使用区(B区)[2]Private Use Area-B,简称PUA-B

Unicode 字符三个私人使用区(Private Use Areas):一个在基本多语言平面(U+E000-U+F8FF)中,另外两个几乎包含了整个第15和第16平面(分别为U+F0000-U+FFFFD,U+100000-U+10FFFD)

Install

npm install svg2font

Usage

const { svg2Font, Font, writeToFile } = require('./dist/index.js')
const path = require('path')
const fs = require('fs')

svg2Font({
  src: './test/svgicon/*.svg', // svg path  support patterns
  dist: './test/',
  fontName: 'svg2font',  // font name
  startCodePoint: 57344, // unicode start code point
  ascent: 924,
  descent: -100,
  css: true,
}).then(() => {
  console.log('svg2Font done !')
})

const icon = fs.readFileSync(path.join( './test/svgicon', `icon_7days.svg`), 'utf8')

const font = new Font({
  fontName: 'svgfont',
  glyphSvgs: icon,  //  support string array object
  ascent: 896,
  descent: -128,
  startCodePoint: 57344,
})

font.convertFonts({
  dist: './test/',
  fontTypes: ['eot', 'ttf', 'svg'],
  css: true,
})

API

svg2Font(options)

  • options
    • src- SVG file
    • dist - out file
    • fontName - font family name
    • startCodePoint - Unicode Private Use Areas start Code Point
    • ascent
    • descent

new Font(options)

  • options

    • fontName - font family name
    • glyphSvgs - svg datas support string array object
    • startCodePoint - Unicode Private Use Areas start Code Point
    • ascent
    • descent
  • method

    • getGlyph
    • getTTF
    • getWOFF
    • getWOFF2
    • convertFonts

Features

  • 支持解析 SVG 基本路径转换
  • 支持导出四种浏览器主流字体(ttf,eot,woff,woff2, svg)
  • 支持设置各种字体相关内容

License

MIT