9 Replies Latest reply on Oct 29, 2015 1:27 AM by cinzia_pn

    Fit TEXT Horizontal Scale to frame (fixed) by max factor of 200% min 40

    CalebChristopher

      We're printing jerseys and often copy/paste player names into a template then adjust the horizontal scale one at a time to fit the text frame (up to 200% no less than 40%). This is a time consuming process, and I am certain there is a way to do this with a script. However I have not been able to figure it out. Any help would be appreciated.

        • 1. Re: Fit TEXT Horizontal Scale to frame (fixed) by max factor of 200% min 40
          [Jongware] Most Valuable Participant

          That came down to a certain amount of lateral thinking. How does one define 'fit' or 'does not fit'? The following seems to hold true, provided your names are the only thing in each its separate text frame: not more than 1 single line, and not (partially or entirely) overset.

           

          First, a reality check: does decreasing the text to 40% width actually make it fit? If not, set the scale back to 100% and leave it alone for Human Intervention. Next, scale it all the way up to 200%. As we cannot go any wider, we don't need to adjust anything that still doesn't "fit" per the above. Only if a name gets line-wrapped, it needs its width adjusted down again.

           

          Here is how it works: select all of your text frames at once, then run the script. Then sit back as it goes over each frame and adjusts the texts to fit with an accuracy of up to 0.1%

           

          I prepared an image to show what it looks -- Fanny Blankers-Koen, the skating Pride of Holland, was chosen to be the "too long" name to show that the script doesn't touch what it cannot fix, and Ali, Pele, and Louis (Joe, of course!) show that it won't go beyond 200%.

           

          Screen Shot 2015-04-07 at 11.12.44 PM.png

           

          Oh and here is the Javascript:

           

          //DESCRIPTION:Multi-text-frame-fit
          // A Jongware Script 07-Apr-2015
          
          for (i=0; i<app.selection.length; i++)
          {
            f = app.selection[i];
            ft = app.selection[i].parentStory;
            ft.horizontalScale = 40;
            // check if they fit -- if not, change back and YOU decide
            if (ft.lines.length > 1)
              ft.horizontalScale = 100;
            else
            {
              // calc what should fit
              ft.horizontalScale = 200;
              // still not there at 200? Leave it, else try smaller
              if (f.overflows || ft.lines.length > 1)
              {
                while (f.overflows || ft.lines.length > 1)
                  ft.horizontalScale -= 10;
                ft.horizontalScale += 10;
                while (f.overflows || ft.lines.length > 1)
                  ft.horizontalScale -= 1;
                ft.horizontalScale += 1;
                while (f.overflows || ft.lines.length > 1)
                  ft.horizontalScale -= 0.1;
              }
            }
          }
          
          • 2. Re: Fit TEXT Horizontal Scale to frame (fixed) by max factor of 200% min 40
            Vamitul Level 4

            Jongware,looking at those three while loops makes me want to slap myself... i always used just one with the lowest increment.Guess live and learn

            • 3. Re: Fit TEXT Horizontal Scale to frame (fixed) by max factor of 200% min 40
              Marc Autret Level 4

              Hi Theunis,

               

              Performance might probably be increased in seeking the optimal scale through a binary search.

              Here is a generic implementation:

               

              (function(/*Item[]*/a,/*str*/k,/*uint*/MIN,/*uint*/MAX, /*num*/PRECISION)
              {
                  var t, s, v, w, m = [],
                      wrong = function(){ return +(t.overflows || 1 != s.lines.length) };
              
                  while( t=a.pop() )
                  {
                      if( 'TextFrame'!=t.__class__ ) continue;
              
                      // Init
                      // ---
                      v = (s=t.parentStory)[k];
                      m[0] = MIN;
                      m[1] = MAX;
              
                      // Try extremum and quit if status doesn't change
                      // ---
                      s[k] = m[1-(w=wrong())];
                      if( w==wrong() ){ s[k]=v; continue; }
              
                      // Binary search
                      // ---
                      while( m[1]-m[0] > PRECISION ){ m[w=wrong()] = s[k] = (m[0]+m[1])/2; }
                      w && (s[k] = m[0]);
                  }
                  
              })(app.properties.selection||[], 'horizontalScale', 40, 200, .5);
              

               

              @+

              Marc

              • 4. Re: Fit TEXT Horizontal Scale to frame (fixed) by max factor of 200% min 40
                rpetersen65

                That is awesome, I really appreciate it. Thank you so much. If you're up for another challenge; can you do the same thing, but with names separated by paragraphs in the same text box? Like this?

                BooneCounty-ND2.jpg

                • 5. Re: Fit TEXT Horizontal Scale to frame (fixed) by max factor of 200% min 40
                  CalebChristopher Level 1

                  (rpetersen65 and I work together)

                  I suppose we could just make a "page" with multiple text frames on it and select all and run as a batch, like Jongware said.  However, I understand how copy/pasting a whole list of names into a single text frame would save more time. 

                   

                  Marc, is your script something to be combined with / modified into Jongware's script?

                  • 6. Re: Fit TEXT Horizontal Scale to frame (fixed) by max factor of 200% min 40
                    Marc Autret Level 4

                    @CalebChristopher

                     

                    > Marc, is your script something to be combined with / modified into Jongware's script?

                     

                    No, the code I suggest works alone. That's only an alternative approach.

                     

                    @+

                    Marc

                    • 7. Re: Fit TEXT Horizontal Scale to frame (fixed) by max factor of 200% min 40
                      cinzia_pn

                      this script is great but would it be possible to horizontally scale the text contained also in multiple line frames and with overset text only, in order to make the text fit without resizing the frames?

                      thank you!

                      • 9. Re: Fit TEXT Horizontal Scale to frame (fixed) by max factor of 200% min 40
                        cinzia_pn Level 1

                        uhm that is not exactly what I'm looking for as it decreases the font dimension. I'm only allowed to apply horizontal scale to the text, nothing else unfortunately.

                        thank you anyway!