在 Flex/AS3 中动态加载字体
虽然有多种方法可以将字体加载为 swf 文件,但我更关注的是加载字体文件本身的方法,假设用户上传了字体文件,我如何在应用程序本身中使用该字体文件?
谢谢, 费萨尔·阿比德
While there are ways to load fonts as swf files, what I am more looking at is a way to load the font file itself, say the user uploads a font file , how can i use that font file in the application itself?
Thanks,
Faisal Abid
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,我很确定这是不可能的,至少以任何正常的方式都是不可能的。
您无法加载 ttf 文件的字节数组并将其传递给 Font.registerFont(),需要调用该方法才能使用该字体。
然而,尽管我不具备做到这一点的所有知识,但我知道这绝对不是不可能的。
正如您所说,字体可以从 swf 加载,并且 swf 可以动态创建为 byteArray 并加载。
我不知道这是否适合您,我'我不确定这到底有多难。
我会阅读此处提供的 swf 文件格式规范:
http://www.adobe.com/devnet/swf/
然后研究空swf的字节码,然后研究嵌入单一字体的swf的字节码,并找到字体的数据在哪里,这就是必须用用户提供的字体替换的内容。
我想知道嵌入 swf 中时是否所有文件内容都未受影响。 在这种情况下,实际上只需将字体数据插入模板 swf 的正确位置即可,这应该不会太难。 但它可能比这更难一点,而且我怀疑它也会被压缩......
如果你用谷歌搜索,可能会有一些关于以编程方式创建 swf 的信息。
抱歉,我无法给你一个更方便的答案 =)
Unfortunately I am quite sure this is not possible, in any normal way at least.
You can't load in a bytearray of a ttf-file and pass it to Font.registerFont(), which needs to be called in order to use the font.
However, even though I do not possess all of the knowledge to do it, I know it is definitely not impossible.
As you said, fonts can be loaded from swf's, and swf's can be created dynamically as a byteArray and loaded in.
I don't know if this would be an option at all for you, and I'm not sure how hard it would really be.
I would read up on the swf file format spec available here:
http://www.adobe.com/devnet/swf/
Then study the bytecode of an empty swf, and then the bytecode of a swf with a single font embedded, and find where the data of the font is, that's what has to be replaced with the font supplied by the user.
I wonder if all of the file-content is untouched when embedded in the swf. In that case it's practically just a matter of inserting the font-data in the right place of the template swf, which shouldn't be too hard. But it probably be a bit harder than that, and I suspect it gets compressed as well...
There might be some info about creating swf's programmatically if you google around..
Sorry I couldn't give you a more convenient answer =)