Google Fonts API 和 Actionscript

发布于 2024-11-16 00:25:26 字数 781 浏览 3 评论 0原文

据我在 Google Fonts API 上所知,这些字体应该可以通过 JavaScript/CSS 访问。有没有什么方法可以为 Flash 应用程序动态加载它们,而无需将它们本地下载到服务器?

更新:所以我一直在研究这个问题,以下只是我对如何去做的一些想法。它们都不起作用,但我觉得它们走在正确的轨道上。仅供将来参考...

当您选择要在 Google API 中使用的字体时,系统会向您提供一个指向根据您的偏好生成的 CSS 样式表的链接:

<link href='http://fonts.googleapis.com/css?family=Kranky' rel='stylesheet' type='text/css'>

我最初尝试仅使用 href 我的 内的 URL,但 ActionScript 拒绝了此操作(不确定是否是因为它不是本地的,或者它意识到它没有结束在 .css 中)。

失败后,我将链接复制到浏览器中并手动检索 CSS,将其粘贴到 标记内,就像粘贴任何其他 CSS 一样。同样,ActionScript 不喜欢这样,因为它无法在本地定位 URL。

我怀疑其中一些预防措施的实施是由于 Flash 强制执行的整个“安全沙箱”位。具有更多 ActionScript 能力的人可能可以使用它来解决问题,但我不知道它是否可以解决。

From what I can tell on the Google Fonts API, these fonts are meant to be accessible by JavaScript/CSS. Is there any way to dynamically load them for a Flash application without having to download them locally to the server?

Update: So I've been piddling around with this some more, and the following are just some thoughts I had about how to go about it. None of them work, but I feel like they're on the right track. Just for future reference...

When you choose a font to use in the Google API, you're provided with a link to a CSS stylesheet that's generated based on your preferences:

<link href='http://fonts.googleapis.com/css?family=Kranky' rel='stylesheet' type='text/css'>

I initially tried using just the href URL inside my <fx:Style source=.../>, but ActionScript rejected this (not sure if it was because it wasn't local, or it realized it didn't end in .css).

After that failed, I copied the link into my browser and manually retrieved the CSS, pasting it inside <fx:Style> tags like you would with any other CSS. Again, ActionScript didn't like this because it couldn't locally locate the URL.

I suspect some of these precautions are in place due to the whole 'security sandbox' bit that Flash enforces. Someone who has some more ActionScript prowess may be able to use this to solve the problem, but I don't know if it's solvable.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝颜夕 2024-11-23 00:25:26

您可以在运行时将动态字体加载到 flash/actionscript 中。这里有一个很好的例子: http://developer.yahoo.com /flash/articles/runtime-fonts-as3.html

基本上它归结为使用 Loader 类和 Font.registerFont();

问题是由Google 正在提供 WOFF(网络开放字体)文件,但我不相信 Flash 可以嵌入该字体类型。

但是,Google 字体可以下载并轻松嵌入到您的 Flex/Flash 应用程序中。只需在 Google 网站上找到您想要的字体,然后单击“下载”即可。从那里,您可以提取 TTF 文件并将其直接嵌入到您的 Flash 应用程序中。

您可以在动作脚本中执行此操作,如下所示:

[Embed(source="theFontYouDownloaded.ttf",  fontName = "someFont",  mimeType = "application/x-font")]
private var someFont:Class;

根据我的经验,有时您需要使用该 mimetype 才能使其正常工作。

由于您似乎正在使用 Flex,因此您可以简单地使用 Flex 样式表,如下所示:

@font-face
{
src:            url("fonts/someFont.ttf");
fontFamily:     someFont;
font-weight:    normal; 
}

You can load dynamic fonts INTO flash/actionscript at runtime. There's a good example of it here: http://developer.yahoo.com/flash/articles/runtime-fonts-as3.html

Basically it boils down to using a Loader class and Font.registerFont();

The problem is that the CSS provided by Google is providing a WOFF (web open font) file and I don't believe flash can embed that font type yet.

However, the Google fonts are downloadable and easily embedable into your Flex/Flash applications. Simple go to the font you want on Google's site and click "download". From there, you can extract a TTF file and embed it directly into your Flash app.

You can do that in actionscript like this:

[Embed(source="theFontYouDownloaded.ttf",  fontName = "someFont",  mimeType = "application/x-font")]
private var someFont:Class;

In my experience sometimes you need to play with that mimetype to get it working right.

Since you appear to be using Flex, you can simply use a Flex style sheet like so:

@font-face
{
src:            url("fonts/someFont.ttf");
fontFamily:     someFont;
font-weight:    normal; 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文