11 Replies Latest reply: Feb 4, 2012 7:49 PM by [Jongware] RSS

    [AS][CS5] Find and replace a missing font

    lithodora Community Member

      I have an overly complex script that compares the document's fonts missing fonts to the system fonts and makes a best guess. It was written to handle conversion of Multi-ad Creator documents to InDesign. It has worked 100% of the time so far. It needs a LOT of cleaning up and tweaking to make effecient, but that is not the point of my question. Everyday I am sent an InDesign file I have to work with and everyday it will has a missing font. Arial (OTF).

      I ran my script thinking it would replace it with Arial (TT). No problem...

       

      Ran it... nothing.

       

      When I use the find dialog in Indesign to search based on the applied font it works, the returned properties in AS contain:

       

      return properties of find text preferences

      font:"Arial (OTF)"

       

      Ok, fine so I try...

       

      set properties of find change text options to {case sensitive:false, whole word:false, include footnotes:false, include hidden layers:false, include locked layers for find:true, include locked stories for find:true, include master pages:true}

          set applied font of find text preferences to "Arial (OTF)"

          set applied character style of change text preferences to "Page&Header"

          tell document 1

              set myFoundItems to change text

          end tell

       

      Nothing.

       

      This has pretty much worked on every other font I've tried, so what am I doing wrong here?

        • 1. Re: [AS][CS5] Find and replace a missing font
          sstanleyau Community Member

          lithodora wrote:

           

              set applied font of find text preferences to "Arial (OTF)"

           

          What happens if you use:

           

              set applied font of find text preferences to font "Arial (OTF)"

          • 2. Re: [AS][CS5] Find and replace a missing font
            Nagaraj Muthu Community Member

            Use the Type Menu -> Find Font to easy replace the missing fonts manually.

            • 3. Re: [AS][CS5] Find and replace a missing font
              lithodora Community Member

              Shane Stanley wrote:

               

              What happens if you use:

               

                  set applied font of find text preferences to font "Arial (OTF)"

              I believe I did try that and it said something along the lines of Unable to reconcile font name. I'll be back on the Mac in the morning and I'll verify that.

               

              On a side note: It seems almost everytime I google for something to do with scripting this stuff your name pops up in the thread. Directly (here) and indirectly (old mail lists) you have been a great help to me in most of my endeavours at automating. I just wanted to say thanks.

              கற்பனை (Imagine) wrote:

               

              Use the Type Menu -> Find Font to easy replace the missing fonts manually.

              That would defeat the purpose of automating the entire process. I don't want to have to do anything but be George Jetson and click 1 button to do the whole proccess. If I have the time to write the scripts then I'm going to automate the majority of my job. Luckily for me no one else understands how to write any of this stuff. They don't trust the scripts either, so I'm in no danger of automating myself out of a job. 

              • 4. Re: [AS][CS5] Find and replace a missing font
                sstanleyau Community Member

                lithodora wrote:

                 

                On a side note: It seems almost everytime I google for something to do with scripting this stuff your name pops up in the thread. Directly (here) and indirectly (old mail lists) you have been a great help to me in most of my endeavours at automating. I just wanted to say thanks.

                 

                <blush> Glad to know it helps.

                • 5. Re: [AS][CS5] Find and replace a missing font
                  John Hawkinson CommunityMVP

                  So what happened? I woudl speculate that you might have to omit the (OTF) from the font name. I realize this might be seriously problematic.

                  • 6. Re: [AS][CS5] Find and replace a missing font
                    Muppet Mark Community Member

                    John, I too would have tried that… App dictionary says:

                     

                    applied font (any) : The font applied to the find text preference, specified as either a font object or the name of font family. Can return: font, string or nothing.

                     

                    Other apps like to use the postscript name but Im not sure if thats the case here…?

                    • 7. Re: [AS][CS5] Find and replace a missing font
                      absqua Community Member

                      I suppose we should wait to hear back from the OP, but I thought I would chime in to say that CS5 acts weeeeeird when you have different faces of the same font from different font types (which I think is the only time you see the "(T1)", "(TT)" or "(OTF)"), in a way that CS4 didn't. I don't have mixed faces of Arial, but I do of Helvetica Neue. If I do a findText() with this findTextPreference:

                       

                      app.findTextPreferences.appliedFont = "Helvetica Neue (T1)     47 Light Condensed";
                      

                       

                      I get nothing, even though I should. When I then look at the Find/Change dialog in the UI, I see:

                       

                      Screen shot 2012-02-01 at 2.57.17 PM.PNG

                       

                      (Note the "TT".) Assigning a string rather than font to findTextPreferences.appliedFont, or using "Helvetica Neue" or "Helvetica Neue (T1)", gets me the same thing: nothing found, and "Helvetica Neue (TT)" displayed in the Find/Change UI.

                       

                      I can specify any of those in the UI and it works as expected—as it did in CS4. I ran into a different but related issue, involving idml interpretation, with CS5, and filed a bug report, but have not had a chance to see if it was fixed in 5.5.

                       

                      Jeff

                      • 8. Re: [AS][CS5] Find and replace a missing font
                        lithodora Community Member

                        Well I've been to busy to revisit this but I will in the next day or two. Sadly one of my co-workers had to leave work permanently due to cancer treatment not being effective. It has been somewhat emotional and overwhelmingly busy as the rest of us picked up the added work load.

                         

                        My experience has been quiet like absqua described: The font name shows up in the Find/Change UI, but for whatever reason it does not work. When I manually changed it the Font Family field is empty. Selecting the font has the result that the Find/Change UI appears to be exactly as it was before, except now the characters with the applied font are actually found.

                         

                        I returned the properties of the missing font and got the postscript name. I tried doing something defining the font by the postscript name but it never worked.

                         

                        I'll most likely return to the issue on Friday, if not Saturday for sure. I'm interested in resolving this.

                        • 9. Re: [AS][CS5] Find and replace a missing font
                          lithodora Community Member

                          All right, back at it....

                           

                          I've run into even more fonts that it is an issue with. My basic thoughts on this are as follows: When bringing a document from Multi-ad Creator to InDesign the fonts are named in a way that InDesign does not recognize them. The thing is those fonts are really fonts that are on my system. It is simply a matter of rearranging the name of the applied font to match what InDesign would recognize. The thing is InDesign will allow me to use Find/Change to modify the fonts in the document.

                           

                          Now the fonts I've run across that give me an issue are fonts that do not correspond to any font on my system. I do not have any TrueType fonts, this document I opened today did...

                           

                          tell application "Adobe InDesign CS5.5"

                              set myDocument to active document

                              tell myDocument

                                  set myPage to page 1

                                  return properties of every font

                              end tell   

                          end tell

                           

                          {{font family:"Helvetica (TT)", PostScript name:"Helvetica-Bold", parent:document id 34 of application "Adobe InDesign CS5.5", index:1, name:"Helvetica (TT)     Bold", object reference:font "Helvetica (TT)     Bold" of document id 34 of application "Adobe InDesign CS5.5", status:not available}, {font family:"Helvetica (TT)", PostScript name:"Helvetica", parent:document id 34 of application "Adobe InDesign CS5.5", index:0, name:"Helvetica (TT)     Regular", object reference:font "Helvetica (TT)     Regular" of document id 34 of application "Adobe InDesign CS5.5", status:not available}, {font family:"Times (TT)", PostScript name:"Times-Bold", parent:document id 34 of application "Adobe InDesign CS5.5", index:3, name:"Times (TT)     Bold", object reference:font "Times (TT)     Bold" of document id 34 of application "Adobe InDesign CS5.5", status:not available}, {font family:"Times (TT)", PostScript name:"Times-Roman", parent:document id 34 of application "Adobe InDesign CS5.5", index:0, name:"Times (TT)     Regular", object reference:font "Times (TT)     Regular" of document id 34 of application "Adobe InDesign CS5.5", status:not available}}

                          Ok, so let me try this (commented out are the different ways I've tried):

                          tell application "Adobe InDesign CS5.5"

                              set myDocument to active document

                              tell myDocument

                                  set myPage to page 1

                                    --return properties of "Helvetica (TT)" --"Helvetica (TT)     Bold"

                                  return properties of font "Helvetica (TT)" -- "Helvetica (TT)   Bold"

                                  set myDocumentFonts to name of every font

                              end tell

                          end tell

                          Adobe InDesign CS5.5 got an error: Unable to retrieve the font's UID from its name.

                           

                          I was able to get the properties of the font using:

                           

                          return properties of every font whose PostScript name is "Helvetica-Bold"

                          {font family:"Helvetica (TT)", PostScript name:"Helvetica-Bold", parent:document id 34 of application "Adobe InDesign CS5.5", index:1, name:"Helvetica (TT)     Bold", object reference:font "Helvetica (TT)     Bold" of document id 34 of application "Adobe InDesign CS5.5", status:not available}

                           

                          Now I thought of trying the following:

                           

                          tell application "Adobe InDesign CS5.5"

                              set find text preferences to nothing

                              set change text preferences to nothing

                              --Set the find options.

                              set properties of find change text options to {case sensitive:false, whole word:false, include footnotes:false, include hidden layers:false, include locked layers for find:true, include locked stories for find:true, include master pages:true}

                              set applied font of find text preferences to every font whose PostScript name is "Helvetica-Bold"

                              set applied font of change text preferences to "Helvetica"

                              tell document 1

                                  set myFoundItems to change text

                              end tell

                             

                          end tell

                           

                          Now this does result in something, the find of the Find/Change dialog is looking for Helvetica + Bold. The only problem with that is it isn't looking for the TT font.

                           

                          tell application "Adobe InDesign CS5.5"

                              set myDocument to active document

                              tell myDocument

                                  set myfind to properties of every font whose PostScript name is "Helvetica-Bold"

                              end tell

                              set find text preferences to nothing

                              set change text preferences to nothing

                              --Set the find options.

                              set properties of find change text options to {case sensitive:false, whole word:false, include footnotes:false, include hidden layers:false, include locked layers for find:true, include locked stories for find:true, include master pages:true}

                              set applied font of find text preferences to name of myfind

                              set applied font of change text preferences to "Helvetica"

                              tell document 1

                                  set myFoundItems to change text

                              end tell

                          end tell

                          And nothing happens.. other than it trying to search for Helvetica + Bold

                           

                           

                           

                          I'll try some other ideas later when I have more time.

                          • 10. Re: [AS][CS5] Find and replace a missing font
                            lithodora Community Member

                            Something else I thought I'd try with no success:

                             

                            (Index 1 for this test only as it was the only font in the document)

                            set mytest to (object reference of every font of active document whose index is 1) as string

                            Which sets mytest to:

                             

                            font "Arial (OTF)     Bold" of document id 3 of application "Adobe InDesign CS5.5"

                            Put that into the find text preferences and it says it got nothing...

                            • 11. Re: [AS][CS5] Find and replace a missing font
                              [Jongware] CommunityMVP

                              Thus far you confirmed everything I found while experimenting in Javascript ...

                               

                              It seems a missing font is not a Font -- the internal type for InDesign, with a name, an id, a version number etc. etc. Since it's not a Font, none of the regular ways of using it work: not by object id, not by name, and not by direct object reference. The "(OTF)" and "(TT)" suffixes are not part of the font name, as you can see when doing this

                               

                              alert (app.selection[0].appliedFont.name);

                               

                              with the text cursor inside a missing font. Note that ID still thinks it's a Font object:

                               

                              alert (app.selection[0].appliedFont);

                               

                              will say it's [Object Font], but about the only thing you can access is its name. Stuff like "app.selection[0].appliedFont.fullName" will return an error.

                               

                              I gave up trying to script this.