我想从 Font Awesome 字形中获取 SVG 路径数据,以便可以在我的 HTML 中直接将它们用作 SVG。我认为这就像从 fontawesome-webfont.svg 复制粘贴路径数据一样简单,但是当我在我的 HTML 中使用它时,所有符号都颠倒了。有谁知道为什么?
(见Fiddle)
字体真棒SVG:
<glyph unicode="" horiz-adv-x="1408" d="M1408 131q0 -120 -73 -189.5t-194 -69.5h-874q-121 0 -194 69.5t-73 189.5q0 53 3.5 103.5t14 109t26.5 108.5t43 97.5t62 81t85.5 53.5t111.5 20q9 0 42 -21.5t74.5 -48t108 -48t133.5 -21.5t133.5 21.5t108 48t74.5 48t42 21.5q61 0 111.5 -20t85.5 -53.5t62 -81 t43 -97.5t26.5 -108.5t14 -109t3.5 -103.5zM1088 1024q0 -159 -112.5 -271.5t-271.5 -112.5t-271.5 112.5t-112.5 271.5t112.5 271.5t271.5 112.5t271.5 -112.5t112.5 -271.5z" />
... 移植到 HTML SVG(并按比例缩小):
<svg width="1000" height="1000" ><path transform="scale(0.1,0.1)" d="M1408 131q0 -120 -73 -189.5t-194 -69.5h-874q-121 0 -194 69.5t-73 189.5q0 53 3.5 103.5t14 109t26.5 108.5t43 97.5t62 81t85.5 53.5t111.5 20q9 0 42 -21.5t74.5 -48t108 -48t133.5 -21.5t133.5 21.5t108 48t74.5 48t42 21.5q61 0 111.5 -20t85.5 -53.5t62 -81 t43 -97.5t26.5 -108.5t14 -109t3.5 -103.5zM1088 1024q0 -159 -112.5 -271.5t-271.5 -112.5t-271.5 112.5t-112.5 271.5t112.5 271.5t271.5 112.5t271.5 -112.5t112.5 -271.5z"/></svg>
2022 年更新感谢 Chris Aelbrecht 评论:官方仓库有最新版本的 SVG 供下载
https://github.com/FortAwesome/Font-Awesome/tree/master/svgs
原答案:
只需从 this github repo
获取现成的 svg 图标它们已经根据需要翻转和居中
https://i.stack.imgur.com/c7hW4.png
所有根据 SVG specification...
与 SVG 中的标准图形不同,其中初始坐标系的 y 轴指向下方,SVG 字体的设计网格以及字形的初始坐标系具有指向上方的 y 轴,以与公认的行业惯例保持一致许多流行的字体格式。
根据 this comment,将包装器更改为 <svg height="179.2" width="179.2"><path transform="scale(0.1,-0.1) translate(0,-1536)" d="..." /></svg>
似乎可以解决问题,其中 1792 是每 em 单位,1536 是字体的上升 -人脸元素
<svg height="179.2" width="179.2"><path transform="scale(0.1,-0.1) translate(0,-1536)" d="..." /></svg>
似乎可以解决问题,其中 1792
是 units-per-em
而 1536
是 font-face
元素上的 ascent
。
1792 is the units-per-em
:错字?我认为匹配高度/宽度将是 179.2
。
IcoMoon app 使这变得非常简单。
path
是通过 IcoMoon 获得的 837 个字符,而 514 in the repo。
使用 fontforge 脚本。我找到了一个脚本 online here:
fontforge -lang=ff -c 'Open($1); SelectWorthOutputting(); foreach Export("svg"); endloop;' font.ttf
请参阅:http://fontforge.sourceforge.net/scripting.html
你可以从他们在 Github 的 repo 下载你需要的任何 Font-Awesome svg
https://github.com/FortAwesome/Font-Awesome/tree/master/svgs
还有一个 node.js 工具可以为您自动执行此操作,&创建一个之前 & verify.html
之后。 https://github.com/eugene1g/font-blast
我已经在其他字体上使用过它,到目前为止只有 1 次错误的图标转换,但字体 SVG 的其余部分很好。
您只需在此处下载最新版本的 fa
:https://fontawesome.com/
然后转到 advanced-options/raw-svg
文件夹。在那里您会找到三个文件夹 brands
、regular
和 solid
,其中包含所有可用的最新图标。
您可以在此处从 flaticon.com 下载它们:
http://www.flaticon.com/packs/font-awesome