How to use fonts in external SWF files - apache-flex

What I would like to do is a flex app, that uses fonts that are available in external swf.
What I have succeded so far is:
to create a AS class hat holds the embedded font:
package
{
import flash.display.Sprite;
public class _Arial extends Sprite
{
[Embed(source='C:/WINDOWS/Fonts/ARIAL.TTF', fontName='_Arial', unicodeRange='U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E')]
public static var _MyArial:Class;
}
}
compiled this into a swf with following command: mxmlc.exe -static-link-runtime-shared-libraries=true _Arial.as
When I try to load the font from my flex app, this fails with following error message:
ArgumentError: Error #1508: The value specified for argument font is invalid.
at flash.text::Font$/registerFont()
at valueObjects::FontLoader/fontLoaded()[C:\Documents and Settings\nutrina\Adobe Flash Builder 4\flex_pdf\src\valueObjects\FontLoader.as:33]
This is the code where I try to load the SWF file:
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.*;
import mx.collections.ArrayCollection;
import mx.core.FontAsset;
public class FontLoader extends Sprite {
public function FontLoader(url:String) {
super();
loadFont(url);
}
private function loadFont(url:String):void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fontLoaded);
loader.load(new URLRequest(url));
}
private function fontLoaded(event:Event):void {
var fontList:ArrayCollection = new ArrayCollection(Font.enumerateFonts(true));
var FontLibrary:Class = event.target.applicationDomain.getDefinition("_Arial") as Class;
trace("FontList: " + fontList)
trace("FontLibrary: " + FontLibrary)
trace("FontLibrary._Arial: " + FontLibrary._MyArial)
Font.registerFont(FontLibrary._MyArial);
fontList = new ArrayCollection(Font.enumerateFonts(true));
trace("Font list: " + fontList)
}
}
}
The font file is definitely not corrupt because if I put the _Arial class from the code above into the Flex application, the embedding works. So my guess is that probably I missed some compilation options?
I am using Adobe Flash Builder 4.
I would appreciate any help on this matter.
Thanks,
Gerald

Could be a problem with class name conflicts. I wrestled with an external font loading issue for hours. Turns out my font class was called "Main", and so was the application that was trying to load it. The font never got registered correctly.

Related

JxBrowser does not launch from another class

I have a problem that I cannot launch my JxBrowser from another class but it works fine on its own class. I will give the code for the internet browser class here
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
import javax.swing.*;
import java.awt.*;
public class InternetBrowser
{
//properties
Browser browser;
BrowserView browserView;
JFrame frame;
//constructor
public InternetBrowser()
{
browser = new Browser();
browserView = new BrowserView(browser);
frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(browserView, BorderLayout.CENTER);
frame.setSize(500, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.loadURL("https://www.youtube.com/embed/bO7yYDIOuXo");
}
public static void main( String [] args )
{
InternetBrowser browser = new InternetBrowser();
}
}
The error that I get is
Class StartIPCTask is implemented in both /private/var/folders/cs/1z68c1xs2q3crwrwm__fx_t80000gn/T/jxmaps-chromium-49.0.2623.110.unknown/data/Temp/libjxmaps-common64-397f2f15-9ac5-4806-91f6-88c8aaa29714.dylib (0x1288d5630) and /private/var/folders/cs/1z68c1xs2q3crwrwm__fx_t80000gn/T/browsercore-64.0.3282.24.6.21/data/Temp/libbrowsercore-common64-01e73e7f-2b85-4bd3-ac76-05d908fa4928.dylib (0x16b2576c8). One of the two will be used. Which one is undefined.
I need to define which one of the directories that the class should use but I do not know how. I am using the latest version of Netbeans. Also at the top of the class that im trying to construct a browser, the imports are highlighted as "unused import". Thank you for your help!
I realized that this is a bug seen in OSX.. The program works without any problem in windows computers.
In general, this warning doesn't affect the program, so you can just ignore it. If you don't want to receive it at all, then please try using the jxbrowser.jni.singleton.fix=false VM parameter.

Getting a popup for downloading the font file(ttf) in a spring-boot application

I'm getting a popup for downloading the fonts files(ttf) in a spring-boot application, the font file is related to bootstrap3.
I tried to add MimeTypes like this but still getting the popup for first time I open the application.
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.MimeMappings;
import org.springframework.stereotype.Component;
#Component
public class ServletCustomizer implements EmbeddedServletContainerCustomizer {
#Override
public void customize(ConfigurableEmbeddedServletContainer container) {
MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
mappings.add("woff","application/x-font-woff");
mappings.add("eot","application/vnd.ms-fontobject");
mappings.add("ttf","application/x-font-ttf");
container.setMimeMappings(mappings);
}
}
I'm using Spring-boot 1.3.3.RELEASE+thymeleaf.
Anyone know how to resolve this issue?
I resolved the issue by adding this line to my security config
http.authorizeRequests().antMatchers("/fonts/**").permitAll();

How to import a custom component with resource into SceneBuilder?

I have created a bunch of custom nodes for my project, by subclassing existing ones.
For example:
package sample;
import javafx.scene.control.Button;
public class MyCustomButton extends Button {
public MyCustomButton() {
System.out.println("This is my custom button...");
}
}
This is working fine, I create a jar file and I can import it into Scenebuilder.
However if my custom node uses a resource, and I try to import the jar in Scenebuilder, the custom component won't show up in the Import Dialog.
package sample;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
public class MyCustomButton extends Button {
public MyCustomButton() {
Image image = new Image("sample/picture.gif");
System.out.println("This is my custom button...");
}
}
How can I convince Scenebuilder to import my custom components if they contain resources? The jar file has all the needed resources, and a component working fine in code, but I would like to be able to use it in Scenebuilder as well.
I did for you:)
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class MyCustomButton extends Button {
public MyCustomButton() {
final ImageView imageView = new ImageView();
Image image = new Image(getClass().getClassLoader().getResource("sample/picture.png").toExternalForm());
imageView.setImage(image);
this.setGraphic(imageView);
System.out.println("This is my custom button...");
}
}
Check the analysis report on SB. Click on the settings icon on the right hand side of Library, then select "Custom Library Folder" --> "Show Jar Analysis Report". You can see some useful hints. Maybe this helps you.

ModuleMessageInterceptor vs MessageInterceptor

I am developing an application in Flex using the cairngorm module library and Parsley.
Parsley documentation chapter 5 says: "Interceptors may come in handy when you want to decide whether or not the message should be passed to handlers".
When using the ModuleMessageInterceptor the above is not true. Which means that my MessageHandler receive the message before the MessageInterceptor.
Does anyone knows a work around?
Regards,
Fadi
The solution to this problem was extending the ModuleMessageInterceptor class as follows:
package fr.core.patch.cairngorm
{
import com.adobe.cairngorm.module.ModuleIdMetadata;
import com.adobe.cairngorm.module.ModuleMessageDispatcher;
import com.adobe.cairngorm.module.ModuleMessageInterceptor;
import com.adobe.cairngorm.module.ParsleyModuleMessage;
import flash.system.ApplicationDomain;
import org.spicefactory.lib.reflect.ClassInfo;
import org.spicefactory.lib.reflect.Property;
import org.spicefactory.parsley.core.registry.ObjectDefinitionRegistry;
import org.spicefactory.parsley.core.registry.RootObjectDefinition;
import org.spicefactory.parsley.tag.messaging.MessageHandlerDecorator;
import org.spicefactory.parsley.tag.messaging.MessageInterceptorDecorator;
public class ATPModuleMessageInterceptor extends ModuleMessageInterceptor
{
public function ATPModuleMessageInterceptor()
{
super();
}
public var order:int;
private var target:Property;
override public function process(registry:ObjectDefinitionRegistry):void
{
target=getModuleIdTargetProperty(registry.domain);
var interceptor:MessageInterceptorDecorator=new MessageInterceptorDecorator();
interceptor.type=type;
interceptor.selector=selector;
interceptor.method="interceptModuleMessage";
interceptor.order = order;
var messageHandler:MessageHandlerDecorator=new MessageHandlerDecorator();
messageHandler.type=ParsleyModuleMessage;
messageHandler.method="parsleyModuleMessageHandler";
var definition:RootObjectDefinition=registry.builders.forRootDefinition(ModuleMessageDispatcher).decorators([interceptor, messageHandler]).buildAndRegister();
definition.constructorArgs.addValue(target);
if (moduleRef)
{
definition.constructorArgs.addIdReference(moduleRef);
}
}
private function getModuleIdTargetProperty(domain:ApplicationDomain):Property
{
var props:Array=ClassInfo.forClass(type, domain).getProperties();
for each (var prop:Property in props)
{
if (prop.hasMetadata(ModuleIdMetadata))
{
return prop;
}
}
return null;
}
}
}
By doing the above we have added the order property to the ModuleMessageInterceptor which solve the problem I had.
Regards,
Fadi Mansour
In Parsley 2.4, MessageInterceptors have been depracated:
And ModuleMessageInterceptor is not a Parsley thing, it's a Cairngorm thing. Personally, I'd stay away of Cairngorm altogether because of my experience with it. After looking online, I saw that other people had similar issues. Your best bet is to post on the same forum and hopes somebody helps.

as3: xml loads but doesn't seem to be coerced to native flash xml

I have a class that loads some xml data via php scripting.
I am trying to grab the formatted xml (which i have verified is formatted correctly), and stuff it into a number of variables.
I try:
package utils.php
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
public class DirectoryReader extends EventDispatcher
{
public var fileList:XMLList;
public var totalBytes:int;
private var loader:URLLoader;
public function DirectoryReader(url:String)
{
var urlreq:URLRequest = new URLRequest(url);
trace(url);
urlreq.contentType = "text/xml";
urlreq.method = URLRequestMethod.POST;
loader = new URLLoader(urlreq);
loader.addEventListener(Event.COMPLETE, completeHandler);
loader.load(urlreq);
}
protected function completeHandler(e:Event):void
{
trace("seems to have worked...");
var loaded:XML = loader.data;
fileList = loaded.child("filelist").attribute("file");
trace("file list: " + fileList);
totalBytes = loaded.child("totalsize");
trace("total size: " + totalBytes);
dispatchEvent(new Event("directoryLoaded"));
}
}
}
Am I doing anything obvious that is wrong?
Basically I get an error that the loaded variable cannot be propagated correctly as if there is a type mismatch.
FWIW, my class extends EventDispatcher so that I can notify other classes that it has loaded. I am sending in a URL, including php variables ala ? and &.
Thanks,
jml
Actually I think that URLRequest.contentType refers only to the request headers, not the response. And AFAIK, even if you are getting a text/xml response header, Flash will indeed treat it as a String, so you need to create a new XML object using the response string as its "expression" parameter...
I think this would solve your problem:
var loaded:XML = new XML(loader.data);

Resources