4 Replies Latest reply on Dec 17, 2010 6:20 AM by chughes133

    replace with false glyph?

    chughes133 Level 1

      Hi guys, im making a script that is designed to replace one character with another.

       

      in the case of Arabic, when importing the test you need to change the opening quote for a closing and closing for opening. However in order to do that i need to temporarily change one to another character.

       

      Im using Jongware's script, i understand we are free to modify. the following is a simplified version for my needs:

       

      app.findTextPreferences = null;
      app.changeTextPreferences = null;

       


      var changelijst = [

       

          [ "\u201C",    "\u002A" ],    //     ; Opening Curly for X
          [ "\u201D",    "\u201C" ],    //     ; Closing Curly for Opening Curly
          [ "\u002A",    "\u201D" ],    //     ; X for Closing Curly
          [ "\u00BB",    "\u002A" ],    //     ; Opening Arrow for X
          [ "\u00AB",    "\u201C" ],    //     ; Closing Arrow for Opening Arrow
          [ "\u002A",    "\u201D" ],    //     ; X for Closing Arrow
          [ "\u2018",    "\u002A" ],    //     ; Opening Curly single for X
          [ "\u2019",    "\u2018" ],    //     ; Closing Curly single for Opening Curly single
          [ "\u002A",    "\u2019" ],    //     ; X for Closing Curly single
      ];

       

      for (a=0; a<changelijst.length; a++)
      {
          app.findTextPreferences.findWhat = changelijst[a][0];
          app.changeTextPreferences.changeTo = changelijst[a][1];
          app.activeDocument.changeText();

       

      right now X is a * in that font.

       

      however i need to use a glyph that i can guarantee 100% will not be in their document. is there any way i can use a false glyph? I tried using 999X, but it doesnt leave a character, but rather leaves nothing. (more or less i'd like to create a fake version of that missing font scenario).  Anyone know if there is such a thing? or otherwise, any other suggestions? Thanks!

        • 1. Re: replace with false glyph?
          [Jongware] Most Valuable Participant

          Oh that's a good idea!

           

          You are correct, though, that "999X" does not work. The character codes in this script are for Unicode characters, and their notation is in hexadecimal, which only allows the characters 0..9 and A..F. It's the X that marks the bad spot here

           

          There are a couple of Unicode codes that are "guaranteed not to be a valid character" (per Unicode definition), but it's a bit tricky to use them, because there is no way telling how InDesign will react to them ... And there are a couple of Unicode codes that do not display a character but actually perform a function -- switching between RTL and LTR text, for example. You definitely don't want those to pop up in your text at random.

           

          So, second best is to use a character which is just highly unlikely to appear in your text. How about some Klingon? Oh wait ...

           

          21 Oct 2010 ... Contrary to rumors posted on Unicode discussion boards, Klingon is NOT part of the Unicode specs

           

          Bummer.

           

          Well, you could choose any safe character that is actually defined under Unicode -- say, some Chinese or Korean glyph, or an ancient Greek numeral, a Mahjong tile, or an Alchemical Symbol (see http://www.unicode.org/charts/) -- but there is still a remote chance that character was used somewhere in your text.

           

          Fortunately, the Unicode codepoints do not range seamlessly from U+0001 to U+FFFF (actually they even go far, far beyond that; there are literally millions of unused codepoints). There are huge gaps between the sets, and that's because character sets hardly ever come in a handy number (sets of 128, for Unicode), and they also like to have some "free" space at the end of the range, in case someone wants to add yet another character to Latin or Greek or any other set. So just pick a code that is valid but (as yet) unassigned. All you have to do is browse the UC Chart PDFs one by one until you find an empty spot: http://www.unicode.org/charts/PDF

           

          (Okay, that actually took several minutes.)

           

          Well, first one I found is U+0380, which is somewhere in the middle of the "Greek and Koptic" set but has no associated character or function. If you insert in your text using Find/Change, ID will search for an associated character to display, but it won't find anything -- in any font on your system. So this would be a safe code to use as an interim: "\u0380".

          1 person found this helpful
          • 2. Re: replace with false glyph?
            chughes133 Level 1

            Hi Jongware! Thanks for making useful scripts and letting them be available for people to use and modify!

             

            Now, i tried 0380 and unfortunately it had the same result as 999X, that is it only left a blank space, and not a red indicator. Afterwards, it could not be searched. It might be helpful to know that I am working with 2 fonts, Yakout Linotype and Traditional Arabic. Other than that I don't know what else might be helpful. I tried a blank space in one of the Arabic sections, FDD0 to be precise, however the result was the same. Any other leads?

             

            Thanks again!

             

            Edit, as what was my primary idea, Grep searches will not work. Neither in the FindChangeByList script, nor in this one.

             

            what works in indesign to find what should be an opening parenthesis is the following: (?<=\s)~{

             

            however that doesnt catch anything when you run it. Also, if you cut and paste your search from Indesign you get: (?<= )"

             

            Which also doesnt find anything. I assume that it is because of some kind of character issue. I tried saving the text file for FindChangeByList as a UTF-8 .txt however that didnt work.

            • 3. Re: replace with false glyph?
              [Jongware] Most Valuable Participant

              Hmm -- there appear to be something wrong in your code, but I can't figure out what it is. I tried without a script, and replacing something with \u0380 works just fine:

               

              0380.PNG

               

              "\u0380" is native Javascript notation, but you could try the alternative notations that InDesign supports: for plain text find/replace <0380>, and when using GREP \x{0380}

              • 4. Re: replace with false glyph?
                chughes133 Level 1

                HMMM odd, OK

                 

                I was trying to use 0380 inside indesigned native glyph change. However when I ran the glyph in a script it worked! I find that strange, but ok great! Thanks a bunch again Jongware! (btw, i used the /u version, it simply had to do it with a javascript rather than inside indesign)

                 

                edit:

                and Brilliant, I tried the full thing and it works like a charm!