简体   繁体   English

使用fontswf创建的在运行时加载的字体的定义名称是什么?

[英]What's the definition name for fonts loaded at runtime created with fontswf?

I ran into the 'fontswf' utility to embed TTF fonts into SWF and I am struggling to load them at runtime from my app. 我遇到了'fontswf'实用程序,将TTF字体嵌入到SWF中,而我正在努力在运行时从应用程序中加载它们。 All the examples I find online refer to loading the font via [Embed] but I am actually loading them with a flash.display.Loader and from what I gather, once the Loader.contentLoaderInfo fires an Event.INIT I need to register the font, like so: 我在网上找到的所有示例均涉及通过[Embed]加载字体,但实际上是使用flash.display.Loader以及从我收集的内容加载字体,一旦Loader.contentLoaderInfo触发Event.INIT,我就需要注册字体,就像这样:

public function handleLoaderComplete( event:Event ):void {
  var FontClass:Class = event.target.applicationDomain.getDefinition( fontName );
  Font.registerFont( FontClass );
}

The problem is I don't know what to pass in as fontName. 问题是我不知道作为fontName传入什么。 I am generating my SWF through: 我正在通过以下方式生成SWF:

$ fontswf -a belshaw -o belshaw.swf belshaw.ttf

But when I try to call getDefinition( 'belshaw' ), I get an error saying 'Variable belshaw is not defined'. 但是,当我尝试调用getDefinition('belshaw')时,出现一个错误,提示'未定义变量belshaw'。 Any suggestions on how to accomplish this? 关于如何做到这一点的任何建议?

The alternative is to generate my on SWF files through templating an .as file and compiling them, but I would rather use a built in tool like fontswf if it's already there. 另一种方法是通过对.as文件进行模板化和编译来在SWF文件上生成我的文件,但是我宁愿使用诸如fontswf之类的内置工具(如果已存在)。

Thanks 谢谢

Ruy 鲁伊

I am on a project that had to allow users to dynamically upload their own fonts. 我在一个必须允许用户动态上传自己的字体的项目中。 We tried getting fontswf to work and ran into issue after issue and the terrible documentation did nothing to help. 我们试图让fontswf正常工作,并且每次发行都遇到问题,糟糕的文档无济于事。 Eventually we just created a template and use a bash script to embed the .ttf file into a new .swf, the service returns the url to that .swf, then the main app loads that .swf and registers the font. 最终,我们刚刚创建了一个模板,并使用bash脚本将.ttf文件嵌入到新的.swf中,该服务将URL返回到该.swf,然后主应用程序加载该.swf并注册该字体。

I know that's not exactly an answer to your question, but I do know that it works. 我知道这并不完全是您的问题的答案,但我知道它是可行的。 ;) ;)

You could use a decompiler psoftware to decompile your font SWF to see what fonts are embedded. 您可以使用反编译器软件对字体SWF进行反编译,以查看嵌入了哪些字体。

Or ... 要么 ...

You can loop through the fonts in the embedded file runtime: 您可以在嵌入式文件运行时中浏览字体:

import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;

var fontLoader:Loader = new Loader();
var fontLoaderInfo:LoaderInfo = fontLoader.contentLoaderInfo;

fontLoaderInfo.addEventListener(Event.COMPLETE, onFontLoaded);

fontLoader.load(new URLRequest("Verdana.swf"));

function onFontLoaded (e:Event):void {
   var info:LoaderInfo = e.currentTarget as LoaderInfo;
   var loader:Loader = info.content as Loader;
   var embeddedFonts:Array = Font.enumerateFonts(false);
   for(var i:Number = 0; i < embeddedFonts.length; i++){
      var item:Font = embeddedFonts[i];
      trace("[" + i + "] name:" + item.fontName + ", style: " + item.fontStyle + ", type: " + item.fontType);
   }
}

This is not tested, I found it here 这未经测试,我在这里找到

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

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