I am loading multiple swf files containing the different fonts at run-time. I am having problem when I am applying it to textflow in Rich Editable Text. Any Idea how to apply those custom fonts to the textflow ?
Here is the part of my code.
For registering the fonts
var FontClass:*;
var dom:ApplicationDomain = response.target.applicationDomain;
FontClass = dom.getDefinition(fileName) as Class;
Font.registerFont(FontClass);
Works!
For applying the font to textflow.
var cf:TextLayoutFormat = new TextLayoutFormat();
cf.fontFamily = mFontName; //Font Name
cf.fontLookup = FontLookup.EMBEDDED_CFF;
var editManager: IEditManager = IEditManager(textflow.interactionManager);
editManager.applyLeafFormat(cf);
No crash! Works!
But the applied font is not correct. Any suggestion please.
IEditManager is an interface, it doesn't do anything. You should be using EditManager.
Interfaces are not working classes, they used to define a common set of functions, any class that implements an interface, has to create working versions of all functions defined in the interface, or the compiler will fail. Further reading here
Related
I'm currently working with the mxGraph library in javascript and I'm trying to create my own shapes in draw.io, to export them, then to reuse them as much as I want in my own program using the mxGraph library.
So far, I have tried to create a custom library, which contains all my shapes. I have exported it in XML which gives me a half-encoded XML file. Then, I'd like to import that mxLibrary in my own app so I can reuse these shapes for creating my own diagrams. I have no idea how to deal with that XML file.
I have also tried taking the XML from Extras -> Edit Diagram and reimport it with the codec, then with mxGraph#addCells but the shapes aren't grouped anymore, and I can't seem to find how to clone them.
My goal would literally to have my list of shapes/cells somewhere, which I can reuse whenever I want.
If this is not possible, how may I do that instead? I have also looked up how to create my own shapes (with redrawPath and the style thing), but it looks really long and boring.
Here's an example of what the XML looks like. The shape is a simple double square.
<mxlibrary>[{"xml":"xVNBbsIwEHyN78EugjOhcOqpLzDJgi05XstZSPJ7trFbiAqCqpV6sLQ7O2N7xrJQZdNvow7mDWtwQr0KVUZESlXTl+CckIWthVoLKQteQm7uTGfjtAg6gqdnBDIJTtodISEJaGlwGThEPIZMg0jQT46q0HuoSO8+6cX3K4zUfP4WsAGKA1M6W5NJjGVWGbAHQ1NMt/keX8qLHy6ypdv21GN7nbEE70FXH33HDyHUylDDO65nXOo2sD1u9rYH3nV1N4lrx/LfHL/8veO9da5Eh5Exjx5+GUIWzJNgmHRXAS1uBLT4eUDcXn7TOJt8tjM=","w":80,"h":80,"aspect":"fixed","title":"custom_shape_1"}]</mxlibrary>
Thank you in advance!
There are 2 ways I know, to do it, depending on your needs.
Embed draw.IO as an iframe in your app, and create a plugin that adds your own palette of icon on the side bar. you can watch the p1 plugin code, and replicate it plugin list in draw.io, look for the p1 plugin
. code example of how to integrate draw.io in your app
hint: if pulgins are not loaded, check the plugin folder link.
If you add the vertices on you own app, create your own style, and reuse it when creating.
updateStyles()
{
var style = new Object();
style[(<any>window).mxConstants.STYLE_SHAPE] =
(<any>window).mxConstants.SHAPE_IMAGE;
style[(<any>window).mxConstants.STYLE_PERIMETER] =
(<any>window).mxPerimeter.RectanglePerimeter;
style[(<any>window).mxConstants.STYLE_IMAGE] =
'../assets/transformer.png';
style[(<any>window).mxConstants.STYLE_FONTCOLOR] = '#000000';
style[(<any>window).mxConstants.STYLE_WHITE_SPACE] = 'wrap';
style[(<any>window).mxConstants.STYLE_VERTICAL_ALIGN] = 'bottom';
this.graph.getStylesheet().putCellStyle('transformer', style);
}
reuse this style whenever creating a vertex using insertVertex function.
try {
const parent = this.graph.getDefaultParent();
this.graph.getModel().beginUpdate();
const vertex = this.graph.insertVertex(parent, uuid.v4(), node, 40, 40, 80, 40, 'transformer');
} finally {
this.graph.getModel().endUpdate();
}
I am building an app using Starling and have imported the scaffold project however whenever I call getTextureAtlas() it doesn't show the image
this.mLogo = new Image(Assets.getAtlasTexture("powered_by_starling"));
this.mLogo.x = 0;
this.mLogo.y = 0;
this.addChild(this.mLogo);
There are no errors so I am guessing it can find the texture. If I change the name to something that doesn't exist it throws an error 'texture cannot be null'. I am also using
Assets.contentScaleFactor = Starling.current.contentScaleFactor;
and everything is pretty much a standard import of the scaffold as is however I am using Feathers UI screen navigator but I haven't had a blank image issue on other projects.
Edit: I can't seem to get the sprite to work within a class that extends feathers.controls.Screen
Is getAtlasTexture a function that you wrote? Are you using starlings asset manager? If that's the case, you will need a instance of that class, not static method call.
Anyway, try using the Texture class and the static method it offers. You don't need atlas(sprite sheet) for a Image - you will need it however for MovieClip.
Texture.fromBitmap
Texture.fromBitmapData
.... and others, check documentation
If your graphics are embedded, then use this:
var _img:Image = new Image(Texture.fromBitmap(new Assets.EmbeddedGraphic()));
Are you using atf? because the same happened to me until I used png and then it worked
I am using Flash Develop for compilation ( Not Flash IDE )
Here is a sample code :
[Embed(source = 'assets.swf', symbol = 'app.view.CustomButton')
var customButton_Class:Class ;
var customButton_Instance ;
customButton_Instance = new customButton_Class();
The problem is that this "customButton_Instance" doesnot know anything about app.view.CustomButton ?? ( Actually this means there is no sense in setting the class as app.view.CustomButton in the assets.fla library )
The workaround i am following is :
var customButton:CustomButton = new CustomButton();
customButton.setView( customButton_Instance )
But i wanted somehow, the customButton_Instance should automatically associate itself with the customButton class. Any ideas pls ?
When using Embed you lose the symbol's associated class. That's how it works.
Instead, if you're using Flash Pro, choose to Publish a SWC that you can then add to your FlashDevelop project (in FlashDevelop: right-click > Add to Library), and then all the symbols will be visible in code completion like any class and you can just write new app.view.CustomButton() or create a custom class extending it.
I am using as3 and trying to use embed fonts with Arabic text but it doesn't work
So is there a way that I can access from .tff file the shape of the character or make it works using embed fonts
As using system fonts works but at same time its bad as on some machines it is reverted so I want to use embed font
Hope anyone can help
I found code by some one to change the input arabic text to the correct shape based on the position in text and I modified it to work perfectly with my code :)
here the AS3 code file: http://www.akhalifa.com/testing/ArabicAS3File/ArabicStringUtils.as
and here an example on how to use it: http://www.akhalifa.com/testing/ArabicAS3File/Main.as
You can use any arabic/persian input language like Maryam4
then write your sentence in this program after that copy it and paste in your code
also as #Goran Mottram said embed your font (for this situation if you use Maryam you must select F_fonts)
but noticed that in your code if you paste your arabic language it shows you wired character like ÂMoø , but dont worry if you publish you see a correct arabic word with rtl support
If you have the font installed on your system, make sure to import the font into your library and tick the box "Export for ActionScript" and give it an appropriate name, say MyArabicFont, then bind it to textfield using the following code:
// create the font
var myFont:Font = new MyArabicFont();
// assign to textformat
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.font = myFont.fontName;
// assign to textfield
var myTextField:TextField = new TextField();
myTextField.defaultTextFormat = myTextFormat;
myTextField.embedFonts = true;
myTextField.text = "Hello, world";
this.addChild(myTextField);
I have a problem with doing proper font embedding in a actionscript 3 project (flash CS4, not flex).
I followed this Adobe guide to do font embedding:
http://www.adobe.com/devnet/flash/quickstart/embedding_fonts/
the guide tells to set the Textfield.embedFonts property to true. if I do so and try to display a text with another font in this textfield, then nothing is displayed - that's fine, i expect it like this.
But now I have this particular problem:
i embed the font "Arial" in Regular style and create two input Textfields on the stage. one of them i set the embedFonts property to true (as described in the guide) the other i leave as is. Now I publish the thing as swf and try to enter the following (Turkish) string into the textfield
Yeni Yılın Barış ve Mutluluk Getirmesini Dileriz.
now the problem is, that the untouched textfield displays the string correctly - but the one with embedFonts set to true is missing some of the letters (for example ş is not displayed). But the Arial font does have this letter since it is displayed correctly in static - so why does it not render correctly when i set this property (as told in the guide)?
in my final app there shall be a single textField, but multiple embedded fonts and a way to switch between them (for example the user must be able to choose another font for entering chinese text).
can someone tell me how to do it properly?
thanks!
Embedding fonts in Flash is not as straight forward as it should be, and there are a bunch of special cases... One way to ensure that you are embedding the correct characters of your font is enabling "Generate size report" in the Flash Publish Settings.... there you will see all characters of all fonts that are being embedded. The only exception is that fonts embedded using the [EMBED tag do not show there.
Adding the font to the library doesn't embed the whole set of characters of that font (Arial for instance is about 8mb)... it only embeds a subset of them... I'm not sure if its always the standard occidental Latin set, or if it depends on the computer language.
You can extend this set manually using any textfield in your movie (with the "Character embedding..." dialog) as long as you use the actual Library Font name (it shows in the font list with an asterisc at the end... in your case it would be "Arial*").
You can also use the [EMBED tag with the unicodeRange to declare de character set, but bare in mind that the fonts you declare there wont be available in the Flash IDE during editing time... you need to set them at runtime with ActionScript (TextFormat, StyleSheet, etc...), which is not very practical when working with Flash.
I use the system fonts, and avoid the embedded ones like Arial.
public function get availableFonts(): Array
{
var font: Font = null;
var allFonts: Array = Font.enumerateFonts(true).sortOn("fontName", Array.CASEINSENSITIVE);
var embeddedFonts: Array = Font.enumerateFonts(false);
var excludeList: Object = {}
for each(font in embeddedFonts)
{
excludeList[font.fontName] = '';
}
var ourFonts: Array = [];
for each(font in allFonts)
{
if (!excludeList.hasOwnProperty(font.fontName))
{
ourFonts.push(font);
}
}
return ourFonts;
}
The list of fonts that this returns are going to have all their letters.
(wouldn't it be nice if ActionScript had some easier way of doing set difference built in?)
If you're looking for a more robust font loading solution that can load the different fonts at runtime, I've posted some code here (http://labs.tomasino.org/2009/07/16/flash-as3-runtime-font-manager/) and explanations of how to use it.