Unicode that is not recognized properly - actionscript-3

I'm using in Unicode in my application using
for(var i:int=0;i<16;i++) {
for(var j:int=0;j<16;j++) {
button = new Button();
button.x = j*35+10;
button.y = i*20+10;
button.height = 21;
button.width = 35;
button.setStyle("borderColor","red");
button.setStyle(" fontWeight","bold");
button.label= String.fromCharCode(0x2190+16*i+j);
button.addEventListener(MouseEvent.CLICK,greekalpha_clickHandler);
vgr.addElement(button);
}
}
But when I run this code, some symbols are recognized properly and others are not
Hilighted words are recognized properly and others are not. What mistakes have I made in this code?

(I'm just reposting the apparent answer to get this question off the unanswered list. The original answerer(s) in the comments are more than welcome to post instead. I also know the given answer should work, based on my own experience.)
In order to ensure the Unicode symbols show up properly, you need to embed a Unicode font, such as Arial Unicode MS or Lucida Sans Unicode, and set your text objects to that font (it doesn't happen automatically).
Then, turn on anti-aliasing, either via advancedAntiAliasing = true; or by setting the Anti-alias property in Flash Professional to "Anti-Alias for readability".
Any issues beyond this, I presume, are device-specific.

Related

CreateJS/Canvas text position changed after chrome version upgrade from 70 to 71

Createjs text position changed after chrome version upgrade from 70 to 71. please guide me.
I didn't like the current proposed solutions (changing the lineHeight or the line count) because they're not very reliable with different fonts, styles and sizes ... so I rolled my own solution:
var cache = {}
createjs.Text.prototype._drawTextLine = function (ctx, text, y) {
this.textBaseline = ctx.textBaseline = "alphabetic";
if (!(this.font in cache)) {
var metrics = this.getMetrics();
cache[this.font] = metrics.vOffset;
}
var offset = cache[this.font];
if (this.outline) {
ctx.strokeText(text, 0, y - offset, this.maxWidth || 0xFFFF);
} else {
ctx.fillText(text, 0, y - offset, this.maxWidth || 0xFFFF);
}
};
The alphabetic value of textBaseline is the most reliable crossbrowser and generally the standard nowadays.
When it's set to both the Text instance and the CanvasRenderingContext2D, we can call getMetrics and have vOffset of the font from the top of it's bounding box to its baseline.
Apply that offset to the fillText call and you generally get a decent rendering of the font. The cache is there for good measure to avoid re-measuring the metrics of the same fonts on every frame.
From the (limited amount of) tests I ran so far, it seems to be:
pretty stable crossbrowser
performance conscious
very close to the expected font rendering (as seen in Animate) showing just some minor offsets at high font sizes
And yet, some fonts still sucks (ie. Poppins) but I suspect it's a "fault" of the font itself in this case.
Hopefully #lanny will have an official fix in createjs soon, but there's no guarantee when that will be included in Animate sadly.
This is an intentional change in Chrome to bring it inline with the "correct" behaviour (which Firefox has had all along). Here is more information. It looks like that Chrome 71 (and later releases) finally addresses that bug.
The only affected alignment is "top", which is the default. Here is a quick comparison between the two Chrome versions.
We are considering a built-in solution in EaselJS since this is more impactful then when it was just Firefox that was the outlier.
The issue can be solved similarly by overriding "_drawTextLine" in the same Text.js class as described here: https://forums.adobe.com/message/10845543#10845543.
The actual problem with this issue is that different fonts classic, google or adobe (former typekit) behave differently. I am looking for a solution that would normalize font alignment regardless its type or nature.
See an example below. Browser Chrome version 71
Without fix it is
With _drawTextLine fix
Just patched it (only tested with my team and with the Open Sans font) by a simple check on the current user agent and forcing the count property to 0.2 (just tested it with the logic of 1.2 * lineHeight in mind, and it works) instead of 0. Basicaly it will just push down the text by 20% of the lineHeight property.
Be careful, it's not an offical patch, it works for me but it's not battle tested.
Add this code at the begining of the file src/easeljs/display/Text.js (thanks to is.js for the browser detection code):
var userAgent = (navigator && navigator.userAgent || "").toLowerCase();
var vendor = (navigator && navigator.vendor || "").toLowerCase();
var isChrome = /google inc/.test(vendor) ? userAgent.match(/(?:chrome|crios)\/(\d+)/) : null;
And at the line 348, replace the next line:
var maxW = 0, count = 0;
By this one:
var maxW = 0, count = isChrome ? 0.2 : 0;
Of course i'm opened to suggestions and improvments ! :)
Thanks!

Want `­` to be always visible

I'm working on a web app and users sometimes paste in things they've copy/pasted from other places and that input may come with the ­ character (0xAD). I don't want to filter it out, I simply need the user to see that there is an invisible character there, so they have no surprises later.
Does anyone know a way to make the ­ always be visible? To show a hyphen, rather than remain hidden? I suspect a custom web font might be needed, if so, does anyone know of a pre-existing one?
You would need to either use JavaScript or a custom typeface that has a visible glyph for the soft-hyphen character. Given the impracticalities of working with typefaces for the web (and burdening the user with an additional hundred-kilobyte download) I think the JavaScript approach is best, like so:
document.addEventListener("DOMContentLoaded", function(domReadyEvent) {
var textBoxes = document.querySelectorAll("input[type=text]");
for(var i=0;i<textBoxes.length;i++) {
textBoxes[i].addEventListener("paste", function(pasteEvent) {
var textBox = pasteEvent.target;
textBox.value = textBox.value.replace( "\xAD", "-" );
} );
}
} );

Japanese text in TextField with embedded font

In my ActionScript 3 project I use TextField with embedded font set to true and isHTML set to true. Everything works fine when I display latin characters.
But when I want to display Japanese characters they do not appear. Actually it is expected to be like this because Japanese font is not embedded.
Is there is a way to fall back to system font if embedded font doesn't have glyphs for certain characters?
Try to use hasGlyphs("..."); on a Font instance. I had some problems with it but in general it works alright, hopefully it works for Japanese too. Then you can simply use _sans if there is no japanese glyphs.
Edit:
I have no way to test this now but I assume something like this would work:
import flash.text.Font;
var myFont:Font = new MyFont(); // Embedded font in library, linkage set to 'MyFont'
if(myFont.hasGlyphs("Hello!")) {
field.embedFonts = true; // Not sure whether this is necessary in case of HTML text
field.htmlText = "<p><font color='#ff0000' face='" + myFont.fontName + "'>Hello!</font></p>";
}
else {
field.embedFonts = false;
field.htmlText = "<p><font color='#ff0000' face='_sans'>Hello!</font></p>";
}

Basic TextFormat change is doing nothing

Code:
var BoldTextFormat:TextFormat = new TextFormat();
BoldTextFormat.bold = true;
weapons[player.activeWeapon].weaponName.defaultTextFormat = BoldTextFormat;
This seems very simple, but it is not doing anything! The text is not becoming bold at all.
Using weapons[player.activeWeapon].weaponName.setTextFormat(BoldTextFormat); does nothing also.
These traces:
trace(weapons[player.activeWeapon].weaponName);
trace(weapons[player.activeWeapon].weaponName.defaultTextFormat);
trace(BoldTextFormat);
Result in this output:
[object TextField]
[object TextFormat]
[object TextFormat]
And this is the text field I am trying to make bold:
I have embedded the bold font:
What could possibly be wrong? There are no errors. Tracing the text field's text shows the correct text, so that can't be the problem.
You might need to embed the bold font, your image shows 'Regular' font.
Ok, I figured out the magic here. Likely why it started working for you is that you actually set the bold font for your field.
But here's the magic. In the library, right-click on the bold font and choose properties. Then go to the actionscript settings and enable :
export for actionscript
Next, in your code you need to add this line :
BoldTextFormat.font = "Times New Roman Bold";
That should work.
Sadly, the .bold of the TextFormat doesn't seem to automatically find the bold version.
Try :
weapons[player.activeWeapon].weaponName.setTextFormat(BoldTextFormat);
defaultTextFormat applies to text that is added after you set the format, if you want to change the format of text that is already set you should use setTextFormat

Can't embed multiple fonts and use them in same textfield - cs5, as3

having a bit of trouble getting embedded fonts to work. The inconsistency with this is driving me crazy. I've gotten this to work before but not since going to cs5.
My set up is as follows:
I have a dynamic textfield on stage named "tf".
The following code populates the textfield and attempts to style one word, "love" in the sentence with a different font.
_style = new StyleSheet();
var styleObj = new Object();
styleObj.color = '#FF0000';
styleObj.fontFamily = 'Futura Bold Oblique';
_style.setStyle('.otherText', styleObj);
tf.styleSheet = _style;
tf.htmlText = 'I <span class="otherText">love</span> it when stuff works!';
The font is embedded and set to export for actionscript with the export name Font1. The word "love", which is supposed to be displayed as the font Futura Bold Oblique just disappears. It makes no difference if I use the font screen name listed in the properties panel for that font or if I use the export instance name I gave it.
My sentence looks like : I it when stuff works! As you can see, "love" is gone. Come on people, show me some love! lol.
Anyone have an idea why this isn't working. This is highly essential to my daily work and its driving my crazy!! Thx!
I have been playing around with this since posting, hoping that maybe that specific font was causing the trouble, but its not the font. I tried using different styles of Helvetica Neue as separately embedded fonts and got the same result.
Fixed it, sort of. using enumerateFonts. This lists the fonts' names as Flash sees them. Copy and paste from the output window, and use that for the stylesheet fontFamily property. It still seems that Flash thinks some different styles from the same family, like Futura Bold and Futura Bold Oblique are the same; in my case it listed them both as Futura Book. In order to get the Oblique text in there I had to embed two separate versions of the font, Futura and Futura BT.
private function getFontNames():void
{
var fontArray:Array = Font.enumerateFonts(false);
fontArray.sortOn("fontName", Array.CASEINSENSITIVE);
for(var i:int = 0; i<fontArray.length; i++)
{
trace(fontArray[i].fontName);
}
}