Skip to main content
Known Participant
Oct 20, 2024 4:37 PM UTC
Answered

How-To Display Proper Unicode text via ExtendScript

Is there a way to properly display UNICODE text when adding it via script. I was able to get Illustrator to display UNICODE by enabling "Show Indic Options" under Type Preferences but it still fails via script.

 

This topic is closed to new replies. Start a new post to keep the conversation going.
hhas01Correct answer
Inspiring
Oct 21, 2024 8:10 AM UTC

That’s a font issue, not a Unicode issue. The empty box symbol means the current font doesn’t contain the required glyph.

 

Set the text in a font that contains the “⅛” glyph (e.g. try Arial) and it appears correctly.

5 replies

renél80416020
Inspiring
Oct 21, 2024 1:55 PM UTC

Salut!

Petit script en réponse...

// JavaScript Document
// diametre.js
var police1 = "SymbolMT";

var doc = activeDocument;

 var Phi = String.fromCharCode(8709); // Phi = "\u2205";

      alert(Phi+" 1254");

      police1 = getFont(police1);
      var pointText = doc.textFrames.pointText([20,-20]);
          pointText.contents = Phi+" 1254";
          if (police1 != undefined) pointText.textRanges[0].textFont = police1;
// -------
function getFont(nomPolice) {
     try {
       var police = textFonts.getByName(nomPolice);
     }   catch (e) {
        alert( "The specified font doesn’t exist" );
        return undefined;
        }
     return police;
}
// -------

si ensuite vous modifez la police, dans de nombreux cas le symbole ∅ subsiste.

René

Translate
hhas01Correct answer
Inspiring
Oct 21, 2024 8:10 AM UTC

That’s a font issue, not a Unicode issue. The empty box symbol means the current font doesn’t contain the required glyph.

 

Set the text in a font that contains the “⅛” glyph (e.g. try Arial) and it appears correctly.

Translate
nutradialAuthor
Known Participant
Oct 21, 2024 1:38 PM UTC

I used this script to cycle thru my fonts and obtain proper names for scripting and as you said Arial is one the fonts that contain all necessary glyphs to display the Unicode fractions. Thanks for the help.

Translate
Participant
Nov 20, 2024 5:12 PM UTC

Great script! For advanced text manipulation or working with hidden text, you can also explore Text Invisible—a handy tool for such tasks. Let me know if you'd like details!

Translate
Sergey Osokin
Inspiring
Oct 21, 2024 3:53 AM UTC

Would it help to use the Unicode character for insertion?

var tf = app.activeDocument.textFrames.add();
tf.contents = '\u215B" Diameter';
Translate