ChatGPT解决这个技术问题 Extra ChatGPT

从 Font Awesome 中提取 SVG

我想从 Font Awesome 字形中获取 SVG 路径数据,以便可以在我的 HTML 中直接将它们用作 SVG。我认为这就像从 fontawesome-webfont.svg 复制粘贴路径数据一样简单,但是当我在我的 HTML 中使用它时,所有符号都颠倒了。有谁知道为什么?

(见Fiddle

字体真棒SVG:

<glyph unicode="&#xf007;" 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>

A
Angie

2022 年更新感谢 Chris Aelbrecht 评论:官方仓库有最新版本的 SVG 供下载

https://github.com/FortAwesome/Font-Awesome/tree/master/svgs

原答案:

只需从 this github repo
获取现成的 svg 图标它们已经根据需要翻转和居中

https://i.stack.imgur.com/c7hW4.png


我发现其中很多都有侧面裁剪的图标,例如汽车
C
Community

所有根据 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> 似乎可以解决问题,其中 1792units-per-em1536font-face 元素上的 ascent
回复 1792 is the units-per-em:错字?我认为匹配高度/宽度将是 179.2
j
jedierikb

IcoMoon app 使这变得非常简单。


IcoMoon 非常易于使用,但我发现它导出的路径比 this GitHub repo 中的 SVG 更长。尝试比较 fa-gift 图标。 path 是通过 IcoMoon 获得的 837 个字符,而 514 in the repo
j
jedierikb

使用 fontforge 脚本。我找到了一个脚本 online here

fontforge -lang=ff -c 'Open($1); SelectWorthOutputting(); foreach Export("svg"); endloop;' font.ttf 

请参阅:http://fontforge.sourceforge.net/scripting.html


m
muah

你可以从他们在 Github 的 repo 下载你需要的任何 Font-Awesome svg

https://github.com/FortAwesome/Font-Awesome/tree/master/svgs


t
tomByrer

还有一个 node.js 工具可以为您自动执行此操作,&创建一个之前 & verify.html 之后。 https://github.com/eugene1g/font-blast

我已经在其他字体上使用过它,到目前为止只有 1 次错误的图标转换,但字体 SVG 的其余部分很好。


O
Orlandster

您只需在此处下载最新版本的 fahttps://fontawesome.com/

然后转到 advanced-options/raw-svg 文件夹。在那里您会找到三个文件夹 brandsregularsolid,其中包含所有可用的最新图标。


J
John Dangerous

您可以在此处从 flaticon.com 下载它们:

http://www.flaticon.com/packs/font-awesome


可能会有所帮助,但是当您想将路径从 512x512 调整为 20x20 时,需要大量按比例缩小按钮混搭