6 Replies Latest reply on Sep 24, 2008 12:24 AM by Loic.Aigon

    Font problem

      Lang = javascript
      Indesign version = CS2

      The following code throws an error;

      1. var docObj = app.documents.add();
      2. var page = docObj.pages.add();
      3. var tFrame = page.textFrames.add({geometricBounds:[20,20,100,400]});
      4. var korFont = app.fonts.item("Adobe Myungjo Std");
      5. tFrame.contents = "향찰/鄕札";
      6. tFrame.paragraphs.firstItem().appliedFont = "Adobe Myungjo Std";
      7. tFrame.paragraphs.firstItem().fontStyle = "M";

      The error "The requested font family is not available." is thrown at line 6. How can Indesign return a valid font object at line 4 and then throw the above error at line 6 using the same font family name.

      If I change line 6 to use the font object "korFont" the same error is thrown.

      I noticed looking in ExtendScripts data browser that most of the properties on the font object are prefaced with "Error" ex: "fontType = Error: fontType". I have seen this before with other fonts but was still able to use them.

      Any ideas

      Thanks Mike
        • 1. Re: Font problem
          Loic.Aigon Adobe Community Professional
          At first glance, I would suspect a "lack" of precision.
          I mean :
          tFrame.paragraphs.firstItem().appliedFont = app.fonts.item("Adobe Myungjo Std");
          or
          tFrame.paragraphs.firstItem().appliedFont = korFont;
          but not
          tFrame.paragraphs.firstItem().appliedFont = "Adobe Myungjo Std";

          "Adobe Myungjo Std" is just a string, app.fonts.item("Adobe Myungjo Std"); is a reference to the font object.
          • 2. Re: Font problem
            Level 1
            Adobe's docs state that you can use either a string or a font object when setting the "appliedFont" property of a paragraph object (or any other object that supports the "appliedFont" property).

            But as I stated in the initial post Indesign throws the error in either case.

            Thanks Mike
            • 3. Re: Font problem
              Loic.Aigon Adobe Community Professional
              i But as I stated in the initial post Indesign throws the error in either case.
              oops sorry about that :-)
              Loic
              • 4. Re: Font problem
                Loic.Aigon Adobe Community Professional
                Hi again,<br />I dropped an eye on the Indesign CS2 scripting guide and noticed this line :<br />app.fonts.item("Minion Pro");<br />But I guess the font should be Adobe Minion Pro. " " " Maybe" " " using Adobe in your "Adobe Myungjo Std" is useless. Hence you could try with "Myungjo Std".<br />In last case, you can have a debug script in the ESTK to get the native indesign denomination for the fonts.<br />something like...<br /><br />for(i=0; i<app.fonts.length; i++)<br />$.writeln(app.fonts[i].name);<br /><br />This way you would definitely put aside a error due to maybe a bad call to the font name. (I mean "Adobe" necessary or not ?)<br /><br />Loic
                • 5. Re: Font problem
                  Peter Kahrel Adobe Community Professional & MVP
                  Mike,

                  You have to specify font name and font style at the same time:
                  >tFrame.paragraphs.firstItem().appliedFont = "Adobe Myungjo Std\tM";

                  So the font's name followed by a tab (\t) followed by the font style.

                  Peter
                  • 6. Re: Font problem
                    Loic.Aigon Adobe Community Professional
                    Hi Mike,<br />i So the font's name followed by a tab (\t) followed by the font style. <br /><br />It appears clearly with that command :<br />for(i=0; i<app.fonts.length; i++) $.writeln(app.fonts[i].name); <br />You see the font written with the tab and then style.<br /><br />As Peter says in his book, sometimes it's good to just let the ESTK tell you ;-)