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.
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
Hi Jang,
try this:
var sAttrValue = "2018";
var sCharCode = String.fromCharCode("0x" + sAttrValue);
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
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).
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
Copy link to clipboard
Copied
Hi Jang,
try this:
var sAttrValue = "2018";
var sCharCode = String.fromCharCode("0x" + sAttrValue);
Copy link to clipboard
Copied
Klaus, that works for me. Thank you for the useful code.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now