创建自己的icon字体

背景

在很多软件中,想要显示一个图标,除非是开源软件中存在的图标,否则图标就无法适配,当前文章将会描述如何从png生成icon。

实现一个icon

PNG2SVG

首先,通过png转换为svg:

freeconvert

SVG to TTF

再通过svg生成对应的ttf文件,建议对图片进行处理:

svg2ttf

Show Icon in TTF

最终,在css文件中,增加相关内容,即可使用icon-excalidraw-plus-icon-filled类来显示icon。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@font-face {
font-family: 'icomoon';
src: url('fonts/icomoon.eot?1jeat0');
src: url('fonts/icomoon.eot?1jeat0#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?1jeat0') format('truetype'),
url('fonts/icomoon.woff?1jeat0') format('woff'),
url('onts/icomoon.svg?1jeat0#icomoon') format('svg');
font-weight: normal;
font-style: normal;
font-display: block;
}

[class^="icon-"], [class*=" icon-"] {
/* use !important to prevent issues with browser extensions that change fonts */
font-family: 'icomoon' !important;
speak: never;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;

/* Better Font Rendering =========== */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

.icon-excalidraw-plus-icon-filled:before {
content: "\e900";
}