TextLayoutFormat, when using embedded fonts, FontWeight property does not work - actionscript-3

I have replaced all TextField objects with TextLayout as I require the functionality it offers. When using TextLayoutFormat I try to embolden text using "this._textLayoutFormat.fontWeight = FontWeight.BOLD;"
Adobe have said you can only embolden text when using device fonts:
"Applies only to device fonts (fontLookup property is set to flash.text.engine.FontLookup.DEVICE)."
This seems crazy to me! Does anyone know of a work around?

You have to embed your font twice: once with a normal weight "myFont" and once with fontWeight=bold "myBoldFont", then you should be able to switch from normal to bold by changing the fontName of your TextField. I do agree, this is stupid.

Related

TLFTextField taking device fonts automatically in Flex Application

I am using a Flex Application,It can load external font swfs,Now I am using TLFTextField,Eventhough I set a embedFonts = true, It still taking the device font,How to stop it.
In adobe Documentation it is mentioned that, TLFTextField takes fall back font if embedded font is not available.
Use DF4 instead of DF3 while embedding fonts using AnimateCC or flash. Also use TextLayoutFormat instead of TextFormat

How to get the "style" from a classic textField when loaded by code?

I need to get the style used in a textField placed in the stage, and doing this by code.
The thing is, bold and italic are not enough in my case, since I have a style that is semi-bold.
And I can't find the way to get that style when I analyze the textField in my code.
Do you know of any way to do this?.
In other words, I need to know what is the style of the font used in Flash when I get the textFormat.
For example, if I have a font that is "Signika", I need to know that the style is Semibold. Right now, I only get "Signika". It works if I check the bold style, becuase bold is true. But thats all the information I can get from it.
Thanks.
Behold TextField API Reference and the getTextFormat() method. (yay!)
It returns a TextFormat object which contains a complete definition of that TextField, which can then be applied to another TextField via setTextFormat().
That said, font families work a little differently in AS3 (sadly, not Adobe's fault, but rather the OS). For example, Myriad Pro has Regular, Light, Semibold, and Bold. Yet, once embedded, only two actual font names are displayed, and the only way to differentiate them is by setting the TextFormat.bold = true.
Interestingly, omitting the embed of one of these companion fonts will not throw an error, but rather, in the case that you were to embed only Myriad Pro Regular and not Myriad Pro Bold, setting the TextFormat.bold = true will perform faux bold on regular (which will naturally be much lower quality than the actual bold font, but... it works).
Hope that clears things up.
Update
I looked into the Signika, and it apparently suffers from an acute identity crisis. To exemplify this, embed the entire font family and run the following:
var fontList:Array = Font.enumerateFonts();
for( var i:int = 0; i < fontList.length; i++ ) {
trace("Font Name: " + fontList[i].fontName + ", " + fontList[i].fontStyle )
}
This will trace a list of each font that's present in the environment. Sadly, regardless of how you embed the font (programmatically, or via library import), the font overwrites other family entries (hypothetically because they report the same way without distinction to the environment).
// Myriad Pro Results:
Font Name: Myriad Pro, regular
Font Name: Myriad Pro, bold
Font Name: Myriad Pro Light, regular
Font Name: Myriad Pro Light, bold
Running the same query against a the Myriad Pro family actually reports four entries, without overlap, whereas Signika will only report 2 of 4.
// Signika Results:
Font Name: Signika, regular
Font Name: Signika, bold
What I stated previously still stands: using the API methods above will result in a TextFormat object that fully describes the fonts in use. These are distinguished by both name:String, and bold:Boolean properties on the object. However, since Flash overwrites the embedded object with the same reported properties (or simply doesn't overwrite), you only have 2 of the 4 family styles available at any time: a regular version, and a bold version.
Hope that clarifies things.

AS3 textformat, embedfonts and multiple fonts?

Here is my issue : I have a dynamic html text field, to which i passed html text / textformat such as :
<P ALIGN="LEFT"><FONT FACE="Trebuchet MS" SIZE="14" COLOR="#000000" LETTERSPACING="0" KERNING="0">Some text<B>some bold text</B><I><U>and some italic underline</U></I></FONT></P>
My problem is, i can't use embedfonts because if i do, and use Trebuchet MS for instance, the bold tag will never render as in flash you have to select if the font your embed is bold or not. I'm trying to avoid to convert the whole htmltext/textformat thing to a CSS one..
Any ideas?
You need to make sure all versions of the font (regular, bold, italic, whatever) have been compiled into the SWF.
An easy way to do this is to create some dynamic TextFields (one for each version of the font you want to embed) and place them on stage somewhere out of sight at the start of your movie (for example on the root timeline, frame 1, at x = -100). Make sure they appear in your movie before you display the rest of your text, and make sure you embed the relevant character ranges.
This forces Flash to compile all versions of the font, not just the version you happen to have in your actual TextField you want to display.

Bold and regular font in dynamic text under a mask In Flash with AS3

I have this text "my text is <b>bold</b> and regular".
I want "<b>bold</b>" to be... well, let's say... bold !
I have a mask layer under which there is a text field.
The text field shows htmlText, and i must embed chars. If not embedded, it doesn't display because of the mask. So the solution of importing 2 user fonts ( one bold and one regular) does not work.
I'm thinking this is impossible to do with Flash... Maybe I wrong, am I ?
Thank you !
The problem is that when you embed the characters, it only embeds normal-weight font characters. The Mask is a red-herring; this will happen whether you mask the TextField or not.
You can solve the problem however! Create another TextField in your FLA (off-stage, I imagine) with the same font at the same size, but set the font to bold. Embed characters in that TextField too.
Then, the bold characters in your first TextField will display as bold.
There are other ways to achieve this, especially if you don't use the Flash IDE to compile your swfs (if you use MXML through FDT, FlexBuilder, FlashBuilder or FlashDevelop for example). If you do, then you should lookup how to embed fonts using [Embed] metadata.

ActionScript 3 & font embedding

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.