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

How to add unicode characters from extendscript

Advocate ,
Apr 06, 2023 Apr 06, 2023

Copy link to clipboard

Copied

One of my scripts requires entering a unicode character, but I have not yet found the method to do so. I need to use the oDoc.AddText method, which requests the second parameter to be a text string. I can enter a unicode character in the script, but it needs to be pulled from an attribute which carries the unicode number for the character. So how do I go from unicode number to an actual character to be pushed into my doc?

Maybe this is trivial, but I am not getting any results with my trials so far. I have tried using the String.fromCharCode(  ) but that results in a question mark (indicating an unknown character).

Any help is greatly appreciated.

TOPICS
Formatting and numbering , Scripting

Views

410

Translate

Translate

Report

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 2 Correct answers

Community Expert , Apr 06, 2023 Apr 06, 2023

Hi Jang, Try this:

#target framemaker

var doc, pgf, textLoc;

doc = app.ActiveDoc;
pgf = doc.TextSelection.beg.obj;
textLoc = new TextLoc (pgf, 0);

doc.AddText (textLoc, "\u03C3"); // sigma

Votes

Translate

Translate
Enthusiast , Apr 07, 2023 Apr 07, 2023

Hi Jang,

 

try this:

var sAttrValue = "2018";
var sCharCode = String.fromCharCode("0x" + sAttrValue);

Votes

Translate

Translate
Community Expert ,
Apr 06, 2023 Apr 06, 2023

Copy link to clipboard

Copied

Hi Jang, Try this:

#target framemaker

var doc, pgf, textLoc;

doc = app.ActiveDoc;
pgf = doc.TextSelection.beg.obj;
textLoc = new TextLoc (pgf, 0);

doc.AddText (textLoc, "\u03C3"); // sigma

Votes

Translate

Translate

Report

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 ,
Apr 06, 2023 Apr 06, 2023

Copy link to clipboard

Copied

re: \u03C3

Note that this works for Unicode BMP characters only (U+0000 to U+FFFF), 4 hex digit \u markup.

FM does not yet properly support any Supplementary Plane characters (U+10000 & up, no known markup notation).

Votes

Translate

Translate

Report

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
Advocate ,
Apr 06, 2023 Apr 06, 2023

Copy link to clipboard

Copied

Hi Rick,

Thanks for the code. I expected you would answer.

I tried the code and although it works when using the '\u03C3' as a single string value, I have not been able to assemble the code from the \u prefix with a string value coming from the attribute. The attribute would show '2018' and if I literally create the string '\u2018' it works fine, but when I use the following code it does not:

var sAttrValue = '2018'

(this is actually read from an attribute by another function, but that would make this reply too long and hard to read.

var sCharCode = '\u' + sAttrValue;

Although the combined string should read '\u2018' what happens is that I get the visible text '2018' on my page. For my current project I can live with this as there are only about 10 possible attribute values (i.e. character codes) so I used a switch statement and entered the correct \u values as complete strings. But if there is another application where I would need to read any possible unicode into an extendscript I would not be able to handle it this way. So if you have another trick to make this work I would be happy about that.

Jang

Votes

Translate

Translate

Report

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
Enthusiast ,
Apr 07, 2023 Apr 07, 2023

Copy link to clipboard

Copied

Hi Jang,

 

try this:

var sAttrValue = "2018";
var sCharCode = String.fromCharCode("0x" + sAttrValue);

Votes

Translate

Translate

Report

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 ,
Apr 07, 2023 Apr 07, 2023

Copy link to clipboard

Copied

Klaus, that works for me. Thank you for the useful code.

Votes

Translate

Translate

Report

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
Advocate ,
Apr 07, 2023 Apr 07, 2023

Copy link to clipboard

Copied

LATEST

Thanks everyone. Nice to get help on various deep-technical things. As you may know, I keep pushing the boundaries of what FrameMaker can do. I am still very much covered in work but I am planning to share some of my scripting tricks when I find the time. Not here, where they will quickly be lost in all the other posts but in a dedicated corner of my Smart Information Design website, so that they remain available as sources of inspiration and reference to taming Frame.

Votes

Translate

Translate

Report

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