A ColdFusion UDF Designed to Format a Unicode String for InDesign

I was generating InDesign JSX files using ColdFusion and creating PDFs that happened to have Unicode characters in them. This task is not difficult, but it is rather boring. At least, it was boring until I realized that I could not use Unicode characters inside an InDesign JavaScript file. JSX only accepts Unicode characters by their "glyph id number," or "code point," or whatever name you geeks prefer to call it. So I put together a small ColdFusion function that formats the Unicode characters in a string into code points that are recognized by inDesign. I prefer to save ascii characters as they are, so if I have to read the converted string, it will make sense to me.

This function will convert a string, such as "Peace™ Justice® and යුනිකෝඩ්", into a string that is recognized by InDesign script, such as:

"Peace\u2122 Justice\u00AE and \u0DBA\u0DD4\u0DB1\u0DD2\u0D9A\u0DDD\u0DA9\u0DCA"

   1: <cffunction
   2:  name        = "toCodePoint"
   3:  returntype ="string"
   4:  output     = "no"
   5:  description = "Convert Unicode in to inDesign friendly code point values">
   6:      <cfargument name="string" required="Yes" type="string">
   7:     
   8:      <cfset newString = "">
   9:      <cfloop from="1" to="#len(arguments.string)#" index="i">
  10:      <cfset thisChr    = mid(string,i,1)>
  11:          <cfset deci    = asc(thisChr)>        
  12:  <cfif deci gt 4096>
  13:              <cfset newString = "#newString#\u#Ucase(FormatBaseN(deci,16))#">
  14:          <cfelseif deci gt 255>
  15:              <cfset newString = "#newString#\u0#Ucase(FormatBaseN(deci,16))#">
  16:          <cfelseif deci gt 127>
  17:              <cfset newString = "#newString#\u00#Ucase(FormatBaseN(deci,16))#">
  18:          <cfelse>
  19:              <cfset newString = "#newString##thisChr#">
  20:          </cfif>
  21:      </cfloop>
  22:     
  23:      <cfreturn newString>
  24:  </cffunction>
Show/Hide Line Numbers . Full Screen . Plain

6 Comments :
නිෂාන
Monday 15 October 2012 03:25 AM
අයියා.
මට කියන්කො යුනිකෝඩ කොහොමද ඇඩෝබෙ ඉන්ඩිසයින් එකේ ලියන්නෙ කියල.

මම ගොඩ කාලයක් මේක කරන්නෙ කොහොමද කියල කල්පනා කරනව.

ඉස්තූතියි.
Wednesday 17 October 2012 04:06 AM
Go to window > Type & Tables > Glyphs. Select Iskoka Potha as the font and scroll down until you find Sinhala Unicode range. You won't be able to type Sinhala, but will be able to select letter by letter. Indic Scripts (including Sinhala) Unicode design compromised quite a lot of flexibility in basic lever, for years to come we may have to use workarounds like that. Japanese other hand always smarter than us build an complete Unicode table, one position for each character.
j.v.subramanyam
Friday 16 December 2011 02:04 AM
when i am creating pdf using cfdocument some of the unicode fonts like hindi are not visible in the pdf. other fonts like telugu, tamil are visible in pdf. when I cahnged the fromat of cfdocumen from pdf to Flashpaper the hindi fonts also visible. when i combined the hindi and telugu fonts the hindi fonts are showing properly , but the telugu fonts are showing as junk. Please help me.
Wednesday 21 December 2011 01:33 PM
Are you using InDesign server to make PDF of coldfusion cfpdf tag? this sound more like a font issue. if it's a indesign server, make sure fonts are also copied in to InDesign server's font folder. if it's CFPDF, try using another font and also make sure fonts are registred with the cf admin.
Thursday 07 April 2011 04:17 PM
CS5 should work with Unicode characters without special formatting.
Joel Stobart
Thursday 07 April 2011 05:40 AM
Seems to not work in cs5 - puts the replacement characters into the strings

e.g. \u205c appears as "\u205c"...