我了解到,根据谷歌浏览器/设备它是从访问的自动供应TTF,EOT,WOFF,或SVG字体文件。
现在我打算主机,并且从我的服务器本身,这是我首先要下载网络字体(S)的所有文件格式所服务的字体文件。
我如何或在哪里可以下载4种文件格式,我想使用Web字体?
PS:通过使用不同的浏览器-浏览器,IE9和Safari(DEV - iPhone UA),我是能够得到WOFF,EOT和TTF格式。 没有运气与SVG格式虽然。 如果有一个更简单的方法这将是真棒。
编辑:哦,对了,我知道我可以下载各种格式fontsquirrel ,但我说的是从这里正式回购下载。
Answer 1:
您可以在克隆谷歌网络字体目录http://code.google.com/p/googlefontdirectory/
您也可以在获得单一字体文件http://code.google.com/p/googlefontdirectory/source/browse/#font_name
Answer 2:
=======已更新2016年5月31日=======
我做了一个微小的PHP脚本得到谷歌的字体CSS导入URL像下载链接: https://fonts.googleapis.com/css?family=Roboto:400,700|Slabo+27px|Lato:400,300italic,900italic
你可以在这里使用这个工具: http://nikoskip.me/gfonts.php
举例来说,如果你使用上面的导入网址,你会得到这样的:
我厌倦了在Chrome的每个新版本更新这个答案,因为他们总是改变你可以欺骗用户代理字符串的方式,因此请改为使用此脚本。
=======·解老=======
使用从Chrome中,您可以覆盖用户代理DevTools。
如何:
- 获取你需要在谷歌网页字体的字体。
- 您将获得一个网址在你的CSS导入,如: http://fonts.googleapis.com/css?family=Cabin:500,700,500italic,700italic
- 打开网址在浏览器中,你会看到完整的网址,让您可以真正下载的字体。
- 转到开发工具(F12)和按ESC
- 选择“仿真”选项卡,然后单击“网络”子选项卡上
- 最后,关于
Spoof user agent
选择IE9为EOT格式,机器人4 TTF和该UA字符串为SVG: Mozilla/4.0 (iPad; CPU OS 4_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/4.1 Mobile/9A405 Safari/7534.48.3
(感谢匿名)
Answer 3:
如何获取字体下载网址,其中包括SVG和woff2。
要下载的每个字体所需要的用户代理如下。 源 。
module.exports = {
USER_AGENTS: {
eot: 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)',
woff: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0',
woff2: 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML like Gecko) Chrome/38.0.2125.104 Safari/537.36', // complete woff2 file for one variant
svg: 'Mozilla/4.0 (iPad; CPU OS 4_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/4.1 Mobile/9A405 Safari/7534.48.3',
ttf: 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.54.16 (KHTML, like Gecko) Version/5.1.4 Safari/534.54.16'
},
GOOGLE_FONTS_API_KEY: 'AIzaSyDY-C-Lt9uyPP5fSTjMCR4bB944SlI4spw',
CACHE_DIR: __dirname + "/cachedFonts/",
}
添加使用devtool这些useragents。
资源
你现在可以访问https://fonts.googleapis.com/css?family=Open+Sans
和欺骗你的用户代理,通过访问发现的URL中下载的字体@font-face
。
另外谷歌,网络字体的辅助做这一切为您服务。 有一个伟大的博客文章在这里我从哪里获取的图像中开发商。
你为什么要自我主机?
始终使用一个共同的CDN如果可能的话,它的很多更可能是你的字体甚至不需要下载(浏览器缓存)。
如果你担心谷歌发送了错误的字体给用户,很可能是因为他们被欺骗了用户代理,再就是在另外一个选择,仍然可以得到使用谷歌托管的好处。
插入@font-face
自己,只是使用上述步骤找到谷歌字体url和插入该<head>
;
<style>
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: url(google-font-url-here/opensans.eot);
src: local('Open Sans'), local('OpenSans'),
url(google-font-url-here/opensans.eot?#iefix) format('embedded-opentype'),
url(google-font-url-here/opensans.woff2) format('woff2'),
url(google-font-url-here/opensans.woff) format('woff'),
url(google-font-url-here/opensans.ttf) format('truetype'),
url(google-font-url-here/opensans.svg#OpenSans) format('svg');
}
</style>
这都与它的风险,因为这些网址可能会改变!
Answer 4:
我在网上发克隆:)
https://bitbucket.org/Tymek/google-web-fonts/你去那里!
Answer 5:
我写了一个PowerShell脚本来自动下载字体,提供给多个不同的用户代理。 对于基本字体,它得到的所有四种格式(WOFF,TTF,SVG,EOT)。 谷歌似乎并不满足SVG和EOT文件粗体和斜体的权重。
$agents = "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0",`
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1",`
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)",`
"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7",`
"Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.2; SV1; .NET CLR 3.3.69573; WOW64; en-US)"
foreach($arg in $args) {
$arg;
foreach($agent in $agents) {
$agent;
$webclient = New-Object System.Net.WebClient
[void]$webclient.Headers.Add("user-agent", $agent)
$url = "http://fonts.googleapis.com/css?family=$arg"
$css = $webclient.DownloadString($url)
$css
$fonts = $css |
Select-String -AllMatches "http://[A-Za-z0-9/._?&=%-]+" |
Select-Object -ExpandProperty Matches |
Select-Object -ExpandProperty Value
foreach($font in $fonts) {
$font
$fontfile = [System.Io.Path]::GetFileName((new-object System.Uri $font).LocalPath)
[void]$webclient.DownloadFile($font, "$pwd\$fontfile")
}
}
}
一旦它在一个名为.ps1文件,它可以与字体被要求下载作为参数:
PS> .\DownloadFonts.ps1 "Open+Sans:400,700,400italic,700italic"
该脚本将输出的CSS从谷歌的服务器拉来帮助你找出哪些文件是(例如,在我的情况下,SVG字体被拉到一个名为“字体”文件)。
这是基于发表RichardN和ldeck在博客文章的bash脚本本地缓存谷歌的Web字体 。
作为参考,在这里是ldeck的bash脚本:
#!/bin/sh
for family in $*; do
for url in $( {
for agent in \
'Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0' \
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1' \
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)' ;
do
curl -A "$agent" -s "http://fonts.googleapis.com/css?family=$family" | \
grep -oE 'http://[A-Za-z0-9/._-]+'; \
done } | sort -u ) ;
do
extn=${url##*.} ;
file=$(echo "$family"| tr +[:upper:] _[:lower:]);
echo $url $file.$extn;
curl -s "$url" -o "$file.$extn";
done
done
更多参考: 使用HTML5应用程序缓存 。
Answer 6:
我不是联盟关系的公司或网站,无论如何,但我能得到所有我需要在格式onlinefontconverter.com 。
我需要EOT,SVG,WOFF和TTF格式。 我已经有TTF。 我上传和网站上创建其余的 - 都在几分钟。
Answer 7:
我已经写了一个python脚本作为我对开源项目工作的一部分MDIDX 。 它会得到一个给定的字体家庭从谷歌字体CDN的所有可能的字体格式。 这是天真的 - 暴力破解共同平台的用户代理
它可以简化像这样:
import re
import os
import requests
def main():
font_family = "Material Icons"
output_directory = "fonts"
download_fonts(font_family, output_directory)
def download_fonts(font_family, output_directory, output_file_name=None):
if not os.path.isdir(output_directory):
os.makedirs(output_directory)
if not output_file_name:
output_file_name = font_family.lower().replace(" ","-")
user_agents = USER_AGENTS.splitlines()
user_agents = map(lambda x: x, user_agents)
font_urls = set()
for user_agent in user_agents:
url = 'https://fonts.googleapis.com/icon?family={}'.format("+".join(font_family.strip().split()))
r = requests.get(url, headers={"user-agent": user_agent})
r.raise_for_status()
urls = re.findall('url\((.*?)\)', r.text)
urls = map(str, urls)
urls = filter(str, urls)
font_urls.update(urls)
fonts_map = {font_url.split('.')[-1].lower(): font_url for font_url in font_urls}
for file_extension, url in fonts_map.items():
file_path = os.path.join(output_directory, '{output_file_name}.{file_extension}'.format(output_file_name=output_file_name, file_extension=file_extension))
_download_file(url, file_path)
USER_AGENTS = """
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090913 Firefox/3.5.3
Mozilla/5.0 (Windows; U; Windows NT 6.1; en; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.1) Gecko/20090718 Firefox/3.5.1
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.1 (KHTML, like Gecko) Chrome/4.0.219.6 Safari/532.1
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; InfoPath.2)
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30729)
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Win64; x64; Trident/4.0)
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; .NET CLR 2.0.50727; InfoPath.2)Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)
Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; da-dk) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1
Opera/9.80 (Windows NT 6.1; U; es-ES) Presto/2.9.181 Version/12.00
Mozilla/5.0 (Linux; U; Android 2.3.4; fr-fr; HTC Desire Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; Android 7.0; SAMSUNG SM-N920C Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/6.2 Chrome/56.0.2924.87 Mobile Safari/537.36
Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 BIDUBrowser/2.x Safari/537.31
Mozilla/5.0 (Linux; U; Android 4.4.2; zh-cn; GT-I9500 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.0 QQ-URL-Manager Mobile Safari/537.36
Mozilla/5.0 (Android 8.0.0; Tablet; rv:57.0) Gecko/57.0 Firefox/57.0
Mozilla/5.0 (Android 8.1.0; Mobile; rv:61.0) Gecko/61.0 Firefox/61.0
"""
def _download_file(url, file_path):
r = requests.get(url)
r.raise_for_status()
with open(file_path, 'wb') as f:
f.write(r.content)
if __name__ == '__main__':
main()
文章来源: How to download multiple formats of a web font from the (official) Google Web Fonts repo?