Can I convert a library font into a sprite sheet in AS3? - actionscript-3

In Flash I am able to create a font asset and add it to the library:
I want to convert this asset into some BitmapData that will contain all of the characters with the correct letter spacing/line height etc.
Is there an inbuilt way of doing this other than manually creating text fields, adding a character, using BitmapData.draw() and then adding the result to a sprite sheet?
If I need to do it manually like above, is there a way to retrieve all of the embedded characters? For example, in the above screenshot I'd expect only a-z, A-Z. Or will I need to note these manually as well?

If you're going to go with your own solution as I mentioned in my comment (like drawing out each supported character and then batching them together) then here is how you can look up every possible glyph supported by the embedded font. (Psuedo Code)
//Build out a loop that will generate char codes for all possible glyphs
for(etc, etc, etc) {
String glyph = String.fromCharCode(%26);
if(myFont.hasGlyphs(glyph) == true) {
myTextField.text = glyph;
myBitmap.draw(myTextField);
//Save image and repeat
}
}
Reference material:
List of supported char codes.
Font.hasGlyphs() documentation.
String.fromCharCode() documentation.

Related

Cesium PinBuilder using "fromMakiIconId"

I started using cesium for representing 3d maps and was trying to add Point of Interest data on top of this 3d view. I tried local png icons and it worked. I also realized can add icons from built in assets. I tried the below code and it worked perfect. I have a various set of PoIs but could not find the labels using which I can add them onto the map.
For example to add a hospital i referred hospital in the iconid.
var hospitalPin = Cesium.when(
pinBuilder.fromMakiIconId("hospital", Cesium.Color.RED, 48),
function (canvas) {
return viewer.entities.add({
name: "Hospital",
position: Cesium.Cartesian3.fromDegrees(77.311, 32.826),
billboard: {
image: canvas.toDataURL(),
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
},
});
}
);
In the similar way is there any reference for the icon Ids which I can use to make use of them in my code to represent the PoIs. Any help is appreciated.
I found the source images located at \Build\Cesium\Assets\Textures\maki from the cesium library which I think can be used.
The image you posted is from the PinBuilder docs, but check out the original source for that: It's a screenshot of the Cesium Sandcastle GeoJson Demo.
As you noticed, the images of the individual pins are stored in a folder called maki which has names like this:
airport.png
alcohol-shop.png
america-football.png
art-gallery.png
bakery.png
bank.png
bar.png
baseball.png
...
Just strip the .png off the end of the image filename, and that's it. That's the ID.
The dashes are allowed in the ID:
pinBuilder.fromMakiIconId("america-football", Cesium.Color.RED, 48)
But, the first few pins in the original screenshot don't have corresponding Maki icons, they're simple letters or numbers. You can build pins using text, using a different function, like this:
pinBuilder.fromText("A", Cesium.Color.RED, 48)
You may also use pins with Unicode characters on them.
pinBuilder.fromText("\u267b", Cesium.Color.RED, 48)
And finally, if you have a custom PNG file of your own, similar to a Maki icon but customized for your app's need, you may build a pin directly from the URL of the custom PNG file.
pinBuilder.fromUrl(url, Cesium.Color.RED, 48)

if statement skipped , uppercase letters not displaying

I'm making a mini game for my multimedia class using Adobe Animate with ActionScript 3.
The first question requires the user to fill in the blanks to print "hi" like in python.
the question looks like this
_____("hi")
then you would fill in the blanks and click on a check answer button.
Then to check if the answer is correct I use an if-else statement like so :
import flash.events.MouseEvent;
stop();
checkBtn1.addEventListener(MouseEvent.CLICK, checkClick);
function checkClick(event:MouseEvent): void
{
if(input1.text == "print")
{
ans1.text = "Correct!";
}
else
{
ans1.text = "Wrong answer!";
}
}
However, even if the input is correct, it will skip the if part of the code and run straight into else.
It also won't display uppercase letters?
It'll display "rong answer!" ignoring the uppercase "W".
Any ideas?
#Organis is right; The font needs to be embedded.
Flash Professional CS5 (and later) automatically embeds any characters used by text fields on the Stage. However, if you are using Dynamic or Input text fields, the project may also need to include characters for the font that aren't specifically contained in instances on the Stage during authoring. If you do not embed the necessary characters and text elements are programmatically displayed or entered by the user, the characters may be missing and the application may appear broken.
Common Mistakes Working with Fonts and Text Objects in Flash
For help embedding fonts, refer to the Adobe documentation on it.
Embedding Fonts with ActionScript
Embedding Fonts in Adobe Animate (Flash)

Starling Font Fallback

I'm using bitmap fonts to display text.
In case of special characters such as Chinese, I'd like to be able to fall back to system default instead of having all possible characters in the world in the bitmap font.
Is that possible?
Starling's TextField does not provide a way to specify fallback fonts. You will need to check which language you are using beforehand and pass in the font name (in your case system default) that you know will work for the current language.
How to embed a font:
[Embed(source="../embeds/fonts/FuturaLTPro-Book.ttf", embedAsCFF="false", fontFamily="FuturaLTPro-Book")]
public static const Font_FuturaLTPro_Book:Class;
// create a TextFormat instance and use it instead of your bitmap font
var textFormat:TextFormat = new TextFormat(Font_FuturaLTPro_Book:Class, 18, 0x000000);

Simple Flex Paint Application,how to save in the database not in image form

I have a simple Flex paint application which let the user draw anything they want. My problem is how can I save it into MySQL database without converting it to an image format. Moreover, I want it to be save and at the same time to retrieve in case there is an unfinished drawing.
Thank you.
Define what objects can be drawn, e.g. straight lines, points, polygons with controlled corners, etc. For each object, create serialization methods. It may be binary format (I guess you won't need search drawing in database by features used): object type first, then it's attributes. For line, it would be end points, color, maybe width and drawing style (solid, striped, dotted.)
Entire drawing will have some properties too, like width/height, format version. Write those in the header, then will go all drawing objects. If you need layers, you can make special tag for them, which will act like separator between drawing objects:
header - layer 1 tag - line - line - line - layer 2 tag - square - circle
Binary format also gives ability to save drawing into file (or in database as a blob.) Also, you can go with XML, it just will use much more bytes (but will be easier to debug.)

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.