简体   繁体   English

在HTML页面中嵌入的SVG对象中使用Adobe TypeKit字体

[英]Use Adobe TypeKit fonts in an SVG object embedded in an HTML page

How can I use fonts from Adobe TypeKit in an SVG object embedded in an HTML page? 如何在嵌入HTML页面的SVG对象中使用Adobe TypeKit中的字体?

I'm able to use web fonts directly (eg via a google stylesheet: http://fonts.googleapis.com/css?family=Spicy+Rice ), but TypeKit uses a different javascript-based loading strategy which doesn't seem to be applying font availability to the SVG object. 我可以直接使用网络字体(例如,通过google样式表: http ://fonts.googleapis.com/css?family=Spicy+Rice),但是TypeKit使用了不同的基于javascript的加载策略,这种加载策略似乎并不将字体可用性应用于SVG对象。

Is this possible, and if so, how can I go about doing this? 这可能吗?如果可以,我该怎么做?

Thanks! 谢谢!

SVG is stylable with CSS stylesheets, so you should be able to apply it that way. SVG可以使用CSS样式表进行样式设置,因此您应该能够以这种方式应用它。

And as long as the font is registered on the page, you can use textElToApplyFontTo.attr({ "font-family": "myFont" }); 并且只要在页面上注册了字体,就可以使用textElToApplyFontTo.attr({ "font-family": "myFont" });

Note that IE<9 will likely have problems, I don't know much about VML font support. 请注意,IE <9可能会出现问题,我对VML字体支持了解不多。 IE9+ has SVG support, so it should work with that, and all other modern [desktop] browsers. IE9 +具有SVG支持,因此它应与SVG以及所有其他现代[桌面]浏览器一起使用。

One important thing to consider is that Typekit and other JS-based loading mechanisms work asynchronously, so fonts will only be available once they're loaded. 需要考虑的重要一件事是Typekit和其他基于JS的加载机制是异步工作的,因此字体仅在加载后才可用。

Some modern browsers won't load the font unless a DOM element is using it, so that may also be causing problems (you can try to load the font by using it on a DOM element, preferably above the SVG file. A dirty trick but it works...). 某些现代浏览器除非使用DOM元素,否则不会加载字体,因此这也可能会引起问题(您可以尝试在DOM元素上使用字体来加载字体,最好是在SVG文件上方。)有用...)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM