4 Replies Latest reply on Mar 30, 2009 5:38 PM by masc145

    script for a newspaper

    masc145
      We are a newspaper trying to write a script that creates two lines headlines, no matter how many words are in the headline, changing the font size?, is this possible?
        • 1. Re: script for a newspaper
          [Jongware] Most Valuable Participant
          What a fun challenge! This one took me about 3 minutes -- but it was a mental exercise.
          Put your text cursor in a line and double-click this script:

          while (app.activeDocument.selection[0].paragraphs[0].lines.length < 2)
          

          app.activeDocument.selection[0].paragraphs[0].pointSize += 1;
          lowerguess = app.activeDocument.selection[0].paragraphs[0].pointSize;

          while (app.activeDocument.selection[0].paragraphs[0].lines.length < 3)

          app.activeDocument.selection[0].paragraphs[0].pointSize += 1;

          higherguess = app.activeDocument.selection[0].paragraphs[0].pointSize;

          app.activeDocument.selection[0].paragraphs[0].pointSize = (lowerguess+higherguess)/2;

          while (app.activeDocument.selection[0].paragraphs[0].lines.length > 2)

          app.activeDocument.selection[0].paragraphs[0].pointSize -= 1;

          It first enlarges the text up to a
          i minimum
          required size to make the text 2 lines. I thought that a bit ... too easy -- you'll mostly end up with a single word on the 2nd line. So, next it enlarges the text up to 3 lines. It then takes the average of the two. If it ends up being 3 lines after all (I guess that's possible), the text gets smaller again to fit.

          (Don't use it on a single word! I just did -- it still works, but ... it will never get to 2 lines. Ever.)
          • 2. Re: script for a newspaper
            [Jongware] Most Valuable Participant
            Okay, tested some more. You get a better fit if you
            i first
            enlarge to at least 3 lines, then take the previous size:

            while (app.activeDocument.selection[0].paragraphs[0].lines.length < 3)
            

            app.activeDocument.selection[0].paragraphs[0].pointSize += 1;

            app.activeDocument.selection[0].paragraphs[0].pointSize -= 1;
            • 3. Re: script for a newspaper
              Jeremy bowmangraphics-DQuh1B Level 3
              jongware, that is brilliant!

              Thank you for that snippet -- it's given me all sorts of ideas.

              Best wishes -- Jeremy
              • 4. Re: script for a newspaper
                masc145 Level 1
                Thank´s it worked excellent and also gave me new ideas
                Miguel Sanchez