Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

How to evaluate string for "emoji" characters and convert to "EmojiOne" font?

LEGEND ,
Jul 09, 2019 Jul 09, 2019

I routinely receive text strings that include emoji characters like this:


(this is the actual text but the heart does not appear after posting: Missing You   )

When pasted into Illustrator they look like this:

I'd like to convert the font character to "EmojiOne" automatically using Javascript:

Using Javascript, how do I test the string variable to see if it contains an emoji character then convert to "EmojiOne"?

Edit:
Interesting… When I paste directly into AI (not into a pre-formatted placeholder) the emoji converts automatically and the rest of the text is the default font,Myriad Pro. Cannot get it to paste consistently through.

TOPICS
Scripting
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 10, 2019 Jul 10, 2019

Yes, ExtendScript not support the Surrogate area. However, you can check char codes with the charCodeAt method.

I tried to write sample code. Is this helps you?

var tg = app.selection[0]; //Target is selected textFrame

var fnt = app.textFonts.getByName('EmojiOneColor');

var chrcd;

for (var i=0;i<tg.characters.length;i++){

  chrcd = tg.characters.contents.charCodeAt(0);

  if (chrcd>55295&&chrcd<56320) { //find High Surrogate

  tg.characters.textFont = fnt;

  i++;

  }

}

Translate
Adobe
Community Expert ,
Jul 09, 2019 Jul 09, 2019

Emoji has two char codes, You can see below example.

These are High Surrogate and Low Surrogate code. ExtendScript can't phrase characters in this area correctly.

スクリーンショット 2019-07-10 12.50.46.png

Probably, You can search High Surrogate and you'll get Emoji position.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 10, 2019 Jul 10, 2019

Thanks for the explanation, Ten A. I'll see what I can come up with.

Edit:
The "alert" appears garbled when I run it from ESTK (Mac).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 10, 2019 Jul 10, 2019

Yes, ExtendScript not support the Surrogate area. However, you can check char codes with the charCodeAt method.

I tried to write sample code. Is this helps you?

var tg = app.selection[0]; //Target is selected textFrame

var fnt = app.textFonts.getByName('EmojiOneColor');

var chrcd;

for (var i=0;i<tg.characters.length;i++){

  chrcd = tg.characters.contents.charCodeAt(0);

  if (chrcd>55295&&chrcd<56320) { //find High Surrogate

  tg.characters.textFont = fnt;

  i++;

  }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 11, 2019 Jul 11, 2019

This is awesome, Ten A​! Thank you!

I was able to change the this line to make the script update any emoji. I arbitrarily changed the first number to "25295" and it seems to be working. I'm not sure how to verify what number it should really be.

if (chrcd>25295&&chrcd<56320) { //find High Surrogate

Edit:

After a little more testing I went with these numbers:

(chrcd>195&&chrcd<96320)

I created a text frame that included all normal keyboard characters + a few emojis and ran the script until some of the normal characters changed font or some of the emojis did NOT change font.

If anyone knows how to set these with accuracy I'm interested in learning.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2019 Jul 11, 2019

Most Emoji characters are allocated to the Unicode plane 1. However, Some characters allocated into Basic Multilingual Plane(Plane 0), You can see the below image.

These characters need individualized processing.

スクリーンショット 2019-07-12 11.17.19.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 12, 2019 Jul 12, 2019
LATEST

Funny, I don't see the "Unicode" option in my left column (Mac OS X 10.13.6).

Edit:
Found it… Had to "Customize" list:

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines