5 Replies Latest reply on Apr 3, 2015 3:12 AM by Gaius Coffey

    I promise you that the font _is_ there. :(

    Gaius Coffey Level 2

      OK, so I am having problems dynamically managing fonts in an automated build process.

       

      To be clear;

      a) I have a font

      b) I really, really, really _know_ that I have this font

      c) I checked again, the font _is_ there

       

      Having checked all that, I search for the font using app.fonts.itemByName(fontName) and then try to _use_ the font that I _know_ that I have.

       

      It works for roughly 650 out of 710 fonts.

       

      For the others... I just see "The requested font style is not available."

       

      _WHY_?

       

      _WHY_?

       

      Please, please, please...

      Anybody?

      Thanks,

      G

       

      found.fontFamily : Baskerville
      found.fontStyleName : Regular
      found.fontStyleNameNative : Regular
      found.fontType : 1718898516(OPENTYPE_TT)
      found.fullName : Baskerville
      found.fullNameNative : Baskerville
      found.index : -1
      found.isValid : true
      found.location : C:\Program Files\Adobe\Adobe InDesign CC 2014\Fonts\Baskerville.ttf
      found.name : BaskervilleRegular
      found.ordering :
      found.parent : [object Application]
      found.platformName : Baskerville
      found.postscriptName : Baskerville
      found.properties : [object Object]
      found.registry :
      found.restrictedPrinting : false
      found.status : 1718831470 (ok)
      found.version : Version 1.00
      found.writingScript : 0

      ERROR: {"fileName": "printFinal.jsx", "lineNumber": "368", "templateId": "TEMPLATE", "message": "The requested font style is not available.", "inputArguments": {}}

       

       

      [code]

      var found = app.fonts.itemByName(cleanedFontFamily);

                      function writeFontType(val) {

                          switch(val) {

                              case FontTypes.ATC : return "ATC";

                              case FontTypes.BITMAP: return "BITMAP";

                              case FontTypes.CID : return "CID";

                              case FontTypes.OPENTYPE_CFF : return "OPENTYPE_CFF";

                              case FontTypes.OPENTYPE_CID : return "OPENTYPE_CID";

                              case FontTypes.OPENTYPE_TT : return "OPENTYPE_TT";

                              case FontTypes.TRUETYPE : return "TRUETYPE";

                              case FontTypes.TYPE_1 : return "TYPE_1";

                              case FontTypes.UNKNOWN : return "UNKNOWN";

                             

                          }

                          return "unknown";

                      }

                      this.debug("\tNATIVE:\n\t"+[

      "found.fontFamily : "+found.fontFamily,

      "found.fontStyleName : "+found.fontStyleName,

      "found.fontStyleNameNative : "+found.fontStyleNameNative,

      "found.fontType : "+found.fontType+"("+(writeFontType(found.fontType))+")",

      "found.fullName : "+found.fullName,

      "found.fullNameNative : "+found.fullNameNative,

      "found.index : "+found.index,

      "found.isValid : "+found.isValid,

      "found.location : "+found.location,

      "found.name : "+found.name,

      "found.ordering : "+found.ordering,

      "found.parent : "+found.parent,

      "found.platformName : "+found.platformName,

      "found.postscriptName : "+found.postscriptName,

      "found.properties : "+found.properties,

      "found.registry : "+found.registry,

      "found.restrictedPrinting : "+found.restrictedPrinting,

      "found.status : "+found.status+" ("+(found.status==FontStatus.INSTALLED?"ok":"investigate")+")",

      "found.version : "+found.version,

      "found.writingScript : "+found.writingScript

                      ].join("\n\t"));

                     

                      style.appliedFont = found;

      [/code]

        • 1. Re: I promise you that the font _is_ there. :(
          Gaius Coffey Level 2

          Update:

           

          I can get past the style not found error by using;               

          style.properties = {fontStyle:fontStyle,appliedFont:found};

           

          This will set both the font style and the applied font at the same time, so prevent any problems with inconsistent values.

           

          Now, instead, I am seeing "Missing font" errors with, not very helpfully, "Apply a different font or choose Type > Find Font to replace the font throughout the document."

           

          This is not very helpful because;

          a) The font _is_ there and using Find Font simply applies the same font "in a different way"

          b) This is an automated scripted solution where the font should be correct... because all values taken from InDesign in the first place

           

          So...

           

          Still need help...

          • 2. Re: I promise you that the font _is_ there. :(
            Gaius Coffey Level 2

            To be clear; as per the screenshots below, I "fix" the document by using the values I specify in my script ("Baskerville" rather than the "Baskerville (TT)" that InDesign has selected for no apparent reason).

             

            However, I can _only_ achieve this through the IDE. There is no way that I can detect to use the font _without_ going into the IDE. If, for example, I were to use "Baskerville (TT)" as my font name, the script would fail because there is no matching font.

             

            Stage1.PNG

            Stage2.PNG

            Stage3.PNG

            • 3. Re: I promise you that the font _is_ there. :(
              Marc Autret Level 4

              Hi Gaius,

               

              Your first post prompts "found.index : -1", which means that your Font object (found) has no actual match in the app.fonts collection (despite the many details that the code reveals).

              Why is that item unresolved? As long as we don't know what is within your cleanedFontFamily argument, it's difficult to help you.

               

              A possible mistake is that cleanedFontFamily may only contain a family name, which is not what app.fonts.itemByName() expects. The full pattern of a font name is:

              <fontFamily><TAB><fontStyleName>

              so maybe you should try something like app.fonts.itemByName("Baskerville\tRegular")

               

              @+

              Marc

              • 4. Re: I promise you that the font _is_ there. :(
                Gaius Coffey Level 2

                Hi Marc,

                First of all, thanks a million for correcting my font reference name - I couldn't find any documentation on what it should have been so I tried a few things and ended up using what my predecessors had used (which was... wrong). I've now corrected the lookup to use the correct format and I have eliminated about 90% of my font lookup issues.

                 

                Which means that I am left with the tricky ones.

                 

                Taking the Baskerville font as an example;

                1. I am importing a snippet with IDML stating appliedFont = Baskerville

                2. When I test the relevant style ranges, they are reporting appliedFont = Baskerville (TT)

                3. If I look for app.fonts.itemByName("Baskerville (TT)\tRegular") I get index = -1; (thanks for giving me that test for font install also!) and font is not found

                4. If I look for app.fonts.itemByName("Baskerville\tRegular") I get a valid index and no error when I try to use the font... But...

                5. Whatever I do, the preflight fails with uninstalledFonts "Baskerville (TT)"

                 

                I've dug a little deeper here; I saved as IDML, and looked at the fonts.xml file; there are two Baskerville fonts listed... and there shouldn't be. I can _manually_ edit the Fonts.xml file in IDML then open in InDesign and save as INDD... _then_ my scripted build process works.

                 

                But...

                 

                I can't do that across the millions (literally) of legacy INDD files that I have running around here.

                 

                Any ideas how to eradicate broken font references like this without manually editing IDML / XML?

                 

                Thanks,

                G

                 

                ManualFixes.PNG

                • 5. Re: I promise you that the font _is_ there. :(
                  Gaius Coffey Level 2

                  OK, so had some help from Vlad / vamitul off line and the font list can be cleaned out with a save to IDML then reopen and overwrite the INDD.

                  All good, thanks Marc, thanks Vlad!

                  G