7 Replies Latest reply on Jul 4, 2016 7:25 AM by oleh.melnyk

    Another JSXBIN question.

    cbishop01 Level 2

      Hi all. 

      I have a Fit text to Frame script that works great.  However it adjusts the Fonts by .001 increments is there a way to change this to .02?  I know JSXBIN files cannot be edited but can another script running the Bin file override the font size?

        • 1. Re: Another JSXBIN question.
          oleh.melnyk Level 3

          Are you talking about script from in-tools?

          Try to contact a script author and ask if he can help...

           

          Actually, there's online parser for jsxbin files version 2, but scripts from in-tools were made with jsxbin v1. So, in theory, jsxbin v1 also can be converted to editable js file, but I don't know available parsers

          • 2. Re: Another JSXBIN question.
            cbishop01 Level 2

            I'll contact the author.  I don't want to infringe on his/her work.  Thank you..  and yes this is from in-tools.  Its a great script. 

            • 3. Re: Another JSXBIN question.
              oleh.melnyk Level 3

              here's my version, but it requires testing

               

              //DESCRIPTION: Fit each text line to the frame width
              
              
              /*
                  Oleh Melnyk <oleh.melnyk[at]gmail.com> 
                  30 June 2016
                  alpha v.0.1
              */
              
              
              #target:indesign;
              
              
              app.doScript(doUndoWrapper, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Fit text");
              function doUndoWrapper()
              {
                  var pointStep = 2; // pt    
              
              
                  if(app.selection[0] && app.selection[0].hasOwnProperty("parentStory")){    
                      var text = app.selection[0].parentStory;
                              
                      if(text.contents.length == 0){
                          exit(alert("Empty text frame selected!", "Error", 1));
                      }else{
                          // replace space to fixed width space (\u202F). 
                          // But since fixed width space is non-breakable - we add discretionary line break (\u200B) before and after
                          text.contents = text.contents.replace(/ /g, "\u200B\u202F\u200B");            
                      }
                      
                      app.selection[0].textFramePreferences.firstBaselineOffset = FirstBaseline.CAP_HEIGHT;
                      app.selection[0].textFramePreferences.verticalJustification = VerticalJustification.JUSTIFY_ALIGN;
                      
                      text.hyphenation = false;
                      text.justification = Justification.FULLY_JUSTIFIED;        
              
              
                      var lines = app.selection[0].parentStory.lines.length;
              
              
                      for(var i = 0; i < lines; i++){
                          // increasing text size till it break to the next line
                          while(app.selection[0].parentStory.lines.length == lines){
                             app.selection[0].parentStory.lines[i].pointSize += pointStep;
                          };
                          // roll back (to the last acceptable text size)
                          app.selection[0].parentStory.lines[i].pointSize -= pointStep;
                      }
                  
                      app.selection[0].fit(FitOptions.frameToContent);
                  }else{
                      exit(alert("Select text frame first!", "Error", 1));
                  }
              }
              
              1 person found this helpful
              • 4. Re: Another JSXBIN question.
                Marc Autret Level 4

                A generic fit-text-to-frame is reviewed here:

                Indiscripts :: InDesign Scripting Forum Roundup #8

                 

                It is fast and flexible. Any text property can be made adjustable.

                 

                @+

                Marc

                • 5. Re: Another JSXBIN question.
                  oleh.melnyk Level 3

                  Hi Mark,

                   

                  The link you provided is pointed to HORIZONTAL TEXT SCALE and here we are looking for text size change (fit text to frame), not horizontal text scale...

                   

                  And your script seems not working, or I'm doing something wrong - nothing changes, and there are no errors

                  • 6. Re: Another JSXBIN question.
                    Marc Autret Level 4

                    Hi Oleh,

                     

                    Sorry, my mistake.

                     

                    Two changes must be done to use my code:

                    1. Use 'pointSize' instead of 'horizontalScale' in parameter.

                    2. Remove the 1 != s.lines.length condition in the wrong() function (in the original script we had to handle single-line frames.)

                     

                    The final snippet looks like

                     

                    (function(/*Item[]*/a,/*str*/k,/*uint*/MIN,/*uint*/MAX, /*num*/PRECISION)  
                    {  
                        var t, s, v, w, m = [],  
                            wrong = function(){ return +t.overflows };
                    
                        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||[], 'pointSize', 6, 36, .1);
                    

                     

                    Does it work better?

                     

                    @+

                    Marc

                    1 person found this helpful
                    • 7. Re: Another JSXBIN question.
                      oleh.melnyk Level 3

                      Mark, your script works now, but not at the expected way (for me). Seems your script just increase font size to fill the frame with text.

                      And, personally, I expected to increase each line of text to the frame width, like in a screenshot below...

                      img-2016-07-04-17-16-28.png

                       

                      I think that's what Fit text to frame should do. But looks like your script just do what topic starter was looking for - let's wait and see